$(function() {
	//Global variables
	
	URCHIN = typeof(pageTracker)=='undefined'?true:false;

	$('.track').each(function() {
		var tag = '/'+this.name.replace(/:/g,'/');
		if($(this).is('form')) {
			var a = $(this).attr('action');
			$(this).submit(function() {
				URCHIN?urchinTracker(tag):pageTracker._trackEvent('form', 'submit', tag);
				if(tag.indexOf("reservations")>0) {
					$(this).attr({action:a+'?'+$(this).serialize(), method:'post'});
					URCHIN?__utmLinkPost(this):pageTracker._linkByPost(this);
				}
			});
		} else {
			$(this).click(function(e) {
				URCHIN?urchinTracker(tag):pageTracker._trackPageview(tag);
				if(tag.indexOf("reservations")>0) {
					e.preventDefault();
					var l = URCHIN?__utmLinkerUrl(this.href):pageTracker._getLinkerUrl(this.href);
					$(this).attr('target')=='_blank'?window.open(l,''):window.location=l;
				}
			});
		}
	});

	
	$('div.terms').hide();
	$('a.toggle').toggle(function(){
	$('div.terms').show();
	 return false;
	},function(){
	$('div.terms').hide();
	return false;
	});
		


	$('div#travelling-with-children').hide();
	$('div#canoehouse-dining-reservations').hide();
	$('#dining-reservation0').hide();
	$('div#spa-and-salon').hide();
	$('#spa-reservation0').hide();
	$('div#golf-courses').hide();
	$('#golf-reservation0').hide();
	
	$('input#travelling_with_children').click(function(){

		if($('input#travelling_with_children').attr("checked")) {
			$('div#travelling-with-children').show();
			$('input#travelling_with_children').attr("checked", "true");
			
		} else {
			$('div#travelling-with-children').hide();
			$('input#travelling_with_children').attr("checked", "");
		}
	

	});
	

	$('input#canoehouse_dining_reservations').click(function(){

		if($('input#canoehouse_dining_reservations').attr("checked")) {
			$('div#canoehouse-dining-reservations0').show();
			$('#dining-reservation0').show();
			$('input#canoehouse_dining_reservations').attr("checked", "true");
			
		} else {
			$('div#canoehouse-dining-reservations0').hide();
			$('#dining-reservation0').hide();
			$('input#canoehouse_dining_reservations').attr("checked", "");
		}

	});
	
	$('input#spa_and_salon').click(function(){
		
		if($('input#spa_and_salon').attr("checked")) {
			$('div#spa-and-salon0').show();
			$('#spa-reservation0').show();
			$('input#spa_and_salon').attr("checked", "true");
			
		} else {
			$('div#spa-and-salon0').hide();
			$('#spa-reservation0').hide();
			$('input#spa_and_salon').attr("checked", "");
		}
	
	});
	
	$('input#golf_courses').click(function(){

		if($('input#golf_courses').attr("checked")) {
			$('div#golf-courses0').show();
			$('#golf-reservation0').show();
			$('input#golf_courses').attr("checked", "true");
			
		} else {
			$('div#golf-courses0').hide();
			$('#golf-reservation0').hide();
			$('input#golf_courses').attr("checked", "");
		}
	});

	activateActiveX();
	$("div#js-warning").hide();
	$("div#js-warning-spacer").hide();
	$('a.iframe').iframe();

// Adds hover class for IE and animation for drop down nav
	$("ul#nav-primary li").hover(
	    function(){ $("ul", this).fadeIn("fast"); }, 
	    function() { } 
	);
    if (document.all && !window.opera) {
        $("ul#nav-primary li").hoverClass("sfhover");
		//$("ul#nav-primary li ul li").hoverClass("sfhover");
    }

	$("#disclaimer-popup").click(function() {
	disclaimerPopUp(this.href);
	return false;
	});
	$("#disclaimer-popup-j").click(function() {
	disclaimerPopUpJapanese(this.href);
	return false;
	});

	$('#webcams a.webcam').click(function() {
		webcamPopUp(this.href);
		return false;
	});
	
	
// sIFR'ize headers 
	var h2Selector = (location.href.indexOf('esiteinteractive.com') != -1) ? 'div#content h2 div' : 'div#content h2';
	$(h2Selector).sifr({path:'/flash/sifr/', size:'36', color:'#591b0e' });
	var h3Selector = (location.href.indexOf('esiteinteractive.com') != -1) ? 'div#content h3 div' : 'div#content h3';
	$(h3Selector).sifr({path:'flash/sifr/', size:'18', color:'#591b0e' });
	var h4Selector = (location.href.indexOf('esiteinteractive.com') != -1) ? 'div#content h4 div' : 'div#content h4';
	$(h4Selector).sifr({path:'flash/sifr/', size:'24', color:'#591b0e' });
	//$('#subnav li.selected').sifr({path:'flash/sifr', size:'12', width:'135', link:arrColors[section]});
	//$('div#sidebar span.section').sifr({path:'flash/sifr', size:13, color:'#000000'});
	//$('h4.specials-title').sifr({path:'flash/sifr/', size:'15', color: '#c79347'});
	//$('div#sidebar h3').sifr({ path:'flash/sifr/', color: arrColors[section], size:'17', width:'120' });
	//$('div#sidebar h3.activities-h3').sifr({ path:'flash/sifr/', color: arrColors[section], size:'17', width:'140' });

// Finds a form on the page, instantiates a Calendar Popup and hides "other" fields if necessary
	$(this).find("form").each(function() {
		if ( window.CalendarPopup ) {
			// instantiate CalendarPopup and set some params
			
			// Sets starting date by yesterdays date
			var yesterday = new Date();
			yesterday.setDate( yesterday.getDate() - 1 );
			
			// new instance of Calendar popup
			cal = new CalendarPopup( "cp" );
			cal.addDisabledDates( null, formatDate( yesterday, "MM/dd/yyyy" ) );
			
			// create the <div> for calendar popup
			$("body").append("<div id=\"cp\"></div>");
		}
		//set focus background color for IE
		if (document.all) {
			$(".textfield").focus(function() {
				$(this).css({background: "fdfcfa"});
			});
			$(".textfield").blur(function() {
			    $(this).css({background: "ffffff"});
			});
			
		}
		// hide all "other" fields
		$("ul.checkboxgroup input.other").filter(".textfield").hide();
		$("ul.checkboxgroup input").click(function() {
			// if the input has a class of other, show it's "other" field
			if ($(this).is(".other")){
				$(this).siblings(".other").show().addClass("required");
				// if it's a checkbox, remove the "other" field when it is unchecked
				if (!this.checked) {
					$.removeWarning($(this));
					$(this).siblings(".other").filter(".textfield").hide().removeClass("required");
				}
			}
			// if it's a radio button group, hide "other" fields if not needed
			else if ($(this).is(".radio")) {
				$.removeWarning($(this));
				$(this).parent().parent().find(".other").filter(".textfield").hide().removeClass("required");
			}
		});
	                 // hide all "select-other" divs
  	                 $("div.select-other").hide();
  	                 // if "Other" is selected, then show it's "other" field
 	  	                 $("select.select-other").change( function () {
	  	                         if($(this).val() == "--") {
 	                                 $(this).parent().next().show();
  	                                 $(this).parent().next().find("label").addClass("required");
	  	                                 $(this).parent().next().find("input").addClass("required");
	  	                         } else {
	  	                                 $(this).parent().next().hide().find("input").val("").removeClass("required");
	  	                         }
	  	                 });
		
	});


// Input Elements that need a calendar popup, but no calendar Icon, need a class of "makeitpopup"
	$(".makeitpopup").click(function() {
		cal.select( this, this.id, "MM/dd/yyyy" );
		return false;
	});


// Finds all elements with a class of "form-cal" and replaces them with a calendar icon, link, and onclick handler
	$(this).find(".form-cal").each(function(i) {
		var icon = '<a href="#" class="icon-cal" id="form-cal-' + i + '" name="form-cal-' + i + '" title="Click to select a date"><img src="images/icon-cal.gif" /></a>';
		$(icon).appendTo($(this).parent()).click(function(){

		    if (!$(this).parent().parent().is('#check-availability-form')) {
			if (document.all && window.ActiveXObject && !window.opera) { 
			    var formEl = $(this).parents('form');
			    if ( $(formEl).is('#concierge') ) {
				if ( !$(this).is('#form-cal-0') ) {
				    $(this).parents("fieldset").find("select").css("visibility","hidden"); 
				}
			    } else {
				$(this).parents("form").find("select").css("visibility","hidden"); 
			    }
			    //if ( !formEl.is('#concierge') && $(this)
			}
		    }
			var o = this.previousSibling;
			while (o.nodeType != 1) { o = o.previousSibling; }
			
			// check to see if it is an arrival/departure pair
			if($(o).is(".date-end")) {
				var arrive_string = $(o).parent().prev(".field").children(".date-begin").attr("value");
				var arrive_label = $(o).parent().prev(".field").children("label").html().replace(":","");
				//check to see if begin date has been set already and adjust disabled/current dates
				if (arrive_string != "mm/dd/yyyy" && arrive_string) {
					var arrive_array = arrive_string.split('/');
					var arrive_date = new Date(arrive_array[0]+'/'+arrive_array[1]+'/'+arrive_array[2]);
					var arrive_date = formatDate(arrive_date, "MM/dd/yyyy" );
					cal.clearDisabledDates();
					cal.addDisabledDates( null, arrive_date );
					cal.select(o,$(this).attr("id"),"MM/dd/yyyy", arrive_date);
					return false;
				}
				// begin date not set first, so pull label text and alert
				else {
					alert("Please select \"" + arrive_label + "\" first");
					if (document.all && window.ActiveXObject && !window.opera) { $(this).parents("form").find("select").css("visibility","visible"); }
					return false;
				}
			}
			// it's just a plain calendar popup
			else {
				cal.clearDisabledDates();
				var yesterday = new Date();
				yesterday.setDate( yesterday.getDate() - 1 );
				cal.addDisabledDates( null, formatDate( yesterday, "MM/dd/yyyy" ) );
				cal.select( o,$(this).attr("id"), "MM/dd/yyyy", yesterday );
				return false;
			}
		});
		$(this).remove();
	});


// Validates the form, adding warning icons where needed and alerting user upon completion
	$(".validate").submit(function() {
		var counter = 0;
		var first_error = "";
		
		// find all elements with class name of "required" within all divs with a class of field
		$(this).find("div.field .required").each(function() { 
			// remove any previous warnings and validate based on element type
			$.removeWarning($(this));
			if ( ($(this).is("input")) || ($(this).is("select")) || ($(this).is("textarea")) ) {
				var valid = true;
				var o = $(this).val().replace(/^\s+|\s+$/g, '');

				if ($(this).is(".email")) {
					// if it's an email address make sure the email is valid using both regular expressions
					var regExp = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
					var regExp2 = /(\s+)|(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
					if ( ( o.search( regExp ) ) == -1 || o.search( regExp2 ) != -1 ) {
						valid = false;
					}
				} 
				else if ($(this).is(".select-other") && $(this).val() == "--" && $(this).parent().next().find("input").val().replace( /(^\s+)|(\s+$)/g, '' ).length < 1 ) {
					$.addWarning($(this).parent().next().find("input"));
				} 
				else if ( ($(this).next().is(".icon-cal")) && (o.replace( /(^\s+)|(\s+$)/g, '' ).length < 1 || o == "mm/dd/yyyy") ) {
					// if it's a date field
					valid = false;
				} 
				else if (o.replace( /(^\s+)|(\s+$)/g, '' ).length < 1) {
					// if not an email address take out funky characters and see if its still blank
					valid = false;
				}
				// if the data is not valid show warning icon
				if (!valid) {
					$.addWarning($(this));
					counter++;
					if ( first_error == "" ) {
						first_error = $(this).attr("id");
					}		
				}
				
			}
			else if ( $(this).is("ul") ) {
				// This is for checkboxes
				$(this).each(function() { 
					// find all elements w/required class name
					var valid = false;
					$(this).find("li").each(function() {
						// checkboxes in the list
						var testdis = $(this).children("input");
						//if not an "other" pair
						if ( testdis.length == 1 ) {
							if ( $(testdis).attr("checked") == true ) {
								valid = true;
							}
						}
						//it is an "other"
						else {
							if ( $(testdis[0]).attr("checked") && $(testdis[1]).val().replace( /(^\s+)|(\s+$)/g, '' ).length > 0 ) {
								valid = true;
							}
						}
					});
					if(!valid) { 
						$.addWarning($(this));
						counter++;
						if ( first_error == "" ) {
							first_error = $(this).attr("id");
						}
					}
				});			
			}
		});
		if ( counter > 0 ) {
			alert( "A valid " + $('#'+first_error).parent().children('label').html().replace(":","").replace("*","") + " is required." );
			$('#'+first_error).focus();
			return false;
		}		
	});

// Removes the Warning Icon
	jQuery.removeWarning = function(el) {
		// find img elements, if it's present, remove it
		$(el).parents(".field").find("img.validation-error").remove();
	};
	
// Adds the Warning Icon
	jQuery.addWarning = function(el) {
		var img = "<img />";
		// adds the source and class attributes
		img = $(img).attr("src", "images/icon-warning.gif").addClass("validation-error");	
		// Add the image after the input field
		// if el is part of checkbox group put it after the first list item
		if( $(el).is("ul") ) {
			$(el).find("li:first").append(img);
		}
		// if not throw it at the end
		else {
			$(el).parent().append(img);
		}
	};
	
// For Each Package Wrapper add a Toggle Function if Neccessary
	$("div.golf-instructors-wrapper").each(function() {
	// Div for the Toggler to be Held
	$(this).append("<div class=\"golf-toggle\" style=\"clear:both;padding-left:40px;\">");

		// If this is a package that is going to be expanded
		// add a control for it
		// Since this is expandable hide the details
			$(this).find("div.golf-instructor-long").hide();
			// Add the Control
			$(this).find(".golf-toggle").append("<a href=\"#\">Read More</a>");
		
	});

// Once the Package Toggler Control is clicked
// Toggle the details and chance the text
	$("div.golf-toggle a").toggle(function() {
		$(this).parents("div.golf-instructors-wrapper").find("div.golf-instructor-long").animate({
			height: 'show'
		}, 'slow');
		// Changes the Text of the Control
		$(this).html("Read Less");
	}, function() {
		$(this).parents("div.golf-instructors-wrapper").find("div.golf-instructor-long").animate({
			height: 'hide'
		}, 'slow');
		// Changes the Text of the Control
		$(this).html("Read More");
	});


// For Each Package Wrapper add a Toggle Function if Neccessary
	$("div.package-wrapper").each(function() {
	// Div for the Toggler to be Held
	$(this).append("<div class=\"package-toggle\" style=\"clear:both;\">");

		// If this is a package that is going to be expanded
		// add a control for it
		if( $(this).is(".package-expandable") ) {
			// Since this is expandable hide the details
			$(this).find("div.package-long").hide();
			// Add the Control
			$(this).find(".package-toggle").append("<a href=\"#\">View Details</a>");
		}
	});

// Once the Package Toggler Control is clicked
// Toggle the details and chance the text
	$("div.package-toggle a").toggle(function() {
		$(this).parents("div.package-wrapper").find("div.package-long").animate({
			height: 'show'
		}, 'slow');
		// Changes the Text of the Control
		$(this).html("Hide Details");
	}, function() {
		$(this).parents("div.package-wrapper").find("div.package-long").animate({
			height: 'hide'
		}, 'slow');
		// Changes the Text of the Control
		$(this).html("View Details");
	});
    
// Handle Concierge form activity required fields
    $("input[@name='canoehouse_dining_reservations']").click(function() {
        if ($("input[@name='canoehouse_dining_reservations']:checked").val() == '1') {
            $("input[@name='preferred_date']").addClass('required');
            $("select[@name='canoe_hours']").addClass('required');
            $("select[@name='canoe_minutes']").addClass('required');
            $("select[@name='canoe_ampm']").addClass('required');
            $("input[@name='canoe_number_in_your_party']").addClass('required');
        }else{
            $("input[@name='preferred_date']").removeClass('required');
            $("select[@name='canoe_hours']").removeClass('required');
            $("select[@name='canoe_minutes']").removeClass('required');
            $("select[@name='canoe_ampm']").removeClass('required');
            $("input[@name='canoe_number_in_your_party']").removeClass('required');
        }
    });
    $("input[@name='spa_and_salon']").click(function() {
        if ($("input[@name='spa_and_salon']:checked").val() == '1') {
            $("input[@name='spa_preferred_date']").addClass('required');
            $("select[@name='spa_hours']").addClass('required');
            $("select[@name='spa_minutes']").addClass('required');
            $("select[@name='spa_ampm']").addClass('required');
            $("select[@name='services_requested']").addClass('required');
        }else{
            $("input[@name='spa_preferred_date']").removeClass('required');
            $("select[@name='spa_hours']").removeClass('required');
            $("select[@name='spa_minutes']").removeClass('required');
            $("select[@name='spa_ampm']").removeClass('required');
            $("select[@name='services_requested']").removeClass('required');
        }
    });
    $("input[@name='golf_courses']").click(function() {
        if ($("input[@name='golf_courses']:checked").val() == '1') {
            $("input[@name='golf_preferred_date']").addClass('required');
            $("select[@name='golf_hours']").addClass('required');
            $("select[@name='golf_minutes']").addClass('required');
            $("select[@name='golf_ampm']").addClass('required');
            $("input[@name='golf_number_in_your_party']").addClass('required');
        }else{
            $("input[@name='golf_preferred_date']").removeClass('required');
            $("select[@name='golf_hours']").removeClass('required');
            $("select[@name='golf_minutes']").removeClass('required');
            $("select[@name='golf_ampm']").removeClass('required');
            $("input[@name='golf_number_in_your_party']").removeClass('required');
        }
    });
});



$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};   

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

// Gets the Difference Between 2 Dates
function daysElapsed(date1,date2) {
    var difference =
        Date.UTC(y2k(date1.getYear()),date1.getMonth(),date1.getDate(),0,0,0)
      - Date.UTC(y2k(date2.getYear()),date2.getMonth(),date2.getDate(),0,0,0);
    return difference/1000/60/60/24;
}

function getDateDiff(start,end){
	if(document.getElementById(start).value != 'mm/dd/yyyy' && document.getElementById(start).value != '' && document.getElementById(end).value != 'mm/dd/yyyy' && document.getElementById(end).value != ''){
		// Get the Start and End Date and split the dates based on the slash and put in dashes
		start_date = document.getElementById(start).value;
		start_array = start_date.split('/');
		new_start_date = start_array[2]+'-'+start_array[0]+'-'+start_array[1];
		end_date = document.getElementById(end).value;
		end_array = end_date.split('/');
		new_end_date = end_array[2]+'-'+end_array[0]+'-'+end_array[1];
		
		// Call daysElapsed function to get difference between 2 dates
		var dayDiff = daysElapsed(new Date(end_array[2],(end_array[0]-1),end_array[1]),new Date(start_array[2],(start_array[0]-1),start_array[1]));
		return dayDiff;
	}
	else {
		return;
	}
}

//set day name abbreviations to use
var daynames = Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');

function createRoomBlock(start,days) {
	//Removes Any Previous Tbodies Created
	$("#block-details").remove();

	var start_date = document.getElementById(start).value;
	var start_array = start_date.split('/');

	// Creates a Tbody element
	var tbody = '<tbody id="block-details">';
	// For Each Number of Days that need information a row is created for each
	for(var i=0; i<=days; i++)
	{
		temp_date = new Date(start_array[2],(start_array[0]-1),(parseInt(start_array[1],10)+i));
		dayname = daynames[temp_date.getDay()];
		month = temp_date.getMonth() + 1;
		day = temp_date.getDate();
		//year = temp_date.getFullYear();
		//temp_date = month + "/" + day + "/" + year;
		temp_date = month + "/" + day;
		
		// Create a row with a cell for the day, one for each room type, and one for the total
		tbody += '<tr>\n\
			<th scope="row">' + dayname + ', ' + temp_date + '</th>\n\
			<td><input type="text" class="textfield day_' + (i+1) + ' single" maxlength="5" onchange="calcTotal(this);" value="0" id="single_rooms_day_' + (i+1) + '" name="room_block[day_' + (i+1) + '][single]" /></td>\n\
			<td><input type="text" class="textfield day_' + (i+1) + ' dbl" maxlength="5" onchange="calcTotal(this);" value="0" id="dbl_rooms_day_' + (i+1) + '" name="room_block[day_' + (i+1) + '][dbl]" /></td>\n\
			<td><input type="text" class="textfield day_' + (i+1) + ' suite" maxlength="5" onchange="calcTotal(this);" value="0" id="suite_rooms_day_' + (i+1) + '" name="room_block[day_' + (i+1) + '][suite]" /></td>\n\
			<td><input type="text" class="textfield" readonly="readonly" disabled="disabled" value="0" id="day_' + (i+1) + '_total" name="room_block[day_' + (i+1) + '][total]" /></td>\n\
			</tr>';
	}
	//Add the totals row
	tbody += '<tr><th scope="row">Room Total</th>\n\
		<td><input type="text" class="textfield" readonly="readonly" disabled="disabled" value="0" id="single_rooms_total" name="room_block[single][total]" /></td>\n\
		<td><input type="text" class="textfield" readonly="readonly" disabled="disabled" value="0" id="dbl_rooms_total" name="room_block[dbl][total]" /></td>\n\
		<td><input type="text" class="textfield" readonly="readonly" disabled="disabled" value="0" id="suite_rooms_total" name="room_block[suite][total]" /></td>\n\
		<td><input type="text" class="textfield" readonly="readonly" disabled="disabled" value="0" id="total_rooms" name="total_rooms" /></td>\n\
		</tr>';
	
	//add tbody to existing table
	$(tbody).appendTo("#block-requirements");
}


function createMeetingRooms(start,days) {
	//Removes Any Previous Tbodies Created
	$("#meeting-details").remove();

	var start_date = document.getElementById(start).value;
	var start_array = start_date.split('/');
	// Creates a Tbody elemnt
	var tbody = '<tbody id="meeting-details">';
	// For Each Number of Days that need information a row is created for each
	for(var i=0; i<=days; i++)
	{
		temp_date = new Date(start_array[2],(start_array[0]-1),(parseInt(start_array[1],10)+i));
		dayname = daynames[temp_date.getDay()];
		month = temp_date.getMonth() + 1;
		day = temp_date.getDate();
		//year = temp_date.getFullYear();
		//temp_date = month + "/" + day + "/" + year;
		temp_date = month + "/" + day;
		
		// Create a row with a cell for the day, room type and breakout room info
		tbody += '<tr>\n\
			<th scope="row">' + dayname + ', ' + temp_date + '</th>\n\
			<td><select name="meeting_requirements[day_' + (i+1) + '][room_setup]">\n\
				<option value="Classroom" name="meeting_requirements[day_' + (i+1) + '][room_setup]">Classroom</option>\n\
				<option value="Boardroom" name="meeting_requirements[day_' + (i+1) + '][room_setup]">Boardroom</option>\n\
				<option value="Theater" name="meeting_requirements[day_' + (i+1) + '][room_setup]">Theater</option>\n\
				<option value="U-Shaped" name="meeting_requirements[day_' + (i+1) + '][room_setup]">U-Shaped</option>\n\
				<option value="Hollow Sq." name="meeting_requirements[day_' + (i+1) + '][room_setup]">Hollow Sq.</option>\n\
				<option value="Rounds" name="meeting_requirements[day_' + (i+1) + '][room_setup]">Rounds</option>\n\
				<option value="Reception" name="meeting_requirements[day_' + (i+1) + '][room_setup]">Reception</option>\n\
				</select></td>\n\
			<td><input type="text" class="textfield" maxlength="5" id="breakout_rooms_day_' + (i+1) + '" name="meeting_requirements[day_'+(i+1)+'][breakout_rooms]" /></td>\n\
			<td><input type="text" class="textfield" maxlength="5" id="breakout_people_day_' + (i+1) + '" name="meeting_requirements[day_'+(i+1)+'][breakout_people]" /></td>\n\
			<td><select name="meeting_requirements[day_' + (i+1) + '][breakout_setup]">\n\
				<option value="Classroom" name="meeting_requirements[day_' + (i+1) + '][breakout_setup]">Classroom</option>\n\
				<option value="Boardroom" name="meeting_requirements[day_' + (i+1) + '][breakout_setup]">Boardroom</option>\n\
				<option value="Theater" name="meeting_requirements[day_' + (i+1) + '][breakout_setup]">Theater</option>\n\
				<option value="U-Shaped" name="meeting_requirements[day_' + (i+1) + '][breakout_setup]">U-Shaped</option>\n\
				<option value="Hollow Sq." name="meeting_requirements[day_' + (i+1) + '][breakout_setup]">Hollow Sq.</option>\n\
				<option value="Rounds" name="meeting_requirements[day_' + (i+1) + '][breakout_setup]">Rounds</option>\n\
				<option value="Reception" name="meeting_requirements[day_' + (i+1) + '][breakout_setup]">Reception</option>\n\
				</select></td>\n\
			</tr>';
	}
	//add tbody to existing table
	$(tbody).appendTo("#meeting-requirements");
}


function calcTotal(field) {
	//make sure a number was entered
	$(field).attr("value",(isNaN(parseInt(field.value,10))?0:parseInt(field.value,10)));
	var day_total = 0;
	var room_total = 0;
	var temp = field.name.split("][");
	var day_num = temp[0].substring(temp[0].indexOf('[')+1,temp[0].length);
	var room_type = temp[1].substring(0,temp[1].length-1);

	//calculate daily and room type total
	$("input." + day_num).each(function(){ day_total += parseInt(this.value,10); });
	$("input." + room_type).each(function(){ room_total += parseInt(this.value,10); });
	
	//set total fields
	$("#" + day_num + "_total").attr("value",day_total);
	$("#" + room_type + "_rooms_total").attr("value",room_total);
	$("#total_rooms").attr("value",parseInt($("#single_rooms_total").attr("value"),10)+parseInt($("#dbl_rooms_total").attr("value"),10)+parseInt($("#suite_rooms_total").attr("value"),10));
}


/* Source : http://sixtwothree.org/blog/archives/2006/05/20/activateactivex-11/ */
function activateActiveX() {
	if ( !document.getElementsByTagName || !document.body.outerHTML || !document.compatMode ) return false;
	var elems = new Array( "object", "applet" );
	for ( i = 0, j = elems.length; i < j; i++ ) {
		var objects = document.getElementsByTagName(elems[i]);
		for ( k = 0, l = objects.length; k < l; k++ ) {
			var params = "";
			for ( m = 0, n = objects[k].childNodes.length; m < n; m++ ) {
				params += objects[k].childNodes[m].outerHTML;
			}
			objects[k].outerHTML = objects[k].outerHTML.replace( "</" + elems[i].toUpperCase() + ">", params + "</" + elems[i].toUpperCase() + ">" );
		}
	}
}


/* Old functions from MaunaLani.com -- still need to be modernized */

function disclaimerPopUp (url) {
	var newWindow = window.open('http://www.maunalani.com/disclaimer.htm','form_window',"resizable=1,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,copyhistory=0,width=450,height=350,top=5,left=50");
	newWindow.focus();
}

function disclaimerPopUpJapanese (url) {
	var newWindow = window.open(url,'form_window',"resizable=1,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,copyhistory=0,width=450,height=350,top=5,left=50");
	newWindow.focus();
}

function subscribePopUp (url) {
	var newWindow = window.open("http://www.clicklinktracker.com/c/?id=560","form_window","resizable=1,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,width=462,height=670,top=5,left=50");
	newWindow.focus();
}

function webcamPopUp(url) {
	var newWin = window.open(url, 'spa', config='height=370,width=392');
	newWin.focus();
}

function openCalendar(FormElement){
   var calendarwindow;
	   url = "calendar.html?formname=form1&formelement=" + FormElement;
   
   calendarwindow = window.open(url,"thewindow","toolbar=no,LEFT=300,TOP=250,WIDTH=170,HEIGHT=140,status=no,scrollbars=no,resize=no,menubar=no");
   calendarwindow.focus();
}

	function verifyForm(form)
{
  var errormsg = "A required field is blank.\n";
  errormsg += "Please enter info for ";

  for (var i = 0; i < form.elements.length; i++) {
    element = form.elements[i];
    switch (element.name) {
      case "first_name":
      case "last_name":
      case "email":
      case "company":
      case "phone":
      /* case "subcategory": */
      case "description":
        if (element.value == "" || element.value == "-1") {
          alert(errormsg + element.name.split("_").join(" ").toUpperCase());
          form.elements[element.name].focus();
          return false;
        }
    }
  }
  return true;
}

function openPreview(urlrequest) {
	window.open(urlrequest, 'myWindow', 'width=940,height=700,left=100,top=100,toolbar=No,location=No,scrollbars=No,status=No,resizable=No,fullscreen=No');
	document.getElementById('flashCallBox').value = urlrequest;
}


