// DHTMLapi.js custom API for cross-platform
// object positioning by Danny Goodman (http://www.dannyg.com).
// Release 2.0. Supports NN4, IE, and W3C DOMs.

// Global variables
var isCSS, isW3C, isIE4, isNN4, isIE6CSS;
// Initialize upon load to let all browsers establish content objects
function initDHTMLAPI() {
    if (document.images) {
        isCSS = (document.body && document.body.style) ? true : false;
        isW3C = (isCSS && document.getElementById) ? true : false;
        isIE4 = (isCSS && document.all) ? true : false;
        isNN4 = (document.layers) ? true : false;
        isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
    }
}

// Seek nested NN4 layer from string name
function seekLayer(doc, name) {
    var theObj;
    for (var i = 0; i < doc.layers.length; i++) {
        if (doc.layers[i].name == name) {
            theObj = doc.layers[i];
            break;
        }
        // dive into nested layers if necessary
        if (doc.layers[i].document.layers.length > 0) {
            theObj = seekLayer(document.layers[i].document, name);
        }
    }
    return theObj;
}

// Convert object name string or object reference
// into a valid element object reference
function getRawObject(obj) {
    var theObj;
    if (typeof obj == "string") {
        if (isW3C) {
            theObj = document.getElementById(obj);
        } else if (isIE4) {
            theObj = document.all(obj);
        } else if (isNN4) {
            theObj = seekLayer(document, obj);
        }
    } else {
        // pass through object reference
        theObj = obj;
    }
    return theObj;
}

// Convert object name string or object reference
// into a valid style (or NN4 layer) reference
function getObject(obj) {
    var theObj = getRawObject(obj);
    if (theObj && isCSS) {
        theObj = theObj.style;
    }
    return theObj;
}

// Position an object at a specific pixel coordinate
function shiftTo(obj, x, y) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isCSS) {
            // equalize incorrect numeric value type
            var units = (typeof theObj.left == "string") ? "px" : 0 
            theObj.left = x + units;
            theObj.top = y + units;
        } else if (isNN4) {
            theObj.moveTo(x,y)
        }
        theObj.style.left = x + "px";
        theObj.style.top = y + "px";
    }
}

// Move an object by x and/or y pixels
function shiftBy(obj, deltaX, deltaY) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isCSS) {
            // equalize incorrect numeric value type
            var units = (typeof theObj.left == "string") ? "px" : 0 
            theObj.left = getObjectLeft(obj) + deltaX + units;
            theObj.top = getObjectTop(obj) + deltaY + units;
        } else if (isNN4) {
            theObj.moveBy(deltaX, deltaY);
        }
    }
}

// Set the z-order of an object
function setZIndex(obj, zOrder) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.zIndex = zOrder;
    }
}

// Set the background color of an object
function setBGColor(obj, color) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isNN4) {
            theObj.bgColor = color;
        } else if (isCSS) {
            theObj.backgroundColor = color;
        }
    }
}

// Set the visibility of an object to visible
function show(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "visible";
    }
}

// Set the visibility of an object to hidden
function hide(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "hidden";
    }
}

// Retrieve the x coordinate of a positionable object
function getObjectLeft(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (document.defaultView) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("left");
    } else if (elem.currentStyle) {
        result = elem.currentStyle.left;
    } else if (elem.style) {
        result = elem.style.left;
    } else if (isNN4) {
        result = elem.left;
    }
    return parseInt(result);
}

// Retrieve the y coordinate of a positionable object
function getObjectTop(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (document.defaultView) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("top");
    } else if (elem.currentStyle) {
        result = elem.currentStyle.top;
    } else if (elem.style) {
        result = elem.style.top;
    } else if (isNN4) {
        result = elem.top;
    }
    return parseInt(result);
}

// Retrieve the rendered width of an element
function getObjectWidth(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (elem.offsetWidth) {
        result = elem.offsetWidth;
    } else if (elem.clip && elem.clip.width) {
        result = elem.clip.width;
    } else if (elem.style && elem.style.pixelWidth) {
        result = elem.style.pixelWidth;
    }
    return parseInt(result);
}

// Retrieve the rendered height of an element
function getObjectHeight(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (elem.offsetHeight) {
        result = elem.offsetHeight;
    } else if (elem.clip && elem.clip.height) {
        result = elem.clip.height;
    } else if (elem.style && elem.style.pixelHeight) {
        result = elem.style.pixelHeight;
    }
    return parseInt(result);
}

// Return the available content width space in browser window
function getInsideWindowWidth() {
    if (window.innerWidth) {
        return window.innerWidth;
    } else if (isIE6CSS) {
        // measure the html element's clientWidth
        return document.body.parentElement.clientWidth
    } else if (document.body && document.body.clientWidth) {
        return document.body.clientWidth;
    }
    return 0;
}

// Return the available content height space in browser window
function getInsideWindowHeight() {
    if (window.innerHeight) {
        return window.innerHeight;
    } else if (isIE6CSS) {
        // measure the html element's clientHeight
        return document.body.parentElement.clientHeight;
    } else if (document.body && document.body.clientHeight) {
        return document.body.clientHeight;
    }
    return 0;
}

function centerOnPage(oObject) {
    var iLeft;
    var iTop;

    iLeft = (getInsideWindowWidth()-getObjectWidth(oObject))/2;
    iTop = (getInsideWindowHeight()-getObjectHeight(oObject))/2;
    oObject.style.left = iLeft + "px";
    oObject.style.top = iTop + "px";
}

function stopEvent() {
    return false;
}

function RemoveFromArray(aArray, iPosition) { 
//Removes a specific element from an array.
    var iLoop;
    for(iLoop=iPosition;iLoop<aArray.length-1;iLoop++) {
        aArray[iLoop] = aArray[iLoop+1];
    }
    aArray.length -=1;
    return aArray;
}

function MoveArrayElement(aArray,iFrom, iTo) {

    var oHolder;
    var iLoop;
    
    oHolder = aArray[iFrom];
    
    if(iFrom < iTo) {
        for(iLoop=iFrom; iLoop < iTo; iLoop++) {
            aArray[iLoop] = aArray[iLoop+1];
        }
        aArray[iTo] = oHolder;
    } else if(iFrom > iTo) {
        for(iLoop=iFrom; iLoop > iTo; iLoop--) {
            aArray[iLoop] = aArray[iLoop-1];
        }
        aArray[iTo] = oHolder;
    }
}

function SetControlEnabled(oObject, blnIsEnabled, strDisabledText) {

    var strClass = "";
    var strType = oObject.tagName;
    
    strClass = oObject.className;
    
    if(blnIsEnabled) {
        oObject.disabled = false;

        if(strDisabledText && oObject.value == strDisabledText) {
            oObject.value = "";
        }

    } else {
        oObject.disabled = true;
        if(strDisabledText) {
            oObject.value = strDisabledText;
        }
    }            
}

function overlaps(r1, r2) {
var xLeft = (r1[0] >= r2[0] && r1[0] <= (r2[0] + r2[2]));
var xRight = ((r1[0] + r1[2]) >= r2[0] && (r1[0] + r1[2]) <= r2[0] + r2[2]);
var xComplete = ((r1[0] < r2[0]) && ((r1[0] + r1[3]) > (r2[0] + r2[3])));

var yLeft = (r1[1] >= r2[1] && r1[1] <= (r2[1] + r2[3]));
var yRight = ((r1[1] + r1[3]) >= r2[1] && (r1[1] + r1[3]) <= r2[1] + r2[3]);
var yComplete = ((r1[1] < r2[1]) && ((r1[1] + r1[3]) > (r2[1] + r2[3])));
if ((xLeft || xRight || xComplete) && (yLeft || yRight || yComplete)) {
    return true;
}

return false;
}

function getBounds(element) {
    var iX = getObjectLeft(element, true);
    var iY = getObjectTop(element, true);
    return new Array(iX, iY, element.offsetWidth || 0, element.offsetHeight || 0);
}

function getScrollOffset(element, recursive) {
    var left = element.scrollLeft;
    var top = element.scrollTop;
    if (recursive) {
        var parent = element.parentNode;
        while (parent != null && parent.scrollLeft != null) {
            left += parent.scrollLeft;
            top += parent.scrollTop;
            // Don't include anything below the body.
            if (parent == document.body && (left != 0 && top != 0))
                break;
            parent = parent.parentNode;
        }
    }
    return new Array(left, top);
}
function EncodeText(strText) {

    var strText2 = "";
    
    if(strText == null) {
        strText = "";
    }
    strText2 = "";
    
    strText = strText.replaceAll("&","&amp;");

    while(strText2 != strText) { 
        strText2 = strText;
        strText = strText.replace("<","&lt;");
        strText = strText.replace(">","&gt;");
        strText = strText.replace("\"","&quot;");
        strText = strText.replace("'", "&apos;");
    }
    return strText;
}

// This is the failed callback function.
function OnWebServiceTimeOut(error)//, userContext, methodName)
{
    alert("OnActvityWebServiceTimeOut=");
    var stackTrace = error.get_stackTrace();

    var message = error.get_message();

    var statusCode = error.get_statusCode();

    var exceptionType = error.get_exceptionType();

    var timedout = error.get_timedOut();

    // Display the error.    
   // var RsltElem =   document.getElementById("Results");
    //RsltElem.innerHTML = 
    //userContext + "\n" +  methodName + "\n" +
    alert(  "Stack Trace: " +  stackTrace + "<br/>" +
        "Service Error: " + message + "<br/>" +
        "Status Code: " + statusCode + "<br/>" +
        "Exception Type: " + exceptionType + "<br/>" +
        "Timedout: " + timedout);
}

function OnWebServiceError(error)
{
    var stackTrace = error.get_stackTrace();

    var message = error.get_message();

    var statusCode = error.get_statusCode();

    var exceptionType = error.get_exceptionType();

    var timedout = error.get_timedOut();

    // Display the error.   

    alert(  "Stack Trace: " +  stackTrace + "<br/>" +
        "Service Error: " + message + "<br/>" +
        "Status Code: " + statusCode + "<br/>" +
        "Exception Type: " + exceptionType + "<br/>" +
        "Timedout: " + timedout);
    // goto the home page if this is a session issue

}

function getElementsByAttribute(tagName, attribute, attributeValue) 
{ 
 var elementArray = new Array(); 
 var matchedArray = new Array(); 
// get the list based on the browser dom

    elementArray = document.getElementsByTagName(tagName); 
    
// handle the exceptions class and for
 //alert("elementArray.length=" + elementArray.length);
 for (var i = 0; i < elementArray.length; i++) 
 { 
    //alert("for " + elementArray[i].id + " elementArray[i].getAttribute("+ attribute + ") with value " +  attributeValue + " = " + elementArray[i].getAttribute(attribute));
   if (attribute == "class") 
   { 
     var pattern = new RegExp("(^| )" + attributeValue + "( |$)"); 

     if (pattern.test(elementArray[i].className)) 
     { 
       matchedArray[matchedArray.length] = elementArray[i]; 
     } 
   } 
   else if (attribute == "for") 
   { 
     if (elementArray[i].getAttribute("htmlFor") || elementArray[i].getAttribute("for")) 
     { 
       if (elementArray[i].htmlFor == attributeValue) 
       { 
         matchedArray[matchedArray.length] = elementArray[i]; 
       } 
     } 
   } 
   else if (elementArray[i].getAttribute(attribute) == attributeValue) 
   { 
     matchedArray[matchedArray.length] = elementArray[i]; 
   } 
 } 

 return matchedArray; 
}

function OpenWindow(strURL, strName, intWidth, intHeight) {

    var strFeatures;
    
    strFeatures = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1";
    
    if(!strName) {
        strName = "";
    }
    
    if(intWidth && intHeight) {
        strFeatures += ",width=1000,height=700";
    }
  
    window.open(strURL,strName, strFeatures);

}

function getCursorPosition(e) {

	e = e || window.event;
	var cursor = {x:0, y:0};
	if (e.pageX || e.pageY) {
		cursor.x = e.pageX;
		cursor.y = e.pageY;
	} 
	else {
		cursor.x = e.clientX + 
		(document.documentElement.scrollLeft || 
		document.body.scrollLeft) - 
		document.documentElement.clientLeft;
		cursor.y = e.clientY + 
		(document.documentElement.scrollTop || 
		document.body.scrollTop) - 
		document.documentElement.clientTop;
	}
return cursor;
}

function addOption(selectbox,text,value ) {
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
    selectbox.options.add(optn);
}

function selectOption(oObject, strValue) {
    var iLoop;
    
    for(iLoop=0;iLoop < oObject.options.length;iLoop++) {
        if(oObject.options[iLoop].value == strValue) {
            oObject.selectedIndex = iLoop;
            break;
        } 
    }
}

function CheckSession() {
    window.onfocus = "";
    startHTTPRequest("Security","LoginStatusInquiry","","OnCheckSessionComplete","","OnCheckSessionError");
}


function OnCheckSessionComplete(arg) {
    var strContent = objHttp[arg].responseText;
    var oXML = new ActiveXObject("Microsoft.XMLDOM");

    oXML.loadXML(strContent);
    status = GetXMLNodeText(oXML, "StatusInquiry");
    
    if(status.toLowerCase() == 'false') {
        window.onfocus = "";
        alert("Your session has ended.  Click 'OK' to close this window.");
        window.close();
    }

    window.onfocus = CheckSession;
}

function OnCheckSessionError(arg) {
    window.onfocus = "";
    window.close();
}

// Set event handler to initialize API
//window.onload = initDHTMLAPI;
initDHTMLAPI();


//Adds a trim function.
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };





/////////////////////////////////////////////////////////
// activityhandler.js start
///////////////////////////////////////////////////////////
    // register this script block as "activityHandler"

//        function eThorityOpenDialog(URL,name,specs,replace)
//        {
//                var strEncoded = escape(guid.value);
//                strEncoded = strEncoded.replace(/\+/g, "%2B");
//                strEncoded = strEncoded.replace(/\//g, "%2F");
//                var qs = "isDialog=1";
//               if (URL.indexOf("?") > -1)
//                {
//                    URL +=  "&" +qs;
//                }
//                else
//                {
//                    URL += "?" + qs;
//                }
//               name = name.replace(/ /gi, "_");
//                window.open(URL,name,specs,replace);
//        }
        
        function eThorityOpenWindow(URL,name,specs,replace)
        {
            var tid = document.getElementById("hf_transactionID");
            var guid = document.getElementById("hf_guid");
                if ((tid ) && (guid))
            {
                var strEncoded = escape(guid.value);
                strEncoded = strEncoded.replace(/\+/g, "%2B");
                strEncoded = strEncoded.replace(/\//g, "%2F");
                var qs = "hf_guid=" + strEncoded + "&hf_newtransaction=1&hf_transactionID=0&hf_newtransaction=1&isJS=1&hf_openingtid=" + tid.value + "&openingtid=" + tid.value;
               if (URL.indexOf("?") > -1)
                {
                    URL +=  "&" +qs;
                }
                else
                {
                    URL += "?" + qs;
                }
               name = name.replace(/\s/gi, "_");
               name = name.replace(/\./gi, "_");
               if ( name == "" )
               {
                    name = "_blank"; // force a new window to open
               }
                window.open(URL,name,specs,replace);
            }
        }
        
        function eThorityOpenSWF( swffile, title, OtherParms, width, height, scaleFlag,resizeFlag, name, specs, isDialog )
        {
				//document.title += " 2 ";
				if ( swffile.match(".swf") == null )
				{
					swffile += ".swf";
				}
				//document.title += " 2a ";
				
				// ----------------------------------------------------- features to pass to window.open start----------------------------
				if (specs == null)
				{
					specs = "";
				}
				if (specs == undefined)
				{
					specs = "";
				}
				
				if (specs.length > 0)
				{
					specs = "," + specs;
				}
				//always this at a minimum
				specs = "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0" + specs;
				//alert(specs);
				// is there a valid width to use
				if (isNaN(width))
				{
				//document.title += " 2b ";
					width= 1024;
				}
				else
				{
				//document.title += " 2c ";
					if (width <= 0 )
					{
						width= 1024;
					}
				}
				//document.title += " 2d ";
				specs = specs + ",width=" + width.toString();
				//document.title += " 3 " +  width.toString();
				// is there a valid height to use
				if (isNaN(height))
				{
					height= 768;
				}
				else
				{
					if (height <= 0 )
					{
						height= 768;
					}
				}
				specs = specs + ",height=" + height.toString();
				// decide how to resize
				//alert(resizeFlag);
				resizeFlag = GetBooleanFromValue(resizeFlag, false);
				//alert(resizeFlag);
				// if allowing resize, make sure the scaleFlag is true
				if ( resizeFlag )
				{
				    scaleFlag = true;
				}
				//document.title += " 5 " +  resizeFlag.toString();
				specs = specs + ",resizable=" + (resizeFlag == true ? "1" : "0");
				// ----------------------------------------------------- features to pass to window.open end----------------------------
				
				// ----------------------------------------------------- querystring part of url to pass to window.open start----------------------------
				if (OtherParms == null)
				{
					OtherParms = "<root></root>";
				}
				if (OtherParms == undefined)
				{
					OtherParms = "<root></root>";
				}
				var URL = "../Flash/FlexShell.aspx?swffile=" + swffile +  "&docTitle=" + encodeURI(title) + "&OtherParms=" + encodeURI(OtherParms);
				if ( isDialog = "1" )
				{
				    URL += "&isDialog=1";
				}
				//document.title += " 4 " +  height.toString();
				
				// decide how to scale
				scaleFlag = GetBooleanFromValue(scaleFlag, false);
				//document.title += " 6 " +  scaleFlag.toString();
				URL = URL + "&scaleMode=" + (scaleFlag == true ? "showAll" : "noScale");
				//document.title = specs;
				
				// ----------------------------------------------------- querystring part of url to pass to window.open end----------------------------
				
				// make sure there is a name for the window
				if (name == null) 
				{
					name = "";
				}
				if (name == "") 
				{
					name = title;
				}
				//document.title = URL;
				eThorityOpenWindow(URL,name,specs,true);
		}
	
        function eXtensionOpenSWF( swffile, title, OtherParms, width, height, scaleFlag,resizeFlag, name, specs, isDialog )
        {
				//document.title += " 2 ";
				if ( swffile.match(".swf") == null )
				{
					swffile += ".swf";
				}
				//document.title += " 2a ";
				
				// ----------------------------------------------------- features to pass to window.open start----------------------------
				if (specs == null)
				{
					specs = "";
				}
				if (specs == undefined)
				{
					specs = "";
				}
				
				if (specs.length > 0)
				{
					specs = "," + specs;
				}
				//always this at a minimum
				specs = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0" + specs;
				//alert(specs);
				// is there a valid width to use
				if (isNaN(width))
				{
				//document.title += " 2b ";
					width= 1024;
				}
				else
				{
				//document.title += " 2c ";
					if (width <= 0 )
					{
						width= 1024;
					}
				}
				//document.title += " 2d ";
				specs = specs + ",width=" + width.toString();
				//document.title += " 3 " +  width.toString();
				// is there a valid height to use
				if (isNaN(height))
				{
					height= 768;
				}
				else
				{
					if (height <= 0 )
					{
						height= 768;
					}
				}
				specs = specs + ",height=" + height.toString();
				// decide how to resize
				resizeFlag = GetBooleanFromValue(resizeFlag, true);
				//document.title += " 5 " +  resizeFlag.toString();
				specs = specs + ",resizable=" + (resizeFlag == true ? "1" : "0");
				// ----------------------------------------------------- features to pass to window.open end----------------------------
				
				// ----------------------------------------------------- querystring part of url to pass to window.open start----------------------------
				if (OtherParms == null)
				{
					OtherParms = "<root></root>";
				}
				if (OtherParms == undefined)
				{
					OtherParms = "<root></root>";
				}
				var URL = webserviceProcessorURLeXt+"/Flash/FlexShell.aspx?swffile=" + swffile +  "&docTitle=" + encodeURI(title) + "&OtherParms=" + encodeURI(OtherParms);
				if ( isDialog = "1" )
				{
				    URL += "&isDialog=1";
				}
				//document.title += " 4 " +  height.toString();
				
				// decide how to scale
				scaleFlag = GetBooleanFromValue(scaleFlag, true);
				//document.title += " 6 " +  scaleFlag.toString();
				URL = URL + "&scaleMode=" + (scaleFlag == true ? "showAll" : "noScale");
				//document.title = specs;
				
				// ----------------------------------------------------- querystring part of url to pass to window.open end----------------------------
				
				// make sure there is a name for the window
				if (name == null) 
				{
					name = "";
				}
				if (name == "") 
				{
					name = title;
				}
				//document.title = URL;
				eThorityOpenWindow(URL,name,specs,true);
		}


		   function GetBooleanFromValue(value, defaultValue)
		   {
				if (defaultValue == null)
				{
					defaultValue = false;
				}
				if (defaultValue == undefined)
				{
					defaultValue = false;
				}
				
				switch (value )
				{
				case "true":
				 return true;
				  break;
				case true:
				 return true;
				  break;
				case 1:
				 return true;
				  break;
				case "1":
				 return true;
				  break;
				case "false":
				 return false;
				  break;
				case false:
				 return false;
				  break;
				case "0":
				 return false;
				  break;
				case 0:
				 return false;
				  break;
				default:
				 return defaultValue;
				}
		   
		   }
		   
		   
        function eThoritypostwindow(destination, strCommand, blnIsDialog)
        {
            if (!destination)// make sure there is a destination
            {return false;}
            var guid = document.getElementById("hf_guid");


            document.getElementById("hf_newtransaction").value = "";
            if(blnIsDialog) 
            {
                document.forms[0].target=destination; // iframe
            } else {
                if(destination) {
                    document.forms[0].target = destination; // new form
                    document.getElementById("hf_newtransaction").value = "1";
                } else {
                    document.forms[0].target=""; // same form
                }
            }
            __doPostBack('postBackButton',strCommand);
            document.forms[0].target=""; // same form
            document.getElementById("hf_newtransaction").value = "";

            return true;
        }
            


            // Replaces all instances of the given substring.
        String.prototype.replaceAll = function( 
                strTarget, // The substring you want to replace
                strSubString // The string you want to replace in.
            )
            {
//                var strReplaceAll = this.replace( new RegExp( strTarget, strSubString ), "[X]" );
                var strReplaceAll = this.replace( new RegExp( strTarget, "g" ), strSubString );
                
                return strReplaceAll;

            }
            
//            // Replaces all instances of the given substring.
//        String.prototype.replaceAll = function( 
//                strTarget, // The substring you want to replace
//                strSubString // The string you want to replace in.
//            )
//            {
//				var strText = this;
//				if(strText == null) 
//				{
//					strText = "";
//				}
//                var dup = "'" + strText + "'.replace(/" 
//                 + strTarget + "/g , '" + strSubString + "');";
//				if (strTarget == "\+") 
//				{
//					alert(dup);
//					alert(eval(dup));
//				}
//				var strText2 = eval(dup);
//			
//				return strText2;
//				
//            }
//--------------------------------------
//			if (typeof(sessionRecording) == 'undefined') 
//			{var str = "";			}
//			else
//			{//1
//				if (!sessionRecording) 
//				{var str = "";		}
//				else
//				{//2
//				// we are recording session activity
//						try{
//							// browser is Mozilla, Nestcape, etc.
//							// use addEventListener() method
//							document.addEventListener('mousedown',recordactionTaken,false);
//							document.addEventListener('mouseup',recordactionTaken,false);
//							document.addEventListener('blur',recordactionTaken,false);
//							document.addEventListener('resize',ResizeResumeDiv,false);
//							}
//						catch(e)
//							{
//								try{
//									// browser is Internet Explorer
//									// use attachEvent() method
//									document.attachEvent('onmousedown',recordactionTaken);
//									document.attachEvent('onmouseup',recordactionTaken);
//									document.attachEvent('onblur',recordactionTaken);
//									document.attachEvent('onresize',ResizeResumeDiv);
//									}
//								catch(e)
//									{
//									alert('Failed to add event handler onclick');
//									}
//							}
//					}//2
//				}//1
			
//--------------------------------------
		
		
//        // apply the submit to the form onsubmit event
//        for (var frm in document.forms )
//        {
//            document.forms[frm].onsubmit += postponeActivity;
//        }

        function ResizeResumeDiv()
        {
                var rsdiv = document.getElementById("ws_resumeDiv");
                if (rsdiv)
                {
                    rsdiv.style.width=getInsideWindowWidth() + "px";
                    rsdiv.style.height=getInsideWindowHeight() + "px";
                    centerOnPage(rsdiv);
                }
                return false;
        }
        var posx = 0;
        var posy = 0;
 
        function GetMouseCoordinates() {
            var e = window.event;
	        if (e)
	        {
	            if (e.pageX || e.pageY)
	            {
		            posx = e.pageX;
		            posy = e.pageY;
	            }
	            else if (e.clientX || e.clientY) 	
	            {
		            posx = e.clientX + document.body.scrollLeft
			            + document.documentElement.scrollLeft;
		            posy = e.clientY + document.body.scrollTop
			            + document.documentElement.scrollTop;
	            }
	        } 
	        else
	        {
                posx = 0;
                posy = 0;
	        }
	        // posx and posy contain the mouse position relative to the document
	        // Do something with this information
        }
        function findElementScreenPosition(obj) {
	        var curleft = curtop = 0;
	        var op = obj.offsetParent;
	        curleft = obj.offsetLeft;
	        curtop = obj.offsetTop;
	        if (op != null) {
		        while (op != null) {
			        curleft += op.offsetLeft;
			        curtop += op.offsetTop;
			        op = op.offsetParent;
		        }
	        }
	        return [curleft,curtop];
        }
        var actionsTaken = "";
        var actionCount=0;
	    var targElement; 
        function recordactionTaken() {
			if (typeof(sessionRecording) == 'undefined') return false;
	        if (!sessionRecording) return false;
	        var onTargetValue="";
	        var e;
	        var d = new Date();
            //self.status = d.toString();
	        e = window.event;
	        if (e.target) targElement = e.target;
	        else if (e.srcElement) targElement = e.srcElement;
	        if (targElement.nodeType == 3) // defeat Safari bug
		        targElement = targElement.parentNode;
	        GetMouseCoordinates();
	        // one line per activity
	        // pagename, target, timestamp
	        if (targElement.id)
	        {
                var hf = document.getElementById("hf_actiontaken");
                if (typeof(hf) !== 'undefined')
                {   
                    hf.value+= "\n" + targElement.id + "." + e.type + ((onTargetValue > "") ? " value=" + onTargetValue : "") + "\t" ;
                    hf.value += (d.getUTCMonth() + 1) + "/" +d.getUTCDate() + "/" + d.getUTCFullYear(); 
                    hf.value += " " + (d.getUTCHours() ) + ":" +d.getUTCMinutes() + ":" + d.getUTCSeconds(); 
                    actionCount+=1;
                    if (actionCount >= 30)
                    {
                      // postActivity(1);
                    }
                }
            }
	        return false;
        }
        
        var sessionTimer;
        function postActivity(posttype)
        {
        
			// posttype = 0 is a timer call
			// posttype = 1 is a actionstaken = 30 call
			
            // do not post while suspended
            var SuspendShadow = document.getElementById("ResumeShadow");
            if (SuspendShadow) return;
            window.clearTimeout(sessionTimer);
            sessionTimer= 0;
            if (posttype == 0) return;
            var notAllowed = -1;
            var docurl = location.pathname;
                var hf = document.getElementById("hf_actiontaken");
                if (typeof(hf) == 'undefined')
                {
                    notAllowed = 1;   
                    //self.status  =  "notAllowed = 1;";
                }
                else
                {
	                    var tid = document.getElementById("hf_transactionID");
	                    var guid = document.getElementById("hf_guid");
                        if (typeof(guid) == 'undefined')
                        {
                            notAllowed = 2;   
                        }
                        else
	                    {
	                        if (guid.value == "")
	                        {
                                notAllowed = 3;   
                            }
                            else
	                        {
                                notAllowed = 4;   
                                var sessionDoc = "<root><guid>" + EncodeXMLText(guid.value) + "</guid><transactionID>" + tid.value + "</transactionID><source>" + EncodeXMLText(docurl) + "</source><actiontaken>" + EncodeXMLText(hf.value) + "</actiontaken></root>";
                                //startHTTPRequest( "eThorityAdministration", "RecordActivity",  sessionDoc,  "onRecordActivity",null,  "onRecordActivity",  "onRecordActivity" ) ;
                            }
                    }
                }
            hf.value = "";
            actioncount = 0;
        }
        function postponeActivity()
        {
			if (sessionTimer > 0) window.clearTimeout(sessionTimer);
            sessionTimer= 0;
            return true;
        }
        function onRecordActivity()
        {
            if (sessionTimer > 0) window.clearTimeout(sessionTimer);
            sessionTimer= 0;
            //StartCallbackTimer("postActivity(0)", sessionInterval);
        }
        
        // setup the timer event
        function StartCallbackTimer(timerProc, intInterval) 
        {
            if (sessionRecording)
            {
				//sessionTimer=setTimeout(timerProc, intInterval);
            }
            else
            {
				sessionTimer = 0;
            }
        }

    function submitViaEnter(evt)
    {
        evt = (evt) ? evt : event;
        var target = (evt.target) ? evt.target : event.srcElement;
        var form = target.form;
        var charCode =(evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
        if (charCode == 13 || charCode == 3)
        {
                target.form.submit();
                return false;
        }
        return true;
    }
    
    // create the resume panel
    function createResumePanel()
    {
        // create the div and the pwd control and superimpose over the form
        var zIndex = 0;
        // get the higest zIndex on the form
        zIndex = 50000;
        // create the div
        var divShadow = document.createElement("div");//"DIV"); // no parent except the body tag
        divShadow.id = "ResumeShadow";
        var attrib = (navigator.appName=='Netscape') ? 'class' : 'className';
        divShadow.setAttribute("class", "ResumeShadow");
        divShadow.style.zIndex=zIndex;
        divShadow.innerText = "Click to resume session.";
        document.body.appendChild(divShadow);
        try{
            // browser is Mozilla, Nestcape, etc.
            divShadow.addEventListener('onclick',ResumeShadowClicked,false);
            }
        catch(e)
            {
                try{
                    // browser is Internet Explorer
                    // use attachEvent() method
                    divShadow.attachEvent('onclick',ResumeShadowClicked);
                    }
                // catch thrown error
                catch(e)
                    {
                    alert('Failed to add ResumeShadow onclick event handler');
                    }
            }
    }
    function ResumeShadowClicked()
    {
        //alert('ResumeShadow clicked');
        document.body.removeChild(document.getElementById('ResumeShadow'));
        // now reactivate the session if it can be reactivated.
        var tid = document.getElementById("hf_transactionID");
        var guid = document.getElementById("hf_guid");
        var docurl = location.pathname;
        var sessionDoc = "<root><guid>" + EncodeXMLText(guid.value) + "</guid><transactionID>" + tid.value + "</transactionID><source>" + EncodeXMLText(docurl) + "</source><actiontaken>Resume Session</actiontaken></root>";
        startHTTPRequest( "eThorityAdministration", "ContinueUserSession",  sessionDoc,  "onRecordActivity",null,  "onRecordActivity",  "onRecordActivity" ) ;
        //alert("ContinueUserSession");
    }
// This is the failed callback function.
function OnActvityWebServiceSucceeded(index)
{
            var xmlDoc;
            if (document.implementation && document.implementation.createDocument)
            {
                xmlDoc = document.implementation.createDocument("", "", null);
            }
            else if (window.ActiveXObject)
            {
                xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            }
            else
            {
                alert('Your browser can\'t handle this script');
                return;
            }
}

/////////////////////////////////////////////////////////
// activityhandler.js end
///////////////////////////////////////////////////////////


    function LoggedOut() {
        window.location = '../Administration/Login.aspx?Logout=true';
    }

/////////////////////////////////////////////////////////
// httprequestProcessing.js start
///////////////////////////////////////////////////////////
 function GetHTTPObject()
{
    var xmlhttp=false;
     try 
     {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     } 
     catch (e) 
     {
      try 
      {
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch (E) 
      {
       xmlhttp = false;
      }
     }
    if (!xmlhttp && typeof XMLHttpRequest!=undefined) 
    {
	    try 
	    {
		    xmlhttp = new XMLHttpRequest();
	    } 
	    catch (e) 
	    {
		    xmlhttp=false;
	    }
    }
    if (!xmlhttp && window.createRequest) 
    {
	    try 
	    {
		    xmlhttp = window.createRequest();
	    } 
	    catch (e) 
	    {
		    xmlhttp=false;
	    }
    }
    return xmlhttp;
}


function objXMLHttpRequest(index, onSuccess, requestingObject, onTimeOut, onError)
{
        this.index = index;
        this.onSuccess = onSuccess;
        this.onTimeOut= onTimeOut;
        this.onError = onError;
        this.http = null;
        this.sendData = null;
        this.responseText = null;
        this.statusText = null;
        this.processing = false;
        this.requestingObject = requestingObject;
        this.loadingimage = null;
} 
function objXMLHttpRequestGetIndexName(objectName, methodName)
{
        var dt = new Date;
        var httpRequestGetMilliseconds = dt.getMilliseconds().toString();
        return  objectName + "." + methodName + "." + httpRequestGetMilliseconds ;
}


function OnHTTPRequestError(index)
{
   var status = objHttp[index].statusText;
    // Display the error.   
    //alert("status = " + status);
       var hasError = status.indexOf("<Error>");
       if (hasError >= 0)
       {
            var hasErrorCode = status.indexOf("<ErrorCode>");
            if (hasErrorCode >=0)
            {   // needs a root node to load
             var hasErrorCodeEnd = status.indexOf("</ErrorCode>");
                var errorCode = status.substring(hasErrorCode + "<ErrorCode>".length, hasErrorCodeEnd);
					switch (errorCode)
					{
							case "1":
								createResumePanel();
								break;    
							case "10000":
								postponeActivity(); // stop done the activity monitor when you have this error.
								var tid = document.getElementById("hf_transactionID");
								var guid = document.getElementById("hf_guid");
								var qs =  "Error=" + status.substr(0, hasErrorCodeEnd-1).replace(/\+/g, "%2B");
								qs =  qs.replace(/\//g, "%2F");
								if ((tid ) && (guid))
								{
									var strEncoded = escape(guid.value);
									strEncoded = strEncoded.replace(/\+/g, "%2B");
									strEncoded = strEncoded.replace(/\//g, "%2F");
									qs += "&hf_guid=" + strEncoded + "&hf_transactionID=" + tid.value ;
								}
								if ( (location.pathname.toLowerCase().indexOf("zonelistf") >=0 ) || (location.pathname.toLowerCase().indexOf("login") >= 0))
									qs += "&zlf=1" ;
								else
									qs += "&zlf=0" ;
								window.location.replace(webrootpath +"/Administration/eThorityError.aspx?" + qs);

                                //If using the animated cursor, and it's on...
								if(document.getElementById("AnimCursor")) {
								    TurnOffAnimatedCursor();
								}
								return;
							default:
					}
            }
            var xmlDoc;
            if (document.implementation && document.implementation.createDocument)
            {
                xmlDoc = document.implementation.createDocument("", "", null);
            }
            else if (window.ActiveXObject)
            {
                xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            }
            else
            {
                alert('Your browser can\'t handle this script');
                return;
            }
            xmlDoc.loadXML(status);
            status = GetXMLNodeText(xmlDoc, "Error");
            xmlDoc = null;
    }
    if (status == "")
    {
		alert(objHttp[index].sendData);

//        if(objHttp[index].onError != "") {
//            eval(objHttp[index].onError+ "('" + objHttp[index].index + "')");
//        }
		
    }
    else
    {
		alert(status);

//        if(objHttp[index].onError != "") {
//            eval(objHttp[index].onError+ "('" + objHttp[index].index + "')");
//        }
		
    }

    //If using the animated cursor, and it's on...
	if(document.getElementById("AnimCursor")) {
	    TurnOffAnimatedCursor();
	}

    // goto the home page if this is a session issue
}


var objHttp = new Array();


    // although not declared, the args[0] will be the index of the objHttp[index]
    //Object readyState integer:
    //0 = uninitialized
    //1 = loading
    //2 = loaded
    //3 = interactive
    //4 = complete
    //Object status integer:
 function startHTTPRequest(objectName, methodName,  content, onSuccessproc, requestingObject , onTimeoutproc, onErrorproc, isGet, isAsyncRequest ) 
 {
    if (typeof(isGet) == 'undefined') isGet = false;
    if (typeof(isAsyncRequest) == 'undefined') isAsyncRequest = true;
    if (typeof(onSuccessproc) == 'undefined') onSuccessproc = null;
    if (typeof(onTimeoutproc) == 'undefined') onTimeoutproc = "OnWebServiceTimeOut";
    if (typeof(onErrorproc) == 'undefined') onErrorproc = "OnHTTPRequestError";
    // must have objectName and methodName to get started
    var index = objXMLHttpRequestGetIndexName(objectName, methodName);
    objHttp[index] = new objXMLHttpRequest(index, onSuccessproc, requestingObject, onTimeoutproc, onErrorproc);
    var objtid = document.getElementById("hf_transactionID");
    var objguid = document.getElementById("hf_guid");
    if (requestingObject) 
    {
        showLoading(index);
    }
    var guid = "";
    var tid = "";
    if (typeof(objguid) != 'undefined') guid = objguid.value;
    if (typeof(objtid) != 'undefined') tid = objtid.value;
	//alert( "startHTTPRequest\n" + objectName+ "\n" + methodName + "\n" + typeof(objtid)+ "\n" +  tid);	                    
    //if ( !(objectName=="eThorityAdministration" && methodName == "RecordActivity" && onSuccessproc== "onRecordActivity"))
    //postActivity();
    var hf = document.getElementById("hf_actiontaken");
    var sendData = "<?xml version=\"1.0\" ?><WSRoot>" +
     "<indexStamp>" + EncodeXMLText(objHttp[index].index) + "</indexStamp>" +
     "<guid>" + EncodeXMLText(guid) + "</guid>" +
     "<transactionID>" + tid + "</transactionID>" +
     "<sourceName>" + EncodeXMLText(location.pathname.replaceAll("%2F", "/").replaceAll("%2B", "+")) + "</sourceName>" +
     "<objectName>" + EncodeXMLText(objectName) + "</objectName>" +
     "<methodName>" + EncodeXMLText(methodName) + "</methodName>" +
     "<actiontaken>" + hf.value + "</actiontaken>" +
     "<content>" + content.replaceAll("%2F", "/").replaceAll("%2B", "+")  + "</content>" +
     "</WSRoot>";
    objHttp[index].http = GetHTTPObject();
    objHttp[index].sendData = sendData;
    var method = (isGet? "GET" : "POST");
    objHttp[index].http.onreadystatechange = handleHttpResponse   ; // passes the name of the object in the array
    objHttp[index].http.open(method, webserviceProcessorURL + "/Transport/RequestProcessor.aspx",isAsyncRequest);
    objHttp[index].http.setRequestHeader("Content-Type", "text/xml");
    objHttp[index].http.send(sendData);
}
 
function handleHttpResponse() 
{
    // determine which object has the readystate change
            for  (var op in objHttp)
            {
                 if (objHttp[op].http.readyState == 4 && objHttp[op].processing == false )
                {
                    objHttp[op].processing  = true;
                    var responseText = ""
                    try
                    {
                        responseText = objHttp[op].http.responseText;
                    }
                    catch (e)
                    {
                    }
                   processHttpResponse(objHttp[op], objHttp[op].http.readyState, responseText, objHttp[op].http.statusText, objHttp[op].http.status);
                    delete objHttp[op] ; // removes the object
                }
            }
}

function processHttpResponse(thishttp, readyState, responseText, statusText, status)
{          
    // bychance the xmlhttp could have been handled in simultaneous events
    // so check for it being nothing
    if (typeof(thishttp) == 'undefined') return false;
    if (typeof(thishttp.http) == 'undefined') return false;
    if (thishttp.processing == false) return false;
    //alert("processHttpResponse = " + responseText);
    // Numeric code returned by server, such as 404 for "Not Found" or 200 for "OK"
  if (readyState <= 1) 
  {
    //put an image on the screen to indicate atcivity is happening
  }
  else
  {
      if (readyState == 4) 
      {
         // remove the image on the screen
         if (thishttp.requestingObject)
         {
            hideLoading(thishttp.index);
         }
          thishttp.responseText = responseText; 
          thishttp.statusText = statusText;
          var hasError = thishttp.responseText.indexOf("<Error>");
          if (thishttp.http.status==200 && hasError == -1)
            {
               eval(thishttp.onSuccess+ "('" + thishttp.index + "')" );
            }
          else
            {
                if (hasError >= 0)
                {
                thishttp.statusText = thishttp.responseText;
                thishttp.responseText = "";
                }
				var haserrorCode = thishttp.responseText.indexOf("<ErrorCode>");
				if (haserrorCode >= 0)
				{
					xmlDoc.loadXML(thishttp.responseText);
					var strNode = GetXMLNodeXML(xmlDoc, "//ErrorCode");
					switch (strNode.tolower())
					{
						case "logout":
						// go to logout page
							createLogoutPanel();

				            // let the desired handler deal with it
//                            if(thishttp.onError != "") {
//				                eval(thishttp.onError+ "('" + thishttp.index + "')");
//                            }
							break;
						case "suspend":
						// timed out
							createResumePanel();
							//alert("Timed out");
							break;
						default:
						// life is good
							//alert("good");
							notAllowed = 0; 
							//self.status  ="  Web Service Succeeded" ;
							break;
					}
				// if this is a session return code, exit here
				return
				}
				// let the desired handler deal with it
				eval(thishttp.onError+ "('" + thishttp.index + "')");
            }
      }
   }
}
function addElement(index)
{    
    GetMouseCoordinates() // find out where the user is to position the loading image at the mouse
	if (typeof(objHttp[index]) == "undefined") return; 
	if (typeof(objHttp[index].requestingObject) == "undefined") return; 
	if (objHttp[index].requestingObject == null) return; 
    if (objHttp[index].requestingObject)
    {
        // use the requestingObject to get the position for the loading image
        var pos = new Array;
        if (objHttp[index].requestingObject.offsetParent) {
		        posx = objHttp[index].requestingObject.offsetLeft;
		        posy = objHttp[index].requestingObject.offsetTop;
        }
        pos = findElementScreenPosition(objHttp[index].requestingObject);
        if (!isNaN(pos[0]))
        {
            posx=pos[0];
            posy=pos[1];
        }
        var divid = objHttp[index].loadingimage ;
        if (divid)
        {
			divid.style.top=posy + "px";
			divid.style.left= posx + "px";
			divid.style.visibility = "visible";
			document.body.appendChild(divid);
        }
    }
}

function showLoading(index)
{
	if (typeof(objHttp[index]) == "undefined") return; 
   if (objHttp[index])
    {
 		if (typeof(objHttp[index].requestingObject)== "undefined") return; 
 		if (objHttp[index].requestingObject == null) return; 
       var img = document.createElement("img"); //new Image(); 
        img.style.backgroundColor="white";
        img.style.width="20px";
        img.style.height="20px";
        img.style.position="absolute";
        img.alt="loading";
        img.style.zIndex =5000;
        if (webserviceProcessorURL.indexOf(location.protocol + "//" + location.hostname) ==0 )
			img.src = webserviceProcessorURL + "/images_gen/bigrotation2.gif";	
        else
 			img.src = webserviceProcessorURLeXt + "/images_gen/bigrotation2.gif";	
       img.id = "div"+  index.replace(/[.]/gi, "_");
        objHttp[index].loadingimage = img;
        setTimeout("addElement('" + index + "')", 10);
    }
}

function hideLoading(index)
{
	if (typeof(objHttp[index]) == "undefined") return; 
    if (objHttp[index])
    {
        var divid = objHttp[index].loadingimage ;
        if (divid)
        {
			try
			{
            document.body.removeChild(divid);
            }
            catch (e)
            {
 			try
			{
            document.removeChild(divid);
            }
            catch (e)
            {
            }
           }
            objHttp[index].loadingimage = null;
        }
    }
}
function GetXMLNodeXML(oXML, strNodeName) {
    var strText;
    var oNode;
    oNode = oXML.selectSingleNode(strNodeName);
    
    if(oNode) {
        strText = oNode.xml;
    } else {
        strText = "";
    }
    
    return strText;
}

function GetXMLNodeText(oXML, strNodeName) {
    var strText;
    var oNode;
    oNode = oXML.selectSingleNode(strNodeName);
    
    if(oNode) {
        strText = oNode.text;
    } else {
        strText = "";
    }
    
    return strText;
}
//function GetHeaders()
//{
//xmlhttp.open("HEAD", "/faq/index.html",true);
// xmlhttp.onreadystatechange=function() {
//  if (xmlhttp.readyState==4) {
//   alert(xmlhttp.getAllResponseHeaders());
//  }
// }
// xmlhttp.send(null);

//}

function EncodeXMLText(strText) {

    var strText2 = "";
    
    if(strText == null) {
        strText = "";
    }
    if (strText > "")
    {
      var re = new RegExp("&", "g");
      strText2 =strText.replace(re,"&amp;");
      re = new RegExp("<", "g");
      strText2 =strText2.replace(re,"&lt;");
      re = new RegExp(">", "g");
      strText2 =strText2.replace(re,"&gt;");
      re = new RegExp("\"", "g");
      strText2 =strText2.replace(re,"&quot;");
    }
    
    return strText2;
}
function CreateXMLDoc(strXML) {
    var xmlDoc;
    
    if (document.implementation && document.implementation.createDocument)
    {
        xmlDoc = document.implementation.createDocument("", "", null);
    }
    else if (window.ActiveXObject)
    {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    }
    else
    {
        alert('Your browser can\'t handle this script');
        return;
    }
    xmlDoc.loadXML(strXML);
    return xmlDoc;
}


/////////////////////////////////////////////////////////
// httprequestProcessing.js end
///////////////////////////////////////////////////////////


