function addOnHoverMenu(){
	menuRows = document.getElementsByTagName('table');
	for (var i=0; i<menuRows.length; i++){
		if (menuRows[i].className == "menu-row"){
			menuRows[i].onmouseover = highLightRow;
			menuRows[i].onmouseout = normalRow;
		}
	}
	
}
function highLightRow(){
	this.className = "s-menu-row";
}
function normalRow(){
	this.className = "menu-row";
}
function addOnChangeHandler() {
	var ff = document.getElementById('filterContainer');
	if (ff){
		var chbks = ff.getElementsByTagName('input');
		for (var i=0; i<chbks.length; i++){
			chbks[i].onchange = changeHandler;
		}
		var selects = ff.getElementsByTagName('select');
		for (var i=0; i<selects.length; i++){
			selects[i].onchange = changeHandlerSelect;
		}
	}
}
function changeHandlerSelect(){
//	alert(this.id+'='+this.value);
	var ids = this.id.split('-');

	var founded = -1;
	for (var i=0; i<selectedOptions.length; i++){
		//alert(i);
		ss = selectedOptions[i]
		if ((ss[0] == ids[1])&&(ss[2] == ids[0])){
			founded = i;
			break;
		}
	}
	if (founded != -1){
		selectedOptions.splice(founded,1);
	}
	var founded = -1;
	for (var i=0; i<selectedOptions.length; i++){
		ss = selectedOptions[i]
		if (ss[0] == ids[1]){
			founded = i;
			break;
		}
	}
	if (founded == -1){
		document.getElementById('a-'+ids[1]).style.display = 'none';
	}
	var str = '';
		//alert("q");
	if (this.value.length){

		selectedOptions[selectedOptions.length] = new Array(ids[1], this.value, ids[0]);
		document.getElementById('a-'+ids[1]).style.display = 'inline';

	}
	if (selectedOptions.length == 0){
		document.getElementById('clearAllFilers').style.display = 'none';
	} else {
		document.getElementById('clearAllFilers').style.display = 'inline';
	}
	
	//sendFilter();
	//applyFilter();
}
function changeHandler(){
	var ids = this.id.split('-');
	var str = '';
	if (this.checked){
		selectedOptions[selectedOptions.length] = new Array(ids[1], this.value, 's');
		document.getElementById('a-'+ids[1]).style.display = 'inline';

	} else {
		var founded = -1;
		for (var i=0; i<selectedOptions.length; i++){
			ss = selectedOptions[i]
			if ((ss[0] == ids[1])&&(ss[1] == this.value)){
				founded = i;
				break;
			}
		}
		if (founded != -1){
			selectedOptions.splice(founded,1);
		}
		var founded = -1;
		for (var i=0; i<selectedOptions.length; i++){
			ss = selectedOptions[i]
			if (ss[0] == ids[1]){
				founded = i;
				break;
			}
		}
		if (founded == -1){
			document.getElementById('a-'+ids[1]).style.display = 'none';
		}
		
	}
	if (selectedOptions.length == 0){
		document.getElementById('clearAllFilers').style.display = 'none';
	} else {
		document.getElementById('clearAllFilers').style.display = 'inline';
	}
	
	//sendFilter();
	//applyFilter();
}
function setCookieVal(cookName, cookVal){
	document.cookie = cookName+"="+cookVal+";path=/";
}
function getCookieVal(cookName){

	cook = document.cookie.split("; ");
	
	for (var i in cook) {
		aCook = cook[i];
		if (aCook.split('=')[0] == cookName){
			return(aCook.split('=')[1]);
		}
	}
	return 0;
}
function moveOrderForm(){
	myQueryDialog = document.getElementById('queryDialog').style;
	if (myQueryDialog.visibility == "visible") {
		if (document.documentElement && document.documentElement.clientHeight){
			// 6+ brousers
			theTop = document.documentElement.scrollTop;
			if (document.body.offsetHeight != document.body.clientHeight){
				// Opera
				_y = document.body.clientHeight;
			} else {
				// IE, FireFox
				_y = document.documentElement.clientHeight;
			}
		} else {
			// IE 5.5-
			theTop = document.body.scrollTop;
			_y=document.body.offsetHeight;
		}
		x = (document.body.clientWidth-200)/2;
		y = theTop+_y/2;
		myQueryDialog.left = parseInt(x)+'px';
		myQueryDialog.top = parseInt(y)+'px';
	}
	
}
function addToOrder(id){
	if (getCookieVal('cEn')== 0){
		alert('Добавление в корзину невозможно, так как не включены Cookie');
		return;
	}
	c = parseInt(document.getElementById("in_cart").innerHTML);
	a = parseInt(getCookieVal('a['+id+']'));
	// -------
	if (document.documentElement && document.documentElement.clientHeight){
		// 6+ brousers
		theTop = document.documentElement.scrollTop;
		if (document.body.offsetHeight != document.body.clientHeight){
			// Opera
			_y = document.body.clientHeight;
		} else {
			// IE, FireFox
			_y = document.documentElement.clientHeight;
		}
	} else {
		// IE 5.5-
		theTop = document.body.scrollTop;
		_y=document.body.offsetHeight;
	}

	x = (document.body.clientWidth-200)/2;
	y = theTop+_y/2;
	prodid = document.getElementById('prodid');
	quantity = document.getElementById('quantity');
	document.getElementById('prodname').innerHTML = document.getElementById('prod'+id).innerHTML;
	quantity.value = 1;
	prodid.value = id;
	myQueryDialog = document.getElementById('queryDialog').style;
	myQueryDialog.height = parseInt(document.getElementById('prodname').offsetHeight + 40 + 85 + 10)+'px';
	myQueryDialog.left = parseInt(x)+'px';
	myQueryDialog.top = parseInt(y-document.getElementById('queryDialog').offsetHeight / 2)+'px';
	myQueryDialog.visibility = "visible";
	document.getElementById('quantity').focus();
	document.getElementById('quantity').select();
    // -------
	/*
	b = parseInt(prompt('Введите количество:', 1));
	if (isNaN(b)) {
		return false;
	}
	a = a+b;
	setCookieVal('a['+id+']', a);
	document.getElementById("in_cart").innerHTML = b+c;
	*/
	return false;
}
function refreshCartIndicator(){
	c = parseInt(document.getElementById("in_cart").innerHTML);
	if (c == 0) {
		cook = document.cookie.split("; ");
		
		for (var i in cook) {
			aCook = cook[i];
			if (aCook.substr(0,2) == 'a['){
				c = parseInt(c) + parseInt(aCook.split('=')[1]);
			}
		}
		document.getElementById("in_cart").innerHTML = c;
	}
}
function cancelAdd(){
	myQueryDialog = document.getElementById('queryDialog').style;
	myQueryDialog.visibility = "hidden";
	prodid = document.getElementById('prodid');
	quantity = document.getElementById('quantity');
	quantity.value = 1;
	prodid.value = "";
}
function orderAdd(){
	c = parseInt(document.getElementById("in_cart").innerHTML);
	prodid = document.getElementById('prodid');
	id = prodid.value;
	a = parseInt(getCookieVal('a['+id+']'));
	
	quantity = document.getElementById('quantity');
	b = parseInt(quantity.value);
	if (isNaN(b)) {
		alert('Неверное число');
		return false;
	} else {
		if (b > 0 ) {
			a = a+b;
			setCookieVal('a['+id+']', a);
			document.getElementById("in_cart").innerHTML = b+c;
		} else {
			alert('Число должно быть больше нуля');
			return false;
		}
	}

	myQueryDialog = document.getElementById('queryDialog').style;
	myQueryDialog.visibility = "hidden";
	return false;

}
