// JavaScript Document
function checkRegistration(form)
    	{
    		
			setRegistartion(form,form.fname.value,form.lname.value,form.city.value,form.mail.value,form.mailCheck.value,form.mphone.value,form.mphone.value,form.hphone.value);
			fl=true;
			 var filter =/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;
			if(form.fname.value==''){fl=false;toggleBox('fname',1,'<br/>Введите  Имя<br/>'); /*alert('Введите  Имя');*/}else{toggleBox('fname',1,'');}
  			if(form.mail.value==''){fl=false;toggleBox('mail',1,'<br/>Введите e-Mail<br/>'); /*alert('Введите e-Mail');*/}else{toggleBox('mail',1,'');}
  			if(form.city.value==''){fl=false;toggleBox('city',1,'<br/>Введите Город<br/>'); /*alert('Введите e-Mail');*/}else{toggleBox('city',1,'');}
			if (!form.mail.value.match(filter)) {fl=false;toggleBox('mail',1,'<br/>Введите  правельно e-Mail<br/>'); /*alert('Введите  правельно e-Mail ');*/	}else{toggleBox('mail',1,'');}
			if(form.mail.value!=form.mailCheck.value){fl=false;toggleBox('mailCheck',1,'<br/>Введите правельно e-Mail<br/>'); /*alert('Введите правельно e-Mail');*/}else{toggleBox('mailCheck',1,'');}
			if(form.psw.value==''){fl=false;toggleBox('psw',1,'<br/>Введите пожалуста пароль<br/>'); /*alert('Введите пожалуста пароль');*/}else{toggleBox('psw',1,'');}
			if(form.psw.value.length < 4 || (form.psw.value!=form.pswCheck.value)){fl=false;toggleBox('psw',1,'<br/>Введите пароль <br/>');/*alert('Введите правельно пароль, не меньше 4 символов');*/}else{toggleBox('psw',1,'');}
			
			return fl;
    	}
		function checkRegistrationEdit(form)
    	{
			setRegistartionEdit(form,form.fname.value,form.lname.value,form.city.value,form.mphone.value,form.mphone.value,form.hphone.value);
			fl=true;
			 var filter =/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;
			if(form.fname.value==''){fl=false;toggleBox('fname',1,'<br/>Введите  Имя<br/>'); /*alert('Введите  Имя');*/}else{toggleBox('fname',1,'');}
  			if(form.city.value==''){fl=false;toggleBox('city',1,'<br/>Введите Город<br/>'); /*alert('Введите e-Mail');*/}else{toggleBox('city',1,'');}
			if(form.psw.value==''){fl=false;toggleBox('psw',1,'<br/>Введите пожалуста пароль<br/>'); /*alert('Введите пожалуста пароль');*/}else{toggleBox('psw',1,'');}
			if(form.psw.value.length < 4 || (form.psw.value!=form.pswCheck.value)){fl=false;toggleBox('psw',1,'<br/>Введите правельно пароль, не меньше 4 символов<br/>');/*alert('Введите правельно пароль, не меньше 4 символов');*/}else{toggleBox('psw',1,'');}
			
			return fl;
    	}
function checkContact(form)
   	{
			fl=true;
			 var filter =/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;
			if(form.fname.value=='')			{fl=false;toggleBox('fname',1,'<br/>Введите  Имя<br/>'); 			}else{toggleBox('fname',1,'');}
  			if(form.mail.value=='')				{fl=false;toggleBox('mail',1,'<br/>Введите e-Mail<br/>'); 			}else{toggleBox('mail',1,'');}
			if (!form.mail.value.match(filter)) {fl=false;toggleBox('mail',1,'<br/>Введите  правельно e-Mail<br/>');}else{toggleBox('mail',1,'');}
			if(form.comments.value=='')			{fl=false;toggleBox('comments',1,'<br/>Введите коментарии <br/>');  }else{toggleBox('comments',1,'');}
			if(form.code.value=='')			{fl=false;toggleBox('code',1,'<br/>Введите Код подтверждения <br/>');  }else{toggleBox('code',1,'');}
	return fl;
   	}	
function setRegistartion(form,vfname,vlname,vcity,vmail,vmailCheck,vmphone,vmphone,vhphone)
{		

	form.fname.value=checkOnQuoteQuote(checkOnQuote(vfname));
	form.lname.value=checkOnQuoteQuote(checkOnQuote(vlname));
	form.city.value=checkOnQuoteQuote(checkOnQuote(vcity));
	form.mail.value=checkOnQuoteQuote(checkOnQuote(vmail));
	form.mailCheck.value=checkOnQuoteQuote(checkOnQuote(vmailCheck));
	form.mphone.value=checkOnQuoteQuote(checkOnQuote(vmphone));
	form.hphone.value=checkOnQuoteQuote(checkOnQuote(vhphone));
//	form.wphone.value=checkOnQuoteQuote(checkOnQuote(vwphone));

								
}
function setRegistartionEdit(form,vfname,vlname,vcity,vmphone,vmphone,vhphone)
{		

	form.fname.value=checkOnQuoteQuote(checkOnQuote(vfname));
	form.lname.value=checkOnQuoteQuote(checkOnQuote(vlname));
	form.city.value=checkOnQuoteQuote(checkOnQuote(vcity));
	form.mphone.value=checkOnQuoteQuote(checkOnQuote(vmphone));
	form.hphone.value=checkOnQuoteQuote(checkOnQuote(vhphone));
//	form.wphone.value=checkOnQuoteQuote(checkOnQuote(vwphone));

								
}

function checkInfo(form){
	form.value=checkOnQuote(form.value);
	form.value=checkOnQuoteQuote(form.value);
	}
function checkOnQuote(val){
var re = /"/g;
return val.replace(re, "&acute;");
}

function checkOnQuoteQuote(val){
var re = /'/g;
return val.replace(re, "&acute;");
}

function promptRegistartion(form)
{
		if(checkRegistration(form)==true){
			if(form.fname.value!=""){info2=" \n \n\n \n Вше имя:"+ form.fname.value;}
			if(form.lname.value!=""){info2+=" \n Ваша фамилия:"+form.lname.value;}
			if(form.city.value!=""){info2+=" \n Ваш Город:"+form.city.value;}
			if(form.mail.value!=""){info2+=" \n Ваш почтовый яшик (логин):"+form.mail.value;}
			if(form.mphone.value!=""){info2+=" \n Ваш мобильный телефон:"+form.mphone.value;}
			if(form.hphone.value!=""){info2+=" \n Ваш дополниотельный телефон 2:"+form.hphone.value;}
		//	if(form.wphone.value!=""){info2+=" \n Ваш дополнительный телефон 2 :"+form.wphone.value;}
			return true;//confirm(info+info2);
		}
		
}
function promptRegistartionEdit(form)
{

if(checkRegistrationEdit(form)==true){
			if(form.fname.value!=""){info2=" \n \n\n \n Вше имя:"+ form.fname.value;}
			if(form.lname.value!=""){info2+=" \n Ваша фамилия:"+form.lname.value;}
			if(form.city.value!=""){info2+=" \n Ваш Город:"+form.city.value;}
			if(form.mphone.value!=""){info2+=" \n Ваш мобильный телефон:"+form.mphone.value;}
			if(form.hphone.value!=""){info2+=" \n Ваш дополниотельный телефон 2:"+form.hphone.value;}

			return true;//confirm(info+info2);
		}
		
}
function checkLogin(form)
{			fl=true;
			 var filter =/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;
  			if(form.mail.value==''){fl=false;toggleBox('mail',1,'Введите e-Mail (логин)');}else{toggleBox('mail',1,'');}
			//if(!form.mail.value.match(filter)) {fl=false;toggleBox('mail',1,'Введите  правельно e-Mail (логин)');	}else{toggleBox('mail',1,'');}
			if(form.psw.value==''){fl=false;toggleBox('psw',1,'Введите пожалуста пароль');}else{toggleBox('psw',1,'');}
			if(form.psw.value.length < 4 ){fl=false;toggleBox('psw',1,'Введите правельно пароль, не меньше 4 символов');}else{toggleBox('psw',1,'');}
			
			return fl;
}
function checkMail(form)
{			fl=true;
			 var filter =/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;
  			if(form.mail.value==''){fl=false;toggleBox('mail',1,'Введите e-Mail (логин)');}else{toggleBox('mail',1,'');}
			if(!form.mail.value.match(filter)) {fl=false;toggleBox('mail',1,'Введите  правельно e-Mail (логин)');	}else{toggleBox('mail',1,'');}
			
			return fl;
}
function confirmRegistration(form,vfname,vlname,vcity,vmail,vREMOTE_ADDR,vmphone,vmphone,vhphone,vwphone,vpsw)
{		

	toggleBox('dfname',1,vfname);
	toggleBox('dlname',1,vlname);
	toggleBox('dcity',1,vcity);
	toggleBox('dmail',1,vmail);
	toggleBox('dmphone',1,vmphone);
	toggleBox('dhphone',1,vhphone);
	//toggleBox('dwphone',1,vwphone);

	form.fname.value=checkOnQuote(vfname);
	form.lname.value=checkOnQuote(vlname);
	form.city.value=checkOnQuote(vcity);
	form.mail.value=checkOnQuote(vmail);
	form.psw.value=checkOnQuote(vpsw);
	form.mphone.value=checkOnQuote(vmphone);
	form.hphone.value=checkOnQuote(vhphone);
	//form.wphone.value=checkOnQuote(vwphone);
	form.REMOTE_ADDR.value=checkOnQuote(vREMOTE_ADDR);
}


function toggleBox(szDivID, iState, TEXT) // 1 visible, 0 hidden
{
	var obj = document.layers ? document.layers[szDivID] :
	document.getElementById ?  document.getElementById(szDivID).style :
	document.all[szDivID].style;
	document.getElementById(szDivID).innerHTML = TEXT;
}
function toggleBox_2(szDivID, TEXT, n) // 1 visible, 0 hidden
{
	document.getElementById(szDivID).innerHTML = TEXT;
        var i;
        for (i = 1; i <= 6; i++) {
            var obj = getById('small_pic'+i);
            obj.style['background'] = i == n ? '#666666' : '#e3e3e3';
        }
}
function toggleBoxDiv(szDivID) // 1 visible, 0 hidden
{
 
    if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
       if(obj.style.visibility == "visible"){
	   	obj.style.visibility = "hidden";
	   	obj.style.display = "none";
	   }else{
		   obj.style.visibility = "visible";
	   		 obj.style.display = "block";	  
	   }

    }
    else if(document.all)	// IE 4
    {
      if(document.layers[szDivID].style.display == "block"){
	      document.all[szDivID].style.visibility ="hidden";
		  document.layers[szDivID].style.display = "none";	 

	  }else{
	      document.all[szDivID].style.visibility ="visible";
		  document.layers[szDivID].style.display = "block";

	  }

    }
}
function checkAvtoAnonce(){
	

}
function checkComments(form)
   	{
			fl=true;
			if(form.nickname.value=='')			{fl=false;toggleBox('nickname',1,'<br/>Введите  Имя<br/>'); 			}else{toggleBox('nickname',1,'');}
  			if(form.code.value=='')				{fl=false;toggleBox('code',1,'<br/>Введите код подтверждения<br/>');	}else{toggleBox('code',1,'');}
  			if(form.city.value=='')				{fl=false;toggleBox('city',1,'<br/>Введите ваш Город<br/>');			}else{toggleBox('city',1,'');}			
			if(form.message.value=='')			{fl=false;toggleBox('message',1,'<br/>Введите коментарии <br/>');  		}else{toggleBox('message',1,'');}
	return fl;
   	}
function checkEnter(e)
{ //e is event object passed from function invocation
        var characterCode;// literal character code will be stored in this variable

        if(e && e.which)
        { //if which property of event object is supported (NN4)
                e = e
                characterCode = e.which //character code is contained in NN4's which property
        }
        else
        {
                e = event
                characterCode = e.keyCode //character code is contained in IE's keyCode property
        }

        if(characterCode == 13)
        { //if generated character code is equal to ascii 13 (if enter key)
                document.forms['login'].submit(); //submit the form
//                return false;
        }
        else
                return true;

}

function popUp(URL,name) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, 'w" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,left = 0,top = 0');");
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
function MM_findObj(n, d) { //v4.0
var p,i,x;if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}}//-->
function getById(id) {
return (document.getElementById) ? document.getElementById(id) : document.all[id];}
var search_req_file = "/includes/searchrq.php";
var search_req = null;
function changeMarca(obj) {loadXMLDoc(search_req_file+'?action=list&id='+obj.value);}
function switchSearchForm() {toggleBoxDiv('search_div');}
function loadXMLDoc(url) {
if (window.XMLHttpRequest) {
search_req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {search_req = new ActiveXObject("Msxml2.XMLHTTP");} catch (e) {
try {search_req = new ActiveXObject("Microsoft.XMLHTTP");} catch (f) {
search_req = null;}}}
if (search_req) {
search_req.onreadystatechange = processReqChange;
search_req.open("GET", url, true);
search_req.send(null);}}
function processReqChange() {
var ready = search_req.readyState;
if (ready != 4) return;
var data = search_req.responseText;
//if (!data) return;
if (data.substr(0, 1) != '<') {
var obj = getById('search_count');
obj.innerHTML = data;
return;}
var list = '<select class="bar_search" name="model" onchange="onSearchFieldChange();"><option value="0">Любая</option>'+data+'</select>';
var o = getById('s_select_model');
o.innerHTML = list;
onSearchFieldChange();}
function makeQSearchQuery(t) {
 var f = document.forms['qsearch_form'];
 return t
 ? 'marca='+f['marca'].value+'&model='+f['model'].value+'&yearfrom='+f['yearfrom'].value+'&yearto='+f['yearto'].value+'&kmfrom='+f['kmfrom'].value+'&kmto='+f['kmto'].value+'&engine='+f['engine'].value+'&pricefrom='+f['pricefrom'].value+'&priceto='+f['priceto'].value
 : 'marca='+f['marca'].value+'|model='+f['model'].value+'|yearfrom='+f['yearfrom'].value+'|yearto='+f['yearto'].value+'|kmfrom='+f['kmfrom'].value+'|kmto='+f['kmto'].value+'|engine='+f['engine'].value+'|pricefrom='+f['pricefrom'].value+'|priceto='+f['priceto'].value;
return q;}
function onSearchFieldChange() {
loadXMLDoc(search_req_file+'?'+makeQSearchQuery(1));}
function initQSearchForm() {
var f = document.forms['qsearch_form'];
changeMarca(f['marca']);
if (f['marca'].value != 0) switchSearchForm();
}
function onQSearchClick() {
//document.location.href = '/?type=SearchResult&'+makeQSearchQuery()+'&datestart=90';
document.location.href = '/searchresult/'+makeQSearchQuery(0)+'|datestart=90';
//document.forms['qsearch_form'].submit();
}
function filterNumInput(obj) {
var v = '';
for (i = 0; i < obj.value.length; i++) {
var c = obj.value.substr(i, 1);
if (c >= '0' && c <= '9') v += c;}
obj.value = v;
}
function onTopSearch() {
var f = document.forms['topsearchform'];
//alert(window.location);
s = new String(window.location);
var ro = s.indexOf('/ro') >= 0 ? '/ro' : '';
var t = f['text'].value;
if (t.length > 1) {
    if (qs_div != '' && qs_div.indexOf('news') >= 0) {
        document.location.href = ro+'/'+qs_div+'/search/'+'text='+t;
        return false;
    }
    if (qs_div == 'sp')
        document.location.href = ro+'/announcements/sparepartslist/search/cat='+qs_sub+'|text='+t;
    else if (qs_div == 'wallpapers')
        document.location.href = ro+'/wallpapers/search/text='+t+(qs_sub==0?'':'|sub='+qs_sub);
    else
        document.location.href = ro+'/searchresult/'+(qs_div?'div='+qs_div+'|':'')+(qs_sub?'marca='+qs_sub+'|':'')+'text='+t;
}
return false;
}

