

/* Fonction d'affichage de la popin de validation */

function incPdt(objet,inc){
  var inputQuantite = objet.parentNode.getElementsByTagName('INPUT');
  qte = new Number(inputQuantite[0].value);
  qte = qte+inc;	
  inputQuantite[0].value = qte;  
}

//Fonction d&eacute;cr&eacute;mente quantit&eacute; article panier
function decPdt(objet,dec){
  var inputQuantite = objet.parentNode.getElementsByTagName('INPUT');
  if (inputQuantite[0].value > dec ) {
    qte = new Number(inputQuantite[0].value);
    qte = qte-dec;	
    inputQuantite[0].value = qte;  
   }
   else{
	    var blocPdtParent = inputQuantite[0].parentNode.parentNode.parentNode;
		showPopinCheckout(blocPdtParent,"popinSupprTicket.html");/* DIGITAS - 23/07/08  : Modifications */
   }
}
function clickRemovePdt2(indexTicket) {
  //clickRemovePdt();
  showPopinCheckout(null,"/rdc/popinRemoveProduit.jsp?indexTicket="+indexTicket);
}
function clickRemovePdt(){
  
	jQuery("#contentTicketCaisse .linkRemovePdt").click(function(){
		var parentDivPdt = $(this).parent().parent()[0];
		var indexTicket = this.href.indexOf("(");
		indexTicket = this.href.substr(indexTicket+1, 1);
		showPopinCheckout(parentDivPdt,"/rdc/popinRemoveProduit.jsp?indexTicket="+indexTicket);/* DIGITAS - 23/07/08  : Modifications */
		return false;
   });
}

function clickEmptyCheckout2(){
	clickEmptyCheckout();
	showPopinCheckout(null,"/rdc/popinEmptyTicket.jsp");
}
function clickEmptyCheckout(){
	jQuery("#contentTicketCaisse .linkEmptyCheckout").click(function(){
		showPopinCheckout(null,"/rdc/popinEmptyTicket.jsp");
		return false;
   });
}

function showPopinCheckout(objSuppr,urlPopin){/* DIGITAS - 23/07/08  : Modifications */
	showOpacDivValid()
	$("#opacDiv").after("<div id=\"popin\" class=\"popin validSmallPopin\"></div>");
	$.ajax({
		type:"GET",
		url: urlPopin,
		success:function(msg) {
			$("#popin").append(msg);
			miseEnFormePopin2();
			if (typeof document.body.style.maxHeight === "undefined") {
				/* DIGITAS - 19/10/09 : Modification refonte */
				$("#pageLift select").css("visibility","hidden");
				$("#popin select").css("visibility","visible");
				/* DIGITAS - 19/10/09 : FIN Modification refonte */
			}
			 var windowsHeight = getWindowHeight1();/* DIGITAS - 23/07/08  : Modifications */
			$("body").css("height", windowsHeight+"px");/* DIGITAS- 19/10/09 : modification refonte */
			$("body").css("overflow","hidden");/* DIGITAS- 19/10/09 : modification refonte */
			intitClosePopinValide(objSuppr);
			}
		});
}

function showOpacDivValid(){
	var windowsHeight = getWindowHeight1();/* DIGITAS - 23/07/08  : Modifications */
	if (typeof document.body.style.maxHeight === "undefined") {
		$('#opacDiv').css("height",windowsHeight+"px");
	}
	$('#opacDiv').css("display","block");	
}

function miseEnFormePopin2(){/* DIGITAS - 23/07/08  : Modifications */
	tmp = $("#popin .popinContent").clone();
	$("#popin").empty();
	$("#popin").append(tmp);
}
function intitClosePopinValide(objSuppr){
	$('#popin a.btAnnuleSuppr').click(function(){
		removeLayer2();/* DIGITAS - 23/07/08  : Modifications */
		return false;
	});
	
	/* Supprimer un elt du ticket de caisse */
	$('#popin a.btValideSuppr').click(function(){
		removeLayer2();/* DIGITAS - 23/07/08  : Modifications */
		/* Fonction de suppression de bloc du Ticket a faire par Atos ("objSuppr" est le bloc conteneur a supprimer) */
		RemovePdtBloc(objSuppr);
		return false;
	});
	
	/* Vider le ticket de caisse */
	$('#popin a.btValideEmpty').click(function(){
		removeLayer2();/* DIGITAS - 23/07/08  : Modifications */
		emptyCheckout();
		return false;
	});
}

/* fonction de suppression de produit */
function RemovePdtBloc(objSuppr){
	
}

/* fonction pour vider le ticket */
function emptyCheckout(){
	
}

function removeLayer2(){/* DIGITAS - 23/07/08  : Modifications */
	$('#popin').remove();
	$('#opacDiv').css("display","none");
	if (typeof document.body.style.maxHeight === "undefined") {
		$("#pageLift select").css("visibility","visible");/* DIGITAS- 19/10/09 : modification refonte */
	}
	$("body").css("height", "auto");/* DIGITAS- 19/10/09 : modification refonte */
	$("body").css("overflow","");/* DIGITAS- 19/10/09 : modification refonte */
}


function getWindowHeight1() {/* DIGITAS - 23/07/08  : Modification */

    var windowHeight=0;
	
    if (typeof(window.innerHeight)=='number') {
        windowHeight=window.innerHeight;
    }
    else {
     if (document.documentElement&&
       document.documentElement.clientHeight) {
         windowHeight = document.documentElement.clientHeight;
    }

    else {

     if (document.body&&document.body.clientHeight) {
         windowHeight=document.body.clientHeight;
      }
     }
    }
    return windowHeight;
}


/* Fin Fonction d'affichage de la popin de validation */



function incQuantity(){
	var linksInc = $(".btPlusPdt");
	if (linksInc.length){
		linksInc.each(function(){
			$(this).click(function(){
				incPrice($(this));					   
			});
		});
	}
	var linksInc2 = $(".btMoinsPdt");
	if (linksInc2.length){
		linksInc2.each(function(){
			$(this).click(function(){
				incPrice($(this));					   
			});
		});
	}
}

function incPrice(elt){
	var nbrProd = elt.parent().children("input").attr("value");
	var parentContent = elt.parent().parent();
	var parentContentInput = parentContent.children("input");

	var addPrice = parentContentInput[0].value.replace(",", '.');
	
	if(parentContentInput[1]){
		var addEcoPart = parentContentInput[1].value.replace(",", '.');
		
		var totalEcoPart = parseFloat(addEcoPart)*parseFloat(nbrProd);
		totalEcoPart = totalEcoPart.toFixed(2);
		totalEcoPart = String(totalEcoPart).replace(".", ",");
		
		var total = parseFloat(nbrProd)*(parseFloat(addPrice) + parseFloat(addEcoPart));
		total = total.toFixed(2);
		total = String(total).replace(".", ",");
	
		parentContent.find(".totalProd").find(".totalPricePdt").html(total);
		parentContent.find(".ecoPartPdtTicket").find(".nbrEcoPart").html(totalEcoPart);
		
	}
	
	else{
		var total = parseFloat(nbrProd)*parseFloat(addPrice);
		total = total.toFixed(2);
		total = String(total).replace(".", ",");
		
		parentContent.find(".totalProd").find(".totalPricePdt").html(total);
		
	}
	
	initTotalTicket();
}

function initTotalTicket(){
	
	
	var totalTousPdt = 0;
	var totalTousEco = 0;
	$("#contentTicketCaisse .totalPricePdt").each(function(){
		var valeurTotaux = $(this).html().replace(",", ".");
		totalTousPdt = totalTousPdt + parseFloat(valeurTotaux);
	})
	$("#contentTicketCaisse .nbrEcoPart").each(function(){
		var valeurTotauxEco = $(this).html().replace(",", ".");
		totalTousEco = totalTousEco + parseFloat(valeurTotauxEco);
	})
	
	totalTousPdt = totalTousPdt.toFixed(2);
	totalTousPdt = String(totalTousPdt).replace(".", ",");
	$("#moduleTicketCaisse .nbrPrixTotal").html(totalTousPdt);
	
	totalTousEco = totalTousEco.toFixed(2);
	totalTousEco = String(totalTousEco).replace(".", ",");
	$("#moduleTicketCaisse .nbrEcoPartTotal").html(totalTousEco);

}


jQuery(document).ready(function(){
	/*incQuantity();*/
	clickRemovePdt();
	clickEmptyCheckout();
});


