/*
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
*/
var required_fields = new Array();
var email_fields    = new Array();
var pwd_fields      = new Array();
var int_fields      = new Array();
var float_fields    = new Array();


function set_language(form,lang)
{
 document.cookie = "langadmin = "+lang;
 form.submit();
}

function SubmitSearch(name,message)
{
 str = new String(document.all(name).value);
 if (str.length < 3)
 {
  alert(message); //Поле должно содержать не менее 3-х символов!
  document.all(name).focus();
  return false;
 }
}//end function SubmitSearch


function SubmitForm(name,message)
{
	if (document.all(name).value == "") {alert(message);document.all(name).focus();return false;}
}//end function SubmitForm

//message1  - Заполните все обязательные поля формы!
//message2  - Неверный адрес почты!
//message3  - Это числовое поле!
//message4  - Это числовое поле!
function Submit_Form(message1,message2,message3,message4)
{

	for(i = 0; i < required_fields.length; i++)
	{
		if(document.all(required_fields[i]).value=="")
		{
			document.all(required_fields[i]).focus();
			alert(message1);
			return false;
		}
	}

	for(i = 0; i < int_fields.length; i++)
	{
		if(document.all(int_fields[i]).value != "")
		{
 		if(!	(/^[0-9]+$/.test(document.all(int_fields[i]).value) ) )
 		{
 			alert(message4);
 			document.all(int_fields[i]).focus();
 			return false;
 		}
		}
	}

	for(i = 0; i < float_fields.length; i++)
	{
		if(document.all(float_fields[i]).value != "")
		{
 		if(!	(/^[0-9\.]+$/.test(document.all(float_fields[i]).value) ) )
 		{
 			alert(message4);
 			document.all(float_fields[i]).focus();
 			return false;
 		}
		}
	}


	for(i = 0; i < email_fields.length; i++)
	{
		if(document.all(email_fields[i]).value != "")
		{
 	 if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.all(email_fields[i]).value)) )
 		{
 			alert(message2);
 			document.all(email_fields[i]).focus();
 			return false;
 		}
		}
	}

	if(document.all(pwd_fields[0]).value !=document.all(pwd_fields[1]).value)
	{
		alert(message3);
		document.all(pwd_fields[0]).focus();
		return false;
	}

}//End function Submit_Form




function SubmitFormFields(message)
{
	var b_error=false;
	for(i=0;i<required_fields.length;i++)
	{
		if(document.all(required_fields[i]).value=="")
		{
			document.all(required_fields[i]).focus();
			alert(message);
			return false;
			break;
		}
	}//for
}//end function SubmitFormFields

function trim(s)
{
	return s.replace(/^\s*(.+?)\s*$/, "$1");
}


	function Delete_record(form,message)
	{
		if(confirm(message)) {form.submit();return true;}
		return false;
	}

	function Delete_all_record(message)
	{
		if(confirm(message)) {return true;}
		return false;
	}

	function Form_Delete_file(name,str)
	{
 	if(confirm(str+" "+name+"?")) return true;
 	else return false;
	}

	function Form_Multi_Values(form,element)
	{
		document.all(element).value=1;
		form.submit();
		return true;
	}


	function setPointer(theRow, thePointerColor)
	{
				if (thePointerColor == '' || typeof(theRow.style) == 'undefined') {return false;}
				if (typeof(document.getElementsByTagName) != 'undefined')   {
								var theCells = theRow.getElementsByTagName('td');
																																																																}
				else if (typeof(theRow.cells) != 'undefined')               {
								var theCells = theRow.cells;
																																																																}
				else {return false;}

				var rowCellsCnt  = theCells.length;
				for (c = 0; c < rowCellsCnt; c++)
				{
					theCells[c].style.backgroundColor = thePointerColor;
				}

				return true;
	}

	function setCheckboxes(form,id,row,do_check)
	{

	 	var curretObj;
 		if(row == 1)
	 	{
		 		for(i = 0; i < 5; i++)
	    {
	      curretObj = form.elements['permission['+id+']['+i+']'];
	  	   curretObj.checked = do_check;
	    }
		 }
		 else
		 {
  	 	for(i = 5; i < 10; i++)
  	  {
	      curretObj = form.elements['permission['+id+']['+i+']'];
	  	   curretObj.checked = do_check;
  	  }
		 }

 	return true;
	} // end of the 'setCheckboxes()' function


	function ShowPreview(img_value,img_preview,img_mini,img_pixel,img_size,img_zoom)
	{
		var re=/\\/g;
		var sn="file://localhost/"+img_value.replace(re,"/");
		document.all(img_preview).src = sn;
		
		var width = 0;
		var height = 0;
		var ratio; // вычисление пропорций 
		
		if(img_pixel != "")
		{
			//document.all(img_mini).width = document.all(img_pixel).value;
			
			if(img_zoom != "")
			{
				if(document.all(img_zoom).checked) //квадрат
				{
					document.all(img_mini).height = document.all(img_pixel).value;
				}
				else
				{
				  
				  if(document.all(img_size).checked) // ширина   
				  {
				    ratio = document.all(img_preview).width / document.all(img_pixel).value; 
				    
  					if(document.all(img_preview).width > document.all(img_pixel).value ) 
  					{
  						document.all(img_mini).width = Math.round(document.all(img_preview).width / ratio); 
  						document.all(img_mini).height = Math.round(document.all(img_preview).height / ratio); 
  					}
  					else
  					{
  						document.all(img_mini).width = document.all(img_preview).width;
  						document.all(img_mini).height = document.all(img_preview).height;
  					}				   
				  }
				  else // высота    
				  {
				    ratio = document.all(img_preview).height / document.all(img_pixel).value; 
				    
  					if(document.all(img_preview).height > document.all(img_pixel).value ) 
  					{
  						document.all(img_mini).width = Math.round(document.all(img_preview).width / ratio); 
  						document.all(img_mini).height = Math.round(document.all(img_preview).height / ratio); 
  					}
  					else
  					{
  						document.all(img_mini).width = document.all(img_preview).width;
  						document.all(img_mini).height = document.all(img_preview).height;
  					}				   
				  }				  

				}
			}
		}

		document.all(img_mini).src=sn;
	}

  function Preview(img_value,img_preview)
	{
		var re = /\\/g;
		var sn = "file://localhost/"+img_value.replace(re,"/");
		document.all(img_preview).src = sn;
	}
	
	function check_pass(message)
	{
		if(f1.password.value!=f1.password2.value)
		{
			alert(message);
			f1.password.focus();
		}
	}

	function check_form(b_name)
	{
		var b_error=false;
		if(f1.descr.value=="")b_error=true;
		if(f1.login.value=="")b_error=true;
		if(f1.email.value=="")b_error=true;
		if(!b_error)
		{
			document.all(b_name).disabled=false;
		}
	}


function Submit_Reg(message1,message2)
{
		if (document.all("login").value=="") {alert(message1);document.all("login").focus();return false;}
		if (document.all("pwd").value=="") {alert(message2);document.all("pwd").focus();return false;}
}

function Submit_Subscribe(message1,message2)
{
		if (document.all("name").value=="") {alert(message1);document.all("name").focus();return false;}
		if (document.all("email").value=="") {alert(message1);document.all("email").focus();return false;}

		if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.all("email").value)) )
		{
				alert(message2);
				document.all("email").focus();
				return false;
		}
}

	function showGalleryImage(url, name, w, h)
	{
		var n3 = (navigator.appName.indexOf('Netscape')!=-1 && navigator.appVersion.indexOf('3.')!=-1)?true:false;
		var ww = (n3)?(parseInt(w)+15):parseInt(w);
		var wh = (n3)?(parseInt(h)+15):parseInt(h);
		var winname = (name.indexOf(' ')!=-1)?name.substring(0, name.indexOf(' ')):name;
		var wnd = window.open('', winname, 'width='+ww+',height='+(wh));
		var code = '<html><head>\n<title>'+name+'</title></head>\n'+
			   '<body bgcolor="White" marginwidth=0 marginheight=0 leftmargin=0 topmargin=0>\n'+
			   '<div align="center"><img src='+url+' onLoad="window.moveTo((screen.width - this.width) / 2 , (screen.height - this.height) / 2); if (navigator.appName==\'Netscape\'){window.outerWidth = this.width;	window.outerHeight = this.height+25;}else window.resizeTo(this.width, this.height+25); window.focus();" name="main_img"></div></body></html>';
		wnd.document.write(code);
		wnd.document.close();
	}
	function sp_f(form)
{
       form.Sp1.value = Math.round((Math.round(form.Wdn.options[form.Wdn.selectedIndex].value*form.Hdn.options[form.Hdn.selectedIndex].value*2
      +form.Rdn.options[form.Rdn.selectedIndex].value*25.4)
      /Math.round(form.Wd.options[form.Wd.selectedIndex].value*form.Hd.options[form.Hd.selectedIndex].value*2
      +form.Rd.options[form.Rd.selectedIndex].value*25.4))*form.Sp.value*100)/100;

      form.Sp2.value = Math.round((form.Sp1.value-form.Sp.value)*100)/100
}

function t_calc(form)
{
      form.Tw.value = form.Wd.options[form.Wd.selectedIndex].value;
      form.Tw1.value = form.Wdn.options[form.Wdn.selectedIndex].value;
      form.Tw2.value = form.Wdn.options[form.Wdn.selectedIndex].value-form.Wd.options[form.Wd.selectedIndex].value;

      form.Tr.value = Math.round(form.Rd.options[form.Rd.selectedIndex].value*25.4);
      form.Tr1.value = Math.round(form.Rdn.options[form.Rdn.selectedIndex].value*25.4);
      form.Tr2.value = Math.round(form.Rdn.options[form.Rdn.selectedIndex].value*25.4)-Math.round(form.Rd.options[form.Rd.selectedIndex].value*25.4);

      form.Th.value = Math.round(form.Wd.options[form.Wd.selectedIndex].value*form.Hd.options[form.Hd.selectedIndex].value*2
      +form.Rd.options[form.Rd.selectedIndex].value*25.4);
      form.Th1.value = Math.round(form.Wdn.options[form.Wdn.selectedIndex].value*form.Hdn.options[form.Hdn.selectedIndex].value*2
      +form.Rdn.options[form.Rdn.selectedIndex].value*25.4);
      form.Th2.value = Math.round(form.Wdn.options[form.Wdn.selectedIndex].value*form.Hdn.options[form.Hdn.selectedIndex].value*2
      +form.Rdn.options[form.Rdn.selectedIndex].value*25.4)
      -Math.round(form.Wd.options[form.Wd.selectedIndex].value*form.Hd.options[form.Hd.selectedIndex].value*2
      +form.Rd.options[form.Rd.selectedIndex].value*25.4);

      form.Kl.value = (Math.round(form.Wdn.options[form.Wdn.selectedIndex].value*form.Hdn.options[form.Hdn.selectedIndex].value*2
      +form.Rdn.options[form.Rdn.selectedIndex].value*25.4)
      -Math.round(form.Wd.options[form.Wd.selectedIndex].value*form.Hd.options[form.Hd.selectedIndex].value*2
      +form.Rd.options[form.Rd.selectedIndex].value*25.4))/2;

      form.Sp1.value = Math.round((Math.round(form.Wdn.options[form.Wdn.selectedIndex].value*form.Hdn.options[form.Hdn.selectedIndex].value*2
      +form.Rdn.options[form.Rdn.selectedIndex].value*25.4)
      /Math.round(form.Wd.options[form.Wd.selectedIndex].value*form.Hd.options[form.Hd.selectedIndex].value*2
      +form.Rd.options[form.Rd.selectedIndex].value*25.4))*form.Sp.value*100)/100;

      form.Sp2.value = Math.round((form.Sp1.value-form.Sp.value)*100)/100
	}