// JavaScript Document
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_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_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.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 callme(rno,td2){
  		 var tmp = document.getElementById(rno);
  		 tmp.className=td2
        }
		
function callme2(rno,td1){
		 var tmp = document.getElementById(rno);
		 tmp.className=td1
		}
function toggleBox(szDivID, iState, TEXT) // 1 visible, 0 hidden
{
	var obj = document.layers ? document.layers[szDivID] :	document.getElementById ?  document.getElementById(szDivID) :	document.all[szDivID];
	obj.innerHTML = TEXT;
//	document.getElementById(szDivID).innerHTML = TEXT;

}
/*#################################################################
CONTACT
###################################################################*/
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,'');}
	return fl;
   	}	
/*#################################################################
COMMENTS
###################################################################*/
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.message.value=='')			{fl=false;toggleBox('message',1,'<br/>Введите коментарии <br/>');  		}else{toggleBox('message',1,'');}
	return fl;
   	}	
	

/*#################################################################
REGISTARTION
###################################################################*/

function checknewsEmail(form)
{
fl=true;
			var error="";
			var filter =/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;
			if(!form.email.value.match(filter)) {fl=false;error+='Введите  правельно e-Mail (логин)\n';	}
		
			if(error){ alert(error); }
			return fl;
}
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/>'); }else{toggleBox('fname',1,'');}
		if(form.lname.value==''){fl=false;toggleBox('lname',1,'<br/>Введите  Фамилию<br/>'); }else{toggleBox('lname',1,'');}
		if(form.city.value==''){fl=false;toggleBox('city',1,'<br/>Введите Город<br/>'); }else{toggleBox('city',1,'');}
		if(form.index.value==''){fl=false;toggleBox('index',1,'<br/>Введите Почтовый индекс<br/>'); }else{toggleBox('index',1,'');}
		if(form.adress.value==''){fl=false;toggleBox('adress',1,'<br/>Введите Адрес <br/>'); }else{toggleBox('adress',1,'');}
		
		if(form.mail.value==''){fl=false;toggleBox('email',1,'<br/>Введите  E-mail<br/>');}else{toggleBox('email',1,'');}
		if(!form.mail.value.match(filter)) {fl=false;toggleBox('email',1,'<br/>Введите  правельно e-Mail<br/>'); }else{toggleBox('email',1,'');}
		

		if(form.psw.value==''){fl=false;toggleBox('epsw',1,'<br/>Введите пожалуста пароль<br/>');}else{toggleBox('epsw',1,'');}
		if(form.psw.value.length < 4 || (form.psw.value!=form.pswCheck.value)){fl=false;toggleBox('epswCheck',1,'<br/>Введите правельно пароль, не меньше 4 символов<br/>');}else{toggleBox('epswCheck',1,'');}
		if(form.liscence.checked==false){fl=false; toggleBox('liscence',1,'<br/>Если вы согласны с условиями Elcom поставте галачку<br/>');}else{toggleBox('liscence',1,'');}
return fl;
}
function checkRegistrationEdit(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/>'); }else{toggleBox('fname',1,'');}
		if(form.lname.value==''){fl=false;toggleBox('lname',1,'<br/>Введите  Фамилию<br/>'); }else{toggleBox('lname',1,'');}
		if(form.city.value==''){fl=false;toggleBox('city',1,'<br/>Введите Город<br/>'); }else{toggleBox('city',1,'');}
		if(form.index.value==''){fl=false;toggleBox('index',1,'<br/>Введите Почтовый индекс<br/>'); }else{toggleBox('index',1,'');}
		if(form.adress.value==''){fl=false;toggleBox('adress',1,'<br/>Введите Адрес <br/>'); }else{toggleBox('adress',1,'');}
		
		if(form.mail.value==''){fl=false;toggleBox('email',1,'<br/>Введите  E-mail<br/>');}else{toggleBox('email',1,'');}
		if(!form.mail.value.match(filter)) {fl=false;toggleBox('email',1,'<br/>Введите  правельно e-Mail<br/>'); }else{toggleBox('email',1,'');}
		

		if(form.psw.value==''){fl=false;toggleBox('epsw',1,'<br/>Введите пожалуста пароль<br/>');}else{toggleBox('epsw',1,'');}
		if(form.psw.value.length < 4 || (form.psw.value!=form.pswCheck.value)){fl=false;toggleBox('epswCheck',1,'<br/>Введите правельно пароль, не меньше 4 символов<br/>');}else{toggleBox('epswCheck',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 checkOnQuote(val){
var re = /"/g;
return val.replace(re, "&quot;");
}

function checkOnQuoteQuote(val){
var re = /'/g;
return val.replace(re, "&quot;");
}

function checkLogin(form)
{			fl=true;
			var error="";
			var filter =/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;
			if(!form.mail.value.match(filter)) {fl=false;error+='Введите  правельно e-Mail (логин)\n';	}
			if(form.psw.value.length < 4 ){fl=false;     error+='Введите правельно пароль, не меньше 4 символов\n';}
			
			if(error){ alert(error); }
			return fl;
}
/// regesstration 

function toggleBoxDiv(szDivID) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
      if(document.layers[szDivID].visibility=='visible'){
	  	 document.layers[szDivID].visibility = "hide";
		 document.layers[szDivID].style.display = "none";
		setTree(szDivID,0);
	  }else{
	  	  document.layers[szDivID].visibility = "show";
  		  document.layers[szDivID].style.display = "block";	  
		  setTree(szDivID,1);
	  }
    }
    else 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";
			setTree(szDivID,0);
	   }else{
			 obj.style.visibility = "visible";
	   		 obj.style.display = "block";	  
			setTree(szDivID,1);
	   }
    }
    else if(document.all)	// IE 4
    {
      if(document.all[szDivID].style.visibility=='visible'){
	      document.all[szDivID].style.visibility ="hidden";
		  document.layers[szDivID].style.display = "none";	 
		setTree(szDivID,0);
	  }else{
	      document.all[szDivID].style.visibility ="visible";
		  document.layers[szDivID].style.display = "block";
		setTree(szDivID,1);
	  }
    }
}

function setTree(idDiv,vh){
		eraseCookie('szDivIDtr');
		eraseCookie('szDivIDtd');
		createCookie('szDivIDtr',idDiv,20);
		createCookie('szDivIDtd',vh,20);
}

function getTreeSet(){
	if(readCookie('szDivIDtd')==1){
		toggleBoxDiv(readCookie('szDivIDtr'))
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

//-->