function restrict(o){
  o.value=o.value.replace(/([^0-9])/g,"");
}

function putInBasket(gid, amount, price) {
//alert("ID: " + gid + " " + amount+ ", price="+price);
 if (amount==""){
  alert("Не указано количество.");
  return;
 }
 if (amount==0) {
  if (document.getElementById('trgood'+gid)) document.getElementById('trgood'+gid).style.display="none";
 }
 if(price>0)
  price=price.replace(/\./g,",");
//alert("ID: " + gid + " " + amount+ ", price="+price);
 var params='gid='+gid+'&amount='+amount+'&price='+price;
 var xl=new XML_Load(Gpath+'module/call_basket.php','POST',params,'',null);
 if (xl.IsReady()) {
  xl.OnReady=function(a,b,ldata) {
//alert("data="+ldata);

  if(ldata!="NO"){
   //document.getElementById('good'+gid).value=amount;
//alert( document.getElementById('basket_count').innerHTML);
   ldata=ldata.split("|");
//alert("data0="+ldata[0]+", data1="+ldata[1]);
   document.getElementById('basket_count').innerHTML=ldata[0];
   document.getElementById('sum').innerHTML=ldata[1];
   if (document.getElementById('sum_basket')) document.getElementById('sum_basket').innerHTML=ldata[1];
   var l=ldata[1]*1;
//alert("l="+l);
   if(l==0) switchDiv('formBasket',false);

   if(ldata[2]==1){
    if(ldata[3]==1) alert('Позиция удалена из корзины.');
    else alert("Не указано количество.");
   }else{
    alert('Позиция добавлена в корзину.');
   }
  }else
   alert('Ошибка. Введите количество.');
  }
  xl.Load();
 }

}


function delFromBasket(gid) {
//alert("ID: " + gid + " " + amount+ ", price="+price);
 if(confirm('Удалить позицию из корзины?')){
 var params='gid='+gid;
 var xl=new XML_Load(Gpath+'module/call_basket.php','POST',params,'',null);
//alert("p="+params);
 if (xl.IsReady()) {
  xl.OnReady=function(a,b,ldata) {
//alert("data="+ldata);
//  if(ldata!="NO"){
   //document.getElementById('good'+gid).value=amount;
//alert( document.getElementById('basket_count').innerHTML);
   ldata=ldata.split("|");
//alert("data0="+ldata[0]+", data1="+ldata[1]);
   document.getElementById('basket_count').innerHTML=ldata[0];
   document.getElementById('sum').innerHTML=ldata[1];
   if (document.getElementById('sum_basket')) document.getElementById('sum_basket').innerHTML=ldata[1];
   var l=ldata[1]*1;
//alert("l="+l);
   if(l==0){
    switchDiv('formBasket',false);
    switchDiv('trcalc',false);
    switchDiv('tbgoods',false);
   }

   switchDiv('trgood'+gid,false);
   alert('Позиция удалена из корзины.');
//  }
  }
  xl.Load();
 }
 }
}



function ListToBasket(lid) {
 var gid,o;
 switchDiv('LbutB',false);
 switchDiv('LmesB',true);

 var s1="";	//id
 var s2="";	//amount
 if(lid=="") return;
 var ar=lid.split(",");
 var sz=ar.length;
 var n=0;
 for(i=0;i<sz;i++){
  gid=ar[i];
//alert("gid="+gid);
  if(gid>0){
   s1+=(s1!="" ? "," : "")+gid;
   o=document.getElementById('good'+gid);
   if(o && o!=undefined && o!=""){
    s2+=(s2!="" ? "," : "")+(o.value!="" && o.value>0 ? o.value : 0);
   }
  }
 }//for
 if(s1!="" && s2!=""){
  var params='list=1&glist='+s1+'&alist='+s2;
//alert("params="+params);
  var xl=new XML_Load(Gpath+'module/call_basket.php','POST',params,'',null);
  if (xl.IsReady()) {
  xl.OnReady=function(a,b,ldata) {
//alert("data="+ldata);
  if(ldata!="NO"){
   //document.getElementById('good'+gid).value=amount;
//alert( document.getElementById('basket_count').innerHTML);
   ldata=ldata.split("|");
//alert("data0="+ldata[0]+", data1="+ldata[1]);
   document.getElementById('basket_count').innerHTML=ldata[0];
   document.getElementById('sum').innerHTML=ldata[1];
   if (document.getElementById('sum_basket')) document.getElementById('sum_basket').innerHTML=ldata[1];
   l=ldata[1]*1;
//alert("l="+l);
   if(l==0){
    switchDiv('formBasket',false);
   }else
    switchDiv('formBasket',true);

   alert("Товарные позиции корзины обновлены.");

//   l=ldata[1]*1;
//alert("l="+l);
//   if(l==0){
//    switchDiv('formBasket',false);
//   }else
//    switchDiv('formBasket',true);
  }//NO
  }
  xl.Load();
  }

 }else
  alert("Ошибка. Список пуст!");

 switchDiv('LbutB',true);
 switchDiv('LmesB',false);

//alert("s1="+s1+", s2="+s2);
}



function showPhoto(nm){
 if(nm!=""){
  phO=window.open(Gpath+"module/iprevbig.php?id="+nm,"","status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes");
  phO.focus();
 }
}

function printPage(doc,pr,tm){
 if(doc>0){
  printO=window.open(Gpath+"/module/print.php?id="+doc+"&lnk2="+pr+"templ="+tm,"","status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes");
  printO.focus();
 }
 return;
}

function checkBasket(){
 return true;
// var o=getelementbyid('sum_basket');
//alert("o.vl="+o.value+", o.tx="+o.text);
// if(o && o!=undefined && o.value>0) return true;
// else return false;
}


function ShowPhoto2(doc,idi,wd,hg){
 wd=wd*1;
 hg=hg*1;
 if(wd<200) wd=200;
 wd+=50;
//alert("wd="+wd+", src="+screen.width);
 if(wd>screen.width)
  wd=screen.width-10;
 if(hg<100) hg=100;
// if(pr!=1)
 hg+=50;
// else hg+=50;
//alert("hg="+hg+", scr="+screen.height);
 if(hg>screen.height) hg=screen.height-80;
//alert("hg="+hg);
 var lV=(screen.width - wd) / 2;
 var tV=(screen.height - hg) / 2;

 phW=window.open("?id="+doc+"&photo="+idi,null,"status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,width="+wd+",height="+hg+",left="+lV+",top="+tV);
 phW.focus();
}

function winDocResize(){
 var obj;
 var winDoc = phW.document;
 if (isNS4){
  obj = winDoc.layers['image'];
 }else if (isIE4) {
  obj = winDoc.all['image'];
 }else if (isIE5 || isNS6) {
  obj = winDoc.getElementById('image');
 }

// var obj = winDoc.getElementById('image');
 if(obj=='' || obj==undefined) return;

 var w = obj.width, h = obj.height;
 var iHeight= document.body.clientHeight, iWidth = self.innerWidth;
 var left = (self.opera ? iWidth : screen.availWidth)/2 - w/2;
 var top =  (self.opera ? iHeight : screen.availHeight)/2 - h/2;
 phW.resizeTo(w+10, h+26);
 phW.moveTo(left, top);
}
