var MT='';

var img = new Array();

var isDOM = (document.getElementById ? true : false);
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);

function getRef(ElementID)
{
   if (isDOM) return document.getElementById(ElementID);
   if (isIE4) return document.all[ElementID];
   if (isNS4) return document.layers[ElementID];
}

function ShowLiting(iIdx,iSwitch)
{
   var obj;
   var i;

   if(iSwitch)
   {
      for(i = 1; i <= MenuItemsCount(); i++)
       {
           obj = getRef('pic'+i);
           if(obj)
           {
               if(i != iIdx) obj.src = '/images2/menuitem' + i + '.gif';
               else obj.src = '/images2/menuitem' + i + '_1.gif';
           }
       }

       PopupMenuShow('menu' + iIdx);
   }
   else
   {
       PopupMenuHide('menu' + iIdx);
   }
}

function MenuItemsCount()
{
   var MenuItemId = 'menu';
   var i;
   var count = 1;

   for(i = 0; i < 4; i++)
   {
       if(getRef(MenuItemId+i)) count++;
   }

   return count;
}

function PopupMenuShow(ElementID)
{
   var obj;
   var MenuItemId = 'menu';
   var i;
   var iIdx = ElementID.replace('menu','');

   for(i = 1; i <= MenuItemsCount(); i++)
   {
       obj = getRef(MenuItemId+i);
       if(obj)
       {
           if(i != iIdx) obj.className = 'class_popup_menu_hide';
           else obj.className = 'class_popup_menu_show';
       }
   }

   if(MT)
   clearTimeout(MT);
}

function PopupMenuHide(ElementID)
{
   MT = setTimeout('menu_off(\''+ElementID+'\')', 500);
}

function menu_off(ElementID)
{
   var obj;
   var iIdx = ElementID.replace('menu','');

   obj = getRef(ElementID);
   if(obj) obj.className = 'class_popup_menu_hide';

   obj = getRef('pic'+iIdx);
   if(obj) obj.src = '/images2/menuitem' + iIdx + '.gif';
}

function preloadImages()
{
   img[0] = new Image();
   img[0].src = '/images2/menuitem1.gif';

   img[1] = new Image();
   img[1].src = '/images2/menuitem1_1.gif';

   img[2] = new Image();
   img[2].src = '/images2/menuitem2.gif';

   img[3] = new Image();
   img[3].src = '/images2/menuitem2_1.gif';

   img[4] = new Image();
   img[4].src = '/images2/menuitem3.gif';

   img[5] = new Image();
   img[5].src = '/images2/menuitem3_1.gif';

   img[6] = new Image();
   img[6].src = '/images2/menuitem4.gif';

   img[7] = new Image();
   img[7].src = '/images2/menuitem4_1.gif';
}

function ValidEmail()
{
   var reg = /^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]+\.[A-Za-z]{2,4}$/;

   f_Email = document.SubscribeOn.f_Email.value;

   if (f_Email.match(reg) == null)
   {
       alert('Укажите, пожалуйста, верный E-mail');
       return false;
   }

   return true;
}

function SendEmail()
{
   var error='ВНИМАНИЕ! ОШИБКА!\n';

   f_Name = document.adminForm.f_Name.value;
   f_OrgName = document.adminForm.f_OrgName.value;
   f_LastName = document.adminForm.f_LastName.value;
   f_SecondName = document.adminForm.f_SecondName.value;
   f_Position = document.adminForm.f_Position.value;
   f_EmailAddr = document.adminForm.f_EmailAddr.value;
   f_PostAddress = document.adminForm.f_PostAddress.value;
   f_TelNumber = document.adminForm.f_TelNumber.value;
   f_Source = document.adminForm.f_Source.value;
   f_Question = document.adminForm.f_Question.value;

   if(f_Name.length < 2)
   {
       alert(error+'Заполните, пожалуйста, поле "Имя"');
       return false;
   }

   if(f_OrgName.length < 2)
   {
       alert(error+'Заполните, пожалуйста, поле "Компания"');
       return false;
   }

   if(f_LastName.length < 2)
   {
       alert(error+'Заполните, пожалуйста, поле "Фамилия"');
       return false;
   }

   if(f_SecondName.length < 2)
   {
       alert(error+'Заполните, пожалуйста, поле "Отчество"');
       return false;
   }

   if(f_Position.length < 2)
   {
       alert(error+'Заполните, пожалуйста, поле "Должность"');
       return false;
   }

   if(f_PostAddress.length < 2)
   {
       alert(error+'Заполните, пожалуйста, поле "Почтовый адрес"');
       return false;
   }

   if(f_TelNumber.length < 2)
   {
       alert(error+'Заполните, пожалуйста, поле "Телефон / факс"');
       return false;
   }

   if(f_Source.length < 2)
   {
       alert(error+'Заполните, пожалуйста, поле "Источник информации о РПРЗ"');
       return false;
   }

   if(f_Question.length < 2)
   {
       alert(error+'Заполните, пожалуйста, поле "Что Вас интересует"');
       return false;
   }

   var reg = /^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]+\.[A-Za-z]{2,4}$/;

   if (f_EmailAddr.match(reg) == null)
   {
       alert(error+'Укажите, пожалуйста, верный E-mail');
       return false;
   }

   return true;
}


function ImgShw(ID, width, height, alt)
{
      var scroll = "no";
      var top=0, left=0;
      if(width > screen.width-10 || height > screen.height-28) scroll = "yes";
      if(height < screen.height-28) top = Math.floor((screen.height - height)/2-14);
      if(width < screen.width-10) left = Math.floor((screen.width - width)/2-5);
      width = Math.min(width, screen.width-10);
      height = Math.min(height, screen.height-28);
      var wnd = window.open("","","scrollbars="+scroll+",resizable=yes,width="+width+",height="+height+",left="+left+",top="+top);
      wnd.document.write("<html><head>\n");
      wnd.document.write("<"+"script language='JavaScript'>\n");
      wnd.document.write("<!--\n");
      wnd.document.write("function KeyPress()\n");
      wnd.document.write("{\n");
      wnd.document.write("        if(window.event.keyCode == 27)\n");
      wnd.document.write("                window.close();\n");
      wnd.document.write("}\n");
      wnd.document.write("//-->\n");
      wnd.document.write("</"+"script>\n");
      wnd.document.write("<title>\""+alt+"\"</title></head>\n");
      wnd.document.write("<body topmargin=\"0\" leftmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" onKeyPress=\"KeyPress()\">\n");
      wnd.document.write("<a href=# title=Закрыть onclick='window.close()'><img src=\""+ID+"\" border=\"0\" alt=\""+alt+"\"></a>");
      wnd.document.write("</body>");
      wnd.document.write("</html>");
      wnd.document.close();
}

//-->
