var params = {
 menu: "false",
 wmode: "transparent"
};
var subscrText = "E-mail";
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); }

function commitFlashObject(_obj, _container) {
   var _output = "";
   var _paramoutput = "";
   for (_cO in _obj) {
      if (_cO != "movie" && _cO != "FlashVars" && _cO != "wmode" && _cO != "quality") _output += _cO+"=\""+_obj[_cO]+"\" ";
      if (_cO != "data" && _cO != "width" && _cO != "height") _paramoutput += "<param name=\""+_cO+"\" value=\""+_obj[_cO]+"\" />\n";
   }
   var ihtm = "<object type=\"application/x-shockwave-flash\" "+_output+">\n";
   ihtm += _paramoutput;
   ihtm += "</object>\n";
   GID(_container).innerHTML = ihtm;
}

function showFlash(path, width, height, div, vars, wmode) {
   var myFlashObject = new Object;
   myFlashObject.movie = path;
   myFlashObject.data = path;
   myFlashObject.quality = "high";
   if (width) myFlashObject.width = width;
   if (height) myFlashObject.height = height;
   if (vars != "") myFlashObject.FlashVars = vars;
   if (wmode != "") myFlashObject.wmode = wmode;
   commitFlashObject(myFlashObject, div);
}

function checkFlash() {
   var flash_versions = 20; var flash_installed = 0; var flash_version = '0.0'; var java_installed = 0;
   if (navigator.plugins && navigator.plugins.length) {  // Netscape style plugin detection
      for (x = 0; x < navigator.plugins.length; x++) {
         if (navigator.plugins[x].name.indexOf('Shockwave Flash') != -1) {
            flash_version = navigator.plugins[x].description.split('Shockwave Flash ')[1];
            flash_installed = 1;
            break;
         }
      }
      for (x = 0; x < navigator.plugins.length; x++) {
         if (navigator.plugins[x].name.indexOf('Java(TM)') != -1) {
            java_installed = 1;
            break;
         }
      }
   }
   else if (window.ActiveXObject) {  // ActiveX style plugin detection
      for (x = 2; x <= flash_versions; x++) {
         try {
            oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + x + "');");
            if (oFlash) {
               flash_installed = 1;
               flash_version = x + '.0';
            }
         }
         catch(e) { }
      }
   }
   return flash_installed;
}

var isFlash = checkFlash();

function SelMenu(tmp, a, flag) {   obj = (flag == true ? tmp : GID(tmp));
   obj.style.background = 'url("image/aktiv-menu.gif") no-repeat 50% 100%';
   obj = GID(a);
   obj.style.color = '#E7921B';
   obj.style.textDecoration = 'none';}

function UnSelMenu(tmp, a, flag) {
   obj = (flag == true ? tmp : GID(tmp));
   obj.style.background = 'none';
   obj = GID(a);
   obj.style.color = '#2E3687';
   obj.style.textDecoration = 'underline';
}

function ShowHint(tmp, left, top) {   obj = GID(tmp);
   obj.style.left = left;
   obj.style.top = top;
   obj.style.display = 'block';}

function HideHint(tmp) {
   obj = GID(tmp);
   obj.style.display = 'none';
}

function fnCheckSearchForm(f) {
   if (!f.search.value.match(/^.+$/)) {
      alert("Укажите поисковый запрос!");
      f.search.focus();
      return false;
   }
   return true;
}

function CheckAddItemForm(f) {   if (!f.addItem.value.match(/^[0-9]+$/)) {
      alert("Укажите правильный артикул!");
      f.addItem.focus();
      return false;
   }
   return true;
}

function fnCheckSubscribeForm(f) {
   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 fnCheckRegistrationForm(f) {
   if (!f.name.value.match(/(.+)/)) {
      alert("Укажите ФИО!");
      f.name.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;
   }
   if (!f.phone.value.match(/(.+)/)) {
      alert("Укажите телефон!");
      f.phone.focus();
      return false;
   }
   if (!f.address.value.match(/(.+)/)) {
	  alert("Укажите адрес!");
	  f.address.focus();
	  return false;
   }
   if (!f.password.value.match(/[0-9A-Za-z._-]+/)) {
	  alert("Пароль может содержать только латинские буквы, цифры и знаки '.', '_', '-'");
	  f.password.focus();
	  return false;
   }
   if (!f.password.value.match(/(.+)/)) {
      alert("Укажите пароль!");
      f.password.focus();
      return false;
   }
   if (f.password.value != f.re_password.value) {
      alert("Подтверждение пароля не совпадает с основным паролем!");
      f.re_password.focus();
      return false;
   }
   if (!f.code.value.match(/(.+)/)) {
      alert("Укажите правильный код!");
      f.code.focus();
      return false;
   }
   return true;
}

function fnCheckOrders(obj) {
   var is_ok = false;
   for (i = 0; i < obj.length; i++) {
      if (obj[i].type == "text") {
         if (!obj[i].value.match(/^([1-9][0-9]*)?$/)) {
            alert("Введено некорректное значение!");
            obj[i].focus();
            return false;
         }
         if (is_ok == false) {
            if (obj[i].value) {
               is_ok = true;
            }
         }
      }
   }
   if (is_ok == false) {
      alert("Укажите количество заказываемых позиций!");
      return false;
   }
   return true;
}

function fnSetStrings(val) {   var e1 = GID('pdString');
   var e2 = GID('pdSumma');
   var e3 = GID('itogString');
   var e4 = GID('itogSumma');
   var e5 = GID('sumString');
   var e6 = GID('sumSumma');
   if (val == 1) {      e1.style.display = 'block';      e2.style.display = 'block';
      e3.style.display = 'block';
      e4.style.display = 'block';
      e5.innerHTML = 'Сумма:&nbsp;';
      e5.style.fontWeight = 'normal';
      e6.style.fontWeight = 'normal';
   }
   else {      e1.style.display = 'none';
      e2.style.display = 'none';
      e3.style.display = 'none';
      e4.style.display = 'none';
      e5.innerHTML = 'Итого:&nbsp;';
      e5.style.fontWeight = 'bold';
      e6.style.fontWeight = 'bold';
   }}

function fnSetRegionString(val, reg, price) {   var obj = document.addOrder;
   var e = GID('regionsString');
   var e1 = GID('radioBlock');
   var e2 = GID('radioBlock2');
   var e5 = GID('sumString');
   var e6 = GID('sumSumma');
   if (val != 'Москва' || reg != 'Москва') e.style.display = 'block';
   else e.style.display = 'none';
   if (val == 'Москва') {      e1.style.display = 'block';
      e2.style.display = 'block';
      e5.style.display = 'block';
      e6.style.display = 'block';
      for (i = 0; i < obj.length; i++) {
         if (obj[i].type == "radio") {
            if (obj[i].value == 2 && price >= 6000 && price < 35000) { obj[i].checked = true; obj[i].disabled = false; }
            else if (obj[i].value == 4 && price >= 35000 && price < 45000) { obj[i].checked = true; obj[i].disabled = false; }
            else if (obj[i].value == 5 && price >= 45000) { obj[i].checked = true; obj[i].disabled = false; }
            else obj[i].checked = false;
         }
      }
   }   else {
      fnSetStrings(3);
      e1.style.display = 'none';
      e2.style.display = 'none';
      e5.style.display = 'none';
      e6.style.display = 'none';
      for (i = 0; i < obj.length; i++) {
         if (obj[i].type == "radio") {
            if (obj[i].value == 3) obj[i].checked = true;
            else obj[i].checked = false;
         }
      }
   }
}

var maxLen = 1200;
function checkMaxInput(form) {
   if (form.comment.value.length > maxLen)
   form.comment.value = form.comment.value.substring(0, maxLen);
}

function printPage(form) {   var e = GID('commentP');
   e.innerHTML = form.comment.value;
   window.print();}
