function addToCart(idProduct) {
	var productOption = [];
	
	$("#div_product_options_"+idProduct).ready(function(){
		$(".productOption").each(function(i){
			productOption.push($(this).val());
		});
  	});
	
	productOption = productOption.join(",");	
	$.post("index.php?to=ajax_shop",{
		action: "addToCart",
		productId: idProduct,
		productOption: productOption
    });
    //showCartModal();
	setTimeout("showCartModal()",400);

}

function addToCartDeclinaison(idProduct) {
	var productOption = [];
	
	$("#div_product_options_"+idProduct).ready(function(){
		$(".productOption").each(function(i){
			productOption.push($(this).val());
		});
  	});
	
	productOption = productOption.join(",");	
	$.post("index.php?to=ajax_shop",{
		action: "addToCart",
		productId: idProduct,
		productOption: productOption,
		productDeclinaison: $("#f_i_declinaison").val()
    });
    //showCartModal();
	setTimeout("showCartModal()",400);
}

function updateCodePromo(displayOnly) {
	$("#div_cart").load("index.php?to=ajax_shop", {
		action:"updateCodePromo",
		displayOnly: displayOnly,
		codePromo: $("#f_s_code_promo").val()
	});
}

function contact(idProduct) {
	contactProduct(0);
}

function contactProduct(idProduct) {
	$.nyroModalManual({
   		url: 'index.php?to=contact_form&id_product='+idProduct,
  		width: 780,
		height: 400
   	});
}

function contactDevis() {
	$.nyroModalManual({
   		url: 'index.php?to=contact_form&Devis=1',
  		width: 780,
		height: 400
   	});
}

function contactPro() {
	$.nyroModalManual({
   		url: 'index.php?to=contact_form&pro=1',
  		width: 780,
		height: 400
   	});
}

function removeFromCart(idProduct,productOptionId) {
	$.post("index.php?to=ajax_shop",{
		action: "removeFromCart",
		productId: idProduct,
		productOptionId: productOptionId
    });
   setTimeout("refreshCart()",400);
}

function updateCartQuantity(o) {
	$.post("index.php?to=ajax_shop",{
		action: "updateCartQuantity",
		field: o.id,
		value: o.value
    });
    setTimeout("refreshCart()",400);
}

function refreshCart() {
	$("#div_cart").load("index.php?to=ajax_shop",{
    	action: "refreshCart"
    });
}

function showCartModal() {
	$.nyroModalManual({
   		url: 'index.php?to=cart',
  		width: 780,
		height: 500
   	});
}

function processCartModal() {
	$.nyroModalManual({
   		url: 'index.php?to=cart_process',
  		width: 780,
		height: 500
   	});
}

function autoSaveUserInfo(o) {
	$.post("index.php?to=ajax_custom",{
		action: "autoSaveUserInfo",
		field: o.id,
		value: o.value
    });
}

function orderSimpleValidate() {
	if(confirm('Etes vous sur de vouloir valider votre commande?')) {
		document.location.href = 'index.php?order_confirm&confirm=1';
	}
}

function checkCGV() {
	if($("#f_i_cgv").attr("checked")) {
		return true;
	}
	alert("Vous devez accepter les conditions générales de vente.");
	return false;
}

function updateAddressInvoiceLikeDelivery() {
	$("#div_order_address_select").load("index.php?to=ajax_shop",{
    	action: "updateAddressInvoiceLikeDelivery"
    });
}

function updateAddressSelected(value,type) {
	$("#div_order_address_select").load("index.php?to=ajax_shop",{
    	action: "updateAddressSelected",
    	value: value,
		type: type
    });
}

function updateOrderTransporteur(idTransporteur,displayOnly) {
	$("#div_cart").load("index.php?to=ajax_shop",{
    	action: "updateOrderTransporteur",
    	displayOnly: displayOnly,
    	idTransporteur: idTransporteur
    });
}

