/* FONCTIONS POUR FORMULAIRE DE RÉSERVATIONS DES ENTÊTES DES PAGES */

function popUp(url,vwidth,vheight,scroll,name)
{
	var w = vwidth;
	var h = vheight;
	var x = (screen.width - w)/2;
	var y = (screen.height - h)/2;
	var s = scroll;
	var n = name;
	
	if (!name) {
		n = "remote";
	}

if ((s == 0) || (s == "") || (s == null)) {
	s = "no"
}
else {
	s = "yes"
}

popupWin = window.open(url, n,  'menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars='+s+',resizable=no,width='+w+',height='+h+',left='+x+',top='+y+'')
}

//Affichage des cartes de localisation des gares de VIA
/*	function StationMap(coords, addy) {
		var page = "/planner/en_plan_gare_popup.html?" + coords
//		/php/data2vars/getvars.php?action=read&lng=en&id=datamaps&code=ALDR
		var params = "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,screenX=10,screenY=10,width=500,height=550";
		window.open(page,'WinOpen',params) ;
	}*/

	//Affichage des cartes de localisation des gares de VIA
	function StationMap(coords, addy) {
		var page = coords
//		/php/data2vars/getvars.php?action=read&lng=en&id=datamaps&code=ALDR
		var params = "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,screenX=10,screenY=10,width=500,height=565";
		window.open(page,'WinOpen',params) ;
	}


// Pour faire popper une fenêtre
function PopWin(theURL,winName,features) {
	window.open(theURL,winName,features);
}

// Bug de Netscape pour le BR des années
function br(){
	if(document.layers){
		document.write("<BR>")
	}
}

function modifon(bouton){
	bouton.style.background='#C0C0C0';
	bouton.style.color='#333333';
	//this.style.background='#333333';this.style.color='#FFCC00';
}

function modifoff(bouton){
	//this.style.background='#C0C0C0';this.style.color='#333333';
	bouton.style.background='#000000';
	bouton.style.color='#FFCC00';
}


//mouseover script
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



// POUR SOUMETTRE LE FORMULAIRE AVEC DES HOVERS SUR LES IMAGES

/* Pour sélectionner la date d'aujourd'hui dans le bon menu */
/*
function selectDate(){
	var sel_aujo = new Date();
	var sel_demain = new Date();
	sel_demain.setTime(sel_aujo.getTime() + 86400000);

//	document.f.departureDay.selectedIndex = sel_demain.getDate() - 1;
//	document.f.departureMonth.selectedIndex = sel_demain.getMonth() + 1;
	
	//document.f.returnDay.selectedIndex = sel_demain.getDate();
	//document.f.returnMonth.selectedIndex = sel_demain.getMonth() + 1;	

}
*/


/* Pour calculer l'annee de depart selon le mois choisi */
function makeArray() {
	this[0] = makeArray.arguments.length ;
	for (i = 0; i<makeArray.arguments.length; i++)
	this[i+1] = makeArray.arguments[i] ;
}

var accumulate    = new makeArray( 0,31,59,90,120,151,181,212,243,273,304,334) ;
var accumulateLY  = new makeArray( 0,31,60,91,121,152,182,213,244,274,305,335) ;

/* Pour calculer annees bissextiles */
function LeapYear(year) {
	if ((year/4)   != Math.floor(year/4))   return false;
	if ((year/100) != Math.floor(year/100)) return true;
	if ((year/400) != Math.floor(year/400)) return false;
	return true;
}

/* Pour obtenir le nombre de jours écoulés depuis le 1er janvier */
function getJulian(day,month,year) {
	if (LeapYear(year))
		return (day + accumulateLY[month]);
	else
		return (day + accumulate[month]);
}

/* Calcul des dates et années pour envoyer la bonne année */
function calculerEnvoyer(f) {
	var today = new Date() ;
	var ddjour = parseInt(f.departureDay.value) ;
	var ddmois = parseInt(f.departureMonth.value) ;
	var ddannee = today.getYear() ;
	var dd = getJulian(ddjour,ddmois,ddannee) ;
	var aujourdhui = getJulian(today.getDate(), today.getMonth() + 1, today.getYear() ) ;
	if ((dd > 0) && (dd < aujourdhui)) {
		var zeDate =  (ddannee + 1) ;
		var zeDateString =  zeDate + "" ;
		var dateCroppee = zeDateString.substring(2,4) ;
//		f.dda.value = dateCroppee ;
	}
	else {
		var zeDate = today.getYear() ;
		var zeDateString =  zeDate + "" ;
		var dateCroppee =  zeDateString.substring(2,4) ;
//		f.dda.value = dateCroppee ;
	}
	return(false) ;
}

	function verifNombre(choix) {
		var totalPass = parseInt(document.f.cat_1.options[document.f.cat_1.options.selectedIndex].value) +
						parseInt(document.f.cat_2.options[document.f.cat_2.options.selectedIndex].value) +
						parseInt(document.f.cat_4.options[document.f.cat_4.options.selectedIndex].value) +
						parseInt(document.f.cat_5.options[document.f.cat_5.options.selectedIndex].value) +
						parseInt(document.f.cat_0.options[document.f.cat_0.options.selectedIndex].value) ;
		if ((choix==3) && (totalPass < 2)) {
			alert("Le nombre total de billets est de " + totalPass + " alors que\nles couchettes doubles doivent loger 2 personnes.\n");
		}
		else
		if ((choix==4) && (totalPass < 3)) {
			alert("Le nombre total de billets est de " + totalPass + " alors que\nles couchettes triples doivent loger 3 personnes.\n");
		}
	}

	function Validate (f){

	with (f){

		if (departureMonth.selectedIndex == 0){
		alert ('Veuillez S.V.P. choisir une date de départ (mois) ...')
		departureMonth.focus();
		return(false);
		}

		if (departureDay.selectedIndex == 0){
		alert ('Veuillez S.V.P. choisir une date de départ (jour) ...')
		departureDay.focus();
		return(false);
		}

		if ((departureStnCd.selectedIndex==0) || (destinationStnCd.selectedIndex==0)){
			alert('Veuillez S.V.P. choisir une gare de départ et d\'arrivée ...');
			departureStnCd.focus();
			return(false);
			}

		if ((numAdults.selectedIndex + numSeniors.selectedIndex + numStudents.selectedIndex + numChildren.selectedIndex) > 6) {
			alert('Vous avez excédé le maximum de six passagers.');
			return(false);
			}

		if ((numAdults.selectedIndex + numSeniors.selectedIndex + numStudents.selectedIndex + numChildren.selectedIndex) == 0) {
			alert('Veuillez S.V.P. choisir au moins un passager.');
			numAdults.focus();
			return(false);
			}

		if ((numAdults.selectedIndex + numSeniors.selectedIndex + numStudents.selectedIndex) == 0) {
			if (numChildren.selectedIndex > 0) {
				alert('Les enfants doivent être accompagnés par au moins un adulte.');
				return(false);
				}
			}

		if ((numAdults.selectedIndex == 0) && (numSeniors.selectedIndex == 0) && (numStudents.selectedIndex > 0) && (numChildren.selectedIndex > 0)){
			var agree = confirm("Les enfants de moins de huit ans doivent être accompagnés par leur mère ou leur père (la mère ou le père peut avoir moins de 18 ans) ou par un ADULTE (d'au moins 18 ans).\n\nLes enfants de huit à 11 ans peuvent voyager seuls s'ils sont sous la garde et la supervision d'un employé de VIA jusqu'à ce qu'ils soient accueillis par leur mère ou leur père, ou par un ADULTE désigné (d'au moins 18 ans).\n\nCliquez OK pour continuer.\nCliquez Annuler pour lire toutes les conditions.");
			if (agree) {
				numAdults.focus();
				return(true);
				}
			else {
				popUp('familles/fr_fami_enfa_noac.html',800,500,1);
				return false;
				}
			}
		}
	}

// sondage pop-under

// read cookie function
Cookies = {
	read : function(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i<ca.length;i++) {
		var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
}

var w = 500;
var h = 400;
var x = (screen.width - w)/2;
var y = (screen.height - h)/2;
//var currentURI = ""+parent.document.location;
var afficherSondage = Cookies.read("sondageVia2");

// ouvre sondage popup si cookie existe pas ET si ont est pas sur askvia.ca
/*
if ((!afficherSondage) && (currentURI.indexOf("askvia") < 0 )) {
	window.open('/fr_sondage.html', 'sondage', 'menubar=no,toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,width='+w+',height='+h+',left='+x+',top='+y+'');
	window.focus();
}
*/

function viewStationInfo(f,selected)
{
	var link = f.xml.options[selected].value ;
	document.location.href = link;
	return true;
}


