var Timeout=100;
var MenuLeft=300;
var topricemenu_about;
var topricemenu_news;
var topricemenu_price;
var CatCurLevel = new Array(0, 0,0);

function HideCur( Level ){
    
   if ((Level<=1) &&(CatCurLevel[1]!=0)) triggerDiv( CatCurLevel[1], 1);
   if ((Level==0) &&(CatCurLevel[0]!=0)) triggerDiv( CatCurLevel[0], 0);
}
//Переключатель Открыть/закрыть элемент
function triggerDiv( id, Level)
{
  if (Level==0){
    Back  = "#E0F5FF";//   active
    Back1 = "#F4FCFE";// inactive
    Frw   = "green"; //
    Frw1  = "red";
  }else if (Level == 1){
    Back  = "#CCEBFB";       //#B6E2F9
    Back1 = "#CCEBFB";//
    Frw   = "green"; //
    Frw1  = "red";
  }
  //F4FCFE цвет фона активного 3 уровня


  if (isDOM) {

    var whichEl = document.getElementById('child' + id);
    var whichIm = document.getElementById('fldr_img'+id);
    var whichTr = document.getElementById('tr'+id);
    if (whichEl.style.display == 'none' && whichIm) {
      HideCur(Level);
      CatCurLevel[Level] = id;
      whichEl.style.display  = 'block';
      whichIm.src            = imgOpened.src;
      whichTr.style.backgroundColor = Back;
    }
    else{
      CatCurLevel[Level]   = 0;
      CatCurLevel[Level+1]   = 0;
      whichEl.style.display  = 'none';
      whichIm.src            = imgClosed.src;
      whichTr.style.backgroundColor = Back1;
    }
  } // end of the DOM case
  else if (isIE4) {
    var whichEl = document.all('child' + id);
    var whichIm = document.images.item('fldr_img'+id);
    if (whichEl.style.display == 'none') {
      whichEl.style.display  = 'block';
      whichIm.src            = imgOpened.src;
    }
    else if (unexpand==0) {
      whichEl.style.display  = 'none';
      whichIm.src            = imgClosed.src;
    }
  } // end of the IE4 case
  else if (isNS4) {
    var whichEl = document.layers['child' + id];
    var whichIm = document.layers['fldr_img'+id].document.images['imEx']; //???
    if (whichEl.visibility == 'hide') {
      whichEl.visibility  = 'show';
      whichIm.src         = imgOpened.src;
    }
    else if (unexpand==0) {
      whichEl.visibility  = 'hide';
      whichIm.src         = imgClosed.src;
    }
//    nsArrangeList();
  } // end of the NS4 case

} // triggerDIV


function ClearAll() {
  for (i = 0; i < document.price.elements.length; i++) {
    var item = document.price.elements[i];
    //alert(item.name);
    if(item.name.substring(0,5)=="good_"){
      item.value = "";
    }
  }
}

function Search(){
//  alert("Search");
//  alert(document.price.action.value);
    if (document.price.search_cond.value!=""){
      if(document.price.search_cond.style.visibility!="hidden"){
        document.price.pg.value = "";
        document.price.tr.value = "search";
        document.price.submit();
      }
    }
}

function goBack() {
  if(document.price.prevaction.value=="view"){document.price.action.value = "full_list";}
  else {
    if(document.price.prevaction.value=="step1"){document.price.action.value = "view";}
    else
      if(document.price.prevaction.value=="step2"){document.price.action.value = "step1";};
  };
  document.price.submit();
}

function saveOrder() {
  document.price.action.value = "save";
  document.price.submit();
}

function addOrder() {
  document.price.action.value = "add";
  document.price.submit();
}

function clearOrder() {
  if(confirm("Вы действительно хотите очистить Ваш заказ?")==true){
    document.price.action.value = "clear";
    document.price.submit();
  }
}

function viewOrder() {
  if(document.price.order_qty.value==0) alert("Ваш заказ пуст. Для того чтобы узнать как заказать товар, обратитесь к 'помощи'.");
  else{
    document.price.action.value = "view";
    document.price.submit();
  }
}

function orderStep1() {
  document.price.action.value = "step1";
  document.price.submit();
}

function orderStep2() {
 ok = 1;
 if(document.price.fio.value =="") {ok=0};
 if(document.price.phone.value =="") {ok=0};
 if(document.price.email.value =="") {ok=0};
 if(document.getElementById("ur_data").style.visibility=="visible"){
   if(document.price.work.value =="") {ok=0};
   if(document.price.position.value =="") {ok=0};
 }else{
   if(document.price.address.value =="") {ok=0};
   if(document.price.dt.value =="") {ok=0};
//   if(document.price.tm.value =="") {ok=0};
 }
 if(ok==0) {
   alert("Пожалуйста, заполните все поля");
   return(false)
 }
 document.price.action.value = "step2";
 document.price.submit();
}


function win_open(good,price) {
  var file = 'good.php?good=' + good + '&price=' + price;
  var par = 'width=600,height=400,left=' + wx + ',top=' + wy + ',location=no,scrollbars=yes,resizable';
  window.open(file,'good',par);
}

function MenuPopdown(Mname){document.getElementById(Mname).style.visibility='none'}

function PopDownAnother(Mname){
  if(Mname=='menu_about'){
    MenuPopdown('menu_news');
    MenuPopdown('menu_price');
  }else{
    if(Mname=='menu_news'){
      MenuPopdown('menu_about');
      MenuPopdown('menu_price');
    }else{
      if(Mname=='menu_price'){
        MenuPopdown('menu_about');
        MenuPopdown('menu_news');
      }
    }
  }
}

function MenuPopup(Mname){PopDownAnother(Mname); StopMenuPopdown(Mname);document.getElementById(Mname).style.visibility='visible'}

function StartMenuPopdown(Mname){
 eval('toprice'+Mname+'=setTimeout("MenuPopdown(\''+Mname+'\');",'+Timeout+');');
}
function StopMenuPopdown(Mname){
 if(eval('toprice'+Mname)){eval('clearTimeout(toprice'+Mname+');');};
}

// Загрузка картинки
function newImage(arg) {
   if (document.images) {
      rslt = new Image();
      rslt.src = arg;
      return rslt;
   }
}

function preloadImages() {
   if (document.images) basket_over = newImage("/images/basket-over.gif");
}

function ShowStep1Data(ct){
  if(ct=="0"){
    document.getElementById("ur_data").style.visibility='visible';
    document.getElementById("fiz_data").style.visibility='hidden';
    document.getElementById("fiz_data").style.height='0';
  }else{
    document.getElementById("ur_data").style.visibility='hidden';
    document.getElementById("ur_data").style.height='0';
    document.getElementById("fiz_data").style.visibility='visible';
    }
}

function changeImages() {
   if (document.images)
      for (var i=0; i<changeImages.arguments.length; i+=2)
         document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
}



function setPointer(theCell, State)// State = 0||1
{
    // State=1 '#3399ff', '#ffffff'
    // State=0 '#f2fdff', '#003366'
    var theBackColor = '#DEEFF6';
    var theFontColor = '#ffffff';

    if (State == 0){
      theBackColor = '#FFFFFF';
      theFontColor = '#DEEFF6';
    };

//    if (State == '' || typeof(theRow.style) == 'undefined') {
//        return false;
//    }

    if (State == '1'){
       theCell.style.backgroundColor = theBackColor;
       theCell.style.color = theFontColor;
    }
    else{
       theCell.style.backgroundColor = theBackColor;
       theCell.style.color = theBackColor;
    }

    return true;
} // end of the 'setPointer()' function
