/**
  * Copyright © (C) IAC "CiM™" 2007. All rights reserved.
  * http://www.cimdesign.com
  * mailto:info@cimdesign.com
  * phone: +38 044 5319078
  * This is a standard copyright header for all source code
  * appearing at cimdesign.com
  **/

/*
**
*/
var req;

function loadXMLDoc(url) {
   // branch for native XMLHttpRequest object
   if (window.XMLHttpRequest) {
      req = new XMLHttpRequest();
      req.onreadystatechange = processReqChange;
      req.open("GET", url, true);
      req.send(null);
      // branch for IE/Windows ActiveX version
   } else if (window.ActiveXObject) {
      req = new ActiveXObject("Microsoft.XMLHTTP");
      if (req) {
         req.onreadystatechange = processReqChange;
         req.open("GET", url, true);
         req.send();
      }
   }
}
/*
**
*/
var response = '';

function processReqChange()
{
   ab = window.setTimeout("req.abort();", 5000);
   // only if req shows "complete"
   if (req.readyState == 4) {
      // only if "OK"
      clearTimeout(ab);
      if (req.status == 200) {
         // ...processing statements go here...
         response = req.responseText;
         /*alert(response);*/
      } else {
         alert("There was a problem retrieving the XML data:\n" + req.statusText);
      }
   }
}
/*
**
*/
function order (param)
{
    url  = '/module/group_propert/order.php?'+param
    /*alert(url);*/
    loadXMLDoc(url);

    return false;
}
/*
 *
 *
 * функции работы с корзиной *
*/
var pricearr=new Array();
var countarr=new Array();

function deltr(rownum){
   obj=document.getElementById("tblZakaz");
   objtr=document.getElementById("row"+rownum);
   if ((obj!=null) && (objtr!=null)){
      if (confirm("Удалить выбраный товар из корзины ?")){
         order(document.getElementById('count'+rownum).name+'=0'); // удаляем товар из корзины
         obj.deleteRow(objtr.rowIndex);
         countarr[rownum]=0;
         updatediv("cost",sumcount());
      }
   }
}
//
/////
function changecount(rownum,curcount){
   /*curcount=parseInt(curcount);*/
   if (isNaN(curcount)){
      /*alert('Количество товара должно быть целым числом');
      obj=document.getElementById('count'+rownum);
      if (obj!=null){
         obj.value=0; //countarr[rownum];
      }
      return false;*/
      curcount = 0;
   }
   countarr[rownum]=curcount;
   updatediv("cost"+rownum,pricearr[rownum]*curcount);
   updateinput("cost_"+rownum,pricearr[rownum]*curcount);
   updatediv("cost",sumcount());
   updateinput("cost_all",sumcount());
}
//
/////
function sumcount(){
   sum=0;
   for (var i = 0; i < countarr.length; i++) {
      sum += countarr[i]*pricearr[i];
   }
   return sum;
}
//
/////
function updatediv(elname,val){
   obj=document.getElementById(elname);
   if (obj!=null){
      obj.innerHTML=val.toFixed(2);
   }
}
//
/////
function updateinput(elname,val){
   obj=document.getElementById(elname);
   if (obj!=null){
      obj.value=val.toFixed(2);
   }
}

