//Generic Popup window
function popUp(path,wname) 
{
	newWin=eval("window.open('"+path+"',wname,'width=600,height=580,left=340,top=187,screenX=10,screenY=100,scrollbars=1,toolbar=0,location=0,status=1,menubars=0,resizable=0')")
}

//Help Popup window
function popUpHelp(path,wname) 
{
	newWin=eval("window.open('"+path+"',wname,'width=600,height=500,left=340,top=187,screenX=10,screenY=100,scrollbars=1,toolbar=0,location=0,status=1,menubars=0,resizable=0')")
}

//Select all checkbox for the multiple select search results grid
function SelectAllCheckboxes(spanChk)
{
    var oItem = spanChk.children;
    var theBox=(spanChk.type=="checkbox")?spanChk:spanChk.children.item[0];
    xState=theBox.checked;
    elm=theBox.form.elements;
    for(i=0;i<elm.length;i++)
        if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
        {
            if(elm[i].checked!=xState)
            elm[i].click();
        }
}

// Show/hide a div. Used for collapsible sections/descriptions
// Toggles visibility of a div.
function showHideDiv(divName)
{
    o = document.getElementById(divName);
    
    if (o != null)
    {
        if (o.style.display=="none")
        {
            o.style.display="block";
            o.style.visibility="visible";
        }
        else
        {
            o.style.display="none";
            o.style.visibility="hidden";
        }
    }
}

// cookie functions

// Get Expiry Date in required format
function GetExpiryDate(numofdays)
{
	var UTCstring;
	Today = new Date();
	msec=Date.parse(Today);
	Today.setTime(msec+numofdays*24*3600*1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
}

// set cookie
function SetCookie(name,value,duration)
{
	cookiestring=name+"="+escape(value)+";EXPIRES="+GetExpiryDate(duration);
	document.cookie=cookiestring;
}

// retrieve cookie
function GetCookie(cookiename) 
{
	var cookiestring=""+document.cookie;
 	var index1=cookiestring.indexOf(cookiename);
 	if (index1==-1 || cookiename=="") return ""; 
 	var index2=cookiestring.indexOf(';',index1);
 	if (index2==-1) index2=cookiestring.length; 
 	return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

function checkRedirect()
{
	var redirUrl = GetCookie("LandcorRedir");
	if (redirUrl != "")
		window.location = redirUrl;
}

function saveRedirect(url)
{
	o = document.getElementById("saveSettings");
	if (o.checked == true)
	{
		SetCookie("LandcorRedir",url,60);
	}
} 