

function getCookie(theName){
//alert("getCook " + theName);
	var theNameLen = theName.length;
    var theCookieLen = document.cookie.length;
    var cookieEnd;
    var i =0;
    
    while(i < theCookieLen){
        var stringPointer = i + theNameLen;        
        if(document.cookie.substring(i,stringPointer) == theName){
	         cookieEnd = document.cookie.indexOf(";",stringPointer);
	    	    if (cookieEnd == -1) {                                                      // end of cookie of the cookie was reached
	                cookieEnd = document.cookie.length;
	          }//if				  

	            return document.cookie.substring(stringPointer+1,cookieEnd);         // return the cookie
	     }//if  
         i++; 	
	}//while
    return ""  ;                                                                        // theName not found
}//getCookie

function clearFirstTime(){
    firstTime = true;
}  //clearFirstTime

function writeCookie(theName,theValue){ 
	document.cookie = theName + "=" + theValue;
}  //writeCookie

function writeCookie2(theName,theValue){ 
    var expiresDate = new Date();
    var oneDay = expiresDate.getTime() +(1 *24*60*60*1000);  // convert 1 day to seconds
    expiresDate.setTime(oneDay);        
	document.cookie = theName + "=" + theValue + "; expires = " + expiresDate.toGMTString();  //convert time to greenwich 
}  //writeCookie


function expire_date(days){ 
 //alert('here'); 
    var expiresDate = new Date();
    var expires = expiresDate.getTime() +(days *24*60*60*1000);  // convert days to seconds 
	expiresDate.setTime(expires); 
    return expiresDate;       
}// expire_date

function writeCookie3(theName,theValue,expires_days,path,domain,secure){
//alert("WC31" + theValue);
	expires = expire_date(expires_days);
	theValue = unescape(theValue);
//alert("WC32" + theValue);
	if((theName) && (theValue)){	
		document.cookie = theName + "=" + unescape(theValue) +
		((expires)  ?  "; expires=" + expires.toGMTString() : "") +	 
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") + 
		((secure) ? "; secure=" + secure : "");	
	}//if
	else {
		//alert("Please enter a name and value for the cookie");
		return;
	}//else	 
}//writeCookie3		
