//var index = '';

function calculateMod(valor, qty){
	if(parseInt(valor)<=parseInt(qty)) {
		vv = qty;
	} else {
		v = parseInt(valor)/parseInt(qty);
		//alert(v);
		vvv = parseInt(valor) % parseInt(qty);
		//alert(vvv)
		if(vvv!=0) {
			vvv = 1;
		} else {
			vvv = 0;
		}
		
		vv = (parseInt(v)+vvv) * parseInt(qty);
		
	}
	return vv;
}

function callBacksuggestQty(res){
	if (res != 0) {
		infoObj = eval('(' + res + ')');
		setInnerHtml('subtotal', infoObj[1]);
		setInnerHtml('unit_price', infoObj[0]);
	}
	setDisplay("reloading", "none");
}

function callBacksuggestQtySpecial(res){
	if (res != 0) {
		infoObj = eval('(' + res + ')');
		setInnerHtml('subtotal', infoObj[1]);
		setInnerHtml('unit_price', infoObj[0]);
	}
	setDisplay("reloading", "none");
}


function calculateQtyClass_special(){
	id_special = getValue('h_id_special');
	qty = getValue('h_qty');
	valor = getValue('suggest_special');
//	prod_unit_price
	if (IsNumeric(valor) && valor.length > 0) {
		setInnerHtml('unit_price', '<input type="button" value="" id="" class="reloading" disabled="disabled" title="Actualizando..." />');
		setDisplay("reloading", "");
		setInnerHtml('subtotal', '<input type="button" value="" id="" class="reloading" disabled="disabled" title="Actualizando..." />');
		vv = calculateMod(valor, qty);
		setValue('suggest_special', vv);
		sendAjax('ajax.ecommerce.php', 'action=suggestQtySpecial&id_product='+id_special+'&qty='+vv,'callBacksuggestQtySpecial');
	}
	else{
		setInnerHtml('subtotal', '0,00');
	}
}

function calculateQtyClass_product(){
	id_product = getValue('h_id_product');
	qty = getValue('h_qty');
	valor = getValue('suggest_product');
	price = 2;
	id_variant = getValue('variant_select');
	if (IsNumeric(valor) && valor.length > 0) {
		setInnerHtml('unit_price', '<input type="button" value="" id="" class="reloading" disabled="disabled" title="Actualizando..." />');
		setDisplay("reloading", "");
		setInnerHtml('subtotal', '<input type="button" value="" id="" class="reloading" disabled="disabled" title="Actualizando..." />');
		vv = calculateMod(valor, qty);
		setValue('suggest_product', vv);
		sendAjax('ajax.ecommerce.php', 'action=suggestQty&id_product='+id_product+'&qty='+vv+'&id_variant='+id_variant,'callBacksuggestQty');
	}
	else{
		setInnerHtml('subtotal', '0,00');
	}
}


function callBackCalculateQtyClassOrderSaved(res){
	if (res != 0){
		infoObj = eval('('+res+')');
		setInnerHtml("subtotal_"+index, infoObj[1]);
		setInnerHtml("total_price", infoObj[2]);
		setInnerHtml("unit_price_"+index, infoObj[0]);
		//setInnerHtml('sh_cart_status_subtotal', infoObj[1]);
	}
}
function callBackCalculateQtyClassCartchanged(res){
	callBackCalculateQtyClassCart(res);
	MM_goToURL('top', 'mi_cesta.php');
	return document.MM_returnValue;
}
function callBackCalculateQtyClassCart(res){
	if (res != 0){
		infoObj = eval('('+res+')');
		setInnerHtml("subtotal_"+index, infoObj[1]);
		setInnerHtml("total_price", infoObj[2]);
		setInnerHtml("unit_price_"+index, infoObj[0]);
		setInnerHtml('sh_cart_status_subtotal', infoObj[2]);
	}
}

function callBackCalculateQtyClass_special(res){
	if (res != 0){
		infoObj = eval('('+res+')');
		setInnerHtml('subtotal', infoObj[1]);
		setInnerHtml('unit_price', infoObj[0]);
	}
	setDisplay("reloading", "none");
}

function callBackCalculateQtyClass_product(res){
	if (res != 0){
		infoObj = eval('('+res+')');
		setInnerHtml('subtotal', infoObj[1]);
		setInnerHtml('unit_price', infoObj[0]);
	}
	setDisplay("reloading", "none");
}

jQuery(function() {
	$(".suggest_order_saved").numeric();
	$(".suggest").numeric();
	$(".suggest_product").numeric();
	$(".suggest_special").numeric();
	$(".gift_cant").numeric();

});
