// =============================================================================
// JavaScript Document

// Author:	Franco

// Changes:	
//  - (04/10/2008) Multi language support
//  - (24/10/2008) Fix error: Same year next month gave old date msg
//  - (31/10/2008) Date check for 30/31 and bissextile
//  - (12/11/2008) More languages
// =============================================================================
	

	var sLang    = new Array("eng","ita","fra","deu","esp","rus");
	
  var nMonth= new Array();
  nMonth[0] = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	nMonth[1] = new Array("Gen","Feb","Mar","Apr","Mag","Giu","Lug","Ago","Set","Ott","Nov","Dic");
  nMonth[2] = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
  nMonth[3] = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
  nMonth[4] = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
  nMonth[5] = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	
	var nDefNight	= 1;							// Default value for Nights Number
	var nNightMax	= 21;							// Max number of night selectable
	var nAdultMax	= 10;							// Max number of adult selectable
	var nNightSel	= 1;							// Default Nights 
	var nAdultSel	= 2;							// Default adult 
	
	var sMsgOldDate   = new Array("Warning: the date is in the paste.",
	                              "Attenzione: la data inserita � nel passato.",
	                              "Attention: la date inscrite n'est pas valable. Veuillez v�rifier.",
	                              "Achtung: Das eingegebene Datum ist ung�ltig. Bitte versuchen Sie es erneut.",
                                "Advertencia: la fecha insertada ya paso. Por favor verifique.",
                                "????????! ???? ??????? ???????????. ?????????, ??????????, ??? ???"
                                 );
	                              
	var sMsgWrongDate = new Array("Warning: the date is in wrong.",
	                              "Attenzione: la data � errata.",
	                              "Warning: the date is in wrong.",
	                              "Warning: the date is in wrong.",
	                              "Warning: the date is in wrong.",
	                              "Warning: the date is in wrong.");
	                              
	var sMsgNumAdult	= new Array("at least one adult is needed to continue",
                                "E' necessario almeno un adulto per continuare",
                                "at least one adult is needed to continue",
                                "at least one adult is needed to continue",
                                "at least one adult is needed to continue",
                                "at least one adult is needed to continue");
                                
	var sMsgNumNights	= new Array("input the number of nights to continue",
	                              "Prego , inserire il numero notti per continuare",
                                "input the number of nights to continue",
                                "input the number of nights to continue",
                                "input the number of nights to continue",
                                "input the number of nights to continue");
	                              
	var sMsgChildAge	= new Array("input children age to continue",
                                "E' necessario inserire l''et� dei bambini per continuare.",
                                "input children age to continue",
                                "input children age to continue",
                                "input children age to continue",
                                "input children age to continue");
                                
	var sMsgOccRoom		= new Array("insert at least one adult per room to continue",
	                              "E' neccassario inserire almeno un occupante per stanza per continuare.",
                                "insert at least one adult per room to continue",
                                "insert at least one adult per room to continue",
                                "insert at least one adult per room to continue",
                                "insert at least one adult per room to continue");
	                              
	var sBookNow			= new Array("BOOK NOW",
	                              "PRENOTA",
                                "RESERVEZ",
                                "BOOK NOW",
                                "BOOK NOW",
                                "BOOK NOW");
	                              
	var	sHotel				= new Array("Hotel",
	                              "Albergo",
                                "Hotel",
                                "Hotel",
                                "Hotel",
                                "Hotel");
	                              
	var sAllHotel			= new Array("All the hotels",
                                "Tutti gli alberghi",
                                "All the hotels",
                                "All the hotels",
                                "All the hotels",
                                "All the hotels");
                                
	var sArrival			= new Array("Arrival Date",
                                "Data Arrivo",
                                "Arrival Date",
                                "Arrival Date",
                                "Arrival Date",
                                "Arrival Date");
                                
	var sNights				= new Array("Nights",
                                "Notti",
                                "Nuits",
                                "Nachts",
                                "Nights",
                                "Nights");
                                
	var sAdults				= new Array("Adults",
                                "Adulti",
                                "Adults",
                                "Adults",
                                "Adults",
                                "Adults");
                                
	var sChild				= new Array("Children",
                                "Bambini",
                                "Children",
                                "Children",
                                "Children",
                                "Children");
                                
  var sImageUrl     = new Array("images/quick_reserve/prenota_ing.png",   
                                "images/quick_reserve/prenota.png",
                                "images/quick_reserve/prenota_ing.png",
                                "images/quick_reserve/prenota_ing.png",
                                "images/quick_reserve/prenota_ing.png",
                                "images/quick_reserve/prenota_ing.png");  
                                                              
  var sPromo        = new Array("Special code",
                                "Codice Sconto",
                                "Special code",
                                "Special code",
                                "Special code",
                                "Special code");	

  var sButton       = new Array("Reserve",
                                "Prenota",
                                "Reserve",
                                "Reserve",
                                "Reserve",
                                "Reserve");                              
	
	// Date 
	var data = new Date();
	var gg1, mm1 , aa1;
	gg1  = data.getDate();
	mm1  = data.getMonth();
	aa1  = data.getFullYear();
	
	//correzione necessaria per firefox
	// if (aa1 < 199) {var  aaaa=1900+aa1; }else // getFullYear fix it
		var aaaa=aa1; //per gli altri browser diversi da firefox

function frmcheck(frm) {
	if (parseInt(frm.aa.value) < aaaa) 	{
			alert (sMsgOldDate[cLang]);
			frm.aa.focus();
			return false;
	}	else {
    if (parseInt(frm.aa.value) == aaaa) {
  		if (parseInt(frm.mm.value) < mm1+1) {
  			alert (sMsgOldDate[cLang]);
  			frm.mm.focus();
  			return false;
  		}	else {
  		  if (parseInt(frm.mm.value) == mm1+1) {
    		  if (parseInt(frm.gg.value) < gg1) {
    			 alert (sMsgOldDate[cLang]);
    			 frm.gg.focus();
  			   return false;
  			  }
  		  }
      }
    }
  }
// alert(frm.gg.value+"/"+frm.mm.value+"/"+frm.aa.value);
	if(parseInt(frm.gg.value)==31){
    switch(parseInt(frm.mm.value)) {
      case 2:
      case 4:
      case 6:
      case 9:
      case 11:
        alert (sMsgWrongDate[cLang]);
        return false;
        break;
      default:
        break;
    }
  }
  if(parseInt(frm.mm.value)==2 && parseInt(frm.gg.value)>28){
    if ( (( parseInt(frm.aa.value) % 4 != 0)  ||  (parseInt(frm.aa.value) % 100 == 0))  &&  (parseInt(frm.aa.value) % 400 != 0 )) {
      alert (sMsgWrongDate[cLang]);
      return false;
    }    
  }
	var tot_adulti_pren = 0;
	var tot_camere_pren = 0;
	
	if (parseInt(frm.tot_adulti.value) < 1) {
		alert(sMsgNumAdult[cLang]);
		frm.tot_adulti.focus();
		return false;
	}
	if (!(parseInt(frm.notti_1.value) > 0)) {
		alert(sMsgNumNights[cLang]);
		frm.notti_1.focus();
		return false;
	}
	if ((parseInt(frm.tot_bambini.value)>0)&&(parseInt(frm.tot_camere.value)==1)) {
		tutto_ok = 1;
		for (i=1; i<=parseInt(frm.tot_bambini.value); i++) {
			myvar = "st1bamb" + i;
			eta = parseInt(document.getElementById(myvar).value);
			if (eta < 0) tutto_ok = 0;
		}
		if (tutto_ok==0) {
			alert(sMsgChildAge[cLang]);
			frm.st1bamb1.focus();
			return false;
		}
	}
	tot_adulti_pren 	= parseInt(frm.tot_adulti.value);
	tot_camere_pren 	= parseInt(frm.tot_camere.value);
	tot_bambini_pren 	= parseInt(frm.tot_bambini.value);
	tot_occupanti_pren 	= tot_adulti_pren + tot_bambini_pren;
	// str = "occ = " + tot_occupanti_pren + " cam = " + tot_camere_pren;
	// alert(str); // debug
	if (tot_occupanti_pren < tot_camere_pren || isNaN(tot_occupanti_pren) )	{
    alert(sMsgOccRoom[cLang]);
		frm.tot_adulti.focus();
		return false;
	}
  //debugger; // alert(frm.)
}



