window.name = 'main';

// stop right click menu just on images
function noclickimagemenu(){
   		var imgs
   		imgs=document.getElementsByTagName('img');

		// checks for a park background image and disables
		if(document.getElementById('park-home-bg')) {
		   document.getElementById('park-home-bg').oncontextmenu= function(){ return false;}
		}

		// all img tag references on all pages
		for(var i=0;i<imgs.length;i++) {
			document.images[i].oncontextmenu= function(){ return false;}
		}
}


function checkObject(o) {
	var s = '';
	for(var i in o) { s+=i+'   '; }
	alert(s);
}

function swapImage(o,s) {
	o.src = o.src.replace(/\_\d\./, '_'+s+'.');
}
// Can cause issues with ie6 when closing the popUp. Be carefull
function winOpen() {
	var a = arguments;
	var n,f,s,w,h,t,l;
	n = (a[1]) ? a[1] : 'child';
	f = (a[6]) ? a[6].toString() : null;
	s = (f && f.search(/scrollbars=(1|true)/) != -1);
	w = getWidth(a[2],s);
	h = a[3];
	t = (a[4]) ? a[4] : 0;
	l = (a[5]) ? a[5] : 0;
	child = window.open(a[0],n,'width='+w+',height='+h+',top='+t+',left='+l+',directories=0,'+f);
	setTimeout('child.focus()',100);
	if(f && f.search(/temp=(1|true)/) != -1) window.onfocus = function(){ if(window.child) child.close(); child = null };
}

function vrxWindowOpen (href){
         winOpen(href,'popUp',925,625,5,5,'status=0,resizable=0,scrollbars=0,location=0');
}

//Used window.open to fix weird ie6 crashing issue.
function fullWindowOpen (href){
         //winOpen(href,'popUp',(screen.width),(screen.height),0,0,'status=0,resizable=1,scrollbars=1,location=0');
         window.open(href,'popUp','width=' +(screen.width)+', height='+(screen.height)+',top =0, left=0, status=0,resizable=1,scrollbars=1,location=0');
}

function voucherChecker(){
        var ccTypelabel = $("type-label");
        var ccNumberlabel = $("number-label");
        var ccExpDate = $("exp-label");
        var ccDropDown = $("creditcardtype");
        
        var selIndex = ccDropDown.options[ccDropDown.selectedIndex].value;
        
        if(selIndex == "V"){
                ccTypelabel.innerHTML = '<span style="font-size: 12px; color: red;">*</span> Payment Type:';      
                ccNumberlabel.innerHTML = '<span style="font-size: 12px; color: red;">*</span> Voucher #:';      
                ccExpDate.innerHTML = '<span style="padding:0 0 0 8px;"> Expiration Date:</span>';      
        }else{
                ccTypelabel.innerHTML = '<span style="font-size: 12px; color: red;">*</span> Credit Card Type:';      
                ccNumberlabel.innerHTML = '<span style="font-size: 12px; color: red;">*</span> Credit Card #:';      
                ccExpDate.innerHTML = '<span style="font-size: 12px; color: red;">*</span> Expiration Date:';    
        }
}

addEvent(window,"load",function(){
        if($("creditcardtype")){
                  addEvent($("creditcardtype"),"change",voucherChecker);   
                  voucherChecker();
        }
});



function UA(){
	var v = navigator.appVersion.toLowerCase(), u = navigator.userAgent.toLowerCase(), n = navigator.appName;
	this.full = navigator.appVersion.toLowerCase(), u = navigator.userAgent.toLowerCase(), n = navigator.appName;
	this.mac = (v.indexOf("mac")+1);
	this.win = (v.indexOf("win")+1);
	this.safari = (u.indexOf("safari")+1);
	this.nn = (n == "Netscape");
	this.ie = (n == "Microsoft Internet Explorer");
}
var ua = new UA();

function getWidth(w,s) {
	if(s) {
    if(ua.mac) {
    	if(ua.nn) w += 17;
			if(ua.safari)	w -= 4;
    }
    if(ua.win) w += 16;
  } else {
		if(ua.safari)	w -= 2;
  }
return w;
}

function printWindow() {
  if(window.print) {
    window.print();
  } else {
		alert('Your browser doesn\'t support this feature. Please select "Print" from your File menu.');
  }
}


// Generic Shorthand GetElement Function
function $(){
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string') {
			if (document.getElementById){element = document.getElementById(element);}
			else if (document.all){element = document.all[element];}
		}
		if (arguments.length == 1) {return element;}
		elements.push(element);
	}
	return elements;
}

// Add Event Function
function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
    obj.attachEvent( 'on'+type, obj[type+fn] );
  } else
    obj.addEventListener( type, fn, false );
}



/**
 * helper function to make a simple date object for use with fixDate and fixDates from todays date
 */
function makeSimpleDateFromToday()
{
	var tobj = new Object;

	tobj.y = window.today[0];
	tobj.m = window.today[1]+1;
	tobj.d = window.today[2];

	return tobj;
}

/**
 * fixDates is called on pageload by the quickbook.
 * fixDates now handles a very special case for pre-opening, for example:
 *		* Todays Date is July 15th 2006
 *		* The user visits a pre-opening property that opens March 8th 2008
 *		* The user now visits the main Hyatt site, or a normal property site
 *		* The initially selected day portion of the date, which should be the 15th, remains the 8th
 *		* The fixDate javascript properly only allows the day range from the 14th-31st of August
 *		* because the selected day is the 8th, the selected day now becomes the 14th (yesterdays date)
 */
function fixDates(id,dir,dateobj) {

	var o = document.getElementById(id);

	var validateAndFixPreOpeningProblem = function()
	{
		if (dateobj)	// if we're passed a dateobj, we are in a pre-opening quickbook, so no need to run this
			return;

		today = makeSimpleDateFromToday();

		var checkInYearMonthSelect = o['monthyear0'];
		var checkInDaySelect = o['day0'];

		if ((checkInYearMonthSelect.selectedIndex == 0) && ((checkInDaySelect.selectedIndex + 1) < today.d))
		{
			checkInDaySelect.selectedIndex = today.d-1;
		}
	}

	validateAndFixPreOpeningProblem();

	if(o && o.monthyear0 && o.monthyear1) {
		fixDate(o.monthyear0,dir,dateobj);
		fixDate(o.monthyear1,dir,dateobj);
	}
}

/**
 * Refactoring notes:
 *	There is still some disconnect between the date in the checkInDate and checkOutDate, and the actual select values
 *
 *	Refactored functions are in the form of
 *		var funcname = function( ... ) { ... }
 *
 * Behavioral notes:
 *	- if the check-in month/year selected is the last of the list, then the days for the checkin should be one less then the total number of days
 *  - When a different month is selected, the days displayed needs to be calculated, and updated.
 *
 * PreOpening notes:
 *	If you are using this function with PreOpening, then you may want to use the
 *	prepPreOpeningFixDate funciton, which will modify this funciton on the fly
 *	to use the selected pre-opening date.  By using this function, fixDate will
 *	act the way the rest of the Hyatt website expects it to.
 *
 *@param	htmlSelectElement	o			the select element that caused the update
 *@param	(unknown)			dir			dir relates to the start and end dates
 *@param	object				startDate	an object representing the minimum date for the startDate, should have the y, m, and d properties. Used for pre-opening.
 */

function fixDate(o,dir,startDate)
{
	/**
	 * This code was deactivated in the origional version, to deal with CR 8042.
	 * if/when this behavior is fixed, or moved to the conference page containing the quickbook,
	 * reactivate it.
	 */
	var ACTIVATE_ON_CHECK_OUT_SELECT = false;

	var CHECK_IN_SELECT = 0;
	var CHECK_OUT_SELECT = 1;

	var SET_DATE_TO_LAST_DAY = 69;

	var today = makeSimpleDateFromToday();
	var checkInDate = new Object;
	var checkOutDate = new Object;

	var isPreOpening = (startDate) ? true : false;

	if (isPreOpening)
	{
		today.y = startDate.y;
		today.m = startDate.m;
		today.d = startDate.d;
	}

	var checkInYearMonthSelect = o.form['monthyear0'];
	var checkInDaySelect = o.form['day0'];
	var checkOutYearMonthSelect = o.form['monthyear1'];
	var checkOutDaySelect = o.form['day1'];

	/**
	 * Return the number of days in a given month.  Note that this handles leap-years
	 *@param	year	Year of the month
	 *@param	month	Month of the month, 1=Jan, 2=Feb....
	 */
	var getDaysInMonth = function(cy,cm) {
		var a = new Array(31, ((cy % 4 == 0 && cy % 100 != 0) || cy % 400 == 0 ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
		return a[cm-1];
	}

	/**
	 * A helper function to sync the checkInDate and checkOutDate variables with the GUI select boxes.
	 */
	var syncVars = function() {
		checkInDate.y = parseInt('20'+checkInYearMonthSelect.value.toString().substring(3));
		checkInDate.m = parseInt(checkInYearMonthSelect.value.toString().substring(0,2),10);
		checkInDate.d = parseInt(checkInDaySelect.value);

		checkOutDate.y = parseInt('20'+checkOutYearMonthSelect.value.toString().substring(3));
		checkOutDate.m = parseInt(checkOutYearMonthSelect.value.toString().substring(0,2),10);
		checkOutDate.d = parseInt(checkOutDaySelect.value);

		/**
		 * This is a cheesy hack to make sure that pre-opening properties will properly select the next
		 * date.  This is because the java object responsible for selecting the check out date isn't
		 * working quite right, so it is easier to fix it here.
		 */
		if (isPreOpening)
		{
			if (checkOutDate.d > today.d + 1)
			{
				checkOutDate.d = today.d + 1;
			}
		}
	}


	/**
	 * This function is polymorphic.  It can work on the check in or the check out date.
	 *@param	dateSet		int		The "set" of check in dates to work with (SELECT_CHECK_IN, SELECT_CHECK_OUT)
	 *@param	v			mixed	day in the month to set
	 */
	var syncMonth = function(dateSet,v)
	{
		syncVars();

		var yearMonthSelect, daySelect, dateData

		if (dateSet == CHECK_IN_SELECT)
		{
			yearMonthSelect = checkInYearMonthSelect;
			daySelect = checkInDaySelect;
			dateData = checkInDate;
		}
		else
		{
			yearMonthSelect = checkOutYearMonthSelect;
			daySelect = checkOutDaySelect;
			dateData = checkOutDate;
		}

		var lastDayInSelectedMonth = getDaysInMonth(dateData.y, dateData.m);
		var selectedDateLessThenToday = (dateData.y<today.y || (dateData.y==today.y && dateData.m<today.m));

		var startDay, endDay;

		if (dir)
		{
			if ((dateSet == CHECK_OUT_SELECT) && yearMonthSelect.selectedIndex==0)
				startDay = 2;
			else
				startDay = 1;

			if (today.y==dateData.y && today.m==dateData.m)
			{
				if (dateSet == CHECK_OUT_SELECT)
					endDay = today.d+1;
				else
					endDay = today.d;
			}
			else
				endDay = lastDayInSelectedMonth;
		}
		else
		{
			if (selectedDateLessThenToday)
				startDay = lastDayInSelectedMonth;
			else
			{
				if (today.y==dateData.y && today.m==dateData.m && today.d>1)
				{
					 if (dateSet == CHECK_OUT_SELECT)
						 startDay = today.d;
					 else if (dateData[0] == null)
						 startDay = (today.d);
					 else
						 startDay = (today.d-1);
				}
				else
					startDay = 1;
			}

			if (dateSet = CHECK_IN_SELECT && (yearMonthSelect.selectedIndex==yearMonthSelect.options.length-1))
				endDay = lastDayInSelectedMonth - 1;
			else
				endDay = lastDayInSelectedMonth;
		}

		var selectedDay;

		if (v == SET_DATE_TO_LAST_DAY)
		{
			selectedDay = endDay;
		}
		else if (!v)
		{
			selectedDay = Math.max(Math.min(dateData.d, endDay), startDay);
		}
		else
		{
			selectedDay = v;
		}

		var updateHtmlSelectBox = function(sel, start, end)
		{
			daySelect.options.length = 0;
			for (var i=start, c=0; i < (end+1); i++, c++)
			{
				daySelect.options[c] = new Option(i, i);
				if(daySelect.options[c].value==sel)
					daySelect.selectedIndex = c;
			}
			dateData.d = parseInt(daySelect.value);
		}

		updateHtmlSelectBox(selectedDay, startDay, endDay);
	}

	/**
	 * Changes a given html select (for the day) to the specified value
	 *@param	htmlSelect	DOM.HtmlSelectElement	the html select element to operate on
	 *@param	v			int						the date to move to
	 */
	var syncDay = function(htmlSelect,v) {
		for(i=0; i<htmlSelect.options.length; i++) {
			if(htmlSelect.options[i].value == v) {
				htmlSelect.selectedIndex = i;
				break;
			}
		}
	}

	/**
	 * Tells us if the date is at a "critical boundry", i.e. check in is the last day of the month, or checkout is the first day
	 */
	var isDateAtCriticalBoundry = function()
	{
		if (set == CHECK_IN_SELECT){
			return checkInDate.d==getDaysInMonth(checkInDate.y, checkInDate.m);
		}else{
			return checkOutDate.d==1;
		}
	}

	var monthSelectBoxActivated = function()
	{
		return (!(o.id.indexOf('day')+1));
	}

	/**
	 * If the month and year are the same, is the checkout day before the check in day?
	 */
	var isCheckOutDayBeforeCheckInDay = function()
	{
		return (checkOutDate.y==checkInDate.y && checkOutDate.m==checkInDate.m && checkOutDate.d<=checkInDate.d);
	}

	/**
	 * Is the checkout month/year before the checkin month/year?
	 */
	var isCheckOutBeforeCheckIn = function()
	{
		return (checkInDate.y <= checkOutDate.y || (checkOutDate.y == checkInDate.y && checkOutDate.m <= checkInDate.m));
	}

	var set = parseInt(o.id.substring(o.id.length-1));
	syncVars();

	if(monthSelectBoxActivated()) {
		syncMonth(set);
	}

										 // (o2.y<o1.y || (o2.y==o1.y && o2.m<=o1.m)
	var eor = (isDateAtCriticalBoundry() && (checkInDate.y>=checkOutDate.y || (checkInDate.y==checkOutDate.y && checkInDate.m > checkOutDate.m)));

	if(checkInDate.y>checkOutDate.y || (checkInDate.y==checkOutDate.y && checkInDate.m>checkOutDate.m) || eor)
	{
		var selectBoxesSameLength = (checkInYearMonthSelect.options.length == checkOutYearMonthSelect.options.length);

		if (set == CHECK_OUT_SELECT)
		{
			if (ACTIVATE_ON_CHECK_OUT_SELECT)
			{
				if (eor)
				{

					if (selectBoxesSameLength){
						checkInYearMonthSelect.selectedIndex = checkOutYearMonthSelect.selectedIndex - 1;
					}else{
						checkInYearMonthSelect.selectedIndex = checkOutYearMonthSelect.selectedIndex;
						syncMonth(CHECK_IN_SELECT, SET_DATE_TO_LAST_DAY);
					}

				}
				else
				{

					checkInYearMonthSelect.selectedIndex = checkOutYearMonthSelect.selectedIndex;
					syncMonth(CHECK_IN_SELECT, checkOutDate.d-1);
				}
			}
		}
		else
		{
			if (eor)
			{
				if (selectBoxesSameLength)
					checkOutYearMonthSelect.selectedIndex = (checkInYearMonthSelect.selectedIndex+1);
				else
					checkOutYearMonthSelect.selectedIndex = checkInYearMonthSelect.selectedIndex;

				syncMonth(CHECK_OUT_SELECT, 1);
			}
			else
			{
				if (selectBoxesSameLength)
					checkOutYearMonthSelect.selectedIndex = checkInYearMonthSelect.selectedIndex;
				else
					checkOutYearMonthSelect.selectedIndex = checkInYearMonthSelect.selectedIndex - 1;

				syncMonth(CHECK_OUT_SELECT, (checkInDate.d+1));
			}
		}
	}
	else if(isCheckOutDayBeforeCheckInDay())
	{
		if(set == CHECK_OUT_SELECT)
		{
			if (ACTIVATE_ON_CHECK_OUT_SELECT)
				syncDay(checkInDaySelect, checkOutDate.d-1);
		}
		else
		{
			syncDay(checkOutDaySelect, checkInDate.d+1);
		}
	}
}

/**
 * Wrap fixdate for preopening properties
 * Because pre-opening uses a date in the future versus the current date, we
 * need to modify the behavior of the fixdate funciton to set the boundry date
 * to the earliest pre-opening date, versus today.
 *
 * The problem is that the calendar javascript also needs to call fixdate, but
 * calendar.js it doesn't necessarily know it is dealing with a pre-opening
 * property.
 *
 * The fix is to redefine the fixdate function, to a new function that calls it
 * with the proper ppreopening arguments
 *
 * Usage:
 *  Before calling any fixDate functions, prep it with this function first:
 *		prepPreOpeningFixDate({y:2023, m:5, d:23});
 *	Be sure that there are no leading zeros in your date, otherwise Javascript
 *	will interpret them to be octal.
 */
function prepPreOpeningFixDate(preOpeningDate)
{
	var oldFixDate = fixDate;
	var oldFixDates = fixDates;

	fixDate = function(o,dir)
	{
		oldFixDate(o,dir,preOpeningDate);
	}

	fixDates = function(o,dir)
	{
		oldFixDates(o,dir,preOpeningDate);
	}
}


//OLD SITE BELOW....
function submitForm(formref) {
	window.document.getElementById(formref).submit();
}

function resetSelectedIndex(f) {
  for(var i=0; i<f.elements.length; i++) {
    if(f.elements[i].type == 'select-one') {
      f.elements[i].selectedIndex = 0;
    }
  }
}

// called by a link to submit a form, disables the link after the first click
function disableLinkAndSubmitForm(objAnchor, message, formID){
    var form = document.getElementById(formID);
    objAnchor.innerHTML = message;
    objAnchor.onclick = function(){return false};
    form.submit();
    return false;
}

//Works for both button and hyper link
function toggleCheckboxes(formName, checkboxNamePrefix)
{		
	var aForm = document.forms[formName];
	//
	for (var i=0; i < aForm.elements.length; i++)
	{
		if (aForm.elements[i].type == "checkbox")
		{	
			if (aForm.elements[i].name.indexOf(checkboxNamePrefix) == 0)
			{				
				aForm.elements[i].checked = !aForm.elements[i].checked;
			}
		}
	}	
}

function externalLinkImageOn(element){	
		$(element).down(1).removeClassName('external-link-image');
		$(element).down(1).addClassName('external-link-image-hover');  	
}

function externalLinkImageOff(element){	
		$(element).down(1).removeClassName('external-link-image-hover');
		$(element).down(1).addClassName('external-link-image');  
}


function tcToggleFaq(element){
	element=$(element);
	if(element.hasClassName('tc-faq-link')){
		element.removeClassName('tc-faq-link');	
		element.addClassName('tc-faq-link-expanded');	
		element.next().setStyle({
			display: 'block'
		});    		
	}
	else{
		element.removeClassName('tc-faq-link-expanded');
		element.addClassName('tc-faq-link');
		element.next().setStyle({
			display: 'none'
		});    		
	}
}
