
/*
 * Hotel Penn master javascript file - jquery 1.3 dependant
 * 10.5.2009 Bjackson
*/
//Force background cache for IE 6, otherwise calendar rendering is too slow
	try{
		document.execCommand("BackgroundImageCache", false, true);
	} catch(exception) {
		// other browsers do nothing
	}
	
// Code runs when document is ready, images are still loading
$(document).ready(function(){
						   
	//Setup the date picker and range restriction
	$("#reservations-form #DateIn").datepicker({showOn: 'button', buttonImage: 'images/calendar-icon.gif', buttonImageOnly: true, showAnim: 'fadeIn',duration:0,numberOfMonths:2,beforeShow:restrictDateRange});
	$("#reservations-form #DateOut").datepicker({showOn: 'button', buttonImage: 'images/calendar-icon.gif', buttonImageOnly: true, showAnim: 'fadeIn',duration: 0,numberOfMonths:2,beforeShow:restrictDateRange});								

	
	//Setup toggling prompts based on the rel attribute of the inputs
	$('#reservations-form input.prompting, #email.prompting, #footer-email.prompting, #meeting-reservation-form input.prompting').each(function(){
		$(this).focus(function(){					
			if($(this).val() == $(this).attr('rel')){						
				$(this).val('');						
			}
		});
		$(this).blur(function(){
			if($(this).val() == ''){						
				$(this).val($(this).attr('rel'));
			}
		});
	});
	
	//change the promo code variable name before submitting if not changed
        //since travel click counts an empty variable as an invalid code!?
        //Handle unchanged date inputs due to tc change
        //Adjust adults value if rooms > 2
	$('#reservations-form').submit(function(){
		if($('#identifier').val() == $('#identifier').attr('rel')){
                    $('#identifier').attr('name','noidentifier');
		}
                if($('#DateIn').val() == $('#DateIn').attr('rel')){
                    $('#DateIn').attr('name','noDateIn');
                }
                if($('#DateOut').val() == $('#DateOut').attr('rel')){
                    $('#DateOut').attr('name','noDateOut');
                }
                if($('#Rooms').val() > 2){
                    $('#Adults').val($('#Rooms').val());
                }else{
                     $('#Adults').val('2');
                }
	
        });

        //Setup simple alert based validation for global email sub boxes
        $('#mail-list-form').submit(function(){
            if($('#mail-list-form #email').val() == $('#mail-list-form #email').attr('rel') || $('#mail-list-form #email').val() == ""){
                alert('Please enter a valid email address.');
                return false;
            }
        });

        $('#footer-mail-list-form').submit(function(){
            if($('#footer-mail-list-form #footer-email').val() == $('#footer-mail-list-form #footer-email').attr('rel') || $('#footer-mail-list-form #footer-email').val() == ""){
                alert('Please enter a valid email address.');
                return false;
            }
        });
	
	//Setup url linking from special offers select box, language select box & i heart ny
	$('#special-offers-select, #language-select, #i-love-newyork-select').change(function(){
		var url = $(this).val();
		if(url != 'none' && url != null){
			location.href = url;
		}
	});
	
	//Nav fixes for IE6 not executing hover class on anything but links
	if(document.all){$("#nav-list li").hover(function(){$(this).addClass("ie6hover")},function(){$(this).removeClass("ie6hover")});}
	if(document.all){$("#subpage-header ul li").hover(function(){$(this).addClass("ie6hover")},function(){$(this).removeClass("ie6hover")});}
		
});				

// Function called before show of datepicker - keeps date range in sync.
// Restricts checkout day to be min checkin date + 1 day, and check in date to be today
// NOT restricting date in < date out since it can cause visual confusion about availability.
function restrictDateRange(input){						
	if(input.id == "DateOut"){	
		var dateIn = new Date($("#reservations-form #DateIn").datepicker('getDate'));
		dateIn.setDate(dateIn.getDate()+1);
		$("#reservations-form #DateOut").datepicker('option','minDate',dateIn);
	}else if(input.id == "DateIn"){			
		$("#reservations-form #DateIn").datepicker('option','minDate',new Date());
	}
}



