function newsletterPopupSubmit() {
      // function used to open the newsletter popup
      var email = document.forms['newsletterForm'].elements['email'].value;

      //Validate e-mail
      if (email == '') {
        alert("Veuillez entrer votre adresse e-mail");
      } else if(!checkEmail(email)){
          alert("Votre adresse e-mail n'est pas valide");
      } else{
          var param = email + '&type=Newsletter';
          popupWindowParam("subscribeNewsletter.do", "Newsletter", "yes", "170", "220", "no", param);
      }

}

/**
 * Reference: Sandeep V. Tamhankar (stamhankar@hotmail.com),
 * http://javascript.internet.com
 */
function checkEmail(emailStr) {
   if (emailStr.length == 0) {
       return true;
   }
   var emailPat=/^(.+)@(.+)$/;
   var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
   var validChars="\[^\\s" + specialChars + "\]";
   var quotedUser="(\"[^\"]*\")";
   var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
   var atom=validChars + '+';
   var word="(" + atom + "|" + quotedUser + ")";
   var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
   var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$");
   var matchArray=emailStr.match(emailPat);
   if (matchArray == null) {
       return false;
   }
   var user=matchArray[1];
   var domain=matchArray[2];
   if (user.match(userPat) == null) {
       return false;
   }
   var IPArray = domain.match(ipDomainPat);
   if (IPArray != null) {
       for (var i = 1; i <= 4; i++) {
          if (IPArray[i] > 255) {
             return false;
          }
       }
       return true;
   }
   var domainArray=domain.match(domainPat);
   if (domainArray == null) {
       return false;
   }
   var atomPat=new RegExp(atom,"g");
   var domArr=domain.match(atomPat);
   var len=domArr.length;
   if ((domArr[domArr.length-1].length < 2) ||
       (domArr[domArr.length-1].length > 3)) {
       return false;
   }
   if (len < 2) {
       return false;
   }
   return true;
}

function popupWindowParam(url,title,resizable,aHeight,aWidth,scrollbars,params) {
      // open a popup with the newsletter form
      pop = window.open(url + "?email=" + params,title,"resizable="+resizable+",height="+aHeight+",width="+aWidth+",scrollbars="+scrollbars);
      //window.alert("params=" + params);
      pop.focus();
}

// for inscription page
function initDeliveryAddress() {
    if(document.forms["inscriptionForm"].insurance[0]){
        document.forms["inscriptionForm"].insurance[0].checked = false; 
    }
    if (document.forms["inscriptionForm"].elements["askForDelivery"].checked == true) {
        document.getElementById("divLivraisonAd").style.display = "";
        document.getElementById("divLivraisonCP").style.display = "";
        document.getElementById("divLivraisonCity").style.display = "";
        document.getElementById("divLivraisonCountry").style.display = "";
        document.getElementById("divLivraisonCol").style.display = "";
    } else {
        document.getElementById("divLivraisonAd").style.display = "none";
        document.getElementById("divLivraisonCP").style.display = "none";
        document.getElementById("divLivraisonCity").style.display = "none";
        document.getElementById("divLivraisonCountry").style.display = "none";
        document.getElementById("divLivraisonCol").style.display = "none";
    }
    return true;
}

function displayReturnDate() {
    var visibility = "hidden";
    if (document.forms["searchAirAvailabilitiesForm2"] != null) {
       var options = document.forms["searchAirAvailabilitiesForm2"].elements["returnTicket"];
      for (var ii = 0; ii < options.length; ii++) {
          if (options[ii].checked) {
              if (options[ii].value == "true") {
                  visibility = "";
                  break;
              }
          }
      }
    } else {
         if (document.forms["searchAirAvailabilitiesForm"] != null) {
         var options = document.forms["searchAirAvailabilitiesForm"].elements["returnTicket"];
       for (var ii = 0; ii < options.length; ii++) {
          if (options[ii].checked) {
              if (options[ii].value == "true") {
                  visibility = "";
                  break;
              }
          }
       }
       }
    }
    if (document.getElementById("ReturnDate")) {
        document.getElementById("ReturnDate").style.visibility = visibility;
    }
    if (document.getElementById("ReturnInput")) {
        document.getElementById("ReturnInput").style.visibility = visibility;
    }

    if (document.getElementById("returnDate1")) {
        document.getElementById("returnDate1").style.visibility = visibility;
        document.getElementById("returnDate2").style.visibility = visibility;
    }
    return true;
}

function switchVis(objectId, visType) {
    if (document.getElementById(objectId)) {
        document.getElementById(objectId).style.display = visType;
    }
}
// refresh home page
function autoRefresh() {
    var sURL = unescape(window.location.pathname);
    if (typeof(ttl) == 'undefined') {
        ttl = 31 * 60 * 1000; // default is 31 minutes
    }
    var aPage = sURL.substring(sURL.lastIndexOf('/')+1, sURL.length);
    // only refresh when page is the homepage
    if (sURL.indexOf('home.do') != -1 || aPage == '') {
        setTimeout('document.location=document.location',ttl);
    }
}
document.onload = autoRefresh();


function flightDetails(index) {
    window.open("displayFlightDetails.do?index=" + index,
                "flightDetails",
                "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, width=790, height=500");
}
// display mode de reglement for PASS2 carte only
function displayCartePlus(code) {
    var cards = document.getElementsByName('cardType');
    document.getElementById('crypoTR').style.display = "block";
    for (var i = 0; i < cards; i++) {
        var nameCard = cards[i].value;
        if ((code == 'PASS2' ) && (nameCard == code)) {
            nameCard = nameCard + 'TR';
            document.getElementById(nameCard).style.display = "block";
            document.getElementById('crypoTR').style.display = "none";
        } else {
            nameCard = nameCard + 'TR';
            document.getElementById(nameCard).style.display = "none";
        }
    }
}

function initCarte() {
    var cards = document.forms['paymentForm'].elements['cardType'];
    var pass = false;
    for (var i = 0; i < cards.length; i++) {
        var t = cards[i].value;
        if (cards[i].checked && (t == 'PASS' || t == 'PASS2' || t == 'CBPASS')) {
            pass = true;
        }
    }
    if (pass) {
        document.getElementById('passTR').style.display = "block";
        document.getElementById('crypoTR').style.display = "none";
    } else {
        document.getElementById('passTR').style.display = "none";
        document.getElementById('crypoTR').style.display = "block";
    }
}
function afficherPopupAssurances(){
	pop = window.open ('CS/aircameleo/assurance-pop-up.htm', '', config='height=600px, width=650px, scrollbars=yes, resizable=no, menubar = no');
	pop.focus();
}

