var opera = (navigator.userAgent.indexOf('Opera') >= 0);
var ie = (document.all && !opera);
var dom = (document.getElementById && !ie && !opera);

//  при загрузке
function fOnLoadWithDelay() {
    if (dom) {
        document.getElementById('tempBlock').style.display = "none";
        document.getElementById('tempBlock').style.cursor = "default";
        document.getElementById('mainBlock').style.display = "block";
    } else {
        document.all.tempBlock.style.display = "none";
        document.all.tempBlock.style.cursor = "default";
        document.all.mainBlock.style.display = "block";
    }

    setTimeout("return;", 2000);
}

//  при загрузке
function fOnLoad() {
    if (dom) {
        document.getElementById('tempBlock').style.display = "none";
        document.getElementById('tempBlock').style.cursor = "default";
        document.getElementById('mainBlock').style.display = "block";
    } else {
        document.all.tempBlock.style.display = "none";
        document.all.tempBlock.style.cursor = "default";
        document.all.mainBlock.style.display = "block";
    }
}

function isEmail(string) {
   if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
      return true;
   else
      return false;
}

function expandIt(elemName) {
    if (dom) {
        if (document.getElementById(elemName).style.display == "none") {
            document.getElementById(elemName).style.display = "block";
        } else {
            document.getElementById(elemName).style.display = "none";
        }
    } else {
        if (document.all[elemName].style.display == "none") {
            document.all[elemName].style.display = "block";
        } else {
            document.all[elemName].style.display = "none";
        }
    }
}

function ValidateMailForm(cform) {
  if(cform.subj.value.length<1){
     alert("Пожалуйста, введите тему!");
     cform.subj.focus();
     return false;
  }

  if(cform.name.value.length<1){
     alert("Пожалуйста, введите имя, фамилию!");
     cform.name.focus();
     return false;
  }

  if(cform.email.value == ""){
     alert("Пожалуйста, введите ваш электронный адрес!");
     cform.email.focus();
     return false;
  }

  if (!isEmail(cform.email.value)) {
      alert("Пожалуйства введите свой e-mail корректно");
      cform.email.focus();
      return false;
  }

  if(cform.msg.value == ""){
     alert("Пожалуйста, введите текст письма!");
     cform.msg.focus();
     return false;
  }

  return true;
}

function frmsubmit(action) {
    frm = document.bask_form;
    frm.action.value = action;
    if (action == 'clear') {
        if (confirm('Все товары будут удалены! Продолжить?')) frm.submit();
    } else {
        frm.submit();
    }
}

function changeValue(elemValue, elemName) {
    if (dom) {
        document.getElementById(elemName).value = document.getElementById(elemValue).value;
    } else {
        document.all[elemName].value = document.all[elemValue].value;
    }
}

function showSearchBlock(elemName, hElem1, hElem2) {
    if (dom) {
        document.getElementById(hElem1).style.display = "none";
        document.getElementById(hElem2).style.display = "none";
        document.getElementById(elemName).style.display = "block";

        document.getElementById("a_"+hElem1).style.color = "darkslateblue";
        document.getElementById("a_"+hElem2).style.color = "darkslateblue";
        document.getElementById("a_"+elemName).style.color = "orangered";
    } else {
        document.all[hElem1].style.display = "none";
        document.all[hElem2].style.display = "none";
        document.all[elemName].style.display = "block";

        document.all["a_"+hElem1].style.color = "darkslateblue";
        document.all["a_"+hElem2].style.color = "darkslateblue";
        document.all["a_"+elemName].style.color = "orangered";
    }
}

function CheckEmail(form) {
   var errmsg = "";

   if (form.email.value == "" || form.email.value == form.oldemail.value) {
      errmsg = 'Пожалуйства введите свой e-mail корректно\n\n';
      form.email.focus();
      alert(errmsg);
      return false;
   } else if (isEmail(form.email.value) == false) {
      errmsg = 'Пожалуйства введите свой e-mail корректно\n\n';
      form.email.focus();
      alert(errmsg);
      return false;
   }

   return true;
}

