function addToSelection(nom, prodId, ref, url){
	if (!document.getElementById('hSelection' + prodId)) {		
		if ($("#selectionContent").length > 0) {
			var sProStr = "<tr id='selProd" + prodId + "'>" +
			 "<td class='selRef'>" + ref + "</td>" +
			 "<td class='selNom'>" + nom + "</td>" +
			 "<td class='selQte'><input type='text' size=3 name='quant" + prodId + "' /></td>" +
			 "<td class='selMrqg'>" +
			 "<select>" +
			 "<option>1 Coul.</option>" +
			 "<option>2 Coul.</option>" +
			 "<option>3 Coul.</option>" +
			 "<option>4 Coul.</option>" +
			 "</select>" +
			 "</td>" +
			 "<td><div id='prixHead" + prodId + "' class='selPrixHead selPrixHeadOpen' onclick='handleSelectionPrixList(" + prodId + ")'></div></td>" +
			 "<td>" +
			 "<select>" +
			 "<option>Choisissez</option>" +
			 "<option>Inférieur à 1 Mois </option>" +
			 "<option>Entre 1 et 3 Mois</option>" +
			 "<option>Superieur à 3 Mois</option>" +
			 "</select>" +
			 "</td>" +
			 "<td><div  class='selDelete' onclick='removeFromSelection(" + prodId + ")'></div></td>" +
			 "</tr>" +
			 "<tr id='selProdPrix" + prodId + "' class='selPrixList'>" +
			 "</tr>";

			$("#prodTable").append(sProStr);
			
		}
		else {
			var arrayPageSize = getPageSize();
			var heightTest =  arrayPageSize[1]+'px';
			
			$("#selOverlay").hide().css({width: '100%',height: heightTest, opacity: '0.5'}).show(); 
			var arrayPageScroll = getPageScroll();
			var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 4);
			var lightboxLeft = arrayPageScroll[0];
			$("#popBox").html("<div id='selPopBox'><div id='selPopBoxHead'><span>PRODUIT AJOUTE !</span></div>" + 
					"<div id='selPopBoxBody'><div id='imageBoxPop'><img class='smallLoader' src='../images/smallLoader.gif' /></div>" +
					"<h2>" + nom + "</h2><span>a été ajouté à votre selection</span>" + 
					"<div id='selPopBoxButtons'><a id='selPBBContinue' href='javascript:void(0)'><span>Continuer</span></a><a id='selPBBMaSelection' href='" +baseUrlJ+ "/ma-selection.html'><span>Voir ma selection</span></a></div>" +
					"</div><div id='selPopBoxBottom'></div></div>");
			$('#popBox').css({
				top: lightboxTop + 'px',
				left: lightboxLeft + 'px'
			}).show();
		}
	
		var msp = document.getElementById('servMaSelectionHead').innerHTML;
		if(msp.match("Voir") === null){
			document.getElementById('servMaSelectionHead').innerHTML = "<a href='" + baseUrlJ + "/ma-selection.html'>Voir <strong>Ma Sélection</strong></a>";
		}

		var proStr = document.getElementById('servMaSelectionCont').innerHTML;
		proStr += "<div class='selectionProduit' id='hSelection" + prodId + "'>" +
				"<div class='imageBoxSelection' id='imageBoxSelection" + prodId + "'>" +
		 			"<img class='smallLoader' src='../images/smallLoader.gif' />" +
		 		"</div>" +
		 		"<div class='prodDetails'>" +
		 			"<a href='" + url + "'>" + nom + "</a><a class='hsVoirFiche' href='" + url + "'>Voir fiche produit</a>" +
		 		"</div>" +
		 		"<div class='selectionButtons' onclick=removeFromSelection('"+ prodId +"')></div>" +
		 "</div>";
		document.getElementById('servMaSelectionCont').innerHTML = proStr;
		
		$("#servBoxSelection").slideDown(100);
		$("#servBoxSelectionHead").removeClass("servOpen");
		$("#servBoxSelectionHead").addClass("servClose");
		//$("#servBoxSelectionHead").addClass("serviceNSelected");
		
		$("#btSelect" + prodId).removeClass("showIt");
		$("#btMaSelection" + prodId).removeClass("hideIt");
				
		$("#btMaSelection" + prodId).addClass("showIt");
		$("#btSelect" + prodId).addClass("hideIt");
		
		ajaxRequest = getXmlHttpObject();
		ajaxRequest.onreadystatechange = responseAjaxSelection;
		ajaxRequest.open("GET", baseUrlJ + "/ajax/ajax_selection.php?n=" + nom + "&pid=" + prodId + "&ref=" + ref + "&a=a", true);
		ajaxRequest.send(null);
	}
}

function responseAjaxSelection(){
	if (ajaxRequest.readyState == 4 && ajaxRequest.status == 200) {
		var response = ajaxRequest.responseText.split("#");
		document.getElementById('imageBoxSelection' + response[0]).innerHTML = response[1];
		document.getElementById('imageBoxPop').innerHTML = response[1];
	}
}

function removeFromSelection(prodId){
	ajaxRequest = getXmlHttpObject();
	ajaxRequest.onreadystatechange = responseAjaxRemoveSel;
	ajaxRequest.open("GET", baseUrlJ + "/ajax/ajax_selection.php?pid=" + prodId + "&a=r", true);
	ajaxRequest.send(null);
}
function responseAjaxRemoveSel(){
	if (ajaxRequest.readyState == 4 && ajaxRequest.status == 200) {
		if(ajaxRequest.responseText != "false"){
			$("#hSelection" + ajaxRequest.responseText).fadeOut(200);
			$("#hSelection" + ajaxRequest.responseText).remove();
			
			if($("#selProd" + ajaxRequest.responseText).length > 0){
				$("#selProd" + ajaxRequest.responseText).remove();
				if($("#selProdPrix" + ajaxRequest.responseText).length > 0){
					$("#selProdPrix" + ajaxRequest.responseText).remove();
				
				}
			}
			else if($("#btSelect" + ajaxRequest.responseText).length > 0 || $("#btMaSelection" + ajaxRequest.responseText).length > 0){
				$("#btSelect" + ajaxRequest.responseText).removeClass("hideIt");
				$("#btSelect" + ajaxRequest.responseText).addClass("showIt");
				
				$("#btMaSelection" + ajaxRequest.responseText).removeClass("showIt");
				$("#btMaSelection" + ajaxRequest.responseText).addClass("hideIt");
			}	
		}
	}
}

function handleSelectionPrixList(pid){
	if($("#selProdPrix" + pid).is(':not(:hidden)')){
		$("#selProdPrix" + pid).fadeOut(100);
		$("#prixHead" + pid).removeClass("selPrixHeadClose");
		$("#prixHead" + pid).addClass("selPrixHeadOpen");
	}
	else{
		$("#prixHead" + pid).removeClass("selPrixHeadOpen");
		$("#prixHead" + pid).addClass("selPrixHeadClose");
		if($("#prixTable" + pid).length == 0){
			$("#selProdPrix" + pid).html("<td class='prixLoader' colspan=7><img src='" + baseUrlJ +"/images/cLoader.gif' /></td>");
			$("#selProdPrix" + pid).fadeIn(100);	
			
			ajaxRequest = getXmlHttpObject();
			ajaxRequest.onreadystatechange = responseHandlePrixList;
			ajaxRequest.open("GET", baseUrlJ + "/ajax/ajax_prixList.php?pid=" + pid, true);
			ajaxRequest.send(null);
		}
		else{
			$("#selProdPrix" + pid).fadeIn(100);	
		}	
	}
}

function responseHandlePrixList(){
	if (ajaxRequest.readyState == 4 && ajaxRequest.status == 200 && ajaxRequest.responseText != "") {
		var response = ajaxRequest.responseText.split("#");
		$("#selProdPrix" + response[0]).html(response[1]);	
	}
}

/* //////////////overlay pop boxes ////////////////// */
function initPop(){
	$("#popBox").remove();
	$("#selOverlay").remove();
	$("#yahOverlay").remove();
	$('body').append("<div id='selOverlay'></div><div id='popBox'></div><div id='popBoxRapp'></div>");
	$("#selOverlay").click(function(){ closePop(); }).hide();
	$("#popBox").click(function(){ closePop(); }).hide();
	
	$('body').append("<div id='yahOverlay'></div>");
	$("#yahOverlay").click(function(){closeDropLists(); }).hide();
}

function closePop(){
	$("#popBox").hide();
	$("#popBoxRapp").hide();
	$("#selOverlay").hide();  	
}

function checkEmpty(e, oke){
	if($(e).val() != ""){
		$('#' + oke + "OK").removeClass("errorImg");
		$('#' + oke + "OK").removeClass("errorImg");
		$('#' + oke + "ErrorMsg").html("");
		$('#' + oke + "OK").addClass("okImg");
	}
	else{
		$('#' + oke + "OK").removeClass("okImg");
	}
}

function validSelForm(){
	var isOk = true;
	if(document.selectionForm.nom.value == ""){
		isOk = false;
		$('#selFormNomOK').addClass("errorImg");
		$('#selFormNomErrorMsg').html("Merci de remplir ce champs");
	}
	if(document.selectionForm.societe.value == ""){
		isOk = false;
		$('#selFormSocieteOK').addClass("errorImg");
		$('#selFormSocieteErrorMsg').html("Merci de remplir ce champs");
	}
	if(document.selectionForm.codePostal.value == ""){
		isOk = false;
		$('#selFormCodePostalOK').addClass("errorImg");
		$('#selFormCodePostalErrorMsg').html("Merci de remplir ce champs");
	}
	if(document.selectionForm.telephone.value == ""){
		isOk = false;
		$('#selFormTelephoneOK').addClass("errorImg");
		$('#selFormTelephoneErrorMsg').html("Merci de remplir ce champs");
	}
	if(document.selectionForm.email.value == ""){
		isOk = false;
		$('#selFormEmailOK').addClass("errorImg");
		$('#selFormEmailErrorMsg').html("Merci de remplir ce champs");
	}
	
	if(isOk){
			return true;
	}
	else{
		return false;
	}
}

/* ////// you are here //////////// */ 
function handleDropList(list){
	if($("#" + list).is(':visible')){
		$("#" + list).hide();
		$("#yahOverlay").hide();
	}
	else{
		$('#yahCatList').hide();
		$('#yahFamList').hide();
		$('#yahTypList').hide();
		$('#yahMrqList').hide();
		$("#yahOverlay").hide();
		var arrayPageSize = getPageSize();
		if(arrayPageSize[1] < 4000){
			var yahOverlayHeight = arrayPageSize[1] + 'px';
		}
		else{
			var yahOverlayHeight = '4000px';
		}
		$("#yahOverlay").hide().css({width: '100%',height: yahOverlayHeight,opacity : '0.1'}).show();
		$("#" + list).show();
	}
}

function closeDropLists(){
	$('#yahCatList').hide();
	$('#yahFamList').hide();
	$('#yahTypList').hide();
	$('#yahMrqList').hide();
	$("#yahOverlay").hide();
}

/* //////////////////////////////// affinage des resultats dans le page de produits //////////////////// */
function handleAffinDropList(list){
	if($("#" + list).is(':visible')){
		$("#" + list).hide();
	}
	else{
		$("#" + list).show();
	}
}

/* ///////// affinage resultat marque //// */
function mrqAffinSelected(mrqAObj, mrqAId){
	$('#affinageLoader').show();
	var selectedAM= document.prodAffinHiddenForm.hAffinMrqs;
	if(selectedAM.value.search(mrqAId) != -1) {
		mrqAObj.firstChild.className = "boxEmpty";
		if(selectedAM.value.search("," + mrqAId) != -1){
			selectedAM.value = selectedAM.value.replace(","+mrqAId, "");
		}
		else if(selectedAM.value.search(mrqAId+",") != -1) {
				selectedAM.value = selectedAM.value.replace(mrqAId+",", "");
		}
		else{
			selectedAM.value = selectedAM.value.replace(mrqAId, "");
			document.getElementById('mrq_all_affin').firstChild.className = "boxEmpty boxSelected";
		}
	}
	else{
		document.getElementById('mrq_all_affin').firstChild.className = "boxEmpty";
		mrqAObj.firstChild.className = "boxEmpty boxSelected";
		if(selectedAM.value == ""){
			selectedAM.value += mrqAId;
		}
		else{
			selectedAM.value += "," + mrqAId;
		}	
	}
	getAjaxAffin();
}

function mrqAllAffinSelected(allMrqObj){
	var selectedAM = document.prodAffinHiddenForm.hAffinMrqs;
	if(selectedAM.value != "" ){
		// reseting the selected marques
		var rm = document.getElementById('affinMrqList').getElementsByTagName('li');
		for (var m = 0; m < rm.length; m++) {
			rm[m].firstChild.className = "boxEmpty";
		}
		allMrqObj.firstChild.className = "boxEmpty boxSelected";
		selectedAM.value = "";
		getAjaxAffin();
	}
}

/* ///////// affinage resultat marque //// */
function typAffinSelected(typAObj, typAId){
	$('#affinageLoader').show();
	var selectedAM= document.prodAffinHiddenForm.hAffinTyps;
	if(selectedAM.value.search(typAId) != -1) {
		typAObj.firstChild.className = "boxEmpty";
		if(selectedAM.value.search("," + typAId) != -1){
			selectedAM.value = selectedAM.value.replace(","+typAId, "");
		}
		else if(selectedAM.value.search(typAId+",") != -1) {
				selectedAM.value = selectedAM.value.replace(typAId+",", "");
		}
		else{
			selectedAM.value = selectedAM.value.replace(typAId, "");
			document.getElementById('typ_all_affin').firstChild.className = "boxEmpty boxSelected";
		}
	}
	else{
		document.getElementById('typ_all_affin').firstChild.className = "boxEmpty";
		typAObj.firstChild.className = "boxEmpty boxSelected";
		if(selectedAM.value == ""){
			selectedAM.value += typAId;
		}
		else{
			selectedAM.value += "," + typAId;
		}	
	}
	getAjaxAffin();
}

function typAllAffinSelected(allTypObj){
	var selectedAM = document.prodAffinHiddenForm.hAffinTyps;
	if(selectedAM.value != "" ){
		// reseting the selected marques
		var rm = document.getElementById('affinTypList').getElementsByTagName('li');
		for (var m = 0; m < rm.length; m++) {
			rm[m].firstChild.className = "boxEmpty";
		}
		allTypObj.firstChild.className = "boxEmpty boxSelected";
		selectedAM.value = "";
		getAjaxAffin();
	}
}

/* ///// prix affinage /////// */
var cbTimer;
function affinageBudget(){
	$('#affinageLoader').show();
	if(cbTimer) {
		window.clearTimeout(cbTimer);
	}
	cbTimer = window.setTimeout(ajaxAffinBudget, 1000);
}

function ajaxAffinBudget(){
	cbTimer = null;
	var pfCom = document.btPrixForm.btPrixCom.value;
	var pfFin = document.btPrixForm.btPrixFin.value;
	if(pfCom != "" ||  pfFin != ""){
		pfFin = (IsNumeric(pfFin)) ? pfFin : "";	
		if((pfFin != "" && parseInt(pfCom) > parseInt(pfFin)) || (pfCom == "" || pfCom < 0)){
			pfCom = "0";
			document.btPrixForm.btPrixCom.value = 0;
		}
	}
	getAjaxAffin();
}

function getAjaxAffin(){
	var cV = document.prodAffinHiddenForm.hAffinCats.value;
	var fV = document.prodAffinHiddenForm.hAffinFams.value;
	var tV = document.prodAffinHiddenForm.hAffinTyps.value;
	var qV = document.prodAffinHiddenForm.hAffinQte.value;
	var mV = document.prodAffinHiddenForm.hAffinMrqs.value;
	var theV = document.prodAffinHiddenForm.hAffinThe.value;
	var cleV = document.prodAffinHiddenForm.hAffinCle.value;
	if(document.btPrixForm.btPrixCom.value != "" || document.btPrixForm.btPrixFin.value != ""){
		var prVStr = "&pr=" + document.btPrixForm.btPrixCom.value + "_" + document.btPrixForm.btPrixFin.value;
	}
	else{
		var prVStr = "";
	}
	
	
	var urlStr = "?a=count&c=" + cV + "&f=" + fV + "&t=" + tV + prVStr + "&q=" + qV + "&m=" + mV + "&the=" +theV+ "&cle="+cleV;
	ajaxRequest = getXmlHttpObject();
	ajaxRequest.onreadystatechange = responseAjaxAffin;
	ajaxRequest.open("GET", baseUrlJ + "/ajax/ajax_affinage.php" + urlStr , true);
	ajaxRequest.send(null);
}

function responseAjaxAffin(){
	if (ajaxRequest.readyState == 4 && ajaxRequest.status == 200 && ajaxRequest.responseText != "") {
		$('#affineCount').html(ajaxRequest.responseText);
		$('#resultatAffinButton').show();
		$('#affinageLoader').hide();	
	}
}

function createAffinLink(currentPage){
	var prodCount = $('#affineCount').text();
	if(prodCount != 0){
		var cV = (document.prodAffinHiddenForm.hAffinCats.value != "") ? "&c=" + document.prodAffinHiddenForm.hAffinCats.value : "";
		var fV = (document.prodAffinHiddenForm.hAffinFams.value != "") ? "&f=" + document.prodAffinHiddenForm.hAffinFams.value : "";
		var tV = (document.prodAffinHiddenForm.hAffinTyps.value != "") ? "&t=" + document.prodAffinHiddenForm.hAffinTyps.value : "";
		var qV = (document.prodAffinHiddenForm.hAffinQte.value != "") ? "&q=" + document.prodAffinHiddenForm.hAffinQte.value : "";
		var mV = (document.prodAffinHiddenForm.hAffinMrqs.value != "") ? "&m=" + document.prodAffinHiddenForm.hAffinMrqs.value : "";
		var theV = (document.prodAffinHiddenForm.hAffinThe.value != "") ? "&the=" + document.prodAffinHiddenForm.hAffinThe.value : "";
		if(document.btPrixForm.btPrixCom.value != "" || document.btPrixForm.btPrixFin.value != ""){
			var prV = "&pr=" + document.btPrixForm.btPrixCom.value + "_" + document.btPrixForm.btPrixFin.value;
		}
		else{
			var prV = "";
		}
		
		setTimeout(function(){
   			window.location = baseUrlJ2 + currentPage + "?total=" + prodCount + cV + fV + tV + prV + qV + mV + theV;
		}, 0);	
	}
	else{
		alert("temp message: 0 produits");
	}
}

function freeSearchSuggest(){
	ajaxRequest = getXmlHttpObject();
	var kStr = document.getElementById('freeSearchKeys').value;
	if (kStr.length > 2 && !((kStr.toUpperCase()).indexOf("LAG")== 0) && !parseInt(kStr) && !parseFloat(kStr)) {
		var keyStr = "?keys=" + kStr;
		$('#freeSearchLoader').show();
		ajaxRequest.onreadystatechange = ajaxFreeSearchSuggest;
		ajaxRequest.open("GET", baseUrlJ + "/ajax/ajax_freeSearch.php" + keyStr, true);
		ajaxRequest.send(null);
	}
	else{
		closeFreeSearch();
	}
}

function ajaxFreeSearchSuggest(){
	if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200) {
		$('#freeSearchLoader').hide();
		if (ajaxRequest.responseText != "") {
			$('#freeSearchResults').show();
			$('#freeSearchResults').html(ajaxRequest.responseText);
			
			if($('#fsOverlay').length == 0) {
				$('body').append("<div id='fsOverlay'></div>");
				$('#fsOverlay').click(function(){closeFreeSearch(); }).hide();
				var arrayPageSize = getPageSize();
				if(arrayPageSize[1] < 4000){
					var fsOverlayHeight = arrayPageSize[1] + 'px';
				}
				else{
					var fsOverlayHeight = '4000px';
				}
				$('#fsOverlay').css({width: '100%', height: fsOverlayHeight, opacity: 0.1}).show();
				$('#freeSearchForm').css('zIndex', '250');
			}
		}
		else{
			document.getElementById('freeSearchResults').innerHTML = "";
			document.getElementById('freeSearchResults').style.display = "none";
		}
	}
}

function closeFreeSearch(){
	$('#freeSearchLoader').hide();
	$('#freeSearchResults').hide();
	$('#freeSearchResults').html(""); 
	$('#fsOverlay').hide();
	$('#fsOverlay').remove();
	$('#freeSearchForm').css('zIndex', '50');
}

////////////////////  free search  /////////////////
function freeSearchLink(){
	var kStr = document.getElementById('freeSearchKeys').value;
	if (kStr.length > 2) {
		kStr = kStr.replace(/ /g, "-");
		kStr = kStr.replace(/é/g, "e");
		kStr = kStr.replace(/è/g, "e");
		kStr = kStr.replace(/â/g, "e");
		kStr = kStr.replace(/\./g, "-");
		var urlStr = baseUrlJ + "/recherche-" + kStr + ".html"; 
		window.location = urlStr;
		setTimeout(function(){
   			window.location = urlStr;
		}, 0);	
	}
	else{
		alert("Votre recherche doit comporté minimum 3 caractères");
	}
}

function getPrecis(){
	var kStr = "";
	if(document.avanceePrecisForm.ref.value != ""){
		kStr = document.avanceePrecisForm.ref.value;
		kStr = kStr.replace(/\./g, "-");
	}
	else if(document.avanceePrecisForm.motcle.value != ""){
		kStr = document.avanceePrecisForm.motcle.value;
		kStr = kStr.replace(/ /g, "-");
		kStr = kStr.replace(/é/g, "e");
		kStr = kStr.replace(/è/g, "e");
		kStr = kStr.replace(/â/g, "e");
		kStr = kStr.replace(/\./g, "-");
	}
	
	if (kStr != "") {
		var urlStr = baseUrlJ + "/recherche-" + kStr + ".html";
		window.location = urlStr;
		setTimeout(function(){
			window.location = urlStr;
		}, 0);
	}
}

function getPageSize(){
		var xScroll, yScroll;
		if (window.innerHeight && window.scrollMaxY) {
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		var windowWidth, windowHeight;
		if (self.innerHeight) { // all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth;
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else {
			pageHeight = yScroll;
		}
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){
			pageWidth = xScroll;
		} else {
			pageWidth = windowWidth;
		}
		var arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
		return arrayPageSize;
}

function getPageScroll(){
		var xScroll, yScroll;
		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
			xScroll = self.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){  // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
			xScroll = document.documentElement.scrollLeft;
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
			xScroll = document.body.scrollLeft;
		}
		var arrayPageScroll = new Array(xScroll,yScroll);
		return arrayPageScroll;
}

function gotoPage(url, perPage, totalPage, vars){
	var toPage = Number(document.gotoForm.toPageNum.value);
	if(IsNumeric(toPage) && toPage > 0 && toPage <= totalPage){
		window.location = url + "?page=" + toPage + "." + perPage + vars;
		//alert(url + "?page=" + toPage + "." + perPage + vars);
		return false;
	}
	else{
		$('#gotoForm').append("<div id='gotoFormError'>cette page n'existe pas<span id='closeGotoError'></span></div>");
		$("#closeGotoError").click(function(){ $('#gotoFormError').remove(); });
		return false;
	}
	return false;
}

var promoInterval;
var promoState = "Play";
function pausePlay(){
	if(promoState == "Play"){
		clearInterval(promoInterval);
		$('#pausePlay').css({backgroundPosition:'0 2px'});
		promoState = "pause";
	}
	else if(promoState == "pause"){
		$('#pausePlay').css({backgroundPosition:'0 -56px'});
		promoInterval = setInterval(runPromoInterval, 5000); 
		$("div.scrollable").scrollable().next(); 
		promoState = "Play";
	}
}

function submitContactEmailForm(){
	var cENom = trim($('#cENom').val());
	var cESociete = trim($('#cESociete').val());
	var cETel = trim($('#cETel').val());
	var cEEmail = trim($('#cEEmail').val());
	var cEMessage = trim($('#cEMessage').val());
	
	if(trim($('#cESociete').val()) == "") {
		
	}
	if(trim($('#cEEmail').val()) == "") {
	
	}
	
	ajaxRequest = getXmlHttpObject();
	ajaxRequest.onreadystatechange = responseSubmitContactEmailForm;
	ajaxRequest.open("GET", baseUrlJ + "/ajax/ajax_contactEmail.php?cENom=" + cENom + "&cESociete=" + cESociete + "&cETel=" + cETel + "&cEEmail=" + cEEmail + "&cEMessage=" + cEMessage , true);
	ajaxRequest.send(null);
	
}
function responseSubmitContactEmailForm(){
	if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200) {
		if(ajaxRequest.responseText == "ok"){
			$('#contactEmailForm').hide();
			$('#contactEmailForm').html("<b>Merci, votre email a bien été envoyée.</b>").css("width", "200px").show();
		}
		else{
			$('#contactEmailForm').hide();
			alert("Une erreur est survenue. Votre email n'a pas été envoyée.");
		}
	}
}
function rappel(){
		var arrayPageSize = getPageSize();
		var heightTest =  arrayPageSize[1]+'px';
		$("#selOverlay").hide().css({width: '100%',height: heightTest, opacity: '0.5'}).show(); 
		var arrayPageScroll = getPageScroll();
		var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 4);
		var lightboxLeft = arrayPageScroll[0];
		$("#popBoxRapp").html("<div id='selPopBox'><div id='popBoxHeadArr'><span>Rappel automatique</span><a class='popHeadFermer' href='javascript:void(0)' onclick=closePop();>fermer</a></div>" + 
				"<div id='rappPopBoxBody'>" +
				"<table><tr><td class='rapLable'>*NOM:</td><td><input type='text' name='rapNom' id='rapNom' onblur=\"checkEmpty(this, 'vRapNom')\" /></td><td id='vRapNomOK' class='selFormOk' /></tr>" +
				"<tr><td class='rapLable'>*SOCIETE:</td><td><input type='text' name='rapSociete' id='rapSociete' onblur=\"checkEmpty(this, 'vRapSociete')\" /></td><td id='vRapSocieteOK' class='selFormOk' /></tr>" +
				"<tr><td class='rapLable'>*TELEPHONE DU STANDARD:</td><td><input type='text' name='rapTelStand' id='rapTelStand' onblur=\"checkEmpty(this, 'vRapTelStand')\" /></td><td id='vRapTelStandOK' class='selFormOk' /></tr><tr>" +
				"<td class='rapLable'>TELEPHONE DIRECT:</td><td><input type='text' name='rapTelDirect' id='rapTelDirect' /></td><td></td></tr>" + 
				"<td class='rapLable'>EMAIL:</td><td><input type='text' name='rapEmail' id='rapEmail' /></td><td></td></tr></table>" + 
				"<a id='rapEnvoyer' href='javascript:void(0)' onclick=rappelEmail();><span>ENVOYER</span></a><div id='rapLoader' /></div>" +
				"</div>");
		$('#popBoxRapp').css({
			top: lightboxTop + 'px',
			left: lightboxLeft + 'px'
		}).show();
}
function rappelEmail(){
	var eField = false;
	var rapNom = trim($('#rapNom').val());
	var rapSociete = trim($('#rapSociete').val());
	var rapTelStand = trim($('#rapTelStand').val());
	var rapTelDirect = trim($('#rapTelDirect').val());
	var rapEmail = trim($('#rapEmail').val());
	if(rapNom == "") {
		eField = true;
		$('#vRapNomOK').addClass("errorImg");	
	}
	if(rapSociete == "") {
		eField = true;	
		$('#vRapSocieteOK').addClass("errorImg");	
	}
	if(rapTelStand == "") {
		eField = true;
		$('#vRapTelStandOK').addClass("errorImg");	
	}
	if (!eField) {
		$('#rapLoader').show();
		ajaxRequest = getXmlHttpObject();
		ajaxRequest.onreadystatechange = responseRappelEmail;
		ajaxRequest.open("GET", baseUrlJ + "/ajax/ajax_contactEmail.php?rapNom=" + rapNom + "&rapSociete=" + rapSociete + "&rapTelStand=" + rapTelStand + "&rapTelDirect=" + rapTelDirect + "&rapEmail=" + rapEmail, true);
		ajaxRequest.send(null);
	}
}
function responseRappelEmail(){
	if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200) {
		if(ajaxRequest.responseText == "ok"){
			$("#rappPopBoxBody").html("<a class='rapMercifremer' href='javascript:void(0)' onclick=closePop();>Fermer</a> ");
			$("#rappPopBoxBody").css({background: 'url(../images/fd-rappel-merci.png) no-repeat'});
		}
		else{
			$("#rappPopBoxBody").html("");
			$("#rappPopBoxBody").css({background: 'url(../images/fd-rappel-error.png) no-repeat'});
		}
	}
}
function cbForm(){
	var cbNumeroC = trim($('#cbNumeroC').val());
	var cbEmail = trim($('#cbEmail').val());
	var reg = /^[\w\-]+(\.[\w\-]+)*@[\w\-]+(\.[\w\-]+)*\.[\w\-]{2,}$/ ;
	var cbChamps=""; var cbSpecial="";
	var cbTel = (trim($('#cbTelephone').val())).split(' ').join('');
	if(cbNumeroC == "" || cbNumeroC.length != 5) {$('#cbErrorTop').html('La numéro de commande doit contenir 5 chiffres');}
	else if(trim($('#cbNumeroCPre').val()) == "") cbChamps = "Numéro Command";	
	else if(document.cbFormulaire.societeRadio[0].checked && (trim($('#cbNomClient').val()) == "" || $('#cbNomClient').val() == "Nom Société" )) cbChamps = "Société";
	else if(trim($('#cbNomPers').val()) == "" || trim($('#cbPrenomPers').val()) == "") cbChamps = "Contact";
	else if(cbTel.length != 12) cbSpecial = "Le numéro de téléphone doit comporter 9 chiffres";
	else if(reg.test(cbEmail) == false) cbChamps = "Email";
	else if(trim($('#cbMontant').val()) == "" || trim($('#cbMontant').val()) <= 0) cbChamps = "Montant";
	else if(!document.cbFormulaire.mLegal.checked) cbSpecial = "Vous devez accepter les Mentions légales";
	else return true;

	if(cbChamps != ""){$('#cbErrorTop').html('Veuillez renseigner le champ  - ' + cbChamps);}
	else if(cbSpecial != "") {$('#cbErrorTop').html(cbSpecial);}
	$('#cbErrorTop').css({display:'block'});
	return false;
}
function clearInputVal(iFieldID, iVal){
	if($('#'+iFieldID).val() == iVal){ $('#'+iFieldID).val(""); $('#'+iFieldID).css({color:'#555555'});}
}
function pcForm(){
	var pcChamps = "";
	if(document.promoCForm.societe.value == "")  pcChamps = "Société";
	else if(document.promoCForm.persNom.value == "")  pcChamps = "Nom";
	else if(document.promoCForm.persPrenom.value == "")  pcChamps = "Prenom";
	else if(document.promoCForm.email.value == "")  pcChamps = "Email";
	else if(document.promoCForm.tel.value == "")  pcChamps = "Telephone";
	else if(document.promoCForm.adress.value == "")  pcChamps = "Adress";
	else if(document.promoCForm.codePostal.value == "")  pcChamps = "Code Postal";
	else if(document.promoCForm.ville.value == "")  pcChamps = "Ville";
	else if(!document.promoCForm.reglement.checked)  pcChamps = "Reglement";
	
	if(pcChamps != ""){
		$('#cbErrorTop').html('Veuillez renseigner le champ - ' + pcChamps);
		$('#cbErrorTop').css({display:'block'});
		return false;
	}
	return true;
}
function changeImage(image, imageLarge){
	document.getElementById('mainImage').innerHTML = "<a href='"+ imageLarge + "' class='lightbox' rel='prodImages'><img src='" + image + "' /></a><a href='"+ imageLarge + "' id='zoomImg' class='lightbox' rel='prodImages'></a>";
	$("a[rel='prodImages']").colorbox();
}

function getListTumbs(pList){
	for(var pl = 0; pl < pList.length; pl++){
		$.get(baseUrlJ + "/ajax/ajax_tumbs.php", 
			{pRef:pList[pl][0], pCatalogue:pList[pl][1], pCount:pl}, 
			function(tumbsHtml){
				var tumbResult = tumbsHtml.split('#');
				$('#listTumbImages'+ tumbResult[0]).html(tumbResult[1]);
				var relTemp = "a[rel='listTumbRel"+tumbResult[0]+"']";
				$("'"+relTemp+"'").colorbox();
			}, 
			"html"
		);
	}
}
function changeListImage(image, imageLarge, mainImageId){
	//document.getElementById('listMainImage'+mainImageId).innerHTML = "<a href='"+ imageLarge + "' rel='listTumbRel"+mainImageId+"'><img src='" + image + "' /></a>";
	$('#listMainImage'+mainImageId).html("<a href='"+ imageLarge + "' rel='listTumbRel"+mainImageId+"'><img src='" + image + "' /></a>");
	var relTemp = "a[rel='listTumbRel"+mainImageId+"']";
	$("'"+relTemp+"'").colorbox();
}
