var oFocus; //object to move the focus to after closing a dialog

function validateLoginForm() {
	var sError="";
	if(!$("#LoginUsername").val() || ($("#LoginUsername").val()=="username")) {
		sError+="<li>The Login ID is required.</li>";
		if(!oFocus) oFocus=$("#LoginUsername");
	}
	if(!$("#LoginPassword").val() || ($("#LoginUsername").val()=="password")) {
		sError+="<li>The Password is required.</li>";
		if(!oFocus) oFocus=$("#LoginPassword");
	}
	
	if(sError!="") {
		modalMessage("Missing Information","Please correct the following error(s) before proceeding:<ul>" + sError + "</ul>",true);
		return(false);
	}
	return(true);
}
(function($) {
	$(function() { //on DOM ready
		$("#LoginUsername").bind("focus",function() {
			if($(this).val()=="username") {
				$(this).val("");
				$(this).css("color","#252525");
			}
		}).bind("blur",function() {
			if($(this).val()=="") {
				$(this).val("username");
				$(this).css("color","#848484");
			}
		});
		$("#LoginPassword").bind("blur",function() {
			if($(this).val()=="") {
				$("#LoginPasswordDisplay").show();
				$("#LoginPassword").hide();
			}
		});
		$("#LoginPasswordDisplay").bind("focus",function() {
			$("#LoginPasswordDisplay").hide();
			$("#LoginPassword").show();
			$("#LoginPassword").focus();
		});
		$("#LoginPassword").hide();
		
		//standard dialog
		$("#divDialog").dialog({
			bgiframe: true,
			modal: true,
			buttons: {
				Ok: function() {
					$(this).dialog('close');
					if(oFocus) {
						oFocus.focus();
						oFocus=null;
					}
				}
			},
			autoOpen: false,
			width:700,
			height:500
		});
	});
})(jQuery);

//shows a modal message similar to the alert commend, but using our styled dialog
function modalMessage(sTitle,sContents,bAlert) {
	if(bAlert) sContents='<span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>' + sContents;
	$('#divDialog').dialog('close');
	$('#divDialog').dialog('option','title',sTitle);
	$('#divDialog').dialog('option','width',400);
	$('#divDialog').dialog('option','height','auto');
	$('#divDialog').dialog('option','maxHeight',500);
	$("#divDialog").html(sContents).dialog("open");
}

