var prevClickTime = 0;

var isIE = (navigator.appName.indexOf("Microsoft") != -1);
var isNS = (navigator.appName.indexOf("Netscape") != -1);
var isFF = (navigator.userAgent.indexOf("Firefox") != -1);
var browserVer = parseInt(navigator.appVersion);

            
function _dropPopup() {
    if( self.dropPopup )
        dropPopup()
    else if(parent.dropPopup)
        parent.dropPopup();
}
function keyPressHandler(e) {
   var kC  = (window.event) ? event.keyCode : e.keyCode;  // MSIE or Firefox?
   var Esc = (window.event) ? 27 : e.DOM_VK_ESCAPE  // MSIE : Firefox
   if(kC==Esc)
        _dropPopup()
}
    
function ClickHandler( e ) {
	var curClickTime = (new Date()).getTime();
	if( (curClickTime-prevClickTime) >= 5000 ) {
		prevClickTime = curClickTime;
		return true;
	}
	else 
		return false;
}

function fLoadTimeoutWarning() {
	return true;
}

function disableFilters(selectedOption ,filterArray){ 
	if(filterArray !=null){   
	     for(var i=0; i<filterArray.length;i++){
	          for(var j=0; j<filterArray[i].length; j++){
	               if(filterArray[i][j]!= null && i!=selectedOption)
	                    filterArray[i][j].disabled=true;
	          }
	     }
	     for(var i=0; i<filterArray.length;i++){
	          for(var j=0; j<filterArray[i].length; j++){
	               if(filterArray[i][j]!= null && i==selectedOption)
	                    filterArray[i][j].disabled=false;
	          }
	     }
     }

}

function setDisabledByElement(e, ary){
    // we check if length is a number otherwise we know there is only one element and it doesn't need to be disabled
	if(e!=null && isNaN(parseInt(e.length))==false ) {
	     for(var i=e.length-1; i>0; i--)
	     	if(e[i]!=null && e[i].checked)
	     		break;
	    disableFilters(i, ary);
	} 
}

function fLogoutWarning( nRecurses ){
	var cookieTime = readCookie('PageRefreshTime');

	if( cookieTime == startTime ) {
		var strMessage = "You are about to log out. You have " + nRecurses + " minutes before being logged out.";
		window.status = strMessage;
		//setTimeout( function() { fAnimateMessage( strMessage, 5 ) }, 200 );
		if( nRecurses > 1 ) 
		    TimeoutId = setTimeout( function() {fLogoutWarning( nRecurses - 1 )}, 6000 );
		else
		    TimeoutId = setTimeout( function() { fLogoutUser() }, 6000 );
	}
	else {
	    window.status = "";
	    //do nothing
	    //fTimerRecalc( cookieTime ); //recalculates the timer
	}
}

function fLogoutUser(){
	var cookieTime = readCookie('PageRefreshTime');
	if( cookieTime == startTime ) {
	
    window.status = "You are now logged out...";

    if( bRedirectOnTimeout == true ){
	    //redirect
	    window.location = strServerURL + "/common/Timeout.aspx";
	}
	else {
	//rewrite onsubmit, disable button onsubmit/onclick, disable/change form onsubmit/onclick
	var i = 0;
	var j;
	while( document.forms[i] != null ) {
	    	j = 0;
	    	while( document.forms[i].elements[j] != null ){
	    	    //alert(document.forms[i].elements[j].name);
	    	    if( document.forms[i].elements[j].type != 'textarea' && document.forms[i].elements[j].type != 'text' ) {
	    	    	document.forms[i].elements[j].onclick = null;
	    	    	document.forms[i].elements[j].onsubmit = null;
	    	    	document.forms[i].elements[j].onchange = null;
	    	    	document.forms[i].elements[j].onclick = function(){alert('You have been logged out of TeacherEase and cannot save.');}
	    	    }
	    	    j++;
	    	}
			document.forms[i].onsubmit = null;
			document.forms[i].onsubmit = function(){return false;}
			i++;
		}
		fSessionAbandon();
		alert('You have been inactive for ' + ( TimeoutMin - 5 ) + ' minutes.  As a security measure,'
			+ ' you have been automatically\r\n logged out of' + ApplicationName + '.'
			+ 'You can NOT save the information on the current page to ' + ApplicationName + '\r\n (because you\'re now logged out). '
			+ 'Print this page (or copy/paste) to make a copy of your latest changes.\r\n\r\n'
			+ 'Please login again to continue using ' + ApplicationName + '.\r\n');

	}
}
else {
	//do nothing
	//fTimerRecalc( cookieTimer );
	}

}

function fSessionAbandon() {
   	try {
		var AjaxRequest = new ActiveXObject("Msxml2.XMLHTTP");	// new IE
	}
	catch (e) {
		try {
			var AjaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); // old IE
		}
		catch (e2) {
			try {
				var AjaxRequest = new XMLHttpRequest();	// Firefox
			}
			catch(e3) {
				var AjaxRequest = null;
			}
		}
	}	// ends Try/Catch block
	if( AjaxRequest != null ) {
		AjaxRequest.open("POST", "/common/SessionAbandon.aspx", true);  // Open a connection to the server
		AjaxRequest.onreadystatechange = function() {}; // Setup a function for the server to run after the ajax submit returns
		AjaxRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		AjaxRequest.send("");
	}	// lObjName !=null
}

function fAnimateMessage( strMessage, nMessageCount ){
    if( nMessageCount == 5 )
        window.status = strMessage;
    else if( nMessageCount == 4 || nMessageCount == 0 )
	    window.status = strMessage + " .";
	else if ( nMessageCount == 3 || nMessageCount == 1 )
	    window.status = strMessage + " . .";
	else if ( nMessageCount == 2 )
	    window.status = strMessage + " . . .";

	nMessageCount -= 1;
	if( nMessageCount >= 0 )
	    setTimeout( function() { fAnimateMessage( strMessage, nMessageCount ) }, 500 );
}

//cookie reader
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function fTimerRecalc( cookieTime ) {

	//example startTime 2251, cookieTime was refreshed at 0013(the next day) from diff browser, start timeout in 2300 - 2251 + 0013
	if( cookieTime < startTime ) {
	    var overFlowTime = 2300 - startTime + cookieTime;
	}
	else {
		if( (cookieTime - startTime) <= 15 ) {
		    fLogoutWarning( (cookieTime - startTime) );
		}
		else {//your logout time is greater than 15 minutes, give a warning then
			setTimeout( 'fLogoutWarning( 15 )', (cookieTime - startTime - 15 ) * 60000 );
		}
		alert(cookieTime - startTime );
		startTime = cookieTime;

		alert('Recalced timer to: ' + startTime);
	}
}

function fDisplayHelp( path ) {
    var width = 900;
    var height = 600;
    if( window.screen.availWidth < width )
        width = window.screen.availWidth - 5;
    if( window.screen.availHeight < height )
        height = window.screen.availHeight - 5;
    
    // default options
    var strOptions = ",menubar=0,resizable=0,status=0,toolbar=1,location=0"; 
    
    // special options for IE 7.0
    if( navigator.appName.indexOf("Microsoft")!=-1 && navigator.appVersion.indexOf("7.0")!=-1)    
        strOptions = ",menubar=0,resizable=0,status=0,toolbar=0,location=1";
            
    var windowName = window.open( path, "TE_Help", "height=" + height + ",width=" + width + strOptions, false );
}

function spchr_client( str ) {
	if( str != "" && str != null ){
		var strReturn = str.replace(/&/, '&amp;');
		strReturn = strReturn.replace(/\"/, '&quot;');
		strReturn = strReturn.replace(/</, '&lt;');
		strReturn = strReturn.replace(/>/, '&gt;');
		return strReturn;
	}
	else
		return "";
}

function ProcessTime( lTime ) {
	if( typeof lTime=="undefined" || lTime=="" || lTime==null || lTime.search(/[0-1]?[0-9]\:?[0-5][0-9] ?[ap]?m?/)==-1 )
		return null;

	// find hour
	var strHour = "";
	var nMinStartingPosition = -1;
	// the inString has a colon
	if( lTime.search(":") > -1 ) {
		strHour = lTime.substr( 0, lTime.search(":") );
		nMinStartingPosition = lTime.search(":") + 1;
	}
	// the string does NOT have a colon,
	// if the fourth character is a number,
	// then the hour is two characters long
	else if( lTime.length>=4 && lTime.charAt(3).search(/[0-9]/)>-1 ) {
		strHour = lTime.substr( 0, 2 );
		nMinStartingPosition = 2;
	}
	// the hour is only one character long
	else {
		strHour = lTime.substr( 0, 1 );
		nMinStartingPosition = 1;
	}

	// find min, it must be two characters long
	var strMin = lTime.substr( nMinStartingPosition, 2 );

    strHour = parseInt(parseFloat(strHour));
    strMin = parseInt(parseFloat(strMin));
    
	if( isNaN(parseInt(strHour)) || isNaN(parseInt(strMin)) ||
		parseInt(strHour)<1 || parseInt(strHour)>12 ||
		parseInt(strMin)<0 || parseInt(strMin)>59 )
		    return null;

    // find am/pm
	if( lTime.search(/[pP]/) > -1 ) {
	    if( strHour != 12 )
   			strHour += 12;
	}
    else if( lTime.search(/[aA]/) > -1 ) {
        if( strHour == 12 )
        	strHour = 0;
	}
	// if no am/pm entered, guess what it should be for a typical school day
	else if( strHour>=1 && strHour<6 ) {
		strHour += 12;
	}
	strHour = strHour%24;
	
	return new Array( strHour, strMin );

} // ProcessTime()

var menu=function(){
    var TIMER=200,HOVERID,IFRAME;
    function dd( ulid ){
        this.ULID = ulid;
        this.HEADER=[];
        this.DDLIST=[]
    }
	dd.prototype.init=function( ulid, hoverid ){
        IFRAME = document.getElementById("coverup");
        HOVERID=hoverid;
        var w=document.getElementById( ulid );
        var s=w.getElementsByTagName('ul');
		for( var i=0; i < s.length; i++ ){
            var header=s[i].parentNode;
            this.HEADER[i]=header;
            this.DDLIST[i]=s[i];
            header.onmouseover = new Function(this.ULID+'.starttimer('+i+',true)');
            header.onmouseout = new Function(this.ULID+'.starttimer('+i+',false)');
		}
	}
	dd.prototype.starttimer=function(x,f){
	    var ddlist = this.DDLIST[x];
        var header = this.HEADER[x];
        var title = header.getElementsByTagName('a')[0];
        clearTimeout( ddlist.timer )
        if( f ){
            //In TIMER miliseconds, make the list visible
            ddlist.timer = setTimeout(function(){showlist(ddlist, header, true)},TIMER)
	    }
	    else{
	        //Stop the timer.
            ddlist.timer = setTimeout(function(){showlist(ddlist, header, false)},0)
	    }
	    return;
    }
    function showlist(ddlist, header, f){
        var title = header.getElementsByTagName('a')[0];
        if( f ){
            ddlist.style.display='block';
            ddlist.style.overflow='visible';
            ddlist.style.opacity= 1;
            ddlist.style.display= 'block';
            if( title.className.indexOf(HOVERID) != -1 )
                title.className += ' '+HOVERID;
            if( isIE ){
                IFRAME.style.display = "block";
                IFRAME.style.left = (header.offsetLeft-3) + "px";
                IFRAME.style.top = "80px";
                IFRAME.style.width = ddlist.offsetWidth + "px";
                IFRAME.style.height = ddlist.offsetHeight + "px";
            }
        }
        else{
            ddlist.style.overflow='hidden';
            ddlist.style.display= 'none';
            ddlist.style.opacity=0;
            title.className=title.className.replace(' ' + HOVERID,'');
            if( isIE ){
                IFRAME.style.display = "none";
            }
        }
    }
	return{dd:dd}
}();


  
//this function returns "" as succes,
// or a string explaining why it failed.
function jsVerifyDate(objName, bCorrectFormatting, bFourDigitYear, lstrDelimeter) {
	if(lstrDelimeter == null || lstrDelimeter == "")
		lstrDelimeter = "/";
		
	var strDatestyle = "US"; //United States date style
	//var strDatestyle = "EU";  //European date style
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var datefield = objName;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr; 
	var strMonthArray = new Array( "Jan", "Feb", "Mar", "Apr", "May"
				, "Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	strDate = datefield.value;
	if (strDate == null || strDate=="" || strDate.length < 1) {
		return 0;
	}
	
	var booFound = false;
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) {
				return 1;
			}
			else {
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true; 
		}
	}
	if (booFound == false) {
		if (strDate.length>5) {
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
		else 
			return "date incomplete"
	}
	if (strYear.length == 2) {
		if(isNaN(strYear))
			return 4;
		if( strYear == "19")
			return "year incomplete"
		else if( strYear == "20")
			return "year incomplete"
		else if(parseInt(strYear) > 50)
			strYear = '19' + strYear;
		else
			strYear = '20' + strYear;
	}
	else if(strYear.length == 1 || strYear.length == 3)
		return "year incomplete"
	// US style
	if (strDatestyle == "US") {
		var strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	} 
	
	intday = parseInt(strDay, 10);
	if (isNaN(intday)) { 
		return 2;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) {
		//if the month is given as a string (NOV) then convert it to a number
		for (i = 0;i<12;i++) {
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
			}
		}
		if (isNaN(intMonth)) { 
			return 3;
		}
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) { 
		return 4;
	}
	if (intMonth>12 || intMonth<1) { 
		return 5;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
		return 6;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
		return 7;
	}
	if (intMonth == 2) {
		if (intday < 1) { 
			return 8;
		}
		if (LeapYear(intYear) == true) {
			if (intday > 29) { 
				return 9;
			}
		}
		else {
			if (intday > 28) { 
				return 10;
			}
		}
	}
	var tempDate = new Date(intMonth + "/" + intday + "/" + strYear);
	if( tempDate < new Date("1/1/1900"))
		return "date out of range";
	if(tempDate > new Date("12/31/2099"))
		return "date out of range";
	
	if(bCorrectFormatting){
		if(!bFourDigitYear) 
			strYear = strYear.substr(2);
		if (strDatestyle == "US")
			datefield.value = intMonth + lstrDelimeter + intday + lstrDelimeter + strYear;
		else
			datefield.value = intday + lstrDelimeter + strMonthArray[intMonth-1] + lstrDelimeter + strYear;
	}
	return "";
}
function LeapYear(intYear) {
	if (intYear % 100 == 0) {
		if (intYear % 400 == 0) 
			return true;
	}
	else {
		if ((intYear % 4) == 0)
			return true;
	}
	return false;
} 
//  End --> 

function TEIsNumeric(lValue, lbIntegerOnly, lbPositiveOnly){
	if(lValue == null || lValue=="" || typeof lValue=="undefined")
		return false;
		
	if(lbIntegerOnly && lValue.indexOf(".")!=-1)
		return false;
	 
	if(lbPositiveOnly && lValue < 0)
		return false;

	if(isNaN( lValue) )
		return false;
	
	return true;
}


function findPos(obj) {
	var pos = new Object;
	pos.left = 0;
	pos.top = 0;
	
	if(obj!=null){
		if (obj.offsetParent)	{
			while (obj.offsetParent) {
				pos.left += obj.offsetLeft;
				pos.top  += obj.offsetTop;
				obj = obj.offsetParent;
			};
		}	
		else if (obj.x) {
			pos.left = obj.x;
			pos.top = obj.y;
		};
	}
	return pos;
};

function getScreenSize(){
	var pos = new Object;
	pos.width = 0;
	pos.height = 0; 
	 
	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 
	 if (typeof window.innerWidth != 'undefined')
	 {
	      pos.width = window.innerWidth,
	      pos.height = window.innerHeight
	 }
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	
	 else if (typeof document.documentElement != 'undefined'
	     && typeof document.documentElement.clientWidth !=
	     'undefined' && document.documentElement.clientWidth != 0)
	 {
	       pos.width = document.documentElement.clientWidth,
	       pos.height = document.documentElement.clientHeight
	 }
	 
	 // older versions of IE
	 
	 else
	 {
	       pos.width = document.getElementsByTagName('body')[0].clientWidth,
	       pos.height = document.getElementsByTagName('body')[0].clientHeight
	 }
	 return pos;
 }
 
function getScrollOffset() {
    var dim = new Object()
    dim.width = 0
    dim.height = 0;
  
    if (self.pageYOffset) // all except Explorer
    {
    	dim.width = self.pageXOffset;
    	dim.height = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop)
    	// Explorer 6 Strict
    {
    	dim.width = document.documentElement.scrollLeft;
    	dim.height = document.documentElement.scrollTop;
    }
    else if (document.body) // all other Explorers
    {
    	dim.width = document.body.scrollLeft;
    	dim.height = document.body.scrollTop;
    }
    return dim;
} 

function getPageSize() {
    var dim = new Object()
    dim.width = 0
    dim.height = 0;
     
    if (document.body.scrollHeight > document.body.offsetHeight) 
    	dim.height = document.body.scrollHeight; 
    else
    	dim.height = document.body.offsetHeight;
    	
    if (document.body.scrollWidth > document.body.offsetWidth) 	
    	dim.width = document.body.scrollWidth; 
    else  
    	dim.width = document.body.offsetWidth; 
    
    return dim;
}

function getParentWindowSize() {
  var dim = new Object()
  dim.width = 0
  dim.height = 0;
  if( typeof( parent.window.innerWidth ) == 'number' ) {
    //Non-IE
    dim.width = parent.window.innerWidth;
    dim.height = parent.window.innerHeight;
  } else if( parent.document.documentElement && ( parent.document.documentElement.clientWidth || parent.document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    dim.width = parent.document.documentElement.clientWidth;
    dim.height = parent.document.documentElement.clientHeight;
  } else if( parent.document.body && ( parent.document.body.clientWidth || parent.document.body.clientHeight ) ) {
    //IE 4 compatible
    dim.width = parent.document.body.clientWidth;
    dim.height = parent.document.body.clientHeight;
  }
  return dim;
}

function resizeParent() { 
 	var elem = parent.document.getElementById('edit_popup')
 	if(elem ==null)
 		return;
 	elem.style.display="";
 		
	var windowSize = getParentWindowSize(); 
	var pageSize = getPageSize();   
 		

// 	height += elem.style.paddingTop + elem.style.paddingBottom
	elem.style.height = document.body.offsetHeight + "px";
 	var height = document.body.scrollHeight;
 	if(isIE)
		height += 8;
	elem.style.height = height + "px";  
	
	var width = pageSize.width; 
 	elem.style.width = width + "px";   
	
	
		// center popup, if it can fit on the entire screen. 
	var top =  (windowSize.height - height )/2       
 	if(top < 0)
 		top = 5;
 	top += parent.document.body.scrollTop;  
	var left = (windowSize.width - width )/2  
 	if(left < 0)
 		left = 5; 
	elem.style.top = top  + "px";
	elem.style.left = left + "px";
	
	return false;
}
function dropIframe(){
    var popup = document.getElementById("edit_popup");
    if(popup != null){
	    var containerElem = document.getElementById("page_contents"); 
		if(containerElem != null && containerElem.tagName!='TABLE') 
		    containerElem.removeChild( popup ); 
		else
		    document.body.removeChild( popup );  
	}
	
    var trans = document.getElementById("edit_trans");
    if(trans != null)
	    document.body.removeChild(trans);

	var coverFrame = document.getElementById("edit_coverup");
	if(coverFrame != null)
	    document.body.removeChild(coverFrame);
}
function addIframe(url){ 
    fResetTimeout();
    // Create an overlay to darken the area behind the popup
    var coverFrame = null;
	var page =  getPageSize()
/*	//there is some way to fix select boxes from showing through the transparent div....for now this is not working
	if(false && BrowserDetect.browser == "Explorer" && BrowserDetect.version == 6){  
    	coverFrame = document.createElement( "iframe" );
		coverFrame.src = "../common/blank.html";
	    coverFrame.setAttribute( 'id', 'edit_coverup' );   
    	coverFrame.className = "coverup" ;   
    	coverFrame.style.zIndex=10;   
	    coverFrame.style.display = ""  
	    coverFrame.style.backgroundColor = "red";
		document.body.appendChild( coverFrame ); 
    }*/
    var new_fade = document.createElement( "div" );
    new_fade.setAttribute( 'id', 'edit_trans' );  
    new_fade.setAttribute( 'class', 'transparency' );
    new_fade.setAttribute("className", "transparency");
	new_fade.style.cursor = "wait";	 
	document.body.appendChild( new_fade );
	new_fade.style.cursor = "";	  
	
 	var new_iframe = document.createElement( "iframe" );
    new_iframe.setAttribute( 'id', 'edit_popup' );
	new_iframe.setAttribute( 'src', url );
        
    new_iframe.setAttribute( 'class', 'popup_iframe' );
    new_iframe.setAttribute( 'className', 'popup_iframe' ); 
       
    new_iframe.style.position = 'absolute'; 
    new_iframe.style.display = "none";
     

//it is best to add the iframe to the page_contents div so that the css is properly inherited
    var containerElem = document.getElementById("page_contents");
    // add the widget and overlay to the page
	if(containerElem != null && containerElem.tagName!='TABLE') 
	    containerElem.appendChild( new_iframe ); 
	else
	    document.body.appendChild( new_iframe ); 
	
    new_fade.style.height = page.height;
    new_fade.style.width = page.width; 
}

function getWindowSize() {
  var dim = new Object()
  dim.width = 0
  dim.height = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    dim.width = window.innerWidth;
    dim.height = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    dim.width = document.documentElement.clientWidth;
    dim.height = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    dim.width = document.body.clientWidth;
    dim.height = document.body.clientHeight;
  }
  return dim;
}  
function TEGetAjaxObject( url, argsToPost, onReadyStateChangeFunctionName, lbAsync ) { 
    fResetTimeout(); 
    try { 
        ajaxObject = new ActiveXObject("Msxml2.XMLHTTP");	// new IE 
    }  
    catch (e) { 
        try { 
            ajaxObject = new ActiveXObject("Microsoft.XMLHTTP"); // old IE 
        }  
        catch (e2) { 
            try { 
                ajaxObject = new XMLHttpRequest();	// Firefox   
            }  
            catch(e3) { 
                ajaxObject = null;   
            } 
        } 
    }	// ends Try/Catch block 
    if(lbAsync!=false && lbAsync!=0 ) 
    lbAsync=true 
    if(!lbAsync && onReadyStateChangeFunctionName != null) 
        alert('do not send in onReadyStateChangeFunctionName when lbAsync is false'); 
    if( ajaxObject != null ) {  
        ajaxObject.open("POST", url, lbAsync );  // Open a connection to the server 
        if(onReadyStateChangeFunctionName != null) 
            ajaxObject.onreadystatechange = onReadyStateChangeFunctionName;  // Setup a function for the server to run after the ajax submit returns      
        ajaxObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded');   
        ajaxObject.send(argsToPost);	 
    }// lObjName !=null 
    return ajaxObject; 
}


//lID: The id of your div, if it already exists it will not create anything
//lHTML: What you want to appear in the div
//lWidth: Default is 350. Set in px
//lHeight: Default is 50. Set in px
//lbVisible: Good for creating divs at page load and showing them later on. 
//      Sometimes animated gif might not animate on submitting pages as the image
//      isn't fully loaded when created at page submit.
//lTopOffset: Will place in the middle of the window if not passed in
//lLeftOffset: Will place in the middle of the window if not passes in
//lbShowLoadingIcon: Places a loading icon and your html in a table. You can acheive
//          the same effect by passing in the table an icon and your message as lHTML instead
//NOTE: If you want to add a div at page creation you need to place this function in bodycode as IE
//      will not allow you to dynamically append DOM objects while the DOM tree is being built.
//      Depending on your page setup, you may need to display the image AFTER you submit the page as IE
//      will freeze the animation if it is placed before the submit. ImportExportPictures.aspx has an example...
function popUpDiv( lID, lHTML, lWidth, lHeight, lbVisible, lTopOffset, lLeftOffset, lbShowLoadingIcon ) {
   
	var newdiv = document.getElementById(lID);
	if( newdiv==null ){
	    var newdiv = document.createElement('div');
	    newdiv.setAttribute('id', lID);
	    newdiv.setAttribute( 'class', 'popup_div');
	    newdiv.setAttribute( 'className', 'popup_div'); 

	//it is best to add the popup to the page_contents div so that the css is properly inherited
	    var containerElem = document.getElementById("page_contents"); 
		if(containerElem != null && containerElem.tagName!='TABLE') 
		    containerElem.appendChild( newdiv ); 
		else
		    document.body.appendChild( newdiv ); 
    
    } 
        
    if (lbShowLoadingIcon) {
        newdiv.innerHTML = "<table border=0 cellpadding=3 cellspacing=0 width=100% height=100% ><tr valign=middle>"
            + "<td><img id=img" + lID + " src=\"../images/LoadingAnimatedClearLarge.gif\"></td>"
            + "<td>" + lHTML + "</td></tr></table>";
    }
    else
        newdiv.innerHTML = lHTML;
    
    if( isNaN(parseFloat(lWidth))==false )
        newdiv.style.width = lWidth; 

    if( isNaN(parseFloat(lHeight))==false )
        newdiv.style.height = lHeight; 
        
    var ScrollPos = getScrollOffset();    
    var scrolledX = ScrollPos.width;
    var scrolledY = ScrollPos.height;
    
    // Next, determine the coordinates of the center of browser's window
    var ScreenPos = getScreenSize();
    var centerX = ScreenPos.width;
    var centerY = ScreenPos.height;

    // Xwidth is the width of the div, Yheight is the height of the
    // div passed as arguments to the function:
    newdiv.style.display = '';
    var topoffset = (isNaN(parseFloat(lTopOffset))==false?lTopOffset:scrolledX + (centerX - parseInt(newdiv.offsetHeight)) / 2);
    var leftoffset = (isNaN(parseFloat(lLeftOffset))==false?lLeftOffset:scrolledY + (centerY - parseInt(newdiv.offsetWidth )) / 2);

    if( !lbVisible )
        newdiv.style.display = 'none';
    else
        newdiv.style.display = '';
        
    if( isNaN(parseFloat(topoffset))==false )
        newdiv.style.top = topoffset + 'px';
    if( isNaN(parseFloat(leftoffset))==false )
        newdiv.style.left = leftoffset + 'px';

    return newdiv;
}

/*
http://www.quirksmode.org/js/detect.html
*/
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"
		}
	]

};
BrowserDetect.init();

function submitForm(f){ 
	if(f.onsubmit==null || f.onsubmit(f)!=false){ 
		f.submit(); 
	}
}

