var PathAbsolu
PathAbsolu = "www.gitesetaubergesdupassant.com";
var locationDNSPath = window.location;
locationDNSPath = locationDNSPath.toString();
if( locationDNSPath.indexOf( "https://" ) == -1 ) {
	if( locationDNSPath.indexOf( "www." ) == -1 ) {
		PathAbsolu = PathAbsolu .replace( "http://www.", "http://" );
	}
}else{
	if( locationDNSPath.indexOf( "www." ) == -1 ) {
		PathAbsolu = PathAbsolu .replace( "http://www.", "https://" );
	}else{
		PathAbsolu = PathAbsolu .replace( "http://", "https://" );
	}
}

///////////////////////////////////////////////////////////
//////////// FUNCTION QUI VALIDE LES FORMULAIRES //////////
///////////////////////////////////////////////////////////
function validationFormulaire(arrayValeurs,nameForm,  typeFormulaire, langue){
	var boValidation = true;
	var boValidationCourriel = true;
	var boValidationRadio;
	var boValidationConfirmerCourriel = true;
	var strPaiement;
	strPaiement = "";
	if(arrayValeurs.length > 0 ){
		for( var x = 0; x < arrayValeurs.length ; x++ ){
			if(document.getElementsByName(arrayValeurs[x])[0]){
				if(document.getElementsByName(arrayValeurs[x])[0].type == "radio"){
					boValidationRadio = false;
					for( var y = 0 ; y < document.getElementsByName(arrayValeurs[x]).length ; y++ ){
						if( document.getElementsByName(arrayValeurs[x])[y].checked ){ boValidationRadio = true; }
					}
					if(!boValidationRadio){ boValidation = false; break; }
				}else{
					if( document.getElementsByName(arrayValeurs[x])[0].value == "" ){ 
						boValidation = false; break; 
					}else{ 
						if( (arrayValeurs[x].indexOf("courriel") >= 0 ) || ( arrayValeurs[x].indexOf("Courriel") >= 0 ) ){
							if( eMailValidationFormulaire( document.getElementsByName(arrayValeurs[x])[0].value ) ){
								if( document.getElementsByName("Confirmer_courriel")[0].value == document.getElementsByName("Courriel")[0].value ){
									boValidation = true;
									boValidationCourriel = true;
								}else{

									boValidationConfirmerCourriel = false; break;
								}
							}else{
								boValidationCourriel = false; boValidation = false; break;
							}
						}		 
					}
				}		
			}
		}
	}
	if( typeFormulaire == "mandat" ){
		//// ON VÉRIFIE QUEL EST LE TYPE DE PAIEMENT SOIT PAR MANDAT POSTE, CARTE DE CRÉDIT OU SI C'EST DÉJÀ PAYÉ
		for(var z = 0 ; z < document.getElementsByName("Paiement").length ; z++){
			if(document.getElementsByName("Paiement")[z].checked){ strPaiement = document.getElementsByName("Paiement")[z].value; break; } 
		}
		if( strPaiement == "" ){ boValidation = false; }
		//// SI LE PAIEMENT EST PAR CARTE DE CRÉDIT ON VALIDE LES CHAMPS
		if( strPaiement == "carte_de_credit" ){
			if(boValidation){
				if(document.getElementsByName("carte_credit")[0] && document.getElementsByName("Titulaire_carte")[0] && document.getElementsByName("Numero_carte")[0] && document.getElementsByName("Mois_expiration")[0]  && document.getElementsByName("Annee_expiration")[0]){
					if((document.getElementsByName("carte_credit")[0].value == "" ) || ( document.getElementsByName("Titulaire_carte")[0].value == "" ) || (document.getElementsByName("Numero_carte")[0].value == "" ) || (document.getElementsByName("Mois_expiration")[0].value == "" ) || (document.getElementsByName("Annee_expiration")[0].value == "" )){ boValidation = false; }else{ boValidation = true; }
				}
			}
		}else if( typeFormulaire == "secur" ){
			if(boValidation){
				if(document.getElementsByName("carte_credit")[0] && document.getElementsByName("Titulaire_carte")[0] && document.getElementsByName("Numero_carte")[0] && document.getElementsByName("Mois_expiration")[0]  && document.getElementsByName("Annee_expiration")[0]){
					if((document.getElementsByName("carte_credit")[0].value == "" ) || ( document.getElementsByName("Titulaire_carte")[0].value == "" ) || (document.getElementsByName("Numero_carte")[0].value == "" ) || (document.getElementsByName("Mois_expiration")[0].value == "" ) || (document.getElementsByName("Annee_expiration")[0].value == "" )){ boValidation = false; }else{ boValidation = true; }
				}
			}
		}
	}else if( typeFormulaire == "secur" ){
		if(boValidation){
			if(document.getElementsByName("carte_credit")[0] && document.getElementsByName("Titulaire_carte")[0] && document.getElementsByName("Numero_carte")[0] && document.getElementsByName("Mois_expiration")[0]  && document.getElementsByName("Annee_expiration")[0]){
				if((document.getElementsByName("carte_credit")[0].value == "" ) || ( document.getElementsByName("Titulaire_carte")[0].value == "" ) || (document.getElementsByName("Numero_carte")[0].value == "" ) || (document.getElementsByName("Mois_expiration")[0].value == "" ) || (document.getElementsByName("Annee_expiration")[0].value == "" )){ boValidation = false; }else{ boValidation = true; }
			}
		}
	}else if(typeFormulaire == "demande_secur"){
		if(document.getElementsByName('Confirme_reservation')){
			if(document.getElementsByName('Confirme_reservation')[0].checked){
				if(boValidation){
					if(document.getElementsByName("carte_credit")[0] && document.getElementsByName("Titulaire_carte")[0] && document.getElementsByName("Numero_carte")[0] && document.getElementsByName("Mois_expiration")[0]  && document.getElementsByName("Annee_expiration")[0]){
						if((document.getElementsByName("carte_credit")[0].value == "" ) || ( document.getElementsByName("Titulaire_carte")[0].value == "" ) || (document.getElementsByName("Numero_carte")[0].value == "" ) || (document.getElementsByName("Mois_expiration")[0].value == "" ) || (document.getElementsByName("Annee_expiration")[0].value == "" )){ boValidation = false; }else{ boValidation = true; }
					}
				}
			}
		}
	}

	if(boValidation && boValidationCourriel && boValidationConfirmerCourriel){
		if( document.getElementById('txtCaptcha') ){
                       if (ValidCaptcha()==false){
                                if(langue=="ang"){
                                         alert("Error in code validation.");
                                 }else{
                                         alert("Erreur dans la validation du code.");
                                 }
			}else{
				document.getElementsByName(nameForm)[0].submit();
		       }  
                }else{
                       document.getElementsByName(nameForm)[0].submit();
                }
	}else{
		if(!boValidationCourriel){
			if(langue=="ang"){ alert("Please enter a valid email."); }else{ alert("Veuillez entrer un courriel valide."); }
		}else if(!boValidationConfirmerCourriel){
			if(langue=="ang"){ alert("Anglais | Votre courriel de confirmation doit être identique.(À modifier)"); }else{ alert("Votre courriel de confirmation doit être identique.(À modifier)"); }
		}else{
			if(langue=="ang"){ alert("Please answer all the questions marked with an asterik."); }else{ alert("Merci de répondre à toutes les questions identifiées par un astérisque."); }
		}
	}
}

function IsNumeric( sText ){
	sText = sText.toString();
 	var IsNumber=true;
	if (sText.indexOf('.') > 0){
		IsNumber = false;
	}
  return IsNumber; 
}


function roundNumber(num, dec) {
	var result;
	if(!IsNumeric(num)){
		result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	}else{
		result = num + ".00";
	}
	return result;
}

function afficherTPSTVQ(){
	var intPrix = 0;
	for(var x = 0 ;  x < document.getElementsByName("Choix_forfait").length ; x++ ){
		if(document.getElementsByName("Choix_forfait")[x].checked){
			intPrix = document.getElementsByName("Choix_forfait")[x].value;
		}
	}
	if( document.getElementById("taxe_tps") && document.getElementById("taxe_tvq") && intPrix != "" ){
		var intTPS, intTVQ, intDemandeGTotal, arrayValue;
		arrayValue = intPrix.split("_");
		intPrix = arrayValue[1];
		intTPS = document.getElementById("taxe_tps").value * parseInt(intPrix);
		intTVQ = ( parseFloat(intTPS) + parseInt(intPrix) ) * document.getElementById("taxe_tvq").value;
		document.getElementById("affiche_taxe_tps").innerHTML = roundNumber(intTPS,2) + " $ CAN";
		document.getElementById("affiche_taxe_tvq").innerHTML = roundNumber(intTVQ,2) + " $ CAN";
		intDemandeGTotal = parseFloat(intTPS) + parseFloat(intTVQ) + parseInt(intPrix);
		document.getElementById("affiche_taxe_total").innerHTML = roundNumber(intDemandeGTotal,2) + " $ CAN";
		document.getElementById("montant_total").value = roundNumber(intDemandeGTotal,2);
		document.getElementById("montant_forfait").innerHTML = roundNumber(intPrix,2) + " $ CAN";
		
	}
}

function ajouterEventForfaits(){
	var objForfaits = document.getElementsByName("Choix_forfait");
	 var el;
	if(objForfaits.length > 1 ){
		for(var x = 0 ;  x < objForfaits.length ; x++ ){
			el = objForfaits[x];
			if (el.addEventListener){
			  el.addEventListener('click', afficherTPSTVQ, false);
			} else if (el.attachEvent) {
			  el.attachEvent('onclick', afficherTPSTVQ);
			}
		}
	}
}

function eMailValidationFormulaire(txt_mail){
	var mail_regexp = /^[a-zA-Z0-9]+([_|\.|-]{1}[a-zA-Z0-9]+)*@[a-zA-Z0-9]+([_|\.|-]­{1}[a-zA-Z0-9]+)*[\.]{1}(com|ca|net|org|fr|us|qc.ca|gouv.qc.ca|gc.ca)$/;
	if(mail_regexp.test(txt_mail)) { return  true; }
	else{ return  false; }
}

try {
  // Set Netscape up to run the "captureMousePosition" function whenever
  // the mouse is moved. For Internet Explorer and Netscape 6, you can capture
  // the movement a little easier.
  if (document.layers) { // Netscape
      document.captureEvents(Event.MOUSEMOVE);
      document.onmousemove = captureMousePosition;
  } else if (document.all) { // Internet Explorer
      document.onmousemove = captureMousePosition;
  } else if (document.getElementById) { // Netcsape 6
      document.onmousemove = captureMousePosition;
  }
  // Global variables
  xMousePos = 0; // Horizontal position of the mouse on the screen
  yMousePos = 0; // Vertical position of the mouse on the screen
  xMousePosMax = 0; // Width of the page
  yMousePosMax = 0; // Height of the page
} catch(err) {
  //on ignore l'erreur, pas de traitement
}

function captureMousePosition(e) {
  try {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has 
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position 
        // reflects the position from the top/left of the screen the 
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no 
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard 
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
  } catch(err) {
  //on ignore l'erreur, pas de traitement
  }
}

function afficherCourrielRaisonSocialFormulaireReservation(){
if( parent.document.getElementById("formulaire_reservation_raison_social") )  document.getElementById("formulaire_reservation_raison_social").value = parent.document.getElementById("formulaire_reservation_raison_social").value;
if( parent.document.getElementById("formulaire_reservation_courriel") )  document.getElementById("formulaire_reservation_courriel").value = parent.document.getElementById("formulaire_reservation_courriel").value;
}

function calcHauteurIframe_parent(nom_iframe)
{
var the_height
if ( parent.document.getElementById(nom_iframe).contentDocument ) // firefox
{
the_height = parent.document.getElementById(nom_iframe).contentDocument.height;
}
else // IE
{
the_height= parent.document.getElementById(nom_iframe).contentWindow.document.body.scrollHeight;
}
  //change la hauteur de l'iframe
 parent.document.getElementById(nom_iframe).height=the_height;
}


function calcHauteurDiv_parent(id_pop_up,id_contenu, ajout){
  var the_height= parent.document.getElementById(id_contenu).contentWindow.document.body.scrollHeight;
  //change la hauteur de l'iframe
  if(parent.document.getElementById(id_pop_up)) parent.document.getElementById(id_pop_up).style.height=the_height+ajout+"px";

}

