

////////////////////////////////////////////////////////////////////////////////
//	Debugging Variables
////////////////////////////////////////////////////////////////////////////////

var lastExceptionLocation;	//used for debugging purposes
var lastException;			//used for debugging purposes


////////////////////////////////////////////////////////////////////////////////
//	JavaScript Smart Navigation Methods
////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////
//  setFocus:		
//		Given an element name, this will execute the focus() method of that
//		element.  If the document supports getElementById then the element
//		will be retrieved using that function.  If not, the getElementsByName
//		function will be used, and we will assume that the first element that
//		is returned by the function is the appropriate element.
//
//	Used With:		Set Focus for Intial Element
//  Compatability:	IE 6.0, Navigator 7.1, Opera 7.53
////////////////////////////////////////////////////////////////////////////////
	function setFocus__(elementId){	
		if(document.getElementById){
			//getElementById is supported, so use it
			if(document.getElementById(elementId)){
				document.getElementById(elementId).focus();
			}//end if
		}else{
			if(document.getElementsByName){
				var items = document.getElementsByName(elementId);				
				if(items.length > 0){
					items[0].focus();				
				}//end if
			}//end if
		}//end if
	}//end function


////////////////////////////////////////////////////////////////////////////////
//  saveTabPos:		
//		Determines the active element and copies the element name into the
//		__lastTab hidden variable.  Used to track tab position during postback 
//		with the SetElementFocus() method.
//
//	Used With:		Tab Position Tracking
//	Assumptions:	__lastTab hidden variable is declared
//  Compatability:	IE 6.0, Navigator 7.1, Opera 7.53
////////////////////////////////////////////////////////////////////////////////

	function saveTabPos(formName){
		if(document.forms[formName]){
			if(document.forms[formName].__lastTab){
				document.forms[formName].__lastTab.value = document.activeElement.name;
			}//end if		
		}//end if
		return true
	}//end function


////////////////////////////////////////////////////////////////////////////////
//	setupTrackTab
//		Netscape does not support the document.activeElement property.  If the
//		browser is a Netscape browser, this will iterate through all controls
//		on the page and append an onfocus() handler that creates/sets the 
//		document.activeElement to the element that receieved the focus.
//
//	Used With:		Tab Position Tracking
//  Compatability:	IE 6.0, Navigator 7.1, Opera 7.53
////////////////////////////////////////////////////////////////////////////////
	function setupTrackTab(){
			
			if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {			
			
				var allElements = document.body.getElementsByTagName('*');
			
				for (var i = 0; i<allElements.length; i++) {
					
					if(allElements[i].focus != undefined){
						var functionBody = 'document.activeElement = this;';
						var oldOnFocus = allElements[i].getAttribute('onfocus');
						if (oldOnFocus) functionBody += oldOnFocus;
						allElements[i].onfocus = new Function ('event', functionBody);
					}//end if
					
				}//end if		
				
			}//end if
			
	}//end function



////////////////////////////////////////////////////////////////////////////////
//	setScrollPos
//		Sets the browser scroll position to the appropriate position
//
//	Used With:	Page Positioning
//  Compatability:	IE 6.0, Navigator 7.1, Opera 7.53
////////////////////////////////////////////////////////////////////////////////
	function setScrollPos(leftPos,topPos){		
		document.body.scrollLeft = leftPos;
		document.body.scrollTop = topPos;				
	}


////////////////////////////////////////////////////////////////////////////////
//	getScrollPos
//		Acquires the scroll position from the page and places the values into
//		hidden variables on the form. 
//
//	Used With:		Tab Position Tracking
//  Compatability:	IE 6.0, Navigator 7.1, Opera 7.53
////////////////////////////////////////////////////////////////////////////////
	function getScrollPos(formName){
		if(document.forms[formName]){
			if(document.forms[formName].__leftPos){
				document.forms[formName].__leftPos.value = document.body.scrollLeft;
				document.forms[formName].__topPos.value = document.body.scrollTop;
			}
		}
	}//end function


////////////////////////////////////////////////////////////////////////////////
//	DoPostBack Hijacking Variables and Methods
////////////////////////////////////////////////////////////////////////////////

var __oldDoPostBack;
var __formName;

////////////////////////////////////////////////////////////////////////////////
function hijackDoPostBack(){
	//This function assumes the variable __oldDoPostBack exists		
	try { 
		__oldDoPostBack = __doPostBack;
	} catch ( e ) { 
		return; // Assumes __doPostBack exists. If page doesn't have ASP controls that postback then __doPostBack is undefined.
	} 
	__doPostBack = runOnSubmit;	
}

////////////////////////////////////////////////////////////////////////////////
function getCode(functionCode){		
	var index = functionCode.indexOf("{");
	functionCode = functionCode.substring(index+1,functionCode.length);
	index = functionCode.lastIndexOf("}");
	functionCode = functionCode.substring(0,index-1);
	index = functionCode.indexOf("ValidatorOnSubmit();");
	if (index != -1){						
		return functionCode.substring(0,index);
	} else {	
		return functionCode;
	}					
	return functionCode;
}

////////////////////////////////////////////////////////////////////////////////
function runOnSubmit(eventTarget, eventArgument){			
	var onSubmitWithoutValidation = 
		new Function(
				getCode(
				document.forms[__formName].onsubmit.toString()
				)
			);
	onSubmitWithoutValidation();
	__oldDoPostBack(eventTarget, eventArgument);		
}
