function checkNum(field) {
var valid = "0123456789"	// Determine allowable characters
var ok = "yes";
var temp;

// check for numbers in the field
for (var i=0; i<field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);

if  (valid.indexOf(temp) == "-1") ok = "no";
}
//If numbers are input, display error message
if (ok == "no") {
alert("Please insert a number only.");
field.focus();
field.select();
   }
 }

function formatCurrency(num)
{

num = num.toString().replace(/\$|\,/g,'');

if(isNaN(num)) num = "0";

	cents = Math.floor((num*100+0.5)%100);
	num = Math.floor((num*100+0.5)/100).toString();
if(cents < 10) cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
return (String.fromCharCode(163) + num + "." + cents);
}

//bookingform will not be submitted where false is returned
function SetReturn()
{
return(false);
}

function SetForm2( text1, text2)
{
	(text2.value=text1.value);
}


function checkChoice(num, Onlinecost, Onlinetotal, Cost, Total, View)
{

  if ( num.value == "")
    {
    Onlinetotal.value = 0;
    Total.value= 0;
    return("");
    }
  else
  if (isNaN(num.value))
    {
    Onlinetotal.value = 0;
    Total.value= 0;
    return("");
   }
  else
  {
  if ( num.value != "")
    {
    Onlinetotal.value = eval(num.value) * eval (Onlinecost.value);
    Total.value= eval(num.value) * eval(Cost.value);

    return(formatCurrency(Total.value));
      
    }
}
}

function getTotal()
{

document.bookingform.CostsCalculated.value = "calculated";
var Total = eval(document.bookingform.AdultOnlineTotal.value) + eval(document.bookingform.SeniorOnlineTotal.value) + eval(document.bookingform.ChildrenOnlineTotal.value) + eval(document.bookingform.UnderSixOnlineTotal.value);

var OnlineTotal = eval(document.bookingform.AdultTotal.value) + eval(document.bookingform.SeniorTotal.value) + eval(document.bookingform.ChildrenTotal.value) + eval(document.bookingform.UnderSixTotal.value);


if (Total == 0)
  {
    document.bookingform.ReqTotalCost.value=formatCurrency(OnlineTotal);
    TotalSavings=( Total - OnlineTotal );
			//document.bookingform.TotalSavings.value=(TotalSavings);
    document.bookingform.hiddenOnlineTotal.value=OnlineTotal;
  }
else
  {
  document.bookingform.ReqTotalCost.value=formatCurrency(OnlineTotal);
  TotalSavings=( Total - OnlineTotal );
		//document.bookingform.TotalSavings.value=(TotalSavings);
  document.bookingform.hiddenOnlineTotal.value=OnlineTotal;
  }
}

//set todays date
Now = new Date();
//NowYear = Now.getYear();
NowYear = Now.getUTCFullYear();

function WriteYearOptions(YearsAhead)
{
  line = "";
  for (i=0; i<YearsAhead; i++)
  {
    line += "<OPTION value='";
    line += NowYear + i;
    line += "'>";
    line += NowYear + i;
  }
  return line;
}

//added 28/02/07
function checkOrder()
{

	var result = false;
		var Total= document.form2.Total.value;
		var CheckTotal = eval(document.bookingform.AdultOnlineTotal.value) + eval(document.bookingform.SeniorOnlineTotal.value) + eval(document.bookingform.ChildrenOnlineTotal.value) + eval(document.bookingform.UnderSixOnlineTotal.value) ;
		var Adult = document.form2.AdultsNumF2.value;
		var Seniors = document.form2.SeniorNumF2.value;
		var Unders = document.form2.UnderSixNumF2.value;
		var Children = document.form2.ChildrenNumF2.value;
		if (document.bookingform.CostsCalculated.value == "calculated")
		{
			if (( Adult == "") && (Seniors == "") && (Unders == "") && (Children == ""))
			{
				alert("Please enter the number of tickets required for each type of person.");
			}
			else
			{
				result = true;
			}
		}
		else
		{	
			alert("Please calculate the tour cost.");
			var result = false;	
		}



return result;

}


//check required fields
function checkrequired(which)
{
var pass=true;
var total = eval(document.bookingform.AdultOnlineTotal.value) + eval(document.bookingform.SeniorOnlineTotal.value) + eval(document.bookingform.ChildrenOnlineTotal.value) + eval(document.bookingform.UnderSixOnlineTotal.value);

if (document.images)
{
  for (i=0;i<which.length;i++)
  {
  var tempobj=which.elements[i];

    if (tempobj.name.substring(0,3)=="Req")
    {
    if (((tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="hidden")&&
    tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
    tempobj.selectedIndex==0))
      {
      pass=false;
      break;
      }
    }
  }
}

if (!pass)
{
	shortFieldName=tempobj.name.substring(3,30).toUpperCase();
	alert("Please make sure the "+shortFieldName+" field was properly completed.");
	return(false);
}
else
  if (pass)
  {
    if (document.bookingform.hiddenOnlineTotal.value == 0)
    {
	alert("Total order must not be zero. Please total the order before you submit the booking form.");
	return(false);
    }
    else
    //alert("total" + total + "bookingform.hiddenOnlineTotal.value" + bookingform.hiddenOnlineTotal.value);
    if ( total != document.bookingform.hiddenOnlineTotal.value)
    {
    alert("Please total the final order before you complete the booking.");
	return(false);
    }
  }
else
return(true);
}


//function to change the available days in a months
function ChangeOptionDays(Which)
{
  DaysObject = eval("document.form2." + Which + "Day");
  MonthObject = eval("document.form2." + Which + "Month");
  YearObject = eval("document.form2." + Which + "Year");
  TimeObject=eval("document.form2." + Which + "Time");

  Month = MonthObject[MonthObject.selectedIndex].text;
  Year = YearObject[YearObject.selectedIndex].text;


  NoDaysInMonth = DaysInMonth(Month);
  CurrentDaysInSelection = DaysObject.length;

  if (CurrentDaysInSelection > NoDaysInMonth)
  {
    for (i=0; i<(CurrentDaysInSelection-NoDaysInMonth); i++)
    {
      DaysObject.options[DaysObject.options.length - 1] = null
    }
  }
  if (NoDaysInMonth > CurrentDaysInSelection)
  {
    for (i=0; i<(NoDaysInMonth-CurrentDaysInSelection); i++)
    {
      NewOption = new Option(DaysObject.options.length + 1);
      DaysObject.add(NewOption);
    }
  }
    if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;
}

//function for returning how many days there are in a month including leap years
function DaysInMonth(WhichMonth)
{
  var DaysInMonth = 31;

  if (WhichMonth == "Apr" || WhichMonth == "Jun" || WhichMonth == "Sep") DaysInMonth = 30;
  if (WhichMonth == "Nov") DaysInMonth = 16;

  return DaysInMonth;
}

function DeCalculate()
{
	document.bookingform.CostsCalculated.value = "";
}