/*                                                                  
* Copyright © 1999-2008 TeaLeaf Technology, Inc.  
* All rights reserved.
*
* THIS SOFTWARE IS PROVIDED BY TEALEAF ``AS IS'' 
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, 
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE DISCLAIMED.  
* IN NO EVENT SHALL TEALEAF BE LIABLE FOR ANY DIRECT, INDIRECT, 
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
* THE POSSIBILITY OF SUCH DAMAGE.
*
* @fileoverview
* This file sends Summary about Window, Document, Navigator and Screen 
* objects rendered on the page.
* 
* @requires 
* TeaLeaf.js
* TeaLeafEnvCfg.js
* TeaLeafEvent.js
*
* @version 2008.09.29.1
*                                                                   
*/
if(TeaLeaf.Env && TeaLeaf.Env.Configuration) {		
	/**
    * Send a page summary about Window, Document, Navigator and Screen 
    * object when the page is loaded.
    * @requires
    * TeaLeafEvent.js 
    * @addon
    */            	                                       
	TeaLeaf.Env.tlSendPageSummary = function() {
	    if( TeaLeaf.Configuration.tlSDK == false ){	    
	        if( TeaLeaf.Env.Configuration.tlinitpost == true ) {                 
                TeaLeaf.Env.Configuration.tlinitpost = false; 
                var tlevt = new TeaLeaf.Event("PERFORMANCE", "INIT");
			    TeaLeaf.Event.PageLoadMilliSecs = TeaLeaf.Event.tlDateDiff(TeaLeaf.tlStartLoad, tlevt.date);
                TeaLeaf.Event.SetType = tlevt.EventType;
                
                if(TeaLeaf.Event.SetSubType == ""){
                    TeaLeaf.Event.SetSubType = tlevt.EventSubType;
                }
                else{
                    TeaLeaf.Event.SetSubType += "; " + tlevt.EventSubType;
                }
                TeaLeaf.Event.Configuration.tlinitflag = true;                
                TeaLeaf.Env.tlInfo(tlevt);    
                TeaLeaf.Env.tlDOMDocumentInfo(tlevt);
                TeaLeaf.Env.tlDOMWindowInfo(tlevt);
                TeaLeaf.Env.tlDOMNavigatorInfo(tlevt);
                TeaLeaf.Env.tlDOMScreenInfo(tlevt);
                TeaLeaf.Env.tlPluginInfo(tlevt);
			    tlevt.tlSend(true);
            }
	    }
    }
	/*
    * Gather Basic Info.
    * @param tlevt TeaLeaf event used for reporting on the Document object.  
    * @requires
    * TeaLeafEvent.js 
    * @addon
    */            	                                           
    TeaLeaf.Env.tlInfo = function(tlevt){
        tlevt.tlPushXML("Info");
        var tlAddNameValueArray = new Array("PageLoadMilliSecs", TeaLeaf.Event.tlGetRenderTime(),
				                                    "Version", TeaLeaf.Event.tlGetJSVersion(), 
				                                    "TimezoneOffset", tlevt.date.getTimezoneOffset());
        tlevt.tlAddData(tlAddNameValueArray);  
        tlevt.tlPopXML();
    }
    
	/*
    * Gather Information about the Document object.
    * @param tlevt TeaLeaf event used for reporting on the Document object.  
    * @requires
    * TeaLeafEvent.js 
    * @addon
    */            	                                           
    TeaLeaf.Env.tlDOMDocumentInfo = function(tlevt){
        tlevt.tlPushXML("Document");
        var tlAddNameValueArray1 = new Array("URL", document.URL,
		                                    "Title", document.title,
						                    "Referer", document.referer,
						                    "ContentType", document.contentType,
						                    "LastModified", document.lastModified,
						                    "CharacterSet", document.characterSet,
						                    "Height", document.height,
						                    "Width", document.width);
		tlevt.tlAddData(tlAddNameValueArray1);
        var tlAddNameValueArray2 = new Array("Anchors", document.anchors.length,
						                     "Applets", document.applets.length,
						                     "Embeds", document.embeds.length,
						                     "Forms", document.forms.length,
						                     "Images", document.images.length,
						                     "BadImages", TeaLeaf.Event.tlBadImageCount(),
						                     "Links", document.links.length,
						                     "Plugins", document.plugins.length);
		tlevt.tlAddData(tlAddNameValueArray2);
		tlevt.tlPopXML();
    }
	/**
    * Gather Information about the Window object.
    * @param tlevt TeaLeaf event used for reporting on the Window object.
    * @requires
    * TeaLeafEvent.js 
    * @addon
    */            	                                           
    TeaLeaf.Env.tlDOMWindowInfo = function(tlevt){
	    tlevt.tlPushXML("Window");
	    var tlAddNameValueArray = new Array("WindowHref", escape(window.location.href),
						                    "WindowProtocol", window.location.protocol,
						                    "WindowHost", window.location.host,
						                    "WindowHostName", window.location.hostname,
						                    "WindowPort", window.location.port,
						                    "WindowPathName", window.location.pathname);	
		tlevt.tlAddData(tlAddNameValueArray);
		if( window.innerHeight && window.innerWidth ) {
		    var tlAddNameValueArrayWinClientSize = new Array("ClientSize", window.innerHeight + "x" + window.innerWidth);
		    tlevt.tlAddData(tlAddNameValueArrayWinClientSize);
		}
		else if(document.body) {
		    if(document.body.clientWidth && document.body.clientHeight){
		        var tlAddNameValueArrayDocClientSize = new Array("ClientSize", document.body.clientHeight + "x" + document.body.clientWidth);
                tlevt.tlAddData(tlAddNameValueArrayDocClientSize);
            }
		}
		var tlAddNameValueArrayScreen = new Array("FullScreen", navigator.fullScreen,
						                          "Frames", window.frames.length);
        tlevt.tlAddData(tlAddNameValueArrayScreen);
		tlevt.tlPopXML();
    }
	/**
    * Gather Information about the Navigator object.
    * @param tlevt TeaLeaf event used for reporting on the Navigator object.
    * @requires
    * TeaLeafEvent.js 
    * @addon
    */            	                                           
    TeaLeaf.Env.tlDOMNavigatorInfo = function(tlevt){
	    tlevt.tlPushXML("Navigator");
		//	Navigator Info
		var tlAddNameValueArray = new Array("AppCodeName", navigator.appCodeName,
						"AppName", navigator.appName,
						"AppVersion", navigator.appVersion,
						"BrowserLanguage", navigator.browserLanguage,
						"CookieEnabled", navigator.cookieEnabled,
						"CPUClass", navigator.cpuClass,
						"Language", navigator.language,
						"OSCPU", navigator.oscpu,
						"Platform", navigator.platform,
						"Product", navigator.product,
						"SystemLanguage", navigator.systemLanguage,
						"UserAgent", navigator.userAgent,
						"UserLanguage", navigator.userLanguage,
						"Vendor", navigator.vendor,
						"VendorSub", navigator.vendorSub);
		tlevt.tlAddData(tlAddNameValueArray);
		tlevt.tlPopXML();
    }    
	/**
    * Gather Information about the Screen object.
    * @param tlevt TeaLeaf event used for reporting on the Navigator object.
    * @requires
    * TeaLeafEvent.js 
    * @addon
    */            	                                           
    TeaLeaf.Env.tlDOMScreenInfo = function(tlevt){ 
 	    tlevt.tlPushXML("Screen");
		//	Screen Info
		var tlAddNameValueArray = new Array("AvailHeight", screen.availHeight,
						                    "AvailLeft", screen.availLeft,
						                    "AvailTop", screen.availTop,
						                    "AvailWidth", screen.availWidth,
						                    "BufferDepth", screen.bufferDepth,
						                    "ColorDepth", screen.colorDepth,
						                    "DeviceXDPI", screen.deviceXDPI,
						                    "DeviceYDPI", screen.deviceYDPI,
						                    "FontSmoothingEnabled", screen.fontSmoothingEnabled,
						                    "Height", screen.height,
						                    "Left", screen.left,
						                    "LogicalXDPI", screen.logicalXDPI,
						                    "LogicalYDPI", screen.logicalYDPI,
						                    "Top", screen.top,
						                    "UpdateInterval", screen.updateInterval,
						                    "Width", screen.width);
		tlevt.tlAddData(tlAddNameValueArray);	
		tlevt.tlPopXML();

    }
	/**
    * Gather Information about the available plugins.
    * @param tlevt TeaLeaf event used for reporting on available plugins.
    * @requires
    * TeaLeafEvent.js 
    * @addon
    */            	                                           
    TeaLeaf.Env.tlPluginInfo = function(tlevt){  
        if(window.ActiveXObject){
            for (var i = 0; i <TeaLeaf.Env.Configuration.tlPlugins.length; i++) {
                if(TeaLeaf.Env.Configuration.tlPlugins[i].tlenable){            
                    var tlPlugin = TeaLeaf.Env.Configuration.tlPlugins[i].tlIEplugin;
                    try {
                        var tlActiveX = new ActiveXObject(tlPlugin); 
                        if(tlActiveX){  
                            tlevt.tlPushXML("Plugin");
                            var tlAddNameValueArray = new Array("pluginname", TeaLeaf.Env.Configuration.tlPlugins[i].tlpluginname,
                                                                "version", TeaLeaf.Env.Configuration.tlPlugins[i].tlversion);	               
		                    tlevt.tlAddData(tlAddNameValueArray);	
		                    tlevt.tlPopXML();
                        }
                    }
                    catch(e){}
                }
            }
        }
        else{
          for(var i =0; i <navigator.plugins.length; i++){       
                for(var j =0; j <TeaLeaf.Env.Configuration.tlPlugins.length; j++){               
                    if(TeaLeaf.Env.Configuration.tlPlugins[j].tlenable){                    
                        var tlnavpluginname = navigator.plugins[i].name.substr(0, TeaLeaf.Env.Configuration.tlPlugins[j].tlpluginname.length);    
                        if(tlnavpluginname == TeaLeaf.Env.Configuration.tlPlugins[j].tlpluginname){   
                            TeaLeaf.Env.Configuration.tlPlugins[j].tlenable = false;        
                            tlevt.tlPushXML("Plugin");
                            var tlAddNameValueArray = new Array("pluginname", TeaLeaf.Env.Configuration.tlPlugins[j].tlpluginname,
                                                                "version", TeaLeaf.Env.Configuration.tlPlugins[j].tlversion);
		                    tlevt.tlAddData(tlAddNameValueArray);	
		                    tlevt.tlPopXML();

                        }                           
                    }  
                }
            }        
        } 
    }

	/**
    * Initialize the call to tlSendPageSummary when UI Client Event
    * Capture is not used as an SDK.
    * @addon
    */            	                                           
	TeaLeaf.Env.CallInit = function() {	
        TeaLeaf.addOnLoad(TeaLeaf.Env.tlSendPageSummary);
	}	
	if(TeaLeaf.Env.Configuration.tlinit == false){
	    TeaLeaf.Env.Configuration.tlinit = true;
	    TeaLeaf.Env.CallInit();
	}
}
