﻿var iChecked = '/images/from-case.gif';
var iUnchecked = '/images/to-case.gif';

function getCookie(name, nf) {
	st = document.cookie.indexOf(name + '=');
	if (st == -1) return nf;
	return document.cookie.substring(st + name.length + 1).split(';')[0];
}

function setCookie(self, aid, doReload, eng) {
	var dtExpires = new Date();
	var dtExpiryDate = "";
	dtExpires.setTime(dtExpires.getTime() + 1 * (365 * 24 * 60 * 60 * 1000));
	dtExpiryDate = dtExpires.toGMTString();
	var SHExpiration = 'expires=' + dtExpiryDate;

	if (self.src.indexOf(iChecked) == -1) {
		document.cookie = 'Gazeta_cookies=bcase' + '=' + getCookie('bcase', '') + 's03_' + aid + ':' + ';'
			+ SHExpiration + ';' + 'path=/;domain=gazeta.kz;';
		self.src = iChecked;
	}
	else if (self.src.indexOf(iUnchecked) == -1) {
		var ck = getCookie('bcase', 0) + '';
		document.cookie = 'Gazeta_cookies=bcase' + '=' + ck.replace('s03_' + aid + ':', '') + ';'
			+ SHExpiration + ';' + 'path=/;domain=gazeta.kz;';
		self.src = iUnchecked;
	}
	else alert('error');
}

function setCookieText(self, aid, doReload, eng)
{
	var dtExpires = new Date();
	var dtExpiryDate = "";
	dtExpires.setTime(dtExpires.getTime() + 1 * (365 * 24 * 60 * 60 * 1000));
	dtExpiryDate = dtExpires.toGMTString();
	var SHExpiration = 'expires=' + dtExpiryDate;
	if (self.innerHTML == "Добавить") 
	{
		document.cookie = 'Gazeta_cookies=bcase' + '=' + getCookie('bcase', '') + aid + ':' + ';' + SHExpiration + ';' + 'path=/;domain=gazeta.kz;';
		self.innerHTML = "Удалить";
	}
	else 
	{
		var ck = getCookie('bcase', 0) + '';
		document.cookie = 'Gazeta_cookies=bcase' + '=' + ck.replace(aid + ':', '') + ';' + SHExpiration + ';' + 'path=/;domain=gazeta.kz;';
		self.innerHTML = "Добавить";
		if (eng) {
			if (doReload) if (confirm('Update content?')) document.location = 'http://eng.gazeta.kz/case.asp';
		} else {
			if (doReload) if (confirm('Обновить страницу?')) document.location = '/case.asp';
		}
	}
}

function clearCookie(doReload, eng) {
	var SHExpiration = 'expires=Monday, 23-Oct-2000 00:00:00 GMT';
	document.cookie = 'Gazeta_cookies=bcase' + '=' + '' + ';' + SHExpiration + ';' + 'path=/;domain=gazeta.kz;';
	var i;
	for (i = 0; i < document.images.length; i++)
		if (document.images[i].src.lastIndexOf(iChecked) != -1) document.images[i].src = iUnchecked;
	if (eng) {
		if(doReload) if(confirm('Update content?')) document.location = 'http://eng.gazeta.kz/case.asp';
	} else {
		if(doReload) if(confirm('Обновить страницу?')) document.location = '/case.asp';
	}
		
}
