﻿/** Core UsaProxy JavaScript part. This proxyscript.js is used for pure logging of user activity
	without any collaboration functionality */
//alert("testA");
//alert('inScript');

 
var logVal_UsaProxy;			// String: Initialised when page loads. Contains current event log entries
var FLG_writingLogVal_UsaProxy;	// Boolean: if flag set, writing log entry to logVal_UsaProxy not possible

var IVL_saveLog_UsaProxy;		// Interval function variable for sending captured data to UsaProxy

var serverdataId_UsaProxy;      /* String: contains related serverdata ID defined by UsaProxy 
			
	 * (page ID assigned by UsaProxy when data was cached)*/

var id_UsaProxy;				// String: contains String identifying the current UsaProxy instance
								 
/* timestamp objects */
var startDate_UsaProxy;			/* Date: Initialised by UsaProxy. Load completion timestamp is  
								   calculated relative to this timestamp */
var loadDate_UsaProxy;			// Date: Initialised on load. All further timestamps are calculated
								// by adding the ms passed since page load completion to this
								//  relative timestamp.

var FLG_LogMousemove_UsaProxy;	// Boolean: while flag set, mousemove logging is interrupted 
								// for all following log attempts
var lastMousePosX_UsaProxy;		// Integer: last x position of the mouse pointer
var lastMousePosY_UsaProxy;		// Integer: last y position of the mouse pointer

var IVL_scrollCheck_UsaProxy;	// Interval function variable for processScroll_UsaProxy()
var lastScrollPosY_UsaProxy;	// Integer: last position of vertical scrollbar resp. top offset of document
var lastScrollPosX_UsaProxy;	// Integer: last position of vhorozontal scrollbar resp. left offset of document

var keyName_UsaProxy;			// String: holds current pressed key/key combination
var FLG_ctrlPressed_UsaProxy;	// Boolean: flag is set when ctrl-key is pressed (and reset when released)
var FLG_ctrl_comb_UsaProxy;		// additional flag for ctrl+key combinations
var FLG_altPressed_UsaProxy;	// Boolean: flag is set when alt-key is pressed (and reset when released)
var FLG_shiftPressed_UsaProxy;	// Boolean: flag is set when shift-key is pressed (and reset when released)

var fieldValueHas = new Object();//hash table object to store original field values
var FLG_keyPress_UsaProxy;		// Boolean: flag disables keypress check; set when any of the control keys is pressed
var FLG_comb_UsaProxy;			// Boolean: flag indicates a key combination
var combMembers_UsaProxy;		// Integer: number of remaining unreleased keys if a key combination was pressed
var TIMER = 5;
var SPEED = 10;
var WRAPPER = 'content';
//var lastSelection_UsaProxy;		// String: last selected text
var isReveresProxy=false;
var UnKnownIPByProxy='false';
VIH_BackColor = "palegreen";
VIH_ForeColor = "navy";
VIH_FontPix = "16";
VIH_DisplayFormat = "You are visiting from:<br>IP Address: %%IP%%<br>Host: %%HOST%%";
VIH_DisplayOnPage = "no";
var side_URL = 'http://194.90.113.20:80'; 

//var side_URL = 'http://127.0.0.1:8000'; 
/* usability dinamic vars */var VAR_G1_I2=0;var VAR_G2_I4=0;//end of usability dinamic vars //
/* Flags for RM feature*/
	var isRMEnabled=false;
	var isRMActive=false;// end of RM flags
/* response info dinamic vars*/var responseFlag=true;var responseArray = new Array();var matchedString = '';responseArray['testC']='testD';//end of response info dinamic vars //

/* Initializes all variables, event handlers, and interval functions and
 * invokes the logging of the load event 
 */
//alert("before on error");
var lastLoggedEvent='';//String of wrote Event
var clickOnSaveURL = 'http://localhost/clickOn/clickOnSave.aspx?event=';
var clickOnShowURL = 'http://localhost/clickOn/clickOnShow.aspx?event=';
var sessionID_UsaProxy = 'abcdefg'
var lastControlType;	// Last control type to have focus
var lastControlID; // Last Control ID to have focus
var lastControlName // last Control Name to have value
//var dip = 


var fType="isStart"; // id,name or none

//alert('before flag');
if(responseFlag)
	{
	so_getHTTPHeaders();
	}
//alert('after flag');

function init_UsaProxy() {
	//alert("start init");
	
	logVal_UsaProxy 			= "";
	window.status 				= "";
	FLG_writingLogVal_UsaProxy 	= false;
	
	FLG_LogMousemove_UsaProxy 	= false;
	lastMousePosX_UsaProxy 		= 0;
	lastMousePosY_UsaProxy 		= 0;
	
	/* initialize lastScrollPos_UsaProxy with current top/left offset */
	lastScrollPosY_UsaProxy 	= (window.Event) ? window.pageYOffset : document.body.scrollTop;
	lastScrollPosX_UsaProxy 	= (window.Event) ? window.pageXOffset : document.body.scrollLeft;
	
	lastSelection_UsaProxy 		= "";
	
	keyName_UsaProxy 			= "";
	FLG_ctrlPressed_UsaProxy 	= false;
	FLG_ctrl_comb_UsaProxy		= false;
	FLG_altPressed_UsaProxy 	= false;
	FLG_shiftPressed_UsaProxy 	= false;
	FLG_keyPress_UsaProxy 		= true;
	FLG_comb_UsaProxy 			= false;
	combMembers_UsaProxy 		= 0;
	
	/* retrieve reference string URL parameters */
	
	var par_start			= document.getElementById("proxyScript_UsaProxy").src.indexOf("?");
	var pars_UsaProxy   	= document.getElementById("proxyScript_UsaProxy").src.substring(par_start);
	/* retrieve current httptrafficindex which is specified by the parameter sd */
	par_start				= 4;
	var par_end				= pars_UsaProxy.indexOf("&");
	serverdataId_UsaProxy	= pars_UsaProxy.substring(par_start, par_end);
	/* initialize start date specified by parameter ts */
	par_start				= pars_UsaProxy.indexOf("&ts=") + 4;
	var par_end				= pars_UsaProxy.indexOf("&", par_start);
	if (par_end==-1) par_end = pars_UsaProxy.length;
	startDate_UsaProxy		= date_UsaProxy(pars_UsaProxy.substring(par_start, par_end));
	/* initialize UsaProxy instance ID specified by parameter id */
	par_start				= pars_UsaProxy.indexOf("&id=") + 4;
	var par_end				= pars_UsaProxy.indexOf("&", par_start);
	if (par_end==-1) par_end = pars_UsaProxy.length;
	id_UsaProxy				= pars_UsaProxy.substring(par_start, par_end);	
	if (!(isReveresProxy))
		{
			serverdataId_UsaProxy = randomPassword(12);


		}	
	
	/* log load event */
	processLoad_UsaProxy();
	
	/* registration of event handlers
	 * most event handlers are attached to the document/window element
	 * mouse events "bubble" from the target element (such as a button)
	 * to the document element and can be captured there.
	 * Other events such as focus, blur, change need to be directly
	 * captured at the target element */
		window.status="";
	
	// NS explicit event capturing
	var browser=navigator.appName;
	//alert("before window event : " + browser);
	if(browser=="Netscape") {
		document.captureEvents(Event.CHANGE | Event.MOUSEUP | Event.KEYPRESS | Event.KEYDOWN | Event.KEYUP | Event.MOUSEMOVE | Event.MOUSEOVER | Event.FOCUS | Event.BLUR | Event.SELECT);
		window.captureEvents(Event.RESIZE);
	}
	//alert("after window event");
	/* attach event handlers to avoid overwriting
	 * IE: attachEvent
	 * NS: addEventListener */
	 
	// IE
	if(document.attachEvent) { 
		
		document.attachEvent('onmousedown', processMousedown_UsaProxy);
		document.attachEvent('onkeypress', processKeypress_UsaProxy);
		document.attachEvent('onkeydown', processKeydown_UsaProxy);
		document.attachEvent('onkeyup', processKeyup_UsaProxy);
		document.attachEvent('onmousemove', processMousemove_UsaProxy);
		//document.attachEvent('onmouseover', processMouseover_UsaProxy);
		document.attachEvent('onmouseup', processMouseUp_UsaProxy);
		//document.attachEvent('onSubmit', processMouseover_UsaProxy);
		document.attachEvent('ondblclick', processDoubleClick_UsaProxy);	
		window.attachEvent('onresize', processResize_UsaProxy);
		window.attachEvent('onbeforeunload', processBrowserClose_UsaProxy);
		
		/* change, focus, and blur handler for each relevant element
		 * dropdowns, lists, text fields/areas, file fields, password fields, and checkboxes*/
		/* in addition change, focus, blur, and select listener will be applied to
		 * each relevant element onmouseover (see function processMouseover_UsaProxy) */
		
		for (var i = 0; i < document.forms.length; ++i) {
			for (var j = 0; j < document.forms[i].elements.length; ++j) {
			
				if(document.forms[i].elements[j].type) {
					var elType = document.forms[i].elements[j].type;
					if (elType=="select-one" || elType=="select-multiple" || elType=="text" || elType=="textarea" || elType=="file" || elType=="checkbox" || elType=="password" || elType=="radio") {
						document.forms[i].elements[j].attachEvent('onchange', processChange_UsaProxy);
						document.forms[i].elements[j].attachEvent('onblur', processBlur_UsaProxy);
						document.forms[i].elements[j].attachEvent('onfocus', processFocus_UsaProxy);
						if (elType=="text")
						fieldValueHas[document.forms[i].elements[j].id]=document.forms[i].elements[j].value;
					}
				}
			
			
			}
		}
	}
	
	// NS
	if(document.addEventListener) {
	//	alert("NS attach event ");
		document.addEventListener('mousedown', processMousedown_UsaProxy, false);
		document.addEventListener('keypress', processKeypress_UsaProxy, false);
		document.addEventListener('keydown', processKeydown_UsaProxy, false);
		document.addEventListener('keyup', processKeyup_UsaProxy, false);
		document.addEventListener('mousemove', processMousemove_UsaProxy, false);
		//document.addEventListener('mouseover', processMouseover_UsaProxy, false);
		window.addEventListener('resize', processResize_UsaProxy, false);
		window.addEventListener('beforeunload', processBrowserClose_UsaProxy, false);
		/* change, focus, and blur handler for each relevant element
		 * dropdowns, lists, text fields/areas, file fields, password fields, and checkboxes*/
		/* in addition change, focus, blur, and select listener will be applied to
		 * each relevant element onmouseover (see function processMouseover_UsaProxy) */
		for (var i = 0; i < document.forms.length; ++i) {
			for (var j = 0; j < document.forms[i].elements.length; ++j) {
				
				if(document.forms[i].elements[j].type) {
					var elType = document.forms[i].elements[j].type;
					if (elType=="select-one" || elType=="select-multiple" || elType=="text" || elType=="textarea" || elType=="file" || elType=="checkbox" || elType=="password" || elType=="radio") {
						document.forms[i].elements[j].addEventListener('change', processChange_UsaProxy, false);
						document.forms[i].elements[j].addEventListener('blur', processBlur_UsaProxy, false);
						document.forms[i].elements[j].addEventListener('focus', processFocus_UsaProxy, false);
					}
				}
				
				
			}
		}
	}
	//alert("before interval");
	/* instantiate scroll check and save function being invoked periodically */
	IVL_scrollCheck_UsaProxy 	= window.setInterval("processScroll_UsaProxy()",1000);
	IVL_saveLog_UsaProxy 		= window.setInterval("saveLog_UsaProxy()",3000);
	

	//alert(location.href + " start end");
	//alert("after init");
}

//alert('before attach');
if(document.attachEvent) window.attachEvent('onload', init_UsaProxy);
if(document.addEventListener) window.addEventListener('load', init_UsaProxy, false);
//alert('after attach');
// Returns a Date object computed from a given datestamp string

function date_UsaProxy(datestamp /*string*/) {
	var datestampTail 	= datestamp;
	var year 			= Number(datestampTail.substring(0,datestampTail.indexOf("-")));
	datestampTail 		= datestampTail.substring(datestampTail.indexOf("-")+1);
	var month 			= Number(datestampTail.substring(0,datestampTail.indexOf("-")));
	datestampTail 		= datestampTail.substring(datestampTail.indexOf("-")+1);
	var day 			= Number(datestampTail.substring(0,datestampTail.indexOf(",")));
	datestampTail 		= datestampTail.substring(datestampTail.indexOf(",")+1);
	var hours 			= Number(datestampTail.substring(0,datestampTail.indexOf(":")));
	datestampTail 		= datestampTail.substring(datestampTail.indexOf(":")+1);
	var mins 			= Number(datestampTail.substring(0,datestampTail.indexOf(":")));
	datestampTail 		= datestampTail.substring(datestampTail.indexOf(":")+1);
	var secs 			= Number(datestampTail);
	return			    new Date(year,month,day,hours,mins,secs);
}

/* Returns a timestamp string of the form "2004-12-31,23:59:59".
 * Takes UsaProxy's httptraffic log entry time as start time and adds
 * the difference between load time and current time */
function datestamp_UsaProxy() {
	if (loadDate_UsaProxy==null) loadDate_UsaProxy = new Date();
	var currentDate 	= new Date();
	// get milliseconds from load time
	var diffSecs 		= Math.abs(currentDate.getTime() - loadDate_UsaProxy.getTime());
	// return new Date object according to UsaProxy start time + diffMSecs
	//var currentUPDate 	= new Date(startDate_UsaProxy.getTime() + diffSecs);
	var currentUPDate 	= new Date();
    //alert(currentDate.getMonth());
	return currentUPDate.getFullYear() + "-" + completeDateVals(currentUPDate.getMonth()+1) + "-"
	  + completeDateVals(currentUPDate.getDate()) + "," + completeDateVals(currentUPDate.getHours())
	  + ":" + completeDateVals(currentUPDate.getMinutes())
	  + ":" + completeDateVals(currentUPDate.getSeconds());
}

/** Completes single-digit numbers by a "0"-prefix */
function completeDateVals(dateVal) {
	var dateVal = "" + dateVal;
	if (dateVal.length<2) return "0" + dateVal;
	else return dateVal;
}
  
/* Appends an event log entry together with the httptrafficindex referencing this page,
   the client's session ID,
 * and the current timestamp to logVal_UsaProxy */
function writeLog_UsaProxy(text) {
	// if function is already being executed, defer writeLog_UsaProxy for 50ms
	//alert(text);
	lastLoggedEvent=text;
	if(FLG_writingLogVal_UsaProxy) { window.setTimeout("writeLog_UsaProxy(" + text + ")",50); return false;}
	
	// generate and append log entry
	var logline;
	logLine = datestamp_UsaProxy() + "&sd=" + serverdataId_UsaProxy + "&sid="
	+ sessionID_UsaProxy + "&event=" + text;
	
	// set synchronization flag (block function)
	FLG_writingLogVal_UsaProxy = true;
	logVal_UsaProxy = logVal_UsaProxy + logLine + "&xX"; // Add logLine to interaction log
	// reset synchronization flag (release function)
	FLG_writingLogVal_UsaProxy = false;
}

/* Returns all available node information such as the DOM path, an image name, href, etc. */
function generateEventString_UsaProxy(node /*DOM element*/) {
	
	//alert(node);
	var eventString = "";
	eventString = eventString + "&dom=" + getDOMPath(node);  // append DOM path
	
	// if target has a href property
	if (node.href) {
		
		/* image detection IE: IE doesn't register any src property
		 * instead href contains the file path */
		//alert("is href");
		if(node.nodeName=="img" || node.nodeName=="IMG") {	
			// if linked image (parent node is an <a>-element)
			eventString = eventString
			if(node.parentNode.href)  
				eventString = eventString + "&img=" + getFileName(node.href) + "&link=" + node.parentNode.href;
			else eventString = eventString + "&img=" + getFileName(node.href);
		}
		// NS+IE: link detection
		else if(node.nodeName=="a" || node.nodeName=="A") {  // if anchor tag
			// IE: innertext property contains link text
			if (node.innerText)
				eventString = eventString + "&link=" + node.href + "&text=" + node.innerText;
			// NS: text property contains link text
			else eventString = eventString + "&link=" + node.href + "&text=" + node.text;
		}
	} else {
		// image detection NS
		
		if(node.nodeName=="button" || node.nodeName=="BUTTON")
		{
			//alert("isButton");
			if (node.type=="submit" || node.type=="SUBMIT")
			{
				//alert('submited');
				eventString = eventString + "&button=submit"
			}
		}
		//alert("not href");
		if (node.src) {		
			if (node.parentNode.href)
				eventString = eventString + "&img=" + getFileName(node.src) + "&link=" + node.parentNode.href
			else eventString = eventString + "&img=" + getFileName(node.src);
			
		
		}
	}
	
	return eventString;
}

/* Returns file name of a URL/path */
function getFileName(path /*string*/) {
	if(path.lastIndexOf("/")>-1)
		return path.substring(path.lastIndexOf("/")+1);
	else return path;
}

/***** AJAX code.
	   Used with each logging request  */
//alert("before array");
var xmlreqs_UsaProxy = new Array();	/** contains the currently used XMLHttpRequest objects */
//alert("after array");
/* Creates a new XMLHttpRequest object with a freed parameter 
   which indicates whether the object is currently operating 
   (e.g. expecting a UsaProxy response) */
function OBJ_XHR_UsaProxy(freed /*number*/){
	this.freed = freed;
	this.newReq = false;
	// NS
	if(window.XMLHttpRequest) {
		//if(isReveresProxy)
		//{
			try { this.newReq = new XMLHttpRequest(); }
			catch(e) { this.newReq = false; }
		//}
		//else
		//{
			//try { this.newReq = new CrossXHR(); }
		  	
		  	//catch(e) { this.newReq = false; }	
		//}
	 // 	
	  	
		//this.newreq = new flensed.flXHR();
	}
	// IE
	else if(window.ActiveXObject) {
		if(isReveresProxy)
		{
			try { this.newReq = new ActiveXObject("Microsoft.XMLHTTP");  }
			  catch(e) {
				try { this.newReq = new ActiveXObject("Msxml2.XMLHTTP"); }
				catch(e) {
				  this.newReq = false;}
				}
		}
		else
		{
			//try { this.newReq = new CrossXHR(); }
			 // catch(e) {
			//	try { this.newReq = new ActiveXObject("Msxml2.XMLHTTP"); }
				//catch(e) {
				//  this.newReq = false;}
				//}
		}
		
	 // try { this.newReq = new ActiveXObject("Microsoft.XMLHTTP"); }
	
	// }
	}
}

/** Sends an asynchronous HTTP request to UsaProxy.
	Examines each existent XMLHttpRequest object in xmlreqs_UsaProxy array,
	whether it is ready to handle this request. If not, a new OBJ_XHR_UsaProxy
	object is created with a freed value of 1 and added to the array.
	Then, the request is sent, freed is set to 0: occupied, and the readystatechange listener
	assigned the specified handler function. */
function xmlreqGET_UsaProxy(url /*string*/, callback_function /*string*/) {
	//alert(url);
	var pos = -1;
	for (var i=0; i< xmlreqs_UsaProxy.length; i++) {
		if (xmlreqs_UsaProxy[i].freed == 1) { pos = i; break; }
	}
	//alert('after for');
	if (pos == -1) { pos = xmlreqs_UsaProxy.length; xmlreqs_UsaProxy[pos] = new OBJ_XHR_UsaProxy(1); }
	//alert('after first if');
	if (xmlreqs_UsaProxy[pos].newReq) {
		xmlreqs_UsaProxy[pos].freed = 0;
		//alert('before open');
		xmlreqs_UsaProxy[pos].newReq.open("GET",url,true);
		//alert('after open');
		if(isReveresProxy)
		{
			xmlreqs_UsaProxy[pos].newReq.onreadystatechange = function() {
				if (window.xmlhttpChange_UsaProxy) { xmlhttpChange_UsaProxy(pos, callback_function); }
		}
		
		}
		//alert('after second if');
		if (window.XMLHttpRequest) {
			try
			{
				//alert('try to send 1');
				//xmlreqs_UsaProxy[pos].newReq.onreadystatechange = function() {
				//if (window.xmlhttpChange_UsaProxy) { xmlhttpChange_UsaProxy(pos, callback_function); }
				xmlreqs_UsaProxy[pos].newReq.send(null);
				//CSSHttpRequest.get(
				//        url,"");
				//alert('after send 1');       
			}
			catch(e)
			{
				//alert('catch send 1');
			}
			
		} else if (window.ActiveXObject) {
			//alert('try to send 2');
			xmlreqs_UsaProxy[pos].newReq.send();
		}
	}
}

/** Executes the specified handler function and 
    assigns it the received XML response provided by the used XMLHttpRequest object
	(stored in the array at position pos) */
function xmlhttpChange_UsaProxy(pos /*number*/, callback_function /*string*/) {
	if (typeof(xmlreqs_UsaProxy[pos]) != 'undefined' && xmlreqs_UsaProxy[pos].freed == 0 && xmlreqs_UsaProxy[pos].newReq.readyState == 4) {
		// try catch due to status exceptions in Firefox
		try {
			if (xmlreqs_UsaProxy[pos].newReq.status == 200 || xmlreqs_UsaProxy[pos].newReq.status == 304) {
				eval(callback_function + '(xmlreqs_UsaProxy[' + pos + '].newReq.responseXML)'); 
			} else {
				//handle_error();
			}
			xmlreqs_UsaProxy[pos].freed = 1;
		}
		catch( e ) {
		//	alert('Caught Exception: ' + e.description);
		}
	}
}

/** end of AJAX code */

/** Sends tracked usage data (if available) to UsaProxy */
function saveLog_UsaProxy() {
	//alert('in save');

	if(logVal_UsaProxy!="") {
		//alert(logVal_UsaProxy);
		//CSSHttpRequest.get(side_URL + "/usaproxylolo/log?" + logVal_UsaProxy, "");
		if(isReveresProxy)
		{
			xmlreqGET_UsaProxy("/usaproxylolo/log?" + logVal_UsaProxy, "");
		}
		else
		{
			//xmlreqGET_UsaProxy(side_URL + "/usaproxylolo/log?" + logVal_UsaProxy, "");

		var browser=navigator.appName;
		//alert("before window event : " + browser);
		if(browser=="Netscape") {
			//alert('in firefox');
			try
			{
			
				xmlreqGET_UsaProxy(side_URL + "/usaproxylolo/log?" + logVal_UsaProxy, "");
			}
			catch( e ) {
			//alert('Caught Exception: ' + e.description);
			}
		}
		else
		{
                	//alert('in json');
			
			var head = document.getElementsByTagName("head")[0];
			var script = document.createElement("script");
			script.src = side_URL + "/usaproxylolo/log?" + logVal_UsaProxy ;
			head.appendChild(script);
			
			window.status="";
			
               	 	logVal_UsaProxy = "";
			
			try
			{
                		head.removeChild(script);
			}
			catch(e)
			{
				script.parentNode.removeChild(script);

			}
			
		}


		}
		
		/*var head = document.getElementsByTagName("head")[0];
		var script = document.createElement("script");
		script.src = side_URL + "/usaproxylolo/log?" + logVal_UsaProxy ;*/
		//script.src = "/usaproxylolo/log?" + logVal_UsaProxy ;
		/*head.appendChild(script);*/
		logVal_UsaProxy = ""; // reset log data
		/*head.removeChild(script);*/
	}
}

/** Event logging functionality */

/* Processes load event (logs load event together with the page size) */
function processLoad_UsaProxy(e) {
	/* get size
	 * NS: first case (window.innerWidth/innerHeight available); IE: second case */
// Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
	var loadWidth, loadHeight;
	loadWidth 	= (window.innerWidth) ? window.innerWidth : document.body.offsetWidth;  // innerWidth=NS
	loadHeight 	= (window.innerHeight) ? window.innerHeight : document.body.offsetHeight;  // innerHeight=NS
	//saveHTML();
	if(isRMEnabled)
	{
		
		var RM_BTN = document.getElementById('proposebut');
		if (isRMActive)		
		{		
			RM_BTN.style.visibility = 'visible'; 
		}
		else
		{		
			RM_BTN.style.visibility = 'hidden'; 			
		}		
	}
	//var s = this.file;
	//alert(s);
	if(isReveresProxy==false)

	{
	// newdiv= document.createElement("div");
	// set div attributes 
	//newdiv.id="service";
	//newdiv.addBehavior("webservice.htc");
        //newdiv.style.display = 'none';
	//document.body.appendChild(newdiv);
	//mydiv = document.getElementById("service")
	//document.getElementsByTagName("body")[0].Style.Add("BEHAVIOR","url(htc/webservice.htc)");   
	//document.getElementsByTagName("body")[0].useService("http://localhost/ejitDataServices/toOracle.asmx?WSDL","toOracle");
	//saveHTML();
	//document.body.removeChild(newdiv);
	 //document.body.addBehavior('webservice.htc');
        // document.body.onreadystatechange =StateChange

	}
	

if(UnKnownIPByProxy=='true')
{


               id_UsaProxy=VIH_HostIP;
               // head.removeChild(script);

}

	
//alert("responsep is " + matchedString); 	
writeLog_UsaProxy("load&size=" + loadWidth + "x" + loadHeight + "&ref=" + document.referrer + "&browser=" + BrowserDetect.browser + " " + BrowserDetect.version + "&responseP=" + matchedString + "&dip=" + id_UsaProxy + "&dURL=" + location.href );
	
	//saveLog_UsaProxy();
}

/* Processes window resize event (logs resize event together with the page size) */
function processResize_UsaProxy(e) {
	/* get size
	 * NS: first case (window.innerWidth/innerHeight available); IE: second case */
	var newWidth, newHeight;
	
	newWidth 	= (window.innerWidth) ? window.innerWidth : document.body.offsetWidth;  // innerWidth=NS
	newHeight 	= (window.innerHeight) ? window.innerHeight : document.body.offsetHeight;  // innerHeight=NS
	//writeLog_UsaProxy("resize&size=" + newWidth + "x" + newHeight);
	//saveLog_UsaProxy();
}
/* process browser close event (log just the closing of the browser)

 */
function processBrowserClose_UsaProxy(e){
	if ( window.event.clientY < 0 )
	{
	// User closed the browser via the 'X' button;
		writeLog_UsaProxy("close&btpe=browser");
	}
	else
	{
		// User navigated to another page;
		writeLog_UsaProxy("unload&btpe=browser");
	}
	
	saveLog_UsaProxy();
}
/* Processes mousemove event if FLG_LogMousemove_UsaProxy isn't set 
   (FLG_LogMousemove_UsaProxy defers the next mousemove logging action
   for 150 ms) */
function processMousemove_UsaProxy(e) {
	
	/* get event target, x, and y value of mouse position
	 * NS: first case (window.Event available); IE: second case */
	var browser=navigator.appName;
	var ev 		= (browser=="Netscape") ? e : window.event;
	var target 	= (browser=="Netscape") ? ev.target : ev.srcElement;
	var x 		= (browser=="Netscape") ? ev.pageX : ev.clientX;
	var y 		= (browser=="Netscape") ? ev.pageY : ev.clientY; 
	
	var xOffset = x ;	// - absLeft(target) compute x offset relative to the hovered-over element
	var yOffset = y ;	// - absTop(target) compute y offset relative to the hovered-over element
	
	// if log mousemove flag is false, set it true and log a mousemove event
	if (!FLG_LogMousemove_UsaProxy
		/** if mouse pointer actually moved */
		&& !(x==lastMousePosX_UsaProxy && y==lastMousePosY_UsaProxy) ) {
			FLG_LogMousemove_UsaProxy = true;
			lastMousePosX_UsaProxy = x;
			lastMousePosY_UsaProxy = y;
			
			//writeLog_UsaProxy("mousemove&offset=" + xOffset + "," + yOffset + generateEventString_UsaProxy(target));
			//writeLog_UsaProxy("mousemove&offset=" + xOffset + "," + yOffset + "&dom=a");
			//saveLog_UsaProxy();
			window.setTimeout('setInaktiv_UsaProxy()',150);
	}
}

/* Resets the log mousemove blocking flag so that the next 
   mousemove event may be logged */
function setInaktiv_UsaProxy() {
	FLG_LogMousemove_UsaProxy = false;
}

/* Processes mouseover event.
 * logs mouseover events on all elements which have either an
 * id, name, href, or src property (logging more would cause a log overload).
   In addition it applies the appropriate direct event listeners to form elements */  
function processMouseover_UsaProxy(e) {
	//alert("in over");
	/* get event target
	 * NS: first case (window.Event available); IE: second case */
	var ev = (window.Event) ? e : window.event;
	var target = (window.Event) ? ev.target : ev.srcElement;
	//var target = window.event.srcElement;
	/* add appliable event listeners to hovered element */
	/* first, check if element has a type property.
	 * Secondly, check its type and apply listeners */
	 if(target.type) {
		if (target.type=="select-one" 
		 || target.type=="select-multiple"
		 || target.type=="text" 
		 || target.type=="textarea" 
		 || target.type=="file" 
		 || target.type=="checkbox" 
		 || target.type=="password"
		 || target.type=="radio") {
		 	// IE
		 	if(target.attachEvent) { 
				/* first, remove existent event listener
				 * detachEvent doesn�t give any errors if the listener 
				 * to be removed has not been added to target */
				// change listener
				target.detachEvent('onchange', processChange_UsaProxy);
				target.attachEvent('onchange', processChange_UsaProxy);
				if (target.type=="text" 
		 		 || target.type=="textarea" 
		 		 || target.type=="file" 
		 		 || target.type=="password" 
		 		 || target.type=="select-multiple") {
				 	// focus listener
				 	target.detachEvent('onfocus', processFocus_UsaProxy);
				 	target.attachEvent('onfocus', processFocus_UsaProxy);
					// blur listener
					target.detachEvent('onblur', processBlur_UsaProxy);
					target.attachEvent('onblur', processBlur_UsaProxy);
				 }
			}
			// NS
			else if (target.addEventListener) {
				/* first, remove existent event listener (equal to detachEvent) */
				// change listener
				target.removeEventListener('change', processChange_UsaProxy, false);
				target.addEventListener('change', processChange_UsaProxy, false);
				if (target.type=="text" 
		 		 || target.type=="textarea" 
		 		 || target.type=="file" 
		 		 || target.type=="password" 
		 		 || target.type=="select-multiple") {
				 	// focus listener
					target.removeEventListener('focus', processFocus_UsaProxy, false);
				 	target.addEventListener('focus', processFocus_UsaProxy, false);
					// blur listener
					target.removeEventListener('blur', processBlur_UsaProxy, false);
					target.addEventListener('blur', processBlur_UsaProxy, false);
				 }
				 if (target.type=="text" 
		 		  || target.type=="textarea" ) {
				 	// select listener: only for NS
					target.removeEventListener('select', processSelectionNS_UsaProxy, false);
				 	target.addEventListener('select', processSelectionNS_UsaProxy, false);
				 }
			}
		}
	}
	
	// log mouseover coordinates and all available target attributes
	// if element has an id attribute
	/*if (target.id) 	//writeLog_UsaProxy("mouseover&id=" + target.id + "&type=" + target.type + generateEventString_UsaProxy(target));
	else {
		// if element has a name attribute
		if(target.name)// writeLog_UsaProxy("mouseover&name=" + target.name + "&type=" + target.type + generateEventString_UsaProxy(target));
		else {
			// if element has an href or src attribute
			if (target.href || target.src)
				//writeLog_UsaProxy("mouseover" + generateEventString_UsaProxy(target));
		}
	}*/
}

/* no mouseout event since with regular user tracking not necessary */

/* Processes mouse release event.
   Logs mousedown event together with the mouse button type (if middle or
   right button), and the available event target properties.
   Since click might have occured also outside of form fields, images, or, hyperlinks,
   the mouse pointer position is recorded relative to the hovered-over area/element. */
function processMouseUp_UsaProxy(e) {
	//alert('in mouse up');
	var ev 		= (window.Event) ? e : window.event;
	var target 	= (window.Event) ? ev.target : ev.srcElement;
	var x 		= (window.Event) ? ev.pageX : ev.clientX;
	var y 		= (window.Event) ? ev.pageY : ev.clientY; 
	target=window.event.srcElement;
	var xOffset = x ;	// - absLeft(target) compute x offset relative to the hovered-over element
	var yOffset = y;	//  - absTop(target) compute y offset relative to the hovered-over element
	//alert(target.outerHTML);
	if(target.nodeName=="IMG")
	{
		//alert(target.outerHTML);
		
		if(target.outerHTML.match("/Images/Map") || target.outerHTML.match("google"))
		writeLog_UsaProxy("mousedown&type=map&offset=" + xOffset + "," + yOffset + generateEventString_UsaProxy(target));
	}
	return;
}
/* procwss mouse double click event/*
 * 
 */
function processDoubleClick_UsaProxy(e){
	var ev 		= (window.Event) ? e : window.event;
	var target 	= (window.Event) ? ev.target : ev.srcElement;
	var x 		= (window.Event) ? ev.pageX : ev.clientX;
	var y 		= (window.Event) ? ev.pageY : ev.clientY; 
	target=window.event.srcElement;
	var xOffset = x;	// - absLeft(target) compute x offset relative to the hovered-over element
	var yOffset = y;	//  - absTop(target) compute y offset relative to the hovered-over element
	if (target.id) 	writeLog_UsaProxy("doubleclick&offset=" + xOffset + "," + yOffset + "&id=" + target.id + "&type=" + target.type + generateEventString_UsaProxy(target) );
	else {
		// if element has a name attribute
		if(target.name) writeLog_UsaProxy("doubleclick&offset=" + xOffset + "," + yOffset + "&name=" + target.name + "&type=" + target.type + generateEventString_UsaProxy(target));
		else {
			
			writeLog_UsaProxy("doubleclick&offset=" + xOffset + "," + yOffset + generateEventString_UsaProxy(target));
			
		}
	}
}
function processMousedown_UsaProxy(e) {

try
{

	/* check if text was selected, if true, discontinue, 
	   since this is handled by processSelection_UsaProxy */
// alert('in mouse down');	
	if(processSelection_UsaProxy()) return;
	
	/* get event target, x, and y value of mouse position
	 * NS: first case (window.Event available); IE: second case */
	var ev 		= (window.Event) ? e : window.event;
	var target 	= (window.Event) ? ev.target : ev.srcElement;
	var x 		= (window.Event) ? ev.pageX : ev.clientX;
	var y 		= (window.Event) ? ev.pageY : ev.clientY; 
	//target=window.event.srcElement;
	//alert(target);
	var xOffset = x;	// - absLeft(target) compute x offset relative to the hovered-over element
	var yOffset = y;	//  - absTop(target) compute y offset relative to the hovered-over element
	//usaTest(target);
	/** mouse button detection: was middle or right mouse button clicked ?*/
	var mbutton = "left";
	if (ev.which) {  		// NS
		switch(ev.which) {
			case 2: mbutton = "m"; break;	// middle button
			case 3: mbutton = "r"; break;	// right button
		}
	} else if (ev.button) {		// IE
		switch(ev.button) {
			case 4: mbutton = "m"; break;
			case 2: mbutton = "r"; break;
		}
	}
	// log middle and right button events, continue if left button was clicked
	if (mbutton!="left") {
		writeLog_UsaProxy("mousedown&but=" + mbutton + generateEventString_UsaProxy(target));
		//saveLog_UsaProxy();
		return;
	}
	/* end mouse button detection */
	
	// dropdown selection event is handled by function processChange_UsaProxy
	if(target.nodeName=="OPTION" || target.nodeName=="option") return; // do nothing
	if(target.nodeName=="SELECT" || target.nodeName=="select") return; // do nothing
	
	// radio button selection event is handled by function processChange_UsaProxy
	if(target.type && (target.type == "radio")) {
		return;
	}
	
	//alert(target.nodeName);
	/* if regular click, log click coordinates relative to the clicked element
	   and all available target properties */
	// if element has an id attribute
	if (target.id)
	{ 
		if(target.name)
		{
			writeLog_UsaProxy("mousedown&offset=" + xOffset + "," + yOffset + "&id=" + target.id + "&name=" + target.name + "&type=" + target.type + generateEventString_UsaProxy(target));

		}
		else
		{
			writeLog_UsaProxy("mousedown&offset=" + xOffset + "," + yOffset + "&id=" + target.id + "&type=" + target.type + generateEventString_UsaProxy(target));
		}
        }
	else {
		// if element has a name attribute
		if(target.name) writeLog_UsaProxy("mousedown&offset=" + xOffset + "," + yOffset + "&name=" + target.name + "&type=" + target.type + generateEventString_UsaProxy(target));
		else {
			
			writeLog_UsaProxy("mousedown&offset=" + xOffset + "," + yOffset + generateEventString_UsaProxy(target));
			
		}
	}
}
catch(e)
{
}
	//saveLog_UsaProxy();
}

/* no mouseup event since with regular user tracking not necessary */

/* Processes change event in select lists, input fields, textareas.
   Logs change event together with the corresponding field type, and
   a couple of field content properties such as the new field value. */
function processChange_UsaProxy(e) {
	
	/* get event target
	 * NS: first case (window.Event available); IE: second case */
	var ev 		= (window.Event) ? e : window.event;
	var target 	= (window.Event) ? ev.target : ev.srcElement;
	target=window.event.srcElement
	// check for usability demo
	//alert("testing1");
	//usaTest(target);
	// if select list, log the selected entry's value
	if (target.type=="select-multiple") {
		var value = "";
		// check which entries were selected
		for (var i = 0; i < target.options.length; i++)
			if (target.options[ i ].selected) value = value + target.options[ i ].value;
		// log entries
		if (target.id) {
			writeLog_UsaProxy("change&type=select-multiple&id=" + target.id
						+ generateEventString_UsaProxy(target) + "&value=" + value);
		} else { if (target.name)
					writeLog_UsaProxy("change&type=select-multiple&name=" + target.name
						+ generateEventString_UsaProxy(target) + "&value=" + value) ;
		}
		saveLog_UsaProxy();
	}
	
	// if dropdown menu, log the selected entry's value
	else if (target.type=="select-one") { 
		if (target.id) {
			writeLog_UsaProxy("change&type=select-one&id=" + target.id + generateEventString_UsaProxy(target) + "&value="
					+ target.options[target.selectedIndex].value + "&selected=" + target.selectedIndex);
		} else { if (target.name)
					writeLog_UsaProxy("change&type=select-one&name=" + target.name
							+ generateEventString_UsaProxy(target) + "&value=" 
							+ target.options[target.selectedIndex].value
							+ "&selected=" + target.selectedIndex);
		}
		saveLog_UsaProxy();
	}
	
	// if text field/area, file field, log changed value
	else if (target.type=="text" || target.type=="textarea" || target.type=="file") {
		if (target.id) {
			writeLog_UsaProxy("change&type=" + target.type + "&id=" + target.id
							  + generateEventString_UsaProxy(target) + "&value=" + fieldValueHas[target.id] + target.value);
			fieldValueHas[target.id]=target.value;
		} else { if (target.name)
					writeLog_UsaProxy("change&type=" + target.type + "&name="
							+ target.name + generateEventString_UsaProxy(target) + "&value=" + target.value);
		}
		//saveLog_UsaProxy();
	}
	
	// log that checkbox was checked/unchecked
	else if (target.type=="checkbox") {
		var value = "";
		// check boxes in checkbox group
		if(target.length>1) { 
			for ( i=0 ; i < target.length ; i++ ){ 
				if (target[i].checked==true)  
					value = value + "." + target[i].value;
			}
			if (value=="") value = "none";
		// single checkbox
		} else {value==target.checked}
		// log entries
		if (target.id) {
			writeLog_UsaProxy("change&type=" + target.type + "&id=" + target.id
							  + "&checked=" + target.checked + generateEventString_UsaProxy(target));
		} else { if (target.name)
					writeLog_UsaProxy("change&type=" + target.type + "&name="
							+ target.name + "&checked=" + target.checked + generateEventString_UsaProxy(target));
		}
		//saveLog_UsaProxy();
	}
	
	// in the case of a password field, log only THAT content was modified
	else if (target.type=="password") {
		if (target.id) {
			writeLog_UsaProxy("change&type=" + target.type + "&id="
							  + target.id + generateEventString_UsaProxy(target));
		} else { if (target.name)
					writeLog_UsaProxy("change&type=" + target.type + "&name="
									  + target.name + generateEventString_UsaProxy(target));
		}
		//saveLog_UsaProxy();
	}
	
	// log that radio button was clicked
	else if (target.type=="radio") {
		// log entries
		if (target.id) {
			writeLog_UsaProxy("change&type=" + target.type + "&id=" + target.id
							  + generateEventString_UsaProxy(target));
		} else { if (target.name)
					writeLog_UsaProxy("change&type=" + target.type + "&name="
							+ target.name + generateEventString_UsaProxy(target));
		}
		saveLog_UsaProxy();
	}
	
}

/* Processes scrolling of the page.
 * Function is invoked periodically since no explicit scroll event is triggered.
   The page offset is logged in the form of a percentage value relative
   to the total HTML document height/width */
function processScroll_UsaProxy() {
	
	/** since total HTML height/width may be modified through font size settings
	    it must be computed each time a scrolling is performed */
		
	var scrollHeight_UsaProxy;
	var scrollWidth_UsaProxy;
	
	if (document.documentElement && document.documentElement.scrollHeight)
		// Explorer 6 Strict
	{
		scrollHeight_UsaProxy = document.documentElement.scrollHeight;
		scrollWidth_UsaProxy = document.documentElement.scrollWidth;
	}
	else if (document.body) // all other Explorers
	{
		scrollHeight_UsaProxy 	= document.documentElement.scrollHeight;
		scrollWidth_UsaProxy 	= document.documentElement.scrollWidth;
	}

	/* get current offset */
	 
	if (self.pageYOffset) // all except Explorer
	{
		currentScrollPosX = self.pageXOffset;
		currentScrollPosY = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		currentScrollPosX = document.documentElement.scrollLeft;
		currentScrollPosY = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		currentScrollPosX = document.body.scrollLeft;
		currentScrollPosY = document.body.scrollTop;
	}

	// if vertical scrollbar was moved new scrollbar position is logged
	if(lastScrollPosY_UsaProxy != currentScrollPosY) {
	
		/** e.g. 100, 80, 6, 0 */
		var percentOfHeight = "" + Math.round(currentScrollPosY/scrollHeight_UsaProxy * 100);
		/** shift */
		if(percentOfHeight.length==0) percentOfHeight = "000";
		if(percentOfHeight.length==1) percentOfHeight = "00" + percentOfHeight;
		if(percentOfHeight.length==2) percentOfHeight = "0" + percentOfHeight;
		percentOfHeight = percentOfHeight.substring(0,1) + "." + percentOfHeight.substring(1);
	
		//writeLog_UsaProxy("scroll&y=" + percentOfHeight);
		// set last scrollbar position
		lastScrollPosY_UsaProxy = currentScrollPosY;
		//saveLog_UsaProxy();
	}
	// if horizontal scrollbar was moved new scrollbar position is logged
	if(lastScrollPosX_UsaProxy != currentScrollPosX) {
	
		var percentOfWidth = "" + Math.round(currentScrollPosX/scrollWidth_UsaProxy * 100);
		/** shift */
		if(percentOfWidth.length==0) percentOfWidth = "000";
		if(percentOfWidth.length==1) percentOfWidth = "00" + percentOfWidth;
		if(percentOfWidth.length==2) percentOfWidth = "0" + percentOfWidth;
		percentOfWidth = percentOfWidth.substring(0,1) + "." + percentOfWidth.substring(1);
	
		//writeLog_UsaProxy("scroll&x=" + percentOfWidth);
		// set last scrollbar position
		lastScrollPosX_UsaProxy = currentScrollPosX;
		//saveLog_UsaProxy();
	}
}


/* Detects key combinations: first part - key down
 * flags are set in the case that shift, ctrl, or alt is pressed
 * in case any og those flags is true, a combination is detected and logged.  */
function processKeydown_UsaProxy(e) {

	/* get keycode
	 * IE: first case (window.event available); NS: second case */
	var evtobj 				= window.event ? window.event : e;
	var KeyID 				= evtobj.which ? evtobj.which : evtobj.keyCode;
	FLG_ctrl_comb_UsaProxy 	= false;	// "ctrl key pressed" combinations flag

	switch(KeyID)
	{
		
	// if shift is pressed
		case 16:		
			FLG_comb_UsaProxy = false;			// reset combination flag
			combMembers_UsaProxy = 0;			// reset combination members
			FLG_shiftPressed_UsaProxy = true;	// set "shift key pressed" flag
			FLG_keyPress_UsaProxy = false;		// keypress-event blocked (keypress event is blocked)
			return false;
		break;
		// if ctrl is pressed
		case 17:		
			FLG_comb_UsaProxy = false;			// reset combination flag
			combMembers_UsaProxy = 0;			// reset combination members
			FLG_ctrlPressed_UsaProxy = true;	// set "ctrl key pressed" flag
			FLG_keyPress_UsaProxy = false;		// keypress-event blocked
			return false;
		break;
		// if alt is pressed
		case 18:		
			FLG_comb_UsaProxy = false;			// reset combination flag
			combMembers_UsaProxy = 0;			// reset combination members
			FLG_altPressed_UsaProxy = true;		// set "alt key pressed" flag
			FLG_keyPress_UsaProxy = false;		// keypress-event blocked
			return false;
		break;
		case 13:
		//alert("in enter");

	
	// log all available target attributes
		// if element has an id attribute
      		// var target = lastFOcusTarget.type;
		//alert(fType);

		if (fType=="id") {
				writeLog_UsaProxy("Enter&id=" + lastControlID + "&value=" + document.getElementById(lastControlID).value + "&type=" + lastControlType +generateEventString_UsaProxy(document.getElementById(lastControlID)));
				// if element has a name attribute
				} else {if (fType=="name") writeLog_UsaProxy("Enter&name=" + lastControlName + "&value=" + document.getElementsByName(lastControlName).value + "&type=" + lastControlType + generateEventString_UsaProxy(document.getElementsByName(lastControlName)));
				// all others
				else
				writeLog_UsaProxy("Enter&value=unknown");
				}
				saveLog_UsaProxy();
				return true;
				break;
	}
	
	/** the following code is only executed for the character key in a key combination */
	
	/** combination check: if shift-char combination */
	if (FLG_shiftPressed_UsaProxy) {			// if shift was already pressed: keyID holds the char which follows shift
		keyName_UsaProxy = "shift+" + String.fromCharCode(KeyID);	// Select capital
		FLG_comb_UsaProxy = true;		// set key combination flag
		combMembers_UsaProxy = 2;	// 2 keys pressed
	}
	/** combination check: if ctrl-char combination */
	if (FLG_ctrlPressed_UsaProxy) {
		switch(KeyID) {		// if ctrl was already pressed: keyID holds the char which follows ctrl
			case 65: keyName_UsaProxy = "ctrl+a"; break;	// Select Alls command
			case 66: keyName_UsaProxy = "ctrl+b"; break;	// Edit bookmarks command
			case 67: keyName_UsaProxy = "ctrl+c"; break;	// Copy command
			case 68: keyName_UsaProxy = "ctrl+d"; break;	// Add bookmark command
			case 69: keyName_UsaProxy = "ctrl+e"; break;
			case 70: keyName_UsaProxy = "ctrl+f"; break;	// Find command
			case 71: keyName_UsaProxy = "ctrl+g"; break;	// NS: find Again command
			case 72: keyName_UsaProxy = "ctrl+h"; break;	// NS: open history command
			case 73: keyName_UsaProxy = "ctrl+i"; break;	// NS: page info command
			case 74: keyName_UsaProxy = "ctrl+j"; break;	// NS: downloads box
			case 75: keyName_UsaProxy = "ctrl+k"; break;	// NS: google search bar
			case 76: keyName_UsaProxy = "ctrl+l"; break;	// IE: open command
			case 77: keyName_UsaProxy = "ctrl+m"; break;	
			case 78: keyName_UsaProxy = "ctrl+n"; break;	// IE: new window NS: new message command
			case 79: keyName_UsaProxy = "ctrl+o"; break;	// Open command
			case 80: keyName_UsaProxy = "ctrl+p"; break;	// Print command
			case 81: keyName_UsaProxy = "ctrl+q"; break;	// NS: exit command
			case 82: keyName_UsaProxy = "ctrl+r"; break;	// Reload command
			case 83: keyName_UsaProxy = "ctrl+s"; break;	// Save command
			case 84: keyName_UsaProxy = "ctrl+t"; break;	
			case 85: keyName_UsaProxy = "ctrl+u"; break;	// NS: page source command
			case 86: keyName_UsaProxy = "ctrl+v"; break;	// Paste command
			case 87: keyName_UsaProxy = "ctrl+w"; break;	// Close command
			case 88: keyName_UsaProxy = "ctrl+x"; break;	// Cut command
			case 89: keyName_UsaProxy = "ctrl+y"; break;	// Select Alls command
			case 90: keyName_UsaProxy = "ctrl+z"; break;	// Select Alls command
		}
		
		// log ctrl+key combination
		//writeLog_UsaProxy("keypress&key=" + keyName_UsaProxy);
		//saveLog_UsaProxy();
		
		keyName_UsaProxy 			= "";				// reset keyName_UsaProxy
		
		/* reset ctrl key pressed flag already at keydown since NS doesn't
		 * trigger any keyup event in case of e.g. ctrl-f */
		FLG_ctrlPressed_UsaProxy 	= false;
		FLG_ctrl_comb_UsaProxy		= true;		/* set additional flag true to be able to
												 * determine a ctrl+key below although FLG_ctrlPressed_UsaProxy
												 * was already set false above */
		
		/* unlock handling of regular key presses:
		 * enable processKeyUp_UsaProxy functionality */
		FLG_keyPress_UsaProxy 		= true;
		
		FLG_comb_UsaProxy 			= true;			// set key combination flag
		combMembers_UsaProxy 		= 2;			// 2 keys pressed
	}
	
	/* NS: in case a combination (ctrl+key) was requested before
	 * which triggered a platform action (such as focus on Firefox find box)
	 * the keyup event won't be triggered. Therefore a reset of a possible
	 * combination must be performed on keydown
	 * since FLG_ctrlPressed_UsaProxy is set false above in the
	 * "if (FLG_ctrlPressed_UsaProxy)" block the additional variable
	 * FLG_ctrl_comb_UsaProxy is used */
	if(!FLG_ctrl_comb_UsaProxy && !FLG_shiftPressed_UsaProxy && !FLG_altPressed_UsaProxy) {
		FLG_comb_UsaProxy 			= false;			// reset key combination flag
		combMembers_UsaProxy 		= 0;
	}
	
}

/* Processes the release of key combinations: second part - key up/released
 * flags are reset in case shift, ctrl, or alt is released
 * in case any flag is true a combination is detected and logged  */
function processKeyup_UsaProxy(e) {

	/* get keycode
	* IE: first case (window.event available); NS: second case */
	var evtobj 	= window.event ? window.event : e;
	var KeyID 	= evtobj.which ? evtobj.which : evtobj.keyCode;
	//alert(KeyID);
	// control key check
	switch(KeyID)
	{	
		// if shift is released
	
		case 16:
			// in case combination was pressed
			if(FLG_comb_UsaProxy==true) {
				/* if shift key is the first key of the combination which is released
				 * decrease number of remaining combination members */
				if (combMembers_UsaProxy==2) combMembers_UsaProxy=1;
				/* if shift is last released key of the combination */
				else {	
					FLG_comb_UsaProxy 			= false;	// reset key combination
					//writeLog_UsaProxy("keypress&key=" + keyName_UsaProxy);	// log key combination
					//alert(keyName_UsaProxy);
					if (keyName_UsaProxy=='shift+V')
					{
						window.open(clickOnSaveURL + lastLoggedEvent ,'','location=no,menubar=no,width=385,height=300,top=300,left=300,resizable=yes,scrollbars=no,status=no,toolbar=no');
					}
					if (keyName_UsaProxy=='shift+G')
					{
						window.open(clickOnShowURL + lastLoggedEvent ,'','location=no,menubar=no,width=385,height=300,top=300,left=300,resizable=yes,scrollbars=no,status=no,toolbar=no');
					}
					keyName_UsaProxy 			= "";		// reset key name
					FLG_shiftPressed_UsaProxy 	= false;	// reset shift pressed flag
					FLG_keyPress_UsaProxy 		= true;		// re-enable keypress event processing
				}
				return false;
			// if shift was pressed without combining it with another key
			} else {
				keyName_UsaProxy 			= "shift";		// set key name	
				FLG_shiftPressed_UsaProxy 	= false;		// reset shift pressed flag
				FLG_keyPress_UsaProxy 		= true;			// re-enable keypress event processing
			}
		break;
		/* if ctrl is released and no key combination was pressed (single ctrl press)
		 * since all combination reset actions were already performed on keydown
		 * no key combination resetting neccessary at this point */
		case 17:
			if(FLG_comb_UsaProxy==false && FLG_ctrlPressed_UsaProxy) {
				keyName_UsaProxy 			= "ctrl";		// set key name
				FLG_ctrlPressed_UsaProxy 	= false;		// reset ctrl pressed flag
				FLG_keyPress_UsaProxy 		= true;			// re-enable keypress event processing
			} 
		break;
		// if alt is released
		case 18:
			if(FLG_comb_UsaProxy==true) {
				/* if alt key is the first key of the combination which is released
				 * decrease number of remaining combination members */
				if (combMembers_UsaProxy==2) combMembers_UsaProxy=1;
				else {	
					FLG_comb_UsaProxy 		= false;		// reset key combination
					//writeLog_UsaProxy("keypress&key=" + keyName_UsaProxy);
					keyName_UsaProxy 		= "";			// reset key name
					FLG_altPressed_UsaProxy = false;		// reset alt pressed flag
					FLG_keyPress_UsaProxy 	= true;			// re-enable keypress event processing
				}
				return false;
			// if alt was pressed without combining it with another key
			} else {
				keyName_UsaProxy 			= "alt";		// set key name
				FLG_altPressed_UsaProxy 	= false;		// reset alt pressed flag
				FLG_keyPress_UsaProxy 		= true;			// re-enable keypress event processing
			}
		break;


		// set key name in case of other control keys
		case 8: keyName_UsaProxy = "backspace"; break;			// set key name
		case 13: keyName_UsaProxy = "enter"; break;			// set key name
		case 19: keyName_UsaProxy = "pause"; break;			// set key name
		case 37: keyName_UsaProxy = "arrowleft"; break;		// set key name
		case 38: keyName_UsaProxy = "arrowup"; break;		// set key name
		case 39: keyName_UsaProxy = "arrowright"; break;	// set key name
		case 40: keyName_UsaProxy = "arrowdown"; break; 	// set key name
		case 46: keyName_UsaProxy = "del"; break; 			// set key name
	}
	
	/* if combination is released (except ctrl+key since all flags
	 * are released on keydown)
	 * if first key of combination, decrease number of combination members
	 * else, reset combination flag */
	if(FLG_comb_UsaProxy) {
		if (combMembers_UsaProxy==2) combMembers_UsaProxy=1;
		else	FLG_comb_UsaProxy = false;
	}

	/* log a single key press or a key combination
	 * single press or end of key combination (last member to be released)
	 * is true if flag FLG_comb_UsaProxy is false and
	 * also the additional ctrl+key combination indicator (since
	 * resetting of all ctrl+key combination (except FLG_ctrl_comb_UsaProxy)
	 * flags occurs on keydown) */
	if(FLG_comb_UsaProxy==false && !FLG_ctrl_comb_UsaProxy && keyName_UsaProxy.length!=0) {
		//writeLog_UsaProxy("keypress&key=" + keyName_UsaProxy);
		//saveLog_UsaProxy();
		keyName_UsaProxy = "";
	}
}

/* Logs all regular single key presses. are logged
 * If keyPress flag is enabled (in case no control key is clicked at the same time)
 * the keyPress event returns for regular char keys the correct small case key code. */
function processKeypress_UsaProxy(e) {
	if(FLG_keyPress_UsaProxy) {
		/* get keycode
		 * IE: first case (window.event available); NS: second case */
		var evtobj 	= window.event ? window.event : e;
		var KeyID 	= evtobj.which ? evtobj.which : evtobj.keyCode;
		keyName_UsaProxy = String.fromCharCode(KeyID);
		
		if(FLG_comb_UsaProxy==false && !FLG_ctrl_comb_UsaProxy) {
			//writeLog_UsaProxy("keypress&key=" + keyName_UsaProxy);
			//saveLog_UsaProxy();
			keyName_UsaProxy = "";
		}
	}
}

/* Processes blur event */
function processBlur_UsaProxy(e) {
try
{
	/* get event target
	 * NS: first case (window.Event available); IE: second case */
	var ev 		= (window.Event) ? e : window.event;
	var target 	= (window.Event) ? ev.target : ev.srcElement;
	target=window.event.srcElement;
	//usaTest(target);

	// log all available target attributes
	// if element has an id attribute
	if (target.id)
	{ 
		if(target.name)
		{
			writeLog_UsaProxy("blur&id=" + target.id + "&name=" + target.name + "&value=" + target.value +"&type=" + target.type + generateEventString_UsaProxy(target));

		}
		else
		{
			writeLog_UsaProxy("blur&id="  + target.id + "&value=" + target.value +"&type=" + target.type + generateEventString_UsaProxy(target) );
		}
        } 
	else {if (target.name) writeLog_UsaProxy("blur&name=" + target.name + "&value=" + target.value + "&type=" + target.type + generateEventString_UsaProxy(target));
			// all others
			else
				writeLog_UsaProxy("blur" + generateEventString_UsaProxy(target));
	}
	//saveLog_UsaProxy();
}
catch(e)
{
}
}

/* Processes focus event */
function processFocus_UsaProxy(e) {

try
{

	/* get event target
	 * NS: first case (window.Event available); IE: second case */
	var ev 		= (window.Event) ? e : window.event;
	var target 	= (window.Event) ? ev.target : ev.srcElement;
//	target=window.event.srcElement;
	// usaTest(target);
	//lastFOcusTarget=target;
 lastControlType=target.type;	


//alert(lastFOcusTarget.type);
	// log all available target attributes
	// if element has an id attribute
	if (target.id) { 
	 fType="id";
        lastControlID=target.id;

	if(target.name)
	{
	writeLog_UsaProxy("focus&id=" + target.id + "&name=" + target.name + "&type=" + target.type + generateEventString_UsaProxy(target));

	}
	else
	{
	writeLog_UsaProxy("focus&id="  + target.id + "&type=" + target.type + generateEventString_UsaProxy(target) );
	}
        } else { if (target.name)
{
fType="name";
lastControlName = target.name;
 writeLog_UsaProxy("focus&name=" + target.name + "&value=" + target.value+"&type=" + target.type + generateEventString_UsaProxy(target));
		}	
// all others
			else
{
fType="none";
}
				
writeLog_UsaProxy("focus" + generateEventString_UsaProxy(target));
	}
	//saveLog_UsaProxy();
}
catch(e)
{
}
}

/* Processes the selection of text within the web page's content.
 * Function is invoked on  */
function processSelection_UsaProxy() {
		var currentSelection;
		// NS
		if (window.getSelection) currentSelection = window.getSelection();
		// safari, konqueror
		else if (document.getSelection) currentSelection = document.getSelection();
		// IE
		else if (document.selection) currentSelection = document.selection.createRange().text;
		
		// if selection is not empty and new text was selected, log select event
		if(currentSelection != "" && lastSelection_UsaProxy != currentSelection) {
			writeLog_UsaProxy("select&text=" + currentSelection);
			// set last selected text
			lastSelection_UsaProxy = currentSelection;
			saveLog_UsaProxy();
			return true;
		}
		return false;
}

/* NS: Processes text selection event in textfields/areas.
 * Since NS doesn't capture any selected text in text fields/areas over getSelection,
 * function is invoked on select */
function processSelectionNS_UsaProxy(e) {

	/* get event target
	 * NS: first case (window.Event available); IE: second case (not necessary) */
	var ev 		= (window.Event) ? e : window.event;
	var target 	= (window.Event) ? ev.target : ev.srcElement;
	
	// if selection is not empty, log select event with the selected text
	if (target.selectionStart!=target.selectionEnd) {
		writeLog_UsaProxy("select" + generateEventString_UsaProxy(target) + "&text=" + target.value.substring(target.selectionStart,target.selectionEnd));
		saveLog_UsaProxy();
	}
}

/** end events logging */

/* Returns the DOM path of the specified DOM node beginning with the first
 * corresponding child node of the document node (i.e. HTML) */
function getDOMPath(node /*DOM element*/) {
	/* if nodeType==9 same as nodetype==Node.DOCUMENT_NODE, IE doesn't speak constants */
	
	if(node.parentNode.nodeType==9) return getDOMIndex(node);
	else return getDOMPath(node.parentNode) + getDOMIndex(node);
	
	
}

/** Returns the position of the specified node 
    in its parent node's childNodes array */
function getDOMIndex(node /*DOM element*/) {
	
	var parent = node.parentNode;
	var children = parent.childNodes;
	var length = children.length;
	var position = 0;
	for (var i = 0; i < length; i++) {
		/* if nodeType==1 same as nodetype==Node.ELEMENT_NODE, IE doesn't speak constants */
		if (children[i].nodeType==1) { // count only element nodes
			position += 1;
			if (children[i] == node) return mapToAlph(position);
		} 
	}
	
}

/* Optional: returns a hex representation of DOM path
 * e.g. having a path of <HTML><BODY><FORM><P>1st<INPUT>
 * results in 2h2h1h1h1h
 * e.g. having a path of <HTML><BODY><FORM><P>34th<INPUT>
 * results in 2h2h1h1h22h
 * with an "h" as hex suffix */
function mapToHex(position /*number*/) {
	return (position.toString(16) + "h");
}

/* Returns an alphabetic representation of the DOM path
 * e.g. having a path of <HTML><BODY><FORM><P>1st<INPUT>
 * results in bbaaa
 * e.g. having a path of <HTML><BODY><FORM><P>34th<INPUT>
 * results in bbaa1h
 * with an optional number as prefix which indicates the extent
 * to which the position exceeds the number of characters available
 * e.g. a position of 54 is represented by 2b (= 2x26 + b)*/
//alert("before alphaarray");
var alphArray = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
                 //alert("after alphaarray");
                 function mapToAlph(position /*number*/) {
	var amountAlphs = 0;
	var alphRemain = "";
	if(position>alphArray.length) { // if position > available indexes
		amountAlphs = Math.floor(position/alphArray.length);
		alphRemain = alphArray[(position % alphArray.length)-1];
	} 
	if(amountAlphs>0) return (amountAlphs + alphRemain);
	return (alphArray[position-1]);
}

/* Computes the element's offset from the left edge
   of the browser window */
function absLeft(element) {
	if (element.pageX) return element.pageX;
	else
    	return (element.offsetParent)? 
     	element.offsetLeft + absLeft(element.offsetParent) : element.offsetLeft;
  }

/* Computes the element's offset from the top edge
   of the browser window */
function absTop(element) {
  	if (element.pageY) return element.pageY;
	else
     	return (element.offsetParent)? 
     	element.offsetTop + absTop(element.offsetParent) : element.offsetTop;
}
/* saves the HTML source to file*/
function saveHTML()
{




//	alert(document.documentElement.outerHTML.length);
	//var xhr = new XMLHttpRequest(); 
	//xhr.open("POST", side_URL + "/usaproxylolo/logHTML?sid=" + sessionID_UsaProxy); 
	//xhr.setRequestHeader("Content-Length",document.documentElement.outerHTML.length+5); 	
	//  alert(document.documentElement.outerHTML);
	//xhr.send(document.documentElement.outerHTML);
	   
	   /*var head = document.getElementsByTagName("head")[0];
		var script = document.createElement("script");
		script.src = side_URL + "/usaproxylolo/log?" + logVal_UsaProxy ;
		//script.src = "/usaproxylolo/log?" + logVal_UsaProxy ;
		head.appendChild(script);
		logVal_UsaProxy = ""; // reset log data
		head.removeChild(script);*/
	
	//var iCallID = document.body.toOracle.callService(myCallBackFunction,"SaveHTML",document.documentElement.outerHTML,serverdataId_UsaProxy);
	var origHTML= document.documentElement.outerHTML
// .substring(2875,2900);
	//alert(origHTML);
	//alert(origHTML);
	while (origHTML.indexOf("<")>=0)
	{
	var newHTML1=origHTML.replace("<","{{{");
	origHTML=newHTML1;
	//alert(origHTML);

	}

	while (origHTML.indexOf(">")>=0)
	{
	var newHTML1=origHTML.replace(">","}}}");
	origHTML=newHTML1;
	//alert(origHTML);

	}

	while (origHTML.indexOf("&")>=0)
	{
	var newHTML1=origHTML.replace("&","**$**");
	origHTML=newHTML1;
	//alert(origHTML);

	}
	
	var iCallID = document.body.toOracle.callService(myCallBackFunction,"SaveHTML",serverdataId_UsaProxy,origHTML); 

	}

function myCallBackFunction(res) {
	if (!res.error) {
//alert('ok');
		
	}else{
		//alert(res.errorDetail.string);
	}
}

//calculate the current window width //
function pageWidth() {
  return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

// calculate the current window height //
function pageHeight() {
  return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

// calculate the current window vertical offset //
function topPosition() {
  return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

// calculate the position starting at the left of the window //
function leftPosition() {
  return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}
//build/show the dialog box, populate the data and call the fadeDialog function //
function showDialog(title,message,type,autohide) {
	//alert("start");
	  if(!type) {
	    type = 'error';
	  }
	  var dialog;
	  var dialogheader;
	  var dialogclose;
	  var dialogtitle;
	  var dialogcontent;
	  var dialogmask;
	  
	  if(!document.getElementById('dialog')) {
		//  alert(" in if");
		    dialog = document.createElement('div');
		    dialog.id = 'dialog';
		    dialogheader = document.createElement('div');
		    dialogheader.id = 'dialog-header';
		    dialogtitle = document.createElement('div');
		    dialogtitle.id = 'dialog-title';
		    dialogclose = document.createElement('div');
		    dialogclose.id = 'dialog-close'
		    dialogcontent = document.createElement('div');
		    dialogcontent.id = 'dialog-content';
		    dialogmask = document.createElement('div');
		    dialogmask.id = 'dialog-mask';
		    document.body.appendChild(dialogmask);
		    document.body.appendChild(dialog);
		    dialog.appendChild(dialogheader);
		    dialogheader.appendChild(dialogtitle);
		    dialogheader.appendChild(dialogclose);
		    dialog.appendChild(dialogcontent);;
		    dialogclose.setAttribute('onclick','hideDialog()');
		    dialogclose.onclick = hideDialog;
		  } else {
		//	  alert(" in else");
		    dialog = document.getElementById('dialog');
		    dialogheader = document.getElementById('dialog-header');
		    dialogtitle = document.getElementById('dialog-title');
		    dialogclose = document.getElementById('dialog-close');
		    dialogcontent = document.getElementById('dialog-content');
		    dialogmask = document.getElementById('dialog-mask');
		    dialogmask.style.visibility = "visible";
		    dialog.style.visibility = "visible";
		  }
	 // alert("first style");
	  dialog.style.opacity = .00;
	  dialog.style.filter = 'alpha(opacity=0)';
	  dialog.alpha = 0;

	  var width = pageWidth();
	  var height = pageHeight();
	  var left = leftPosition();
	  var top = topPosition();

	  var dialogwidth = dialog.offsetWidth;
	  var dialogheight = dialog.offsetHeight;
	  var topposition = top + (height / 3) - (dialogheight / 2);
	  var leftposition = left + (width / 2) - (dialogwidth / 2);
	 // alert("dialog style");
	  dialog.style.top = topposition + "px";
	  dialog.style.left = leftposition + "px";
	  dialog.style.position = "absolute";
	  dialog.style.width = "425px";
	  dialog.style.padding = "10px";
	  dialog.style.zIndex = 200;
	 // dialogheader.className = type + "header";
	  dialog.style.background="#fff";
	  
	 // alert("dialog header style");
	  dialogheader.style.display = "block";
	  dialogheader.style.position = "relative";
	  dialogheader.style.width = "405px";
	  dialogheader.style.padding = "3px 6px 7px";
	  dialogheader.style.height = "14px";
	  dialogheader.style.fontSize = "14px";
	  dialogheader.style.fontWeight = "bold";
	  
	  //dialogheader.className = type + "header";
	  dialogtitle.innerHTML = title;
	  
	  dialogheader.style.float = "left";
	  //dialogcontent.className = type;
	  //alert("dialog content style");
	  dialogcontent.style.display = "block";
	  dialogcontent.style.height = "160px";
	  dialogcontent.style.padding = "6px";
	  dialogcontent.style.color = "#666666";
	  dialogcontent.style.fontSize = "13px";
	  dialogcontent.innerHTML = message;
	 // alert("after content style");
	 // var content = document.getElementById(WRAPPER);
	  //alert("after get element");
	  //content.style.padding = "20px";
	 // alert("dialog mask style");
	  dialogmask.style.height = "100px";
	  dialogmask.style.position = "absolute";
	  dialogmask.style.top = 0;
	  dialogmask.style.left = 0;
	  dialogmask.style.minHeight = "100%";
	  dialogmask.style.width = "100%";
	  dialogmask.style.background = "#FFF";
	  dialogmask.style.opacity = .75;
	  dialogmask.style.filter = "alpha(opacity=75)";
	  dialogmask.style.zIndex = 100;
	 dialogclose.style.styleFloat = "right";
	  dialogclose.style.cursor = "pointer";
	  dialogclose.style.margin = "-10px 0px 0 0";
	  dialogclose.style.height = "11px";
	  dialogclose.style.width = "11px";
	  dialogclose.style.padding = "6px";
	  dialogclose.style.background = "url(/usaproxylolo/file/images/dialog_close.gif) no-repeat";
	  dialog.timer = setInterval("fadeDialog(1)", TIMER);
	  switch(type)
	  {
	  case 'error':
		  dialogcontent.style.background = "#fff url(/usaproxylolo/file/images/error_bg.jpg) bottom right no-repeat"; 
		  dialogcontent.style.border = "1px solid #924949";
		  dialogcontent.style.borderTop = "none";
		  dialogheader.style.background = "url(/usaproxylolo/file/images/error_header.gif) repeat-x";
		  dialogheader.style.color = "#6f2c2c";
		  dialogheader.style.border = "1px solid #924949";
		  dialogheader.style.borderBottom = "none";
		  break;
	  case 'warning':
		  dialogcontent.style.background = "#fff url(/usaproxylolo/file/images/warning_bg.jpg) bottom right no-repeat"; 
		  dialogcontent.style.border = "1px solid #c5a524";
		  dialogcontent.style.borderTop = "none";
		  dialogheader.style.background = "url(/usaproxylolo/file/images/warning_header.gif) repeat-x";
		  dialogheader.style.color = "#957c17";
		  dialogheader.style.border = "1px solid #c5a524";
		  dialogheader.style.borderBottom = "none";
		  break;
	  case 'success':
		  dialogcontent.style.background = "#fff url(/usaproxylolo/file/images/success_bg.jpg) bottom right no-repeat"; 
		  dialogcontent.style.border = "1px solid #60a174";
		  dialogcontent.style.borderTop = "none";
		  dialogheader.style.background = "url(/usaproxylolo/file/images/success_header.gif) repeat-x";
		  dialogheader.style.color = "#3c7f51";
		  dialogheader.style.border = "1px solid #60a174";
		  dialogheader.style.borderBottom = "none";
		  break;
	  case 'prompt':
		  dialogcontent.style.background = "#fff url(/usaproxylolo/file/images/prompt_bg.jpg) bottom right no-repeat"; 
		  dialogcontent.style.border = "1px solid #4f6d81";
		  dialogcontent.style.borderTop = "none";
		  dialogheader.style.background = "url(/usaproxylolo/file/images/prompt_header.gif) repeat-x";
		  dialogheader.style.color = "#355468";
		  dialogheader.style.border = "1px solid #4f6d81";
		  dialogheader.style.borderBottom = "none";
		  break;

	  }

	  
	 /* if(autohide) {
		
	    dialogclose.style.visibility = "hidden";
	    window.setTimeout("hideDialog()", (autohide * 1000));
	  } else {*/
		 
	    dialogclose.style.visibility = "visible";
	  //}*/
	//  alert("end");

}






	// hide the dialog box //
	function hideDialog() {
	  var dialog = document.getElementById('dialog');
	  clearInterval(dialog.timer);
	  dialog.timer = setInterval("fadeDialog(0)", TIMER);
	}

	// fade-in the dialog box //
	function fadeDialog(flag) {
	  if(flag == null) {
	    flag = 1;
	  }
	  var dialog = document.getElementById('dialog');
	  var value;
	  if(flag == 1) {
	    value = dialog.alpha + SPEED;
	  } else {
	    value = dialog.alpha - SPEED;
	  }
	  dialog.alpha = value;
	  dialog.style.opacity = (value / 100);
	  dialog.style.filter = 'alpha(opacity=' + value + ')';
	  if(value >= 99) {
	    clearInterval(dialog.timer);
	    dialog.timer = null;
	  } else if(value <= 1) {
	    dialog.style.visibility = "hidden";
	    document.getElementById('dialog-mask').style.visibility = "hidden";
	    clearInterval(dialog.timer);
	  }
	}

	/* Usability function
	 * 
	 */
	 	function usaTest(target) { /* Rule 0 - myListTest*/ if (target.name == 'txtFromList') {VAR_G1_I2 = 1;  } else {VAR_G1_I2 = 0;  }if ( VAR_G1_I2 == 1 ){VAR_G1_I2 = -1 ;  /*showDialog('my test','abcdefg','success',2);*/}/* end of Rule 0 - myListTest*//* Rule 1 - testC*/if ( VAR_G2_I4 == 1 ){VAR_G2_I4 = -1 ;  showDialog('--','--','success',2);}/* end of Rule 1 - testC*/// end of usability function 
	}
/* enable/disable remote monitoring on page
 * 
 */
	window.onerror = function(msg, url, line)
	{
		//alert('in error');
		var editdString=msg;
		editdString.replace("%20","");
		writeLog_UsaProxy("error&msg=" + editdString + "&url=" + url + "&line=" + line);
		saveLog_UsaProxy()
	  return false;
	}

/* random string function
	 * 
	 */
function randomPassword(length)
{
  chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  pass = "";
  for(x=0;x<length;x++)
  {
    i = Math.floor(Math.random() * 62);
    pass += chars.charAt(i);
  }
  return pass;
}

/* get Response function
	  
*/

function so_getHTTPHeaders()

 {
	if(!document.getElementById)return;


	if(window.XMLHttpRequest)

	 {

		conn = new XMLHttpRequest();

       	 } 
	
         else if(window.ActiveXObject)
	
         {
	
        	conn = new ActiveXObject("Msxml2.XMLHTTP");
	
         } 

   	 else

	 {
	
        	return ;//alert("Unsupported browser.");
	
 }
	

	conn.onreadystatechange=function()
        {
	
        	if (conn.readyState==4)
	
        	 {
	
                   var responseString= ""
;
         	   responseString = conn.getAllResponseHeaders();
		
   //alert(responseString);
        	
   var stringToCheck='';

         	   for (var i in responseArray)
	           {
	              stringToCheck = i + ": " + responseArray[i];
                      //alert(stringToCheck);
	              if (stringToCheck.length > 2)
	              {
	                if (responseString.indexOf(stringToCheck)>0)
	                {
                           // alert("is match");         
                            matchedString = "@@" + matchedString + stringToCheck;
	                }
	              }
	            
                   }

		}

	}
	
        conn.open("HEAD", location.href ,true);
	
        conn.send(null);

 }

/* jsHandler.js */
function inc(filename)
{
var body = document.getElementsByTagName('body').item(0);
script = document.createElement('script');
script.src = filename;
script.type = 'text/javascript';
body.appendChild(script)
}


var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";

		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
//alert('before detect');
BrowserDetect.init();
//alert('after detect');
function StateChange()
     {
      if(document.body.readyState=="complete")
      {
	
       	 var t = document.body.useService("http://localhost/ejitDataServices/toOracle.asmx?WSDL","toOracle");
	//alert(t);
	saveHTML();
   
      }
        
     }
function EndRequestHandler(sender, args) {
   
       saveHTML();
}