/* Создание нового объекта XMLHttpRequest для общения с Web-сервером */
var xmlHttp = false;
var parr='00';
var bkol=0;
var baskid=0;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
@end @*/

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}

function addcena(id,what) {
if(what==1){
var cena=document.getElementById('pricezap'+id).value;}
if(what==2){
var cena=document.getElementById('pricevost'+id).value;}
if(what==3){
var cena=document.getElementById('priceprod'+id).value;}
if(what==4){
var cena=document.getElementById('pricesov'+id).value;}

ssm=parseInt(document.getElementById('forms_1').value);
ssm=ssm+parseInt(cena);
ssmz=document.getElementById('forms1').value;
document.getElementById('forms_1').value=ssm;
document.getElementById('forms').innerHTML=ssmz+' позиций на сумму';
document.getElementById('formsc').innerHTML=ssm+'';

}

function callServer1(id,uid,what) {
var dobs='';

if(what==1){dobs='Заправка';
var price=document.getElementById('pricezap'+id).value;
}
if(what==2){dobs='Заправка с заменой чипа';
var price=document.getElementById('pricevost'+id).value;
}
if(what==3){dobs='Картридж';
var price=document.getElementById('priceprod'+id).value;
}
if(what==4){dobs='Совместимый';
var price=document.getElementById('pricesov'+id).value;
}


var cf = document.getElementById('c'+id).value;

var ziv=what;

var name=document.getElementById('name'+id).value;
bkol=document.getElementById('forms1').value;
bkol=parseInt(bkol)+parseInt(cf);
document.getElementById('forms1').value=bkol;
document.getElementById('forms').innerHTML=bkol;
var url = "ajax2/form.php?id="+escape(id)+'&ziv='+escape(what)+'&price='+escape(price)+'&cf='+escape(cf)+'&uid='+escape(uid);
alert('Добавлено в корзину заказов\n'+dobs+' '+name+'\n на сумму '+price+' руб.');
parr=id;
xmlHttp.open("GET", url, true);
if(what==1){
xmlHttp.onreadystatechange = updatePage1;
}
if(what==2){
xmlHttp.onreadystatechange = updatePage11;
}
if(what==3){
xmlHttp.onreadystatechange = updatePage111;
}
if(what==4){
xmlHttp.onreadystatechange = updatePage1111;
}
xmlHttp.send(null);
}


function updatePage1() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
   var response = xmlHttp.responseText;
//   alert(parr);
   document.getElementById('formszap__'+parr).innerHTML = response;
//   alert('добавлен в корзину');
  var zake=document.getElementById('zake').value;
  if(zake==1){
//   alert('000');
 window.location = "http://www.oncopy.ru/?zakaz&k"
  }
  }
}

function updatePage11() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
   var response = xmlHttp.responseText;
//   alert(parr);
   document.getElementById('formsvost__'+parr).innerHTML = response;
//   alert('добавлен в корзину');
  var zake=document.getElementById('zake').value;
  if(zake==1){
//   alert('000');
 window.location = "http://www.oncopy.ru/?zakaz&k"
  }
  }
}
function updatePage111() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
   var response = xmlHttp.responseText;
//   alert(parr);
   document.getElementById('formsprod__'+parr).innerHTML = response;
//   alert('добавлен в корзину');
  var zake=document.getElementById('zake').value;
  if(zake==1){
//   alert('000');
 window.location = "http://www.oncopy.ru/?zakaz&k"
  }
  }
}
function updatePage1111() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
   var response = xmlHttp.responseText;
//   alert(parr);
   document.getElementById('formssov__'+parr).innerHTML = response;
//   alert('добавлен в корзину');
  var zake=document.getElementById('zake').value;
  if(zake==1){
//   alert('000');
 window.location = "http://www.oncopy.ru/?zakaz&k"
  }
  }
}






function callServer2(id) {

//alert(parr);

  var cou = document.getElementById('z'+id).value;    
  baskid=id;
  alert(cou);

  var url = "ajax2/recount.php?id="+escape(id)+'&cou='+escape(cou);
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = updatePage2;
  xmlHttp.send(null);

}

function updatePage2() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
   var response = xmlHttp.responseText;
//   alert(parr);
  document.getElementById('ce'+baskid).innerHTML = '<b>'+response+'</b>';
//alert(response+'..'+baskid);
  }
}



function Round(n,d){
return new Number(n.toFixed(d))
} 


function callServer3(ac,id) {
  var pr=document.getElementById('p'+id).value;
  var co=document.getElementById('z'+id).value;
  if(co<1){alert('Для удаления товара из заказа - воспользуйтесь соответствующей ссылкой');
  document.getElementById('z'+id).value=1;
  return;}
  var um=pr*co;
  document.getElementById('ce'+id).innerHTML='<b>'+Round(um,2)+'</b>';
  var url = "ajax2/recountsum.php?account="+escape(ac)+"&id="+escape(id)+"&co="+escape(co);
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = updatePage3;
  xmlHttp.send(null);
}


function updatePage3() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
   var response = xmlHttp.responseText;
  document.getElementById('summ').innerHTML = ''+response+'';
  document.getElementById('summ').innerHTML=''+response+'';
  document.getElementById('temprez').innerHTML = '<b>'+response+'</b>';
  document.getElementById('summ').innerHTML =document.getElementById('summf').value;
  document.getElementById('countss').innerHTML =document.getElementById('summf2').value;
  document.getElementById('forms').innerHTML =document.getElementById('summf2').value;

  zzz=document.getElementById('summf').value;
  document.getElementById('forms_1').value=zzz;
  document.getElementById('formsc').innerHTML=' позиций на сумму '+zzz+'';

  
  var summ=document.getElementById('summf').value;
  var mis=document.getElementById('minsum').value;

  var ssm=parseInt(summ);
  var mss=parseInt(mis);
   
  if(ssm>mss){
  document.getElementById('minsumtext').style.display="none";
  document.getElementById('disform').style.display="inline";  
  }else{
  document.getElementById('minsumtext').style.display="inline";
  document.getElementById('disform').style.display="none";    
  }
  

  }
}

