function SetCookie(name, value, days, path, domain, secure){//добавляет или зменяет куки с полным набором параметров
	var today = new Date();
	var expString = (days) ? "; expires=" + new Date(today.getTime() + days*24*60*60*1000) : '';
	var pathString = ((path == null)? "" : ("; path=" + path));
	var domainString = ((domain == null)? "" : ("; domain=" + domain));
	var secureString = ((secure == true) ? ";secure" : "");
	document.cookie = name + "=" + escape(value) + expString + pathString + domainString + secureString;
}

function GetCookie(name){ //возвращает значение указанного куки или null, если куки не существует
	var result = null;
	var myCookie = " " + document.cookie + ";"	;
	var searchName = " " + name + "=";
	var startOfCookie = myCookie.indexOf(searchName);
	var endOfCookie;
	if(startOfCookie != -1){
		startOfCookie += searchName.length;
		endOfCookie = myCookie.indexOf(";",startOfCookie);
		result = unescape(myCookie.substring(startOfCookie,endOfCookie));
	}
	if((typeof(result) == 'string') && result == 'null')
		return null;
	return result;
}
function getExpDate(days, hours, minutes){
	var expDate = new Date();
	if( typeof days == "number" && typeof hours == "number" && typeof hours == "number" ){
		expDate.setDate(expDate.getDate() + parseInt(days));
		expDate.setHours(expDate.getHours() + parseInt(hours));
		expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
		return expDate.toGMTString();
	}
}
// Удаляет cookie.
function deleteCookie(name,path, domain) {
        if (getCookie(name)) {
                document.cookie = name + "=" + 
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                "; expires=Thu, 01-Jan-70 00:00:01 GMT"
    }	
  }
//Добавляет или заменяет cookie
function setCookie(name, value, expires, path, domain, secure)	{
 var expString = (expires==null) ? "" : ("; expires=" + new Date((new Date()).getTime()+expires*3600000));
 var pathString = ((path==null) ? "" : ("; path=" + path));
 var domainString = ((domain==null) ? "" : ("; domain=" + domain));
 var secureString = ((secure==true) ? "; secure" : "" );
 document.cookie = name + "=" + escape(value) + expString + pathString + domainString + secureString;
}
//Получение значения cookie.
function getCookie(name) {
        var prefix = name + "="
        var cookieStartIndex = document.cookie.indexOf(prefix)
        if (cookieStartIndex == -1)  return null
        var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
        if (cookieEndIndex == -1)  cookieEndIndex = document.cookie.length
        var rezult = unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
        if((rezult == "null")&&(typeof(rezult) == "string")) return null
        else return rezult
}
  
