// Image Rollover & Preload
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.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 docopen(filename){
newwindow=window.open("","big","toolbar=0,menubar=0,scroolbars=0");
newwindow.document.open("text/html");
newwindow.document.writeln("<HTML><HEAD></HEAD><BODY leftmargin=0 topmargin=0  scroll=no>");
newwindow.document.writeln('<img src='+filename+' onClick="window.close();" style=CURSOR:hand; onload="resizeTo(width,height+28);">');
newwindow.document.writeln("</BODY></HTML>");
newwindow.document.close();
window.newwindow.focus();
}






function MM_preloadImages() { //v2.0
  if (document.images) {
    var imgFiles = MM_preloadImages.arguments;
    if (document.preloadArray==null) document.preloadArray = new Array();
    var i = document.preloadArray.length;
    with (document) for (var j=0; j<imgFiles.length; j++) if (imgFiles[j].charAt(0)!="#"){
      preloadArray[i] = new Image;
      preloadArray[i++].src = imgFiles[j];
  } }
}
MM_preloadImages('/data/images/about_menu_arrow_over.gif','/data/images/about_menu_arrow.gif');
function MM_swapImage() { //v2.0
  var i,j=0,objStr,obj,swapArray=new Array,oldArray=document.MM_swapImgData;
  for (i=0; i < (MM_swapImage.arguments.length-2); i+=3) {
    objStr = MM_swapImage.arguments[(navigator.appName == 'Netscape')?i:i+1];
    if ((objStr.indexOf('document.layers[')==0 && document.layers==null) ||
        (objStr.indexOf('document.all[')   ==0 && document.all   ==null))
      objStr = 'document'+objStr.substring(objStr.lastIndexOf('.'),objStr.length);
    obj = eval(objStr);
    if (obj != null) {
      swapArray[j++] = obj;
      swapArray[j++] = (oldArray==null || oldArray[j-1]!=obj)?obj.src:oldArray[j];
      obj.src = MM_swapImage.arguments[i+2];
  } }
  document.MM_swapImgData = swapArray; //used for restore
}
function MM_swapImgRestore() { //v2.0
  if (document.MM_swapImgData != null)
    for (var i=0; i<(document.MM_swapImgData.length-1); i+=2)
      document.MM_swapImgData[i].src = document.MM_swapImgData[i+1];
}
var info_mail = "$i$n$$f$o"; info_mail += "\x40"; info_mail += "v$$id$e$$o$scr$e$e$$n."; info_mail += "$r$u";
while(info_mail.indexOf("$") >= 0) { info_mail = info_mail.replace("$", ""); }
var advertising_mail = "$a$$$d$"; advertising_mail += "\x40"; advertising_mail += "v$$id$e$$o$scr$e$e$$n."; advertising_mail += "$r$u";
while(advertising_mail.indexOf("$") >= 0) { advertising_mail = advertising_mail.replace("$", ""); }
var support_mail = "$s$up$$po$r$$t$"; support_mail += "\x40"; support_mail += "v$$id$e$$o$scr$e$e$$n."; support_mail += "$r$u";
while(support_mail.indexOf("$") >= 0) { support_mail = support_mail.replace("$", ""); }
var enthronic_mail = "$i$$$nf$o$$"; enthronic_mail += "\x40"; enthronic_mail += "en$$t$hr$$$$o$ni$c$$."; enthronic_mail += "$r$u";
while(enthronic_mail.indexOf("$") >= 0) { enthronic_mail = enthronic_mail.replace("$", ""); }

function checkEmail(email) {
  var myRegExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  return myRegExp.test(email);
}

function DoSubmitEmail() {
  var user_email = "" + document.getElementById("user_email").value;
  var user_name = "" + document.getElementById("user_name").value;
  var user_question = "" + document.getElementById("user_question").value;

  var errorStr = "";
  if(user_email.length == 0) {
    errorStr += "Введите e-mail" + String.fromCharCode(13, 10);
  } else if(!checkEmail(user_email)) {
    errorStr += "Укажите правильный e-mail" + String.fromCharCode(13, 10);
  }
  if(user_name.length == 0) {
    errorStr += "Укажите свое имя" + String.fromCharCode(13, 10);
  }
  if(user_question.length == 0) {
    errorStr += "Задайте вопрос" + String.fromCharCode(13, 10);
  }

  if(errorStr.length != 0) { alert(errorStr); } else { document.question.submit(); }
}
function DoSubmitDealer() {
/*  var login = "" + document.getElementById("login").value;
  var password = "" + document.getElementById("password").value;

  var errorStr = "";
  if(login.length == 0) {
    errorStr += "Укажите имя пользователя" + String.fromCharCode(13, 10);
  }
  if(password.length == 0) {
    errorStr += "Укажите пароль" + String.fromCharCode(13, 10);
  }
  if(errorStr.length != 0) { alert(errorStr); } else { document.dealer_form.submit(); }*/
  document.dealer_form.submit();
}
function DoSubmitSearch(form_name) {
//  document.search_form.submit();
  document.getElementById(form_name).submit()
return;
}

function DoSubmitRegistry() {
  	var rf_comp_name = "" + document.getElementById("rf_comp_name").value;
  	var rf_phones = "" + document.getElementById("rf_phones").value;
  	var rf_mail = "" + document.getElementById("rf_mail").value;
  	var rf_login = "" + document.getElementById("rf_login").value;
  	var rf_pass = "" + document.getElementById("rf_pass").value;

  	var errorStr = "";
  	if(trim(rf_comp_name) == "") {
    		errorStr += "Введите название компании" + String.fromCharCode(13, 10);
	} else if (!isValidString(trim(rf_comp_name))) {
		errorStr += "Вы не можете использовать в названии компании любые из этих символов !#$%^&*()=+{}[]|\;:/?>,<'" + String.fromCharCode(13, 10);
	}
  	if(trim(rf_phones) == "") {
    		errorStr += "Укажите номера телефонов" + String.fromCharCode(13, 10);
	}
  	if(trim(rf_mail) == "") {
    		errorStr += "Введите e-mail" + String.fromCharCode(13, 10);
	} else if(!checkEmail(rf_mail)) {
    		errorStr += "Укажите правильный e-mail" + String.fromCharCode(13, 10);
  	}
  	if(trim(rf_login) == "") {
    		errorStr += "Укажите логин" + String.fromCharCode(13, 10);
	} else if (!isValidString(trim(rf_login))) {
		errorStr += "Вы не можете использовать в логине любые из этих символов !#$%^&*()=+{}[]|\;:/?>,<'" + String.fromCharCode(13, 10);
	}
  	if(trim(rf_pass) == "") {
    		errorStr += "Введите пароль" + String.fromCharCode(13, 10);
	} else if (!isValidString(trim(rf_pass))) {
		errorStr += "Вы не можете использовать в пароле любые из этих символов !#$%^&*()=+{}[]|\;:/?>,<'" + String.fromCharCode(13, 10);
	}

  	if(errorStr.length != 0) { alert(errorStr); } else { document.registry_form.submit(); }
}

function trim(str) {
	str = str.replace(/^\s+/g,"");
 	str = str.replace(/\s+$/g,"");

 	return str;
}

function isValidString(sValidate) {
	var sInvalidChars;
	var bTemp;
	var i;

	sInvalidChars = "!#$%^&*()=+{}[]|\;:/?>,<'";
	for (i = 0; i <sInvalidChars.length; i++ ) {
		if (sValidate.indexOf(sInvalidChars.substr(i, 1)) != -1) bTemp = true;
		if (bTemp) break;
	}
	for (i = 0; i < sValidate.length; i++) {
		if (sValidate.substr(i, 1).charCodeAt(0) == 160) bTemp = true;
		if (bTemp) break;
	}


	if (!bTemp) bTemp = (sValidate.indexOf("..") > 0);
	if (!bTemp) bTemp = (sValidate.indexOf("  ") > 0);
	if (!bTemp) bTemp = (sValidate.length != trim(sValidate).length);

	return !bTemp;
}

function show_picture(img) {
	window.open("show_image.asp?img=" + img, "imgWnd", "toolbar=no; location=no; menubar=no; status=no; directories=no; width=640; height=480; scrollbars=no; left=" + (screen.width-640)/2 + "; top=" + (screen.height-480)/2);
	return;
}

function checkFields() {
  	var fio = "" + document.getElementById("fio").value;
  	var email = "" + document.getElementById("email").value;
  	var question = "" + document.getElementById("question").value;

  	var errorStr = "";
  	if(trim(fio) == "") {
    		errorStr += "Введите ФИО" + String.fromCharCode(13, 10);
	}
  	if(trim(email) == "") {
    		errorStr += "Введите e-mail" + String.fromCharCode(13, 10);
	} else if(!checkEmail(email)) {
    		errorStr += "Укажите правильный e-mail" + String.fromCharCode(13, 10);
  	}
  	if(trim(question) == "") {
    		errorStr += "Укажите вопрос" + String.fromCharCode(13, 10);
	}
  	if(errorStr.length != 0) { alert(errorStr); } else { document.questionForm.submit(); }		
}

function showManagers(id) { 
	if (document.getElementById("tr_" + id + "_1"))
		document.getElementById("tr_" + id + "_1").style.display = (document.getElementById("tr_" + id + "_1").style.display == "none" ? "block" : "none");
	if (document.getElementById("tr_" + id + "_2"))
		document.getElementById("tr_" + id + "_2").style.display = (document.getElementById("tr_" + id + "_2").style.display == "none" ? "block" : "none");
}
