var OP = (navigator.appName == "Opera" || window.opera);
var IE = (navigator.appName == "Microsoft Internet Explorer")
var NS = (navigator.appName == "Netscape") //NS и Mozilla 
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();                  
var simvols_fields  = new Array();    
var whiteBlockEdit = "table-row";
if(IE) whiteBlockEdit = "block";
var message1  = "Заполните все обязательные поля формы!";
var message2  = "Неверный адрес почты!";
var message3  = "Это числовое поле!";
var message4  = "Это числовое поле!";
var message5  = "Поле не должно содержать символов / \\ : * ? \" < > |";

sfHover = function() {
	var sfEls = document.getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if(NS) if (window.attachEvent) window.attachEvent("onload", sfHover);

function Submenu(idNum, act)
{
  var id = 'submenu' + idNum;
  var submenuobj = document.getElementById(id);

  if(act == 0)
  {
    submenuobj.style.display = 'none';
  }
  else
  {
    submenuobj.style.display = whiteBlockEdit;    
  }
}

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)
{
 str = new String(document.all(name).value);
 if (str.length < 3)
 { alert(str.length);return false;}
 
		if (document.all(name).value == "") {alert(message);document.all(name).focus();return false;}
}//end function SubmitForm
	

function Submit_Form()
{
	for(i = 0; i < required_fields.length; i++)
	{
		if(document.getElementById(required_fields[i]).value == "")
		{
			document.getElementById(required_fields[i]).focus();
			alert(message1);
			return false;
		}
	}

	for(i = 0; i < int_fields.length; i++)
	{
		if(document.getElementById(int_fields[i]).value != "")
		{	 
   		if(!	(/^[0-9]+$/.test(document.getElementById(int_fields[i]).value) ) )
   		{  
   			alert(message4);
   			document.getElementById(int_fields[i]).focus();
   			return false;
   		}
		}
	}
	
	for(i = 0; i < float_fields.length; i++)
	{
		if(document.getElementById(float_fields[i]).value != "")
		{	 
   		if(!	(/^[0-9\.]+$/.test(document.getElementById(float_fields[i]).value) ) )
   		{  
   			alert(message4);
   			document.getElementById(float_fields[i]).focus();
   			return false;
   		}
		}
	}

	for(i = 0; i < email_fields.length; i++)
	{	
		if(document.getElementById(email_fields[i]).value != "")
		{
   	  if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.getElementById(email_fields[i]).value)) )
   		{  
   			alert(message2);
   			document.getElementById(email_fields[i]).focus();
   			return false;
   		}
		}
	}
	
	var re,name;
	re=/(\")/;
	
	for(i = 0; i < simvols_fields.length; i++)
	{
	  name = document.getElementById(simvols_fields[i]).value;
  	if (name.match(re) != null)
		{
	  	alert(message5);
 			document.getElementById(simvols_fields[i]).focus();
 			return false;
		}
	}

	for(i = 0; i < pwd_fields.length; i++)
	{
  	if(document.getElementById(pwd_fields[0]).value != document.getElementById(pwd_fields[1]).value)
  	{
  		alert(message3);
  		document.getElementById(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(photo,photo_preview)
	{
		var re = /\\/g;
		var sn = "file://localhost/"+photo.replace(re,"/");
		var preview;
		var ratio;
		
    preview =	document.getElementById(photo_preview);
    preview.src = sn;
    /*
		if(preview.width > 200) 
		{
		  ratio = preview.width / 200;
			preview.width = Math.round(preview.width / ratio); 
			preview.height = Math.round(preview.height / ratio); 
		}
		else if(preview.height > 200)
		{
		  alert(preview.height);
		  ratio = preview.height / 200;
			preview.width = Math.round(preview.width / ratio); 
			preview.height = Math.round(preview.height / ratio); 
		}				
    */
	}

	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 DeleteForm(form,name,id)
	{
	  var info = "";
	  if(id == 1) info = "исполнителя";
	  if(id == 2) info = "альбом";
	  if(id == 3) info = "песню";
	  if(id == 4) info = "вопрос";
	  if(id == 5) info = "ответ";
	  if(id == 6) info = "статью";
	  if(id == 7) info = "раздел фото";
	  if(id == 8) info = "фотографию";
		if(window.confirm("Удалить "+info+" "+name+"?")){document.getElementById(form).submit();return true;}		
		return false;
	}

	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 Submit_search(radioName)
	{
	  var s1 = document.getElementById("txt_singer");
	  varstring1 = new String(s1.value);
	  var check1 = document.getElementById("check_singer");
	  var s2 = document.getElementById("txt_album");
	  varstring2 = new String(s2.value);
	  var check2 = document.getElementById("check_album");
	  var s3 = document.getElementById("txt_song");
	  varstring3 = new String(s3.value);
	  var check3 = document.getElementById("check_song");
	  	 
	  for (i = 1; i < 4; i++)
	  {
	   if(eval("check"+i).checked)  if(eval("varstring"+i) == ""){alert("Заполните поле поиска!");return false;}    
	   if(eval("check"+i).checked)  if(eval("varstring"+i).length < 3){alert("Запрос поиска должен состоять не менее чем из 3-х символов!");return false;}
	  }
	  
	  if(check1.checked == false && check2.checked == false && check3.checked == false) {alert("Установите нужные флажки!");return false;}    
	  
    //alert(document.all(radioName).length);
    if(!validate_search(radioName))
    {
      alert ("Защита от роботов!"+"\n\r"+"Укажите нужную фотографию исполнителя!");
      return false;
    }
	}
	
	function Submit_url(radioName)
	{
	  var s1 = document.getElementById("txt_url");
	  varstring1 = new String(s1.value);
	  var s2 = document.getElementById("txt_email");
	  varstring2 = new String(s2.value);
	  	  	 
	  for (i = 1; i < 2; i++)
	  {
     if(eval("varstring"+i) == "") {alert("Заполните поле URL ссылки !");return false;}    
	  }
 
		if(varstring2 != "")
		{
   	  if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(varstring2)) )
   		{  
   			alert(message2);
   			s2.focus();
   			return false;
   		}
		}	  
    //alert(document.all(radioName).length);
    if(!validate_search(radioName))
    {
      alert ("Защита от роботов!"+"\n\r"+"Укажите нужную фотографию исполнителя!");
      return false;
    }
	}	
	
	function Submit_faq(radioName)
	{
	  var s1 = document.getElementById("txt_name");
	  varstring1 = new String(s1.value);
	  var s2 = document.getElementById("txt_descr");
	  varstring2 = new String(s2.value);
	  var s3 = document.getElementById("txt_email");
	  varstring3 = new String(s3.value);	  
  
	  for (i = 1; i < 3; i++)
	  {
     if(eval("varstring"+i) == "") {alert(message1);return false;}    
	  }
	  
		if(varstring3 != "")
		{
   	  if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(varstring3)) )
   		{  
   			alert(message2);
   			s3.focus();
   			return false;
   		}
		}
 
    //alert(document.all(radioName).length);
    if(!validate_search(radioName))
    {
      alert ("Защита от роботов!"+"\n\r"+"Укажите нужную фотографию исполнителя!");
      return false;
    }
	}		
		
	
	function validate_search(radioName)
  {
    for (var i=0; i < document.all(radioName).length; i++)
      if (document.all(radioName)[i].checked) return document.all(radioName)[i].value;
    return false;
  }
	
String.prototype.printAddr = 
function (_hamper,_prefix,_postfix,_face)
{
  _hamper=
  _prefix+
  "@"+
  this+
  (_postfix || '')
  document.write((_face||_hamper).link("mailto:"+_hamper));
}

function addBookmark(url, title)
{
  if (!url) url = location.href;
  if (!title) title = document.title;
  
  //Gecko
  if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");
  //IE4+
  else if (typeof window.external == "object") window.external.AddFavorite(url, title);
  //Opera7+
  else if (window.opera && document.createElement)
  {
    var a = document.createElement('A');
    if (!a) return false; //IF Opera 6
    a.setAttribute('rel','sidebar');
    a.setAttribute('href',url);
    a.setAttribute('title',title);
    a.click();
  }
  else return false;
  
  return true;
}

function tag(str1, str2, form, obj)
{
 var obj = document.getElementById(obj);
 obj.focus();   
 
 if(document.selection)   // Для IE  
 {  
  var s = document.selection.createRange();  
  if(s.text)  
  {  
	  s.text = str1 + s.text + str2;  
  }  
	else 
  {  
   obj.value = obj.value + str1 + str2;  
  }  
  return true;  
 }  
 else if (typeof(obj.selectionStart) == "number")// Opera, FireFox    
 {  
  if (obj.selectionStart != obj.selectionEnd)  
  {  
	  var start = obj.selectionStart;  
  	var end = obj.selectionEnd;  
	  s = obj.value.substr(start,end-start);  
    obj.value = obj.value.substr(0, start) + str1 + s + str2 + obj.value.substr(end);  
  }  
  else 
  {  
   obj.value = obj.value + str1 + str2;  
  }  
  return true;  
 }
 else return false;  
} 
  
  
function Block_display(id,visible)
{
  var obj = document.getElementById(id);
  if(visible==1)
  {
    obj.style.display = whiteBlockEdit;
  }
  else
  {
    obj.style.display = 'none';    
  }
}  
