// ---------Browser determination-----------
dom = (document.getElementById);
IE4x = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 ));
NN4x = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4 ));
br4x = (IE4x || NN4x);
// ---------Browser determination-----------

Active = 0;
var actLayer = '';
var P = false;

function waitMouse() {
	clearTimeout(Active);
	if (actLayer!='') Active = setTimeout("showsm('')", 800);
}

function showsm(id){
	clearTimeout(Active);
	if (!P && actLayer!='') document.getElementById(actLayer).style.visibility='hidden';
	if(id!=''){
		if(actLayer!='') document.getElementById(actLayer).style.visibility='hidden';
		document.getElementById(id).style.visibility='visible';
		}
	actLayer = (id!='' || P)? id : '';
	P = (id!='')? true : false;
}

function showLayer(layer){
	document.getElementById(layer).style.display = (document.getElementById(layer).style.display != 'block')? 'block' : 'none';
}

function createPictureWindow(Path,Width,Height,Title)
{
	var p = Math.ceil(Math.random()*10000);
	var q = Math.ceil(Math.random()*p);
	windowName = p+'X'+(Width*p)+(Height*q);
	WinFeatures = "top="+(screen.height-Height)/2+",left="+(screen.width-Width)/2+",width="+Width+",height="+Height+",Status=no,toolbar=no,menubar=no,location=no,directories=no,scrollbars=no";
	w = window.open("",windowName,WinFeatures);
	w.document.open();
	w.document.write('<head><title></title><meta http-equiv="Content-Type" content="text/html; charset=windows-1251"></head>');
	w.document.write("<body bgcolor='#FFFFFF' leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'><img src='"+Path+"' height='"+Height+"' width='"+Width+"' alt='&quot;"+Title+"&quot;'></body>"); 
	w.document.close();
}


function checkFeedbackForm(form) {
	f1 = document.forms[form].elements['field[name]'].value;
	f2 = document.forms[form].elements['field[email]'].value;
	f3 = document.forms[form].elements['field[subject]'].value;
	f4 = document.forms[form].elements['field[text]'].value;
	
	if (f1 == "") {
		alert("Введите, пожалуйста, Ваше имя");
		return false;
	}
 	else if ((f2 == "") || (f2.indexOf('@')<0) || (f2.indexOf('.')<0)) {
		alert("Введите, пожалуйста, корректный e-Mail");
		return false;
	}
	else if (f3 == "") {
		alert("Введите, пожалуйста, тему сообщения");
		return false;
	}
	else if (f4 == "") {
		alert("Введите, пожалуйста, Ваше сообщение");
		return false;
	}
	else return true;
}

function createDynamicWindow(Path,Width,Height,Title)
{
	var p = Math.ceil(Math.random()*10000);
	var q = Math.ceil(Math.random()*p);
	windowName = p+'X'+(Width*p)+(Height*q);
	WinFeatures = "top="+(screen.height-Height)/2+",left="+(screen.width-Width)/2+",width="+Width+",height="+Height+",Status=no,toolbar=no,menubar=no,location=no,directories=no,scrollbars=no";
	w = window.open("",windowName,WinFeatures);
	w.document.open();
	w.document.write('<head><title>&quot;'+Title+'&quot;</title><meta http-equiv="Content-Type" content="text/html; charset=windows-1251"></head>');
	w.document.write("<body bgcolor='#FFFFFF' leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'><img src='"+Path+"' height='"+Height+"' width='"+Width+"' alt='&quot;"+Title+"&quot;'></body>"); 
	w.document.close();
}

function setPic(source){
	document.images['big_pic'].src = source;
}

function createPopup(num)
{
	var p = Math.ceil(Math.random()*10000);
	var q = Math.ceil(Math.random()*p);
	windowName = p+'X'+p+p*q;
	WinFeatures = "top=100,left=100,width=1,height=1,Status=no,toolbar=no,menubar=no,location=no,directories=no,scrollbars=no";
	w = window.open(num,windowName,WinFeatures);
}

function MakeImageArray(n)	{
	this.length=n; for (var i=0; i<=n; i++) this[i] = new Image(); return this
	}

button_home = new MakeImageArray(2);
button_home[0].src = "pics/button_home.gif";
button_home[1].src = "pics/button_home_a.gif";

button_mail = new MakeImageArray(2);
button_mail[0].src = "pics/button_mail.gif";
button_mail[1].src = "pics/button_mail_a.gif";

button_map = new MakeImageArray(2);
button_map[0].src = "pics/button_map.gif";
button_map[1].src = "pics/button_map_a.gif";

button_close = new MakeImageArray(2);
button_close[0].src = "pics/button_close.gif";
button_close[1].src = "pics/button_close_a.gif";

function turnOn(num,t,ad) {
	document.getElementById(t+ad).src = eval(t)[num].src;
}

mainmenu_ = new MakeImageArray(5);
mainmenu_a = new MakeImageArray(5);	

for(i=1;i<6;i++){
	mainmenu_[i].src = "pics/menu"+i+".gif";
	mainmenu_a[i].src = "pics/menu"+i+"a.gif";
}

function menuOn(pic,mode){
	document.getElementById('menu'+pic).src = eval('mainmenu_'+mode)[pic].src;
}
	
// Проверка содержимого полей формы заказа
function orderValid(form)
{
	element = document.forms[form].elements;
	Name = element.contact_name.value;
	Phone = element.phone_mobile.value+element.phone_work.value+element.phone_home.value;

	if (Name == "") {
		alert("Введите, пожалуйста, Ваше имя");
		return false;
	}
 	else if (Phone == "") {
		alert("Введите, пожалуйста, хотя бы один телефон");
		return false;
	}	
	else return true;
}

function createDescriptionWindow(_file,_width,_height)
{
	wTop = (screen.height-_height)/3;
	wLeft = (screen.width-_width)/2;
	WinFeatures = "top="+wTop+",left="+wLeft+",width="+_width+",height="+_height+",maximize=no,minimize=no,Status=no,toolbar=no,menubar=no,location=no,directories=no,scrollbars=yes,resize=no";
	_newDescription = window.open(_file,"frontendDescriptionWindow",WinFeatures);
}

var _price_from = new Array();
var _price_to = new Array();

function convertPrice(form,val){
	if(_price_from[form][val]>0) document.getElementById(form+'_price_from').innerHTML = 'от '+_price_from[form][val];
	if(_price_to[form][val]>_price_from[form][val]) document.getElementById(form+'_price_to').innerHTML = 'до '+_price_to[form][val];
}
