$(function(){
	$("#frmPass").submit(function(){
		$(".indicator, p.help, p.error").remove();
		$(".error").removeClass("error");
		var firstMissing = "";
		var bError = false;
		if($("#passwd").val()==""){
			if(firstMissing=="") firstMissing = "passwd";
			$("#passwd").addClass("error");
			bError = true;
		}
		if(bError){
			$("#frmPass").append('<p class="error">Please enter or fix the fields marked with <img alt="Error" src="/jscripts/images/alert.gif" /></p>');
			$("#"+firstMissing).focus();
		}else{
			$("#frmPass").append('<img class="indicator" src="/jscripts/images/indicator.gif" />');
			var formData = $("#frmPass").fastSerialize();
			formData.push({name: "isAjax", value: 1});
			$.post(
				ajaxURL,
				formData,
				function(txt){
					$(".indicator, p.help, p.error").remove();
					if(txt!=""){
						if(txt=="OK"){
							$("#frmPass").append('<p class="help">Password accepted. Please wait.</p>');
							setTimeout("protected('" + ajaxURL + "')",2000);
						}else{
							$("#frmPass").append('<p class="error">Ooops! Password wrong.</p>');
							$("p.error")
								.animate({opacity:0.999},10000)
								.fadeOut();
						}
						txt = null;
					}
				}
			);
		}
		return false;
	});
});
function protected(NewURL){
	location = NewURL;
}