function submitform(form_id) {
	$('#'+form_id).submit();
}

function clearThis(elmId,search,replace) {
	var field = $('#'+elmId);
	var val = field.val();
	if(val == search) {
		field.val(replace);
	}
}

/**
 * Updates the Tour details (date, package id's) on the SearchBox. Without
 * filling in this info, packages cannot be booked correctly.
 * 
 * @param selTour Tour Selection list box element
 * @return void
 */
function updateTourDetails(selTour) {
	var details = selTour.value.split('|');
	$('#frmsearchbox input[name="startdate"]').val(details[0]);

	$('#tour-ticket, #tour-travel-only, #select-pkg-msg').each(function() {
		this.style.display = 'none';
	});
	
	$('#tour-ticket-pkg, #tour-travel-only-pkg').each(function() {
		this.value = '';
	});
	
	if(parseInt(details[1]) > 0) {
		$('#tour-travel-only').show();
		var opt = $('#tour-travel-only-pkg');
		opt.val(details[1]);
		opt.show();
		//If TicketTravel is not available, force checked the TravelOnly travelradio box
		if( ! parseInt(details[2]) > 0) {
			opt.attr('checked', 'checked');
		} else {
			opt.removeAttr('checked');
		}
	}

	if(parseInt(details[2]) > 0) {
		$('#tour-ticket').show();
		var opt = $('#tour-ticket-pkg');
		opt.val(details[2]);
		opt.show();
		opt.attr('checked', 'checked');
	}
	
	if(parseInt(details[3]) > 0 || parseInt(details[4]) > 0)
	{
		(parseInt(details[3]) > 0) ?
			$('#r1c-container').show() :
			$('#r1c-container').hide();
		
		(parseInt(details[4]) > 0) ?
			$('#r1i-container').show() :
			$('#r1i-container').hide();
		
		$('#r1a option').each(function(){
			this.text = this.text.replace('tickets', 'adult tickets');
		});
	}
	else
	{
		$('#r1a option').each(function(){
			this.text = this.text.replace('adult tickets', 'tickets');
		});
		$('#r1c-container, #r1i-container').hide();
		$('#r1c option[value=0], #r1i option[value=0]').attr('selected', 'selected');
	}
	
	if(typeof details[1] == 'undefined' || typeof details[2] == 'undefined') {
		$('#select-pkg-msg').show();
	}
}

function validateSearchBox(form) {
	var ticket_pkg = $('#tour-ticket-pkg');
	var coach_pkg = $('#tour-travel-only-pkg');
	
	var ticket_pkg_val = (typeof ticket_pkg != 'undefined' && ticket_pkg.length > 0) ? ticket_pkg.val() : 0;
	var coach_pkg_val = (typeof coach_pkg != 'undefined' && coach_pkg.length > 0) ? coach_pkg.val() : 0;
	
	if(form.startdate.value == '') {
		return false;
	} else if(ticket_pkg_val.length == 0 && coach_pkg_val.length == 0) {
		return false;
	} else if(form.r1a.value == 0 && form.r1c.value == 0 && form.r1i.value == 0) {
		return false;
	} else {
		return true;
	}
}