﻿
$(document).ready(function() {
	WEEdSiteCommon.Initialize(); 
});


var WEEdSiteCommon = {


    IE7Hack: function(WE) { 
       if ($.browser.msie && parseInt($.browser.version)==7) { 
       
            WE.resize(function() {                
                $(this).children("div").each(function() {
                    if ($(this).css("bottom")!="auto" && $(this).css("top")!="auto") {
                        var Padding = parseInt(WE.css("padding-top")) + parseInt(WE.css("padding-bottom"));
                        var NewHeight = WE.height() - parseInt($(this).css("top")) - parseInt($(this).css("bottom"));
                        $(this).height(NewHeight + Padding);
                    }                
                }); 
            }); 
       
 
            WE.trigger('resize');       
        }
    },

	Initialize: function() {
        
        WEEdSiteCommon.LoadClassEvent();
        
		$("div.BaseDiv").each(function() {        
            
            WEEdSiteCommon.LoadClassGlobalEvent($(this));
		    WEEdSiteCommon.IE7Hack($(this));
		    
		});
		
		
		
		
	},


    //Chargement des évènements global sur les class de zone de styles
    LoadClassGlobalEvent: function (WE) {
    
        var ChildDownEvents = WE.find(".OESZG_" + WE.attr("id") + ".OE_GDownEvent")
        if (ChildDownEvents.size()>0 || WE.hasClass("OE_GDownEvent")) {
    
            WE.bind('mouseup.CssEvents',function() {ChildDownEvents.add($(this)).removeClass("OE_Down")});        
            WE.bind('mousedown.CssEvents',function() {ChildDownEvents.add($(this)).addClass("OE_Down")});  
        
        }
        
        
        var ChildOverEvents = WE.find(".OESZG_" + WE.attr("id") + ".OE_GOverEvent")
        if (ChildOverEvents.size()>0 || WE.hasClass("OE_GOverEvent")) {
    
            WE.bind('mouseenter.CssEvents',function() {ChildOverEvents.add($(this)).addClass("OE_Over")});        
            WE.bind('mouseleave.CssEvents',function() {ChildOverEvents.add($(this)).removeClass("OE_Over")});  
        
        }
          
    },
    
    
    //Chargement des évènements sur les class de zone de styles
    LoadClassEvent: function () {
            
        var DownEvents = $(".OE_DownEvent")
        DownEvents.bind('mouseup.CssEvents',function() {$(this).removeClass("OE_Down")});
        DownEvents.bind('mousedown.CssEvents',function() {$(this).addClass("OE_Down")});
        
        var OverEvents = $(".OE_OverEvent")
        OverEvents.bind('mouseenter.CssEvents',function() {$(this).addClass("OE_Over")});
        OverEvents.bind('mouseleave.CssEvents',function() {$(this).removeClass("OE_Over")});
        
    },



	

    OpenPopup : function (url,name,width,height,top,left,options) {
    
        if (top<0) {top=(screen.height-height)/2};
        if (left<0) {left=(screen.width-width)/2};
        
        window.open(url,name,"top="+top+",left="+left+",width="+width+",height="+height+","+options);
    
    },
        
    //Permet d'obtenir le path d'un lien localisé depuis Json
    //LinkData : Donnée Json du lien
    LinkGetPath: function(LinkData) {
        Culture = WEInfoPage.Culture ;
        var link = this.GetLocalizableString(LinkData.LocalizableLinkPath);
     
        if (LinkData.Type == 0 ){       //EnuLinkType.Page
            var extend = "" ; 
            if (Culture != "DEFAULT"){extend = Culture}
            link =  link.replace(".dat", extend+".htm") ; 
            return link ; 
        }
        else{
            return link ; 
        }
    },
    
    //Permet d'obtenir le path d'un lien localisé depuis Json
    //LocalizableStringData : Donnée Json
    GetLocalizableString: function(LocalizableStringData) {
        Culture = WEInfoPage.Culture ; 
        //recupere le lien
        for (i in LocalizableStringData.Items) {
            if (i==Culture) {
                return LocalizableStringData.Items[i];
            } else {
                return LocalizableStringData.Items["DEFAULT"];
            }
        }
            
    },

    //Recupre la hauteur total d'une fenetre, scroll compris
    GetTotalHeight : function() {  
        // firefox is ok  
        var height = document.documentElement.scrollHeight;  
        // now IE 7 + Opera with "min window"
        if (document.documentElement.clientHeight > height) {
            height = document.documentElement.clientHeight;  
        }
        // last for safari
        if (document.body.scrollHeight > height) {
            height = document.body.scrollHeight;
        } 
        return height;
    },


    //Recupre la largeur total d'une fenetre, scroll compris
    GetTotalWidth : function() {  
        // firefox is ok  
        var width = document.documentElement.scrollWidth;  
        // now IE 7 + Opera with "min window"
        if (document.documentElement.clientWidth > width) {
            width = document.documentElement.clientWidth;  
        }
        // last for safari
        if (document.body.scrollWidth > width) {
            width = document.body.scrollWidth;
        }
        return width;
    }

    };


// CLASSE DE VALIDATION des formulaires
var WEFormValidator = {
        
    Execute: function(Element,value) {
    
        // si on a aucune variable de validation
        if(typeof(WEEdValidators) == 'undefined'){ 
              return true; 
        }
        
        for (index in WEEdValidators) { // Dictionaire
             if (index!=Element.attr("ID")) continue; // Ce n'est pas le bon element 
                      
             for (i in WEEdValidators[index]) { //Liste des regles
                 rule=WEEdValidators[index][i];
              
                 if (rule) {
                    Expression=rule.Expression;
                    var reg = new RegExp(Expression); //test expression reguliere
        
                    // Affichage - retrait des messages d'erreurs
                    if (!reg.test(value)) {
                        this.ShowError(Element,rule.MsgError);
                        return false;
                    } else {
                        this.HideError(Element,rule.MsgError);
                    }
                 }
            }
        }
        return true;
    },
         
    // Affichage du messages d'erreur et de l'icone d'erreur
    ShowError: function(Element,MsgError) {
       
        var ValidatorErr=Element.find(".OEErrorIcone");
        if (ValidatorErr.size()>0) {
            ValidatorErr.children('span').html(MsgError);
            ValidatorErr.show();
        }
    },
    
    // Rend invisible le message d'erreur et l'icone
    HideError: function(Element,MsgError) {
       
        var ValidatorErr=Element.find(".OEErrorIcone");
        if (ValidatorErr.size()>0) {
            ValidatorErr.hide();
        }
    }
    
}



