
getID = (document.getElementById) ? true : false;
ie = (document.all) ? true : false;
okIE = ie && !getID;

function openWin(name, id_auto,w,h)
{
	url= name +'.php?' + Math.random()  +'&id=' + id_auto ;
	//w = 500;
	//h = 450;
	x = (screen.availWidth-w)/2;
	y = (screen.availHeight-h)/2;
	options='toolbar=0,status=0,menubar=0,scrollbars=1,resizable=0,location=0,screenX='+x+',screenY='+y+',width='+w+',height='+h;
	fotowin=window.open(url,name,options);
	fotowin.moveTo(x,y);
	fotowin.focus();

}


function lightBox(name, imageName)
{
	if (document.images)
		document.images[name].src=imageName;
}

function openBlock(nameID){
	var div;
	var srcT;
	if(!(getID||okIE))return;
	if(getID){
		div=document.getElementById(nameID);
	}else{
		div=document.all[nameID];
	}
	if(div.style.display=='none' || !div.style.display){
	    srcT = 'images/closebox.gif';	

		div.style.display='block';
	}else{
	    srcT = 'images/openbox.gif';
 		div.style.display='none';
	}
	lightBox(nameID+'i', srcT);	
	return false;
}


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Недействительный email")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Недействительный email")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Недействительный email")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Недействительный email")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Недействительный email")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Недействительный email")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Недействительный email")
		    return false
		 }

 		 return true					
	}

function ValidateForm(){
	var emailID=document.order.email;
	var contactID  =document.order.contact;
	var telephoneID =document.order.telephone;	
	var messg = "Не заполнены следующие поля:";
	var Terror= false;

	if((contactID.value==null) || (contactID.value.length < 4) ){
	  messg += "\n\t- Контакт";
	  Terror = true;
	}
	if((telephoneID.value==null) || (telephoneID.value.length < 3) ){
	  messg += "\n\t- Телефон";
	  Terror = true;	  
	}	
	if((emailID.value==null)||(emailID.value=="")){
	  messg += "\n\t- E-mail";
	  Terror = true;	  
	}
	
	if (Terror){
		alert(messg)
		emailID.focus()
		return false
	}
	
	if (!echeck(emailID.value)){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
 
function ValidateForm2(){

 var brand_key = document.order.brand.selectedIndex;
 var brandID = document.order.brand.options[brand_key].value;

 var modelID = document.order.model; 
 var messg = "Пожалуйста, введите:"; 
 var Terror= false; 
 
// alert(document.order.brand.selectedIndex);

if(!ValidateForm()) return false;



 if((brandID==null) || (brandID=="") ){
	  messg += "\n+Марка";
	  Terror = true;
	}  
 if((modelID.value==null) || (modelID.value=="") ){
	  messg += "\n+Модель";
	  Terror = true;
	}
 if (Terror){
		alert(messg)
		modelID.focus()
		return false
	}
 return true;
} 

function openWin3(){
	var email =''; // document.subscribe.email.value;
	newwin = window.open('subscribe.php?email=' +email,'Subscribe','width=350,height=300,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=0,resizable=0');
	newwin.focus();
}