// JavaScript Document
/**
 *
 * MODIFICATIONS LOGICA - PROJET GL
  --------------------------------------------------------------
  Auteur	    		Date					Objet
  L.ISBLED 			18/11/2010  	JIRA 1 : Moteur de recherche
  N.Chapurlat		25/11/2010		Ajout comportement votrePanier, votreCompte et banniere menu home
  FX DESMIDT			25/11/2010		Modification des fonctions ActivateVotrePanier, ActivateVotreCompte pour les adapter au header de la page catalogue
  S.Briffaut		03/11/2010		Ajout fonctions de chargement nouvelle couleur et menu des quantit?s
*/

//LAYOUT
var ElGoodies = {

	getDocument: function(){
		return this.ownerDocument;
	},

	getWindow: function(){
		return this.getDocument().getWindow?this.getDocument().getWindow():window;
	},

	dispose: function(){
		return this.parentNode.removeChild(this);
	},

	replaces: function(el){
		if('string'==(typeof el).toLowerCase()) el = document.getElementById(el);
		el.parentNode.replaceChild(this, el);
		return this;
	},

	hasClass: function(className){
		return this.className.contains(className, ' ');
	},

	addClass: function(className){
		if (!this.hasClass(className)) this.className = (this.className + ' ' + className).clean();
		return this;
	},

	removeClass: function(className){
		this.className = this.className.replace(new RegExp('(^|\\s)' + className + '(?:\\s|$)'), '$1').clean();
		return this;
	},

	toggleClass: function(className){
		return this.hasClass(className) ? this.removeClass(className) : this.addClass(className);
	},

	getComputedStyle: function(property){
		var result = null;
		if (this.currentStyle){
			result = this.currentStyle[property.camelCase()];
		} else {
			var computed = this.getWindow().getComputedStyle(this, null);
			if (computed) result = computed.getPropertyValue([property.hyphenate()]);
		}
		return result;
	},

	isBody: function() {
		return this.tagName.toLowerCase() == 'body';
	},

	getPosition: function(relative){
		function objectize(el) {
			if('string'==(typeof el).toLowerCase()) el = document.getElementById(el);
			return el;
		}
		if (this.isBody()) return {x: 0, y: 0};
		var el = this, position = {x: 0, y: 0};
		while (el){
			position.x += el.offsetLeft;
			position.y += el.offsetTop;
			el = el.offsetParent;
		}
		var rpos = (relative) ? objectize(relative).getPosition() : {x: 0, y: 0};
		return {x: position.x - rpos.x, y: position.y - rpos.y};
	},

	enrich: function(el){
		if(null==el) return;
		if('string'==(typeof el).toLowerCase()) el = document.getElementById(el);
		for( var methodName in this ) {
			if('enrich'==methodName) continue;
			if( 'undefined' == typeof el[methodName] || null == typeof el[methodName] ) {
				el[methodName] = this[methodName];
			}
		}
	}
};



function lit_cook(nom) {
      var deb,fin
      deb = document.cookie.indexOf(nom + "=")
      if (deb >= 0) {
         deb += nom.length + 1
         fin = document.cookie.indexOf(";",deb)
         if (fin < 0) fin = document.cookie.length
         return unescape(document.cookie.substring(deb,fin))
         }
      return ""
}


function maximize(el) {
	if(!el.getPosition) ElGoodies.enrich(el);
	var soFarAway = document.getElementById('soFarAway');
	var farAway = document.getElementById('farAway');
	var lastDiv = (document.getElementsByTagName('div'))[document.getElementsByTagName('div').length-1];
	if( null==soFarAway ) {
		var sfaProps = {
			position:'absolute',
			right:'1px',
			bottom:'1px',
			overflow:'hidden',
			width:'1px',
			height:'1px',
			backgroundColor:'transparent',
			zIndex:'-2'
		};
		soFarAway = document.createElement('div');
		soFarAway.setAttribute('id','soFarAway');
		for( var prop in sfaProps ) soFarAway.style[prop] = sfaProps[prop];
		el.getDocument().body.insertBefore(soFarAway,document.body.firstChild);
		ElGoodies.enrich(soFarAway);
		ElGoodies.enrich(lastDiv);
	}
	lastDiv.pos = lastDiv.getPosition();
	soFarAway.pos = soFarAway.getPosition();
	el.style.width  = Math.max(soFarAway.pos.x+2,el.getDocument().body.clientWidth)+'px';
	//el.style.height = Math.max(soFarAway.pos.y+1,lastDiv.pos.y+lastDiv.offsetHeight)+'px';

	h = Math.max((window.innerHeight?window.innerHeight:0),(document.getElementsByTagName('body'))[0].offsetHeight,(document.getElementsByTagName('html'))[0].offsetHeight)
	el.style.height = h+'px';
	el.style.width = '994px';
	el.style.display = 'block';
}

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount = limitNum - limitField.value.length;
	}
}

// POP IN OVERLAY

/*
//PNG IE
var bgsleight	= function(){

	function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			}
		}
	}

	function fnLoadPngs() {
		var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
		var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);
		for (var i = document.all.length - 1, obj = null; (obj = document.all[i]); i--) {
			if (itsAllGood && obj.currentStyle.backgroundImage.match(/\.png/i) != null) {
				fnFixPng(obj);
				obj.attachEvent("onpropertychange", fnPropertyChanged);
			}
		}
	}

	function fnPropertyChanged() {
		if (window.event.propertyName == "style.backgroundImage") {
			var el = window.event.srcElement;
			if (!el.currentStyle.backgroundImage.match(/x\.gif/i)) {
				var bg	= el.currentStyle.backgroundImage;
				var src = bg.substring(5,bg.length-2);
				el.filters.item(0).src = src;
				el.style.backgroundImage = "url(x.gif)";
			}
		}
	}

	function fnFixPng(obj) {
		var bg	= obj.currentStyle.backgroundImage;
		var src = bg.substring(5,bg.length-2);
		obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";
		obj.style.backgroundImage = "url(x.gif)";
	}


	return {
		init: function() {
			if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
				addLoadEvent(fnLoadPngs);
			}
		}
	}

}();
bgsleight.init();
*/



/**fonction pour valider les ecrans tunnel avec encadr? rouge different de la creation a cause des champs en moins **/
function validadressetunnel(){
	var color = "#FF0000";
	document.getElementById('civilite').style.borderColor="";
	document.getElementById('nom').style.borderColor="";
	document.getElementById('prenom').style.borderColor="";
	document.getElementById('adresse').style.borderColor="";
	document.getElementById('cp').style.borderColor="";
	document.getElementById('ville').style.borderColor="";
	document.getElementById('pays').style.borderColor="";
	document.getElementById('telB').style.borderColor="";
	document.getElementById('telP').style.borderColor="";
	document.getElementById('telF').style.borderColor="";

	if(document.getElementById('civilite').value ==''){
		document.getElementById('civilite').style.borderColor=color;
	}else if(document.getElementById('nom').value ==''){
		document.getElementById('nom').style.borderColor=color;
	}else if(document.getElementById('prenom').value ==''){
		document.getElementById('prenom').style.borderColor=color;
	}else if(document.getElementById('adresse').value ==''){
		document.getElementById('adresse').style.borderColor=color;
	}else if(document.getElementById('adresse').value !='' && document.getElementById('adresse').value.length > 50){
		document.getElementById('adresse').style.borderColor=color;
	}else if(document.getElementById('cp').value ==''){
		document.getElementById('cp').style.borderColor=color;
	}else if(document.getElementById('ville').value ==''){
		document.getElementById('ville').style.borderColor=color;
	}else if(document.getElementById('pays').value =='' || document.getElementById('pays').value =='-1'){
		document.getElementById('pays').style.border="1px solid";
		document.getElementById('pays').style.borderColor=color;
	}else if(document.getElementById('telB').value =='' && document.getElementById('telP').value =='' && document.getElementById('telF').value ==''){
		document.getElementById('telB').style.borderColor=color;
		document.getElementById('telP').style.borderColor=color;
		document.getElementById('telF').style.borderColor=color;
	}
}
/*---- fonction de validation du formatage des email ----*/
/*---- -------------------------------- ----*/
/*---- ---------stephane--------------- ----*/
function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return false
	 }

	 if (str.indexOf(" ")!=-1){
	    return false
	 }

		 return true
}
function trim(s) {
    return s.replace(/^\s+/, '').replace(/\s+$/, '');
}
function submit_form_rech(){
	var input_value = document.getElementById('suggest').value;
	if(trim(input_value) == '' || trim(input_value) == 'saisir votre recherche') {
		//alert('veuillez saisir une valeur de recherche');
	} else {
		document.getElementById('formMarques').submit();
	}
}
//function pour la page de non r?sultats
function submit_form_rechBis(){
	var input_value = document.getElementById('suggestBis').value;
	if(trim(input_value) == '' || trim(input_value) == 'saisir votre recherche') {
		//alert('veuillez saisir une valeur de recherche');
	} else {
		document.getElementById('formMarquesBis').submit();
	}
}

//AJOUT LISBLED 18/11/10 JIRA 1 Moteur de recherche

function showPopupArticleCarnetMode(urlServerProcess)
{
//	var nb_result_cm = document.getElementById('nb_result_cm').value;
//	var nbresult=0;

	var url_client=urlServerProcess;

//	document.getElementById('popupNewsCarnetMode').style.display="block";
//	alert(colorSize);
	document.getElementById('cnt-cm').style.display="none";
	DisplayPopUp('cnt-pop-news');
	var sub_array_name;
	//var stringData = 'nb_result_cm='+ nb_result_cm;
	var stringData="";
	var stringUrl = url_client ;
	//alert(stringUrl);
	//alert(stringData);
	$.ajax({
		type: "POST",
		url: stringUrl,
		data: stringData,

		success: function(returnedValues){
			document.getElementById('cnt-pop-news').innerHTML = returnedValues;
			_gaq.push(['_trackPageview', '/layer/carnet_mode/detail/']);
			/*#####################################################################*/
			//alert(document.getElementById('cnt-pop-cn').innerHTML = returnedValues);
			/*#####################################################################*/

		},
		error: ""

	});

	//alert(urlServerProcess);
}

/*
 * GLCOM-621 : Cache du site
 * Modification du type "POST" en "GET"
 */
function showPopupProduit(urlServerProcess)
{
//	var nb_result_cm = document.getElementById('nb_result_cm').value;
//	var nbresult=0;

	var url_client=urlServerProcess;
	document.getElementById('pop-quick-produit').style.display="block";
	document.getElementById('cnt-pop-quick').style.display="block";
	//alert(colorSize);

	var sub_array_name;

	var stringData="";

	var stringUrl = url_client ;

	$.ajax({
		type: "GET",
		url: stringUrl,
		data: stringData,

		success: function(returnedValues){

			document.getElementById('cnt-pop-quick').innerHTML = returnedValues;
			var gaQuickView = document.getElementById('googleAnalyticsQVHidden').value;
			_gaq.push(['_trackPageview', '/apercu/' + gaQuickView + '/']);
			
			$(function(){

	        	$('.selecteurSize').each(function () {

	        		$(".selecteurSize > ul:eq(0)").imgDropDown(
	        				{title:"Taille"}
	        		);
	        		addKeyboardNavToDropDown($(this));
	        	});

    		  	$('.selecteurQuantity').each(function () {
            		$(".selecteurQuantity > ul:eq(0)").imgDropDown(
            				{title:"Quantit&eacute"}
            		);
            		addKeyboardNavToDropDown($(this));
            	});

    		  	$('.selecteurColor').each(function () {

	        		$(".selecteurColor > ul:eq(0)").imgDropDown(
	        				{title:"Couleur"}
	        		);
	        		addKeyboardNavToDropDown($(this));
	        	});

    		  	$('#globalFP .selecteurColor .dropdownPanel .dropdownOpt:first').click();

    		  	var nomb = $('#globalFP .cliq .selecteurSize .dropdownPanel .dropdownOpt').size();
    			if(nomb == 1){
    				$('#globalFP .cliq .selecteurSize .dropdownPanel .dropdownOpt:first').click();
    			}

				$('.selecteurQuantity').click(
						function(event) {
							$('.selecteurSize > .dropdownPanel').hide();
							$('.selecteurColor > .dropdownPanel').hide();
				}
				);
				$('.selecteurSize').click(
							function(event) {
								$('.selecteurQuantity > .dropdownPanel').hide();
								$('.selecteurColor > .dropdownPanel').hide();
				}
				);
				$('.selecteurColor').click(
						function(event) {
							$('.selecteurSize > .dropdownPanel').hide();
							$('.selecteurQuantity > .dropdownPanel').hide();
						}
						);

	        });

		},
		error: ""

	});

}
function DisplayPopUp(nomPopUp)
{
	document.getElementById(nomPopUp).style.display="block";
}
//FIN LISBLED 18/11/10 JIRA 1 Moteur de recherche

// N.Chapurlat		25/11/2010		Ajout comportement votrePanier, votreCompte et banniere menu home
// FX DESMIDT 		25/11/2010      Ajout variable page afin de determiner si l'on se situ dans bonnes affaires ou autre
function activateMenuBanniere(page) {
	// hide the sub menu on startup and when mouse go out
	$('.banniere-submenu').hide();
	
	//Plus besoin du mouseleave la fenetre se ferme avec un bouton "fermer";
	/*$('.banniere-submenu,#header,#blocBanniere').mouseleave(
			function(event) {
				$('.banniere-submenu').hide();
			}
	);*/
	// show the submenu on mouse over

	$('.banniere-menu-item-submenu-parent').click(
			function(event) {
				$('.banniere-submenu').hide();
				$(this).next().show().children('li.first').children('a').focus();
				$('.AFSSuggestPopup').hide();

				//popuprecherche.style.display="none";
			}
	);
	// move in the submenu on arrow up and down, hide the submenu on ESC andarroy left
	if(page=="BA"){
		$('.banniere-menuBA .banniere-submenu-item').keydown(
	    		function(event) {
	    			if (event.keyCode == 38 || event.keyCode == 40 || event.keyCode == 37 || event.keyCode == 27) {
	    				event.preventDefault();
		    			event.stopPropagation();
	                }
	    			if (event.keyCode == 38) {
		    			if (!$(this).parent().prev().hasClass('top')) {
		    				$(this).parent().prev().find('a').focus();
		    			}
	            	} else if (event.keyCode == 40) {
		    			if (!$(this).parent().next().hasClass('bottom')) {
		    				$(this).parent().next().find('a').focus();
		    			}
	                } else if (event.keyCode == 27 || event.keyCode == 37) {
	                	$(this).parent().parent().hide();
	                }
	    		}
	    );
	}
	else{
		$('.banniere-menu .banniere-submenu-item').keydown(
	    		function(event) {
	    			if (event.keyCode == 38 || event.keyCode == 40 || event.keyCode == 37 || event.keyCode == 27) {
	    				event.preventDefault();
		    			event.stopPropagation();
	                }
	    			if (event.keyCode == 38) {
		    			if (!$(this).parent().prev().hasClass('top')) {
		    				$(this).parent().prev().find('a').focus();
		    			}
	            	} else if (event.keyCode == 40) {
		    			if (!$(this).parent().next().hasClass('bottom')) {
		    				$(this).parent().next().find('a').focus();
		    			}
	                } else if (event.keyCode == 27 || event.keyCode == 37) {
	                	$(this).parent().parent().hide();
	                }
	    		}
	    );
	}
       // change style on focus
    $('.banniere-submenu-item').focus(
    		function(event) {
	    		$('.banniere-submenu-item').parent().removeClass('selected');
	    		$(this).parent().addClass('selected');
    		}
    );
    $('.banniere-submenu-item').mouseenter(
    		function(event) {
    			$(this).focus();
    		}
    );
    
    //Laetitia ISBLED Ajout du bouton fermer 
    $('#closePopUpAutresSites').click(
			function(event) {
				$('.banniere-submenu').hide();
			}
	);
}

//FX DESMIDT 		25/11/2010      Ajout variable page afin de determiner si l'on se situ dans bonnes affaires ou autre.
/**
@param page : page where we are to use some function's behavior


*/

function activateVotreCompte(page) {
	if($.browser.webkit) {
		if(page=="BA"){
			//$('#menuCompte').hide();
			$('#closePopUp').click(
					function(event) {
						$('#menuCompte').hide();
						$('#flecheCompteFermeBA:hidden').show();
						$('#votreCompteFermeBA:hidden').show();
					}
			);
			$('#votreCompteFermeBA').click(
					function(event) {
						$('#menuCompte:hidden').show();
						$('#flecheCompteFermeBA:visible').hide();
						$('#votreCompteFermeBA:visible').hide();
					}
			);
		}
		else {

			$('#votreCompteFerme').click(
					function(event) {
						$('#menuCompte:hidden').show();
						$('#flecheCompteFerme:visible').hide();
						$('#votreCompteFerme:visible').hide();
					}
			);
			//$('#menuCompte').hide();
			$('#closePopUp').click(
					function(event) {
						$('#menuCompte').hide();
						$('#flecheCompteFerme:hidden').show();
						$('#votreCompteFerme:hidden').show();
					}
			);
		}
	}
	else {
		if(page=="BA"){
			$('#menuCompte').hide();
			$('#menuCompte,#header').mouseleave(
					function(event) {
						$('#menuCompte').hide();
						$('#flecheCompteFermeBA:hidden').show();
						$('#votreCompteFermeBA:hidden').show();
					}
			);
			$('#votreCompteFermeBA').mouseenter(
					function(event) {
						//on cache la croix utilis? pour ferme la popup vu qu'il suffit de sortir de la popup pour qu'elle se ferme
						$('#closePopUp').hide();
						$('#menuCompte:hidden').show();
						$('#flecheCompteFermeBA:visible').hide();
						$('#votreCompteFermeBA:visible').hide();
					}
			);
		}
		else {

			$('#votreCompteFerme').mouseenter(
					function(event) {
						//on cache la croix utilis? pour ferme la popup vu qu'il suffit de sortir de la popup pour qu'elle se ferme
						$('#closePopUp').hide();
						$('#menuCompte:hidden').show();
						$('#flecheCompteFerme:visible').hide();
						$('#votreCompteFerme:visible').hide();
					}
			);
			$('#menuCompte').hide();
			$('#menuCompte,#header').mouseleave(
					function(event) {
						$('#menuCompte').hide();
						$('#flecheCompteFerme:hidden').show();
						$('#votreCompteFerme:hidden').show();
					}
			);
		}
	}
}

//FX DESMIDT 		25/11/2010      Ajout variable page afin de determiner si l'on se situe dans bonnes affaires ou autre.

function ouvrirPopUpNews() {

		$('#cnt-cm').hide();

		$('.zone-fleche').mouseenter(
				function(event) {
					$('#cnt-cm').show();
					$('#cnt-pop-cn').show();
					$('#fleche_ferme').hide();
					$('#fleche_ouverte').show();

				}
		);
		
		$('#fleche_ferme').mouseenter(
			function(){
				_gaq.push(['_trackEvent', window.location.pathname, 'Recherche - Carnet Mode']);
				_gaq.push(['_trackPageview', '/layer/carnet_mode/liste/']);
				
			}	
		);
}
function hidenews()
{

document.getElementById('cnt-pop-news').style.display="none";
$('#cnt-cm').show();
}

//DEBUT MODIF NVELATI JIRA GLCOM-363
function activateVotrePanier(page, osCsid) {
// FIN MODIF NVELATI
	if(page=="BA"){
		$('#menuPanier').hide();
		$('#milieuPanier,#header').mouseleave(
				function(event) {
					$('#menuPanier').hide();
					$('#flechePanierFermeBA:hidden').show();
					$('#votrePanierFermeBA:hidden').show();
				}
		);
		$('#votrePanierFermeBA,#imagePanierBA,#nbArticlesBA').mouseenter(
				function(event) {
					if ($('#cartLoaded').html() == 'false') {
					    $('#cartLoaded').html('true');
						$('#milieuPanier .content').hide();
						$('#milieuPanier .loader').show();
						$('#menuPanier:hidden').show();
						$('#votrePanierFermeBA:visible').hide();
						$('#flechePanierFermeBA:visible').hide();
						rechargerVotrePanier();
					} else {
						$('#menuPanier:hidden').show();
						$('#votrePanierFermeBA:visible').hide();
						$('#flechePanierFermeBA:visible').hide();
					}
				}
		);
	}
	// DEBUT AJOUT NVELATI JIRA GLCOM-363 ; Si page Cartier
	else if(page=="Cartier"){
		$('#menuPanier').hide();
		$('#milieuPanier,#header').mouseleave(
				function(event) {
					$('#menuPanier').hide();
					$('#flechePanierFerme:hidden').show();
					$('#votrePanierFerme:hidden').show();
				}
		);
		$('#votrePanierFerme,#imagePanier,#nbArticles').mouseenter(
				function(event) {
					if ($('#cartLoaded').html() == 'false') {
					    $('#cartLoaded').html('true');
						$('#milieuPanier .content').hide();
						$('#milieuPanier .loader').show();
						$('#menuPanier:hidden').show();
						$('#votrePanierFerme:visible').hide();
						$('#flechePanierFerme:visible').hide();
						rechargerVotrePanierCartier(osCsid);
				} else {
						$('#menuPanier:hidden').show();
						$('#votrePanierFerme:visible').hide();
						$('#flechePanierFerme:visible').hide();
					}
				}
		);
	}	
	// FIN AJOUT NVELATI

	else{
		$('#menuPanier').hide();
		$('#milieuPanier,#header').mouseleave(
				function(event) {
					$('#menuPanier').hide();
					$('#flechePanierFerme:hidden').show();
					$('#votrePanierFerme:hidden').show();
				}
		);
		$('#votrePanierFerme,#imagePanier,#nbArticles').mouseenter(
				function(event) {
					if ($('#cartLoaded').html() == 'false') {
					    $('#cartLoaded').html('true');
						$('#milieuPanier .content').hide();
						$('#milieuPanier .loader').show();
						$('#menuPanier:hidden').show();
						$('#votrePanierFerme:visible').hide();
						$('#flechePanierFerme:visible').hide();
						rechargerVotrePanier();
					} else {
						$('#menuPanier:hidden').show();
						$('#votrePanierFerme:visible').hide();
						$('#flechePanierFerme:visible').hide();
					}
				}
		);
	}
}

function rechargerVotrePanier() {
	var home = $('#home').val();

	$('#milieuPanier .content').hide();
	$('#milieuPanier .loader').show();

	$.ajax({
		  url: home+"/ajaxPanierHeader.php",
		  cache: false,
		  success: function(html) {
		    $("#milieuPanier .content").html(html);
			$('#milieuPanier .loader').hide();
			$('#milieuPanier .content').show();
			$('#nombreArticleDansPanierUpdated').each( function() { $('#nbArticles').html($(this).html()); } );
		  },
		  error: function() {
			  panierShouldBeReloaded();
		  }
		});
}

//DEBUT AJOUT NVELATI JIRA GLCOM-363
function rechargerVotrePanierCartier(osCsid) {
	$('#milieuPanier .content').hide();
	$('#milieuPanier .loader').show();

	$.ajax({
		  url: "ajaxPanierHeader.php?osCsid="+osCsid,
		  cache: false,
		  success: function(html) {
		    $("#milieuPanier .content").html(html);
			$('#milieuPanier .loader').hide();
			$('#milieuPanier .content').show();
			$('#nombreArticleDansPanierUpdated').each( function() { $('#nbArticles').html($(this).html()); } );
		  },
		  error: function() {
			  panierShouldBeReloaded();
		  }
		});
}
// FIN AJOUT NVELATI

function rechargerVotreCompte() {
	$('#contenuVotreCompte').html($('#loaderVotreCompte').html());
	var home = $('#home').val();
	$.ajax({
		  url: home+"/votreCompteAjax.php",
		  cache: false,
		  success: function(html) {
		    $("#contenuVotreCompte").html(html);
		  }
		});
	//AJOUT ARAGGI JIRA GLCOM-560 & GLCOM-585
	  $.ajax({
		  url: home+"/votreCompteAjax.php",
		  type: "POST",
    	  data: "login=true",
		  cache: false,
		  success: function(html) {
		     $('#infosNom').html(html);
		  }
		});
	  
	//FIN AJOUT ARAGGI JIRA GLCOM-560 & GLCOM-585
	
	//MODIF ARAGGI JIRA GLCOM-612 07/07/11
     //AJOUT ARAGGI JIRA GLCOM-585
     var vente_privee = getCookie('custPrivee');				      
     var home = $('#home').val();
	 if(vente_privee != ''){
		 $.ajax({
			  url: home+"/ventePriveeAjax.php",
			  cache: false,
			  success: function(html) {
			     $('#vente_privee').html('<a href="'+ home +'/fr/vente-privee.htm" title="" id="ephemere">'+html+'</a>');
			  }
			});
	}else{
    	$('#vente_privee').html('');
    }
	//FIN AJOUT ARAGGI JIRA GLCOM-612 07/07/11
    //FIN AJOUT ARAGGI JIRA GLCOM-585
}

//DEBUT AJOUT NVELATI JIRA GLCOM-363
function rechargerVotreCompteCartier(osCsid) {
        $('#contenuVotreCompte').html($('#loaderVotreCompte').html());
        //var home = $('#home').val();
        $.ajax({
                  url: "votreCompteAjax.php?osCsid="+osCsid,
                  cache: false,
                  success: function(html) {
                    $("#contenuVotreCompte").html(html);
                  }
                });
        //AJOUT ARAGGI JIRA GLCOM-560 & GLCOM-585
         /* $.ajax({
                  url: "votreCompteAjax.php?osCsid="+osCsid,
                  type: "POST",
          data: "login=true",
                  cache: false,
                  success: function(html) {
                     $('#infosNom').html(html);
                  }
                });*/

        //FIN AJOUT ARAGGI JIRA GLCOM-560 & GLCOM-585

   //AJOUT ARAGGI JIRA GLCOM-585
   var vente_privee = getCookie('custPrivee');
   //var home = $('#home').val();
   if(vente_privee != ''){
                $('#vente_privee').html('<a href="../fr/vente-privee.htm" title="" id="ephemere">Ventes Priv&eacute;es en cours</a>');
        }else{
        $('#vente_privee').html('');
    }
    //FIN AJOUT ARAGGI JIRA GLCOM-585
}
// FIN AJOUT NVELATI

function actionPanierHeaderEtRechargement(link, refresh_cart) {
	$('#milieuPanier .content').hide();
	$('#milieuPanier .loader').show();
	var current_location = window.location;
	$.ajax({
		url: link,
		cache: false,
		success: function(html) {
			rechargerVotrePanier();
			//AJOUT J.FALCON 11/05/11 GLCOM-431 : rafraichissement de la page panier si suppression d'un article depuis la popup du header
			if(refresh_cart == true){
				window.location.reload();
			}
			//FIN AJOUT J.FALCON 11/05/11 GLCOM-431
		},
		error: function() {
			panierShouldBeReloaded();
		}
	});
}


//DEBUT AJOUT NVELATI JIRA GLCOM-363
function actionPanierHeaderEtRechargementCartier(link, osCsid) {
        $('#milieuPanier .content').hide();
        $('#milieuPanier .loader').show();
        var current_location = window.location;
        $.ajax({
                url: link,
                cache: false,
                success: function(html) {
                        rechargerVotrePanierCartier(osCsid);
                },
                error: function() {
                        panierShouldBeReloaded();
                }
        });
}
// FIN AJOUT NVELATI

function panierShouldBeReloaded() {
	$('#cartLoaded').html('false');
}

/*function activateMenuHomePage() {
	$('.menuTab').mouseenter(
			function (event) {
				var header_offset = $("#header").offset().left;
				$(".tabPane").hide();
				$(this).children('.tabPane').children('.ongletMenu').css('left',$(this).children('.lienOnglet').children('.menuhomeitemimage').offset().left - header_offset);
				$(this).children('.tabPane').show();
			}
	);
	$('.tabPane,#header,.menuTab').mouseleave(
			function(event) {
				$('.tabPane').hide();
			}
	);
}*/

function headerCoherency(page) {
	if(page=="BA"){
		$('.banniere-menu-item-submenu-parent').mouseenter(
				function (event) {
					$('#menuPanier').hide();
					$('#flechePanierFermeBA:hidden').show();
					$('#votrePanierFermeBA:hidden').show();
					$('#menuCompte').hide();
				}
		);
		$('#votrePanierFermeBA,#imagePanierBA,#nbArticlesBA').mouseenter(
				function (event) {
					$('#menuCompte').hide();
					$('.banniere-submenu').hide();
					$('#flecheCompteFermeBA:hidden').show();
					$('#votreCompteFermeBA:hidden').show();
				}
		);
		$('#votreCompteFermeBA').mouseenter(
				function (event) {
					$('#menuPanier').hide();
					$('#flechePanierFermeBA:hidden').show();
					$('#votrePanierFermeBA:hidden').show();
					$('.banniere-submenu').hide();
				}
		);
	}
	else {
		$('.banniere-menu-item-submenu-parent').mouseenter(
				function (event) {
					$('#menuPanier').hide();
					$('#flechePanierFerme:hidden').show();
					$('#votrePanierFerme:hidden').show();
					$('#menuCompte').hide();
					//$('.tabPane').hide();
				}
		);
		$('#votrePanierFerme,#imagePanier,#nbArticles').mouseenter(
				function (event) {
					$('#menuCompte').hide();
					$('.banniere-submenu').hide();
					//$('.tabPane').hide();
					$('#flecheCompteFerme:hidden').show();
					$('#votreCompteFerme:hidden').show();
				}
		);
		$('#votreCompteFerme').mouseenter(
				function (event) {
					$('#menuPanier').hide();
					$('#flechePanierFerme:hidden').show();
					$('#votrePanierFerme:hidden').show();
					$('.banniere-submenu').hide();
					//$('.tabPane').hide();
				}
		);
		$('.menuTab').mouseenter(
				function (event) {
					$('.banniere-submenu').hide();
					$('#menuPanier').hide();
					$('#flechePanierFerme:hidden').show();
					$('#votrePanierFerme:hidden').show();
					$('#menuCompte').hide();
				}
		);
	}
}

// FIN   N.Chapurlat		25/11/2010		Ajout comportement votrePanier, votreCompte et banniere menu home

/* Fonction de rafraichissement des vues, menu des tailles dispos et des quantit?s
 *
 * BriffautSa		20101122
 */

function GetXmlHttpObject()
{
    var objXMLHttp = null;
    if (window.XMLHttpRequest)
        objXMLHttp=new XMLHttpRequest();
    else if (window.ActiveXObject)
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
    return objXMLHttp;
}

/*
 * GLCOM-621 : Cache du site
 * Modification du type "POST" en "GET"
 */
function load_qty(currentPath, prod, coul, max, div){

	$.ajax({
    	  url: currentPath+'ajaxProduitCouleur.php',
    	  type: "GET",
    	  data: 'id_prod='+prod+'&coul='+coul+'&max='+max,
    	  async:false,
    	  success: function(data) {
    		  	$(div + ' .quantite').html(data);
    		  	$(div + ' .selecteurQuantity').each(function () {

        		$(".selecteurQuantity > ul:eq(0)").imgDropDown(
        				{title:"Quantit&eacute;"}
        		);
        		addKeyboardNavToDropDown($(this));  
        	});
    	  }
    	});
		/* MODIFICATION B.OUTTERYCK GLCOM-720 : Modification du comportement du champ quantitÃ© sur la fiche produit*/
		if(max > 1){
			qty_default();
		}
		/* FIN MODIFICATION B.OUTTERYCK GLCOM-720 : Modification du comportement du champ quantitÃ© sur la fiche produit*/
}


/**
 * @author declerckf
 * GLCOM-608 : [PROD] Impossibilit?? de commander un article
 * 
 */
function qty_default()
{	
	//on choix de la taille on met la qtte a 1 par defaut			
	$content  = '<div style="position: relative; width:100%; ">';
	$content += '<a class="listanchor" style="display: block; position: absolute; left: 0; top: 0; width: 100%; height: auto; " href="javascript: void(0); ">&nbsp;</a>';
	$content += '1 </div>';
	$('.selecteurQuantity > .dropdownCell').html($content).attr('value','1');
}

	//FIN AJOUT FDECLERCK GLCOM-608

function load_taille(div, smartyPath, path, produit, ref, code, max, div_qty){
	$(div + ' .cliq').addClass('nocliq');
	$(div + ' .cliq').removeClass('cliq');
	$(div + ' #tailleCouleur'+code).addClass('cliq');
	$(div + ' #tailleCouleur'+code).removeClass('nocliq');
	load_qty(path, produit, code, max, div_qty);
	$(div + ' .dropdownCell').each(function(){
		$('.dropdownCell').removeAttr('value');
	});

	var nomb = $(div + ' .cliq .selecteurSize .dropdownPanel .dropdownOpt').size();
	if(nomb == 1){
		$('.cliq .selecteurSize .dropdownPanel .dropdownOpt:first').click();
	}
	
	var refshort = ref.substring(0,5);
	$('#imgLowQV').removeAttr("src");
	$('#imgLowQV').attr("src", smartyPath + ref + "/" + code + "/VP.jpg");
	$('.vignetteQVOn').each(function(){
		$(this).removeClass('vignetteQVOn');
		$(this).addClass('vignetteQVOff')
	});
	$('.'+code+'_QV').each(function(){			
		$(this).removeClass('vignetteQVOff');
		$(this).addClass('vignetteQVOn')
	});
}

function load_color(smartyPath, path, produit, ref, code, max, div) {

		$('.cliq').addClass('nocliq');
		$('.cliq').removeClass('cliq');
		$('#tailleCouleur'+code).addClass('cliq');
		$('#tailleCouleur'+code).removeClass('nocliq');
		load_qty(path, produit, code, max, div);
		$('.dropdownCell').each(function(){
			$('.dropdownCell').removeAttr('value');
		});

		var nomb = $('.cliq .selecteurSize .dropdownPanel .dropdownOpt').size();
		if(max == 1){
			qty_default();
		}
		if(nomb == 1){
			$('.cliq .selecteurSize .dropdownPanel .dropdownOpt:first').click();
		}

		var refshort = ref.substring(0,5);
		//load_jqzoom(refshort, produit, code);
		$('#imgBig').removeAttr("href");

		$('#imgBig').attr("href", smartyPath + ref + "/" + code + "/ZP.jpg");
		$('#imgLow').removeAttr("src");
		$('#imgLow').attr("src", smartyPath + ref + "/" + code + "/VP.jpg");
		$('.vignetteOn').each(function(){
			$(this).removeClass('vignetteOn');
			$(this).addClass('vignetteOff')
		});
		$('.'+code).each(function(){			
			$(this).removeClass('vignetteOff');
			$(this).addClass('vignetteOn')
		});

}

//FIN AJOUT BriffautSa


// DEBUT AJOUT N. Chapurlat : Extension du img drop down jquery : ajout de la navigation au clavier

function addKeyboardNavToDropDown( jqueryElement ) {
	jqueryElement.find('.dropdownOpt').each(
    		function() {
        		$(this).html('<div style="position: relative; width:100%; "><a href="javascript: void(0); " style="display: block; position: absolute; left: 0; top: 0; width: 100%; height: auto; " class="listanchor">&nbsp;</a>' + $(this).html()+'</div>');
    		}
    );
	jqueryElement.find('.dropdownCell').click(
    		function(event) {
    			$(this).parent().find('.dropdownOpt').removeClass('dropdownOptSelected');
				$(this).parent().find('.dropdownOpt:first').addClass('dropdownOptSelected').find('a.listanchor').focus();
    		}
    );
	jqueryElement.unbind('keydown');
	jqueryElement.find('*').unbind('keydown');
	jqueryElement.find('.dropdownOpt').mouseenter(
			function(event) {
				$(this).parent().find('.dropdownOpt').removeClass('dropdownOptSelected');
				$(this).addClass('dropdownOptSelected').find('a.listanchor').focus();
			}
	);
	jqueryElement.find('.dropdownOpt a.listanchor').keydown(
    		function(event) {
    			if (event.keyCode == 13) {
    				$(this).parents('.dropdownPanel:first').prev('.dropdownCell').attr('value', $(this).parent().attr('value')).html($(this).parent().attr('value'));
    			}
	    			if (event.keyCode == 38) {
   					event.preventDefault();
	    				event.stopPropagation();
		    			if ($(this).parents('.dropdownPanel:first').find('.dropdownOptSelected').length) {
   		    			if ($(this).parents('.dropdownPanel:first').find('.dropdownOptSelected').prev('.dropdownOpt').length) {
		    					$(this).parents('.dropdownPanel:first').find('.dropdownOptSelected').removeClass('dropdownOptSelected').prev('.dropdownOpt').addClass('dropdownOptSelected').find('a.listanchor').focus();
   		    			}
		    			} else {
		    				$(this).parents('.dropdownPanel:first').find('.dropdownOpt:first').addClass('dropdownOptSelected').find('a.listanchor').focus();
		    			}
            	} else if (event.keyCode == 40) {
   					event.preventDefault();
	    				event.stopPropagation();
		    			if ($(this).parents('.dropdownPanel:first').find('.dropdownOptSelected').length) {
   		    			if ($(this).parents('.dropdownPanel:first').find('.dropdownOptSelected').next('.dropdownOpt').length) {
		    					$(this).parents('.dropdownPanel:first').find('.dropdownOptSelected').removeClass('dropdownOptSelected').next('.dropdownOpt').addClass('dropdownOptSelected').find('a.listanchor').focus();
   		    			}
		    			} else {
		    				$(this).parents('.dropdownPanel:first').find('.dropdownOpt:first').addClass('dropdownOptSelected').find('a.listanchor').focus();
		    			}
                }
    		}
    );
}

// FIN Ajout N.Chapurlat

//Function which superpose tab and ongletmenu
function adjustTab(tab) {
	if($.browser.msie && jQuery.browser.version.substr(0,1)=="6"){
		$('.ongletMenu a ').remove();
	}
	else {
		$('.ongletMenu').css('left',$(tab).children('.menuhomeitemimage').offset().left - $('#header').offset().left);
	}
}

//function which load superfish for animation's of menu
function loadSuperfish() {
//there is two differents load of superfish to have compatibility with ie6
if($.browser.msie && jQuery.browser.version.substr(0,1)=="6"){

            jQuery('ul.sf-menu').superfish({autoArrows:    false, hoverClass    : 'sfHover',pathClass:'sf-menu',delay:         1

            });

	}
	else {

            jQuery('ul.sf-menu').superfish({autoArrows:    false });

	}


}

//AJOUT LISBLED 7/03/11
function JustifyPlayerFlash()
{
//Alignement du player flash sur la page en fonction du header.
	$('.PlayerFlash').css('left',$('#conteneur_header').offset().left);
}

// AJOUT J.FALCON 29/03/11 GLCOM-439 : fonction pour changement visuel dans la popup de modif du panier 
function changeProductsImageColor(c){
	var color_split = new Array();
	color_split = c.split('##');
	c = color_split[1];
	$('.popModif .intProduitCoeur img').attr('src',c);
}
// FIN AJOUT J.FALCON 29/03/11 GLCOM-439 : fonction pour changement visuel dans la popup de modif du panier                 



//MODIFICATION A.WAMBRE GL-COM 540 : dans le pop in modifier un article dans le panier, le prix total n'est pas mis ? jour lorsqu'on change la taille de l'article 
function changePriceDisplayedCart(iteration, Ref_Article){

	var qte = $("#selector_" + iteration + "_2 select[id='qte'] > option:selected").val();

	
	$("#selector_" + iteration + "_2 .article_price_on").removeClass('article_price_on');
	$("#selector_" + iteration + "_2 #prices-" + Ref_Article + "-" + qte).addClass('article_price_on');
}

function changePriceDisplayedCartColor(iteration, valeur){
	var color_split = new Array();
	color_split = valeur.split('##');
	valeur = color_split[2];
	changePriceDisplayedCart(iteration, valeur);
}

function changePriceDisplayedCartQte(iteration){
	var i, k;
	var ref;
	
	//On recup?re la r?f?rence courante en fonction de la classe
	ref = $("#selector_" + iteration + "_2 .article_price_on").attr('id');
	ref = ref.split('-')[1];

	//On met a jour le prix
	changePriceDisplayedCart(iteration, ref);
}
//Fin MODIFICATION A.WAMBRE GL-COM 540

