function xLoaded() {}



/*ThickBox*/
if(langue == "fr"){ var tb_closeCaption = "Fermer"; var tb_closeCaption2 = "";}

function showMedia(vFile,vTitre,vWidth,vHeight) {	
	if(!vWidth) vWidth= 450;
	if(!vHeight) vHeight= 340;
	if(!vTitre) vTitre = "";
	//vWidth-=30;
	//vHeight-=10;
	tb_show(vTitre,"/medias/player.aspx?file="+vFile+"&TB_iframe=true&width="+vWidth+"&height="+vHeight+"&modal=false&scrolling=no");
}

function validateZipCode(zip) {
                    var zipCodePattern = /^\d{5}$|^\d{5}-\d{4}$/;
                    return zipCodePattern.test(zip);
                }



function validatePostalCode(zip) {
    var pattern = /[a-zA-Z][0-9][a-zA-Z](-| |)[0-9][a-zA-Z][0-9]/;
    return pattern.test(zip);
}


function showFrame(vUrl,vTitre,vWidth,vHeight) {
	tb_show(vTitre,vUrl+"&TB_iframe=true&width="+vWidth+"&height="+vHeight+"&modal=false&scrolling=no");
}

function showImage(imageUrl,imageTitre) {
    if(!imageTitre) imageTitre = top.document.title;
	tb_show(imageTitre,imageUrl+"?width");
}


var localisateur = {
    init: function() {
    //récupere la valeur dans l'url
    qstring_values=this.qstring_value_pairs();
    pays=qstring_values['p'];
    this.activerLocalisateur();
    this.ajusterHauteurLi();
    //this.validerCodePostal();
    this.initLocalisateurComboBox();
    this.localisateurManageVisibility();
    
    },
     activerLocalisateur: function() {
      $('.codePostal').keydown(function(e){
            var enter = 13;
            if(e.which == enter) {
            
            
                        $('.btTrouver').click();
                        return false;
                    }

        });
        
        $('.btTrouver').click(function() {
      
        localisateur.validerCodePostal();
          return false;
         });
    },
    
    validerCodePostal: function() {
    
            
                $('.codePostal').removeClass('error');
                
                    if  ($('.codePostal').val()==""){
                    $('.codePostal').addClass('error');
                    
                     $('#ctl00_ctnContenu_wheretobuy_paysHidden').val("");
                    
                    }
            
                    else if (validatePostalCode($('.codePostal').val())){
                  
                       $('#ctl00_ctnContenu_wheretobuy_paysHidden').val("CA");
                       __doPostBack('ctl00$ctnContenu$wheretobuy$lbSubmit','');
                      }
                      else  if (validateZipCode($('.codePostal').val())){
                     
                      $('#ctl00_ctnContenu_wheretobuy_paysHidden').val("US");
                      __doPostBack('ctl00$ctnContenu$wheretobuy$lbSubmit','');
                      }
                      else{
                      $('#ctl00_ctnContenu_wheretobuy_paysHidden').val("");
                      $('.codePostal').addClass('error');
                       return false;
                      }
            

                  
                   
                   
                  

                   
                
    },
                 
    ajusterHauteurLi: function() {

                var compteur=0;
                var nbLi=$('.listeDetail li').size();
                
                for (i=0;i<=nbLi;i=i+3){
                var hauteur1=$('.listeDetail li span').eq(i).height();
                var hauteur2=$('.listeDetail li span').eq(i+1).height();
                var hauteur3=$('.listeDetail li span').eq(i+2).height();
                var plusHaut="100";
                    if (hauteur1>plusHaut){
                    plusHaut=hauteur1;
                    }
                    if (hauteur2>plusHaut){
                    plusHaut=hauteur2;
                    }
                    if (hauteur3>plusHaut){
                    plusHaut=hauteur3;
                    }
                    $('.listeDetail li').eq(i).height(plusHaut);
                  
                    $('.listeDetail li').eq(i+1).height(plusHaut);
                     
                    $('.listeDetail li').eq(i+2).height(plusHaut);
                    
                }
                
          
                
               
     $('.listeDetailMonde').css("visibility","visible");
     $('.listeDetail').css("visibility","visible");
    },
    
    localisateurManageVisibility: function() {
            
            
            
    
            $('#selectJob').click(function() {
                $('#ddSelectJob').toggle();
                return false;
            });

            $('body').click(function(e) {
                $('#ddSelectJob').hide();
            });
    },
       
       
       
    qstring_value_pairs : function() {
    
		var r = {};
		var q = location.toString()
		q = q.replace(/\&$/,''); // remove the trailing &
		q = q.split('?')
		if(q[1]){
			jQuery.each(q[1].split('&'), function(index){
				var key = this.split('=')[0];
				var val = this.split('=')[1];
				var val = val.split('#')[0];
				// ingnore empty values
				if(val){
					r[key] = val;
				}
			});
			return r;
		}else{
			return "";}
			
			var pays  = unescape(qstring_values['p'])
           
	},           
                
                
    initLocalisateurComboBox: function() {
        /* Initialize the list with the selected job */
        /*     First we check if a list item is selected; if not, we take the first one in the list */
        if (!$("#ddSelectJob .selected").length)
            $("#ddSelectJob li").eq(0).attr("class", "selected");


        /* Then, we assign the text value of the selected item to the custom hyperlink of the list */
        if (pays!=null){
        
        $("#selectJob").text($("#ddSelectJob #"+pays).text());
        }

        /* When the user selects an item, we change the displayed value and assign it to the
        hidden field for the form submission */
        
//        $('#ddSelectJob li').click(function() {
//            var theText = $(this).text();
//            $('.invInputJob').attr('value', theText);

//            $('#ddSelectJob li').removeClass('selected');
//            $('#selectJob').text(theText);
//        });

        /* Prevent the user from selecting a category item */
        $('.category').click(function() { return false; });
    }
}