
function getCookie(w){
	cName = "";
	pCOOKIES = new Array();
	pCOOKIES = document.cookie.split('; ');
	for(bb = 0; bb < pCOOKIES.length; bb++){
		NmeVal  = new Array();
		NmeVal  = pCOOKIES[bb].split('=');
		if(NmeVal[0] == w){
			cName = unescape(NmeVal[1]);
		}
	}
	return cName;
}


function printCookies(w){
	cStr = "";
	pCOOKIES = new Array();
	pCOOKIES = document.cookie.split('; ');
	for(bb = 0; bb < pCOOKIES.length; bb++){
		NmeVal  = new Array();
		NmeVal  = pCOOKIES[bb].split('=');
		if(NmeVal[0]){
			cStr += NmeVal[0] + '=' + unescape(NmeVal[1]) + '; ';
		}
	}
	return cStr;
}


function setCookie(name, value, expires, path, domain, secure){
	document.cookie = name + "=" + escape(value) + "; ";
	
	if(expires){
		expires = setExpiration(expires);
		document.cookie += "expires=" + expires + "; ";
	}
	if(path){
		document.cookie += "path=" + path + "; ";
	}
	if(domain){
		document.cookie += "domain=" + domain + "; ";
	}
	if(secure){
		document.cookie += "secure; ";
	}
}


function setExpiration(cookieLife){
    var today = new Date();
    var expr = new Date(today.getTime() + cookieLife * 24 * 60 * 60 * 1000);
    return  expr.toGMTString();
}



// >>> set a session cookie which will expire when the browser is closed
//setCookie('hasVisited', 'Yes');

// get the value of a cookie already set
//cookieValue = getCookie('hasVisited');

//alert(cookieValue) // Yes

// set a cookie which will expire in 1 day
////setCookie('hasVisitedToday', 'Yes', 3);

// set a cookie which will expire in 3 days and be accessible site wide
////setCookie('hasVisitedSite', 'Yes', 3, '/');

// set a cookie which will expire in 3 days and be accessible only while 
// in the 'members' folder
////setCookie('cookieName', 'cookieValue', 3, '/members');

// set a cookie which will expire in 3 days and be accessible only while 
// in the 'members' folder, and will be transmitted securely
////setCookie('cookieName', 'cookieValue', 3, '/members', '', 1);

// >>> set a cookie which will expire in 365 days and be accessible site wide
// >>> and set the domain name
////setCookie('RememberMe', 'RememberMyAge', 365, '/', 'garnish.dk');

// print all cookies set for the domain
//allCookies = printCookies();
//document.write(allCookies);
//alert(allCookies);

// >>> delete a specific cookie by setting it's expiration date to the past
// >>> and defining a blank value
////setCookie('cookieName', '', -1);



// set a new cookie
//setCookie('cookieName', 'cookieValue', 3, '/', '.perlscriptsjavascripts.com');

// delete the same cookie, by setting a negative date
//setCookie('cookieName', '', -1, '/', '.perlscriptsjavascripts.com');

// this will NOT delete the cookie, because the path differs 
//setCookie('cookieName', '', -1, '', '.perlscriptsjavascripts.com');




