var d = document;
 
function form_validate(form, field) {
   if ( eval('d.' + form + '.' + field + '.value') < 1 ) {
      alert('Ââåäèòå ïîèñêîâóþ ôðàçó');
      return false;
   }
   return true;
}

function offTimer() {
	if (document.timer) {
		window.clearTimeout(document.timer);
		document.timer = null;
	}
}

function show(obj) {
	document.getElementById('sub' + obj).style.display = 'block';
	document.getElementById('item' + def).className = 'btn';
	document.getElementById('item' + obj).className = 's';
}

function hide() {
	if (document.vis_l3) {
			document.getElementById(document.vis_l3).style.display = 'none';
			document.vis_l3 = null;
		};
	document.getElementById('sub' + document.vis).style.display = 'none';
	document.getElementById('item' + document.vis).className = 'btn';
	document.getElementById('item' + def).className = 's';
}
function on(obj) {
	offTimer();
	if (document.vis) {
		hide();
	}
	show(obj);
}

function off(obj) {
	document.vis = obj;
	document.timer = window.setTimeout('hide()', 300);
}

function changeImg(loc,file) {
	obj = document.getElementById(loc);
	obj.src = file;
}

function preload(obj) {
	new Image().src = obj;
};

function inputFocus(obj, word){
	if ( obj.value == word ){
		obj.value = '';
	}
}

function inputBlur(obj, word){
	if ( obj.value == '' ){
		obj.value = word;
	}
}
function searchSubmit(obj, word){	
	return document.getElementById(obj).value == word ? false : true;
}

function SetCookie(cookieName,cookieValue) {
 var today = new Date();
 var expire = new Date();
 document.cookie = cookieName+"="+escape(cookieValue);
}

function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

function AddGoodToCompare(id){
	goods = ReadCookie('compare').split(';');
	basket = "";
	finded = false;
	for(i=0; i < goods.length; i++){
		if ( goods[i] == id ) {
			finded = true;
		}
		basket = (basket.length ?  basket + ";" : "") + goods[i];
	}
	if ( ! finded ) 		basket = (basket.length ?  basket + ";" : "") + id;
	SetCookie('compare', basket);
}

function RemoveGoodFromCompare(id){
	goods = ReadCookie('compare').split(';');
	basket = "";
	for(i=0; i < goods.length; i++){
		if ( goods[i] != id ) {
			basket = (basket.length ?  basket + ";" : "") + goods[i];
		}
	}
	SetCookie('compare', basket);
}

function RemoveGoodsFromCompareGroup(form_name) {
	var length = document.getElementById(form_name).length;
	var id = 0;
	for ( var i = 0; i < length; i++ ) {
	   id = document.getElementById(form_name).elements[i].value;
	   RemoveGoodFromCompare(id);
	}
}

function CheckAllCompareItems(){
	goods = ReadCookie('compare').split(';');
	basket = "";
	for(i=0; i < goods.length; i++){
		if ( document.getElementById('compare_' + goods[i])){
			document.getElementById('compare_' + goods[i]).checked = true;
		}
	}
}

function CanCompareItems(){
	goods = ReadCookie('compare').split(';');
	return goods.length > 1;
}
