var date = new Date();
//date.setFullYear(date.getFullYear()+10);
//var expires=date.toGMTString();

date.setDate(date.getDate()+1);
var expires=date.toGMTString();

function setBasket(basket,basketsumm){
//alert('here!!');
document.getElementById('basket').firstChild.data = basket + ' ед.';
document.getElementById('basketsumm').firstChild.data =basketsumm + ' руб.';
}


function setCookie(item,price,type) {
	if(type == 'spisok')
	{
	eval("colvo = document.spisok.bye"+ item +".value");

		if(colvo == 0)
		{
		alert('Вы пытаетесь положить в корзину 0 товаров, что невозможно!');
		return;
		}

	}
	else
	{
	colvo = 1;
	}

	var price1 = price*colvo;

//alert(document.getElementById('basket').firstChild.data);
//alert(price +' !! '+item);
//setBasket(1,1)
//return;


	var oldCookie = getCookie();

	if(oldCookie == '') {

                var curCookie = "report=" + item + "#"+ colvo +"::"+ price +"; path=/; expires=" + expires;
		document.cookie = curCookie;
                setBasket(colvo,price1);
//		document.basket.basket.value = colvo;
//		document.basket.basketsumm.value = price1;
		alert('Товар в количестве '+ colvo +' шт. на сумму '+ price1 +' р. положен в корзину!');
		return;
	}


	var splitCookie = oldCookie.split(',');

	var newCookie = '';

	for(var i=0;i<splitCookie.length;i++)
	{
		var splitCookie_id = splitCookie[i].split('#');

		if(splitCookie_id[0] == item)
		{
		alert('Такой товар уже лежит в корзине!\nИзменить количество Вы можете в Вашей корзине!');
		return;
		}

	}

	alert('Товар в количестве '+  colvo +' шт. на сумму '+ price1 +' р. положен в корзину!');

	splitCookie[splitCookie.length]= item+"#"+ colvo +"::"+price;
	var newCookie=splitCookie.join(',');

	var curCookie;
	if((newCookie == '0')||(newCookie == '')) {
		newCookie="";
		var curCookie = "report=" + escape(newCookie) + "; path=/; expires=" + expires;
	}
	else
	{
		var curCookie = "report=" + escape(newCookie) + "; path=/; expires=" + expires;
	}

	document.cookie = curCookie;

	var oldCookie = getCookie();

	if(oldCookie!='')
	{

	 	var basket = 0;
	 	var allbasketsumm = 0;
	 	var basketsumm =0;
		var splitCookie = oldCookie.split(',');
		for(var i=0;i<splitCookie.length;i++)
		{
		 	var splitCookie_id = splitCookie[i].split('#');
		 	var splitCookie_id_col = splitCookie_id[1].split('::');
//if(splitCookie_id_col[1] == 0 or splitCookie_id_col[1] =='0'){
//if(splitCookie_id_col[1] =='0'){

//alert('!!');
//continue;
//}
//alert(splitCookie_id_col[0] + ' , ' + splitCookie_id_col[1]);
//			basket = basket + Number(splitCookie_id_col[0]);
//alert(Number(splitCookie_id_col[0])+ ' + '+ Number(splitCookie_id_col[1]));
//alert(Number(splitCookie_id_col[0]) * Number(splitCookie_id_col[1]));
//			basketsumm = Number(splitCookie_id_col[0]) * Number(splitCookie_id_col[1]);
//			eval("basket = "+ basket +"+"+ splitCookie_id_col[0]);
//			eval("basketsumm = "+ splitCookie_id_col[0] +"*"+ splitCookie_id_col[1]);
//alert(basket);
//alert(basket, basketsumm);
//			eval("allbasketsumm = "+ basketsumm +"+"+ allbasketsumm);
			eval("basket = "+ basket +"+"+ splitCookie_id_col[0]);
			eval("basketsumm = "+ splitCookie_id_col[0] +"*"+ splitCookie_id_col[1]);
			eval("allbasketsumm = "+ basketsumm +"+"+ allbasketsumm);


		}


//alert(basket +','+ allbasketsumm);
        setBasket(basket,allbasketsumm);
//	document.basket.basket.value = basket;
//	document.basket.basketsumm.value = allbasketsumm;
	}
	else
	{
        setBasket('0','0');
//	document.basket.basket.value = '0';
//	document.basket.basketsumm.value = '0';
	}

}


function setCookieOpt(item,price) {
        var colvoName = 'colvo' + item;
	var colvoObj =  $(colvoName);
	colvo =	colvoObj.value;

	if(colvo == 0)
	{
		alert('Вы пытаетесь заказать 0 книг, что невозможно!');
		return;
	}

//	alert(colvo);
//	return;

/*
	if(type == 'spisok')
	{
	eval("colvo = document.spisok.bye"+ item +".value");

		if(colvo == 0)
		{
		alert('Вы пытаетесь положить в корзину 0 товаров, что невозможно!');
		return;
		}

	}
	else
	{
	colvo = 1;
	}
*/
	var price1 = price*colvo;

//alert(document.getElementById('basket').firstChild.data);
//alert(price +' !! '+item);
//setBasket(1,1)
//return;


	var oldCookie = getCookieOpt();

	if(oldCookie == '') {

                var curCookie = "reportOpt=" + item + "#"+ colvo +"::"+ price +"; path=/; expires=" + expires;
		document.cookie = curCookie;
//		document.basket.basket.value = colvo;
//		document.basket.basketsumm.value = price1;
		alert('Товар в количестве '+ colvo +' шт. на сумму '+ price1 +' р. добавлен в ваш заказ! Для того что бы оформить заказ нажмите кнопку "Оформить заказ"!');
		return;
	}


	var splitCookie = oldCookie.split(',');

	var newCookie = '';

	for(var i=0;i<splitCookie.length;i++)
	{
		var splitCookie_id = splitCookie[i].split('#');

		if(splitCookie_id[0] == item)
		{
			alert('Такой товар уже выбран!\nИзменить количество Вы можете при оформлении заказа!');
			return;
		}

	}

	alert('Товар в количестве '+  colvo +' шт. на сумму '+ price1 +' р. добавлен в ваш заказ! Для того что бы оформить заказ нажмите кнопку "Оформить заказ"!');

	splitCookie[splitCookie.length]= item+"#"+ colvo +"::"+price;
	var newCookie=splitCookie.join(',');

	var curCookie;
	if((newCookie == '0')||(newCookie == '')) {
		newCookie="";
		var curCookie = "reportOpt=" + escape(newCookie) + "; path=/; expires=" + expires;
	}
	else
	{
		var curCookie = "reportOpt=" + escape(newCookie) + "; path=/; expires=" + expires;
	}

	document.cookie = curCookie;
}


function getCookie() {
  	var prefix = "report=";
       var cookieStartIndex = document.cookie.indexOf(prefix);
       if (cookieStartIndex == -1)
               return "";
       var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
       if (cookieEndIndex == -1)
               cookieEndIndex = document.cookie.length;
       return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));

}

function getCookieOpt() {
  	var prefix = "reportOpt=";
       var cookieStartIndex = document.cookie.indexOf(prefix);
       if (cookieStartIndex == -1)
               return "";
       var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
       if (cookieEndIndex == -1)
               cookieEndIndex = document.cookie.length;
       return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));

}



browser_name = navigator.appName;
browser_version = parseFloat(navigator.appVersion);

if (browser_name == "Netscape" && browser_version >= 3.0) { roll = 'true'; }
else if (browser_name == "Microsoft Internet Explorer" && browser_version >= 3.0) { roll = 'true'; }
else { roll = 'false'; }

function over(img,ref) { if (roll == 'true') { document.images[img].src = ref; } }
function out(img,ref)  { if (roll == 'true') { document.images[img].src = ref; } }


function validatefind()
{
var f = eval('document.find');

	if(f.find.value.length == 0)
	{
	alert("Введите слово или фразу для поиска!");
	f.find.focus();
	return false;
	}

return true;
}

function initBasket()
{
	var oldCookie = getCookie();
	if(oldCookie!='')
	{
	 	var basket = 0;
	 	var allbasketsumm = 0;
	 	var basketsumm =0;
		var splitCookie = oldCookie.split(',');
		for(var i=0;i<splitCookie.length;i++)
		{
		 	var splitCookie_id = splitCookie[i].split('#');
		 	var splitCookie_id_col = splitCookie_id[1].split('::');
			eval("basket = "+ basket +"+"+ splitCookie_id_col[0]);
			eval("basketsumm = "+ splitCookie_id_col[0] +"*"+ splitCookie_id_col[1]);
			eval("allbasketsumm = "+ basketsumm +"+"+ allbasketsumm);
		}
        setBasket(basket,allbasketsumm);
	}
	else
	{
        setBasket('0','0');
	}
}

function $(id) {
	if ( typeof id == 'object' ) return id;
	return ( document.getElementById ) ? document.getElementById(id) : null;
};

function _help_open(  ) {
//        href = "/pages/send.html";
//	width="480"; 
//	height="400"; 
//	help_window = window.open(href, 'ЋЎа в­ п бўп§м','toolbar=0,directories=0,status=0,menubar=0,scrollbars=1,resizeable=1,width='+width+',height='+height);

	help_window = window.open('/pages/send.html', '_blank', 'toolbar=0,directories=0,status=0,menubar=0,scrollbars=1,resizeable=1,width=620,height=400');

/*
	help_window = window.open(href, 'ЋЎа в­ п бўп§м','toolbar=0,directories=0,status=0,menubar=0,'+		'scrollbars=1,resizeable=1,width='+width+',height='+height);
*/
	help_window.focus();
	return help_window;

}

function OpenSendWindow(textArea) {
        textArea.blur();
	var wh = _help_open( );
	return false;
}

function isdefined( variable)
{
    return (typeof(window[variable]) == "undefined")?  false: true;
}

function clearInput(id,value){
	if(!document.getElementById(id)) return false;
	if(document.getElementById(id).value != value){
		return;
	}

	document.getElementById(id).value='';
}


function clearIe(text){
	document.body.setAttribute("class", "test");
		if (document.body.className == "test")
		{
			return text;
		}
		else
		{
			return new Function(text);
		}

}
