// JavaScript Document

var arrayDestination = new Array();

var monthArray = new Array('','Jan','Fev','Mars','Avr','Mai','Juin','Juil','Aout','Sept','Oct','Nov','Dec');

function menu(idNumb, statement) {
var i=0;
	if(statement=='true') {
		for(i=0; i<arrayDestination.length; i++) {
			document.getElementById(arrayDestination[i]).style.display = 'none';
		}
	}
	else {
		for(i=0; i<arrayDestination.length; i++) {
			if(i!=idNumb) {
			document.getElementById(arrayDestination[i]).style.display = 'none';
			}
			else {
			document.getElementById(arrayDestination[idNumb]).style.display = 'block';
			}
		}
	}
}

// opens a pop up for the calendar
function popupCalendar (url,title) {
      show = window.open(url,title,"resizable=no,height=180,width=180,scrollbars=no,screenX=300,screenY=400,top=400,left=300");
}

// opens a pop up for the dispos
function popupDispo (url,title) {
      show = window.open(url,title,"resizable=yes,width=598,height=640,left=100,top=100,dependent=no,scrollbars=yes");
}

// opens a pop up for the dispos
function popupYahoo () {
		url = "http://www.yahoo.com";
		title = "yahoo";
      show = window.open(url,title,"resizable=yes,width=598,height=640,left=100,top=100,dependent=no,scrollbars=yes");
}

// popup For the printable product description.
function popupPrint(prefix,id) {
    popup = window.open(prefix+id,
                        "print",
                        "resizable=yes,width=825,height=640,left=100,top=100,dependent=no,scrollbars=yes");

}
// popup For the fiches
function popupFiche(prefix,id) {
    popup = window.open(prefix+id,
                        "print",
                        "resizable=yes,width=660,height=640,left=100,top=100,dependent=no,scrollbars=yes");

}

// general popup function
function popupSized(prefix,id,width,height,wind) {
    popup = window.open(prefix+id,
                        wind,
                        "resizable=yes,width="+width+",height="+height+",left=100,top=100,dependent=no,scrollbars=yes");
}


 function PopupLargeImage(img) {
	w=open("",'image','width=400,height=400,toolbar=no,scrollbars=yes,resizable=yes');	
	w.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><title>Fnac.com - Voyages</title></head>");
	w.document.write("<script language=javascript type=\"text/javascript\">function checksize() { if (document.images[0].complete) {  var imgX=document.images[0].width+30; var imgY=document.images[0].height+30; if(imgX>screen.width)imgX=screen.width-30;if(imgY>screen.height)imgY=screen.height-30; window.resizeTo(imgX,imgY); window.focus();} else { setTimeout('check()',250) } }</"+"script>");
	w.document.write("<body onload='checksize()' bgcolor='#000000' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0><img src='"+img+"' border=0/>");
	w.document.write("");
	w.document.write("</body></html>");
	w.document.close();
}

/******************************************/
/** Classe representant une disponibilité */
/******************************************/
/**
* Constructeur
*/
function Dispo(depCityCode, depCityLabel ,depDate, depDate2, price, nbDays, nbNigths) {
    this.depCityCode = depCityCode;
    this.depCityLabel = depCityLabel;
    // Pour l'affichage dans la combobox
    var date = depDate.split("-");
    var day = date[2];
    var month = date[1];
    var monthFr = monthArray[Number(month)];
    var year = date[0];
    this.depDate = new Array(day+" "+monthFr+" "+year);
    this.depDate2 = new Array(day+"/"+month+"/"+year);
    this.price = price;
    this.nbDays = nbDays;
    this.nbNigths = nbNigths;
}
/**
* Methode toString
*/
Dispo.prototype.toString = function() {
    return  this.depCityLabel + ' le ' + this.depDate + ' pour ' + this.price + ' &euro; - '
            + this.nbDays + ' j / ' + this.nbNigths + ' n';
}
/**
* Methode stringInValue
*/
Dispo.prototype.stringInValue = function() {
    return  this.depDate2 + '-' + this.nbDays + '-' + this.nbNigths;
}

/******************************************/
/** Classe representant une disponibilité */
/******************************************/
/**
* Constructeur
*/
function DispoLight(depCityCode, depCityLabel ,depDate, price) {
    this.depCityCode = depCityCode;
    this.depCityLabel = depCityLabel;
    // Pour l'affichage dans la combobox
    var date = depDate.split("-");
    var day = date[2];
    var month = date[1];
    var year = date[0];
    this.depDate = new Array(day+"/"+month+"/"+year);
    this.price = price;
}
/**
* Methode toString
*/
DispoLight.prototype.toString = function() {
    return  this.depCityLabel + ' le ' + this.depDate + ' pour ' + this.price + ' &euro;';
}
/**
* Methode getCity
*/
DispoLight.prototype.getCity = function() {
    return  this.depCityLabel;
}
/**
* Methode getDate
*/
DispoLight.prototype.getDate = function() {
    return  this.depDate;
}
/**
* Methode getPrice
*/
DispoLight.prototype.getPrice = function() {
    return  this.price;
}

/**************************************************************/
/** Classe representant une disponibilité avec prix détaillés */
/**************************************************************/
/**
* Constructeur
*/
function DispoDetail(depCityCode, depCityLabel ,depDate, priceAdult, priceChild, priceBaby, nbDays, nbNigths) {
    this.depCityCode = depCityCode;
    this.depCityLabel = depCityLabel;
    var date = depDate.split("-");
    var day = date[2];
    var month = date[1];
    var monthFr = monthArray[Number(month)];
    var year = date[0];
    this.depMonthYear = monthFr + " " + year;
    this.depDate = new Array(day+"/"+month+"/"+year);
    this.priceAdult = priceAdult;
    this.priceChild = priceChild;
    this.priceBaby = priceBaby;
    this.nbDays = nbDays;
    this.nbNigths = nbNigths;
}
/**
* Methode toString
*/
DispoDetail.prototype.toString = function() {
    return  this.depCityLabel + ' le ' + this.depDate + ' pour ' + this.price + ' &euro; - '
            + this.nbDays + ' j / ' + this.nbNigths + ' n';
}


function checkDate(date){

//        if((date.length==0)||(date.indexOf("jj/mm/aaaa"))) return true;
if ((date==null || date==""||(date.indexOf("jj/mm/aaaa"))!=-1)) return true;

        if(date.length<10) return false;
        ok = "1234567890/";

        for(i=0; i < date.length ;i++)
        {
        if(ok.indexOf(date.charAt(i))<0)
        {
            return (false);
        }

        }
        var jj=date.substring(0,2);
        var mm=date.substring(3,5);
        var aa=date.substring(6,10);
        var newDate=aa+"/"+mm+"/"+jj;

        var Expression = /^((((1[6-9]|[2-9]\d)\d{2})(\/|\-)(0?[13578]|1[02])(\/|\-)(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})(\/|\-)(0?[13456789]|1[012])(\/|\-)(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})(\/|\-)0?2(\/|\-)(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/;

        var objExp = new RegExp(Expression);

        if(objExp.test(newDate)==true)

            return true

        else return false;

    }
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
 function searchFormSubmit(form) {
var buffer = "";
var obj;
var lobj;
var f=document.getElementById("searchForm");
var tmp = f['dateDepart'].value;
obj = f['dateDepart']
tmp = tmp.trim();

if (!checkDate(tmp)) {
    buffer += "Veuillez corriger votre date de d\xE9part jj/mm/aaaa" ;
    lobj = obj;
}
else{

    document.getElementById('searchForm').dd.value = tmp.substring(0,2);
    document.getElementById('searchForm').dmy.value = tmp.substring(3,10);

}


buffer += "\n" ;
if (buffer!="\n") {
buffer = buffer;
alert(buffer);
lobj.focus();
return false;
} else f.submit();

}