
// Checks if browser is Netscape 2.0x since the options array properties don't work with Netscape 2.0x
function isBrowserSupp() {
    // Get the version of the browser
    version =  parseFloat( navigator.appVersion );

    if ( ( version >= 2.0 ) && ( version < 2.1 ) && ( navigator.appName.indexOf( "Netscape" ) != -1 ) ) {
        return false;
    } else {
    return true;
    }
return true;
}

function isLeapYear(yrStr)
{
var leapYear=false;
var year = parseInt(yrStr, 10);
// every fourth year is a leap year
if (year%4 == 0) 
	{
    leapYear=true;
    // unless it's a multiple of 100
    if (year%100 == 0)
        {
        leapYear=false;
        // unless it's a multiple of 400
        if (year%400 == 0)
            {
            leapYear=true;
            }
        }
    }
return leapYear;
}


function getDaysInMonth(mthIdx, YrStr)
{
// all the rest have 31
var maxDays=31
// expect Feb. (of course)
if (mthIdx==1)
    {
    if (isLeapYear(YrStr))
        {
        maxDays=29;
        }
    else
        {
        maxDays=28;
        }
    }
// thirty days hath...
if (mthIdx==3 || mthIdx==5 || mthIdx==8 || mthIdx==10)
    {
    maxDays=30;
    }
return maxDays;
}


//the function which does some magic to the date fields
// return non-zero if it is the last day of the month
function adjustDate(mthIdx, Dt)
{
var value=0;

var today = new Date()
var theYear = parseInt(today.getYear(),10)

if (mthIdx < today.getMonth()) {
    theYear = (parseInt(today.getYear(), 10) + 1)
}
if(theYear<100){
    theYear = "19" + theYear
} else {
    if((theYear-100) < 10){
        theYear = "0" + (theYear-100)
    } else {
        theYear = (theYear-100)+""
    }
    theYear = "20" + theYear
}


var numDays=getDaysInMonth(mthIdx, theYear);

if (mthIdx==1)
    {
    if (Dt.options.selectedIndex + 1 < numDays)
        {
        return 0;
        } else {
        Dt.options.selectedIndex=numDays - 1;
        //check for leap year
        if (numDays==29)
            {
            return 99;
            } else {
            return 1;
            }
        }
    }
if (Dt.options.selectedIndex + 1 < numDays)
    {
    value=0;
    }
else
    {
    if (Dt.options.selectedIndex + 1 > numDays)
        {
        Dt.options.selectedIndex--;
        value=3;
        } else {
        //index is 31 or 30
        value=2;
        }
    }
return value;
}

    //the function which does some magic to the date fields
    // return non-zero if it is the last day of the month
    function adjustDate1( monthObj, dayObj, yearObj ) {
        var value = 0;
        var mthIdx = monthObj.options.selectedIndex;
        var Dt = dayObj;
        var theYear = yearObj.options[yearObj.options.selectedIndex].value;

        var numDays = getDaysInMonth( mthIdx, theYear );

        if( mthIdx == 1 ) {
            if( Dt.options.selectedIndex + 2 < numDays ) {
                return 0;
            } else {
                if( Dt.options.selectedIndex + 1 > numDays) {
                    Dt.options.selectedIndex=numDays - 1;
                }
                //check for leap year
                if( (Dt.options.selectedIndex + 1) == numDays ) {
                    return 1;
                } else {
                    return 4;
                }
            }
        }

        if( Dt.options.selectedIndex + 2 < numDays ) {
            value = 0;
        } else {
            if ( Dt.options.selectedIndex + 1 > numDays ) {
                Dt.options.selectedIndex--;
                value = 3;
            } else if ( Dt.options.selectedIndex + 1 == numDays ) {
                //index is 31 or 30
                value = 2;
            } else {
                value = 4;
            }
        }
        return value;
    }


//changes departure month when arrival month is changed
function amadChange(inM,inD,inY,outM,outD,outY)
{
if (!isBrowserSupp())
    {
    return;
    }

var res = adjustDate(inM.options.selectedIndex, inD);
if (res != 0)
    {
           outD.options.selectedIndex=0;
           if (outM.options.selectedIndex==11){
            outM.options.selectedIndex=0
			outY.options.selectedIndex=inY.options.selectedIndex + 1;
           } else {
            outM.options.selectedIndex=inM.options.selectedIndex + 1;
           }
    } else {
	outY.options.selectedIndex = inY.options.selectedIndex;
    outM.options.selectedIndex = inM.options.selectedIndex;
    outD.options.selectedIndex = inD.options.selectedIndex+1;
    }
return;
}

function dmddChange(outM,outD)
{
if (!isBrowserSupp())
    {
    return;
    }

adjustDate(outM.options.selectedIndex,outD);
return;
}


var espaceblanc = " \t\n\r";

function Vide(s)
{   return ((s == null) || (s.length == 0))
}

function espaceblanche (s)

{   var i;

    // Vide?
    if (Vide(s)) return true;

    for (i = 0; i < s.length; i++)
    {   
	var c = s.charAt(i);

	if (espaceblanc.indexOf(c) == -1) return false;
    }

    // tous les caractères sont espaceblanc.
    return true;
}

// Est-il un nombre?
function isNumber(strField)
{
	var statut=false
	var j = 0;

	for (j = 0; j < strField.length; j++){
		if ((strField.charAt(j) >= "0") && (strField.charAt(j) <= "9")) {
			
			statut=true;
		}}

return statut
}


// Function customer
function checkclient() {
  formpath=document.send_prebooking;
  var text1=formpath.firstname.value;
  var text2=formpath.lastname.value;
  var text3=formpath.address.value;
  var text4=formpath.city.value;
  var text5=formpath.postalcode.value;
  var strField = formpath.phone.value;
  var strField1 = formpath.fax1.value;
  // First Name
  if (espaceblanche(text1)) {
     alert ("Please enter a First Name.");
     formpath.firstname.focus();
     return false;
  }
  // Last Name
  else if (espaceblanche(text2)) {
     alert ("Please enter a Last Name.");
     formpath.lastname.focus();
     return false;
  }
  // E-Mail
  else
  
  var mail1 = formpath.mail.value;
  count=0;
  countdot=0;
  for(i=0; i<mail1.length; i++) {
  if(mail1.charAt(i)=='@')
    count++;
  if(mail1.charAt(i)=='.')
    countdot++;
  }
  if (count != '1' || countdot < '1') {
    alert ("Please enter a valid Email Address.");
    formpath.mail.focus();
    return false;
  }
  // Telephone
  else if ((!isNumber(strField)) || (espaceblanche(strField))) {
     alert ("Please enter a contact Telephone Number.");
     formpath.phone.focus();
     return false;
  }
  // Fax
  else if ((!isNumber(strField1)) || (espaceblanche(strField1))) {
     alert ("Please enter a contact Fax Number.");
     formpath.fax1.focus();
     return false;
  }
  // Address
  else if (espaceblanche(text3)) {
     alert ("Please enter an Address.");
     formpath.address.focus();
     return false;
  }
  // City
  else if (espaceblanche(text4)) {
     alert ("Please enter a City.");
     formpath.city.focus();
     return false;
  }
  // Postal Code
    else if (espaceblanche(text5)) {
     alert ("Please enter a Postal Code.");
     formpath.postalcode.focus();
     return false;
  }
  // Country
  else if (formpath.country.selectedIndex == 0) {
     alert ("Please select a Country.");
     formpath.country.focus();
     return false;
  } else {
	  return true;
  }
}

// Function Check Date
function checkform() {
    var data1,data2,d,dc,dataC,year_arr,month_arr,day_arr,d_arr,year_end,month_end,day_end,d_end,checkoutDate,checkinDate,single_nb,double_nb,date_end,data_end, dater1,dater2;

   d = new Date();
   dc = new Date(d.getFullYear(),d.getMonth(), d.getDate());
   
   year_arr = window.document.prebooking.arr_year.options[window.document.prebooking.arr_year.selectedIndex].value;
   month_arr = window.document.prebooking.arr_month.options[window.document.prebooking.arr_month.selectedIndex].value;
   day_arr = window.document.prebooking.arr_day.options[window.document.prebooking.arr_day.selectedIndex].value;
   d_arr = new Date(year_arr, month_arr-1, day_arr);
   data1 = Date.parse(d_arr);
   
   year_end = window.document.prebooking.end_year.options[window.document.prebooking.end_year.selectedIndex].value;
   month_end = window.document.prebooking.end_month.options[window.document.prebooking.end_month.selectedIndex].value;
   day_end = window.document.prebooking.end_day.options[window.document.prebooking.end_day.selectedIndex].value;
   d_end = new Date(year_end, month_end-1, day_end);
   data2 = Date.parse(d_end);

   date_end = new Date(2010, 10, 1);
   data_end = Date.parse(date_end);
   
   //ajouter pour restriction par priode
   dater1 = new Date(2010, 06, 1);
   dateL1 = Date.parse(dater1);
   dater2 = new Date(2010, 07, 31);
   dateL2 = Date.parse(dater2);
  
   
   single_nb = window.document.prebooking.nb_single.options[window.document.prebooking.nb_single.selectedIndex].value;
   double_nb = window.document.prebooking.nb_double.options[window.document.prebooking.nb_double.selectedIndex].value;

   
   dataC = Date.parse(dc);
   checkoutDate = d_end.getTime();
   checkinDate = d_arr.getTime();
	var numNights = Math.round((checkoutDate - checkinDate) / 86400000);
	
   if((data1>data_end )||(data2>data_end)){
     alert("no booking in this periode!");
     return false;
   }

   if(dataC > data1){
     alert("'Arrival date' cannot be lower than current date!");
     return false;
   }
   if (data1 >= data2){
       alert ("'Arrival date' cannot be greater than 'Departure date'");
       return false;
   }
   
   if(numNights > 28){
     alert("Please select a period of maximum 28 days!");
     return false;
   }
   //test de periode pour un minimum de 7 jour dans les mois de juillet et Août
   if((numNights < 7)&&(((data1>=dateL1 )&&(data1<=dateL2)) || ((date2>=dataL1)&&(data2<=dateL2)))){
     alert("Number of nights must be GREATER OR EQUAL to 7!");
     return false;
   }
   
   
   if((single_nb <= 0) && (double_nb <= 0)){
     alert("Please select a minimum ONE room!");
     return false;
   }

}

// Function Check Customer Information
function checkform1() {

  if (checkclient() == false) {
    return false;
  }


}

// Function Check Number of Customers
function checkform2() {

  if (checkclient() == false) {
    return false;
  }


}

// Function check number of rooms occupancy for the 1st package
function changenumber() {
	
	var single_nb,double_nb;

    formpath=document.prebooking;
	
   single_nb = formpath.nb_single.value;
   double_nb = formpath.nb_double.value;


if (single_nb >= 1) {
//Seulement 1 Adulte et 1 Enfant peuvent partager cette chambre
  switch(single_nb) {  
  	case 1:
  	if ((formpath.adults_single0.selectedIndex +1 > 1) && (formpath.child_single0.selectedIndex +1 > 2)) {
  	alert ("Only (1 Adult & 1 Child) or (2 Children) may share this accommodation");
  	formpath.child_single0.selectedIndex = 0;
  	return false;
  	}
  	break;
	
  }// end switch
}

if (double_nb >= 1) {
//Seulement 2 Adultes et 1 Enfant peuvent partager cette chambre
  if (((formpath.adults_double0.selectedIndex +1 > 2) && (formpath.child_double0.selectedIndex +1 > 2)) || ((formpath.adults_double0.selectedIndex +1 > 1) && (formpath.child_double0.selectedIndex +1 > 3))) {
  alert ("Only (2 Adults & 1 Child) or (1 Adult & 2 Children) or (3 Children) may share this accommodation");
  formpath.child_double0.selectedIndex = 0;
  return false;
  };
}


}



// Function check number of rooms occupancy for the 2nd package
function changenumber1() {
	
	var single_nb,double_nb;

    formpath=document.prebooking;
	
   single_nb = formpath.nb_single.value;
   double_nb = formpath.nb_double.value;



	

if (single_nb >= 1) {
//Seulement 1 Adulte et 1 Enfant peuvent partager cette chambre
  switch(single_nb) {  
  	case 1:
  	if ((formpath.adults_singlep0.selectedIndex +1 > 1) && (formpath.child_singlep0.selectedIndex +1 > 2)) {
  	alert ("Only (1 Adult & 1 Child) or (2 Children) may share this accommodation");
  	formpath.child_singlep0.selectedIndex = 0;
  	return false;
  	}
  	break;
	
  }// end switch
}



if (double_nb >= 1) {
//Seulement 2 Adultes et 1 Enfant peuvent partager cette chambre
  if (((formpath.adults_doublep0.selectedIndex +1 > 2) && (formpath.child_doublep0.selectedIndex +1 > 2)) || ((formpath.adults_doublep0.selectedIndex +1 > 1) && (formpath.child_doublep0.selectedIndex +1 > 3))) {
  alert ("Only (2 Adults & 1 Child) or (1 Adult & 2 Children) or (3 Children) may share this accommodation");
  formpath.child_doublep0.selectedIndex = 0;
  return false;
  };
}


}


// Function Transfert
function transfert() {
  formpath=document.send_prebooking;
  if (formpath.transfer.checked) {
	 alert ("Airport transfer costs are NOT included in the accommodation rate.\n To be paid at your arrival at the reception of the hotel.");
     formpath.comment.focus();
    return true;
   }
}

// Function Baby Cot
function babylit() {
  formpath=document.prebooking;
  if (formpath.babycot.checked) {
     alert ("The Baby Cot costs 2 EURO per night.");
    return true;
   }
}
// Function customer
function checkpolicy() {
  formpath=document.confirmation;
  if (formpath.policy.checked == false) {
    alert ("Please acknowledge reading the Terms & Conditions and accept him.");
    formpath.policy.focus();
    return false;
  }
}

