// N.Chapurlat		25/11/2010			Bug Fix IE du ? une virgule en trop
var functions = {
	waitingTime: 5000,
	
	// vide des champs de types text
	clearInputText: function(){
		$('.clearInputText').bind('focus', function(){ $(this).attr('value',''); });
	},
	
	// Met la premiere lettre d'une phrase en majuscule
	ucfirst: function(str){
		str += '';
		var f = str.charAt(0).toUpperCase();
		return f + str.substr(1);
	},
	
	// Met la premiere lettre d'une phrase en minuscule
	lcfirst: function(str){
		str += '';
		var f = str.charAt(0).toLowerCase();
		return f + str.substr(1);
	},
	
	// Maximise un contenu pour qu'il prenne toute la page
	maximize: function(divObj){
		var bodyWith = $('body').width();
		var h = Math.max( (window.innerHeight?window.innerHeight:0), $('body').offsetHeight, $('html').offsetHeight );
		divObj.height( h+'px' );
		divObj.width(bodyWith);
		divObj.show();
	},

	// Fonction qui va ecrire la balise d'appel du flash
	embedFlash: function(flash,id,div,flashvars,width,height){
		var so = new SWFObject(flash, id, "100%", "100%", "8", "#FFFFFF");
		so.addParam("scale", "noscale");
		so.addParam("wmode", "transparent");
		so.addParam("allowFullScreen", "true");
	
		for (var i = 0;i<flashvars.length;i++)
		{
			so.addVariable(flashvars[i].nom, flashvars[i].value);
		}
		so.write(div);
	},
	
	// Retourne la taille du document
	getDocHeight: function(){
		return Math.max(
			( ($.browser.msie && $.browser.version < 8)? 0 : Math.max(document.body.scrollHeight, document.documentElement.scrollHeight) ),
			Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
			Math.max(document.body.clientHeight, document.documentElement.clientHeight)
		);
	},
	
	// Retourne la taille d'un ??l??ment
	getHeight: function(element){
		return element.height() + parseInt(element.css('margin-top')) + parseInt(element.css('margin-bottom')) + parseInt(element.css('padding-top')) + parseInt(element.css('padding-bottom'));
	},
	
	// Cache le logo sur la page Boutique Luxe
	hideLogo: function(){
		var logoTimeOut = setTimeout( "$('#logo.autoHidden').animate({opacity:0}, 500)", functions.waitingTime );
		$('#logo.autoHidden').hover(
			function(){
				clearTimeout(logoTimeOut);
				$(this).animate({opacity:1}, 500);
			},
			function(){
				$(this).stop(true, true);
				$(this).animate({opacity:0}, 500);
			}
		);
	}
};
	
var menus = {
	// Main menu
	mainMenu: function(){
		$('#conteneur_menu > ul > li').hover(function(){
			if( $(this).find('ul').css('display') != 'block' ){
				$('#conteneur_menu > ul > li > ul').hide(1).removeClass('hover');
				$(this).addClass('hover').find('ul').slideDown('fast');
			}
			if($.browser.msie && $.browser.version < 7 && ( $(this).attr('id') == 'femme' || $(this).attr('id') == 'accessoiresOn' || $(this).attr('id') == 'accessoires' || $(this).attr('id') == 'homme' || $(this).attr('id') == 'hommeOn' )){
				$('#produitsDecroissant').css('visibility', 'hidden');
                         

			}
			if($.browser.msie && $.browser.version < 7 && ( $(this).attr('id') == 'bonnesAffaires' || $(this).attr('id') == 'enfant' )){
				$('#quantity').css('visibility', 'hidden');

			}


		},function(){
			$(this).find('ul').slideUp('fast');
			$(this).removeClass('hover');
			if($.browser.msie && $.browser.version < 7){
				$('#produitsDecroissant').css('visibility', 'visible');
				$('#quantity').css('visibility', 'visible');
			}
			$('#conteneur_menu > ul > li > ul').stop(false, true);
		});
	},
	
	// Vertical menu
	verticalMenu: function(){
		$('#smenu > h3').not('.link').each(function(){
			$('#smenu > h3').not('.link').not('.on').next().hide();
			$(this).bind('click', function(){
				$(this).next().slideToggle('slow').siblings("ul:visible").slideUp('fast');
				$(this).toggleClass('on').siblings('#smenu > h3.on').not('.link').removeClass('on');
			});
		});
	},
	
	// Overflow Scroll Effect on vertical menu
	overflowScrollMenu: function(){

		if( $('#conteneurSmenu').prev('h3').not('.notFixed').is('#titreFriseProduit') ){
			var titreMarginTop = $('#titreFriseProduit').height() + parseInt( $('#titreFriseProduit').css('margin-top') ) + parseInt( $('#titreFriseProduit').css('padding-top') );
		}else{
			var titreMarginTop = ( $('#conteneurSmenu').parent().children().eq(0).is('h2') || $('#conteneurSmenu').parent().parent().children().eq(1).is('h2') )? 0 : 43;
		}
		/*$('#conteneurSmenu').css( 'margin-top', titreMarginTop+'px' );*/
		
		var topByDefault = 0;
		var topFromWindow = 136+titreMarginTop;
		$(window).bind('scroll',function(){
			if( typeof( window.pageYOffset ) == 'number' ) {
				//Netscape compliant
				scrOfY = window.pageYOffset;
			} else if( document.body && document.body.scrollTop ) {
				//DOM compliant
				scrOfY = document.body.scrollTop;
			} else if( document.documentElement && document.documentElement.scrollTop ) {
				//IE6 standards compliant mode
				scrOfY = document.documentElement.scrollTop;
			}
			if( scrOfY > topFromWindow ){
				$('#conteneurSmenu').not('.notFixed').animate({top: ( scrOfY - topFromWindow )}, 1 );
			}else if( scrOfY >= 0 &&  parseInt( $('#conteneurSmenu').css('top') ) >= topByDefault ){
				$('#conteneurSmenu').not('.notFixed').animate({top: topByDefault}, 1 );
			}
			
		});
	}
	
	
	
};
var divs={
overflowScrolldiv: function(){

		
		var titreMarginTop = ( $('.popupdefilant').parent().children().eq(0).is('h2') || $('.popupdefilant').parent().parent().children().eq(1).is('h2') )? 0 : 43;
	
		$('.popupdefilant').css( 'margin-top', titreMarginTop+'px' );
		
		var topByDefault = 0;
		var topFromWindow = 136+titreMarginTop;
		$(window).bind('scroll',function(){
			if( typeof( window.pageYOffset ) == 'number' ) {
				//Netscape compliant
				scrOfY = window.pageYOffset;
			} else if( document.body && document.body.scrollTop ) {
				//DOM compliant
				scrOfY = document.body.scrollTop;
			} else if( document.documentElement && document.documentElement.scrollTop ) {
				//IE6 standards compliant mode
				scrOfY = document.documentElement.scrollTop;
			}
			if( scrOfY > topFromWindow ){
				$('.popupdefilant').not('.notFixed').animate({top: ( scrOfY - topFromWindow )}, 1 );
			}else if( scrOfY >= 0 &&  parseInt( $('.popupdefilant').css('top') ) >= topByDefault ){
				$('.popupdefilant').not('.notFixed').animate({top: topByDefault}, 1 );
			}
			var browser=navigator.appName;


			if (navigator.appVersion.indexOf("MSIE") != -1){
			      // bah, IE again, lets downgrade version number
			      version = parseFloat(navigator.appVersion.split("MSIE")[1]);
			}
		if(browser =='Microsoft Internet Explorer' && version==6){
		
			winH = document.body.offsetHeight;
			winH = winH-225;
		// document.getElementById("conteneurSmenu2").style.position ='relative';
		$('.popupdefilant').css( 'position', 'relative' );
	}
			
		});
	}
};
var slides = {
	durationSSProduct: 1000,
	durationSSCard: 500,
	
	// Automatic SlideShow Home 
	runSlideShowHome: function(){
$("#conteneurSlidesHome .slide:first").addClass("actual").show();
		$("#numberspage .numberpage:first").addClass("current");

		if( $('#conteneurSlidesHome').length > 0 ){
			var slideShowInterval = setInterval('slides.SlideShowHome("#conteneurSlidesHome")',3000);
			$('#numberspage').find('.numberpage').each(function(i){
				$(this).click(function(){
					if(!$(this).hasClass('current')){
						$('#conteneurSlidesHome').find('.slide').removeClass('actual');
						$('#numberspage').find('.numberpage').removeClass('current');
						var _block = $('#conteneurSlidesHome').find('.slide')[i];
						$(_block).addClass("actual");
						$(_block).show();
						$(this).addClass('current');
					}
					clearInterval(slideShowInterval);
				});
			});
		}
	},
	// SlideShow Home
	SlideShowHome: function(container){
		var _active = $(container).find('.actual').length ? $(container).find('.actual') : $(container).find('.slide:last');
		var _next =  _active.next().length ? _active.next() : $(container).find('.slide:first');
		_active.addClass('last-actual');
		_next.css({opacity: 0.0})
			.addClass('actual').show()
			.animate({opacity: 1.0}, 1000, function() {
				_active.removeClass('actual last-actual');
			});
		
		var _activePager = $('#numberspage').find('.current').length ? $('#numberspage').find('.current') : $('#numberspage').find('.slide:last');
		var _nextPager =  _activePager.next().length ? _activePager.next() : $('#numberspage').find('.numberpage:first');
		_activePager.removeClass('current');
		_nextPager.addClass('current');
	},
	
	// SlideShow Fiche Produits
	SlideShowProduct: function(){
		$('.diaporama').each(function(){
			$(this).children('.nextDiapo').bind('click', function(){
				var diaporama = $(this).parent().children('.ListDiapos');
				if(!diaporama.find('.current').is(':last-child')){
					var _active = $(this).parent().find('.ListDiapos > .diapo.current');
					var decal = parseInt( _active.width() ) + parseInt( _active.css('margin-right') ) + parseInt( _active.css('margin-left') );
					diaporama.animate({marginLeft: '-='+decal},slides.durationSSProduct);
					$(this).parent().find('.ListDiapos > .diapo').removeClass('current');
					_active.next().addClass('current');
				}
			});
			$(this).children('.prevDiapo').bind('click', function(){
				var diaporama = $(this).parent().children('.ListDiapos');
				if(!diaporama.find('.current').is(':first-child')){
					var _active = $(this).parent().find('.ListDiapos > .diapo.current');
					var decal = parseInt( _active.width() ) + parseInt( _active.css('margin-right') ) + parseInt( _active.css('margin-left') );
					diaporama.animate({marginLeft: '+='+decal},slides.durationSSProduct);
					$(this).parent().find('.ListDiapos > .diapo').removeClass('current');
					_active.prev().addClass('current');
				}
			});
		});
	},
	
	// SlideShow Choix Cartes
	SlideShowCard: function(){
		$('#choisirCartes').find('.picto').children('a').bind('click',function(){
			if( !$(this).parent().parent().hasClass('current') ){
				var indexThis = $('#choisirCartes').children('ul').children('li').index( $(this).parent().parent() );
				slides.SlideShowCardEffect( indexThis );
			}
		});
		
		var _paginationLinks = $('#choisirCartes').next('#pagination');
		var _paginateCardLinks = _paginationLinks.children().children('.paginateCard');
		_paginationLinks.find('a').bind('click',function(){
			if( $(this).hasClass('next') ){
				var indexPage = _paginateCardLinks.index( _paginationLinks.children().children('.current') )+1;
			}else if( $(this).hasClass('prev') ){
				var indexPage = _paginateCardLinks.index( _paginationLinks.children().children('.current') )-1;
			}else{
				var indexPage = _paginateCardLinks.index( $(this) );
			}
			_paginateCardLinks.removeClass('current');
			_paginationLinks.find('.paginateCard').eq( indexPage ).addClass('current');
			slides.SlideShowCardEffect( indexPage );
		});
		
		// Pagination with verticals mini-cards
		var _rightLink = $('#choixCard').not('.blocked').children('li').children('a');
		_rightLink.bind('click',function(){
			var indexCurrent = _rightLink.index( $(this) );
			_rightLink.removeClass('current');
			$(this).addClass('current');
			$('#conteneurSlideShow').animate({marginLeft: '-'+(indexCurrent*475)},{queue:true, duration:slides.durationSSCard});;
		});
	},
	// Effect of SlideShow Choix Cartes
	SlideShowCardEffect: function( newIndexCurrent ){
		var _currentLI = $('#choisirCartes').find('.current');
		var _allLI = $('#choisirCartes').children('ul').children('li');
		
		_currentLI.find('.privilege').stop({gotoEnd: true}).fadeOut('fast').attr('style','');
		_currentLI.find('.picto').find('img').stop({gotoEnd: true}).animate({width: '159', height: '125', marginTop: '0'},{queue:false, duration:slides.durationSSCard, complete:function(){
			_currentLI.removeClass('current');
			_allLI.eq( newIndexCurrent ).addClass('current');
			$('#choisirCartes').children('ul').animate({left: '-'+(newIndexCurrent*178)},{queue:true, duration:slides.durationSSCard}).height('260');
			_allLI.eq( newIndexCurrent ).find('.picto').find('img').animate({width: '300', height: '236', marginTop: '-44'},{queue:true, duration:slides.durationSSCard, complete:function(){
				_allLI.eq( newIndexCurrent ).find('.privilege').show().attr('style','');
				_allLI.not('.current').find('.picto').find('img').css('margin-top','0');
			}})
		}});
		$('#choisirCartes').next('#pagination').find('.paginateCard').removeClass('current').eq( newIndexCurrent ).addClass('current');
		slides.HidePrevNext();
	},
	// Hide next or prev links in pagination
	HidePrevNext: function(){
		var _paginationLinks = $('#choisirCartes').next('#pagination');
		var _paginateCardLinks = _paginationLinks.children().children('.paginateCard');
		var _prevLink = _paginationLinks.find('.prev');
		var _nextLink = _paginationLinks.find('.next');
		
		_prevLink.show();
		_nextLink.show();
		if( _paginateCardLinks.index( _paginationLinks.children().children('.current') ) == 0 ){
			_prevLink.toggle();
		}
		if( _paginateCardLinks.index( _paginationLinks.children().children('.current') ) == _paginateCardLinks.length-1 ){
			_nextLink.toggle();
		}
	}
};

var popIn = {
	overlayID: 'BgPopup',
	overlay2ID: 'BgPopup2',
	menuID: 'conteneur_menu',
	footerID: 'conteneur_footer',
	tunnelClass: 'tunnelOverlay',
	menuZIndex: 13,
	popinZIndex: 30,
	
	// Affiche la pop-in
	open: function(){
		$('.openPopIn').bind('click', function(){
 			popIn.maximizeOverlay();
			var popInDiv = 'Div'+functions.ucfirst($(this).attr('id'));
			$('#'+popInDiv).show().addClass('popInOpened');
			$('#'+popIn.menuID).css('z-index', -1);
			$('#'+popIn.footerID).css('z-index', -1);
			// Si on ouvre une nouvelle popin depuis une autre, on passe cette derni??re derri??re l'overlay.
			if( $(this).offsetParent().hasClass('popInOpened')){
				$(this).offsetParent().hide().removeClass('popInOpened');
			}
			// On cache les select sous IE6
			if($.browser.msie && $.browser.version < 7){
				$('select').css('visibility', 'hidden');
				$('#'+popInDiv).find('select').css('visibility', 'visible');
			}
			$('#'+popInDiv).find('.closedPopIn').bind('click',function(){
				popIn.closed(popInDiv);
			});
		});
	},
	
	// Affiche la pop-in Panier quand on clique sur "j'ach??te"
	openPanier: function(){
		$('#DivPanier').show().addClass('popInOpened');
		$('#'+popIn.menuID).css('z-index', -1);
		$('#'+popIn.footerID).css('z-index', -1);
		// Si on ouvre une nouvelle popin depuis une autre, on passe cette derni??re derri??re l'overlay.
		if( $(this).offsetParent().hasClass('popInOpened')){
			$(this).offsetParent().hide().removeClass('popInOpened');
		}
		// On cache les select sous IE6
		if($.browser.msie && $.browser.version < 7){
			$('select').css('visibility', 'hidden');
			$('#DivPanier').find('select').css('visibility', 'visible');
		}
		$('#DivPanier').find('.closedPopIn').bind('click',function(){
			popIn.closed('DivPanier');
		});
	},
	
	// Ferme la pop-in
	closed: function(container){
		$('#'+popIn.overlayID).hide();
		$('#'+container).hide().removeClass('popInOpened');
		$('#'+popIn.menuID).css('z-index', popIn.menuZIndex);
		$('#'+popIn.footerID).css('z-index', 1);
		// On affiche les select sous IE6
		if($.browser.msie && $.browser.version < 7){
			$('select').css('visibility', 'visible');
		}
	},
	
    // Ferme la pop-in mais on passe un objet, pas un ID pr??d??fini
    closed2: function(container){
        $('#'+popIn.overlayID).hide();
        container.hide().removeClass('popInOpened');
        $('#'+popIn.menuID).css('z-index', popIn.menuZIndex);
        $('#'+popIn.footerID).css('z-index', 1);
        // On affiche les select sous IE6
        if($.browser.msie && $.browser.version < 7){
            $('select').css('visibility', 'visible');
        }
    },
	// Agrandi l'Overlay pour qu'il prenne tout le body
	maximizeOverlay: function(){
		var bodyWith = $('body').width();
		var windowWith = Math.max($(window).width(), bodyWith, ( ( $.browser.msie && $.browser.version < 8 )? 0 : $('html').width() ) );
		var goToLeft = (windowWith - bodyWith)/2;
		$('#'+popIn.overlayID).height(0).width(0).css('margin-left', 0);
		var h = functions.getDocHeight();
		if (goToLeft > 0){
			$('#'+popIn.overlayID).css('margin-left', -goToLeft);
		}		
		$('#'+popIn.overlayID).height(h).width(windowWith).show();
	},
	
	// Redimentionne l'overlay quand on redimensionne la page
	resizeOverlay: function(){
		$(window).bind('resize', this, function() {
			if( $('#'+popIn.overlayID).css('display') == 'block' && !$('#'+popIn.overlayID).hasClass(popIn.tunnelClass) ){
				popIn.maximizeOverlay();
			}else if( $('#'+popIn.overlayID).css('display') == 'block' && $('#'+popIn.overlayID).hasClass(popIn.tunnelClass) ){
				$('#'+popIn.overlay2ID).remove();
				popIn.tunnelOverlay();
			}
		});
	},
	
	tunnelOverlay: function(){
		var overlay = $('#'+popIn.overlayID);
		/*var headerHeight = Math.max(
			functions.getHeight( $('#header').children('#logo') ),
			functions.getHeight( $('#header').children('#banniereHome') ),
			functions.getHeight( $('#header').children('#compte') )
		);
		headerHeight = headerHeight + functions.getHeight( $('#conteneur_menu') ) + functions.getHeight( $('#Nav') );*/
		var headerHeight = $('#header').outerHeight(true);
		if ($('#conteneur_headerBA').outerHeight(true)) {
			headerHeight = Math.max( headerHeight , $('#conteneur_headerBA').outerHeight(true) );
		}
		var globalHeight = Math.max(
				$('#global').outerHeight(true),
				$('#global').children().eq(0).outerHeight(true),
				$('#global').children().eq(1).outerHeight(true)
		);
		if ($('#div_btn_retour').outerHeight(true)) {
			globalHeight += $('#div_btn_retour').outerHeight(true);
		}
		var topPosition = headerHeight + globalHeight + parseInt( $('#conteneur_footer').css('margin-top') );
		var h = functions.getDocHeight();
		var h2 = headerHeight + globalHeight + $('#conteneur_footer').outerHeight(true);
		var footerHeight = $('#conteneur_footer').outerHeight(true);
		footerHeight = footerHeight + ((h > h2)? h - h2 : 0) - parseInt( $('#conteneur_footer').css('margin-top') ); 
		popIn.maximizeOverlay();
		$('#'+popIn.menuID).css('z-index', -1);
		$('#'+popIn.footerID).css('z-index', -1);
		overlay.addClass(popIn.tunnelClass);
		overlay.clone(true).insertAfter('#'+popIn.overlayID).attr('id',popIn.overlay2ID);
		overlay.height(headerHeight+'px');
		var overlay2 = $('#'+popIn.overlay2ID);
		//AJOUT ARAGGI 31/05/11 GLCOM-618
		topPosition = $('#conteneur_footer').offset().top;
		//FIN AJOUT ARAGGI 31/05/11 GLCOM-618
		overlay2.css('top',topPosition+'px');
		overlay2.height(footerHeight+'px');
	}
};

var accordion = {
	open: function(){
		$('.open').each(function(){
			$(this).bind('click', function(){
				$('.accordion > li').removeClass('visible');
				$(this).parent().addClass('visible');
			});
		});
	},
	
	close: function(){
		$('.close').each(function(){
			$(this).bind('click', function(){
				$('.accordion > li').removeClass('visible');
			});
		});
	}
};

var callAjax = {
	// Appel Ajax quand on clique sur "j'ach??te"
	buy: function(){
		$('.openPanier').bind('click', function(){
			$.ajax({
				type: 'GET',
//				url: 'http://gl-recette.cyo.fr/index.php',
				url: 'index.php',
				data: 'nv=panier_deroulant&action=add&language=fr',
				beforeSend: function() {
					popIn.maximizeOverlay();
				},
				success: function(msg) {
					popIn.openPanier();
				}
			});
		});
	}
};

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
	    c_start=document.cookie.indexOf(c_name + "=");
	    if (c_start!=-1) { 
	    	c_start=c_start + c_name.length+1; 
	    	c_end=document.cookie.indexOf(";",c_start);
	    	if (c_end==-1) c_end=document.cookie.length;
	    	return unescape(document.cookie.substring(c_start,c_end));
	    } 
	}
	return "";
}

/* fonction qui affiche le nom et premom et les infos panier de l'utilisateur dans le header ?? partir des cookies */
//MODIF ARAGGI JIRA GLCOM560 110516
$(document).ready(function() {
    displayUserCookieData();
});
function displayUserCookieData() {
	//var typo3 = getCookie('fe_typo_user');
	//var typo3check = getCookie('user[sessiontypo]');
/*
	if (typo3 == typo3check) {
		var nom    = getCookie('user[nom]');
		var prenom = getCookie('user[prenom]');
		if (prenom != null && prenom != ''){
		  if ( document.getElementById('headerNom') ){
		  	document.getElementById('headerNom').innerHTML = prenom +  '&nbsp;' + nom;
	        document.getElementById('disconnect').innerHTML = '<a href="/compte/compte.html?no_cache=1&action=disconnect">(D&eacute;connexion)</a>';
	        document.getElementById('headerNom').style.display = 'inline';
		  }
		}		
	}
*/
	var nb_article = getCookie('nb_article');
	//var text_article = getCookie('user[text_article]');
	//var total_panier = getCookie('user[total_panier]');
	
	if (nb_article != '') {
	    $('#nbArticles').html(nb_article);
	    //panierShouldBeReloaded();
    }
}
//FIN MODIF ARAGGI JIRA GLCOM560 110516

$(document).ready(function (){
	menus.mainMenu();
	menus.verticalMenu();
	menus.overflowScrollMenu();
	divs.overflowScrolldiv();
	functions.clearInputText();
	functions.hideLogo();
	slides.runSlideShowHome();
	slides.SlideShowProduct();
	slides.SlideShowCard();
	slides.HidePrevNext();
	popIn.open();
	popIn.resizeOverlay();
	accordion.open();
	accordion.close();
	//callAjax.buy();
	functions.hideLogo();
});



function eraseCookie(name) {
	createCookie(name,"",-1);
}



//Debut Ajout FX GL-COM1 fonctions js permettant de rediriger vers une autre page
function chgpageNosMarques(formulaire) {
	var lienDest
	if (formulaire.lstNosMarques.selectedIndex != 0){
		
		lienDest = formulaire.lstNosMarques.options[formulaire.lstNosMarques.selectedIndex].value;
		
		location.href = lienDest;
	}
}
		
function chgpageMeilleursOffres(formulaire) {
	var lienDest
	
	if (formulaire.lstMeilleuresOffres.selectedIndex != 0){
		
		lienDest = formulaire.lstMeilleuresOffres.options[formulaire.lstMeilleuresOffres.selectedIndex].value;
		
		location.href = lienDest;
	}
}
function chgpageGdesTailles(formulaire) {
	var lienDest
	
	if (formulaire.lstGdesTailles.selectedIndex != 0){
		
		lienDest = formulaire.lstGdesTailles.options[formulaire.lstGdesTailles.selectedIndex].value;
		
		location.href = lienDest;
	}
}
//Fin Ajout FX
//AJOUT J.FALCON 03/12/2010 GLCOM 1 => verification de la categorie et marque selectionnee (page de non resultat)
function verifSelectedBrand(){
	var selectElmt = document.getElementById("lstMarques");
	var brand_value = selectElmt.options[selectElmt.selectedIndex].value;
	var brand_text = selectElmt.options[selectElmt.selectedIndex].innerHTML;
	
	if(brand_value == 0){
		document.getElementById("errorMsg").innerHTML = "Veuillez choisir une marque";
		document.getElementById('errorMsg').style.display='block';
	}
	else{
		var selectElmt = document.getElementById("lstCategories");
		var cat_value = selectElmt.options[selectElmt.selectedIndex].value;
		var cat_text = selectElmt.options[selectElmt.selectedIndex].innerHTML;
		if(cat_value == 0){
			window.location = "/index.php?search2="+brand_text;
		}
		else{
			window.location = "/index.php?search2="+brand_text+"&language=fr&sousFamille="+cat_text;
		}
	}	
}
function verifSelectedCategory(){
	var selectElmt = document.getElementById("lstCategories");
	var cat_value = selectElmt.options[selectElmt.selectedIndex].value;
	var cat_text = selectElmt.options[selectElmt.selectedIndex].innerHTML;
	
	if(cat_value == 0){
		document.getElementById("errorMsg").innerHTML = "Veuillez choisir une cat&eacute;gorie";
		document.getElementById('errorMsg').style.display='block';
		location.href = lienDest;
	}
	else{
		var selectElmt = document.getElementById("lstMarques");
		var brand_value = selectElmt.options[selectElmt.selectedIndex].value;
		var brand_text = selectElmt.options[selectElmt.selectedIndex].innerHTML;
		if(brand_value == 0){
			window.location = "/index.php?search2="+cat_text;
		}
		else{
			window.location = "/index.php?search2="+brand_text+"&language=fr&sousFamille="+cat_text;
		}
	}
}
function chgpageGdesTailles(formulaire) {
	var lienDest
	
	if (formulaire.lstGdesTailles.selectedIndex != 0){
		
		lienDest = formulaire.lstGdesTailles.options[formulaire.lstGdesTailles.selectedIndex].value;
		
		location.href = lienDest;
	}
	else{
		document.categories_form.search2.value = cat_text;
		return true;
	}	
	return false;
}

function changeCategoriesList(brand_id){
	$.ajax({
		type: "GET",
		url: "ajax_tepspec_get_categories_list.php",
		data: "brand="+brand_id, 
		success:function(html){
			afficher(html);
		},
		error:function(XMLHttpRequest, textStatus, errorThrows){ // erreur durant la requete
		}
	});

}

function afficher(donnees){
	$("#divSelectCategorie").empty();
	$("#divSelectCategorie").append(donnees);
}
//FIN AJOUT J.FALCON 03/12/2010

//AJOUT ARAGGI JIRA 334 22/02/11
function justifyMenu(){
	var actualWidth = $('#menuHomePage').width()-1;
	var totalLIWidth = 0;
	
	// Calculate total width of list items
	var lis = $('#menuHomePage > li');
	
	lis.each(function(){
	    totalLIWidth += $(this).width();
	});
	// Work out how much padding we need
	var requiredPadding = Math.round(((actualWidth-totalLIWidth)/lis.length)/2);
	
	// To account for rounding errors, the error is going to be forced into the first tab.
	var roundingErrorFix = ((requiredPadding*lis.length*2)+totalLIWidth-actualWidth)/2;
	
	// Apply padding to list items
	var isFirst = true;
	lis.each(function() {
	    if(isFirst) {
	        $(this).css('padding-left',requiredPadding-roundingErrorFix+'px')
	                .css('padding-right',requiredPadding-roundingErrorFix+'px');
	        $(this).children('ul').children('.sfHover').children('.tabPane').children('.ongletMenu')
	        		.css('padding-left',requiredPadding-roundingErrorFix+'px')
	                .css('padding-right',requiredPadding-roundingErrorFix+'px')
	                .css('left',$(this).offset().left - $('#header').offset().left)
	                .css('width',$(this).width());  
	        isFirst = false;
	    }
	    else {
	        $(this).css('padding-left',requiredPadding+'px')
	                .css('padding-right',requiredPadding+'px');
	        $(this).children('ul').children('.sfHover').children('.tabPane').children('.ongletMenu').css('padding-left',requiredPadding+'px')
	                .css('padding-right',requiredPadding+'px')
	                .css('left',$(this).offset().left - $('#header').offset().left)
	                .css('width',$(this).width());
	    }
	                
	});
	lis.last().css('padding-right',requiredPadding+1+'px');
}
//FIN AJOUT ARAGGI JIRA 334 22/02/11

//AJOUT A.WAMBRE 06/04/11 GLCOM-438 : taille par d?faut de la nouvelle couleur pr?selectionn?e
/**
 * Affiche l'erreur dans le cas o? le formulaire n'est pas valide
 */
function verifPopModifShoppingCart(row){
	
	var selectTaille = document.getElementById("popModifSelectTaille_" + row);
	var labelTaille = document.getElementById("popModifLabelTaille_" + row);
	var errorMessage = document.getElementById("popErrorPanierSaisieTaille_" +row);
	
	if (selectTaille.value == -1){
		//si l'option par defaut ('Taille') est s?lectionn?
		labelTaille.style.color = '#C10435';
		errorMessage.style.visibility = 'visible';
		errorMessage.style.height = "30px";
	}
	else {
		labelTaille.style.color = 'black';
		errorMessage.style.visibility = 'hidden';
		errorMessage.style.height = "0px";
		
		//Si la date est valide, on soumet le formulaire
		document.getElementById('selector_' + row + '_2').submit();
	}
}
//FIN AJOUT A.WAMBRE 27/04/11 GLCOM-438 : taille par d?faut de la nouvelle couleur pr?selectionn?e

//AJOUT A.WAMBRE 06/04/11 GLCOM-476 : Lorsque le mode de livraison change entre la date de prise de commande et la date de livraison, on facture au client les frais du nouveau mode de livraison
function desactiveBoutonValiderCommande(){
	inputValider = document.getElementById("imgRight").onclick="";
}
//FIN AJOUT A.WAMBRE 27/04/11 GLCOM-476 : Lorsque le mode de livraison change entre la date de prise de commande et la date de livraison, on facture au client les frais du nouveau mode de livraison



// DEBUT AJOUT NVELATI JIRA GLCOM-363 : implémentation de la fonction d'ajout au panier de Contenix
// Fonction de retour du code pays pour Contenix
function InvokeAddToBasket(productIdentifier, countryCode) {
	
	var stringData = 'prod='+ productIdentifier +'&quantity=1&action=add&osCsid='+document.getElementById('osCsid').value;
	var stringUrl = "/ajaxAddToCartFromEcorner.php";

//	if(document.getElementById("ajoutpanier").value == '1') {

//		document.getElementById("ajoutpanier").value = '0';

		$.ajax({
			type: "GET",
			url: stringUrl,
			data: stringData,
			success: function(returnedValues){
			
				eval(returnedValues);
				if(ajaxReturnValues['status']=="OK"){
	
					rechargerVotrePanierCartier(document.getElementById('osCsid').value);
					$('#errorMessage').html('');
	
					if (document.getElementById('conteneur_headerBA')){
	
						if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion <=6){
	
							$('#imagePanierBA').mouseover().delay(4000).queue(function(){
								$(this).mouseleave();
							});
						}
						else{
	
							function cartWrapper(){
								document.getElementById('flechePanierFermeBA').style.display = 'none';
								document.getElementById('votrePanierFermeBA').style.display = 'none';
								document.getElementById('menuPanier').style.display = 'block';
	
							};
	
							function cartHider(){
								document.getElementById('flechePanierFermeBA').style.display = 'block';
								document.getElementById('votrePanierFermeBA').style.display = 'block';
								document.getElementById('menuPanier').style.display = 'none';
//								document.getElementById('ajoutpanier').value = '1';
							};
	
							cartWrapper();
							setTimeout(cartHider, 4000);
						}
					}else{
						if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion <=6){
	
							$('#imagePanier').mouseover().delay(4000).queue(function(){
								$(this).mouseleave();
							});
						}
						else{
	
							function cartWrapper(){
								document.getElementById('flechePanierFerme').style.display = 'none';
								document.getElementById('votrePanierFerme').style.display = 'none';
								document.getElementById('menuPanier').style.display = 'block';
	
							};
	
							function cartHider(){
								document.getElementById('flechePanierFerme').style.display = 'block';
								document.getElementById('votrePanierFerme').style.display = 'block';
								document.getElementById('menuPanier').style.display = 'none';
//								document.getElementById('ajoutpanier').value = '1';
							};
	
							cartWrapper();
							setTimeout(cartHider, 4000);
						}
	
	
					}
	
				}else{
	
					if( ajaxReturnValues['status']=="NOK" ){
						
						alert(ajaxReturnValues['error_text']);
//						document.getElementById('ajoutpanier').value = '1';
					
					}
				}
			},
			error: ""
		});	
//	}
}

function GetCountryCode() {
        return 'FR';
}

function fromCartier() {
	var stringUrl = '/fromCartier.php';
	var stringData = 'osCsid=' + document.getElementById('osCsid').value;
	 $.ajax({
                        type: "POST",
                        url: stringUrl,
			data: stringData,
			async:false
	});
}

// FIN AJOUT NVELATI


