// JavaScript Document


$(function(){
	$(".bmform2").hide();
	$(".contentrow h1").hide();	
	$("h3.canhide").hide();	
	$(".submitformbutton").addClass("submitdetailsbutton");
	
	// $("#content").hide();

	$("#check_in_date_820").focus(function(){ $("#check_in_date_820").addClass("nobg"); });
	$("#check_out_date_821").focus(function(){ $("#check_out_date_821").addClass("nobg"); });
	$("#arrival_time_a_825").focus(function(){ $("#arrival_time_a_825").addClass("nobg"); });
	
	$("#showform").click(function(){ 
		$('#content').fadeIn('slow');
	});
	
	$('.dateRange').datepicker({beforeShow: customRange, showOn: 'both', buttonImage: 'images/calendar.gif', buttonImageOnly: true, closeAtTop: false, showStatus: true });

	$("form.bmform").each(function() { resetUndo.init(this); })
});	
	
// CODE for fValidation
$().ready(function() {	
	var container = $('div.errorContainer');
	// validate the form when it is submitted
	$("#shortstayform").validate({
		errorContainer: container,
		errorLabelContainer: $("ul", container),
		wrapper: 'li',
		meta: "validate",
		event: "onsubmit",
		onblur: false,
		onkeyup: false,
		onfocusout: false,
		onsubmit: true		
	});
});

// CODE for fReset
var resetUndo =  {		
		init : function(arg){			
		form = $(arg);
		resetInput = form.find("input[@type=reset]");	
		resetInput.click(resetUndo.reset);
	},
	
	reset : function(){			
		var inputform =  $(this.form);			
		inputform.find("div.ResetNotify").remove();
		$("<div class=\"ResetNotify\"><strong>The contents of the form have been cleared.<\/strong> Click here to <a href=\"#\" class=\"undoResetLink\">undo reset<\/a>.<\/div>").appendTo(inputform);				
		var link = inputform.find("a.undoResetLink");				
		console.log(link);			
		this.form.undoBuffer = inputform.formToArray(true);				
		link.click(function() { resetUndo.undo(inputform); });
	},			
	undo : function (form){			
		form.deserialize(form.get(0).undoBuffer);				
		form.find("div.ResetNotify").remove();				
		return false;
	}
};

