var http = false;
if(navigator.appName == "Microsoft Internet Explorer") {
http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
http = new XMLHttpRequest();
}




// ============ валидация формы редактора заказа при нажатии Пересчет =========== 
function valid_look_order_form() {
var cnt_el = document.form_look_order.elements.length - 4;
for (i=1; i<cnt_el; i=i+2) {
if (document.form_look_order.elements[i-1].value==0) {
document.form_look_order.elements[i].value = parseInt(document.form_look_order.elements[i].value);
} else {
document.form_look_order.elements[i].value = parseFloat(replace_string(document.form_look_order.elements[i].value,',','.'));
}
if (document.form_look_order.elements[i].value=='NaN') { document.form_look_order.elements[i].value=0; }
}
}




// функция сокрытия кнопки 'перейти к оформлению' при особых условиях
/*
function chn() {
var IE='\v'=='v'; // internet explorer
document.form_look_order.change_or_not.value=1;
document.getElementById('lnk_submit').style.display = 'none';
if(IE) {
document.getElementById('lnk_submit').style.visibility='hidden'; 
}
}
*/






// Функция 'изменение заказа' [18.09.2010 23:16:58]
function change_order(id, val, dr, tor) {

if (id) {

// корректируем перед отправкой поле ввода, то которое левее кнопки 'купить'
var item = document.getElementById('item_'+id);
var item_pop = document.getElementById('item_pop_'+id); // поле ввода в открывающемся popup блоке
if (dr) {
var val = replace_string(val,',','.');
if (parseFloat(val)) { 
var tmp1=(parseFloat(val)).toFixed(2);
item.value=parseFloat(val);
if (item_pop) { item_pop.value=parseFloat(val); }
val=parseFloat(tmp1);
} else { 
item.value=0; 
if (item_pop) { item_pop.value=0; }
val=0; 
}
} else {
if (parseInt(val)) { 
item.value=parseInt(val); 
if (item_pop) { item_pop.value=parseInt(val); }
val=parseInt(val); 
} else { 
item.value=0; 
if (item_pop) { item_pop.value=0; }
val=0; 
}
}


//document.getElementById('k'+id).innerHTML='***';
// замена поля, то которое правее кнопки 'купить' [19.09.2010 0:05:36]
c1=document.getElementById('k'+id).innerHTML;
c1=replace_string(c1,',','.');
if (c1=='&nbsp;') { c1=0; }
if (dr) { 
if (tor==2) { c2=val.toFixed(2); } else { c2=(val+Number(c1)).toFixed(2); } // ++ only val
} else { 
if (tor==2) { c2=val; } else { c2=val+Number(c1); } // ++
}
if (val==0) { c2=0; }
if (c2<=0) { 
c2='&nbsp;'; 
//document.getElementById("im"+id).className = "koff"; 
$("#im"+id).removeClass("kon").addClass("koff").css("background-color","#FFFFCC").hover(function(){$(this).css("background-color","#FFFFCC");}, function(){$(this).css("background-color","white");}); 
} else { 
//alert('4');
//document.getElementById("im"+id).className = "kon";
$("#im"+id).removeClass("koff").addClass("kon").css("background-color","#CCFFCC").hover(function(){$(this).css("background-color","#CCFFCC");}, function(){$(this).css("background-color","#E0FFE0");}); 
}
c2=replace_string(c2,'.',',');
document.getElementById('k'+id).innerHTML=c2;

}

// отправка на блок 'Ваш заказ' (/_js/change_order.php)

document.getElementById('indicator_ajax').src = "/_img/indicator_arrows.gif";
http.open("GET", "/_js/change_order.php?item_id=" + id + "&item_val=" + val, true);
http.onreadystatechange=function() {
if(http.readyState == 4 && http.status == 200) {
document.getElementById('item_order').innerHTML = http.responseText;
document.getElementById('indicator_ajax').src = '/_img/1px.gif';
}
}
http.send(null);

} 


/*
// отдельная универсальная функция ajax 
function universal_ajax(id, target) {
//document.getElementById(indicator_id).src = "./_img/indicator_arrows.gif";
http.open("GET", target, true);
http.onreadystatechange=function() {
if(http.readyState == 4 && http.status == 200) {
document.getElementById(id).innerHTML = http.responseText;
//document.getElementById(indicator_id).src = './_img/1px.gif';
}
}
http.send(null);
}
*/
