// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function doPostHotelChangeTasks() {
	// verifyDatesSet(); // 2008-06-23 we're no longer validating based on date
	openInfoWindow();
	emptyBeddingAndRoomtypeValues();
}
function verifyDatesSet() {
	if( $('hotel_request_checkin_date').value == '' ) {
		alert( "Please choose a Check In date first." );
	}
	else if( $('hotel_request_checkout_date').value == '' ) {
		alert( "Please choose a Check Out date first." );
	}
}
function openInfoWindow() {
	//call function that was dynamically defined in the new.rhtml document
	open_iw[$('hotel_request_hotel_id').value]();
}
function emptyBeddingAndRoomtypeValues() {
	$('hotel_request_bedding').value = '';
	// no longer being used $('hotel_request_room_type').value = '';
}

function setBeddingValue(val){
    form = document.forms[0];
    form.hotel_request_bedding.value = val;
}

function setRoomtypeValue(val) {
	form = document.forms[0];
	form.hotel_request_room_type.value = val;
}

function checkExpiryDates() {
	if( $('hotel_request_cc_expiry_month').value == '' || $('hotel_request_cc_expiry_year').value == '') {
		alert("Credit card expiration dates must be set before submitting the request.");
		return false;
	}
}

function displaySpinner() {
	$('spinner').style.visibility = 'visible';
}

function hideSpinner() {
	$('spinner').style.visibility = 'hidden';
}

function validateAuthorizationCode(value) {
	new Ajax.Request('/hotel_request/validate_authorization_code', {
		asynchronous:true,
		evalScripts:true,
		parameters:'authorization_code=' + escape(value)
	});	
}

function selectAuthorizationCode() {
	$('hotel_request_authorization_code').select();
}

function setDummyField() {
	$('dummy_field').value = $('hotel_request_first_name').value + ' ' + $('hotel_request_last_name').value;
}

function toggleAvailability(id,attendee_type) {
	new Ajax.Request('/blocks/toggle_availability/'+id, {
		asynchronous: true,
		evalScripts: true,
		parameters: 'attendee_type=' + escape(attendee_type)
	});
}

function toggleTdClass(element_name) {
	$(element_name).hasClassName('checked') ? $(element_name).removeClassName('checked') : $(element_name).addClassName('checked');
}

function toggleBlockDate(block_id, date_id) {
	new Ajax.Request('/blocks/toggle_date/'+block_id, {
		asynchronous: true,
		evalScripts:true,
		parameters: 'date_id=' + escape(date_id)
	});
}

function updateBlockBedding(block_id, beddings_value) {
	//alert(block_id + ' ' + beddings_value);
	new Ajax.Request('/blocks/update_bedding/'+block_id, {
		asynchronous: true,
		evalScripts: true,
		parameters: 'beddings=' + escape(beddings_value)
	});
}
