// JavaScript Document
//set todays date
Now = new Date();
NowDay = Now.getDate();
NowMonth = Now.getMonth();
NowYear = Now.getYear();
if (NowYear < 2000) NowYear += 1900; //for Netscape

//function for returning how many days there are in a month including leap years
function DaysInMonth(WhichMonth, WhichYear)
{
  var DaysInMonth = 31;
  if (WhichMonth == "Apr" || WhichMonth == "Jun" || WhichMonth == "Sep" || WhichMonth == "Nov") DaysInMonth = 30;
  if (WhichMonth == "Feb" && (WhichYear/4) != Math.floor(WhichYear/4))	DaysInMonth = 28;
  if (WhichMonth == "Feb" && (WhichYear/4) == Math.floor(WhichYear/4))	DaysInMonth = 29;
  return DaysInMonth;
}

//function to change the available days in a months
function ChangeOptionDays(Which)
{
  DaysObject = eval("document.Form1." + Which + "Day");
  MonthObject = eval("document.Form1." + Which + "Month");
  YearObject = eval("document.Form1." + Which + "Year");

  Month = MonthObject[MonthObject.selectedIndex].text;
  Year = YearObject[YearObject.selectedIndex].text;

  DaysForThisSelection = DaysInMonth(Month, Year);
  CurrentDaysInSelection = DaysObject.length;
  if (CurrentDaysInSelection > DaysForThisSelection)
  {
    for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++)
    {
      DaysObject.options[DaysObject.options.length - 1] = null
    }
  }
  if (DaysForThisSelection > CurrentDaysInSelection)
  {
    for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++)
    {
      NewOption = new Option(DaysObject.options.length + 1);
      DaysObject.add(NewOption);
    }
  }
    if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;
}

//function to set options to today
function SetToToday(Which)
{
  DaysObject = eval("document.Form1." + Which + "Day");
  MonthObject = eval("document.Form1." + Which + "Month");
  YearObject = eval("document.Form1." + Which + "Year");

  YearObject[0].selected = true;
  MonthObject[NowMonth].selected = true;

  ChangeOptionDays(Which);

  DaysObject[NowDay-1].selected = true;
}

//function to write option years plus x
function WriteYearOptions(YearsAhead)
{
  line = "";
  for (i=0; i<YearsAhead; i++)
  {
    line += "<OPTION>";
    line += NowYear + i;
  }
  return line;
}

function isValidEmail(str) {

   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

function IsNotAlpha(sText)

{
   var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz-";
   var IsNotAlpha=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNotAlpha == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNotAlpha = false;
         }
      }
   return IsNotAlpha;
   }

function validateForm(theForm) {

if ((theForm.fullname.value == "") || (theForm.fullname.value == " "))
{
alert("Please enter a value for the \"Full name\" field.");
theForm.fullname.focus();
return (false);
}
//if (IsNotAlpha(theForm.fullname.value)) 
//  { 
//    alert("Invalid full name entry. Only characters are allowed.");
//    theForm.fullname.focus(); 
//    return false; 
//   }
   
if ((theForm.email.value == "") || (theForm.email.value == " "))
{
alert("Please enter a value for the \"E-mail\" field.");
theForm.email.focus();
return (false);
}

   if (!isValidEmail(theForm.email.value)) 
   { 
      alert('Invalid e-mail address.') 
      theForm.email.focus(); 
      return false; 
      }

//if ((theForm.phonedialingcode.value == "") || (theForm.phonedialingcode.value == " "))
//{
//alert("Please enter a value for the \"Phone dialling code\" field.");
//theForm.phonedialingcode.focus();
//return (false);
//}

if (!IsNumeric(theForm.phonedialingcode.value)) 
  { 
    alert("Invalid phone dialling code entry. Only numbers are allowed.");
    theForm.phonedialingcode.focus(); 
    return false; 
   }

if ((theForm.phonenumber.value == "") || (theForm.phonenumber.value == " "))
{
alert("Please enter a value for the \"Phone number\" field.");
theForm.phonenumber.focus();
return (false);
}

if (!IsNumeric(theForm.phonenumber.value)) 
  { 
    alert("Invalid phone number entry. Only numbers are allowed.");
    theForm.phonenumber.focus(); 
    return false; 
   }


//if (!IsNumeric(theForm.cellnumber.value)) 
  //{ 
  //  alert("Invalid cell number entry. Only numbers are allowed.");
   // theForm.cellnumber.focus(); 
   // return false; 
  // }

//if (!IsNumeric(theForm.faxdialingcode.value)) 
 // { 
 //   alert("Invalid fax dialling code entry. Only numbers are allowed.");
  //  theForm.faxdialingcode.focus(); 
  //  return false; 
  // }
   
if (!IsNumeric(theForm.faxnumber.value)) 
  { 
    alert("Invalid fax number entry. Only numbers are allowed.");
    theForm.faxnumber.focus(); 
    return false; 
   }

if ((theForm.adults.value == "") || (theForm.adults.value == " "))
{
alert("Please enter a value for the \"Adults\" field.");
theForm.adults.focus();
return (false);
}

if (!IsNumeric(theForm.adults.value)) 
  { 
    alert("Invalid adults entry. Only numbers are allowed.");
    theForm.adults.focus(); 
    return false; 
   }

    return true;
 
}

 var letters=' ABCÇDEFGHIJKLMNÑOPQRSTUVWXYZabcçdefghijklmnñopqrstuvwxyzàáÀÁéèÈÉíìÍÌïÏóòÓÒúùÚÙüÜ'
var numbers='1234567890'
var signs=',.:;@-\''
var mathsigns='+-=()*/'
var custom='<>#$%&?¿'

function alpha(e,allow) {
var k;
k=document.all?parseInt(e.keyCode): parseInt(e.which);
return (allow.indexOf(String.fromCharCode(k))!=-1);
}