Array.prototype.inArray = function (value) {var i; for (i=0; i < this.length; i++) { if (this[i] === value) { return true;	} } return false;};
function select_all() {var	boxs = document.getElementsByName("checkproduct[]");var i = 0;for (i = 0; i < boxs.length; i++) {boxs[i].checked = !boxs[i].checked;}}
function change_basket_item_count(productId, alert_text) {
	if(!alert_text) alert_text = '';
	minQuantity = document.getElementById('min_quantity_'+productId).value;
	quantityField = quantity = document.getElementById('textfield'+productId);
	quantity = document.getElementById('textfield'+productId).value;
	if(document.getElementById('is_configuration'+productId).value == 1)
	{
		inConfiguration = document.getElementsByName('part_of_configuration');
		for(i = 0; i < inConfiguration.length; i++)
		{
			if(inConfiguration[i].value == productId)
			{
				var idElems = inConfiguration[i].id.split('_');
				document.getElementById('textfield'+idElems[3]).value = quantity;
			}
		}
	}
	
	if(document.getElementById('is_required'+productId).value == 1)
	{
		var idConfiguration = document.getElementById('part_of_configuration_' + productId).value;
		var configurationsCount = document.getElementById('textfield' + idConfiguration).value;
		
		if(eval(configurationsCount) > eval(quantity))
		{
			document.getElementById('textfield'+productId).value = configurationsCount;
			msgBox(alert_text + configurationsCount + '!');
		}
		else
		{
			if(eval(minQuantity) > eval(quantity)){quantityField.value = minQuantity;msgBox(alert_text + minQuantity + '!');}
				else {document.getElementById("event").value = 3;document.getElementById("order").submit();}
		}
	}	
	else
	{
		if(eval(minQuantity) > eval(quantity)){quantityField.value = minQuantity;msgBox(alert_text + minQuantity + '!');}
			else {document.getElementById("event").value = 3;document.getElementById("order").submit();}
	}
}
function delete_all() {	document.getElementById("event").value = 2;document.getElementById("order").submit();}
function update_shipping(id, call_ajax, id_payment_broker) {
	if (id == 0) return;
	document.getElementById("pay" + id).checked = true;	
	$("input[name='brand']:checked").removeAttr("checked");	
	$('#brandList').css("display","none");
	$('#calcCetelem').css("display","none");
	if (id_payment_broker==3){$('#brandList').css("display","table-row");$("input[name='brand']").eq(0).attr("checked","checked");}
	if (id_payment_broker==4){$('#calcCetelem').css("display","table-row");}	
	var av_shippings = payments[id];var ship = document.getElementsByName("id_shipping_type");var i = 0;var id_ship = null;
	for (i = 0; i < ship.length; i++) {
		if (ship[i].checked == true) id_ship = ship[i].value;
		if (av_shippings.inArray(parseInt(ship[i].value)) == true) {ship[i].disabled = false;} 
		else {ship[i].disabled = true;if (ship[i].checked == true) ship[i].checked = false;}
	}
	if (call_ajax == true) basket_summ(id, id_ship);
}
function update_payment(id, call_ajax) {
	if (id == 0) return; document.getElementById("ship" + id).checked = true;
	var av_payments = shippings[id];var paym = document.getElementsByName("id_payment_type");var i = 0;var id_paym = null;	
	for (i = 0; i < paym.length; i++){if(paym[i].checked == true)id_paym=paym[i].value;
	if (av_payments.inArray(parseInt(paym[i].value)) == true) {	paym[i].disabled = false;} 
	else {paym[i].disabled = true; if (paym[i].checked == true) paym[i].checked = false;}}
	if (call_ajax == true) basket_summ(id_paym, id);
}
function basket_summ(id_payment_type, id_shipping_type) {
	var query_string = new Array();
	if (id_payment_type != null) query_string.push("id_payment_type=" + id_payment_type);
	if (id_shipping_type != null) query_string.push("id_shipping_type=" + id_shipping_type);	
	getData(url + "inc/ajax/abasket_page.php?" + query_string.join("&"), "basket_summ_id");
}
function showCalcCetelem(price){
	window.open(encodeURI(url + "secure/CalculatorCetelem.php?price="+price),"_blank","toolbar=no,scrollbars=no,location=no,status=no,width=380,height=300,resizable=1,screenX=250,screenY=170", false);	
}
