// текущая дата и время в формате для cookie
function curr_date_cookie() {
	var date = new Date();
	return date.toGMTString();
}

// некоторый срок начиная от текущей даты и времени в формате для cookie
function exp_date_cookie(years,months,days,hours,mins,secs) {
	var date = new Date();
	if(years) date.setFullYear(date.getFullYear() + years);
	if(months) date.setMonth(date.getMonth() + months);
	if(days) date.setDate(date.getDate() + days);
	if(hours) date.setHours(date.getHours() + hours);
	if(mins) date.setMinutes(date.getMinutes() + mins);
	if(secs) date.setSeconds(date.getSeconds() + secs);
	return date.toGMTString();
}

// устанавливаются дата и время в формате для cookie
function date_cookie(year,month,day,hour,min,sec) {
	var date = new Date(year,month,day,hour,min,sec);
	return date.toGMTString();
}


// получаем значение cookie с заданным именем
function get_cookie(name) {
	var s_str = name + "=";
	var s_str_len = s_str.length;
	var s_str_pos;
	var d_str_pos;
	var val;

	s_str_pos = document.cookie.indexOf(s_str);
	if(s_str_pos != -1) {
		d_str_pos = document.cookie.indexOf(";",s_str_pos + s_str_len);
		if(d_str_pos != -1) {
			val = document.cookie.substring(s_str_pos + s_str_len, d_str_pos);
		} else {
			val = document.cookie.substring(s_str_pos + s_str_len, document.cookie.length);
		};
		return unescape(val);
	} else {
		s_str = name + ";";
		s_str_pos = document.cookie.indexOf(s_str);
		if(s_str_pos != -1) {
			return "";
		} else {
			return null;
		};
	};
}

// устанавливаем cookie
function set_cookie(name,value,expires) {
	document.cookie = name + 
	((value) ? ("=" + escape(value)) : "") + 
	((expires) ? ("; expires=" + expires) : "");
}

// устанавливаем cookie (полный вариант)
function set_cookie_ex(name,value,expires,path,domain,secure) {
	document.cookie = name + 
	((value) ? ("=" + escape(value)) : "") + 
	((expires) ? ("; expires=" + expires) : "") + 
	((path) ? ("; path=" + path) : "") + 
	((domain) ? ("; domain=" + domain) : "") + 
	((secure) ? ("; secure=" + secure) : "");
}

// удаление cookie путем присвоения прошедшей даты
function delete_cookie(name,path,domain) {
	var t = ((path) ? ("; path=" + path) : "") + 
	((domain) ? ("; domain=" + domain) : "") + 
	"; expires=Thu, 01 Jan 70 00:00:01 GMT";
	document.cookie = name + "=del" + t;
	document.cookie = name + t;
}
