<!--
// Over The Falls Tours Book-a-Tour Script
// 2007-04-06: copy changes by AURORA (Doug K.) per email request from Jaci Whitney dated Tue., 04/03/2007 @ 11:24am

// This section computes the total tour fare
function Compute(bookIt) {
	
  var adPrice  =   0.00		// Adult Fare Initialized
  var adPrice1 = 189.95 	// Adult Fare - T7:Premier
  var adPrice2 =  79.95		// Adult Fare - T3:Royal Canadian
  var adPrice3 =  79.95		// Adult Fare - T2:All American
  var adPrice4 =  79.95		// Adult Fare - T6:Royal Canadian Illumination
  var adPrice5 =  79.95		// Adult Fare - T5:All American Illumination
  var adPrice6 =  82.95		// Adult Fare - Royal Canadian Escape
  var adPrice7 =  69.95		// Adult Fare - Canadian & American
  var adPrice8 =  69.95		// Adult Fare - Canadian & American Illumination
  var adPrice9 =   0.00		// Adult Fare - Niagara-on-the-Lake
	
  var chPrice  =   0.00	 	// Child Fare Initialized
  var chPrice1 = 129.95 	// Child Fare - T7:Premier
  var chPrice2 =  49.95	 	// Child Fare - T3:Royal Canadian
  var chPrice3 =  49.95	 	// Child Fare - T2:All American
  var chPrice4 =  49.95	 	// Child Fare - T6:Royal Canadian Illumination
  var chPrice5 =  49.95	 	// Child Fare - T5:All American Illumination
  var chPrice6 =  52.95	 	// Child Fare - Royal Canadian Escape
  var chPrice7 =  42.95	 	// Child Fare - Canadian & American
  var chPrice8 =  42.95	 	// Child Fare - Canadian & American Illumination
  var chPrice9 =   0.00		// Child Fare - Niagara-on-the-Lake
	
  var lcPrice  =   0.00		// LapChild Fare
  var discount =   0.100	// Discount
  
	if (bookIt.elements[13].selectedIndex == 1) {adPrice = adPrice1; chPrice = chPrice1;}
  if (bookIt.elements[13].selectedIndex == 2) {adPrice = adPrice2; chPrice = chPrice2;}
  if (bookIt.elements[13].selectedIndex == 3) {adPrice = adPrice3; chPrice = chPrice3;}
  if (bookIt.elements[13].selectedIndex == 4) {adPrice = adPrice4; chPrice = chPrice4;}
  if (bookIt.elements[13].selectedIndex == 5) {adPrice = adPrice5; chPrice = chPrice5;}
  if (bookIt.elements[13].selectedIndex == 6) {adPrice = adPrice6; chPrice = chPrice6;}
  if (bookIt.elements[13].selectedIndex == 7) {adPrice = adPrice7; chPrice = chPrice7;}
  if (bookIt.elements[13].selectedIndex == 8) {adPrice = adPrice8; chPrice = chPrice8;}
  if (bookIt.elements[13].selectedIndex == 9) {adPrice = adPrice9; chPrice = chPrice9;}
	
  nSubTotal = ((bookIt.elements[14].value * adPrice) + (bookIt.elements[15].value * chPrice) + (bookIt.elements[16].value * lcPrice));
  bookIt.elements[17].value = Format(nSubTotal);
  
	nDiscount = (nSubTotal * discount);
  bookIt.elements[18].value = Format(nDiscount);
  
	nTotal = (nSubTotal - nDiscount);
  bookIt.elements[19].value = Format(nTotal);
}

// This section formats all extensions and order totals
function Format(expr) {return "$" + expr.toFixed(2);}
// This section performs math rounding and sets certain numeric values to 2 decimal places
function Round(expr,decplaces) {
  var str = "" + Math.round(eval(expr) * Math.pow(10,decplaces));
  while (str.length <= decplaces) {str = "0" + str;}
  var decpoint = str.length - decplaces;
  return str.substring(0,decpoint) + "." + str.substring(decpoint, str.length);
}

// This section validates certain form elements before processing order
function CheckForm(bookIt) {
  //Your Name element test
  if (!document.bookIt.Name.value || isblank(document.bookIt.Name.value)) {
    alert("Part I - Personal Contact Information\n\nPlease enter Your Name.");
    document.bookIt.Name.value = "";
    document.bookIt.Name.focus();
    return false;
  }
  if (splCharsA(document.bookIt.Name.value)) {
    alert("Part I - Personal Contact Information\n\nYour Name cannot contain special characters.");
    document.bookIt.Name.focus();
    return false;
  }
  if (oneSpace(document.bookIt.Name.value)) {
    alert("Part I - Personal Contact Information\n\nPlease enter your First and Last Name.");
    document.bookIt.Name.focus();
    return false;
  }
  //Citizenship element test
  if (!document.bookIt.Citizen.value || isblank(document.bookIt.Citizen.value)) {
    alert("Part I - Personal Contact Information\n\nPlease enter your Citizenship.");
    document.bookIt.Citizen.value = "";
    document.bookIt.Citizen.focus();
    return false;
  }
  if (splCharsB(document.bookIt.Citizen.value)) {
    alert("Part I - Personal Contact Information\n\nCitizenship cannot contain special characters.");
    document.bookIt.Citizen.focus();
    return false;
  }
  //Phone Number element test
  if (!document.bookIt.Phone.value || isblank(document.bookIt.Phone.value)) {
    alert("Part I - Personal Contact Information\n\nPlease enter your Phone Number.");
    document.bookIt.Phone.value = "";
    document.bookIt.Phone.focus();
    return false;
  }
  if (splCharsC(document.bookIt.Phone.value)) {
    alert("Part I - Personal Contact Information\n\nPhone Number is not formatted correctly.");
    document.bookIt.Phone.focus();
    return false;
  }
  //Email Address element test
  if (!document.bookIt.email.value || isblank(document.bookIt.email.value)) {
    alert("Part I - Personal Contact Information\n\nPlease enter your Email address.");
    document.bookIt.email.value = "";
    document.bookIt.email.focus();
    return false;
  }
  if (splCharsD(document.bookIt.email.value)) {
    alert("Part I - Personal Contact Information\n\nEmail address is not formatted correctly.");
    document.bookIt.email.focus();
    return false;
  }
  //Time of Tour element test
  if (document.bookIt.TourTime.selectedIndex == 0) {
    alert("Part II - Tour Information\n\nPlease select Time of Tour.");
    document.bookIt.TourTime.focus();
    return false;
  }
  //Type of Tour element test
  if (document.bookIt.TourType.selectedIndex == 0) {
    alert("Part II - Tour Information\n\nPlease select Type of Tour.");
    document.bookIt.TourType.focus();
    return false;
  }
  //Adults element test
  if (!document.bookIt.Adults.value || isblank(document.bookIt.Adults.value)) {
    alert("Part II - Tour Information\n\nPlease enter Number of Adult passengers.");
    document.bookIt.Adults.value = "";
    document.bookIt.Adults.focus();
    return false;
  }
  if (splCharsE(document.bookIt.Adults.value)) {
    alert("Part II - Tour Information\n\nNumber of Adult passengers must be numeric.");
    document.bookIt.Adults.value = "";
    document.bookIt.Adults.focus();
    return false;
  }
  //Children element test
  if (!document.bookIt.Children.value || isblank(document.bookIt.Children.value)) {
    alert("Part II - Tour Information\n\nPlease enter Number of Child passengers.");
    document.bookIt.Children.value = "";
    document.bookIt.Children.focus();
    return false;
  }
  if (splCharsE(document.bookIt.Children.value)) {
    alert("Part II - Tour Information\n\nNumber of Child passengers must be numeric.");
    document.bookIt.Children.value = "";
    document.bookIt.Children.focus();
    return false;
  }
  //Lap Children element test
  if (!document.bookIt.LapChildren.value || isblank(document.bookIt.LapChildren.value)) {
    alert("Part II - Tour Information\n\nPlease enter Number of Lap Child passengers.");
    document.bookIt.LapChildren.value = "";
    document.bookIt.LapChildren.focus();
    return false;
  }
  if (splCharsE(document.bookIt.LapChildren.value)) {
    alert("Part II - Tour Information\n\nNumber of Lap Child passengers must be numeric.");
    document.bookIt.LapChildren.value = "";
    document.bookIt.LapChildren.focus();
    return false;
  }
  var totPass = (document.bookIt.Adults.value * 1) + (document.bookIt.Children.value * 1) + (document.bookIt.LapChildren.value * 1);
  if (totPass > 19) {
    alert("Due to the large number of passengers in your party, you qualify\n" +
          "for our special Group Tour rates.\n\n" +
          "Please call our Group Tours' Office, toll free 877-783-8900,\n" +
          "Monday through Friday from 9:00 A.M. to 5:00 P.M. EST,\n" +
          "or e-mail us at groupinfo@overthefallstours.com.\n\n" +
          "We look forward to accommodating your special needs.");
    return false;
  }
  //Pickup Country element test
  if (document.bookIt.PickupCountry[0].checked == false && document.bookIt.PickupCountry[1].checked == false) {
    alert("Part III - Point of Pickup Information\n\nPlease select American Side or Canadian Side.");
    return false;
  }
  //Method of Payment element test
  if (document.bookIt.Payment[0].checked == false && document.bookIt.Payment[1].checked == false) {
    alert("Part IV - Method of Payment\n\nPlease select Cash or Credit Card.");
    return false;
  }
  //Name on Credit Card element test
  if (!document.bookIt.ccName.value || isblank(document.bookIt.ccName.value)) {
    alert("Part IV - Method of Payment\n\nPlease enter Name (as it appears on credit card).");
    document.bookIt.ccName.value = "";
    document.bookIt.ccName.focus();
    return false;
  }
  if (splCharsA(document.bookIt.ccName.value)) {
    alert("Part IV - Method of Payment\n\nPlease enter Name (as it appears on credit card).");
    document.bookIt.ccName.focus();
    return false;
  }
  if (oneSpace(document.bookIt.ccName.value)) {
    alert("Part IV - Method of Payment\n\nPlease enter Name (as it appears on credit card).");
    document.bookIt.ccName.focus();
    return false;
  }
  //Credit Card No. element test
  if (!document.bookIt.ccNumber.value || isblank(document.bookIt.ccNumber.value)) {
    alert("Part IV - Method of Payment\n\nPlease enter Credit Card No. without spaces or dashes/hyphens.");
    document.bookIt.ccNumber.value = "";
    document.bookIt.ccNumber.focus();
    return false;
  }
  if (document.bookIt.ccNumber.value.length < 13) {
    alert("Part IV - Method of Payment\n\nPlease enter Credit Card No. without spaces or dashes/hyphens.");
    document.bookIt.ccNumber.focus();
    return false;
  }
  if (splCharsE(document.bookIt.ccNumber.value)) {
    alert("Part IV - Method of Payment\n\nPlease enter Credit Card No. without spaces or dashes/hyphens.");
    document.bookIt.ccNumber.focus();
    return false;
  }
  //Expiration Date element test
  if (!document.bookIt.ccExpiration.value || isblank(document.bookIt.ccExpiration.value)) {
    alert("Part IV - Method of Payment\n\nPlease enter Expiration Date in mm/yy format.");
    document.bookIt.ccExpiration.value = "";
    document.bookIt.ccExpiration.focus();
    return false;
  }
  if (splCharsF(document.bookIt.ccExpiration.value)) {
    alert("Part IV - Method of Payment\n\nPlease enter Expiration Date in mm/yy format.");
    document.bookIt.ccExpiration.focus();
    return false;
  }
  if (confirm("Ready to Book this Tour.\n\nClick OK to process, Cancel to make changes.")) {
    return true;
   } else {
    return false;
  }
}

//Test for whitespace characters
function isblank(s) {
  for(var i=0; i<s.length; i++) {
    var c = s.charAt(i);
    if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
  }
  return true;
}

//Test for invalid characters
function splCharsA(s) {
  var sChars = "~`!@#$%^&*()_+={}[]|\\:;\"\'<>,?/"; //does not test for period (.) or dash (-)
  for (var i=0; i<s.length; i++) {
    if (sChars.indexOf(s.charAt(i)) != -1) return true;
  }
  return false;
}
function splCharsB(s) {
  var sChars = "~`!@#$%^&*()_-+={}[]|\\:;\"\'<>,.?/"; //tests for all special characters
  for (var i=0; i<s.length; i++) {
    if (sChars.indexOf(s.charAt(i)) != -1) return true;
  }
  return false;
}
function splCharsC(s) {
  if (s.length < 10) return true;
  var sChars = "0123456789()- "; //tests for phone numbers
  for (var i=0; i<s.length; i++) {
    if (sChars.indexOf(s.charAt(i)) == -1) return true;
  }
  return false;
}
function splCharsD(s) {
  if (s.length < 6) return true;
  var sChars = "~`!#$%^&*()+={}[]|\\:;\"\'<>,?/"; //does not test for atsign (@) or underscore (_) or period (.) or dash (-)
  for (var i=0; i<s.length; i++) {
    if (sChars.indexOf(s.charAt(i)) != -1) return true;
  }
  var error = 0;
  var sChars = "@."; //tests for mandatory characters
  for (var i=0; i<s.length; i++) {
    if (sChars.indexOf(s.charAt(i)) != -1) error++;
  }
  if (error < 2) return true;
  return false;
}
function splCharsE(s) {
  var sChars = "0123456789"; //tests for numeric
  for (var i=0; i<s.length; i++) {
    if (sChars.indexOf(s.charAt(i)) == -1) return true;
  }
  return false;
}
function splCharsF(s) {
  if (s.length < 4) return true;
  var sChars = "0123456789-/"; //tests for dates
  for (var i=0; i<s.length; i++) {
    if (sChars.indexOf(s.charAt(i)) == -1) return true;
  }
  return false;
}

//Test for space separator
function oneSpace(s) {
  for(var i=0; i<s.length; i++) {
    if (s.charAt(i) == ' ') return false;
  }
  return true;
}

//-->
