﻿$(function(){
	popupCDN();
	//popupAide();
	popupPassOublie();
	identificationInput();	
	popupCoordonnees();
	popupCoordonneesModif();
	popupCoordonneesConfirm();
	popupMotDePasse();	
	/*popupInscription();*/
	popupPolInter();
	popupContact();
	activeLettre();
	closePopup();
	//closeInscription();
	coachingSafari();
	liensSelect();
	popupPrintRecette();
	impressionRette();
	rechercheResetInput();
	//focusFirst();
	show('1');
	//popup bons
	initPopins();
	setPrintPopinBon();
	initRecipeSearchInterface();
	resizeTableResult();
	AfficheItemEngagementQualite();
	selectAllBr();
	validateFormAlert();
	
	if($('.liste2').length){
		AddList();
	}
	
})



/***function show panel****/
function initRecipeSearchInterface(){

    //Difficulty and cost for LIBELLES
    $('input[name=ctl00$MainContent$nameDiff]:radio').click(
      function ()
      {
        $("#ctl00_MainContent_difficultyHdn").attr("value", $(this).attr("value"));
      });
    $('input[name=ctl00$MainContent$nameCost]:radio').click(
      function ()
      {
        $("#ctl00_MainContent_costHdn").attr("value", $(this).attr("value"));
      });
      
    
    $('input[name=ctl00$MainContent$typeDiff]:radio').click(
      function ()
      {
        $("#ctl00_MainContent_difficultyHdn").attr("value", $(this).attr("value"));
      });
      
    $('input[name=ctl00$MainContent$typeCout]:radio').click(
      function ()
      {
        $("#ctl00_MainContent_costHdn").attr("value", $(this).attr("value"));
      });
      
    //Difficulty and cost for PRODUCTS
    $('input[name=ctl00$MainContent$produitDiff]:radio').click(
      function ()
      {
        $("#ctl00_MainContent_difficultyHdn").attr("value", $(this).attr("value"));
      });
    $('input[name=ctl00$MainContent$produitCout]:radio').click(
      function ()
      {
        $("#ctl00_MainContent_costHdn").attr("value", $(this).attr("value"));
      });
      
    // categorie link
//    $('label a').unbind('click');
//    $('label a').bind('click', function(){return false;});
    //End radio
    
    //Tabs
		$('.partLinkTop ul li a').unbind('click');
		$('.partLinkTop ul li a').bind('click',function(){
		
				//$('.resultSearch').hide();
				var index = $('.partLinkTop ul li').index($(this).parents('li'));
			  $('.partLinkTop ul li').removeClass('on');
			  $(this).parent().addClass('on');
			  $('.items').hide();		
				
			  $('#ctl00_MainContent_item'+(index+1)).show();
			  
			  switch (index)
			  {
			    case 0 : 
			      $("#ctl00_MainContent_modeHdn").attr("value","LIBELLES");
			      break;
			    case 1 : 
			      $("#ctl00_MainContent_modeHdn").attr("value","CATEGORIE");
			      break;
			    case 2 : 
			      $("#ctl00_MainContent_modeHdn").attr("value","PRODUIT");
			      break;
			  }
			resizeTableResult();	  
			return false;
		});
		//End Tabs
		
		
		//showPartAffiner
		$('.partContentOption .blockTop .partSearchBtn a').unbind('click');
		$('.partContentOption .blockTop .partSearchBtn a').bind('click',function(){
				if ($(this).hasClass("rechAffine_of")){
						$(this).removeClass();
						$(this).addClass('rechAffine_on');
						 $(this).parent().next().show();
						/* $(".resultSearch .resultTable").css("height","377px");
						  $("#ctl00_MainContent_item1 .resultSearch p.btnALL .linkAllRecette").css("margin-top","105px");
						 $("#ctl00_MainContent_item3 .resultSearch p.btnALL .linkAllRecette").css("margin-top","0px");
						 $("#ctl00_MainContent_item2 .resultSearch p.btnALL .linkAllRecette").css("margin-top","20px"); */
						 if( $(this).parent().parent().attr("id")=="ctl00_MainContent_item3"){
							$(".resultSearch .resultTable").css("height","295px");
						 }else if($(this).parent().parent().attr("id")=="ctl00_MainContent_item2"){
							$(".resultSearch .resultTable").css("height","306px");
						 }else if($(this).parent().parent().attr("id")=="ctl00_MainContent_item1"){
							$(".resultSearch .resultTable").css("height","420px");
						 }
						
				}else if($(this).hasClass("rechAffine_on")){
						$(this).removeClass();
						$(this).addClass('rechAffine_of');
						 $(this).parent().next().hide();
						/*  $(".resultSearch .resultTable").css("height","516px");
						 $(".resultSearch p.btnALL .linkAllRecette").css("margin-top","0px"); */
						  if($(this).parent().parent().attr("id")=="ctl00_MainContent_item3"){
							$(".resultSearch .resultTable").css("height","496px");
						 }else if($(this).parent().parent().attr("id")=="ctl00_MainContent_item2"){
							$(".resultSearch .resultTable").css("height","537px");
						 }else if($(this).parent().parent().attr("id")=="ctl00_MainContent_item1"){
							$(".resultSearch .resultTable").css("height","622px");
						 }
						 
				}
				return false;        
		});
		//showPartAffiner
		
		
		//Product Click
		$('.product a').unbind('click');
				$('.product a').bind('click',function(){
						if($('.product a.selected').length){
								 var srcSel=$('.product a.selected').find("img").attr("src");
				          var cheminSelc=srcSel.substring(0,srcSel.length-5);
				
				if(srcSel.substring(srcSel.length-5,srcSel.length)=="n.gif"){
						
					$('.product a.selected').find("img").attr("src",cheminSelc+"f.gif");
					$('.product a.selected').removeClass("selected");
					// $('.resultSearch').hide();
				}
						}
				var src=$(this).find("img").attr("src");
				var chemin=src.substring(0,src.length-5);
				
				if(src.substring(src.length-5,src.length)=="f.gif"){
						
					$(this).find("img").attr("src",chemin+"n.gif");
					$(this).addClass("selected");
				//	 $('.resultSearch').show();
				}
				//Moteur-Recettes-Resultats.aspx?critName0=PRODUIT&critVal0=NESTLE DESSERT&critDir0=PLUS
				var product = $(this).attr("href");
				var critVal = "critVal0=";
				product = product.substring(product.search(critVal)+critVal.length,product.search("&critDir0"));
				$("#ctl00_MainContent_selectedProductHdn").attr("value",product);
						return false;        
				});
		//Search		
    $('.btnSearch').unbind('click');
		$('.btnSearch').bind('click',function(){
			if($('#ctl00_MainContent_produit_caramel').length){
				var index = $('.partLinkTop ul li').index($('.partLinkTop ul li.on'));
				if(index==2 && $('#ctl00_MainContent_produit_caramel').hasClass('selected')){
					document.location = '/actualites/TabletteChocolatcaramel.aspx';
				}else{
					formCenterSearching();
				}				
			}
		});
		//End Submit
}

function formCenterSearching(){

var q = "critName0=CRITERIA-NAME&critVal0=CRITERIA-VALUE&critDir0=PLUS&critName1=DIFFICULTE&critVal1=DIFFICULTY&critDir1=PLUS&critName2=COUT&critVal2=COST&critDir2=PLUS";
		 var diff = $("#ctl00_MainContent_difficultyHdn").val();
		 var cost = $("#ctl00_MainContent_costHdn").val();
		 var mode = $("#ctl00_MainContent_modeHdn").val();
		 var regDiff = "DIFFICULTY"; //Or use a reg ex
		 var regCost = "COST";//Or use a regexp ,"g");
		 var regMode = "CRITERIA-NAME";
		 var regModeValue ="CRITERIA-VALUE";
		 q =  q.replace(regDiff,diff).replace(regCost,cost).replace(regMode,mode);
		 switch (mode)
		 {
		    default: //including "LIBELLES"
		      var value = $("#ctl00_MainContent_SearchedName").val(); 
		      q = q.replace(regModeValue,value);
		      break;
		    case "CATEGORIE" : 
		      var value = $('input[name=ctl00$MainContent$types]:checked').val();
		       q = q.replace(regModeValue,value);
		       break;
		    case "PRODUIT" : 
		       var value = $("#ctl00_MainContent_selectedProductHdn").val(); 
		       q = q.replace(regModeValue,value);
		       break;
		      
		 }
		 
		 var regModeValue ="";
		 q =  q.replace(regDiff,diff).replace(regCost,cost);
		 document.location.search = q.replace(regDiff,diff).replace(regCost,cost);
}


//focus sur le premier input
function focusFirst(){
		var tabInput = document.getElementsByTagName('input')
		if (tabInput){
				for (var i = 0; i < tabInput.length; i++){
						if(tabInput[i].type != "hidden" && tabInput[i].type == "text"){
								tabInput[i].focus();
								//tabInput[i].value = "";
								break;
						}
				}
		}
}
//---- reset champs textes identifecation 
function identificationInput(){

	$('.inputsMail').each(function(i,obj){
		$($('#top .spaceBloc input')[1]).css("background","#ffffff url(/App_Themes/general/img/Refonte/tt_pass.gif) no-repeat scroll 4px 5px");
		$($('#top .spaceBloc input')[0]).value="Votre email";
		$($('#top .spaceBloc input')[1]).bind('focus',function(){
			$(this).val('');
			$($('#top .spaceBloc input')[1]).removeAttr("style");
		})
		
		$(this).bind('blur',function(){
			if(i==0 && this.value == ""){				
				this.value="Votre email";				
			}else if(i==1 && this.value == ""){
				$($('#top .spaceBloc input')[1]).css("background","#ffffff url(/App_Themes/general/img/Refonte/tt_pass.gif) no-repeat scroll 4px 5px");
			}
		})
		
		
	})
}
// reset champs textes
function rechercheResetInput(){
		var loginEmail = "Votre adresse e-mail";
		//var loginPassword = "Mot de passe";
	 var loginPassword = "";
		var inputTab = document.getElementsByTagName('input');

		if(inputTab){
				var inputTabText = new Array();
				var j = 0;
				for (var i = 0; i < inputTab.length; i++){
						if(inputTab[i].value == loginEmail || inputTab[i].type == "password"){
								inputTabText[j] = inputTab[i];
								j++;
						}
				}
		}
		for (var i = 0; i < inputTabText.length; i++){
				inputTabText[i].onfocus = function(){
						if(this.value == loginEmail || this.value == loginPassword){
								this.value = "";
						}
				}
				inputTabText[i].onblur = function(){
						if(this.value == ""){
								if(this.type == "text"){
										this.value = loginEmail;
								}else{
										this.value = loginPassword;
								}
						}
				}
		}
}
var checkeds=true;
function selectAllBr(){	
	
	var aa= document.getElementById('aspnetForm');
	 if (checkeds == false)
          {
           checkeds = true
          }
        else
          {
          checkeds = false
          }
	for (var i =0; i < aa.elements.length; i++) 
	{
	 aa.elements[i].checked = checkeds;
	}
}

// feuille d'impression
function impressionRette(){
		var pageImprim = document.getElementById('popupImpression');
		if(pageImprim){
			 document.getElementById('popupImpression').onload = window.print(); 
		}
}
// Ouvertures de popups //

function popupMotDePasse(){
	var linkPopup = document.getElementById('popupMDP');
	if (linkPopup){
			linkPopup.onclick = function(){
		window.open( this.href , '' , 'top=' + ((screen.height/2)-161.5) + ' , left=' + ((screen.width/2)-225) + ' , width=450 , height=323 , scrollbars=no' );
		return false;
		}
	}
	var linkPopup2 = document.getElementById('popupMDPNav');
	if (linkPopup2){
			linkPopup2.onclick = function(){
		window.open( this.href , '' , 'top=' + ((screen.height/2)-161.5) + ' , left=' + ((screen.width/2)-225) + ' , width=450 , height=323 , scrollbars=no' );
		return false;
		}
	}
	
}
function popupCDN(){
	$("#popupMCDonnees").unbind()
	$("#popupMCDonnees").bind("click", function(){
			window.open( '/LesCodes/MesCoordonnees.aspx' , '' , 'top=' + ((screen.height/2)-161.5) + ' , left=' + ((screen.width/2)-225) + ' , width=450 , height=510 , scrollbars=no' );
			return false;
	 });
}
function popupCoordonnees(){
		var linkPopupCoordonnes = document.getElementById('btCoordonnees');
		
	if (linkPopupCoordonnes){
			var linkOpenPopCoor = linkPopupCoordonnes.href;
			linkPopupCoordonnes.onclick = function (){
					openPopupBig(linkOpenPopCoor);
					return false;
			}
	}
}
function popupPassOublie(){
		var linkPopupCoordonnes = document.getElementById('passOublie');
	if (linkPopupCoordonnes){
			var linkOpenPopCoor = linkPopupCoordonnes.href;
			linkPopupCoordonnes.onclick = function (){
					openPopupPassOublie(linkOpenPopCoor);
					return false;
			}
	}
}
function popupCoordonneesModif(){
		var linkPopupCoordonnesModif = document.getElementById('btCoordonneesModif');
	if (linkPopupCoordonnesModif){
			var linkOpenPopCoorModif = linkPopupCoordonnesModif.href;
			linkPopupCoordonnesModif.onclick = function (){
					window.close();
					openPopupBig(linkOpenPopCoorModif);
					return false;
			}
	}
}
function popupCoordonneesConfirm(){
		var confirmCoord = document.getElementById("idBodyConfirmCoord");
		if(confirmCoord){
				window.resizeBy(0,-187);
		}
				
}
function popupAide(){
	var linkPopupAide = document.getElementById('btAide');
	var linkPopupAideBis = document.getElementById('popupAide');
	if (linkPopupAide){
			var linkOpenPop = linkPopupAide.href;
			linkPopupAide.onclick = function (){
					openPopupBigScroll(linkOpenPop);
					return false;
			}
	}
	if (linkPopupAideBis){
			var linkOpenPopBis = linkPopupAideBis.href;
			linkPopupAideBis.onclick = function (){
					openPopupBigScroll(linkOpenPopBis);
					return false;
			}
	}
}
function popupPolInter(){
		var linkPopupPolInter = document.getElementById('btPolInter');
	 var linkPopupPolInterBis = document.getElementById('btPolInterBis');
	 if (linkPopupPolInter){
			var linkOpenPolInter = linkPopupPolInter.href;
			linkPopupPolInter.onclick = function (){
					openPopupBig(linkOpenPolInter);
					return false;
			}
	}
	if (linkPopupPolInterBis){
			var linkOpenPolInterBis = linkPopupPolInterBis.href;
			linkPopupPolInterBis.onclick = function (){
					openPopupBig(linkOpenPolInterBis);
					return false;
			}
	}
}
function popupContact(){
		var linkPopupContact = document.getElementById('btContact');
	 var linkPopupContactBis = document.getElementById('btContactBis');
	 if (linkPopupContact){
			var linkOpenContact = linkPopupContact.href;
			linkPopupContact.onclick = function (){
					openPopupBig(linkOpenContact);
					return false;
			}
	}
	if(linkPopupContactBis){
		var linkOpenContactBis = linkPopupContactBis.href;
			linkPopupContactBis.onclick = function (){
					openPopupBig(linkOpenContactBis);
					return false;
		 }
	}
}

function popupPrintRecette(){
		var listePrintRecette = document.getElementById('btBottomRecetteDetail');
		if (listePrintRecette){
				var tabLinkRecette = listePrintRecette.getElementsByTagName('a');
				tabLinkRecette[0].onclick = function(){
						openPopupImprimScroll(this.href);
						return false;
				}
		}
}

function openPopupImprimScroll(linkDestiPop){
		window.open( linkDestiPop , '' , 'top=' + ((screen.height/2)-255) + ' , left=' + ((screen.width/2)-213) + ' , width=436 , height=510 , scrollbars=yes' );
	return false;
}

function openPopupBigfullTop(linkDestiPop){
		window.open( linkDestiPop , '' , 'top=0 , left=' + ((screen.width/2)-234.5) + ' , width=467 , height='+ (screen.height) +' , scrollbars=yes' );
	return false;
}

function openPopupBigScroll(linkDestiPop){
		window.open( linkDestiPop , '' , 'top=' + ((screen.height/2)-255) + ' , left=' + ((screen.width/2)-234.5) + ' , width=467 , height=510 , scrollbars=yes' );
	return false;
}

function openPopupBig(linkDestiPop){
		window.open( linkDestiPop , '' , 'top=' + ((screen.height/2)-255) + ' , left=' + ((screen.width/2)-225) + ' , width=450 , height=510 , scrollbars=no' );
	return false;
}
function openPopupPassOublie(linkDestiPop){
		window.open( linkDestiPop , '' , 'top=' + ((screen.height/2)-255) + ' , left=' + ((screen.width/2)-225) + ' , width=450 , height=325 , scrollbars=no' );
	return false;
}


function closePopup(){
		var linkClosePopup = document.getElementById('fermerPopup');
		var linkClosePopupParrain = document.getElementById('fermerPopupParrain');
		if (linkClosePopup) {
				linkClosePopup.onclick = function(){
						window.close();
						return false;
				}
		}
		if (linkClosePopupParrain) {
				linkClosePopupParrain.onclick = function(){
						window.close();
						return false;
				}
		}
}


//Fonction pour le formulaire de Coaching dessert pour Safari//

var targBox = "formCoaching";
function coachingSafari() {
	if (navigator.userAgent.indexOf("Safari") > -1) {
		var coaching = document.getElementById("formCoaching");
		if (coaching){
				var links = coaching.getElementsByTagName("a");
				for (var i=0;i<links.length;i++) {
					var ca = links[i];
					if (ca.href.indexOf("#") > -1) {
						ca.onclick = function() {
							scrollDivToAnchor(this.href.split("#")[1]);
						}
				}
			}
		}
	}
}
function scrollDivToAnchor(a) {
	var b = document.getElementById(targBox);
	b.scrollTop = document.getElementById(a).offsetTop - b.offsetTop;
}

// Fonctions pour la popup d'inscription
//function popupInscription(){
//    var linkPopupInscription = document.getElementById('btInscription');
//	if (linkPopupInscription){
//	    var linkOpenPopIden = linkPopupInscription.href;
//	    linkPopupInscription.onclick = function (){
//	        openPopupInscription(linkOpenPopIden);
//	        return false;
//	    }
//	}
//}
//function openPopupInscription(linkDestiPop){
//    window.open( linkDestiPop , '' , 'top=0 , left=' + ((screen.width/2)-278.5) + ' , width=558 , height='+ ((screen.height)-35) +' , scrollbars=yes' );
//	return false;
//}

//function closeInscription(){
//    var linkClosePopup = document.getElementById('fermerInscription');
//	 var splitUrl = new Array();
//	 var redirect = "";
//	 var newIndex = "index.aspx";
//    if (linkClosePopup) {
//        linkClosePopup.onclick = function(){
//		  		var urlOpener = opener.location;
//				splitUrl = urlOpener.href.split("/");
//				for(var i=0;i<splitUrl.length-1;i++){
//					redirect += splitUrl[i]+"/"
//				}
//				redirect += newIndex;
//				opener.location.href = redirect;
//            window.close();
//            return false;
//        }
//    }
//}


//fonctions pour le lexique - Tout pour reussir

function activeLettre() {
	var links = document.getElementById("abecedaire");
	if(links){
		//initialisation du tableau des liens
		var tablinks = new Array();
		tabLinks = links.getElementsByTagName("a");
		
		for(i=0;i<tabLinks.length;i++){
				tabLinks[i].onclick = function(){
				activeTitle(tabLinks,this,"active");
				return false;
			}
		}
		// on affiche par defaut le tableau de la lettre A
		document.getElementById("lettreA").style.display = "block";
	}
}
//fonction de changement de classe
function activeTitle(obj,objCompare,nameClass) {
	
	for(var j=0; j<obj.length; j++) {
		
		/* infos du tableau a afficher */
		var divShow = obj[j].hash.split("#")[1];
		var tableau = document.getElementById(divShow);
		
		if(obj[j] != objCompare) {
			obj[j].className = "";
			if(divShow != undefined){
				tableau.style.display = "none";
			}
		} else {
			obj[j].className = nameClass;
			if(divShow != undefined) {
				tableau.style.display = "block";				
			}
		}
	}
}

// Select Liens recettes videos
function liensSelect(){
		var selectVideos = document.getElementById("videoRecetteContent");
		if (selectVideos){
		var  selectListeVideos = selectVideos.getElementsByTagName("select")
				selectListeVideos[0].onchange = function(){
						if(this.options[this.selectedIndex].value!=''){
								window.location.href = this.options[this.selectedIndex].value;
						}
				}
		}
}

function removePossibleScript(valueFieldToParse){
		var result = valueFieldToParse;
		result = valueFieldToParse
		var reg=new RegExp("'", "g");
		result.replace(reg,"");
		reg=new RegExp(";", "g");
		result.replace(reg,"");
}

// FAQ
function show(thingId)
{
 if (!document.getElementById("divid1"))
		return;
 var i;
 var targetElement;
 for(i=1; i<12; i++){
	targetElement = document.getElementById("divid" + i) ;
	targetElement.style.display = "none" ;
 }
 targetElement = document.getElementById("divid" + thingId) ;
 targetElement.style.display = "" ;
}


/* SELECT */
function addEvent( obj, type, fn )
{
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
	} else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener) {
		obj.removeEventListener( type, fn, false );
	} else if (obj.detachEvent) {
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

function launch_page(obj) {

if(document.getElementById(obj)){
			var anchors = document.getElementById(obj).getElementsByTagName('a');
			
			 var txt = '<select id="new'+obj+'"><option>S&#233;lectionnez</option>';
			
			for(var i=0; i < anchors.length; i++) {
				txt += '<option value="'+anchors[i]+'">'+anchors[i].innerHTML+'</option>';
			}
			
			txt += '</select>';
			
			document.getElementById(obj).innerHTML = txt;
			
			addEvent(document.getElementById('new'+obj),'change', function() { window.location = document.getElementById('new'+obj).value; } );
		}
}

function AddList() {
	$('.liste2').each(function(){
		var liste = $('ul li a',$(this));
		var txt = '<select><option>S&#233;lectionnez</option>';
		for(var i=0; i < liste.length; i++) {
			txt += '<option value="'+$($('ul li a',$(this))[i]).attr('href')+'">'+$($('ul li a',$(this))[i]).text()+'</option>';
		}
		txt += '</select>';		
		$(this).html(txt);
	})
	
	$('.liste2 select').change(function(){
		var value = $(this).val();
		window.location=value;
	})
}

addEvent(window,'load',function() { launch_page('liste'); });
//  06-01-09  \\
// Renvoie les dimensions de la page
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;
	}
	
	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;	
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
};

// Mise en place des popins sur la page
function initPopins(){

	var dim = getPageSize();
	
	$('.popin').each(function(i, elem){
		$(elem).bind('click', function(){
			var popinName = $(this).attr('rel');
			var overlay = $('#popinOverlay');
			var popin = $('#'+popinName);
			var scroll = getPageScroll();
			
			
			//
			$('#btnPopinOui').attr("href",$(this).attr('href'));
			
			// Affichage de l'overlay
			if($.browser.msie){ $("select").css("visibility","hidden");	}	// enlever les selects pour IE
			
			overlay.css({
				width: dim[0],
				height: dim[1],
				opacity: 0.7,
				display: 'block'
			}).fadeIn();
			
			// S'il y a un background, on l'affiche
			if($('.popinBG').length){
				var popinBG = $('.popinBG');
				
				$(popinBG).css({
					top: scroll[1] + ($(popinBG).height() / 10),
					left: (dim[2]-$(popinBG).width())/2,
					opacity: 1,
					display: 'block'
				});
			}
			
			// Affichage de la popin
			popin.css({
				top: scroll[1] + (dim[3] / 10),
				left: (dim[2]-$(popin).width())/2,
				opacity: 1,
				display: 'block'
			}).fadeIn();
			
			// Bouton fermer
			popin.find('.btnFermer').bind('click', function(){
				overlay.fadeOut();
				popin.fadeOut(function(){
					if($.browser.msie){ $("select").css("visibility","visible");	}	// enlever les selects pour IE
				});
				if(popinBG) popinBG.fadeOut();
				
				return false;
			});
			
			return false;
		});
	});
}

function setPrintPopinBon(){/*				
		$(obj).unbind();			
		$(obj).bind('click',function(){				
			if($(obj).hasClass('printBons')){
				window.print();				
			}	
			return false;			
		});	*/
}

//var _initialRecipeSearchBoxValue = "Mot cl&eacute;s"; 
var _initialRecipeSearchBoxValue = "Mots clés"; 
$(document).ready(function() {


	//Gestion d'affichage du message
	var blocRecherche = $("#searchRecipeBox");
 
	blocRecherche.attr("value", _initialRecipeSearchBoxValue);
	blocRecherche.bind("focus" , function(){
		if ($("#searchRecipeBox").attr("value") == _initialRecipeSearchBoxValue)
			{
				 $("#searchRecipeBox").attr("value",  "");
			}
	});
	blocRecherche.bind("blur",function()
	{
		if($("#searchRecipeBox").attr("value") == ""){
			 $("#searchRecipeBox").attr("value", _initialRecipeSearchBoxValue);
		}
	});
	//Gestion du keypressed sur l'input text
	$("#searchRecipeBox").bind("keypress", function (event)
		{
			if (event.keyCode == 13) {return searchSubmit();}
		});
	//Gestion du click sur le bouton ok
	 $("#searchRecipeButton").click(function (e)
	 {
	 e.preventDefault();
	 return searchSubmit();
	 })

 });


function searchSubmit()
{
 var valeurRecherche = $("#searchRecipeBox").attr("value");
 if (valeurRecherche!=_initialRecipeSearchBoxValue)
	{
		valeurRecherche = encodeURI(valeurRecherche);
		window.location.href = '/IdeesRecettes/MoteurRecettesResultat.aspx?critName0=LIBELLES&critVal0='+ valeurRecherche +'&critDir0=PLUS';
	}
	return false;
}

function resizeTableResult(){
						  if($(".partLinkTop ul li.on").attr("id")=="ctl00_MainContent_tabProducts"){
							$(".resultSearch .resultTable").css("height","516px");
						 }else if($(".partLinkTop ul li.on").attr("id")=="ctl00_MainContent_tabCategories"){
							$(".resultSearch .resultTable").css("height","547px");
						 }else if($(".partLinkTop ul li.on").attr("id")=="ctl00_MainContent_tabName"){
							$(".resultSearch .resultTable").css("height","642px");
						 }
}

function AfficheItemEngagementQualite(){
    $('#engagementQualite .PartInfoBulle ul li a').unbind();
	$('#engagementQualite .PartInfoBulle ul li a').bind('mouseenter',function(){
	   // alert(".......");
	    $('#engagementQualite .PartInfoBulle ul li').addClass('off');
	    $(this).parent().removeClass('off');
	    if($(this).attr('id')=="qualite"){
	            $('.TxtQualite').show();
	    }else if($(this).attr('id')=="fermentation"){
	                 $('.TxtFermentation').show();
	            }else if($(this).attr('id')=="broyage"){
	                         $('.TxtBroyage').show();
	                    }else if($(this).attr('id')=="torrefaction"){
	                                $('.TxtTorrefaction').show();
	                            }else if($(this).attr('id')=="melange"){
	                                         $('.TxtMelange').show();  
	                                    }else if($(this).attr('id')=="moulage"){
	                                                 $('.TxtMoulage').show();
	                                    }
	}).bind('mouseleave',function(){
	    $('#engagementQualite .PartInfoBulle ul li').removeClass('off');
	    $('#engagementQualite .PartInfoBulle div').hide();
	});
}

/* verification d email */
function isEmail(field){ 
	var val = field.val();
	if (!val.match (/^[a-z0-9\-\._]+@[a-z0-9\-_\.]+\.[a-z]{2,4}$/gi)){
	 	return false;
	}
	return true;
}


function validateFormAlert() {
	$('.submit input,.bt-send').click(function(){
		
		$('.form-alert .error').hide();
		$('.form-alert .alert').hide();
		$('.form-alert p.err-item').removeClass('err-item');
		
		var flag = true;
		
		$('.form-alert .required').each(function(){
			if(!$(this).val()) {
				$(this).parent().addClass('err-item');
				flag = false;
			}
			
			if(!isEmail($(this)) && $(this).hasClass("inputMail")){
				$(this).parent().addClass('err-item');
				flag = false;
			}				
			
		})
		
		if (!flag){
			$('.form-alert .error').show();
			return false;
		}else{
			$('.form-alert .alert').show();
			return true;
		}
	});
}