// Messo in un file 21/1/2003
//<script Language="JavaScript">
//<!--
  var NombreMese= new Array("Gen","Feb","Mar","Apr","Mag","Giu","Lug","Ago","Set","Ott","Nov","Dic");
  var days= new Array();
  days[0]=31; days[1]=28; days[2]=31; days[3]=30; days[4]=31; days[5]=30; days[6]=31; days[7]=31; days[8]=30; days[9]=31; days[10]=30; days[11]=31;
  var Fecha = new Date();
  var Dia = Fecha.getDate();
  var mese= Fecha.getMonth();
  var ano= Fecha.getFullYear();
  var anoM = ano; 
  var meseM= mese;
  var DiaM = 1;
  var anoMM = anoM;
  var meseMM=meseM;
  var DiaMM = 1;
  var anoMMM = anoMM;
  var meseMMM=meseMM;
  var DiaMMM=1;
  var j = 0;

// Funzioni aggiunte da Petter in bnbritain per check email
function Trim(TRIM_VALUE)
{
	if(TRIM_VALUE.length < 1){ return""; }
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){ return "";}
	else { return TRIM_VALUE;}
} //End Function

function RTrim(VALUE)
{
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
	if(v_length < 0){return"";}

var iTemp = v_length -1;

while(iTemp > -1)
	{ 
		if(VALUE.charAt(iTemp) == w_space){ }
		else { 
				strTemp = VALUE.substring(0,iTemp +1);
				break;
			}
		iTemp = iTemp-1;
	} //End While
return strTemp;

} //End Function RTrim

function LTrim(VALUE)
{
var w_space = String.fromCharCode(32);
	if(v_length < 1){return"";}

var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length)
{
	if(VALUE.charAt(iTemp) == w_space) { }
	else {
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		 }
	iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function LTrim
  
function clearField(textField)
{
	var tv = textField.value.toString();
	var defValue = " Riscrivere la mail precedente - ";
	if(tv.toLowerCase()==defValue.toLowerCase())   { textField.select();	}
}

  
function ReqValidator(theForm)
{
  if (theForm.Surname.value == "")  {
    alert("Attenzione! Manca il cognome. Il Cognome è indispensabile per prenotare.");
    theForm.Surname.focus(); return (false); }
  if (theForm.Name.value == "")  {
    alert("Attenzione! Manca il nome. Il NOME è indispensabile per prenotare.");
    theForm.Name.focus(); return (false);  }
  if (theForm.email.value == "")  {
    alert("Attenzione! Non avete immesso l'EMAIL. L'indirizzo email è indispensabile.");
    theForm.email.focus(); return (false); }
	
	
  //if (!(theForm.email.value == theForm.email2.value))  {
  //  alert("Attenzione: controllate l'indirizzo email digitato. I due indirizzi devono essere uguali.\r\nSe volete indicare un indirizzo email secondario, usate il campo RICHIESTE SPECIALI");
  //  theForm.email.focus(); return (false);  }

 	var e1 = Trim(theForm.email.value.toLowerCase());
	var e2 = Trim(theForm.email2.value.toLowerCase());
	
  if (!(e1 == e2))  {
    alert("Attenzione: controllate l'indirizzo email digitato. I due indirizzi devono essere uguali.\r\nSe volete indicare un indirizzo email secondario, usate il campo RICHIESTE SPECIALI");
    theForm.email.focus();theForm.email2.select(); return (false);  }
	  
 if (((theForm.fromdate.value ==Dia)&&(theForm.frommonth.value ==mese)&&(theForm.fromyear.value ==ano))||((theForm.fromdate.value ==DiaM)&&(theForm.frommonth.value ==meseM)&&(theForm.fromyear.value ==anoM)))
   { alert("Attenzione! Controllate la vostra data di arrivo\r\nNon possiamo accettare richieste con data di arrivo \"OGGI\" o \"DOMANI\"\r\nperchè ci servono 24 ore per selezionare il bed and breakfast.\r\nPer prenotazioni last-minute, usate per favore il nostro servizio di prenotazione hotel");
     theForm.fromdate.focus(); return (false); }
 if (((theForm.fromdate.value < Dia) && (theForm.frommonth.value == mese) && (theForm.fromyear.value == ano))||((theForm.frommonth.value <mese)&&(theForm.fromyear.value ==ano))||(theForm.fromyear.value <ano))
  { alert("Per cortesia controlli la sua data di arrivo.\r\nQuesta data di arrivo è già passata");
    theForm.fromdate.focus(); return (false);  }
 if ((theForm.todate.value==theForm.fromdate.value)&&(theForm.tomonth.value==theForm.frommonth.value)&&(theForm.toyear.value==theForm.fromyear.value))
   { alert("Per cortesia controlli la sua data di partenza!\r\nLa data di partenza e di arrivo sono le stesse!");
     theForm.todate.focus(); return (false); }
 if (((parseInt(theForm.todate.value) <parseInt(theForm.fromdate.value))&&(theForm.tomonth.value==theForm.frommonth.value)&&(theForm.toyear.value==theForm.fromyear.value))||((parseInt(theForm.tomonth.value) <parseInt(theForm.frommonth.value))&&(theForm.toyear.value==theForm.fromyear.value))||(theForm.toyear.value <theForm.fromyear.value))
  {  alert("Per cortesia controlli la sua data di partenza.\r\nLa data di partenza è prima di quella di arrivo!");
    theForm.todate.focus(); return (false); }
 if (theForm.TotalDays.value==" - - -")
  { alert("Per cortesia controlli le date di partenza e arrivo!\r\nCi sono più di 2 mesi tra la data di arrivo e di partenza\r\nPer prenotare una sistemazione per più di due mesi, scriveteci a reservation@top-edinburgh-accommodation.com");
  	theForm.tomonth.focus(); return (false);  }
 if (theForm.TotalPerson.value==0)
  { alert("Per cortesia selezionate almeno una stanza\r\n");
  	theForm.single.focus();	return (false);  }
    
 if (theForm.cardnumber.value == "")  {
  alert("Per favore inserite il numero della vostra carta di credito.\r\nPer confermare la prenotazione i Bed and Breakfast richiedono una carta di credito.");
  theForm.cardnumber.focus(); return (false);  }

  var checkOK = "0123456789-";
  var checkStr = theForm.cardnumber.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    { allValid = false;  break;  }
    allNum += ch;  }
  if (!allValid)
  { alert("Per cortesia inserisca solo numeri nel campo \"numero di carta di credito\". \r\nNon inserite spazi, ma solo i numeri");
    theForm.cardnumber.focus(); return (false); }
 if ((theForm.cardnumber.value.length > 16)||(theForm.cardnumber.value.length < 16))  {
    alert("Attenzione, controlli per favore il numero di carta di credito. Quello immesso non è valido.\r\nPer confermare la prenotazione i Bed and Breakfast richiedono una carta di credito.\r\nI dati della vostra carta di credito saranno dati esclusivamente al Bed and Breakfast");
    theForm.cardnumber.focus(); return (false);  }
 if (((theForm.cardexp.value <=mese)&&(theForm.cardexpyear.value ==ano))||(theForm.cardexpyear.value <ano))     {
       alert("Per cortesia controlli la data di scadenza della carta di credito.\r\nUna carta di credito valida è necessaria per confermare la prenotazione.\r\nQuesta carta di credito è scaduta");
       theForm.cardexp.focus(); return (false);  }

  if (theForm.cardname.value == "")  {
    alert("Per cortesia inserisca il nome dell'intestatario della carta di credito.");
    theForm.cardname.focus();  return (false);  }
  if (theForm.address.value == "")  { alert("Per cortesia inserisca l'indirizzo dove riceve l'estratto conto della carta di credito\r\nnel campo \"INDIRIZZO\".");
    theForm.address.focus(); return (false);  }
  if (theForm.City.value == "")  { alert("Per cortesia inserisca la città.");
    theForm.City.focus(); return (false);  }
  if (theForm.ZipCode.value == "")  { alert("Per cortesia completi il suo indirizzo con il codice avviamento postale CAP.");
    theForm.ZipCode.focus(); return (false);  }
  if (theForm.Country.value == "")  { alert("Attenzione manca il paese dove lei riceve l'estratto conto della carta di credito.");
    theForm.Country.focus(); return (false);  }
  if (!theForm.terms.checked) { alert("E' indispensabile aver preso visione ed accettare le condizioni d'uso del nostro servizio per inviare la richiesta.\r\nFaccia click sul bottone per visualizzare le condizioni d'uso e poi spunti la casella apposita");
  	  theForm.terms.focus();  return (false);  }

  return (true);
}

function CalcDays() {
	if (document.MaoForm.fromyear.value==document.MaoForm.toyear.value) {
		if ((document.MaoForm.frommonth.value==document.MaoForm.tomonth.value)&&(parseInt(document.MaoForm.todate.value) >= parseInt(document.MaoForm.fromdate.value))) {
			Tot = (document.MaoForm.todate.value * 1) - (document.MaoForm.fromdate.value * 1);
			document.MaoForm.TotalDays.value= Tot;
			return (true);	  }
		if (parseInt(document.MaoForm.tomonth.value)==(parseInt(document.MaoForm.frommonth.value)+1))  {
		  if ((((document.MaoForm.fromyear.value * 1) % 4 == 0) && ((document.MaoForm.fromyear.value * 1) % 100 != 0)) || ((document.MaoForm.fromyear.value * 1) % 400 == 0)) { days[1] = 29; }
        else { days[1] =28; }
		Tot = days[(document.MaoForm.frommonth.value *1)] - (document.MaoForm.fromdate.value *1) + (document.MaoForm.todate.value * 1);
		document.MaoForm.TotalDays.value= Tot;
		return (true);	}	 }
	else
	 {  if ((parseInt(document.MaoForm.toyear.value)==((document.MaoForm.fromyear.value * 1)+1))&&(document.MaoForm.frommonth.value==11)&&(document.MaoForm.tomonth.value==0)) {
	     Tot = 31 - (document.MaoForm.fromdate.value *1) + (document.MaoForm.todate.value * 1);
        document.MaoForm.TotalDays.value = Tot; 
        return (true); }
	 }
	 document.MaoForm.TotalDays.value = " - - -";
}

function SettaFecha() {
  if (((ano%4==0)&&(ano%100!=0))||(ano%400==0)) { days[1] = 29; }
  else days[1] =28;

  if (Dia == days[mese]) {  DiaM=1; meseM=mese+1; meseMM=mese+1; meseMMM=mese+1; if (meseM==12) { meseM=0; meseMM=0; meseMMM=0; anoM=ano+1; anoMM=ano+1; anoMMM=ano+1; } }
  else DiaM= Dia+1;
    
  if (DiaM == days[meseM]) { DiaMM=1; meseMM=meseM+1; meseMMM=meseM+1; if (meseMM==12) { meseMM=0; meseMMM=0; anoMM=anoM+1; anoMMM=anoM+1; } }
  else  DiaMM=DiaM+1;
  
  if (DiaMM == days[meseMM]) { DiaMMM=1; meseMMM=meseMM+1; if (meseMMM==12) { meseMMM=0; anoMMM=anoMM+1; } }
  else
    DiaMMM=DiaMM+1; }

function RoomNumber()
 {	var Tot = 0;
	Tot += (document.MaoForm.single.value * 1);
	Tot += (document.MaoForm.doubleR.value * 1);
	Tot += (document.MaoForm.twin.value * 1);
	Tot += (document.MaoForm.treble1double.value * 1);
	Tot += (document.MaoForm.treble3single.value * 1);
	Tot += (document.MaoForm.family.value * 1);
	document.MaoForm.TotalRooms.value = Tot;
	Tot = 0;
	Tot += (document.MaoForm.single.value * 1);
	Tot += (document.MaoForm.doubleR.value * 2);
	Tot += (document.MaoForm.twin.value * 2);
	Tot += (document.MaoForm.treble1double.value * 3);
	Tot += (document.MaoForm.treble3single.value * 3);
	Tot += (document.MaoForm.family.value * 4);
	document.MaoForm.TotalPerson.value = Tot;  }
	
function opentermsPopup()
	{
		var	new_window = window.open("termini.htm", "Termsandconditions", 'toolbar=0,scrollbars=1,width=650,height=580,location=0,statusbar=0,menubar=0')
	}
function OpenNewWindow(pagina)
	{
		var	new_window = window.open(pagina, "ServInfo", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=380,height=300')
	}	
//-->
//</script>
