//-------------------------------------------------------------
//cookies.js
//Mike Harris
//Feb 2007
//
//Description: Basic Cookies handling functions.
//--------------------------------------------------------------

//sets a cookie
//Takes: expireDays-num days till this cookie expires set -1 for a temp cookie, name-required,value-required
function setCookie(name,value,expiredays,domain){
	var newCookieString="";	
	if(name){
		newCookieString=name+"="+value+"; ";		
		if(expiredays){
			if(expiredays>=-1){				
				var dateobj = new Date();				
				dateobj.setTime(dateobj.getTime()+(expiredays*24*60*60*1000));				
				newCookieString+="expires="+dateobj.toGMTString()+"; ";
			}}		
		if(domain)
			newCookieString+="domain="+domain+"; ";			
		document.cookie = newCookieString;		
	}
}//end setcookie

//returns cookie value or null if cookie not found
function getCookie(cookiename){	
	var cookiestring = document.cookie;
	var idxStart=-1;var targetCookie;	
		
	if(cookiestring.indexOf(cookiename)>=0 && cookiestring!="")	{
		idxStart =cookiestring.indexOf(cookiename);
		targetCookie = cookiestring.substring(idxStart,cookiestring.length);
				
		if(targetCookie.indexOf(";")>0)
			targetCookie=targetCookie.substring(0,targetCookie.indexOf(";"));		
		return  targetCookie.substring(targetCookie.indexOf("=")+1,targetCookie.length);	
	}
	else 
		return null;	
}//end getcookie

//deletes a cookie
function deleteCookie(cookname)
{setCookie(cookname,"",-1,"");}
