var message = "";

Aujourdhui = new Date();

var Annee = Aujourdhui.getFullYear();

var AnneeSuiv = Annee+1;

var Mois = Aujourdhui.getMonth();

var Jour = Aujourdhui.getDate()+1;

var Heures = Aujourdhui.getHours();

var Minutes = Aujourdhui.getMinutes();

var ListeMoisLibel = new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月");

var ListeJourMois = new Array("31","28","31","30","31","30","31","31","30","31","30","31");

var ListeMoisValue = new Array("01","02","03","04","05","06","07","08","09","10","11","12");

var ListeJourValue = new Array("01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31");

var ListeHeureValue = new Array("F3","F2","F1","00" );

var ListeHeureLibel = new Array("前後7日間", "前後2日間", "指定日", "指定なし" );

var ListeDestValue = new Array("","NRT","KIX" );

var ListeDestLibel = new Array("---お選びください---","成田空港","関西空港" );

if( Jour > eval(ListeJourMois[ Mois ]) )

{

	Jour = Jour - eval( ListeJourMois[Mois] ) ;

	Mois++;

	if( Mois > 11 )

	{

		Annee++ ;

		Mois = 0 ;

	}

}



if( Mois < 2 ){

	if( eval(Annee%400) == 0 ) ListeJourMois[ 1 ] = "29" ;

	else if( eval(Annee%4) == 0 && eval(Annee%100) != 0 ) ListeJourMois[ 1 ] = "29" ;

}

else {

	if( eval(AnneeSuiv%400) == 0 ) ListeJourMois[ 1 ] = "29" ;

	else if( eval(AnneeSuiv%4) == 0 && eval(AnneeSuiv%100) != 0 ) ListeJourMois[ 1 ] = "29" ;

}



var JourFin = Jour - 1;

var MoisFin = Mois + 10;

var AnneeFin = Annee ;

if( MoisFin > 11 )

{

	MoisFin = MoisFin - 12 ;

	AnneeFin = AnneeFin + 1 ;

}

if( JourFin < 1 )

{

	MoisFin = MoisFin - 1 ;

	if( MoisFin < 0 )

	{

		MoisFin = MoisFin + 12 ;

		AnneeFin = AnneeFin - 1 ;

	}

	JourFin = ListeJourMois[MoisFin] ;

}



var tabEltOk = 0 ;

var tabElt;

function RechercherIndiceElt(nomEltForm)

{

	if( tabEltOk == 0 ) {

		var nbEltForm = document.forms[0].length;

		tabElt = new Array(nbEltForm);

		for (i=0; i < nbEltForm; i++) tabElt[document.forms[0].elements[i].name] = i;

		tabEltOk = 1;

	}

	var indiceElt = nomEltForm;

	var num = tabElt[nomEltForm];

	if (isNaN(num) == false) indiceElt = num;

	return indiceElt;    

}



function DesactiveDateRetour () {

		document.forms[0].elements[RechercherIndiceElt("jourRetour")].disabled = true;

	    document.forms[0].elements[RechercherIndiceElt("moisRetour")].disabled = true;

	    document.forms[0].elements[RechercherIndiceElt("heureOuFlexibiliteRetour")].disabled = true;

		if (!document.all && !document.getElementById) {

			document.forms[0].elements[RechercherIndiceElt("jourRetour")].onfocus = skip;

			document.forms[0].elements[RechercherIndiceElt("moisRetour")].onfocus = skip;

			document.forms[0].elements[RechercherIndiceElt("heureOuFlexibiliteRetour")].onfocus = skip;

		}

}

function ReactiveDateRetour () {

	// Reactive les champs

	document.forms[0].elements[RechercherIndiceElt("jourRetour")].disabled = false;

	document.forms[0].elements[RechercherIndiceElt("moisRetour")].disabled = false;

	document.forms[0].elements[RechercherIndiceElt("heureOuFlexibiliteRetour")].disabled = false;

	if (!document.all && !document.getElementById)

	{

		document.forms[0].elements[RechercherIndiceElt("jourRetour")].onfocus = document.forms[0].elements[RechercherIndiceElt("jourRetour")].oldOnfocus;

		document.forms[0].elements[RechercherIndiceElt("moisRetour")].onfocus = document.forms[0].elements[RechercherIndiceElt("moisRetour")].oldOnfocus;

		document.forms[0].elements[RechercherIndiceElt("heureOuFlexibiliteRetour")].onfocus = document.forms[0].elements[RechercherIndiceElt("heureOuFlexibiliteRetour")].oldOnfocus;

	}

}



function majClasses() {

  var cabineNFS = document.forms[0].elements[RechercherIndiceElt("cabineNFS")].value;

  var cabine = cabineNFS.substring(0, 1);

  var ssCabine = cabineNFS.substr(1);

  document.forms[0].elements[RechercherIndiceElt("cabine")].value = cabine;

  document.forms[0].elements[RechercherIndiceElt("ssCabine")].value = ssCabine;

}



function correspondanceHeure(num) {

    var rangSelectionne;

    var radioTypeRecherche = document.forms[0].elements[RechercherIndiceElt("typeRecherche")];

    for (var i=0; i<radioTypeRecherche.length;i++) {

       if (radioTypeRecherche[i].checked) rangSelectionne=radioTypeRecherche[i].value;

    }

    if (rangSelectionne == 0){

        if (num == "21"){

            return "18";

        }else if( num == "15" ){

            return "11";

        }else{

            return "00";

        }

    }else{

        return num;

    }

}



function FlexibiliteAller(){

	var val=document.forms[0].elements[RechercherIndiceElt("heureOuFlexibiliteAller")].options[document.forms[0].elements[RechercherIndiceElt("heureOuFlexibiliteAller")].selectedIndex].value;

	var type  = val.substring(0,1);

	var numVal= val.substring(1,val.length);

	if (type=="F"){

		document.forms[0].elements[RechercherIndiceElt("nbJourFlexibiliteAller")].value=numVal;

		document.forms[0].elements[RechercherIndiceElt("heureAller")].value=0;

	}else{

		document.forms[0].elements[RechercherIndiceElt("nbJourFlexibiliteAller")].value="0";

		if (document.forms[0].elements[RechercherIndiceElt("plusOptions")].value=="PLUSOPTIONS")

			document.forms[0].elements[RechercherIndiceElt("heureAller")].value=numVal;

		else

			document.forms[0].elements[RechercherIndiceElt("heureAller")].value=correspondanceHeure(numVal);

	}

}



function FlexibiliteRetour(){ 

	var val=document.forms[0].elements[RechercherIndiceElt("heureOuFlexibiliteRetour")].options[document.forms[0].elements[RechercherIndiceElt("heureOuFlexibiliteRetour")].selectedIndex].value;

	var type  = val.substring(0,1);

	var numVal= val.substring(1,val.length);

	if (type=="F"){

		document.forms[0].elements[RechercherIndiceElt("nbJourFlexibiliteRetour")].value=numVal;

		document.forms[0].elements[RechercherIndiceElt("heureRetour")].value=0;

	}else{

		document.forms[0].elements[RechercherIndiceElt("nbJourFlexibiliteRetour")].value="0";

		if (document.forms[0].elements[RechercherIndiceElt("plusOptions")].value=="PLUSOPTIONS")

			document.forms[0].elements[RechercherIndiceElt("heureRetour")].value=numVal;

		else

			document.forms[0].elements[RechercherIndiceElt("heureRetour")].value=correspondanceHeure(numVal);

	}

}



function RechercherPlusOptions () {

       document.forms[0].elements[RechercherIndiceElt("plusOptions")].value = "PLUSOPTIONS";

       Rechercher();

}

/*

function FenetrePrecheck(largeur,hauteur) {

    newWindow = window.open("/double6/UK/infolocale.nsf/(LookupPublishedWeb)/en-1ACCU-PrecheckV7_UK?OpenDocument","newWin","width="+largeur+",height="+hauteur+",location=no,menubar=no,status=yes,scrollbars=yes,resizable=yes,directories=no,toolbar=no");

	if( (!newWindow) || (newWindow.closed) )

		alert( "Pop-ups are currently blocked by your browser.\r\nPlease modify your Internet options to allow pop-ups and continue your booking." ) ;

	else

        newWindow.focus();

}

*/

function Continuer() {

  message = "";

	var myForm = document.forms[0];

	myForm.elements[RechercherIndiceElt("plusOptions")].value = "";

	if( myForm.elements[RechercherIndiceElt("aeroportDepart")].selectedIndex == 0)

		message += "出発地をお選びください。\n";

	if( myForm.elements[RechercherIndiceElt("aeroportArrivee")].value  == "")

		message += "到着地をお選びください。\n";

	var IndexJourDepart = myForm.elements[RechercherIndiceElt("jourAller")].selectedIndex;

	var JourDepart = myForm.elements[RechercherIndiceElt("jourAller")].options[IndexJourDepart].value;

	var IndexMoisDepart = myForm.elements[RechercherIndiceElt("moisAller")].selectedIndex;

	var MoisDepart = myForm.elements[RechercherIndiceElt("moisAller")].options[IndexMoisDepart].value;

	var JourComp = Jour;

	var MoisComp = Mois + 1;

	var AnneeComp = Annee ;

	var dateComp = AnneeComp*1000000 + MoisComp*10000 + JourComp*100 ;

	var JourDepartComp = parseInt(JourDepart, 10);

	var MoisDepartComp = parseInt(MoisDepart, 10);

	var dateDepartComp = MoisDepartComp*10000 + JourDepartComp*100 ;

	if( dateDepartComp < dateComp )

		message += "ご出発日をご確認ください。ご出発の5日前前から10ヶ月先までご予約いただけます。.\n";

	if (myForm.typeTrajet[1].checked ) {

		var IndexJourRetour = myForm.elements[RechercherIndiceElt("jourRetour")].selectedIndex;

		var JourRetour = myForm.elements[RechercherIndiceElt("jourRetour")].options[IndexJourRetour].value;

		var IndexMoisRetour = myForm.elements[RechercherIndiceElt("moisRetour")].selectedIndex;

		var MoisRetour = myForm.elements[RechercherIndiceElt("moisRetour")].options[IndexMoisRetour].value;

		JourRetourComp = parseInt(JourRetour, 10);

		MoisRetourComp = parseInt(MoisRetour, 10);

		dateRetourComp = MoisRetourComp*10000 + JourRetourComp*100 ;

		if( dateDepartComp > dateRetourComp )

			message += "復路のご出発日をご確認ください。\n";

	}

	if(message != "") 

	//FenetrePrecheck(450,300);

	alert(message);

	else Rechercher();

}



function Rechercher() {

	document.forms[0].elements[RechercherIndiceElt("nbAdults")].value = parseInt( document.forms[0].elements[RechercherIndiceElt( "ADULT_NUMBER" )].value, 10 ) ;

	document.forms[0].elements[RechercherIndiceElt("nbEnfants")].value = parseInt( document.forms[0].elements[RechercherIndiceElt( "CHILD_NUMBER" )].value, 10 ) ;

	majClasses();

	FlexibiliteAller();

	FlexibiliteRetour();

	var newWindow =  window.open("", "Cybairfrance","toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,menubar=no,resizable=yes,copyhistory=no,width=850,height=700");

	if( (!newWindow) || (newWindow.closed) )

		alert( "Pop-ups are currently blocked by your browser.\r\nPlease modify your Internet options to allow pop-ups and continue your booking." ) ;

	else{

		document.forms[0].target = "Cybairfrance";

		document.forms[0].submit();

		newWindow.focus();

	}

}



function AfficheJours( champJour, champMois ) {

	var i=0, numMois=0;

	var JourChoisi = champJour.selectedIndex ;

	champJour.options.length=0;

	while( ListeMoisLibel[ numMois ] != champMois.options[ champMois.selectedIndex ].text )

	{

		numMois++ ;

	}

	for( j = 1 ; j <= ListeJourMois[numMois] ; j++)

	{

		if( j < 10 ) champJour.options[i]=new Option("0"+j,"0"+j);

		else champJour.options[i]=new Option(j,j);

		i++;

	}

	if( JourChoisi + 1 > eval(ListeJourMois[numMois]) )

		champJour.selectedIndex = 0 ;

	else

		champJour.selectedIndex = JourChoisi ;

}