var searchText = 'Поиск';
var is_ie = (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent));
function GID(id) { return (is_ie) ? document.all[id] : document.getElementById(id); }

$(document).ready(function() {
   checkFlash();
   checkGallery();
   $(".menuLeft").hover(
      function () {
         $(this).removeClass("menuLeft");
         $(this).addClass("menuLeftSel");
         $(this).prev().children().attr('src', 'image/m1-a.gif');
         $(this).next().children().attr('src', 'image/m2-a.gif');
      },
      function () {
         $(this).removeClass("menuLeftSel");
         $(this).addClass("menuLeft");
         $(this).prev().children().attr('src', 'image/m1.gif');
         $(this).next().children().attr('src', 'image/m2.gif');
      }
   ).click(function() { document.location.href = $(this).children().attr('href'); });
});

//onload = bodySize;
//onresize = bodySize;

function bodySize() {
   if ($.browser.msie && (document.documentElement.clientWidth || document.body.clientWidth)) {
      $("#tablemain").css('width', ((document.documentElement.clientWidth || document.body.clientWidth) > 1280) ? 1280 : "100%");
      $("#logo").css('width', ((document.documentElement.clientWidth || document.body.clientWidth) > 1280) ? 1280 : "100%");
   }
   setPhones();
}

function setPhones() {
   //var brouser = $.browser;
   //var offset = $(".topBgr2L img").offset();
   //var left = offset['left']-($.browser.msie ? 2 : 0);
   //$(".topTel").css({'top': 47, 'left': (left - 220)});
}

function fnCheckSearchForm(f) {
   if (!f.search.value.match(/^.+$/) || f.search.value == searchText) {
      alert("Укажите поисковый запрос!");
      f.search.focus();
      return false;
   }
   return true;
}

function fnCheckRegistrationForm(f) {
   if (!f.address.value.match(/(.+)/)) {
      alert("Укажите регион!");
      f.address.focus();
      return false;
   }
   if (!f.name.value.match(/(.+)/)) {
      alert("Укажите название организации!");
      f.name.focus();
      return false;
   }
   if (!f.sfere.value.match(/(.+)/)) {
      alert("Укажите сферу деятельности!");
      f.sfere.focus();
      return false;
   }
   if (!f.fio.value.match(/(.+)/)) {
      alert("Укажите ФИО!");
      f.fio.focus();
      return false;
   }
   if (!f.work.value.match(/(.+)/)) {
      alert("Укажите должность!");
      f.work.focus();
      return false;
   }
   if (!f.phones.value.match(/(.+)/)) {
      alert("Укажите контактный телефон!");
      f.phones.focus();
      return false;
   }
   if (!f.email.value.match(/^[0-9A-Za-z._-]+@([0-9a-z_-]+\.)+[a-z]{2,4}$/)) {
      alert("Укажите правильный E-mail!");
      f.email.focus();
      return false;
   }
   return true;
}

function fnCheckSubscribeForm(f) {
   if (!f.fio.value.match(/(.+)/)) {
      alert('Укажите ФИО!');
      f.fio.focus();
      return false;
   }
   if (!f.company.value.match(/(.+)/)) {
      alert('Укажите наименование организации!');
      f.company.focus();
      return false;
   }
   if (!f.email.value.match(/^[0-9A-Za-z\._-]+@([0-9a-z\._-]+\.)+[a-z]{2,4}$/)) {
      alert("Укажите правильно Ваш e-mail!");
      f.email.focus();
      return false;
   }
   return true;
}

function fnCheckOrderForm(f) {
   if (!f.fio.value.match(/(.+)/)) {
      alert('Укажите ФИО!');
      f.fio.focus();
      return false;
   }
   if (!f.phones.value.match(/(.+)/)) {
      alert('Укажите контактные телефоны!');
      f.phones.focus();
      return false;
   }
   if (!f.email.value.match(/^[a-zA-Z0-9._-]+\@[^\s:,]+\.[^\s:,]+$/i)) {
      alert('Укажите правильный e-mail!');
      f.email.focus();
      return false;
   }
   if (!f.address.value.match(/(.+)/)) {
      alert('Укажите адрес!');
      f.address.focus();
      return false;
   }
   return true;
}

function fnCheckRequirepriceForm(f) {
   if (!f.fio.value.match(/(.+)/)) {
      alert('Укажите ФИО!');
      f.fio.focus();
      return false;
   }
   if (!f.phones.value.match(/(.+)/)) {
      alert('Укажите контактные телефоны!');
      f.phones.focus();
      return false;
   }
   if (!f.email.value.match(/^[a-zA-Z0-9._-]+\@[^\s:,]+\.[^\s:,]+$/i)) {
      alert('Укажите правильный e-mail!');
      f.email.focus();
      return false;
   }
   return true;
}

function showNeed(val) {
   if (val == 1) {
      $("input[name=fiz_fio]").attr('value', '');
      $("input[name=fiz_address]").attr('value', '');
      $("input[name=fiz_phones]").attr('value', '');
      $("input[name=fiz_email]").attr('value', '');
      $("input[name=fiz_education]").attr('value', '');
      $("input[name=fiz_work]").attr('value', '');
      $("#show1").css('display', 'block');
      $("#show2").css('display', 'none');
   }
   else if (val == 2) {
      $("input[name=ur_company]").attr('value', '');
      $("#ur_fio").attr('value', '');
      $("input[name=ur_inn_kpp]").attr('value', '');
      $("input[name=ur_fact_address]").attr('value', '');
      $("input[name=ur_ur_address]").attr('value', '');
      $("input[name=ur_sfere]").attr('value', '');
      $("input[name=ur_fio_contact]").attr('value', '');
      $("input[name=ur_phones]").attr('value', '');
      $("input[name=ur_fax]").attr('value', '');
      $("input[name=ur_email]").attr('value', '');
      $("#show1").css('display', 'none');
      $("#show2").css('display', 'block');
   }
}
