// Messo in un file 12/7/2005
//<script Language="JavaScript">
//<!--
  var NombreMese= new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
  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 = "    - Retype above email - ";
	if(tv.toLowerCase()==defValue.toLowerCase())   { textField.select();	}
}
 
  
function ReqValidator(theForm)
{
  if (theForm.Surname.value == "")  {
    alert("Please enter a value for the \"Surname\" field.");
    theForm.Surname.focus(); return (false); }
  if (theForm.Name.value == "")  {
    alert("Please enter a value for the \"First name\" field.");
    theForm.Name.focus(); return (false);  }
  if (theForm.email.value == "")  {
    alert("Please enter a value for the \"E-mail\" field.");
    theForm.email.focus(); return (false); }
	
	
 // if (!(theForm.email.value == theForm.email2.value))  {
 //   alert("Please check e-mail: you retyped a different address.\r\nIf you wish to specify an alternative e-mail, use the \"Special Needs\" field");
 //   theForm.email.focus(); return (false);  }
 
 	var e1 = Trim(theForm.email.value.toLowerCase());
	var e2 = Trim(theForm.email2.value.toLowerCase());
	
  if (!(e1 == e2))  {
    alert("Please check e-mail: you retyped a different address.\r\nIf you wish to specify an alternative e-mail, use the \"Special Needs\" field");
    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("Please check your arrival date!\r\nWe can not accept requests with arrival date \"Today\" or \"Tomorrow\"\r\nbecause we need at least 24 hours to find suitable accommodation.\r\nFor last minute booking, please use the real-time hotel search engine");
     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("Please check your arrival date\r\nThis arrival date is already gone");
    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("Please check your departure date!\r\nYour departure and arrival date are the same!");
     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("Please check your departure date\r\nDeparture date is before arrival date!");
    theForm.todate.focus(); return (false); }
 if (theForm.TotalDays.value==" - - -")
  { alert("Please check your departure date!\r\nThere are more than 2 months between your arrival and departure dates\r\nTo book an accommodation for more than 2 months please write us at reservation@top-edinburgh-accommodation.com");
  	theForm.tomonth.focus(); return (false);  }
 if (theForm.TotalPerson.value==0)
  { alert("Please select at least one room\r\n");
  	theForm.single.focus();	return (false);  }
    
 if (theForm.cardnumber.value == "")  {
  alert("Please enter a value for the \"Cardnumber\" field.\r\nTo make a reservation a credit card is required");
  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("Please enter only digit characters in the \"cardnumber\" field. \r\nSpaces are not allowed");
    theForm.cardnumber.focus(); return (false); }
 if ((theForm.cardnumber.value.length > 16)||(theForm.cardnumber.value.length < 16))  {
    alert("Please check the credit card number you typed as it appears to be not valid\r\nTo make a reservation a valid credit card is required\r\nPlease enter a valid credit card code");
    theForm.cardnumber.focus(); return (false);  }
 if (((theForm.cardexp.value <=mese)&&(theForm.cardexpyear.value ==ano))||(theForm.cardexpyear.value <ano))     {
       alert("Please check credit card expiry date\r\nA valid credit card is required to make a reservation\r\nThis appears to be already expired!!");
       theForm.cardexp.focus(); return (false);  }

  if (theForm.cardname.value == "")  {
    alert("Please enter a value for the \"Card Name\" field.");
    theForm.cardname.focus();  return (false);  }
  if (theForm.address.value == "")  { alert("Please enter the billing address of your credit card\r\nin the \"Street\" field.");
    theForm.address.focus(); return (false);  }
  if (theForm.City.value == "")  { alert("Please enter a value for the \"City\" field.");
    theForm.City.focus(); return (false);  }
  if (theForm.ZipCode.value == "")  { alert("Please enter a value for the \"Zip code\" field.");
    theForm.ZipCode.focus(); return (false);  }
  if (theForm.Country.value == "")  { alert("Please enter a value for the \"Country\" field.");
    theForm.Country.focus(); return (false);  }
  if (!theForm.terms.checked) { alert("You must accept the terms and conditions of the contract to submit your request");
  	  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("terms.htm", "Termsandconditions", 'toolbar=0,scrollbars=1,width=650,height=580,location=0,statusbar=0,menubar=0')
	}	
//-->
//</script>