if (window.navigator.userAgent.indexOf ("MSIE") > 0) ie4=true;
else ie4=false;

document.onkeydown = NavigateThrough;
function NavigateThrough (event)
{
	if (!document.getElementById) return;
	if (window.event) event = window.event;
	if (event.ctrlKey)
	{
		var link = null;
//		var href = null;
		switch (event.keyCode ? event.keyCode : event.which ? event.which : null)
		{
			case 0x25: link = document.getElementById ("NextLink").value; if (link=="#") link=""; break;
			case 0x27: link = document.getElementById ("PrevLink").value; if (link=="#") link=""; break;
//			case 0x26: link = document.getElementById ("UpLink"); break;
//			case 0x28: link = document.getElementById ("DownLink"); break;
//			case 0x24: href = "/"; break;
		}
		if (link) document.location = link;
//		if (href) document.location = href;
	}			
}

//////////
function Callback()
{
	Hidden("callback", "inline");
	overl=setTimeout("Overlay()", 0);
	document.getElementById("callback").innerHTML=auto[1];
	document.Form1.name.value=name;
	document.Form1.phone.value=phone;
}
function Orders(id, cat_id, title, category, price)
{
	Hidden("order_tovar", "inline");
	overl=setTimeout("Overlay()", 0);
	document.getElementById("order_tovar").innerHTML=auto[2];
	document.Form2.name.value=name;
	document.Form2.phone.value=phone;
	document.getElementById("message2").innerHTML="Я хочу заказать мебель:\n"+category+" - &laquo;"+title+"&raquo;, цена: "+price+" грн";
	document.Form2.id.value=id;
	document.Form2.cat_id.value=cat_id;
	document.Form2.title.value=category+" - "+title;
	document.Form2.price.value=price;
}
function GetPrice(id, cat_id, title, category, event)
{
	if (!event) event=window.event;
	coorY=event.clientY;
	overl=setTimeout("Overlay()", 0);
	document.getElementById("getprice_tovar").innerHTML=auto[3];
	document.Form3.name.value=name;
	document.Form3.phone.value=phone;
	document.getElementById("message3").innerHTML="Я хочу узнать стоимость мебели:\n"+category+" - &laquo;"+title+"&raquo;";
	document.Form3.id.value=id;
	document.Form3.cat_id.value=cat_id;
	document.Form3.title.value=category+" - "+title;

	const_coorY=200;
	if (document.documentElement.scrollTop>const_coorY) 
	coorY=document.documentElement.scrollTop+10;
	if (document.documentElement.scrollTop<=const_coorY) coorY=const_coorY;
//	Hidden("getprice_tovar", "none");
	coorY-=150;
	document.getElementById("getprice_tovar").style.top=coorY+"px";
	Hidden("getprice_tovar", "inline");
}
//////////

///////////////////////////////////////////////
//////////          Service          //////////
///////////////////////////////////////////////
function Hidden(id, style)
{
	if (document.getElementById(id))
	{
		if (style == "table-row")
		{
				if (ie4) document.getElementById(id).style.display="inline";
				else document.getElementById(id).style.display=style;
		}
		else
		document.getElementById(id).style.display=style;
	}
}
function Overlay()
{
	clearTimeout(overl);
	pW = getPageSize();
	x = document.body.clientWidth;
	y = document.body.scrollTop;

	document.getElementById("overlay").style.width = x+"px";
	document.getElementById("overlay").style.height = pW[1]+"px";
	Hidden("overlay", "inline");
}

function getPageSize()
{
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY)
	{
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight) // all but Explorer Mac
	{
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
	{
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight)// all except Explorer
	{
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
	{
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight) pageHeight = windowHeight;
	else pageHeight = yScroll;

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth) pageWidth = windowWidth;
	else pageWidth = xScroll;

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}
///////////////////////////////////////////////
//////////          /Service         //////////
///////////////////////////////////////////////


function Send(num)
{
	if (num==1)
	{
		if (document.Form1.name.value=="")
		{
			alert("Укажите, пожалуйста, имя");
			document.Form1.name.focus();
			return;
		}
		if (document.Form1.phone.value=="")
		{
			alert("Укажите контактный телефон");
			document.Form1.phone.focus();
			return;
		}
		if (document.Form1.message.value=="")
		{
			alert("Поле \"сообщение\" не должно быть пустым");
			document.Form1.message.focus();
			return;
		}
		document.Form1.submit();
	}
	if (num==2)
	{
		if (document.Form2.name.value=="")
		{
			alert("Укажите, пожалуйста, имя");
			document.Form2.name.focus();
			return;
		}
		if (document.Form2.phone.value=="")
		{
			alert("Укажите контактный телефон");
			document.Form2.phone.focus();
			return;
		}
		if (document.Form2.message.value=="")
		{
			alert("Поле \"сообщение\" не должно быть пустым");
			document.Form2.message.focus();
			return;
		}
		document.Form2.submit();
	}
	if (num==3)
	{
		if (document.Form3.name.value=="")
		{
			alert("Укажите, пожалуйста, имя");
			document.Form3.name.focus();
			return;
		}
		if (document.Form3.phone.value=="")
		{
			alert("Укажите контактный телефон");
			document.Form3.phone.focus();
			return;
		}
		if (document.Form3.message.value=="")
		{
			alert("Поле \"сообщение\" не должно быть пустым");
			document.Form3.message.focus();
			return;
		}
		document.Form3.submit();
	}
}

var auto = new Array;
auto[1]='<div id="form1"><form name="Form1" action="/misc/send.php" method="post"><input type="Hidden" name="mode" value="1"><table cellpadding="0" cellspacing="0" width="350" align="center"><tr><td><h2>Обратный звонок</h2><div id="cross"><a href="javascript:Hidden(\'form1\', \'none\'); Hidden(\'overlay\', \'none\');"><img src="/img/ru/cross.gif"/></a></div></td></tr><tr><td class="txt_white" style="padding:8px 0px 8px 0px">Оставьте нам свои данные и мы перезвоним</td></tr><tr><td class="txt_gray">Имя и фамилия:</td></tr><tr><td><input type="Text" name="name" class="input1" value=""/></td></tr><tr><td class="txt_gray">Номер телефона:</td></tr><tr><td><input type="Text" name="phone" class="input1" value=""/></td></tr><tr><td class="txt_gray">Сообщение:</td></tr><tr><td><textarea name="message" id="message1" class="textarea"></textarea></td></tr><tr><td align="center"><br/><br/><a href="javascript:Send(1);"><img src="/img/ru/send1.gif"/></a></td></tr></table></form></div>';
auto[2]='<div id="form2"><form name="Form2" action="/misc/send.php" method="post"><input type="Hidden" name="mode" value="2"><input type="Hidden" name="id" value=""><input type="Hidden" name="cat_id" value=""><input type="Hidden" name="price" value=""><input type="Hidden" name="title" value=""><table cellpadding="0" cellspacing="0" width="350" align="center"><tr><td><h2>Заказ мебели</h2><div id="cross"><a href="javascript:Hidden(\'form2\', \'none\'); Hidden(\'overlay\', \'none\');"><img src="/img/ru/cross.gif"/></a></div></td></tr><tr><td class="txt_white" style="padding:8px 0px 8px 0px">Оставьте нам свои данные и мы перезвоним</td></tr><tr><td class="txt_gray">Имя и фамилия:</td></tr><tr><td><input type="Text" name="name" class="input1" value=""/></td></tr><tr><td class="txt_gray">Номер телефона:</td></tr><tr><td><input type="Text" name="phone" class="input1" value=""/></td></tr><tr><td class="txt_gray">Сообщение:</td></tr><tr><td><textarea name="message" id="message2" class="textarea"></textarea></td></tr><tr><td align="center"><br/><br/><a href="javascript:Send(2);"><img src="/img/ru/send1.gif"/></a></td></tr></table></form></div>';
auto[3]='<div id="form3"><form name="Form3" action="/misc/send.php" method="post"><input type="Hidden" name="mode" value="3"><input type="Hidden" name="id" value=""><input type="Hidden" name="cat_id" value=""><input type="Hidden" name="title" value=""><table cellpadding="0" cellspacing="0" width="350" align="center"><tr><td><h2>Запрос стоимости мебели</h2><div id="cross"><a href="javascript:Hidden(\'form3\', \'none\'); Hidden(\'overlay\', \'none\');"><img src="/img/ru/cross.gif"/></a></div></td></tr><tr><td class="txt_white" style="padding:8px 0px 8px 0px">Оставьте нам свои данные и мы перезвоним</td></tr><tr><td class="txt_gray">Имя и фамилия:</td></tr><tr><td><input type="Text" name="name" class="input1" value=""/></td></tr><tr><td class="txt_gray">Номер телефона:</td></tr><tr><td><input type="Text" name="phone" class="input1" value=""/></td></tr><tr><td class="txt_gray">Сообщение:</td></tr><tr><td><textarea name="message" id="message3" class="textarea"></textarea></td></tr><tr><td align="center"><br/><br/><a href="javascript:Send(3);"><img src="/img/ru/send1.gif"/></a></td></tr></table></form></div>';

