function showsubcatalog(id)
{
	if(document.getElementById(id).style.display=="none")
	{
		document.getElementById(id).style.display="block";
	}
	else
	{
		document.getElementById(id).style.display="none";
	}
}

function getXmlHttp(){
	var xmlhttp;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

function pageX(elem) {

	return elem.offsetParent ?
		elem.offsetLeft + pageX( elem.offsetParent ) :
		elem.offsetLeft;

}

function pageY(elem) {
	return elem.offsetParent ?
		elem.offsetTop + pageY( elem.offsetParent ) :
		elem.offsetTop;
}

function showdiv(id)
{	
	y=pageY(document.getElementById('addbasket_'+id));
	x=pageX(document.getElementById('addbasket_'+id));

	posX=x + 30;
	posY=y;
	
	document.getElementById('kolichestvo_tovara').style.display='block';
	document.getElementById('kolichestvo_tovara').style.top=posY;
	document.getElementById('kolichestvo_tovara').style.left=posX;
	document.getElementById('add_basket_id').value=id;
	document.getElementById('kolichestvo').value='1';
	document.getElementById('kolichestvo').focus();
	document.getElementById('kolichestvo').select();
	return "false";
}

function shownotifydiv(id)
{	
	y=pageY(document.getElementById('addnotify_'+id));
	x=pageX(document.getElementById('addnotify_'+id));

	posX=x + 30;
	posY=y;
	
	document.getElementById('notifydiv').style.display='block';
	document.getElementById('notifydiv').style.top=posY;
	document.getElementById('notifydiv').style.left=posX;
	document.getElementById('add_basket_id').value=id;
	return "false";
}

function hide_div()
{
	document.getElementById('add_basket_id').value="";
	document.getElementById('kolichestvo').value="";
	document.getElementById('kolichestvo_tovara').style.display="none";
}

function hide_notifydiv()
{
	document.getElementById('add_basket_id').value="";
	document.getElementById('notifydiv').style.display="none";
}

function addbasket(id,kolvo)
{
	var xmlhttp = getXmlHttp();
	if(kolvo>0)
	{
	document.getElementById('addbasket_'+id).style.display="none";
	document.getElementById('delbasket_'+id).style.display="block";

		xmlhttp.open('GET', '?page=addbasket&id='+id+'&kolvo='+kolvo, false);
		xmlhttp.send(null);
		if(xmlhttp.status == 200) {
		}
	}
		document.getElementById('add_basket_id').value="";
		document.getElementById('kolichestvo').value="";
		document.getElementById('kolichestvo_tovara').style.display="none";
}

function addnotify(id,pochtamt)
{
	var xmlhttp = getXmlHttp();

//	document.getElementById('addnotify_'+id).style.display="none";
//	document.getElementById('delnotify_'+id).style.display="block";
	document.getElementById('emptybasket_'+id).src="images/megaphone2.gif";

		xmlhttp.open('GET', '?page=addnotify&id='+id+'&pochtamt='+pochtamt, false);
		xmlhttp.send(null);
		if(xmlhttp.status == 200) {}
		
		document.getElementById('add_basket_id').value="";
		document.getElementById('pochtamt').value="";
		document.getElementById('notifydiv').style.display="none";
}

function delbasket(id)
{
	var xmlhttp = getXmlHttp();
	document.getElementById('delbasket_'+id).style.display="none";
	document.getElementById('addbasket_'+id).style.display="block";
	xmlhttp.open('GET', '?page=delbasket&id='+id, false);
	xmlhttp.send(null);
	if(xmlhttp.status == 200) {
	}
}

function delfrombasket(id)
{
	var xmlhttp = getXmlHttp();
	xmlhttp.open('GET', '?page=delbasket&id='+id, false);
	xmlhttp.send(null);
	if(xmlhttp.status == 200) {
	}
}

function basket_delbasket(id)
{
	var xmlhttp = getXmlHttp();
	xmlhttp.open('GET', '?page=delbasket&id='+id, false);
	xmlhttp.send(null);
	if(xmlhttp.status == 200) {
	}
}

function checkform(f)
{
	if (isValidEmail(document.getElementById('email').value) === false)
	{
		alert('Email адрес введен неверно.');
		return false;
	}else{
		var errMSG = ""; 
		for (var i = 0; i<f.elements.length; i++) 
		if (null!=f.elements[i].getAttribute("required")) 
		if (isEmpty(f.elements[i].value))
		errMSG += "  " + f.elements[i].alt + "\n";
		if ("" != errMSG)
		{
			alert("Не заполнены обязательные поля:\n" + errMSG);
			return false;
		}
	}
}

function isValidEmail(email)
{
 return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);
}

function isEmpty(str) {
	for (var i = 0; i < str.length; i++)
	if (" " != str.charAt(i))
	return false;
	return true;
}

function fill_new_basket(counter)
{
	var xmlhttp = getXmlHttp();
	var old_kolvo;
	var old_tovar_id;
	var new_kolvo;
	var i;
	for(i=1; i<=counter; i++)
	{
		old_kolvo=0;
		old_tovar_id=0;
		new_kolvo=0;
		old_kolvo=document.getElementById('kolvo_'+i).value;
		tovar_id=document.getElementById('id_'+i).value;
		new_kolvo=old_kolvo;
		
		xmlhttp.open('GET', '?page=recount_basket&id='+tovar_id+'&kolvo='+new_kolvo, false);
		xmlhttp.send(null);
		if(xmlhttp.status == 200) {
		}
	}
	 location.href='?page=basket';
}

function reset_filter(f)
{
	var nalichieObj = document.getElementById('nalichie');
	var proizvObj = document.getElementById('proizvoditel');
	var modelObj = document.getElementById('model');
	var zapchastObj = document.getElementById('zapchast');
	nalichieObj.selectedIndex = 0;
	proizvObj.selectedIndex = 0;
	modelObj.selectedIndex = 0;
	zapchastObj.selectedIndex = 0;
}
