function pageLoadCommon()
{}


function ChangeImage(sDropDown,sBaseURL,sImage)
{

	var oDropDown=getobject(sDropDown);
	var sImageSrc;
	if(oDropDown.selectedIndex==0)
		sImageSrc="/common/images/misc/selectimage.gif";
	else
		sImageSrc=sBaseURL+oDropDown.options[oDropDown.selectedIndex].text;
	
   var ImageObject = new Image();
   ImageObject.src = sImageSrc;
  // alert(ImageObject.width);
   document.images[sImage].src=ImageObject.src;
   //document.images[sImage].width=ImageObject.width;
   //document.images[sImage].height=ImageObject.height;


}
 
function CheckAllItems(obj,iNumItems,bCheck,bUnCheck)
{
	var sBase=obj.name.substring(0,obj.name.length-2);
	//alert(sBase);
	
	
	if(bCheck && obj.checked)
		bState=true;
	else if(bUnCheck && !obj.checked)
		bState=false;
	else
		return;
	
	
	for(var i=0; i< iNumItems; i++)
	{
		if(getobject(sBase + ":" + i))
			getobject(sBase + ":" + i).checked=bState;
	
	}
	
} 

function CheckAllItemsA(sPrefix,sSuffix,iStartID,iNumItems,bCheck)
{
	 
	
	for(var i=iStartID; i<iStartID+iNumItems; i++)
	{
		var cb=getobject(sPrefix + i + sSuffix)
		 
		if(cb)
			cb.checked=(bCheck && !cb.disabled);
	 
	}
	
} 

function IsAtLeastOneCheckBoxChecked(sPrefix,sSuffix,iStartID,iNumItems)
{
	
	for(var i=iStartID; i<iStartID+iNumItems; i++)
	{
		if(getobject(sPrefix + i + sSuffix).checked)
			return true;
	
	}
	
	return false;
	
}

function redirectToLogOut(iLogoutType)
{
		redirect('/common/pages/noauth/Logout.aspx?mode=' + iLogoutType);


}

function logout()
{
	if(confirm('Are you sure you want to logout?'))
		redirectToLogOut(0);
} 

function LaunchEditor(f)
{
	objf=getobject(f)
	 var myObject = new Object();
    myObject.field = objf.value;
	winEditor=window.open("Editor.aspx?popup=1","winEditor","width=790,height=600,scrollbars=yes,resizable=yes,toolbar=yes,menubar=yes,location=yes");

	//var resp = window.showModelessDialog("Editor.aspx", myObject, 'dialogWidth:400px;dialogHeight:650px;center:Yes;help:No;resizable:No;status: No;'); 
	//if (resp=="1") { objf.value= myObject.field ; };
	//event.returnValue = false;


}


//logout warning code
var AUTOLOGOUT_CLIENTSIDE_TRIGGER_ENABLED = 0;
var AUTOLOGOUT_CLIENTSIDE_TRIGGER_TIMEOUT_ID;



function autologoutClientsideTriggerStart(iMinsUntilExpiry) {
  var alertTime = 5;//parseInt(document.getElementById('edit-alert_time').value);
  //var displayTime = 2;//parseInt(document.getElementById('edit-alert_time').value);
  
	AUTOLOGOUT_CLIENTSIDE_TRIGGER_ENABLED = 1;
	autologoutClientsideTriggeriMinsUntilExpiry(iMinsUntilExpiry,alertTime);	
  
}
	 


function doLogoutCallback()
{
   //this makes sure user is actually logged out before redirecting to logout, possible that they have multiple windows open
   var oXMLHttpObject=getXMLHttpObject();
   
   if(oXMLHttpObject)
   {
		
		oXMLHttpObject.open("POST", "http://" + document.location.host + "/common/sys/auth.asmx/IsAuthenticated", false);
		oXMLHttpObject.setRequestHeader("Cookie", document.cookie);
		oXMLHttpObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        oXMLHttpObject.send("x"); //must send something
        
        //look for false in the response
        var sResponse=oXMLHttpObject.responseText;
        //alert(sResponse);
        if(sResponse.indexOf("false") > 0)
			redirectToLogOut(1);
   }
   else
   {
		redirectToLogOut(1);

	}
}


function autologoutClientsideTriggeriMinsUntilExpiry(iMinsUntilExpiry,alertTime) {
	if(getobject("divLOWarn"))
	{	
		if (iMinsUntilExpiry <= alertTime)
		{
		var sText="Current session will expire in " + (iMinsUntilExpiry > 0 ? iMinsUntilExpiry : 0) + " minute";
		if(iMinsUntilExpiry > 1)
			sText+="s";
		
		sText+=" (this is reset by visiting another page).";
		
		getobject("divLOWarn").innerHTML= sText;
		
		
			getobject("divLOWarn").className="LogOutExpiryAlert";
		}
	/*
		var sText="Current session will expire in " + (iMinsUntilExpiry > 0 ? iMinsUntilExpiry : 0) + " minute";
		if(iMinsUntilExpiry > 1)
			sText+="s";
		
		sText+=" (this is reset by visiting another page).";
		
		getobject("divLOWarn").innerHTML= sText;
		
		if (iMinsUntilExpiry <= alertTime)
			getobject("divLOWarn").className="LogOutExpiryAlert";
		else
			getobject("divLOWarn").className="LogOutExpiry";
			*/
	}
		
	
	
	
  if (iMinsUntilExpiry <= 0) {
    clearTimeout(AUTOLOGOUT_CLIENTSIDE_TRIGGER_TIMEOUT_ID);
    doLogoutCallback();
  }
  
  if (AUTOLOGOUT_CLIENTSIDE_TRIGGER_ENABLED) {
    iMinsUntilExpiry --;
    AUTOLOGOUT_CLIENTSIDE_TRIGGER_TIMEOUT_ID = setTimeout('autologoutClientsideTriggeriMinsUntilExpiry(' + iMinsUntilExpiry + ', ' + alertTime + ')', 60000);
  }
}

function SwapMenusA(sel,qs)
{
	
	var id=sel.options[sel.selectedIndex].value;
	
	if(id=="")
		return;
		
	var url="/default.aspx?" + qs + "=" + id;
	
	if(document.location.href.toLowerCase().indexOf("default.aspx")==-1 && id!="-1")
	{
		if(confirm("This will change the menus and redirect to the home page. You may lose any unsaved work on the current page. Continue?"))
			document.location.href=url;
		else
		{
			//reset dropdpwn
			for (var i=0; i<sel.options.length; ++i)
            {
				if(sel.options[i].defaultSelected)
				{
					sel.options[i].selected = true;
					break; 
				}
                   
            }

		}
			
	}
	else
			document.location.href=url;


} 
	 

                
//function autologoutClientsideTriggerAlert() {
//if(getobject("divLOWarn"))
	
  //alert(document.getElementById('edit-alert_text').value);
//}