//
// $Id: script.js,v 2.2 2007/09/25 07:03:27 Сергей Exp $
//

function FormatFloat(f) {
  Str = new String(f);
  index = Str.indexOf('.', 0);
  if (index == -1) {
    Str = Str + '.';
    index = Str.indexOf('.', 0);
  };
  while (Str.length < index + 3) {
    Str = Str + '0';
  };
//  alert(Str);
  return Str;
};

function SubmitFrm() {
//  alert( document.frm_goods.action = window.event.srcElement);
  //window.event.returnValue = false;

  k = document.forms["frm_goods"];
  if (typeof(k) != "object") {
    //alert("vvv");
    location.href = window.event.srcElement;
    return;
  };

  document.getElementById("frm_goods").action = window.event.srcElement;
  document.getElementById("frm_goods").submit();
};

function SubmitFrm1(sType) {
  //window.event.returnValue = false;
  document.getElementById("frm_goods").action = window.event.srcElement;
  document.all["edt_type"].value = sType;
  //document.frm_goods.submit();
  document.getElementById("frm_goods").submit();
};

function SubmitFrm2(sSort) {
  //window.event.returnValue = false;
  document.getElementById("frm_goods").action = window.event.srcElement;
  document.all["sort"].value = sSort;
  document.getElementById("frm_goods").submit();
};

function SubmitFrm4(href) {
  //alert("SubmitFrm4(" + href + ")");
  //window.event.returnValue = false;
  k = document.forms["frm_goods"];
//
  if (typeof(k) != "object") {
    //alert("SubmitFrm4");
    location.href = href;
    return;
  };
//
  document.forms["frm_goods"].action = href;
  document.forms["frm_goods"].submit();
};

function IncCount(sId, i, GMinCount, Code) {
  var inputCount = document.getElementById(sId);
  if (i == 0) {
    inputCount.value = 0;
    return;
  }

  inputCount.value = Number(inputCount.value) + i;
  if (i > 0) {
    if ((inputCount.value < GMinCount) && (inputCount.value > 0)) {
      inputCount.value = GMinCount;
    };
  } else {
    if ((inputCount.value < GMinCount) && (inputCount.value > 0)) {
      inputCount.value = 0;
    };
  };

  if (inputCount.value < 0) {
    inputCount.value = 0;
  };

  if (Code != '') {
    eval(Code);
  };
// GetTotalSum();
};

function CheckForNumber(GMinCount, Code, inputBox) {
  //var inputBox = window.event.srcElement;
  var aCount;

  if (inputBox.value == '') {
    inputBox.value = 0;
    return;
  };

  if (isNaN(inputBox.value)) {
    inputBox.value = 0;
    if (inputBox.value < GMinCount) {
      inputBox.value = GMinCount;
    };
  } else {
    aCount = inputBox.value;
    inputBox.value = parseInt(inputBox.value, -1); // ???
    if (inputBox.value < 0) {
      inputBox.value = 0;
    } else {
      inputBox.value = Math.round(aCount/1, 1);
    }
  }

  if ((inputBox.value < GMinCount) && (inputBox.value > 0)) {
      inputBox.value = GMinCount;
  }
  // ??? strange maximum
  if (inputBox.value >= 1000) {
    inputBox.value = 1000;
  }

  if (inputBox.value < 0) {
    inputBox.value = 0;
    return;
  }

  if (Code != '') {
    eval(Code);
  }
//  GetTotalSum();
};

function ExpandTreeNode(iNodeId) {
//  alert(bCanExpand[iNodeId]);
//  alert(iNodeId);
  if (bCanExpand[iNodeId] == false) { //Если элемент не может быть раскрыт, выходим
    return;
  };
  if (bIsExpanded[iNodeId] == false) {
    ShowRow('NodeCh' + iNodeId);
  } else {
    HideRow('NodeCh' + iNodeId);
  };
  bIsExpanded[iNodeId] = !bIsExpanded[iNodeId];
};

function edt_passwordClick() {
//  alert("hhh");
  if (window.event.keyCode == 13) {
    form1.submit();
  };
};

function TreeNodeClick(NodeId) {
  return;
  
  // 20070914, denver
  window.event.returnValue = false;
  url = 'show_popup_inform.php?GId=' + NodeId;
  window.open(url, 'description', 'location=no, menubar=no, resizable=yes, scrollbars=no, toolbar=no, width=400, height=400');
};

function addr_keypress() {
//    alert(window.event.keyCode);
    a = window.event.keyCode;
    if (!(
             ((a >= 1040) && (a <= 1105)) //Маленькие и большие русские
          || ((a >= 48) && (a <= 57)) //Цифры, запятая и пробел, минус
          || (a == 32) //Пробел
          || ((a >= 44) && (a <= 46)) //Минус
         )
       ) {
      window.event.returnValue = false;
    };
};


function btn_curr_click(CuId) {
  //alert("btn_curr_click, CuId = " + CuId);
  document.all["CuId"].value = CuId;
  RecalcPrices(RowCount);
  document.all["img_curr_1"].src = 'images/rouble.gif';
  document.all["img_curr_2"].src = 'images/euro.gif';
  document.all["img_curr_3"].src = 'images/dollar.gif';
  if (CuId == 1) {
    document.all["img_curr_1"].src = 'images/rouble_1.gif';
  };
  if (CuId == 2) {
   document.all["img_curr_2"].src = 'images/euro_1.gif';
  };
  if (CuId == 3) {
    document.all["img_curr_3"].src = 'images/dollar_1.gif';
  };
};



var mcl_over='#7DB712';
var mcl_out='#EDEEEF';
var mcl2_over='#EDEEEF';
var mcl2_out='#FFFFFF';

bt=new Array();
var arr=1;

function prl(over,out){
    bt[arr]=new Array(2);
    bt[arr][0]=new Image;
    bt[arr][0].src=over;
    bt[arr][1]=new Image;
    bt[arr][1].src=out;
    arr++;
}

function sel(nam,num,id){
    document.images[nam].src=bt[id][num].src;
}

prl("images/ic1_2.gif","images/ic1_1.gif");
prl("images/ic2_2.gif","images/ic2_1.gif");

function edt_focus(edt_id, edt_text) {
  if (document.all[edt_id].value == edt_text) {
    document.all[edt_id].value = '';
  };
};

function edt_blur(edt_id, edt_text) {
  if (document.all[edt_id].value == '') {
    document.all[edt_id].value = edt_text;
  };
};

function KeyPress(i) {
  if (window.event.keyCode == 13) {
    document.forms[i].submit();
  };
};

function CheckForm() {
  flag = true;
//  if (document.frm_goods.CLast_Name.value == "") { flag = false; };
//  if (document.frm_goods.CRegion.value == "") { flag = false; };
//  if (document.frm_goods.CCity.value == "") { flag = false; };
//  if (document.frm_goods.CAddr.value == "") { flag = false; };
//  if (document.frm_goods.CPhone.value == "") { flag = false; };
  if (document.frm_goods.CE_Mail.value == "") { flag = false; };
  if (document.frm_goods.CLogin.value == "") { flag = false; };
  if (document.frm_goods.CPassword.value == "") { flag = false; };

  if (flag == false) {
    alert("Для регистрации необходимо заполнить все поля, обязательные для ввода.");
  } else {
    document.getElementById("frm_goods").submit();
  };
};

function SubmitFrmToDelete(OId) {
/*
 if (window.event) {
   window.event.returnValue = false;
 } else {  
   e = (e) ? e : ((window.event) ? event : null );
   e.preventDefault();
 };  

 window.event.returnValue = false;
*/  
 if (window.confirm("Действительно удалить данный заказ?") == false) {
   return;
 };

 document.frm_order.OId.value = OId;
 document.frm_order.submit();
};

//function SubmitFrmToDelete(OId) {
//  window.event.returnValue = false;
//  if (window.confirm("Действительно удалить данный заказ?") == false) {
//    return;
//  };
//
//  document.frm_order.OId.value = OId;
//  document.frm_order.submit();
//};

function addr_keypress1() {
//    alert(window.event.keyCode);
  if (document.all["CounId"].value != '10') { //Если страна не Россия, пусть пишут, что хотят
    return;
  };

    a = window.event.keyCode;
    if (!(
             ((a >= 1040) && (a <= 1105)) //Маленькие и большие русские
          || ((a >= 48) && (a <= 57)) //Цифры, запятая и пробел, минус
          || (a == 32) //Пробел
          || ((a >= 44) && (a <= 46)) //Минус
         )
       ) {
      window.event.returnValue = false;
    };
};

function CounIdChange() {
  if (document.all["CounId"].value == '10') {
    document.all["CCity"].readOnly = true;
    document.all["CRegion"].readOnly = true;
    document.all["CDistrict"].readOnly = true;
//    document.all["ui_CAddr"].;
    //Кнопка получить индекс
    document.all["btn_getbyindex"].src = 'images/getbyindex.gif';
    document.all["btn_getbyindex"].style.cursor = 'hand';
  } else {
    document.all["CCity"].readOnly = false;
    document.all["CRegion"].readOnly = false;
    document.all["CDistrict"].readOnly = false;
//    document.all["ui_CAddr"].onkeypress='';
    //Кнопка получить индекс
    document.all["btn_getbyindex"].src = 'images/0.gif';
    document.all["btn_getbyindex"].style.cursor = 'pointer';
  };
};