
// this function gets the cookie, if it exists
function Get_Cookie(name) {

	if (document.cookie == '') { 
    
        // there's no cookie, so go no further
    
	    return false;

	} 
	else {
    
        // there is a cookie

	    var firstChar, lastChar;

	    var theBigCookie = document.cookie;

	    firstChar = theBigCookie.indexOf(name);
	
        // find the start of 'name'

	    if(firstChar != -1)  {
	
            // if you found the cookie

	        firstChar += name.length + 1;
	    
            // skip 'name' and '='
	   
	        lastChar = theBigCookie.indexOf(';', firstChar);
	    
            // Find the end of the value string (i.e. the next ';').
	    
	        if(lastChar == -1) lastChar = theBigCookie.length;
	    
	        return unescape(theBigCookie.substring(firstChar, lastChar));

	    } 
	    else {
	
            // If there was no cookie of that name, return false.
	
	        return false;
	
	    }
    }
}


//set cookie
function Set_Cookie( name, value, path, domain, secure ) {
    var exp;
    var expires = 1000 * 60 * 60;
    var d = new Date();
    var expTime = d.getTime() + expires;
    d.setTime(expTime);
    exp = d.toGMTString();
    var c = name + "=" + escape(value) 
             + ";expires=" + exp 
             + ";path=" + path ;
             if (domain != ""){ c += ";domain=" + domain }
             if(secure){ c += ";secure"; }
            
    document.cookie = c;
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
		( ( path ) ? ";path=" + path : "") +
		( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

// test cookie jar
function findCookie( name ){
    if( Get_Cookie( name ) ){ return true; }
    else { return false; }
}