﻿function hasCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0){
			return true;
		}
	}
	return false;
}

function readCookie(c_name){
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++){
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x==c_name){
			return unescape(y);
		}
	}
}

/*function createCookie(c_name, value, path, exdays){
	alert("creating cookie");
	var	cookiePath;
	var exdate=new Date();
	if(exdays){
		exdate.setDate(exdate.getDate() + exdays);
	}else{
		exdate = 0;
	}
	
	if(path){
		cookiePath = path;
	}else{
		cookiePath = "/";	
	}
	
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()) + "; path=" + cookiePath;
	
	document.cookie=c_name + "=" + c_value;
	
}*/

function createCookie(name,value,days,sitePath) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	
	var pathForCookie;
	if(sitePath){
		pathForCookie = sitePath;	
	}else{
		pathForCookie = "/";	
	}
	
	document.cookie = name+"="+value+expires+"; path=" + pathForCookie;
}


function eraseCookie(name) {
	createCookie(name,"",-1);
}
