function checkEmpty (val){
	if (val=="" || val.search(/[^\s]+/)==-1) {
		return false;
	}
	return true;
}

function RestoreColor()
	{
	document.MessageForm.name.style.background="#ffffff";	
	document.MessageForm.content.style.background="#ffffff";	
	document.MessageForm.contacts.style.background="#ffffff";	
	}

function SubmitMessage()
{
	sm=true;
	if (!checkEmpty(document.MessageForm.name.value)) 
		{
	document.MessageForm.name.style.background="#ED1C24";
	sm=false;	
		}
	if (!checkEmpty(document.MessageForm.contacts.value)) 
		{
	document.MessageForm.contacts.style.background="#ED1C24";
	sm=false;	
		}
	if (!checkEmpty(document.MessageForm.content.value)) 
		{
	document.MessageForm.content.style.background="#ED1C24";
	sm=false;	
		}
	if (sm==true) {document.MessageForm.submit();}		
}

function SelPrice(adr)
{
    s1 = document.getElementById('sel1');
    s2 = document.getElementById('sel2');
    
    document.location.href = fulladress+'from'+s1.value+'to'+s2.value+'/';
}

function digo(id)
{
	inp = document.getElementById('bnum'+id);
	reg = /[Ð-ïð-ŸA-Za-z\]\[{};':",/<>?\-=\\_+|`~\!@#$%^\&*\(\)É]/g;
	result = inp.value.replace(reg,'');
	if (result.substring(0,1)==0) result = result.substring(1,100);
	inp.value = result;
	CalcPrice();
}

function DigOnly(id)
{
	eval ('setTimeout("digo('+id+');",100)');
}

function CheckAll()
{
	x=0;
	while (document.getElementById('box'+x))
	{
		document.getElementById('box'+x).checked = 1;
		x++;
	}
}

function ShowPhoto(path,width,height)
{
	int = document.getElementById('interlaced');
	int.style.height = document.documentElement.scrollHeight + 'px';
	int.style.visibility = 'visible';
	view = document.getElementById('ViewPhoto');
	vd = document.getElementById('Vdiv');
	foto = document.getElementById('Fotka');
	foto.innerHTML = '<img src="'+path+'" onclick="HidePhoto();">';
	view.style.width = width + 'px';
	vd.style.width = width + 'px';
	view.style.height = height + 30 + 'px';
	view.style.marginLeft = -Math.round(width/2) + 'px';
	view.style.marginTop = -Math.round(height/2) - 35 + document.documentElement.scrollTop + 'px';
	view.style.display = 'block';
}

function HidePhoto()
{
	view = document.getElementById('ViewPhoto');
	view.style.display = 'none';
	int = document.getElementById('interlaced');
	int.style.visibility = 'hidden';
}

var httpReq;

var httpReqC;

var httpReqU;

var CurrentId;

var CurrentI;

var Cur;

var CurC;

var CurrentCat;


function createHttpRequest() {

var httpRequest;
var browser = navigator.appName;

if (browser == "Microsoft Internet Explorer") {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
} else {
httpRequest = new XMLHttpRequest();
}

return httpRequest;
} 

function sendRequestC(file)
{
    httpReqC.open('get',file);
    httpReqC.onreadystatechange = ChangeCompare;
    httpReqC.send(null);
}

function sendRequestU(file)
{
    httpReqU.open('get',file);
    httpReqU.onreadystatechange = UnAll;
    httpReqU.send(null);
}

function UnAll()
{
	x=1;
	while (document.getElementById('cb'+x))
	{
		document.getElementById('cb'+x).checked = 0;
		x++;
	} 
	if (httpReqU.readyState==4) 
	{
		document.getElementById('cmp').innerHTML = httpReqU.responseText;
	} else
		{
			setTimeout('UnAll()',300);
		}
}

function ATC(id,x)
{
	jsAjaxUtil.InsertDataToNode('/bitrix/templates/lmc2/ajax/addtocompare.php?pro_id='+id+'&active='+document.getElementById('cb'+x).checked, 'cmp', true);
}

function AddToCompare(id,x)
{
	eval("setTimeout('ATC("+id+","+x+")',50);");
}

function ChangeCompare()
{
	if (httpReqC.readyState==4) 
	{
		document.getElementById('cmp').innerHTML = httpReqC.responseText;
	} else
		{
			setTimeout('ChangeCompare()',300);
		}
}

function UncheckAll()
{
	jsAjaxUtil.InsertDataToNode('/bitrix/templates/lmc2/ajax/addtocompare.php?active=all', 'cmp', true);
	cnt = 0;
	while ((document.getElementById('cb'+cnt) !== null) && (typeof(document.getElementById('cb'+cnt)) == 'object')) {
		document.getElementById('cb'+cnt).checked = false;
		cnt++;
	}
}

function ChangeCart()
{
	if (document.getElementById('wtf'+Cur))
	{ 
		document.getElementById('wtf'+Cur).innerHTML = '<a href="/basket/"><img src="/img/basket_na.gif" alt="ßõ¹õùø ò úþ¹÷øýƒ" class="BS" border="0"></a>';
	} else
		{
			document.getElementById('baska').innerHTML = '<a href="/basket/"><img src="/img/tobask_na.gif" class="ToB" border="0"></a>';
		}
	
	if (httpReq.readyState==4) 
	{
		document.getElementById('bsk').innerHTML = httpReq.responseText;
	} else
		{
			setTimeout('ChangeCart()',300);
		}
	
}

function sendRequest(file)
{
    httpReq.open('get',file);
    if (file!='/addtocart.php?pro_id=0') httpReq.onreadystatechange = ChangeCart;
    httpReq.send(null);
}

function AddToBasket(id)
{
	jsAjaxUtil.InsertDataToNode('/bitrix/templates/lmc2/ajax/addtocart.php?pro_id='+id, 'bsk', true);
}

function AddToBasketProduct(id)
{
	jsAjaxUtil.InsertDataToNode('/bitrix/templates/lmc2/ajax/addtocart.php?pro_id='+id, 'bsk', true);
	//document.getElementById('baska').innerHTML = '<a href="/basket/"><img src="/bitrix/templates/lmc2/pics/addtocart.png" class="ToB" alt="Ïåðåéòè â êîðçèíó" /></a>';
}

function CalcPrice()
{
	if (document.getElementById('pr0'))
	{
		price = 0;
		setupprice = 0;
		i=0;
		while (document.getElementById('pr'+i))
		{
			price = price + document.getElementById('pr'+i).value*document.getElementById('bnum'+i).value;
			setupprice = setupprice + document.getElementById('ppr'+i).value*document.getElementById('bnum'+i).value;
			document.getElementById('showpr'+i).innerHTML = format_price(document.getElementById('pr'+i).value*document.getElementById('bnum'+i).value+'');
			document.getElementById('pshowpr'+i).innerHTML = format_price(document.getElementById('ppr'+i).value*document.getElementById('bnum'+i).value+'');
			i++;
		}
		ap = document.getElementById('prall');
		ap.innerHTML = format_price(price+'');
		app = document.getElementById('pprall');
		app.innerHTML = format_price(setupprice+'');
	}
}

function format_price(prc)
{
	p = '';
	for (k=1; k<=prc.length; k++)
	{
		p = prc.charAt(prc.length-k) + p;
		if (k==3 || k==6 || k==9 || k==12 || k==15) p = ' ' + p;
	}
	return p + ' ðóá.';
}

function ShowOrder()
{
	document.getElementById('oimg').style.visibility = 'hidden';
	document.getElementById('ord').style.display = 'block';
}


function RestoreColorX()
	{
	document.Basket.name.style.background="#ffffff";	
	document.Basket.phone.style.background="#ffffff";	
	}

function SubmitMessageX()
{
	sm=true;
	if (!checkEmpty(document.Basket.name.value)) 
		{
	document.Basket.name.style.background="#ED1C24";
	sm=false;	
		}
	if (!checkEmpty(document.Basket.phone.value)) 
		{
	document.Basket.phone.style.background="#ED1C24";
	sm=false;	
		}
	if (sm==true) {document.Basket.submit();}		
}

var center;

function MoveIT(pos)
{
	center.style.backgroundPosition = pos + '% 0';
}

function MoveBG()
{
	center = document.getElementById('cnt');
	for (i=1; i<101; i++)
	{
		to = 20*i;
		pos = 100-i;
		eval ('setTimeout("MoveIT('+pos+');",to)');
	}	
}

function DelCart()
{
    if (httpReq.readyState==4)
    {
    	t = document.getElementById('tr'+CurrentI);
    	bn = document.getElementById('bnum'+CurrentI);
    	bn.value = 0;
    	t.style.display = 'none';
    	CalcPrice();
    	AddToBasket(0);

    } else
    	{
    		setTimeout('DelCart()',300);
    	}
}

function sendDelRequest(file)
{
    httpReq.open('get',file);
    httpReq.onreadystatechange = DelCart;
    httpReq.send(null);
}

function DelFromCart(id,i)
{
	jsAjaxUtil.InsertDataToNode('/bitrix/templates/lmc2/ajax/delfromcart.php?pro_id='+id, 'bsk', true);
	num_basket--;
	var idElem = document.getElementById("tr"+i);
	idElem.parentNode.removeChild(idElem);
	CalcPrice();
	if (!num_basket) document.location = '/basket/';
}

	var mouseX = 0;
	var mouseY = 0;

function getXY(e)
{
	mouseX = (window.Event) ? e.pageX : event.clientX + document.documentElement.scrollLeft;
	mouseY = (window.Event) ? e.pageY : event.clientY + document.documentElement.scrollTop;
}
	
document.onmousemove = getXY;

function ShowHint(id)
{
	h = document.getElementById('hnt');
	ht = document.getElementById('htxt');
	hs = document.getElementById('hsd');
	h.style.top = mouseY - 420 + 'px';
	h.style.left = mouseX - 185 + 'px';
	h.style.display = 'block';
	hs.style.top = mouseY - 420 + 'px';
	hs.style.left = mouseX - 185 + 'px';
	hs.style.display = 'block';
	ht.innerHTML = hints[id];
}

function ShowHint2(id)
{
	h = document.getElementById('hnt');
	ht = document.getElementById('htxt');
	hs = document.getElementById('hsd');
	h.style.top = mouseY - 160 + 'px';
	h.style.left = mouseX - 310 + 'px';
	h.style.display = 'block';
	hs.style.top = mouseY - 160 + 'px';
	hs.style.left = mouseX - 310 + 'px';
	hs.style.display = 'block';
	ht.innerHTML = hints[id];
}

function HideHint()
{
	h = document.getElementById('hnt');
	hs = document.getElementById('hsd');
	h.style.display = 'none';
	hs.style.display = 'none';
}
