// JavaScript Document

//Variable d'état
var etatdevis = 0;
var oldregion = 0;

var province=new Array();
province[0]="";
province[1]=["British-Colombia", "Alberta", "Saskatchewan", "Manitoba", "Yukon"];
province[2]=["Quebec", "Ontario", "Nova-Scotia", "New-Brunswick", "Newfoundland", "Prince-Edward-Island"];

var villeEst =new Array();
villeEst[0]="";
villeEst[1]=["Alma", "Baie Trinité", "Baie-Comeau", "Baie-St-Paul", "Beaupré", "Bonaventure", "Bromont", "Carleton", "Drummondville", "Gaspé", "Gatineau", "Grandes-Piles", "Havre-St-Pierre", "Hébertville", "Île-aux-coudres", "Île-d'Orléans", "Îles-de-la-Madeleine", "Knowlton", "La Malbaie", "La Tuque/Lac Édouard", "Lac Brome", "Lac Mégantic", "Le Bic", "Les Escoumins", "Matane", "Mingan", "Montebello", "Mont-Laurier", "Montmagny", "Montreal", "Montréal/Airport", "New-Richmond", "Notre-Dame-du-Portage", "Orford-Magog", "Percé", "Péribonka", "Portneuf", "Quebec City", "Quebec City Region", "Rimouski", "Rivière-du-Loup", "Roberval", "Rouyn-Noranda", "Sacré-Cœur", "Saguenay", "Sept-Îles", "Shawinigan", "Sherbrooke", "St-Aimé-des-Monts", "St-André-de-Kamouraska", "Ste-Adèle", "Ste-Anne-des-Monts", "Ste-Rose-du-Nord", "St-Félicien", "St-Gédéon", "St-Georges", "St-Jacques-de-Leeds", "St-Jean-de-Matha", "St-Jean-Port-Joli", "St-Mathieu-du-Parc", "St-Michel-des-Saints", "St-Paul-de-Montmigny", "St-Paulin", "St-Sauveur-des-Monts", "St-Siméon", "St-Urbain", "Tadoussac", "Tadoussac/Baie Ste Catherine", "Tremblant", "Trois-Rives", "Trois-Rivières", "Val d'or", "Wakefield"];
villeEst[2]=["Barri", "Buckhorn", "Collingwood", "Dwight", "Eagle Lake", "Gananoque", "Gore's Landing", "Guelph", "Huntsville", "Keene", "Killarney", "Kingston", "Kitchener", "London", "Manitoulin Island", "Midland", "Niagara Falls", "Niagara-on-the-Lake", "North Bay", "Orillia", "Ottawa", "Owen Sound", "Parry Sound", "Port Severn", "Ste Catharines", "Sault Ste Marie", "Thunder Bay", "Toronto", "Toronto/Airport", "Toronto/Mississauga", "Toronto/North York", "Windsor"];
villeEst[3]=["Amherst", "Annapolis Royal", "Antigonish", "Baddeck", "Bridgewater", "Chéticamp", "Digby", "Halifax", "Halifax/Airport", "Halifax/Dartmouth", "Ingonish", "Ingonish Beach", "Liscomb Mills", "Lunenberg", "New Glasgow", "Pictou", "Port Hastings", "Port Hawkesbury", "St Peters", "Sydney", "Truro", "West Bay", "Western Shore", "Yarmouth"];
villeEst[4]=["Bathurst", "Bouctouche", "Campbelton", "Caraquet", "Edmonson", "Frédéricton", "Grand Falls", "Grand-Sault", "Miramichi", "Moncton", "Moncton/Dieppe", "Sackville", "Shepody", "St-Andrew's", "St-John", "St-Martins"];
villeEst[5]=["Argentia", "Clarenville", "Corner Brook", "Cow Head", "Deer Lake", "Gander", "Lewisporte", "Main Brook", "Port aux Basques", "Rocky Harbour", "St-Anthony", "Stephenville", "St-John's", "Twillingate"];
villeEst[6]=["Cardigan", "Charlottetown", "Morell", "O'Leary", "Summerside"];

var villeOuest =new Array();
villeOuest[0]="";
villeOuest[1]=["100 Mile House", "108 Mile Ranch", "Abbotsford", "Ashcroft", "Bella Coola", "Cache Creek", "Campbell River", "Castlegar", "Clearwater", "Comox", "Cranbrook", "Egmont", "Fernie", "Field", "Gold Bridge", "Golden", "Hope", "Kamloops", "Kelowna", "Kimberly", "Lac La Hache", "Lund", "Mc Bride", "Mount Robson", "Nanaimo", "Nelson", "Osoyoos", "Parksville", "Pemberton", "Penticton", "Port Hardy", "Prince George", "Prince Rupert", "Princeton", "Quathiaski Cove", "Quesnel", "Radium Hot Springs", "Revelstoke", "Richmound", "Rossland", "Salmon Arm", "Sechelt", "Smithers", "Squamish", "Sun Peaks", "Terrace", "Tofino", "Ucluelet", "Valemount", "Vancouver", "Vancouver/Airport", "Vancouver/Burnaby", "Vernon", "Victoria", "Westbank", "Whistler", "Williams Lake", "Windermere"];
villeOuest[2]=["Banff", "Calgary", "Calgary/Airport", "Canmore", "Edmonton", "Exshaw", "Grande-Prairie", "Jasper", "Kananaskis", "Lac Louise", "Lethbridge", "Red Deer", "Waterton Park"];
villeOuest[3]=["Prince Albert", "Regina", "Saskatoon", "Swift Current"];
villeOuest[4]=["Brandon", "Winnipeg"];
villeOuest[5]=["Beaver Creek", "Dawson City", "Eagles Plaines", "Haines Jonction", "Whitehorse"];


//construction des dropdowns selon la région canadienne choisi.
function chargerProvince(region){
	if(etatdevis!=0){
		erase = window.confirm("Do you really want to change the Canadian region.\r\n This will cancel all changes made to the form in the box below.");
		if(erase == true){
			alert("Delete items.");
			//var numItem = 1;
			oldregion = document.hebergement_a_la_carte.region.selectedIndex;
			for(numItem=1; numItem<=21; numItem++){
				document.getElementById("province_" + numItem).options.length=1;
				document.getElementById("ville_" + numItem).options.length=1;
				if (region>0){
					for (i=0; i<province[region].length; i++){
					document.getElementById("province_" + numItem).options[document.getElementById("province_" + numItem).options.length] = new Option(province[region][i] , province[region][i]);
					}
				}
			}
			etatdevis = 0;
		}
		else{
			document.hebergement_a_la_carte.region.selectedIndex = oldregion;
			document.hebergement_a_la_carte.region.selected = oldregion;
			return false;
		}
	}
	else{
		var numItem = 1;
		oldregion = document.hebergement_a_la_carte.region.selectedIndex;
		for(numItem=1; numItem<=21; numItem++){
			document.getElementById("province_" + numItem).options.length=1;
			if (region>0){
				for (i=0; i<province[region].length; i++){
				document.getElementById("province_" + numItem).options[document.getElementById("province_" + numItem).options.length] = new Option(province[region][i] , province[region][i]);
				}
			}

		}
	}
}

/////////////////////------------------------------------/////////////////////

function changerEtat(){
	etatdevis = 1;
}

/////////////////////------------------------------------/////////////////////

function creerVille(province,region,id){
	if(region=="1"){
		var numVille = 1;
		province = document.getElementById(province).selectedIndex;
		document.getElementById("ville_" + id).options.length=1;
		for(numVille=1; numVille<=villeEst[province].length; numVille++){
			document.getElementById("ville_" + id).options.length=1;
			if (province>0){
				for (i=0; i<villeEst[province].length; i++){
				document.getElementById("ville_" + id).options[document.getElementById("ville_" + id).options.length] = new Option(villeEst[province][i] , villeEst[province][i]);
				}
			}
		}
		etatdevis = 1;
	}
	else{
		var numVille = 1;
		province = document.getElementById(province).selectedIndex;
		document.getElementById("ville_" + id).options.length=1;
		for(numVille=1; numVille<=villeOuest[province].length; numVille++){
			document.getElementById("ville_" + id).options.length=1;
			if (province>0){
				for (i=0; i<villeOuest[province].length; i++){
				document.getElementById("ville_" + id).options[document.getElementById("ville_" + id).options.length] = new Option(villeOuest[province][i] , villeOuest[province][i]);
				}
			}
		}
		etatdevis = 1;
	}
}


/////////////////////------------------------------------/////////////////////


function affiche_age_enfant(nombreEnfant){
	nombreEnfant = nombreEnfant;
	if(nombreEnfant != ""){
		var inputbox = 0;
		var barre = nombreEnfant - 1;
		var bla = "";
		var tableAgeEnfant = "<table width=\"100%\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
		tableAgeEnfant += "              <tr>";
		tableAgeEnfant += "                <td width=\"35%\" valign=\"top\">Age of the children*: </td>";
		tableAgeEnfant += "                <td align=\"left\" valign=\"top\" class=\"Style3\">";
		for (inputbox=1;inputbox<=nombreEnfant;++inputbox){
			//bla += inputbox + "\r";
			tableAgeEnfant += "                	<input name=\"age_enfant_"+inputbox+"\" type=\"text\" id=\"age_enfant_"+inputbox+"\" size=\"2\" maxlength=\"2\" value=\"\"  onKeyPress=\"return valid_age(event);\"> years old ";
			if (barre>= inputbox){
				tableAgeEnfant += " - ";
			}
		}
		tableAgeEnfant += "                </td>";
		tableAgeEnfant += "              </tr>";
		tableAgeEnfant += "</table>";
		document.getElementById("age_enfant").style.visibility = "visible";
	}
	else{
		var tableAgeEnfant = "";
		document.getElementById("age_enfant").style.visibility = "hidden";
	}
	
	document.getElementById("age_enfant").innerHTML = tableAgeEnfant;
}

/////////////////////------------------------------------/////////////////////

function affiche_age_adult_assurance(typeAssurance,nombreAdult){
	if (typeAssurance!=""){
		if (typeAssurance != "Ne pas inclure d'assurance dans mon devis"){
			nombreAdult = nombreAdult;
			if(nombreAdult != ""){
				var inputbox = 0;
				var barre = nombreAdult - 1;
				var bla = "";
				var tableAgeAdult = "<table width=\"100%\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
				tableAgeAdult += "              <tr>";
				tableAgeAdult += "                <td width=\"35%\" valign=\"top\">Age of the adults*: </td>";
				tableAgeAdult += "                <td align=\"left\" valign=\"top\" class=\"Style3\">";
				for (inputbox=1;inputbox<=nombreAdult;++inputbox){
					//bla += inputbox + "\r";
					tableAgeAdult += "                	<input name=\"age_adult_"+inputbox+"\" type=\"text\" id=\"age_adult_"+inputbox+"\" size=\"2\" maxlength=\"2\"  onKeyPress=\"return valid_age(event);\"> years old ";
					if (barre>= inputbox){
						tableAgeAdult += " - ";
					}
				}
				tableAgeAdult += "                </td>";
				tableAgeAdult += "              </tr>";
				tableAgeAdult += "</table>";
				document.getElementById("age_adult").style.visibility = "visible";
			}
			else{
				var tableAgeAdult = "";
				document.getElementById("age_adult").style.visibility = "hidden";
			}
		}
		else{
			var tableAgeAdult = "";
			document.getElementById("age_adult").style.visibility = "hidden";
		}
		
		
	}
	else{
			var tableAgeAdult = "";
			document.getElementById("age_adult").style.visibility = "hidden";
	}
	document.getElementById("age_adult").innerHTML = tableAgeAdult;
}

function affiche_age_adult_personne(typeAssurance,nombreAdult){
	if(nombreAdult != ""){
		if(typeAssurance!=""){
			if (typeAssurance != "Ne pas inclure d'assurance dans mon devis"){
				var inputbox = 0;
				var barre = nombreAdult - 1;
				var bla = "";
				var tableAgeAdult = "<table width=\"100%\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
				tableAgeAdult += "              <tr>";
				tableAgeAdult += "                <td width=\"35%\" valign=\"top\">Age of the adults*: </td>";
				tableAgeAdult += "                <td align=\"left\" valign=\"top\" class=\"Style3\">";
				for (inputbox=1;inputbox<=nombreAdult;++inputbox){
					//bla += inputbox + "\r";
					tableAgeAdult += "                	<input name=\"age_adult_"+inputbox+"\" type=\"text\" id=\"age_adult_"+inputbox+"\" size=\"2\" maxlength=\"2\"  onKeyPress=\"return valid_age(event);\"> years old ";
					if (barre>= inputbox){
						tableAgeAdult += " - ";
					}
				}
				tableAgeAdult += "                </td>";
				tableAgeAdult += "              </tr>";
				tableAgeAdult += "</table>";
				document.getElementById("age_adult").style.visibility = "visible";
			}
			else{
				var tableAgeAdult = "";
				document.getElementById("age_adult").style.visibility = "hidden";
			}
		}
		else{
			var tableAgeAdult = "";
			document.getElementById("age_adult").style.visibility = "hidden";
		}
	}
	else{
		var tableAgeAdult = "";
		document.getElementById("age_adult").style.visibility = "hidden";
	}
	document.getElementById("age_adult").innerHTML = tableAgeAdult;
}

/////////////////////------------------------------------/////////////////////

function validForm(){
	
	if (document.getElementById("nom").value=="") {
		alert("Please fill in the \"Name and first name\" field");
		document.getElementById("nom").focus();
		return false;
	}
	if (document.getElementById("nom").value.search(/[a-zA-Z]{2,}/)==-1) {
		alert("Please fill in the \"Email address\" field");
		document.getElementById("nom").focus();
		return false;
	}	
	
	if (document.getElementById("courriel").value=="") {
		alert("Please fill in the \"Email address\" field");
		document.getElementById("courriel").focus();
		return false;
	}
	if (document.getElementById("telephone").value=="") {
		alert("Please fill in the \"Phone number\" field");
		document.getElementById("telephone").focus();
		return false;
	}
	if (document.getElementById("pays").value=="") {
		alert("Please fill in the \"Country\" field");
		document.getElementById("pays").focus();
		return false;
	}
	if (document.getElementById("pays").value.search(/[a-zA-Z]{2,}/)==-1) {
		alert("Please fill in the \"Country\" field");
		document.getElementById("pays").focus();
		return false;
	}	
	
	//vérifie si au moins un adulte est sélectionné
	if (document.getElementById("nombredadulte").value=="") {
		alert("Please fill in the \"Age of the adults\" field");
		document.getElementById("nombredadulte").focus();
		return false;
	}
	
	//Vérifie si l'âge des enfants est inscrit selon le nombre d'enfant
	if (document.getElementById("nombredenfant").value!="") {
		var i = 0;
		var nombreenfant = document.getElementById("nombredenfant").value;
		for (i=1;i<=nombreenfant;++i){
			var caseAge = "age_enfant_"+i;
			//alert(caseAge + " dans le for");
			if(document.getElementById(caseAge).value==""){
				//alert(caseAge + " dans le if");
				alert("Please fill in the \"Age of the children\" field");
				document.getElementById(caseAge).focus();
				return false;
			}
		}
	}
	
	//vérifie le type d'occupation
	if (document.getElementById("chambre").value=="") {
		alert("Please fill in the \"Occupation type\" field");
		document.getElementById("chambre").focus();
		return false;
	}
	
	//vérifie si la personne choisit un véhicule ou non
	if (document.getElementById("vehicule").value=="") {
		alert("Please fill in the \"Your choice of vehicle\" field");
		document.getElementById("vehicule").focus();
		return false;
	}	
	if(document.getElementById("vol").value== "Inclure un vol transatlantique"){
		if(document.getElementById("ville_vol_1").value == ""){
			alert("Please fill the \"city of departure\" field for your transatlantic flight");
			document.getElementById("ville_vol_1").focus();
			return false;
		}
	}
	//Vérifie si les assurance ont été sélectionnée
	if (document.getElementById("assurance").value=="") {
		alert("Please fill in the \"Your choice of insurance\" field");
		document.getElementById("assurance").focus();
		return false;
	}
	
	//Vérifie si l'âge des adulte est inscite selon si la personne prend des assurances.
	if (document.getElementById("nombredadulte").value!="") {
		var i = 0;
		var nombreadulte = document.getElementById("nombredadulte").value;
		for (i=1;i<=nombreadulte;++i){
			var caseAge = "age_adult_"+i;
			//alert(caseAge + " dans le for");
			if(document.getElementById(caseAge).value==""){
				//alert(caseAge + " dans le if");
				alert("Please fill in the \"Age of the adults\" field");
				document.getElementById(caseAge).focus();
				return false;
			}
		}
	}	
	
	//validation de la région
	if(document.getElementById("region").value==""){
		alert("Please select a Canadian region.");
		document.getElementById("region").focus();
		return false;
	}	
	
	//Valide si la date de début de séjour est inscrite.
	if(document.getElementById("date_debut").value == ""){
		alert("Please enter the starting date of your stay.");
		document.getElementById("date_debut").focus();
		return false;
	}
	
	//valide si la première province est vide
	if(document.getElementById("province_1").value!=""){
			//vérifie les 21 étape
			for(i=1;i<=21;i++){
				//vérifie si les champ province sont vide
				if(document.getElementById("province_"+i).selectedIndex != 0){
					//Vérifie si le champ ville est vide
					if(document.getElementById("ville_"+i).selectedIndex == 0){
						alert("Please select a city.");
						document.getElementById("ville_"+i).focus();
						return false;
					}
					//Vérifie si le champ type d'hébergement est vide
					if(document.getElementById("type_hebergement_"+i).selectedIndex == 0){
						alert("Please select a type of accommodation.");
						document.getElementById("type_hebergement_"+i).focus();
						return false;
					}
					//Vérifie si le champ nombre de jour est vide
					if(document.getElementById("nbr_jour_"+i).selectedIndex == 0){
						alert("Please select a number of days.");
						document.getElementById("nbr_jour_"+i).focus();
						return false;
					}
				}
			}
	}
	else{
			alert("Please select a province.");
			document.getElementById("province_1").focus();
			return false;
	}
}
function valid_nom_prenom(evt)
{
var interdit='&*?!:;,#\'"%$£?²¤§%*()[]{}<>\\|/0123456789';
  return InterditTouches(evt, interdit);
}
function valid_age(evt)
{
var interdit='àâäãçéèêëìîïòôöõùûüñÀÂÄÃÇÉÈÊËÌÎÏÒÔÖÕÙÛÜÑ¸qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM «»°±@£¢¤¬¦²³¼½¾§¶[]}{~´­¯µ|!"/$%?&*()_+¨^>`:.()-^¸<`;,#=\'\\';
  return InterditTouches(evt, interdit);
}
function valid_mail(evt)
{
var interdit='àâäãçéèêëìîïòôöõùûüñÀÂÄÃÇÉÈÊËÌÎÏÒÔÖÕÙÛÜÑ¸ &*?!:;,#~\'"^¨%$£?²¤§%*()[]{}<>\\|/`';
  return InterditTouches(evt, interdit);
}
function valid_num(evt)
{
var interdit='àâäãçéèêëìîïòôöõùûüñÀÂÄÃÇÉÈÊËÌÎÏÒÔÖÕÙÛÜÑ¸qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM «»°±@£¢¤¬¦²³¼½¾§¶[]}{~´­¯µ|!"/$%?&*()_+¨^>`:.-^¸<`;,#=\'\\';
  return InterditTouches(evt, interdit);
}
function bSyntaxeEmail(sMail)
{
var re=/^[a-z\d]+((\.|-|_)[a-z\d]+)*@((?![-\d])[a-z\d-]{0,62}[a-z\d]\.){1,4}[a-z]{2,6}$/gi;
return (sMail.match(re)==sMail)&&(sMail.substr(sMail.lastIndexOf("@")).length<=256);
}
function valid_tel(evt)
{
var interdit='àâäãçéèêëìîïòôöõùûüñÀÂÄÃÇÉÈÊËÌÎÏÒÔÖÕÙÛÜÑ¸qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM«»°±@£¢¤¬¦²³¼½¾§¶}{~´¯µ|!"/$%?&*_¨^>`: ^¸<`;,#=\'\\';
  return InterditTouches(evt, interdit);
}



function minuscule(o)
{
o.value=o.value.toLowerCase();
}
function InterditTouches(evt, sInterdit)
{
var keyCode = evt.which ? evt.which : evt.keyCode;
  if (sInterdit.indexOf(String.fromCharCode(keyCode))>=0) return false;
}

