
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// A MODIFIER : LISTE DES MARCHES POSSIBLES

var tabDestiSelection = new Array();

var tabDestiLLE_MLV = new Array();
	tabDestiLLE_MLV[0] = new Object({ville:'Lille Europe',code:'LLE'});
	tabDestiLLE_MLV[1] = new Object({ville:'Paris - Marne la Vallée',code:'MLV'});
	tabDestiLLE_MLV[2] = new Object({ville:'Paris Gare de Lyon',code:'PLY'});
	
var tabDestiPM0 = new Array();
	tabDestiPM0[0] = new Object({ville:'Paris Montparnasse',code:'PMO'});
	
var tabDestiLLE_MLV_LPD = new Array();
	tabDestiLLE_MLV_LPD[0] = new Object({ville:'Lyon Part Dieu',code:'LPD'});
	tabDestiLLE_MLV_LPD[1] = new Object({ville:'Lille Europe',code:'LLE'});
	tabDestiLLE_MLV_LPD[2] = new Object({ville:'Paris - Marne la Vallée',code:'MLV'});
	tabDestiLLE_MLV_LPD[3] = new Object({ville:'Paris Gare de Lyon',code:'PLY'});
	
var tabDesti_LILLE = new Array();
	tabDesti_LILLE[0] = new Object({ville:'Aix-en-Provence',code:'AIE'});
	tabDesti_LILLE[1] = new Object({ville:'Avignon TGV',code:'AVG'});
	tabDesti_LILLE[2] = new Object({ville:'Cannes',code:'JCA'});
	tabDesti_LILLE[3] = new Object({ville:'Marseille Saint Charles',code:'MSC'});
	tabDesti_LILLE[4] = new Object({ville:'Nice ville',code:'NIC'});
	tabDesti_LILLE[5] = new Object({ville:'St Raphael Valescure',code:'XSK'});
	tabDesti_LILLE[6] = new Object({ville:'Toulon',code:'TLN'});
	
var tabDesti_LILLEMLV = new Array();
	tabDesti_LILLEMLV[0] = new Object({ville:'Aix-en-Provence',code:'AIE'});
	tabDesti_LILLEMLV[1] = new Object({ville:'Avignon TGV',code:'AVG'});
	tabDesti_LILLEMLV[2] = new Object({ville:'Cannes',code:'JCA'});
	tabDesti_LILLEMLV[3] = new Object({ville:'Lyon Part Dieu',code:'LPD'});
	tabDesti_LILLEMLV[4] = new Object({ville:'Marseille Saint Charles',code:'MSC'});
	tabDesti_LILLEMLV[5] = new Object({ville:'Nice ville',code:'NIC'});
	tabDesti_LILLEMLV[6] = new Object({ville:'St Raphael Valescure',code:'XSK'});
	tabDesti_LILLEMLV[7] = new Object({ville:'Toulon',code:'TLN'});
	
var tabDesti_LYON = new Array();
	tabDesti_LYON[0] = new Object({ville:'Cannes',code:'JCA'});
	tabDesti_LYON[1] = new Object({ville:'Nice ville',code:'NIC'});
	tabDesti_LYON[2] = new Object({ville:'Paris Gare de Lyon',code:'PLY'});
	tabDesti_LYON[3] = new Object({ville:'Paris - Marne la vallée',code:'MLV'});
	tabDesti_LYON[4] = new Object({ville:'St Raphael Valescure',code:'XSK'});
	tabDesti_LYON[5] = new Object({ville:'Toulon',code:'TLN'});

var tabDestiPLY = new Array();
	tabDestiPLY[0] = new Object({ville:'Paris Gare de Lyon',code:'PLY'});
	
var tabDestiPST = new Array();
	tabDestiPST[0] = new Object({ville:'Paris Est',code:'PST'});
	
var tabDesti_PST = new Array();
	tabDesti_PST[0] = new Object({ville:'Mulhouse',code:'AEK'});
	tabDesti_PST[0] = new Object({ville:'Strasbourg',code:'AEG'});
	
var tabDesti_PARISMONTPARNASSE = new Array();
	tabDesti_PARISMONTPARNASSE[0] = new Object({ville:'Bayonne',code:'XBY'});
	tabDesti_PARISMONTPARNASSE[1] = new Object({ville:'Biarritz',code:'BIQ'});
	tabDesti_PARISMONTPARNASSE[2] = new Object({ville:'Bordeaux St Jean',code:'BOJ'});
	tabDesti_PARISMONTPARNASSE[3] = new Object({ville:'Dax',code:'ACG'});
	tabDesti_PARISMONTPARNASSE[4] = new Object({ville:'Hendaye',code:'AEF'});
	tabDesti_PARISMONTPARNASSE[5] = new Object({ville:'La Rochelle',code:'LRH'});
	tabDesti_PARISMONTPARNASSE[6] = new Object({ville:'Niort',code:'NIT'});
	tabDesti_PARISMONTPARNASSE[7] = new Object({ville:'St Jean de Luz Ciboure',code:'XJZ'});
	tabDesti_PARISMONTPARNASSE[8] = new Object({ville:'Toulouse',code:'XYT'});
	
var tabDesti_PARISLYON = new Array();
	tabDesti_PARISLYON[0] = new Object({ville:'Aix-en-Provence',code:'AIE'});
	tabDesti_PARISLYON[1] = new Object({ville:'Annecy',code:'NCY'});
	tabDesti_PARISLYON[2] = new Object({ville:'Avignon TGV',code:'AVG'});
	tabDesti_PARISLYON[3] = new Object({ville:'Béziers',code:'BZR'});
	tabDesti_PARISLYON[4] = new Object({ville:'Cannes',code:'JCA'});
	tabDesti_PARISLYON[5] = new Object({ville:'Chambéry',code:'CMF'});
	tabDesti_PARISLYON[6] = new Object({ville:'Grenoble',code:'GNB'});
	tabDesti_PARISLYON[7] = new Object({ville:'Lyon Part Dieu',code:'LPD'});
	tabDesti_PARISLYON[8] = new Object({ville:'Lyon Perrache',code:'LPE'});
	tabDesti_PARISLYON[9] = new Object({ville:'Marseille Saint Charles',code:'MSC'});
	tabDesti_PARISLYON[10] = new Object({ville:'Montpellier',code:'MPL'});
	tabDesti_PARISLYON[11] = new Object({ville:'Nice ville',code:'NIC'});
	tabDesti_PARISLYON[12] = new Object({ville:'Nîmes',code:'FNI'});
	tabDesti_PARISLYON[13] = new Object({ville:'Perpignan',code:'PGF'});
	tabDesti_PARISLYON[14] = new Object({ville:'St Raphael Valescure',code:'XSK'});
	tabDesti_PARISLYON[15] = new Object({ville:'Toulon',code:'TLN'});

var tab = new Array();
	tab[0] = new Object({ville:'Sélectionnez',code:'PLY',tabDesti:tabDestiSelection});
	tab[1] = new Object({ville:'Agen',code:'AGF',tabDesti:tabDestiPM0});
	tab[2] = new Object({ville:'Aix-en-Provence',code:'AIE',tabDesti:tabDestiLLE_MLV});
	tab[3] = new Object({ville:'Annecy',code:'NCY',tabDesti:tabDestiPLY});
	tab[4] = new Object({ville:'Avignon TGV',code:'AVG',tabDesti:tabDestiLLE_MLV});
	tab[5] = new Object({ville:'Bayonne',code:'XBY',tabDesti:tabDestiPM0});
	tab[6] = new Object({ville:'Béziers',code:'BZR',tabDesti:tabDestiPLY});
	tab[7] = new Object({ville:'Biarritz',code:'BIQ',tabDesti:tabDestiPM0});
	tab[8] = new Object({ville:'Bordeaux St Jean',code:'BOJ',tabDesti:tabDestiPM0});
	tab[9] = new Object({ville:'Cannes',code:'JCA',tabDesti:tabDestiLLE_MLV_LPD});
	tab[10] = new Object({ville:'Chambéry',code:'CMF',tabDesti:tabDestiPLY});
	tab[11] = new Object({ville:'Dax',code:'ACG',tabDesti:tabDestiPM0});
	tab[12] = new Object({ville:'Grenoble',code:'GNB',tabDesti:tabDestiPLY});
	tab[13] = new Object({ville:'Hendaye',code:'AEF',tabDesti:tabDestiPM0});
	tab[14] = new Object({ville:'La Rochelle',code:'LRH',tabDesti:tabDestiPM0});
	tab[15] = new Object({ville:'Lille Europe',code:'LLE',tabDesti:tabDesti_LILLE});
	tab[16] = new Object({ville:'Lyon Part Dieu',code:'LPD',tabDesti:tabDesti_LYON});
	tab[17] = new Object({ville:'Lyon Perrache',code:'LPE',tabDesti:tabDestiPLY});
	tab[18] = new Object({ville:'Marseille Saint Charles',code:'MSC',tabDesti:tabDestiLLE_MLV});
	tab[19] = new Object({ville:'Montpellier',code:'MPL',tabDesti:tabDestiPLY});
	tab[20] = new Object({ville:'Mulhouse',code:'AEK',tabDesti:tabDestiPST});
	tab[21] = new Object({ville:'Nice ville',code:'NIC',tabDesti:tabDestiLLE_MLV_LPD});
	tab[22] = new Object({ville:'Nimes',code:'FNI',tabDesti:tabDestiPLY});
	tab[23] = new Object({ville:'Niort',code:'NIT',tabDesti:tabDestiPM0});
	tab[24] = new Object({ville:'Paris Est',code:'PST',tabDesti:tabDesti_PST});
	tab[25] = new Object({ville:'Paris Gare de Lyon',code:'PLY',tabDesti:tabDesti_PARISLYON});
	tab[26] = new Object({ville:'Paris Montparnasse',code:'PMO',tabDesti:tabDesti_PARISMONTPARNASSE});
	tab[27] = new Object({ville:'Paris - Marne la Vallée',code:'MLV',tabDesti:tabDesti_LILLEMLV});
	tab[28] = new Object({ville:'Paris - Aéroport Roissy CDG2',code:'MLW',tabDesti:tabDesti_LILLE});
	tab[29] = new Object({ville:'Perpignan',code:'PGF',tabDesti:tabDestiPLY});
	tab[30] = new Object({ville:'St Jean de Luz Ciboure',code:'XJZ',tabDesti:tabDestiPM0});
	tab[31] = new Object({ville:'St Raphael Valescure',code:'XSK',tabDesti:tabDestiLLE_MLV_LPD});
	tab[32] = new Object({ville:'Strasbourg',code:'AEG',tabDesti:tabDestiPST});
	tab[33] = new Object({ville:'Toulon',code:'TLN',tabDesti:tabDestiLLE_MLV_LPD});
	tab[34] = new Object({ville:'Toulouse',code:'XYT',tabDesti:tabDestiPM0});

var monthArrayCourt = ['Jan','Fev','Mar','Avr','Mai','Juin','Juil','Aout','Sept','Oct','Nov','Dec'];
function menuShow(dv) {
    var show = '';
	show += '<table cellspacing=5 style="margin-top:8px"><tr><td valign="top" class="base" align="center">';
	show += '<b>Départ</b><br />';
    show += '<select onchange="menu_B_Refresh(this.selectedIndex)" name="originStation" class="champSelectList" style="width:135px;">';
    for(var i=0; i < tab.length; i++) {
        show += '<option value="'+tab[i].code+'">'+tab[i].ville+'</option>';
    }
    show += '</select>';
			
	show += '</td><td valign="top" class="base" align="center">';
	show += '<b>Destination</b><br />';
    show += '<div id="menu_B" onChange="getDestinationStation()">';
    show += '<select name="destinationStation" onChange="getDestinationStation()" class="champSelectList" style="width:135px;">';
   
    show += '</select>';
    show += '</div>';
	show += '</td></tr></table>';
	document.getElementById('menu').innerHTML = show;
}


function menu_B_Refresh(id) {
	getOriginStation();
    var show_menuB = '';
    show_menuB += '<select name="destinationStation" onChange="getDestinationStation()" class="champSelectList" style="width:135px;">';
	
    for(var i=0; i < tab[id].tabDesti.length; i++) {
        show_menuB += '<option value="'+tab[id].tabDesti[i].code+'">'+tab[id].tabDesti[i].ville+'</option>';
    }
    show_menuB += '</select>';
   
    document.getElementById('menu_B').innerHTML = show_menuB;
	getDestinationStation();
}

function majListeDate(optionAnnee){

	if(optionAnnee==0){
		var listeDepart = document.forms["affiliation"].moisDepart;	
		var indexDepart = listeDepart.options.selectedIndex; // index de l'option sélectionnée
		
		var valeurDepart = listeDepart.options[indexDepart].value; // la valeur de l'option
		var texteDepart = listeDepart.options[indexDepart].text; // le texte de l'option
		var annee2chiffresDepart = texteDepart.substr(texteDepart.length-2,texteDepart.length);
		document.forms["affiliation"].anneeDepart.value = "20"+annee2chiffresDepart;
	}
	if(optionAnnee==1){
		var liste = document.forms["affiliation"].moisRetour;	
		var index = liste.options.selectedIndex; // index de l'option sélectionnée
		var valeur = liste.options[index].value; // la valeur de l'option
		var texte = liste.options[index].text; // le texte de l'option
		var annee2chiffres = texte.substr(texte.length-2,texte.length);
		document.forms["affiliation"].anneeRetour.value = "20"+annee2chiffres;
	}
	getJourDepart();
	getMoisDepart();
	getJourRetour();
	getMoisRetour();
}

function dateShow(dv,depart,jourDepartSelec) {
	var dateToday = new Date();
	var numToday = dateToday.getDate();
    var showDate = '';
	if(depart ==0){
		showDate += "<select name='jourDepart' class='champSelectList' onChange='majListeDate()'>";
	}else{
		showDate += "<select name='jourRetour' class='champSelectList' onChange='majListeDate()'>";
	}
	
	for(var i=1;i<32;i++){
		if(depart ==0){
			if(i == numToday){
				showDate += "<option value='"+i+"' selected>"+i+"</option>";
			}else{
				showDate += "<option value='"+i+"'>"+i+"</option>";
			}
		}else{
			if(i == jourDepartSelec){
				showDate += "<option value='"+i+"' selected>"+i+"</option>";
			}else{
				showDate += "<option value='"+i+"'>"+i+"</option>";
			}
		}
	}
	showDate += "</select>";
	if(depart ==0){
		showDate += '<input name="AvailabilitySearchInputSearchView$DropDownListMarketDay1" type="hidden" value="'+numToday+'">';
	}else{
		showDate += '<input name="AvailabilitySearchInputSearchView$DropDownListMarketDay2" type="hidden" value="'+numToday+'">';
	}
	if(depart ==0){
		document.getElementById('listeDate').innerHTML = showDate;
	}else{
		return showDate;
	}
}

function moisShow(dv,depart, moisDepartSelec, anneeDepartSelec) {
	//alert(moisDepartSelec + " //////////// " + anneeDepartSelec);
	var dateToday = new Date();
	var monthToday = dateToday.getMonth();
	var yearToday = dateToday.getFullYear();
	var yearTodayPlus1 = yearToday+1;
	
	var yearTodayCourt = yearToday.toString().substr(2,4);
	var yearTodayCourtPlus1 = yearTodayPlus1.toString().substr(2,4);
	
	var monthPlus1 = monthToday+1;
    var showMois = '';
	if(depart ==0){
		showMois += "<select name='moisDepart' class='champSelectList' onChange='majListeDate(0)'>";
	}else{
		showMois += "<select name='moisRetour' class='champSelectList' onChange='majListeDate(1)'>";
	}
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// A MODIFIER : NOMBRE DE MOIS AFFICHES EN PLUS DANS LES SELECT
	var changementAnnee = 2+7;
	// tous les mois de la même année EN COURS
	if(changementAnnee<12){ 
		for(var i2=monthToday;i2<changementAnnee;i2++){
			if(depart ==0){
				if(i2 == monthPlus1){
					showMois += "<option value='"+new Number(i2+1)+"' selected>"+monthArrayCourt[i2]+" "+yearTodayCourt+"</option>";
				}else{
					showMois += "<option value='"+new Number(i2+1)+"'>"+monthArrayCourt[i2]+" "+yearTodayCourt+"</option>";
				}
			}else{
				if(i2 == moisDepartSelec-1){
					showMois += "<option value='"+new Number(i2+1)+"' selected>"+monthArrayCourt[i2]+" "+yearTodayCourt+"</option>";
				}else{
					showMois += "<option value='"+new Number(i2+1)+"'>"+monthArrayCourt[i2]+" "+yearTodayCourt+"</option>";
				}
			}
		}
	}else{
	// Si mois d'une autre année
		for(var i2=monthToday;i2<=changementAnnee;i2++){
		
			if(i2<12){
				// MOIS DE LA MEME ANNEE
				if(depart ==0){
					if(i2 == monthPlus1){
					
						showMois += "<option value='"+new Number(i2+1)+"' selected>"+monthArrayCourt[i2]+" "+yearTodayCourt+"</option>";
					}else{
						showMois += "<option value='"+new Number(i2+1)+"'>"+monthArrayCourt[i2]+" "+yearTodayCourt+"</option>";
					}
				}else{
					if(i2 == moisDepartSelec-1){
						showMois += "<option value='"+new Number(i2+1)+"' selected>"+monthArrayCourt[(i2)]+" "+yearTodayCourt+"</option>";
					}else{
						showMois += "<option value='"+new Number(i2+1)+"'>"+monthArrayCourt[(i2)]+" "+yearTodayCourt+"</option>";
					}
				}
			}else{
				// MOIS DE L ANNEE D APRES
				var newMois = i2-11;
				
				if(depart == 0){
					if(newMois == monthPlus1){
						//alert(monthPlus1 +"//////BOUCLE FIN//////"+ moisDepartSelec);
						showMois += "<option value='"+new Number(newMois)+"' selected>"+monthArrayCourt[newMois-1]+" "+yearTodayCourtPlus1+"</option>";
					}else{
						showMois += "<option value='"+new Number(newMois)+"'>"+monthArrayCourt[newMois-1]+" "+yearTodayCourtPlus1+"</option>";
					}
				}else{
					//alert(newMois +"//////BOUCLE FIN//////"+ moisDepartSelec);
					if(newMois == moisDepartSelec){
						showMois += "<option value='"+new Number(newMois)+"' selected>"+monthArrayCourt[newMois-1]+" "+yearTodayCourtPlus1+"</option>";
					}else{
						showMois += "<option value='"+new Number(newMois)+"'>"+monthArrayCourt[newMois-1]+" "+yearTodayCourtPlus1+"</option>";
					}
				}
			}
		}
	}

	showMois += '</select>';
	if(depart == 0){
		showMois += '<select name="anneeDepart" class="champSelectList" style="display:none">';
	}else{
		showMois += '<select name="anneeRetour" class="champSelectList" style="display:none">';
	}
	showMois += '<option value="'+yearToday+'">'+yearToday+'</option>';
	showMois += '<option value="'+yearTodayPlus1+'">'+yearTodayPlus1+'</option>';
	showMois += '</select>';
	if(depart == 0){
		showMois += '<input name="AvailabilitySearchInputSearchView$DropDownListMarketMonth1" type="hidden" value="'+yearToday+'-'+(monthPlus1+1)+'">';
	}else{
		showMois += '<input name="AvailabilitySearchInputSearchView$DropDownListMarketMonth2" type="hidden" value="'+anneeDepartSelec+'-'+moisDepartSelec+'">';
	}
	if(depart ==0){
		document.getElementById('listeMois').innerHTML = showMois;
	}
	
	getJourDepart();
	getMoisDepart();
	getJourRetour();
	getMoisRetour();
	
	if(depart == 1){
		return showMois;
	}
}


function majAnnee(dv){
	
	var liste = document.forms["affiliation"].moisDepart;	
	var index = liste.options.selectedIndex; // index de l'option sélectionnée
	 
	var valeur = liste.options[index].value // la valeur de l'option
	var texte = liste.options[index].text; // le texte de l'option
	var annee2chiffres = texte.substr(texte.length-2,texte.length);
	document.forms["affiliation"].anneeDepart.value = "20"+annee2chiffres;
	displayCalendarSelectBox(document.forms['affiliation'].anneeDepart,document.forms['affiliation'].moisDepart,document.forms['affiliation'].jourDepart,false,false,this);
}
