//
// File : cookies.js
//
// Description : Javascript functions for working with cookies
//
// Contents    : 
//               setCookie
//               getCookie

    //
    // set a cookie
    //
    function setCookie(name,value) {
        var today = new Date();
        var cookie_expire_date = new Date(today.getTime() + (30 * 7 * 86400000)); 
    
        var cookieString = name + "=" +escape(value) +";expires=" + cookie_expire_date.toGMTString() ;
        cookieString += ";path=/";
        document.cookie = cookieString;
    } 
        
    //
    // get a cookie
    //
    function getCookie(name) {
       var start = document.cookie.indexOf(name+"=");
       var len = start+name.length+1;
       if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
       if (start == -1) return null;
       var end = document.cookie.indexOf(";",len);
       if (end == -1) end = document.cookie.length;
       var value = unescape(document.cookie.substring(len,end));
       if(value == null || value == "null") value = "";
       return value;
    }
    
    //
    // returns true if the current browser will take cookies
    //
    function takesCookies()	{
	    var getsCookie = (navigator.cookieEnabled)?true:false
	    // If the browser does not support cookie check
    	if(typeof navigator.cookieEnabled=="undefined" && !cookieEnabled)   {	
	        // Try setting up a test cookie
	        document.cookie = "SampleCookie";

    	    // And see if it got set successfully
	        getsCookie = (document.cookie.indexOf("SampleCookie")!=-1)?true:false
    	}
    	
	    return getsCookie;
	}

 
	// if cookies are disabled, this function 
	// will prompt the user that they must enable cookie functionality
	// in order for the page to complete their requests
	function cookiesRequiredPrompt()  {
	    if(!takesCookies())   {
	        alert("This page requires that you enable cookies in order for it to complete your requests.");
	    }
	}
	
	
	//
	// this deletes the cookie when called
	//
	function deleteCookie( name ) {
		if ( getCookie( name ) ) 
			document.cookie = name + "=" +";path=/;expires=Thu, 01-Jan-1970 00:00:01 GMT";
    }
    
