function getCookie(cookie_key) //getting cookie with the key cookie_key
{	
	var key_length=cookie_key.length;
	var cookie = document.cookie;
	var location_key=cookie.indexOf(cookie_key);
        if(location_key== -1) { return -1} //if key was not found
        var cookie_pos = cookie.indexOf(";", location_key+key_length+1); //find next cookie
	if(cookie_pos !== -1) //if it's last cookie
	{
		value_of_key=cookie.substring(location_key+key_length+1, cookie_pos);
	}
	else //if cookie is in the middle
	{
		value_of_key=cookie.substring(location_key+key_length+1, (cookie.length));
	}
	return value_of_key;
}
function setCookie(cookie_key, cookie_value, cookie_expiration_date, cookie_path)
{
	var cookie_string=cookie_key +"="+cookie_value;
	//Expiration date
	if(cookie_expiration_date)
	{
		var expire_date = new Date();
		var ms_from_now=cookie_expiration_date*24*60*60*1000;
		expire_date.setTime(expire_date.getTime()+ms_from_now);
		var expire_string=expire_date.toGMTString();
		cookie_string+="; expires="+expire_string;
	}
	//if path was specified
	if(cookie_path)
	{
		cookie_string+="; path="+cookie_path;
	}
	document.cookie=cookie_string;
}
function deleteCookies()
{
	var cookie_pair;
	var cookie_name;
	var cookie_array=document.cookie.split("; ");
	for(counter=0; counter<cookie_array.length; counter++)
	{
		cookie_pair=cookie_array[counter].split("=");
		cookie_name=cookie_pair[0];
		setCookie(cookie_name, "", -1, "/");
		setCookie(cookie_name, "", -1);
	}
}
