function openWindow(url, name) { 
  popupWin = window.open(url, name, "toolbar=0,scrollbars=1,width=600,height=370"); 
} 

function openPopup(win_url,win_name,properties) {
  window.open(win_url,win_name,properties);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];};
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Data entry error checking functions
// A utility function that returns true if a string contains only 
// 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;
}

// This is the function that performs form verification. It will be invoked
// from the onSubmit() event handler. The handler should return whatever
// value this function returns.
function verify(f)
{
//alert("incoming = " + f);
    var msg;
    var empty_fields = "";
    var errors = "";
    var last_name = /last_name$/;
    var first_name = /first_name$/;
    var address = /address$/;
    var city = /city$/;
    var state = /state$/;
    var zip = /zip$/;
    var country =/country$/;
    var phone = /h_phone$/;
    var time = /^time$/;
    var email_field = /email$/;
    var party_size = /a_party_size$/;
    var location = "";
    var checked = "";
    var melodrama = "";
    var lodge = "";
    var quote = "";
    var jeep = "";
    var raft = "";
    var elk = "";
    var sat_mat = "";

// Check form name 
    if (f.name == "pricequote")
      quote = 1;
    else if ( f.name == "melodrama" ) 
      melodrama = 1;
    else if ( f.name == "lodge" ) 
      lodge = 1;
    else if ( f.name == "jeep" ) 
      jeep = 1;
    else if ( f.name == "raft" ) 
      raft = 1;
    else if ( f.name == "elk" ) 
      elk = 1;

//alert("length = " + f.length);
//alert("raft= " + raft);
// Loop through the elements of the form, looking for all 
// text and textarea elements that don't have an "optional" property
// defined. Then, check for fields that are empty and make a list of them.
// Next, check that an actual month & day or date are selected.
// Put together error messages for fields that are wrong.
    for(var i = 0; i < f.length; i++) {
      var e = f.elements[i];

//alert("var = " + e.name);

      if (((e.type == "text") || (e.type == "textarea")) && !e.optional) {
        // first check if the field is empty
       if ((e.value == null) || (e.value == "") || isblank(e.value)) {
         var result = e.name.match(first_name)
	 if ( result != null)
           empty_fields += "\n          First Name";
         var result = e.name.match(last_name)
	 if ( result != null)
           empty_fields += "\n          Last Name";
         var result = e.name.match(party_size)
         if ( result != null)
           empty_fields += "\n          Party Size"
         var result = e.name.match(address)
	 if ( result != null)
           empty_fields += "\n          Address";
         var result = e.name.match(city)
	 if ( result != null)
           empty_fields += "\n          City";
         var result = e.name.match(state)
	 if ( result != null)
           empty_fields += "\n          State/Province";
         var result = e.name.match(zip)
	 if ( result != null)
           empty_fields += "\n          Zip";
         var result = e.name.match(country)
	 if ( result != null)
           empty_fields += "\n          Country";
         var result = e.name.match(phone)
	 if ( result != null)
           empty_fields += "\n          Home Phone";
         var result = e.name.match(time)
         if ( result != null)
           empty_fields += "\n          Departure Time";
         var result = e.name.match(email_field)
	 if ( result != null)
           empty_fields += "\n          Email";
         continue;
        } // end if null field
       var result = e.name.match(email_field);
       if ( result != null)  {          // if email field
	 var email_exp = /^[\S]+\@[\S]+\.[\S]+$/;
	 var result_exp = e.value.match(email_exp);
         if ( ! result_exp ) {
 	   errors += "- The E-mail field must contain a single valid email address (e.g. yourname@isp.com)\n";
           continue;
         } // end !result_exp
       } // end !result 
      } // end if text


	if ( melodrama && e.name == "option-PR|4" && e.checked == true )
	  sat_mat = 1;

      // check if location checkbox is checked
      if ( e.type == "checkbox" && ! checked ) {
        var l_box = /^location_/;
	var result = e.name.match(l_box)
	if (result != null) {  // if location checkbox
	  location = 1;
	  if (e.checked == true)
	  { checked = 1; }
        }
	continue;
      } // end if checkbox

      if (e.name == "date_month") { 
	if (e.options[0].selected)  // if "Month" label selected
	  errors += "You must select a month.\n\n";
	  // need number of month (0..11) - this only works if
	  // all months are listed in order
	else if ( melodrama || elk )  // listing starts at June
	    var arrive_month = e.selectedIndex+4;
	else if ( jeep || raft )  // listing starts at May
	    var arrive_month = e.selectedIndex+3;
	else  var arrive_month = e.selectedIndex-1;  
	continue;
      } // end if month
      if (e.name == "date_day") { 
	if (e.options[0].selected)  // if "Day" label selected
	  errors += "You must select a day.\n\n";
	else  var arrive_day = e.options[e.selectedIndex].text;  
	continue;
      } // end if day
      if (e.name == "date_year") { 
	if (e.options[e.selectedIndex].text == "Year")
	  errors += "You must select a year.\n\n";
	else  var arrive_year = e.options[e.selectedIndex].text;  
	continue;
      } // end if year
      if (e.name == "depart_month") { 
	if (e.options[0].selected)  // if "Month" label selected
	  errors += "You must select a departure month.\n\n";
	else  var depart_month = e.selectedIndex-1;  
	continue;
      } // end if depart month
      if (e.name == "depart_day") { 
	if (e.options[0].selected)  // if "Day" label selected
	  errors += "You must select a departure day.\n\n";
	else  var depart_day = e.options[e.selectedIndex].text;  
	continue;
      } // end if depart day
      if (e.name == "depart_year") { 
	if (e.options[e.selectedIndex].text == "Year")
	  errors += "You must select a departure year.\n\n";
	else  var depart_year = e.options[e.selectedIndex].text;  
	continue;
      } // end if depart year
      if (e.name == "returnmonth") { 
	if (e.options[0].selected)  // if "Month" label selected
	  errors += "You must select a return month.\n\n";
	else  var return_month = e.selectedIndex-1;  
	continue;
      } // end if return month
      if (e.name == "returnday") { 
	if (e.options[0].selected)  // if "Day" label selected
	  errors += "You must select a return day.\n\n";
	else  var return_day = e.options[e.selectedIndex].text;  
	continue;
      } // end if return day
      if (e.name == "returnyear") { 
	if (e.options[e.selectedIndex].text == "Year")
	  errors += "You must select a return year.\n\n";
	else  var return_year = e.options[e.selectedIndex].text;  
	continue;
      } // end if return year
      if (e.name == "date") { 
	if (e.options[0].selected)  // if label selected
	  errors += "You must select a date.\n\n";
	continue;
      } // end if date
      if (e.name == "pickup_time") { 
	if (e.options[0].selected)  // if label selected
	  errors += "You must select a pickup time.\n\n";
	continue;
      } // end if pickup time
      if (e.name == "return_time") { 
	if (e.options[0].selected)  // if label selected
	  errors += "You must select a return time.\n\n";
	continue;
      } // end if return time
      // check for max occupancy
      if (e.name == "max_occ") {
//alert("max occ = " + e.value);
	if ( (f.num_youths.options[f.num_youths.selectedIndex].value > (e.value * f.num_rooms.options[f.num_rooms.selectedIndex].value) - f.num_adults.options[f.num_adults.selectedIndex].value) || ( f.num_adults.options[f.num_adults.selectedIndex].value > (e.value * f.num_rooms.options[f.num_rooms.selectedIndex].value)) )
	  errors += "You have exceeded the maximum number of persons for the number of rooms selected.\n\n";
	continue;
      } // end if max_occ
      // check that number in party equal split out numbers
      if (e.name == "a_party_size") {
        if (f.a_party_size.value != ((f.b_num_adults.value * 1) + (f.c_num_youths.value * 1) + (f.d_num_childs.value * 1) + (f.e_num_seniors.value * 1) + (f.f_num_super_srs.value * 1) * 1))
	  errors += "Party size must equal the number of adults + youths + children + seniors + super seniors.\n\n";
	continue;
      } // end if party_size

    } // end for

    // If melodrama form, check for no performance dates
    // Regular season - no Tuesday performance
    // Extended season - no Monday or Tuesday performance
//    alert("melodrama = " + melodrama);
    if ( melodrama && !empty_fields && !errors) {
      var date = new Date(arrive_year, arrive_month, arrive_day);
      // months start at '0', so Sep is '8'
      var begin_break = new Date(2006,8,1);
      var end_break = new Date(2006,8,6);
//    alert("date = " + date);
//    alert("begin= " + begin_break + "end= " + end_break);
      if (date.getTime() > begin_break.getTime() &&
	     date.getTime() < end_break.getTime() )
        errors += "There are no performances 9/01-9/05. Please select another date.\n\n"; 
      if (date.getDay() == 2)
         errors += "There are no Tuesday performances. Please select another date.\n\n";
      else if (date.getTime() >  end_break.getTime() && date.getDay() == 1)
         errors += "There are no Monday performances. Please select another date.\n\n";
      else if (date.getDay() != 6  && sat_mat == 1)
         errors += "The date you have selected is not a Saturday, there is no matinee.\n\n";
 } // end if melodrama

    if ( !empty_fields && !errors && f.item_id )
{
    // check for allowed days -- if month not full listing on form (jan-dec) must adjust above (if e.name == "date_month"
      if ( f.item_id.value == "item-0702" ) {
        var date = new Date(arrive_year, arrive_month, arrive_day);
//        alert("date = " + date); 
        var day = date.getDay();
        if ( day != 0 && day != 1 && day != 3 && day != 5 )
         errors += "Full day Ghost Town Tour only offered on Sunday, Monday, Wednesday & Friday. Please select another date.\n\n";
   } // end if item-0702
      else if ( f.item_id.value == "item-0704" ) {
        var date = new Date(arrive_year, arrive_month, arrive_day);
//      alert("date = " + date); 
        var day = date.getDay();
        if ( day != 2 && day != 4 && day != 6 )
         errors += "Mini Ghost Town Tour only offered on Tuesday, Thursday & Saturday. Please select another date.\n\n";
   } // end if item-0704
      else if ( f.item_id.value == "item-0827" || 
	f.item_id.value == "item-0828" || 	
	f.item_id.value == "item-0831" ) {
        var date = new Date(arrive_year, arrive_month, arrive_day);
//        alert("date = " + date); 
        var day = date.getDay();
        if ( day != 1 && day != 3 && day != 6 )
          errors += "This trip only offered on Monday, Wednesday & Saturday. Please select another date.\n\n";
      } // end if 0831, 0828, 0827
      else if ( f.item_id.value == "item-0834" || 
	f.item_id.value == "item-0867"  ) {
        var date = new Date(arrive_year, arrive_month, arrive_day);
//        alert("date = " + date); 
        var day = date.getDay();
        if ( day != 3 && day != 6 )
          errors += "This trip only offered on Wednesday & Saturday. Please select another date.\n\n";
      } // end if 0834 or 0867
      else if ( f.item_id.value == "item-0826" ) {
        var date = new Date(arrive_year, arrive_month, arrive_day);
//        alert("date = " + date); 
        var day = date.getDay();
        if ( day != 2 && day != 4 && day != 5 && day != 7 )
          errors += "This trip only offered on Tuesday, Thursday, Friday & Sunday. Please select another date.\n\n";
      } // end if 0834
      else if ( f.item_id.value == "item-0845" ) {
        var date = new Date(arrive_year, arrive_month, arrive_day);
//        alert("date = " + date); 
        var day = date.getDay();
        if ( day != 2 && day != 4 && day != 7 )
          errors += "This trip only offered on Tuesday, Thursday & Sunday. Please select another date.\n\n";
      } // end if 0845
      else if ( f.item_id.value == "item-0833" ||
		f.item_id.value == "item-0835" ) {
        var date = new Date(arrive_year, arrive_month, arrive_day);
//        alert("date = " + date); 
        var day = date.getDay();
        if ( day != 3 && day != 4 && day != 6 && day != 7 )
          errors += "This trip only offered on Wednesday, Thursday, Saturday & Sunday. Please select another date.\n\n";
      } // end if 0833-35
      else if ( f.item_id.value == "item-0830" ||
		f.item_id.value == "item-0832" ) {
        var date = new Date(arrive_year, arrive_month, arrive_day);
//        alert("date = " + date); 
        var day = date.getDay();
        if ( day != 1 && day != 3 && day != 4 && day != 5 )
          errors += "This trip only offered on Monday, Wednesday, Friday & Saturday. Please select another date.\n\n";
      } // end if 0830, 0832
      else if ( f.item_id.value == "item-0210" ) {
        var date = new Date(arrive_year, arrive_month, arrive_day);
        var day = date.getDay();
//        alert("date = " + date + "day = " + day); 
       if ( day == 6 || day == 0 )
          errors += "This trip only offered Monday through Friday. Please select another date.\n\n";
      } // end if 0210
} // end if no errors, etc


    // Check that arrive date is prior to depart date & later than today
      var now = new Date();   
      var arrive = new Date(arrive_year, arrive_month, arrive_day);
      var depart = new Date(depart_year, depart_month, depart_day);
      if (arrive.getTime() > depart.getTime()) 
	  errors += "Your arrival date must be prior to your departure date.\n\n";
	// this check can only be done for full year month option listings
      if ( lodge || quote ) {
        if (arrive.getTime() < now.getTime())        
          errors += "Your arrival date must be later than today's date.\n\n";
        }

    // Check that pickup (arrive) date is prior to return date 
      var arrive = new Date(arrive_year, arrive_month, arrive_day);
      var rdate = new Date(return_year, return_month, return_day);
      if (arrive.getTime() > rdate.getTime()) 
	  errors += "Your pickup date must be prior to your return date.\n\n";

    // Check that a location checkbox has been checked
//    alert("location = " + location + " checked = " + checked);
    if ( location && ! checked )    
      errors += "You must select a location preference.\n\n";

    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted. 
    // Otherwise return true.
    if (!empty_fields && !errors) return true;

    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    if (empty_fields) {
      msg += "- The following required field(s) are empty:" 
            + empty_fields + "\n";
     if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;
} // end verify

function verify_email(f)
{
    var email_exp = /^[\S]+\@[\S]+\.[\S]+$/;
    var result_exp = f.email.value.match(email_exp);
    if ( ! result_exp ) {
      alert("The E-mail field must contain a single valid email address (e.g. yourname@isp.com)\n");
      return false;
   }
    else return true;
}

function verify_lodge_form(f)
{
    var msg;
    var empty_fields = "";
    var errors = "";
    var party_size = /a_party_size$/;
    var loc_checked = 0;
    var type_checked = 0;
    var loc = 0;

    for(var i = 0; i < f.length; i++) {
      var e = f.elements[i];

//alert("var = " + e);

      if (((e.type == "text") || (e.type == "textarea")) && !e.optional) {
        // first check if the field is empty
       if ((e.value == null) || (e.value == "") || isblank(e.value)) {
         var result = e.name.match(party_size)
         if ( result != null)
           empty_fields += "\n          Party Size"
         continue;
        } // end if null field
      } // end if text

      // check if location checkbox is checked
      if ( e.type == "checkbox" ) {
        var l_box = /^location_/;
	var result = e.name.match(l_box)
	if (result != null) {  // if location checkbox
	  loc = 1;
	  if (e.checked == true)
	  { loc_checked = 1; }
        }
        var t_box = /^type_/;
	var result = e.name.match(t_box)
	if (result != null) {  // if type checkbox
	  if (e.checked == true)
	  { type_checked = 1; }
        }
	continue;
      } // end if checkbox

      if (e.name == "date_month") { 
	if (e.options[0].selected)  // if "Month" label selected
	  errors += "You must select a month.\n\n";
	  // need number of month (0..11) - this only works if
	  // all months are listed in order
	else  var arrive_month = e.selectedIndex-1;  
	continue;
      } // end if month
      if (e.name == "date_day") { 
	if (e.options[0].selected)  // if "Day" label selected
	  errors += "You must select a day.\n\n";
	else  var arrive_day = e.options[e.selectedIndex].text;  
	continue;
      } // end if day
      if (e.name == "date_year") { 
	if (e.options[e.selectedIndex].text == "Year")
	  errors += "You must select a year.\n\n";
	else  var arrive_year = e.options[e.selectedIndex].text;  
	continue;
      } // end if year
      if (e.name == "depart_month") { 
	if (e.options[0].selected)  // if "Month" label selected
	  errors += "You must select a departure month.\n\n";
	else  var depart_month = e.selectedIndex-1;  
	continue;
      } // end if depart month
      if (e.name == "depart_day") { 
	if (e.options[0].selected)  // if "Day" label selected
	  errors += "You must select a departure day.\n\n";
	else  var depart_day = e.options[e.selectedIndex].text;  
	continue;
      } // end if depart day
      if (e.name == "depart_year") { 
	if (e.options[e.selectedIndex].text == "Year")
	  errors += "You must select a departure year.\n\n";
	else  var depart_year = e.options[e.selectedIndex].text;  
	continue;
      } // end if depart year

      // check that number in party equal split out numbers
      if (e.name == "a_party_size") {
        if (f.a_party_size.value != ((f.b_num_adults.value * 1) + (f.ba_num_students.value * 1) + (f.c_num_youths.value * 1) + (f.d_num_childs.value * 1) + (f.e_num_seniors.value * 1) + (f.f_num_super_srs.value * 1) * 1))
	  errors += "Party size must equal the number of adults + students + youths + children + seniors + super seniors.\n\n";
	continue;
      } // end if party_size
    } // end for

    // Check that arrive date is prior to depart date & later than today
    if (!empty_fields && !errors) {
      var now = new Date();   
      var arrive = new Date(arrive_year, arrive_month, arrive_day);
      var depart = new Date(depart_year, depart_month, depart_day);
      if (arrive.getTime() > depart.getTime()) 
	  errors += "Your arrival date must be prior to your departure date.\n\n";
      if (arrive.getTime() < now.getTime())        
          errors += "Your arrival date must be later than today's date.\n\n";
	  //Stuart
	  //This is to check if dates selected are during high volume period
	  var labor_start = new Date(2005,8,1);
	  var labor_end = new Date(2005,8,6);
//alert("start = " + labor_start + "end = " + labor_end);

	  if ((arrive.getTime() > labor_start.getTime()) && (arrive.getTime() < labor_end.getTime()))
		  errors += "Due to higher than expected volume this Labor Day Weekend, please call 1-800-828-4228 for reservations.\n\n";
	  if ((depart.getTime() > labor_start.getTime()) && (depart.getTime() < labor_end.getTime()))
		  errors += "Due to higher than expected volume this Labor Day Weekend, please call 1-800-828-4228 for reservations.\n\n";
		//end stu*/
    // Check that a location or type checkbox has been checked
    // if exist location ckbox
//    alert("location = " + location + " checked = " + checked);
    if ( loc && !loc_checked && !type_checked )    
      errors += "You must select at least one location or type preference.\n\n";

    // if skipkg, must have > 1 night lodging & must be 3 days prior
	if ( f.pkg.value == "Y" ) {
	  var diff = depart.getTime() - arrive.getTime();
	  diff = Math.floor(diff / (1000 * 60 * 60 * 24)); 
	  if ( diff < 2 )
	    errors += "Package rates require at least a 2 night stay.\n\n";
	  diff = arrive.getTime() - now.getTime();
	  diff = Math.floor(diff / (1000 * 60 * 60 * 24)); 
	  if ( diff < 2 )
	    errors += "Packages must be reserved at least 3 days prior to arrival.\n\n";
       }
    }

    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted. 
    // Otherwise return true.
    if (!empty_fields && !errors) return true;

    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitteda because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    if (empty_fields) {
      msg += "- The following required field(s) are empty:" 
            + empty_fields + "\n";
     if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;
} // end verify_lodge_form

function verify_contact_info(f) {
    var msg;
    var empty_fields = "";
    var errors = "";
    var last_name = /last_name$/;
    var first_name = /first_name$/;
    var address = /address$/;
    var city = /city$/;
    var state = /state$/;
    var zip = /zip$/;
    var country =/country$/;
    var phone = /h_phone$/;
    var group_size = /a_group_size$/;
    var arrive = /b_arrivedate$/;
    var depart = /c_departdate$/;
    var skidate = /d_skidate$/;
    var numski = /e_numskidays$/;
    var email_field = /email$/;
    var cc_num_field = /^cc_num/;
    // non-digit characters which are allowed in credit card numbers
    var creditCardDelimiters = "- "     // space or hyphen

    // Loop through the elements of the form, looking for all 
    // text and textarea elements that don't have an "optional" property
    // defined. Then, check for fields that are empty and make a list of 
    // them. Put together error messages for fields that are wrong.
    for(var i = 0; i < f.length; i++) {
     var e = f.elements[i];

	// Don't need to check hidden fields
     if (e.type == "hidden") { continue; }

     if (((e.type == "text") || (e.type == "textarea")) && !e.optional) {
       // first check if the field is empty
       if ((e.value == null) || (e.value == "") || isblank(e.value)) {
         var result = e.name.match(first_name)
	 if ( result != null)
           empty_fields += "\n          First Name";
         var result = e.name.match(last_name)
	 if ( result != null)
           empty_fields += "\n          Last Name";
         var result = e.name.match(address)
	 if ( result != null)
           empty_fields += "\n          Address";
         var result = e.name.match(city)
	 if ( result != null)
           empty_fields += "\n          City";
         var result = e.name.match(state)
	 if ( result != null)
           empty_fields += "\n          State/Province";
         var result = e.name.match(zip)
	 if ( result != null)
           empty_fields += "\n          Zip";
         var result = e.name.match(country)
	 if ( result != null)
           empty_fields += "\n          Country";
         var result = e.name.match(phone)
	 if ( result != null)
           empty_fields += "\n          Home Phone";
         var result = e.name.match(email_field)
	 if ( result != null)
           empty_fields += "\n          Email";
         var result = e.name.match(cc_num_field)
	 if ( result != null)
           empty_fields += "\n          Credit Card Number";
         var result = e.name.match(group_size)
	 if ( result != null)
           empty_fields += "\n          Group Size";
         var result = e.name.match(arrive)
	 if ( result != null)
           empty_fields += "\n          Arrival Date";
         var result = e.name.match(depart)
	 if ( result != null)
           empty_fields += "\n          Departure Date";
         var result = e.name.match(skidate)
	 if ( result != null)
           empty_fields += "\n          First Ski Day";
         var result = e.name.match(numski)
	 if ( result != null)
           empty_fields += "\n          Number of Ski Days";
         continue;
        } // end if null field
       var result = e.name.match(email_field);
       if ( result != null)  {          // if email field
	 var email_exp = /^[\S]+\@[\S]+\.[\S]+$/;
	 var result_exp = e.value.match(email_exp);
         if ( ! result_exp ) {
 	   errors += "- The E-mail field must contain a single valid email address (e.g. yourname@isp.com)\n";
           continue;
         } // end !result_exp
       } // end !result 
       var result = e.name.match(cc_num_field);
       if ( result != null)  {          // if credit card number field
         var normalizedCCN = strip_chars(e.value, creditCardDelimiters)
	 var card_type = get_selected_value(f.cc_name);
//alert("card = " + card_type + "  number = " + normalizedCCN);
	 if (!isCardMatch(card_type, normalizedCCN)) {
	   errors += "- The Credit Card Number field must contain a valid credit card number\n   (e.g., 9999 9999 9999 9999)\n";
           continue;
	 } // end if valid card number
       } // end if card_number
     } // end if text
   } // end for

    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted. 
    // Otherwise return true.
    if (!empty_fields && !errors) return true;

    msg  = "______________________________________________________\n\n";
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n";

    if (empty_fields) {
        msg += "- The following required field(s) are empty:" 
                + empty_fields + "\n";
        if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;
}

function verify_lodge()
{
    // define f as 1st form in doc
    var f=document.forms[0];
    var msg;
    var empty_fields = "";
    var errors = "";
    var unit_type_checked = "";
    // reg exp to pull out max_occ from item
    var unit = /\|\d+\|(\d+)\|/;
    var room;
    var max_occ;

// Loop through the elements of the form.
// Put together error messages for fields that are wrong.
    for(var i = 0; i < f.length; i++) {
      var e = f.elements[i];

//alert("var = " + e);

      // check if unit type radio is checked
      if ( e.type == "radio" && e.checked  ) {
        var unit_type = /^room_info$/;
	var result = e.name.match(unit_type)
	if (result != null) {  // if unit_type radio
	  unit_type_checked = 1;
	  room = e.value;
          var result = room.match(unit);
	  if (result != null) 
	    max_occ = result[1];
//	alert("max occ = " + max_occ);
	} // end if result
	continue;
      } // end if radio & checked

    } // end for

    // only check if "continuing"
    if ( ! unit_type_checked ) {   
      errors += "You must select a room type.\n\n"; }
    else {
	if ( (max_occ * f.num_rooms.options[f.num_rooms.selectedIndex].value) < f.num_adults.value )
 	errors += "You have exceeded the maximum number of persons for the number of rooms selected.\n\n";
    } // end else
    

    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted. 
    // Otherwise return true.
//    if (!empty_fields && !errors) return true;
    if (!empty_fields && !errors) {
	if ( f.type.value == "submit" ) document.lodging.submit();
	else add_discnt(f.type.value);
    } // end if no errors
    else
  {	
    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    if (empty_fields) {
      msg += "- The following required field(s) are empty:" 
            + empty_fields + "\n";
     if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
  }
//    return false;
} // end verify_lodge

function verify_skirent(f)
{
    var msg;
    var empty_fields = "";
    var errors = "";
    var name = /^guest_name$/;
    var agent = /^gwr_agent$/;
    var number = /^gwr_number$/;
    var phone = /phone$/;
    var email_field = /email$/;
    var putime = /^pickuptime$/;
    var rettime = /^returntime$/;
    var skiname = /^name_1$/;
    var vendor_checked = 0;	

    for(var i = 0; i < f.length; i++) {
     var e = f.elements[i];

	// Check for hidden vendor
	if (e.type == "hidden" && e.name == "vendor")
	{ vendor_checked = 1; }
	
	// Don't need to check hidden fields
     if (e.type == "hidden") { continue; }

     if (e.type == "text" && !e.optional) {
       // first check if the field is empty
       if ((e.value == null) || (e.value == "") || isblank(e.value)) {
         var result = e.name.match(number)
	 if ( result != null)
           empty_fields += "\n          GWR Reservation Number";
         var result = e.name.match(agent)
	 if ( result != null)
           empty_fields += "\n          GWR Agent";
         var result = e.name.match(name)
	 if ( result != null)
           empty_fields += "\n          Guest Name";
         var result = e.name.match(email_field)
	 if ( result != null)
           empty_fields += "\n          Guest Email Address";
         var result = e.name.match(phone)
	 if ( result != null)
           empty_fields += "\n          Guest Phone";
         var result = e.name.match(putime)
	 if ( result != null)
           empty_fields += "\n          Pick up Time";
         var result = e.name.match(rettime)
	 if ( result != null)
           empty_fields += "\n          Return Time";
         var result = e.name.match(skiname)
	 if ( result != null)
           empty_fields += "\n          1st row of rental info";
        } // end if null field
       var result = e.name.match(email_field);
       if ( result != null )  {  // if email field
	 var email_exp = /^[\S]+\@[\S]+\.[\S]+$/;
	 var result_exp = e.value.match(email_exp);
         if ( ! result_exp ) {
 	   errors += "The E-mail field must contain a single valid email address (e.g. yourname@isp.com)\n";
         } // end !result_exp
       } // end !result 
     } // end if text

      if (e.name == "pickupmonth") { 
	if (e.options[0].selected)  // if "Month" label selected
	  errors += "You must select a pick up month.\n\n";
	continue;
      } // end if month
      if (e.name == "pickupday") { 
	if (e.options[0].selected)  // if "Day" label selected
	  errors += "You must select a pick up day.\n\n";
	continue;
      } // end if day
      if (e.name == "pickupyear") { 
	if (e.options[e.selectedIndex].text == "Year")
	  errors += "You must select a pick up year.\n\n";
	continue;
      } // end if year
      if (e.name == "returnmonth") { 
	if (e.options[0].selected)  // if "Month" label selected
	  errors += "You must select a pick up month.\n\n";
	continue;
      } // end if month
      if (e.name == "returnday") { 
	if (e.options[0].selected)  // if "Day" label selected
	  errors += "You must select a pick up day.\n\n";
	continue;
      } // end if day
      if (e.name == "returnyear") { 
	if (e.options[e.selectedIndex].text == "Year")
	  errors += "You must select a pick up year.\n\n";
	continue;
      } // end if year


      // check if vendor checkbox is checked
      if ( e.type == "checkbox" && e.checked  ) {
	var vendor = /^vendor_/;
	var result = e.name.match(vendor)
	if (result != null) 
	  vendor_checked = 1;
	}

   } // end for

    if ( !vendor_checked ) {   
      errors += "You must select a vendor.\n\n"; }

    if (!empty_fields && !errors) return true;

    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    if (empty_fields) {
      msg += "- The following required field(s) are empty:" 
            + empty_fields + "\n";
     if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;

} // end verify_skirent

function verify_groupski(f)
{
    var msg;
    var empty_fields = "";
    var errors = "";
    var name = /^group_name$/;
    var contact = /^contact_name$/;
    var phone = /^contact_phone$/;
    var email_field = /email$/;
    var arrtime = /^arrivetime$/;
    var putime = /^pickuptime$/;
    var dotime = /^dropofftime$/;
    var skiname = /^name_1$/;
    var gp_num = /^group_num$/;
    var own_num = /^norent_num$/;
    var rent_num = /^num_pkgs$/;

    for(var i = 0; i < f.length; i++) {
     var e = f.elements[i];

	// Don't need to check hidden fields
     if (e.type == "hidden") { continue; }

     if (e.type == "text" && !e.optional) {
       // first check if the field is empty
       if ((e.value == null) || (e.value == "") || isblank(e.value)) {
         var result = e.name.match(name)
	 if ( result != null)
           empty_fields += "\n          Group Name";
         var result = e.name.match(contact)
	 if ( result != null)
           empty_fields += "\n          Group Contact Name";
         var result = e.name.match(email_field)
	 if ( result != null)
           empty_fields += "\n          Contact Email Address";
         var result = e.name.match(phone)
	 if ( result != null)
           empty_fields += "\n          Contact Phone";
         var result = e.name.match(arrtime)
	 if ( result != null)
           empty_fields += "\n          Arrival Time";
         var result = e.name.match(putime)
	 if ( result != null)
           empty_fields += "\n          Rental Pick-Up Time";
         var result = e.name.match(dotime)
	 if ( result != null)
           empty_fields += "\n          Rental Drop-Off Time";
         var result = e.name.match(gp_num)
	 if ( result != null)
           empty_fields += "\n          Total Number in Group";
         var result = e.name.match(own_num)
	 if ( result != null)
           empty_fields += "\n          Total Number with Own Equipment";
         var result = e.name.match(rent_num)
	 if ( result != null)
           empty_fields += "\n          Total Number Renting Equipment";
         var result = e.name.match(skiname)
	 if ( result != null)
           empty_fields += "\n          1st row of rental info";
        } // end if null field
       var result = e.name.match(email_field);
       if ( result != null )  {  // if email field
	 var email_exp = /^[\S]+\@[\S]+\.[\S]+$/;
	 var result_exp = e.value.match(email_exp);
         if ( ! result_exp ) {
 	   errors += "The E-mail field must contain a single valid email address (e.g. yourname@isp.com)\n";
         } // end !result_exp
       } // end !result 
     } // end if text

      if (e.name == "arrivemonth") { 
	if (e.options[0].selected)  // if "Month" label selected
	  errors += "You must select an arrival month.\n\n";
	continue;
      } // end if month
      if (e.name == "arriveday") { 
	if (e.options[0].selected)  // if "Day" label selected
	  errors += "You must select an arrival day.\n\n";
	continue;
      } // end if day
      if (e.name == "arriveyear") { 
	if (e.options[0].selected)  // if "Year" label selected
	  errors += "You must select an arrival year.\n\n";
	continue;
      } // end if year

      if (e.name == "pickupmonth") { 
	if (e.options[0].selected)  // if "Month" label selected
	  errors += "You must select an pick-up month.\n\n";
	continue;
      } // end if month
      if (e.name == "pickupday") { 
	if (e.options[0].selected)  // if "Day" label selected
	  errors += "You must select an pick-up day.\n\n";
	continue;
      } // end if day
      if (e.name == "pickupyear") { 
	if (e.options[0].selected)  // if "Year" label selected
	  errors += "You must select an pick-up year.\n\n";
	continue;
      } // end if year

      if (e.name == "dropoffmonth") { 
	if (e.options[0].selected)  // if "Month" label selected
	  errors += "You must select an drop-off month.\n\n";
	continue;
      } // end if month
      if (e.name == "dropoffday") { 
	if (e.options[0].selected)  // if "Day" label selected
	  errors += "You must select an drop-off day.\n\n";
	continue;
      } // end if day
      if (e.name == "dropoffyear") { 
	if (e.options[0].selected)  // if "Year" label selected
	  errors += "You must select an drop-off year.\n\n";
	continue;
      } // end if year

      // check that total group equals own + renting
      if (e.name == "group_num") {
        if (f.group_num.value != ((f.norent_num.value * 1) + (f.num_pkgs.value * 1) * 1))
	  errors += "Total group size must equal non-renters + renters.\n\n";
	continue;
      } // end if group_num

   } // end for

    if (!empty_fields && !errors) return true;

    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    if (empty_fields) {
      msg += "- The following required field(s) are empty:" 
            + empty_fields + "\n";
     if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;

} // end verify_groupski

function verify_skipkg(f)
{
    var msg;
    var errors = "";
    var tickets = /^tickets_/;
    var ski_days;

// Loop through the elements of the form.
// Put together error messages for fields that are wrong.

forloop:
    for(var i = 0; i < f.length; i++) {
      var e = f.elements[i];

//alert("var = " + e);

      // check that at least one person is skiing
	var result = e.name.match(tickets)
	if (result != null) {  // if tickets select
	  if (!e.options[0].selected) {
            ski_days = 1;
	    break forloop;
          }
	} // end if result
	continue;
    } // end for

    if ( ! ski_days ) 
      errors += "At least one person must ski to receive the package discount.\n\n"; 

    // if liftticket OK, ck for rentals
    if ( !errors && !f.no_rentals.checked ) {	
	// alert(" ck rentals");
	if (f.date_day.options[0].selected || 
	f.date_month.options[0].selected || 
	f.date_year.options[0].selected || 	
	f.returnday.options[0].selected || 
	f.returnmonth.options[0].selected || 
	f.returnyear.options[0].selected )
    	{ errors += "You must check the 'No ski/snowboard rentals requested' box or enter your rental information.\n\n"; }

//	if ( !errors ) {
//	  if ( 

    } // end check rentals

    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted. 
    // Otherwise return true.
    if ( !errors) return true;

    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    msg += errors;
    alert(msg);
    return false;
} // end verify_liftticket

function verify_rally(f)
{
    var msg;
    var empty_fields = "";
    var errors = "";
    var item = /^item-/;
    var shirt = /^T-Shirt-/;
    var num_items = 1;
    var num_shirts = 0;
    var num_sites = 0;
    var camp = 0;
    var rv = 0;

// Loop through the elements of the form.
// Put together error messages for fields that are wrong.

forloop:
    for(var i = 0; i < f.length; i++) {
      var e = f.elements[i];

//alert("var = " + e.name + "  value = " + e.value);

      var result = e.name.match(item)
      if (result != null) {  // if item quantity
	for( var j = 1; j < e.length; j++ ) {
	  if ( e.options[j].selected ) 
	    num_items = e.options[j].value;
	} // end for
      } // end if result

      if ( e.type == "checkbox" && e.checked ) {
        var c_box = /3/;
        result = e.name.match(c_box)
        if (result != null) {  // if campsite checkbox
	  camp = 1; 
        }
	
        var rv_box = /4$/;
        result = e.name.match(rv_box)
        if (result != null) {  // if RV checkbox
	  rv = 1; 
        }
     } // end checkbox
            
      result = e.name.match(shirt)
      if (result != null) {  // if shirt quantity
	num_shirts = num_shirts + ( e.value * 1);	
      } // end if result

    } // end for

    if ( num_shirts != num_items )
      errors += "The number of T-Shirts must match the number of tickets requested.\n\n"; 
    if ( num_items < camp + rv )
      errors += "You must purchase a ticket for each campsite or RV spot reserved.\n\n"; 

    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted. 
    // Otherwise return true.
    if (!empty_fields && !errors) return true;

    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    if (empty_fields) {
      msg += "- The following required field(s) are empty:" 
            + empty_fields + "\n";
     if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;
} // end verify_rally

function verify_rrmt(f)
{
    var msg;
    var empty_fields = "";
    var errors = "";
    var time = /^time$/;


// Loop through the elements of the form.
// Put together error messages for fields that are wrong.

    for(var i = 0; i < f.length; i++) {
      var e = f.elements[i];

//alert("var = " + e + "  value = " + e.value);

      if ((e.value == null) || (e.value == "") || isblank(e.value)) {
        var result = e.name.match(time)
        if ( result != null)
           empty_fields += "\n          Train Departure Time";
      } // end if blank
      if (e.name == "date_month") { 
	if (e.options[0].selected)  // if "Month" label selected
	  errors += "You must select an arrival month.\n\n";
	continue;
      } // end if month
      if (e.name == "date_day") { 
	if (e.options[0].selected)  // if "Day" label selected
	  errors += "You must select an arrival day.\n\n";
	continue;
      } // end if day
      // Rafting	
      if (e.name == "raft_month") { 
	if (e.options[0].selected)  // if "Month" label selected
	  errors += "You must select a month for your raft trip.\n\n";
	continue;
      } // end if month
      if (e.name == "raft_day") { 
	if (e.options[0].selected)  // if "Day" label selected
	  errors += "You must select a day for your raft trip.\n\n";
	continue;
      } // end if day
      // Train
      if (e.name == "train_month") { 
	if (e.options[0].selected)  // if "Month" label selected
	  errors += "You must select a month for your train trip.\n\n";
	continue;
      } // end if month
      if (e.name == "train_day") { 
	if (e.options[0].selected)  // if "Day" label selected
	  errors += "You must select a day for your train trip.\n\n";
	continue;
      } // end if day
      // Mesa Verde
      if (e.name == "mv_month") { 
	if (e.options[0].selected)  // if "Month" label selected
	  errors += "You must select a month for your Mesa Verde tour.\n\n";
	continue;
      } // end if month
      if (e.name == "mv_day") { 
	if (e.options[0].selected)  // if "Day" label selected
	  errors += "You must select a day for your Mesa Verde tour.\n\n";
	continue;
      } // end if day
      // Jeep
      if (e.name == "jeep_month") { 
	if (e.options[0].selected)  // if "Month" label selected
	  errors += "You must select a month for your jeep trip.\n\n";
	continue;
      } // end if month
      if (e.name == "jeep_day") { 
	if (e.options[0].selected)  // if "Day" label selected
	  errors += "You must select a day for your jeep trip.\n\n";
	continue;
      } // end if day
    } // end for


    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted. 
    // Otherwise return true.
    if (!empty_fields && !errors) return true;

    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    if (empty_fields) {
      msg += "- The following required field(s) are empty:" 
            + empty_fields + "\n";
     if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;
} // end verify_rrmt

function verify_giftcert(f)
{
    var msg;
    var errors = "";
    var ckd = 0;
    var send = "";
    var via = /^via$/;

// check for amount > $50.00
   if ((f.amount.value == null) || (f.amount.value == "") || isblank(f.amount.value)) 
     errors += "You must select an amount.\n\n";

   else if (f.amount.value < 50 )
     errors += "Minimum amount is $50.00.\n\n";

    for(var i = 0; i < f.length; i++) {
      var e = f.elements[i];

      if ( e.type == "radio" && e.checked  ) {
        var result = e.name.match(via)
	if (result != null) {  
	  ckd = 1;
	  send = e.value;
        }
     }
   } // end for 

// If email selected, check email is valid string
   if ( send == "email" ) {
     if ((f.email.value == null) || (f.email.value == "") || isblank(f.email.value)) 
     errors += "You must enter an email address if you wish to have the gift certificate delivered via email.\n\n";
     else if ( f.email.value ) {
       var email_exp = /^[\S]+\@[\S]+\.[\S]+$/;
       var result_exp = f.email.value.match(email_exp);
       if ( ! result_exp ) 
 	  errors += "- The E-mail field must contain a single valid email address (e.g. yourname@isp.com)\n";
     } // if email.value
   } // end if email
   else 
     if ( f.name.value == "" || f.addr1.value == "" || f.city.value == "" || f.state.value == "" || f.zip.value == "" ) 
     errors += "You must enter a full postal address if you wish to have the gift certificate delivered via postal mail.\n\n";


    if (!errors) return true;

    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    msg += errors;
    alert(msg);
    return false;
} // end verify_giftcert

// A utility function that returns true if a string contains only 
// 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;
}

// Removes all characters which appear in string bag from string s.
function strip_chars (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

// Get checked value from select menu.
function get_selected_value (select_field)
{   for (var i = 0; i < select_field.length; i++)
    {   if (select_field.options[i].selected) { break }
    }
    return select_field.options[i].value
}

/*  ================================================================
    FUNCTION:  isCardMatch()
 
    INPUT:    cardType - a string representing the credit card type
	      cardNumber - a string representing a credit card number

    RETURNS:  true, if the credit card number is valid for the particular
	      credit card type given in "cardType".
		    
	      false, otherwise
    ================================================================ */
function isCardMatch (cardType, cardNumber)
{

	cardType = cardType.toUpperCase();
	var doesMatch = true;
//alert("card type = " + cardType);
	if ((cardType == "VISA") && (!isVisa(cardNumber)))
		doesMatch = false;
	if ((cardType == "MASTERCARD") && (!isMasterCard(cardNumber)))
		doesMatch = false;
	if ((cardType == "AMEX") && (!isAmericanExpress(cardNumber)))
	        doesMatch = false;
	if ((cardType == "DISCOVER") && (!isDiscover(cardNumber)))
		doesMatch = false;
	return doesMatch;

}  // END FUNCTION CardMatch()

/*  ================================================================
    FUNCTION:  isVisa()
 
    INPUT:     cc - a string representing a credit card number

    RETURNS:  true, if the credit card number is a valid VISA number.
		    
	      false, otherwise

    Sample number: 4111 1111 1111 1111 (16 digits)
    ================================================================ */
function isVisa(cc)
{
  if (((cc.length == 16) || (cc.length == 13)) &&
      (cc.substring(0,1) == "4"))
    return isCreditCard(cc);
  return false;
}  // END FUNCTION isVisa()

/*  ================================================================
    FUNCTION:  isMasterCard()
 
    INPUT:     cc - a string representing a credit card number

    RETURNS:  true, if the credit card number is a valid MasterCard
		    number.
		    
	      false, otherwise

    Sample number: 5500 0000 0000 0004 (16 digits)
    ================================================================ */
function isMasterCard(cc)
{
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 16) && (firstdig == "5") &&
      ((seconddig >= "1") && (seconddig <= "5")))
    return isCreditCard(cc);
  return false;

} // END FUNCTION isMasterCard()

/*  ================================================================
    FUNCTION:  isAmericanExpress()
 
    INPUT:     cc - a string representing a credit card number

    RETURNS:  true, if the credit card number is a valid American
		    Express number.
		    
	      false, otherwise

    Sample number: 340000000000009 (15 digits)
    ================================================================ */
function isAmericanExpress(cc)
{
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 15) && (firstdig == "3") &&
      ((seconddig == "4") || (seconddig == "7")))
    return isCreditCard(cc);
  return false;

} // END FUNCTION isAmericanExpress()


/*  ================================================================
    FUNCTION:  isDiscover()
 
    INPUT:     cc - a string representing a credit card number

    RETURNS:  true, if the credit card number is a valid Discover
		    card number.
		    
	      false, otherwise

    Sample number: 6011000000000004 (16 digits)
    ================================================================ */
function isDiscover(cc)
{
  first4digs = cc.substring(0,4);
  if ((cc.length == 16) && (first4digs == "6011"))
    return isCreditCard(cc);
  return false;

} // END FUNCTION isDiscover()


/*  ================================================================
    FUNCTION:  isCreditCard(st)
 
    INPUT:     st - a string representing a credit card number

    RETURNS:  true, if the credit card number passes the Luhn Mod-10
		    test.
	      false, otherwise
    ================================================================ */

function isCreditCard(st) {
  // Encoding only works on cards with less than 19 digits
  if (st.length > 19)
    return (false);

  sum = 0; mul = 1; l = st.length;
  for (i = 0; i < l; i++) {
    digit = st.substring(l-i-1,l-i);
    tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }
// Uncomment the following line to help create credit card numbers
// 1. Create a dummy number with a 0 as the last digit
// 2. Examine the sum written out
// 3. Replace the last digit with the difference between the sum and
//    the next multiple of 10.

//  document.writeln("<BR>Sum      = ",sum,"<BR>");
//  alert("Sum      = " + sum);

  if ((sum % 10) == 0)
    return (true);
  else
    return (false);

} // END FUNCTION isCreditCard()


// popup stuff

function add_discnt(type)
{
  var options="scrollbars=yes,resizable=yes,width=650,height=400";
if ( type == "skipkg" )
  window.open("/LODGING/ski_popup.html","Ski",options);
else if ( type == "trainpkg" )
  window.open("/LODGING/train_popup.html","Train",options);

} // end add_discnt

function do_discnt(x) {
if ( window.name == "Ski" )
{ if ( x == "Y" )
{ window.opener.document.lodging.pkg.value = "skipkg"; }
else
{ window.opener.document.lodging.pkg.value = ""; }
} // end if ski

else if ( window.name == "Train" )
{ if ( x == "Y" )
{ window.opener.document.lodging.pkg.value = "trainpkg"; }
else
{ window.opener.document.lodging.pkg.value = ""; }
} // end if train

window.opener.document.lodging.submit();
window.close();
}

function do_activity(x) {
//alert("x = " + x);
if ( x == "Y" )
{ window.opener.document.review.activity.value = "Y"; }
else
{ window.opener.document.review.activity.value = "N"; }
window.opener.document.review.submit();
window.close();
} // end do_activity

// Called from lodge_popup.html - popup displayed when SUMMER/TRAIN/trainform.html submit
function do_trainlodge(x) {
  if ( x == "Y" )
  { 
   if (window.opener.document.summertrain.refer.value == "DR" )
     { window.opener.document.summertrain.source.value = "lodging_DR"; }  
   else if (window.opener.document.summertrain.refer.value == "SR" )
     { window.opener.document.summertrain.source.value = "lodging_SR"; }  
   window.opener.document.summertrain.page.value = "/SUMMER/LODGING/lodgedateform.html"; 
   window.opener.document.summertrain.seed_summer_train_form_button.value = "";
   window.opener.document.summertrain.trainpkg.value = "Y";   
  }
  window.opener.document.summertrain.submit();
  window.close();
} // end do_trainlodge

function popup_lodge(f) {
//alert("x = " + x);

// Have to do field check here - previously done in verify
  var errors = "";

  for(var i = 0; i < f.length; i++) {
      var e = f.elements[i];

  if (e.name == "date_month") { 
	if (e.options[0].selected)  // if "Month" label selected
	  errors += "You must select a month.\n\n";
	  // need number of month (0..11) - this only works if
	  // all months are listed in order
	continue;
      } // end if month
  if (e.name == "date_day") { 
	if (e.options[0].selected)  // if "Day" label selected
	  errors += "You must select a day.\n\n";
	else  var arrive_day = e.options[e.selectedIndex].text;  
	continue;
      } // end if day
    } // end for

  if (errors)
  {
    var msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    msg += errors;
    alert(msg);
    return false;
  } // end if errors

// No popup for concierge sites

  var ref_exp = /^C-/;
  var result = f.refer.value.match(ref_exp);
  if ( result )
    { document.summertrain.submit(); }
  else
    { openPopup('/SUMMER/TRAIN/lodge_popup.html','Lodging','scrollbars=yes,resizable=yes,width=650,height=400'); }

} // end popup_lodge

