function QuelmoteurVol(x){
    calendarHREF = 'http://fr.xl.com/calendar.html';
    var theDate = new Date();
    var endDate = new Date();
    theDate1 = theDate.getDate() + '/' + (theDate.getMonth() + 1) + '/' + theDate.getFullYear();
    endDate1 = endDate.getDate() + '/' + endDate.getMonth() + '/' + endDate.getFullYear();
    if (x == 1) {
        paramCalandrierVol(theDate1, endDate1, 'moteur', 'DEPART_DD', 'DEPART_MM', 'RETOUR_DD', 'RETOUR_MM', true, true);
    }
    if (x == 2) {
        paramCalandrierVol(theDate1, endDate1, 'RechercheVol', 'DEPART_DD1', 'DEPART_MM1', 'RETOUR_DD1', 'RETOUR_MM1', true, true);
    }
}


var n = navigator, B = (n.userAgent + n.appName).toLowerCase(), V = parseInt(n.appVersion);
var N4 = (B.indexOf("netscape") != -1 && V == 4), IE = (B.indexOf("microsoft") != -1);
FF = (B.indexOf("firefox") != -1);
NT = (B.indexOf("netscape") != -1)
var calForm;
var dropDay1, dropMonth1, dropDay2, dropMonth2, dd1_H;
var calendrierActif;
var initDay, initMonth, initYear;
var jourFin, moisFin;
var numMonths;
var anyMonthVal = 0;
var anyText = "";
var calWidth = 142;
var calHeight = 182;

var bPressed, calendar;
var calendarHTML = "";
var monthNames = new Array("x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x");//placeholders
var localeMonths = "";

if (!N4) 
    document.onmouseup = function(e){
        try {
            calendar.hide();
        } 
        catch (err) {
            erreur = 1;
        }
        
        if (bPressed) {
            bPressed = false;
            VoirCalendrier(e);
        }
    }
    
var CSSinclude = "";
function parseDate(){
    var currentDate = new Date();
    var dep_date = document.getElementById('dep_date');
    var dayDropDown = document.getElementById('depDay');
    var monthDropDown = document.getElementById('depMonth');
    var depDay = dayDropDown.selectedIndex
    var depMonth = monthDropDown.selectedIndex
    if (depDay != 0 && depMonth == 0) {
        searchForm.dep_month.selectedIndex = 1;
    }
    day = dayDropDown.options[dayDropDown.selectedIndex].value;
    month = monthDropDown.options[monthDropDown.selectedIndex].value;
}

function paramCalandrierVol(dateDebut, dateFin, formName, dd1, dm1, dd2, dm2, sync, syncCal, myLocale){
    if (N4) 
        return;
    if (!document.all) 
        document.all = document.getElementsByTagName("*");
    calForm = document.forms[formName];
    dropDay1 = calForm[dd1];
    dropMonth1 = calForm[dm1];
    dropDay2 = calForm[dd2];
    dropMonth2 = calForm[dm2];
    if (dropDay1) 
        anyText = dropDay1.options[0].text;
    calendar = new LayerFrame('cIframe2');
    stPos = currpos = 0;
    
    localeMonths = '</td></tr><tr><td height="20" width="20"><b>L</b></td><td width="20"><b>M</b></td><td width="20"><b>M</b></td>\
			<td width="20"><b>J</b></td><td width="20"><b>V</b></td><td width="20"><b>S</b></td><td width="20"><b>D</b></td></tr>';
    
    initDate = dateDebut.split('/');
    //alert(initDate);
    initDay = initDate[0] * 1, initMonth = initDate[1] * 1, initYear = initDate[2];
    
    
    d = new Date()
    if (syncCal != false) {
        calDay = initDay = initDate[0] * 1;
        calMonth = initMonth = initDate[1] * 1;
        calYear = initYear = initDate[2];
    }
    else {
        calDay = d.getDate();
        calMonth = d.getMonth() + 1;
        calYear = d.getFullYear();
    }
    
    dateFin = dateFin.split('/');
    jourFin = dateFin[0] * 1, moisFin = dateFin[1] * 1;
    if (moisFin > initMonth) 
        numMonths = moisFin - initMonth + 1;
    else 
        numMonths = (12 - initMonth) + moisFin + 1;
    if (moisFin == initMonth) 
        numMonths = 1;
    var tDate_d = d.getDate();
    var tDate_M = d.getMonth() + 1;
    var tDate_y = d.getYear();
    if (tDate_y < 2000) 
        tDate_y += 1900;
    
    
    /* start on current date */
    tDate = tDate_d + '/' + tDate_M + '/' + tDate_y;
    //alert(tdate+'/'+dateDebut)
    //alert(tDate+'/'+dateDebut+'8888888888888')
    
    if (tDate != dateDebut) {
        /*if(dropMonth1)modifJour(initDay,initMonth,1);*/
        if (dropMonth2) {
            modifJour(initDay, initMonth, 2);
            calendrierActif = 1;
            syncDropdowns();
        }
    }
}

function setCalendarVol(Ncalendrier){
    bPressed = true;
    calendrierActif = Ncalendrier;
    var ops = eval('dropMonth' + Ncalendrier);
    for (i = 0; i < ops.length; i++) {
        var opVal = ops.options[i].value;
        monthNames[opVal] = ops.options[i].text;
    }
    var currMonth = getChronMonth(eval('dropMonth' + Ncalendrier).value * 1);
    if (eval('dropMonth' + Ncalendrier).value * 1 == anyMonthVal) 
        currMonth = getChronMonth(initMonth);//if on "any"
    currpos = calHeight * currMonth;
    CalendrierHtml();
    var cIframe = frames['cIframe2'];
    cIframe.document.write(calendarHTML);
    //document.getElementById("txt").value=calendarHTML;
    //document.getElementById("cIframe").contentWindow.document.body.innerHTML = calendarHTML;

    //alert(document.getElementById("txt").value);
    //cIframe.document.location.href=calendarHREF+ '?calendarHTML=' + calendarHTML;
}

function VoirCalendrier(e){
    var button = new posElement((IE) ? event.srcElement : e.target);
    posX = button.x;
    posY = button.y;
    doc_height = document.body.clientHeight + (IE ? document.body.scrollTop : 0);
    if (posY > doc_height - calHeight) 
        calendar.show(posX + 0, posY - calHeight + 10);
    else 
        calendar.show(posX + 0, posY);
}

function posElement(element){
    this.x = element.offsetLeft;
    this.y = element.offsetTop;
    var pElement = element.offsetParent;
    while (pElement && pElement.id != 'master_center') {
        this.x += pElement.offsetLeft;
        this.y += pElement.offsetTop;
        pElement = pElement.offsetParent;
    }
}

function LayerFrame(id){
    this.style = eval('document.all.' + id).style;
    this.reset = cReset;
    this.show = function(x, y){
        cReset();
        this.style.left = x + "px";
        this.style.top = y + "px";
    }
    this.hide = function(){
        this.style.top = "-2000px";
    }
    this.next = scrollDown;
    this.previous = scrollUp;
}

function cReset(){
    //cIframe.scroll(0,stPos);currpos=stPos;
    cIframe.scrollTo(0, currpos);//keep state
}

function scrollDown(){
    currpos += calHeight;
    cIframe.scrollTo(0, currpos);
}

function scrollUp(){
    currpos -= calHeight;
    if (currpos > 0) 
        cIframe.scrollTo(0, currpos);
    else {
        currpos = stPos;
        calendar.reset();
    }
}

function Ajout_date1(d_day, d_month, d_year, jours){

    var DaysOfMonths = Array(); //Nombre de jours par mois
    for (var i = 1; i <= 7; i++) {
        DaysOfMonths[i] = i % 2 ? 31 : 30;
    }
    for (var i = 8; i <= 12; i++) {
        DaysOfMonths[i] = i % 2 ? 30 : 31;
    }
    DaysOfMonths[2] = d_year % 4 ? 28 : 29; // For fevrier only
    var C_Day = parseInt(d_day) + parseInt(jours);
    var C_Month = d_month;
    var C_Year = d_year;
    while (C_Day > DaysOfMonths[C_Month]) {
    
        C_Day = C_Day - DaysOfMonths[C_Month];
        C_Month++;
        if (C_Month == 13) 
            break;
    }
    
    if (C_Month == 13) {
        C_Month = 1;
        C_Year++;
        C_Day--;
        var outputDate = Ajout_date(1, 1, C_Year, C_Day);
    }
    else 
        var outputDate = new Date(C_Year, C_Month, C_Day);
    return outputDate;
    
}

function displayDate(dt){
    try {
        calendar.hide();
    } 
    catch (err) {
        erreur = 1;
    }
    var dates = dt.split("/");
    var DMY = dt.split("/");
    var day = DMY[0];
    var month = DMY[1];
    var year = DMY[2];
    modifJour(day, month, calendrierActif, year, month, day);
    
    if (calendrierActif == 1) {
        var yu = parseInt(day) + parseInt(nbJours);
        
        var secondDate1 = Ajout_date1(day, parseInt(month), year, nbJours);
        
        //---------------------test sur le mois de novembre------------------------//
        /*var day1=secondDate1.getDate();
         if (month==11 && yu >31){
         var month1=12;
         }else {
         var month1=secondDate1.getMonth();
         }
         var year1=secondDate1.getYear();*/
        modifJour(day, month, 2, year, month, day);
    }
}

function modifJour(dv, mv, bn, d_year, d_month, d_day){

    /*jour = new Date(d_year,d_month-1,d_day).getDay();
     if(bn == 1) {
     if (jour == 0) calForm.image1.src="medias/JOURS/dimanche.gif";
     if (jour == 1) calForm.image1.src="medias/JOURS/lundi.gif";
     if (jour == 2) calForm.image1.src="medias/JOURS/mardi.gif";
     if (jour == 3) calForm.image1.src="medias/JOURS/mercredi.gif";
     if (jour == 4) calForm.image1.src="medias/JOURS/jeudi.gif";
     if (jour == 5) calForm.image1.src="medias/JOURS/vendredi.gif";
     if (jour == 6) calForm.image1.src="medias/JOURS/samedi.gif";
     }else{
     if (jour == 0) calForm.image2.src="medias/JOURS/dimanche.gif";
     if (jour == 1) calForm.image2.src="medias/JOURS/lundi.gif";
     if (jour == 2) calForm.image2.src="medias/JOURS/mardi.gif";
     if (jour == 3) calForm.image2.src="medias/JOURS/mercredi.gif";
     if (jour == 4) calForm.image2.src="medias/JOURS/jeudi.gif";
     if (jour == 5) calForm.image2.src="medias/JOURS/vendredi.gif";
     if (jour == 6) calForm.image2.src="medias/JOURS/samedi.gif";
     }
     
     if(calForm.DEPART_YYYY_H) {
     if(bn==1){
     calForm.DEPART_YYYY_H.value=d_year;
     }else{
     calForm.RETOUR_YYYY_H.value=d_year;
     }
     }else {
     if(bn==1){
     calForm.DEPART_YYYY.value=d_year;
     }else{
     calForm.RETOUR_YYYY.value=d_year;
     }
     }*/
    if (bn == 1) {
        var drDay = eval("dropDay" + bn);
        var drMonth = eval("dropMonth" + bn);
        selOptionVal(drMonth, mv);
        setDays(bn);
        selOptionVal(drDay, dv, d_year);
        
        
        
        var drDay1 = eval("dropDay2");
        var drMonth1 = eval("dropMonth2");
        selOptionVal(drMonth1, mv);
        setDays(bn);
        selOptionVal(drDay1, 35, d_year);
        
    }
    else {
        var drDay = eval("dropDay" + bn);
        var drMonth = eval("dropMonth" + bn);
        selOptionVal(drMonth, mv);
        setDays(bn);
        selOptionVal(drDay, dv, d_year);
    }
    if (calForm == document.forms['moteur']) {
        verifier_date_vol2(calForm.DEPART_DD, calForm.DEPART_MM, calForm.DEPART_YYYY, calForm.DateDebut, "D");
    }
}

function selOptionVal(ob, val, year){
    var ops = new Object();
    for (var i = 0; i < ob.length; i++) 
        ops[ob[i].value] = ob[i];
    if (ops[val]) 
        ops[val].selected = true;
    
    
    
}

function hasOptionVal(ob, val){
    var ops = new Object();
    for (var i = 0; i < ob.length; i++) 
        ops[ob[i].value] = ob[i];
    if (ops[val]) 
        return true;
    else 
        return false;
}

function getChronMonth(month){
    var cM = month - initMonth;
    return (cM < 0) ? cM + 12 : cM;
}

function CalendrierHtml(){
    calendarHTML = "";
    var currDate = new Date(Date.UTC(calYear, calMonth - 1, calDay));//yyyy/mm from 0/d from 1
    calendarHTML += '<html><head><title>Calendar</title>'
    calendarHTML += CSSinclude;
    calendarHTML += '<style type="text/css">\
		body{font-family:Verdana,sans-serif;font-size:13px;}\
		a{text-decoration:none;}\
		a.txt:hover{background-color:#b00288;}\
		td{font-family:Verdana,Helvetica,sans-serif;font-size:9px;text-align:center;color:#cccccc}\
		.white{font-family:Verdana,Helvetica,sans-serif;font-size:9px;text-align:center;color:#FFFFFF;font-weight:bold;}\
		td a{color:#000000;}\
		b{color:#000000;}\
		a.green       {color:#ffffff;font-weight:bold;}\
		a.green:hover {color:#ffffff;font-weight:bold;text-decoration:underline}\
		a.green:visited {color:#ffffff;font-weight:bold;text-decoration:underline}\
		a.green:active {color:#ffffff;font-weight:bold;text-decoration:underline}\
		.background_brand{background-color:#0a93d5;}\
		</style>\
		</head><body rightmargin="0" leftmargin="0" topmargin="0" bgcolor="FFFFFF">'
    for (i = 1; i <= 12; i++) {//For each month
        var month = currDate.getMonth() + 1;//mm is from 0
        var numDays = dateJour(month);
        var year = currDate.getYear();
        if (year < 2000) 
            year += 1900;
        
        currDate.setDate(1);//set to first of the month and get day of the week
        var firstDay = currDate.getDay() - 1;//Sun is 0 from getDay() but we run from Mon
        if (firstDay < 0) 
            firstDay = 6;
        
        //Compile HTML
        var monthHTML = '\
			<table border="0" cellspacing="0" cellpadding="0" height="150" width="140" bgcolor=0a93d5 align="center">\
			<tr bgcolor=b00288><td height="20" width="20" valign="top">';
        if (i > 1) 
            monthHTML += '<a href="javascript:top.calendar.previous();"> <img src="medias/prev.gif" hspace="2"  border="0"></a>';
        else 
            monthHTML += '<img src="medias/trans.gif" width="20" height="13" border="0">';
        
        monthHTML += '</td><td colspan="5" width="100" class="white">' + monthNames[currDate.getMonth() + 1] +
        '</td><td  width="20">';
        
        if (i < 13)//jusqu'au mois de octobre
            monthHTML += '<a href="javascript:top.calendar.next()"><img src="medias/next.gif" hspace="2"  border="0"></a>';
        else 
            monthHTML += '<img src="medias/trans.gif" hspace="2" width="20" height="20" border="0">';
        
        monthHTML += '</td></tr><tr><td height="20" width="20"><b>L</b></td><td width="20"><b>M</b></td><td width="20"><b>M</b></td>\
			<td width="20"><b>J</b></td><td width="20"><b>V</b></td><td width="20"><b>S</b></td><td width="20"><b>D</b></td></tr>';
        
        for (j = 0; j < 42; j += 7) {//for 6 week slots in month
            monthHTML += '<tr>';
            
            for (k = 1; k < 8; k++) {//for each day of week
                var slotNo = j + k;
                var countFromFirstDay = slotNo - firstDay;
                var isLink = (slotNo > firstDay) && (countFromFirstDay <= numDays);
                var preDays = (month == calMonth && countFromFirstDay < calDay);
                /*if(calendrierActif==2){
                 var M=dropMonth1.value*1,D=dropDay1.value*1;
                 var M1=getChronMonth(M),cM=getChronMonth(month);
                 preDays=(cM<M1)||(cM==M1&&countFromFirstDay<D);
                 if(M==anyMonthVal||D==0)preDays=(month==calMonth&&countFromFirstDay<calDay);//if on "any"
                 }*/
                var postDays = (month == moisFin && countFromFirstDay > 32);
                var dateToShow = (isLink) ? countFromFirstDay : '';
                
                //compile displayDate('dd/mm/yyyy') argument for link
                var dateDay = countFromFirstDay;
                var dateMonth = currDate.getMonth() + 1;
                //var dateYear=currDate.getYear();
                var dateYear = currDate.getFullYear();
                if (dateYear < 2000) {
                    dateYear = dateYear + 1900
                };
                var dateString = dateDay + "/" + dateMonth + "/" + dateYear;
                jour = new Date(dateYear, dateMonth - 1, dateDay).getDay();
                
                
                //Write table cell with link
                if (FF || NT) {
                    if (jour == 6 || jour == 0) {
                        monthHTML += '<td height="20" bgcolor="#1ab0eb" background="medias/calendrier/trans1.gif">';
                    }
                    else {
                        monthHTML += '<td height="20">';
                    }
                }
                else {
                    if (jour == 6 || jour == 0) {
                        monthHTML += '<td height="20" bgcolor="#1ab0eb" background="medias/calendrier/trans1.gif">';
                    }
                    else {
                        monthHTML += '<td height="20">';
                    }
                }
                if (isLink && !preDays && !postDays) 
                    monthHTML += '<a href="javascript:top.displayDate(\'' + dateString + '\')" class="txt">';
                monthHTML += dateToShow;
                if (isLink && !preDays && !postDays) 
                    monthHTML += '</a>';
                monthHTML += '</td>';
            }
            monthHTML += '</tr>';
        }
        monthHTML += '\
			<tr bgcolor="155a90"><td height="20"></td>\
			<td colspan="5" ><a href="javascript:top.calendar.hide()" class="green">fermer</a></td>\
			<td >&nbsp;</td></tr>\
			<tr bgcolor="155a90"><td colspan="7"><img src="medias/trans.gif" width="140" height="2"></td></tr></table>'
        
        calendarHTML += monthHTML + '</body></html>';
        currDate.setMonth(currDate.getMonth() + 1);
    }
}

function dateJour(M){
    if (M == 2) {
        var febYear = (initMonth <= 2) ? initYear : initYear * 1 + 1;
        var febDate = new Date(Date.UTC(febYear, 1, 29));//yyyy/mm from 0/d from 1
        return (febDate.getMonth() == 1) ? 29 : 28;
    }
    else 
        return (M == 9 || M == 4 || M == 6 || M == 11) ? 30 : 31;
}

//DROPDOWNS--
function setDays(Ncalendrier){
    if (N4) 
        return;
    var D = eval("dropDay" + Ncalendrier).value * 1;
    var M = eval("dropMonth" + Ncalendrier).value * 1;
    var daysDD = eval("dropDay" + Ncalendrier);
    
}

function setDates(Ncalendrier){//onchange from month dropdown
    if (N4) 
        return;
    setDays(Ncalendrier);
    calendrierActif = Ncalendrier;
    if (dropDay2) 
        syncDropdowns();
}



