
function winopen(url) {
	openwin = window.open(url, "openwin", "toolbar=1,scrollbars=1,location=0,status=1,menubar=1,resizable=1,width=500,height=300");
	openwin.focus();
}

function clearText(thefield){
	if (thefield.defaultValue==thefield.value)
	thefield.value = ""
}

function checklogin(photo_id, secure_test, url) {
	(secure_test == "false") ? window.alert("You must be logged in to download this item.") :	window.open(url);
}

function myprint() {
	if (window.print) window.print();
}

function launchSearch() {
	val = document.getElementById("organization").value;
	
	var strLink = "search_MOIDs.cfm?moname=" + val;
	var strOptions = "menubar=0,resizable=0,width=500,height=500,scrollbars";
	var winName = "wdoSearchMOIDs";
	window.open(strLink,winName,strOptions);
}

function openMedia(url) {
	var w = 800;
	var h = 600;		
	var strOptions = "toolbar=1,scrollbars=1,location=0,status=0,menubar=0,resizable=1,width=" + w + ",height=" + h;
	window.open(url, 'Gallery', strOptions);
}

function equalHeight(group,changeVal) {
   tallest = 0;
   group.each(function() {
    	thisHeight = $(this).height();
   		if (thisHeight > tallest) {
   		        tallest = thisHeight + changeVal;
       		}
  		});
  		group.height(tallest);
	}
	$(window).load(function() {
		equalHeight($(".columnTallest"),0);
		resize_nav('2');
});

// Used by the data form fields on the home pages
$(function() {
	var dates = $('#arrivaldate, #leavedate').datepicker({
		defaultDate: '+1d',
		minDate:+1,
		changeMonth: false,
		numberOfMonths: 1,
		onSelect: function(selectedDate) {
			var option = this.id == 'arrivaldate' ? 'minDate' : 'maxDate';
			var instance = $(this).data('datepicker');
			var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
			dates.not(this).datepicker('option', option, date);
			set_client_var('arrivaldate');
			set_client_var('leavedate');
		}
	});
});

// TDD - Gets the browser windows size
function get_window_width() {
	var window_width = $(window).width();
	
	return window_width;
};

function get_window_height() {
	var window_height = $(window).height();
	
	return window_height;
};

function set_content_position() {
	var window_width = get_window_width();
	
	if (window_width <= 1300) {
		$('#content_well').css('margin-left','30');
		$('#content_well').css('margin-right','');
	};
};

function set_phone_dimensions() {
	var window_width = get_window_width();
	var right_border_region = (window_width - 1000) / 2;
	var new_tollfree_width = right_border_region;
	if (right_border_region < 270) {
		$('#footer_contact_region').addClass('footer_contact_region_low');
		$('#footer_contact_region').removeClass('footer_contact_region');
		$('#footer_contact_phone').addClass('footer_contact_phone_float');
		$('#footer_contact_links').addClass('footer_contact_links_float');
		$('.sitemaplnk').css('color','#FFFFFF');
	} else {
		$('#footer_contact_region').addClass('footer_contact_region');
		$('#footer_contact_region').removeClass('footer_contact_region_low');
		$('#footer_contact_phone').addClass('footer_contact_phone');
		$('#footer_contact_phone').removeClass('footer_contact_phone_float');
		$('#footer_contact_links').removeClass('footer_contact_links_float');
		$('.sitemaplnk').css('color','#777C82');
	};
	return true;
};

// TDD - Calculates the width of each footer item based on window size.
function set_footer_item_width() {
	var window_width = get_window_width();
	var footer_item_width = window_width * .25;
	
	return footer_item_width;
};

function resize_elements() {
	/* 11.18.2010 - TDD - Client decided to keep larger header image. Client prefer to have users scroll.
						- Decided in meeting with Simon, Kris H., Kim, and Chris H.
	var window_width = get_window_width();
	var temp_new_height; 
	var size_percent;
	
	if (window_width < 1440) {
		size_percent = window_width / 1440;
		size_percent = .80;
		
		var banner_image = $('#header_banner').height();
		temp_new_height = banner_image * size_percent;
		if (temp_new_height < 100) {
			$('#header_banner').height('100');
		} else {
			$('#header_banner').height(temp_new_height);
		};
		
		var header_region_height = $('#header_region').height();
		temp_new_height = header_region_height * size_percent;
		$('#header_region').height(temp_new_height);
		$('.header_background').height(temp_new_height);
		//$('.content_region').css('margin-top',temp_new_height);
		
	} else {
		temp_new_height = 115;
		$('#header_banner').height(temp_new_height);

		temp_new_height = 170;
		$('#header_region').height(temp_new_height);
		$('.header_background').height(temp_new_height);
		$('.content_region').css('margin-top',temp_new_height);
	};
	*/
	return true;
};

// TDD - Resizes the nav items
function resize_nav(flg) {
	var text_align = 'center';
	var footer_item_width = set_footer_item_width();
	var temp_position = 0;
	var temp_col_width = (footer_item_width - 32)/2;

	if (flg == '2') {
		footer_item_width = footer_item_width - 0.5;
	};
	
	for (i=1; i<=4; i++) {
		$('#ftr_nav_'+i).css('width',footer_item_width); // TDD - Sets the width of each nav item
		$('#ftr_nav_'+i).css('text-align',text_align); // TDD - Centers the text
		$('#ftr_popup_'+i).css('left',temp_position); // TDD - Sets the position of the popup regions
		$('#ftr_popup_'+i).css('width',footer_item_width); // TDD - Sets the width of the popup regions
		$('#ftr_popup_'+i).removeClass('ftr_popup_hide'); // TDD - Makes footer popup visible
		$('.ftr_popup_content').css('width',footer_item_width-22);  // TDD - Sets the width of the popup content regions
		$('.resort_list_left').css('width',temp_col_width); // TDD - Used on the Our Resorts popup
		$('.resort_list_right').css('width',temp_col_width); // TDD - Used on the Our Resorts popup
		temp_position = temp_position + footer_item_width; // TDD - Calculates position of next popup region
	};
	if ( (flg == '1') || (flg == '2') ) {
		$('.footer_nav_item').css('display','inline');
	};

	set_popup_positions();
	//resize_elements();
	//set_phone_dimensions();
	return true;
};

// TDD - Mouse off affect on nav item
function ftr_nav_off(id) {
	var footer_item_width = set_footer_item_width();
	var text_align = 'center';

	$('#'+id).css('width', footer_item_width);
	$('#'+id).css('text-align', text_align);
	$('#'+id).removeClass('footer_nav_item_on').addClass('footer_nav_item_off');
	return true;
};

// TDD - Mouse over affect on nav item
function ftr_nav_on(id) {
	var footer_item_width = set_footer_item_width();
	var text_align = 'center';
	
	$('#'+id).css('width', footer_item_width);
	$('#'+id).css('text-align', text_align);
	$('#'+id).removeClass('footer_nav_item_off').addClass('footer_nav_item_on');

	return true;
};

// TDD - Finds the position on the page of the footer
function get_footer_position() {
	var footer_position = $('#footer_region').position();

	return footer_position;
};

// TDD - This will resize the content area to extend into the footer for pages with limited content.
function set_content_height() {
	var window_height = 0;
	var min_content_height = 0;
	var lft_content_height = 0;
	var rt_content_height = 0;
	var beader_region_height = $(".header_region").height();
	var footer_contact_region = $(".footer_contact_region_low").height();
	var footer_link_region = $(".footer_region").height();
	
	// Gets the height of the browser window
	window_height = get_window_height(); 
	
	// Calculates minimum content height
	//min_content_height = window_height - 75;
	var used_space = beader_region_height + footer_contact_region + footer_link_region
	min_content_height = window_height - beader_region_height - footer_contact_region - footer_link_region;
	
	// Gets the height of the content
	lft_content_height = $(".left_region").height(); 
	rt_content_height = $(".right_region").height(); 
	
	//alert(window_height + " | " + beader_region_height + " | " + footer_contact_region + " | " + footer_link_region + " | " + min_content_height);
	
	if (lft_content_height > rt_content_height) {
		if (lft_content_height < min_content_height) {
			// Resizes content window if shorter than browser window
			$('.right_region').height(min_content_height); 
		} else {
			// Ensures that end of content will scroll above the footer.
			$('.right_region').height(lft_content_height + 100); 
		};
	} else {
		if (rt_content_height < min_content_height) {
			// Resizes content window if shorter than browser window
			$('.right_region').height(min_content_height); 
		} else {
			// Ensures that end of content will scroll above the footer.
			$('.right_region').height(rt_content_height + used_space + 100);
		};
	};
	
	
	// Resizes left rail to match right rail.
	equalHeight($('.columnTallest'),0);
	
	return true;
};

// TDD - Positions the pop-up menus
function set_popup_positions() {
	var temp_popup_height = 0; 
	var temp_popup_ypos = 0;
	
	for (i=1; i<=4; i++) {
		temp_popup_height = $('#ftr_popup_'+i).height(); // Calculates height of each popup
		temp_popup_ypos = (temp_popup_height+10) * -1 ; // Converts height to a negative value to be used for positioning
		$('#ftr_popup_'+i).css('bottom', temp_popup_ypos); // Moved popup down on the page.
		$('#ftr_popup_status_'+i).html('1'); // Sets status to 1 = Hidden
		$('#ftr_popup_height_'+i).html(temp_popup_height+36); //+36 Calculate new height value. Used to know how much to move the popup.
	};

	return true;
};

// TDD - Toggle the display of the selected footer popup
function toggle_current_popup(id) {
	var popup_status = 0;
	var popup_position = 0;
	
	popup_status = $('#ftr_popup_status_'+id).html(); // Gets the current status of the popup
	popup_position = $('#ftr_popup_height_'+id).html(); // Gets the height to move popup

	if (popup_status == '1') {
		show_footer_popup(id);
	} else { 
		hide_footer_popup(id)
	}
	
	return true;
};
// TDD - Display footer popup
function show_footer_popup(id) {
	var popup_status = 0;
	var popup_position = 0;
	
	popup_status = $('#ftr_popup_status_'+id).html(); // Gets the current status of the popup
	popup_position = $('#ftr_popup_height_'+id).html(); // Gets the height to move popup

	if (popup_status == '1') {
		$('#ftr_popup_'+id).animate({top: '-='+popup_position}, "slow")
		$('#ftr_popup_status_'+id).html('0');
	}

	return true;
};
// TDD - Hide footer popup
function hide_footer_popup(id) {
	var popup_status = 0;
	var popup_position = 0;

	popup_status = $('#ftr_popup_status_'+id).html(); // Gets the current status of the popup
	popup_position = $('#ftr_popup_height_'+id).html();

	if (popup_status == '0') {
		$('#ftr_popup_'+id).animate({top: '+='+popup_position}, "slow")
		$('#ftr_popup_status_'+id).html('1');
	};
	
	return true;
};

// TDD - Hide all or not selected footer popup
function hide_all_footer_popup(id) {
	for (i=1; i<=4; i++) {
		if (i != id) {
			hide_footer_popup(i);
		}
	};
};

$(document).ready(function(){
	//set_content_position();
	resize_nav('1'); // Resizes the footer nav based on window size
	set_popup_positions(); // Positions
	
	// As window is resized, resizes the bottom nav dynamically
	$(window).resize(function(){
		var temp_resize_var = resize_nav('2');
		if (temp_resize_var == 'true') {
			set_popup_positions(); 
		};
	});

	$('#ftr_nav_1').click( function() {
		toggle_current_popup('1');
		hide_all_footer_popup('1');
	});
	$('#ftr_nav_2').click( function() {
		toggle_current_popup('2');
		hide_all_footer_popup('2');
	});
	$('#ftr_nav_3').click( function() {
		toggle_current_popup('3');
		hide_all_footer_popup('3');
	});
	$('#ftr_nav_4').click( function() {
		toggle_current_popup('4');
		hide_all_footer_popup('4');
	});

	// Hook up a click handler on the document so that
	// we can hide the menu if it is not the target of
	// the mouse click.

	$(document).click(

		function(event){
			var temp_ftr_nav_click = $('.ftr_popup_filler').is(':visible');
			
			// TDD - Check if the any of the footer popups are displayed
			if	(	( $('#ftr_popup_1').is(':visible') ) || 
					( $('#ftr_popup_2').is(':visible') ) || 
					( $('#ftr_popup_3').is(':visible') ) || 
					( $('#ftr_popup_3').is(':visible') )
				) {
				// TDD - Check if the click is NOT occuring in the nav item or popup content item.
				if	(	( !$( event.target ).closest( "#ftr_nav_1" ).size()  && !$( event.target ).closest( "#ftr_popup_content_1" ).size() ) && 
						( !$( event.target ).closest( "#ftr_nav_2" ).size()  && !$( event.target ).closest( "#ftr_popup_content_2" ).size() ) && 
						( !$( event.target ).closest( "#ftr_nav_3" ).size()  && !$( event.target ).closest( "#ftr_popup_content_3" ).size() ) && 
						( !$( event.target ).closest( "#ftr_nav_4" ).size()  && !$( event.target ).closest( "#ftr_popup_content_4" ).size() )
					) {
					hide_all_footer_popup('0');
				};				

			};

		//function(event){
			// Check to see if this came from the menu.
			//if ( $('#resort_list_region').is( ":visible" ) && !$( event.target ).closest( "##resort_list_region" ).size() ) {
				// The click came outside the menu, so
				// close the menu.
				//$('#resort_list_region').hide();
			//}
		//}
	});

});


// BEGIN: Imported From emailCheck.js
function emailCheck (emailStr) {

	/* The following pattern is used to check if the entered e-mail address
	   fits the user@domain format.  It also is used to separate the username
	   from the domain. */
	var emailPat=/^(.+)@(.+)$/
	/* The following string represents the pattern for matching all special
	   characters.  We don't want to allow special characters in the address. 
	   These characters include ( ) < > @ , ; : \ " . [ ]    */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	/* The following string represents the range of characters allowed in a 
	   username or domainname.  It really states which chars aren't allowed. */
	var validChars="\[^\\s" + specialChars + "\]"
	/* The following pattern applies if the "user" is a quoted string (in
	   which case, there are no rules about which characters are allowed
	   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	   is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")"
	/* The following pattern applies for domains that are IP addresses,
	   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	   e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	/* The following string represents an atom (basically a series of
	   non-special characters.) */
	var atom=validChars + '+'
	/* The following string represents one word in the typical username.
	   For example, in john.doe@somewhere.com, john and doe are words.
	   Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")"
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	/* The following pattern describes the structure of a normal symbolic
	   domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	/* Finally, let's start trying to figure out if the supplied address is
	   valid. */
	
	/* Begin with the coarse pattern to simply break up user@domain into
	   different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
	  /* Too many/few @'s or something; basically, this address doesn't
	     even fit the general mould of a valid e-mail address. */
		alert('Your email address is invalid (check for @ and .)');
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	
	// See if "user" is valid 
	if (user.match(userPat)==null) {
	    // user is not valid
	    alert('The username portion of your email address is invalid.');
	    return false
	}
	
	/* if the e-mail address is at an IP address (as opposed to a symbolic
	   host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
	    // this is an IP address
		  for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
		    	alert('The destination IP address in your email address is invalid.');
			return false
		    }
	    }
	    return true
	}
	
	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert('The domain name in your email address is invalid.');
	    return false
	}
	
	/* domain name seems valid, but now make sure that it ends in a
	   three-letter word (like com, edu, gov) or a two-letter word,
	   representing country (uk, nl), and that there's a hostname preceding 
	   the domain or country. */
	
	/* Now we need to break up the domain to get a count of how many atoms
	   it consists of. */
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
	    domArr[domArr.length-1].length>3) {
	   // the address must end in a two letter or three letter word.
	   alert('Your email address must end in a three-letter domain, or two letter country.');
	   return false
	}
	
	// Make sure there's a host name preceding the domain.
	if (len<2) {
	   alert('Your email address is missing a hostname.');
	   return false
	}
	
	// If we've gotten this far, everything's valid!
	return true;
}
// END: Imported From emailCheck.js

// BEGIN: Imported from javascripts.cfm
/**
 * Gets the ip address of the server.
 * 
 * @return Returns a string. 
 * @author Robert Everland III (reverland@reactivevision.com) 
 * @version 1, January 12, 2004 
 */
function GetServerIP() {
   var iaclass="";
   var addr="";
      
   // Init class
   iaclass=CreateObject("java", "java.net.InetAddress");

   //Get Local host variable
   addr=iaclass.getLocalHost();

   // Return ip address
   return addr.getHostAddress();
}

/*
function popUpHelp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=450,height=450');");
}

function clearResForm(frmName) {
	var agree = confirm("You are about to clear your reservation form fields. Are you sure you wish to continue?");
	if (agree) {
		if(frmName == 'MainForm') {				
			document.MainForm.action = "reservationClearForm.cfm";				
			document.MainForm.submit();
		} else {				
			document.PaymentForm.action = "reservationClearForm.cfm";
			document.PaymentForm.submit();
		}
	} else {
		return false;
	}
}

function CheckRequiredFields () {
	if (document.forms.Login.userName.value != '' && document.forms.Login.password.value == '') {
		alert("You must enter a password.");
		document.forms.Login.password.focus();
		return false;
	} else if (document.forms.Login.password.value != '' && document.forms.Login.userName.value == '') {
		alert("You must enter a Username.");
		document.forms.Login.userName.focus();
		return false;
	}
	return true;
}

function pkgPopUp(x,y,z) {
	popUpWindow = window.open("/pkgPopUp.cfm?ID=" + x + "&resortID=" + y + "&Type=" + z, "pkgPopUpWindow", 
							  "height=500,width=530,scrollbars=1," + 
							  "resizable=1,screenX=200,screenY=100");
}
*/
// END: Imported from javascripts.cfm
