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 all = document.getElementsByName("selectall");
 if(all[0].checked)value = true; else value = false;

 var boxs = document.getElementsByName("checkproduct[]");var i = 0;for (i = 0; i < boxs.length; i++) {boxs[i].checked = value;}}
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 changeShipPay(id,type,call_ajax,id_payment_broker){
    var strType = ''; var arrAcces = []; var strName = '';
    var id_pay = null; var id_ship = null;
    if (type == 0) {
        strType = 'ship'; arrAcces = shippings; strName = 'id_shipping_type'; delName = 'id_payment_type';
    } else {
        strType = 'pay'; arrAcces = payments; strName = 'id_payment_type'; delName = 'id_shipping_type';
        $("input[name='brand']").removeAttr("checked");
        $('#brandList').css("display","none");
        $('#calcCetelem').css("display","none");
        $('#calcHomecredit').css("display","none");
        $('#calcEssox').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");}
        if (id_payment_broker==2){$('#calcHomecredit').css("display","table-row");}
        if (id_payment_broker==6){$('#calcEssox').css("display","table-row");}
    }

    

    var stat = $('#'+strType+id).attr("checked");
    $("input[name='"+strName+"']:checked").removeAttr("checked");
    if (stat) {
        $('#'+strType+id).attr("checked","checked");
        $("input[name='"+delName+"']").attr("disabled","disabled");
        $("input[@type='checkbox'][@name='"+delName+"']").each(function(){if (jQuery.inArray(this.value * 1, arrAcces[id]) >=0) {this.disabled = false;}});
    } else {
        $("input[name='"+delName+"']").removeAttr("disabled");
    }

    unmarked = document.getElementsByName(delName);
    for( i=0;i<unmarked.length;i++)
    {
      if(unmarked[i].disabled==true) unmarked[i].checked = false;
    }


    // uprav cenu v kosiku dle aktualni volby
    id_ship = $("input[name='id_shipping_type']:checked").val() || null;
    id_pay = $("input[name='id_payment_type']:checked").val() || null;
    var shipping_date = $("#delivery_date_" + id_ship).val() || null;
    if (call_ajax == true) basket_summ(id_pay, id_ship, shipping_date);
}
function basket_summ(id_payment_type, id_shipping_type, shipping_date) {
	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);
    if (shipping_date != null) query_string.push("shipping_date=" + shipping_date);
	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);
    return false;
}
function showCalcHomecredit(price) {
	window.open(encodeURI(url + "secure/CalculatorHomecredit.php?price="+price),"_blank","toolbar=no,scrollbars=no,location=no,status=no,width=570,height=420,resizable=1,screenX=250,screenY=170", false);
    return false;
}


function showCalcEssox(price){
	window.open(encodeURI(url + "inc/class/credit_card/essox/kalkulacky.php?cena="+price),"_blank","toolbar=no,scrollbars=no,location=no,status=no,width=720,height=300,resizable=1,screenX=250,screenY=170", false);
}
