var string = new Array();
string[0]= "- Online reservations are limited to four rooms.\nPlease contact Hotel Harrington's toll free number 800 424 8352 to complete this reservation.\n\n";
string[1] = "Only a selected number of our rooms are designated as smoking rooms ...... while we will do our very best to provide you with the smoking room you have requested, occasionally circumstances beyond our control intervene which prevents us from honoring your request.  Should this happen, you will be assigned a non-smoking room as a substitute. We understand that this will be an inconvenience for you, but we do ask your cooperation in honoring our no smoking policy in these types of rooms.";
string[2] = "The majority of our rooms are non-smoking rooms ..... while we will do our very best to provide you with the non-smoking room you have requested, occasionally circumstances beyond our control intervene which prevents us from honoring this request.  We hope you will understand that this request cannot be absolutely guaranteed.";
string[3] ="______________________________________________________\n\n" + "The form was not submitted because of the following error(s).\n" + "Please correct these error(s) and re-submit.\n" + "______________________________________________________\n\n";
string[4] ="While these rooms do have a queen size bed suitable for two adults, the rooms themselves are rather small so we typically recommend single occupancy. Also, these rooms are on the interior side of the building only, and therefore have no city street views.\n\n";
string[5] ="While these rooms do have two twin size beds suitable for two adults, the rooms themselves are rather small with limited closet space.  Also, these rooms are only located on floors that allow smoking in the guest rooms, so \"non-smoking\" is not an option for this room type.\n\n";
string[6] ="The majority of these rooms are located on NON-SMOKING floors, however, we cannot guarantee your preference for either smoking or non-smoking in this room type.\n\n";
string[7] ="You have selected our smallest room type.  Although all rooms in this category have a full size, double bed, we recommend this room type for single occupancy only.  Also, these rooms are on the interior side of our building, and therefore have no city street views.\n\n";
string[8] ="You have a value that is too large.  Our maximum reservation length using this online form is 365 days.  Please enter a value of 365 days or less.\n\n";

window.onerror = errorHandler;

function errorHandler(e,f,l){
	// alert("Error in file: " + f + ", line: " +l+"\n\t" + e);
	return true;
}

var shown = "no";

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;
}


function handleSmokingrules (ind){

	(ind>0)?alert(string[(ind)]):"";
}

var now;
with (now = new Date) {
	setHours(0,0,0,0);
}
var current = new Date(now.getYear(),now.getMonth(),now.getDate());

var the_months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var day_of_month = new Array (31,28,31,30,31,30,31,31,30,31,30,31);
var the_years = new Array(current.getFullYear(),current.getFullYear()+1,current.getFullYear()+2);
var ob

function setdays()
{

	var ob = document.main.theDay
	var ind = document.main.theDay.selectedIndex
	leap()


	len = day_of_month[document.main.theMonth.selectedIndex];

	for (x=0;x<len;x++)
		{
		ob.options[x]= new Option(x+1)
		}

	delete_extra_options (ob,len);
	ob.options[ind].selected=true

}

function leap  (){

	var rest4 = the_years[document.main.theYear.selectedIndex] % 4;
	var rest100 = the_years[document.main.theYear.selectedIndex] % 100;
	var rest400 = the_years[document.main.theYear.selectedIndex] % 400;

	if ((rest4 == 0 && rest100 != 0) || rest400 == 0){
		day_of_month[1]=29;
	} else {
		day_of_month[1]=28;
	}
}

function delete_extra_options (ob, size)
{
	while (ob.options.length > size)
		ob.options[ob.options.length - 1] = null;
}

function checkform () {

	var ErrorMessage = "";

	if (document.main.theDay.selectedIndex < 0) {
			ErrorMessage = "Please select your arrival day\n";
		}
	if (document.main.len_of_stay.value == "") {
			ErrorMessage = ErrorMessage + "Please enter the number of nights\n";
		}
	if (document.main.len_of_stay.value > 28) {
			ErrorMessage = ErrorMessage + "Our online reservation system only accepts reservations for up to 28 days. Please enter a value of 28 or less or call us for reservations longer than 28 days.\n";
			document.main.len_of_stay.value = "";
			document.main.len_of_stay.focus;
		}
	year_string = document.main.theYear.options[document.main.theYear.selectedIndex].value

	month= document.main.theMonth.selectedIndex;
	if (month.toString().length <2) month_string = "0"+ month.toString();
	else month_string = month.toString();

	day = document.main.theDay.selectedIndex+1;
	if (day.toString().length <2) day_string = "0"+ day.toString();
	else day_string = day.toString();

	arrival = new Date(year_string,	month_string, day_string);
	if (arrival < now){
    	ErrorMessage = ErrorMessage + "Invalid arrival date\n";
	}

	if (ErrorMessage != ""){
			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"
			alert( msg + ErrorMessage );
			return false;
		}

	return true;


}

function verify(f)
{
    var msg;
    var empty_fields = "";
    var errors = "";
	var rooms =0;

   for(var i = 0; i < f.length; i++)
   {
        var e = f.elements[i];
        if (((e.type == "text") || (e.type == "radio") || (e.type == "checkbox") || (e.type == "textarea") || (e.type == "password")) && !e.optional)
        {
            // first check if the field is empty
            if ((e.value == null) || (e.value == "") || isblank(e.value)) {
                empty_fields += "\n          " + e.name;
                continue;
            }

            // Now check for fields that are supposed to be numeric.
            if (e.numeric || (e.min != null) || (e.max != null)) {
                var v = parseFloat(e.value);
                if (isNaN(v) ||
                    ((e.min != null) && (v < e.min)) ||
                    ((e.max != null) && (v > e.max))) {
                    errors += "- The field " + e.name + " must be a number";
                    if (e.min != null)
                        errors += " that is greater than " + e.min;
                    if (e.max != null && e.min != null)
                        errors += " and less than " + e.max;
                    else if (e.max != null)
                        errors += " that is less than " + e.max;
                    errors += ".\n";
                }
            }
        }

      }
	rooms = roomTotal();

   	if (rooms == 0) errors += "- Please make a room selection. \n";

    if (empty_fields || errors) {

    	msg = string[3];

    	if (empty_fields) {
        	msg += "- The following required field(s) are empty:"
                + empty_fields + "\n";
        }
        if (errors)
        	msg += "\n";
    	msg += errors;
    	alert(msg);
    	return false;
	} else {
		if (rooms > 4)
			alert(string[0]);
		else
			return true
	}
}

function roomNumber(cat){

	total = roomTotal(); 

	if (total > 4){
		alert(string[0]);
		cat.selectedIndex =0;

	} else if (cat.options[cat.selectedIndex].value==2){
		var agree1 = confirm("Just to confirm ..... this reservation is for two (2) rooms, correct?");
		
		if (agree1){
		
			if ("10" == cat.name) {
				agree2=confirm(string[4]);
				if (!agree2)
					cat.selectedIndex =0;
			}		
			if ("11" == cat.name) {
				agree2=confirm(string[5]);
				if (!agree2)
					cat.selectedIndex =0;
			}
			if ("13" == cat.name) {
				agree2=confirm(string[7]);
				if (!agree2)
					cat.selectedIndex =0;
			}
			
		 // New rooms added
		
		    if ("12" == cat.name) {
				agree2=confirm(string[6]);
				if (!agree2)
					cat.selectedIndex =0;
			}
			
			
		
		
		} else
			cat.selectedIndex =0;
	
	} else if ( "10"== cat.name){
		
		agree2=confirm(string[4]);
		if (!agree2)
			cat.selectedIndex =0;
	} else if ( "11"== cat.name){
	
		agree2=confirm(string[5]);
			if (!agree2)
				cat.selectedIndex =0;
	} else if ( "13"== cat.name){
	
		agree2=confirm(string[7]);
			if (!agree2)
				cat.selectedIndex =0;				
				
	// New rooms added
				
				
	} else if ( "12"== cat.name){
	
		agree2=confirm(string[6]);
		if (!agree2)
			cat.selectedIndex =0;
				
	
				
				
				
	}		
}

function roomTotal(){

	rt =0;
	ds = document.main1;

	for(var i = 0; i < ds.length; i++)
	{
    		var e = ds.elements[i];
    		if (e.name == "1" || e.name == "2" || e.name == "3" || e.name == "4" 
    			|| e.name == "5" || e.name == "6" || e.name == "7" || e.name == "8" 
    				|| e.name == "9" || e.name == "10" || e.name == "11" || e.name == "12"
						|| e.name == "13")
		{
			if (!isNaN(parseInt(e.value)))
				rt += parseInt(e.value)
    		}
	}

	return rt;
}

function maxNights(element) {
  alert(string[8]);
  this.value="";
  return false;
}

