// JavaScript Document

//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 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:'-1'
        };
        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 affichePopIn(nom_popup){
    maximize(document.getElementById('BgPopup'));
    document.getElementById(nom_popup).style.display='block';


    // on enleve les select
    var x = document.getElementsByTagName("select");
    for (i = 0; i < x.length; i++) {
       //x[i].style.display = "none";
       x[i].style.visibility = "hidden";
    }

    return false;
}

function cachePopIn(nom_popup){
    document.getElementById(nom_popup).style.display='none';
    document.getElementById('BgPopup').style.display='none';

    // on remet les select
    var x = document.getElementsByTagName("select");
    for (i = 0; i < x.length; i++) {
       //x[i].style.display = "block";
       x[i].style.visibility = "";
    }
    return false;
}// JavaScript Document

//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();


//MENU
function montre(id) {
   if (id == "partir_deux" || id == "sejour"){
       if (document.getElementById("destination") != undefined){
          document.getElementById("destination").style.visibility = "hidden";
          document.getElementById("ville_depart").style.visibility = "hidden";
      }
      if (document.getElementById("votreagence") != undefined){
          document.getElementById("votreagence").style.visibility = "hidden";
      }

   }
}

function cache(id) {

   if (id == "partir_deux" || id == "sejour"){
       if (document.getElementById("destination") != undefined){
          document.getElementById("destination").style.visibility = "";
          document.getElementById("ville_depart").style.visibility = "";
       }
      if (document.getElementById("votreagence") != undefined){
          document.getElementById("votreagence").style.visibility = "";
      }
   }
}


 function getStyle(el,styleProp)	{
    var x = document.getElementById(el);
    if (window.getComputedStyle)// Mozilla
    var y = window.getComputedStyle(x,null).getPropertyValue(styleProp);
    else if (x.currentStyle)// Explorer 6
    {
        if (styleProp!='clip') var y = eval('x.currentStyle.' + styleProp);
        else{
            ctop=x.currentStyle.clipTop;
            cright=x.currentStyle.clipRight;
            cbottom=x.currentStyle.clipBottom;
            cleft=x.currentStyle.clipLeft;
            y='rect('+ctop+','+cright+','+cbottom+','+cleft+')';
        }
    }
    return y;
}


function calageForm(){
    var tailleArianne = getStyle("arianne","height").split('px')[0];
    if (tailleArianne>43){
        var decalage = parseInt(tailleArianne) + parseInt(223) - parseInt(50);
        document.getElementById("formulaire_recherche").style.top = decalage+"px";
    }
}

function calageForm2(){
    var tailleArianne = getStyle("arianne","height").split('px')[0];
    var topForm = getStyle("formulaire_recherche","top").split('px')[0];
    if (tailleArianne>43){
        var decalage = parseInt(tailleArianne) + parseInt(topForm) - parseInt(50);
        document.getElementById("formulaire_recherche").style.top = decalage+"px";
    }
}


//POPIN
function onscroll(){
   if (document.all){
      document.getElementById('popin_acces_compte').style.top = document.documentElement.scrollTop+100+"px";
      document.getElementById('popin_recherche_pass').style.top = document.documentElement.scrollTop+100+"px";
      document.getElementById('popin_recherche_pass2').style.top = document.documentElement.scrollTop+100+"px";
      document.getElementById('PopinLoader').style.top = document.documentElement.scrollTop+100+"px";
   }else{
      document.getElementById('popin_acces_compte').style.top=window.pageYOffset+100+"px";
      document.getElementById('popin_recherche_pass').style.top=window.pageYOffset+100+"px";
      document.getElementById('popin_recherche_pass2').style.top=window.pageYOffset+100+"px";
      document.getElementById('PopinLoader').style.top=window.pageYOffset+100+"px";
   }
}


function Get_Cookie( check_name ) {
    // first we'll split this cookie up into name/value pairs
    // note: document.cookie only returns name=value, not the other components
    var a_all_cookies = document.cookie.split( ';' );var a_temp_cookie = '';var cookie_name = '';var cookie_value = '';
    var b_cookie_found = false; // set boolean t/f default f
    for ( i = 0; i < a_all_cookies.length; i++ ){
        // now we'll split apart each name=value pair
        a_temp_cookie = a_all_cookies[i].split( '=' );
        // and trim left/right whitespace while we're at it
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
        // if the extracted name matches passed check_name
        if ( cookie_name == check_name ){
            b_cookie_found = true;
            // we need to handle case where cookie has no value but exists (no = sign, that is):
            if ( a_temp_cookie.length > 1 ){cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );}
            // note that in cases where cookie is initialized but no value, null is returned
            return cookie_value;break;
        }
        a_temp_cookie = null;cookie_name = '';
    }
    if ( !b_cookie_found ){return null;}
}

function showMySelection() {
    var mySelectionNumber = 0;
    if (Get_Cookie("mySelectionNumber"))mySelectionNumber=Get_Cookie("mySelectionNumber");
    if (mySelectionNumber != 0) {
        window.location.href = "/retour-moteur?pid=" + Get_Cookie("mySelections");
    } else {
        $("#mySelection").css("color","red").css("font-weight","bold");
        setTimeout("$('#mySelection').css('color','black').css('font-weight','normal')",1000);
        return false;
    }
}

function sharePage(baseUrl, urlParamName, titleParamName) {
    window.open(baseUrl+urlParamName+"="+escape(document.URL)+"&"+titleParamName+"="+escape(document.title), "_bank");
}

function sendEmailAddress(id) {
    var email = $("#"+id).attr("value");
    /*if(email.indexOf("@") == -1) {
        alert("L'adresse saisie n'a pas le bon format.");
        return false;
    }*/
    var url = "http://trc.emv2.com/D2UTF8?emv_tag=4E08DDD01E010000&emv_ref=BdX7CqkdFiJhxWUNCOYLn8rWXUx7HK3D,gwf&EMAIL_FIELD="+escape(email);
    window.open(url,"newsletter","resizable=1, scrollbars=1, height=400, width=700");
}

function submitFormAgence(form) {
    if (form.elements['code'].value == "") {
        alert("Veuillez sélectionner une agence.");
        return false;
    }
    window.location.href="/agences/"+form.elements['code'].value+".html";
}


