/*function login()
{
	document.getElementById('welcomeLogin').style.display='none';
	document.getElementById('loginContainer').style.display='block';
	document.getElementById('email').focus();
}*/
$(document).ready(function(){
	function updateTips(t)
	{
		tips.text(t).addClass('ui-state-highlight');
		setTimeout(function() {
			tips.removeClass('ui-state-highlight', 1500);
		}, 500);
	}

	function checkLength(o, n, min, max)
	{
		if (o.val().length > max || o.val().length < min) {
			o.addClass('ui-state-error');
			updateTips("The " + n + " field must be between "+min+" and "+max+".");
			return false;
		} else {
			return true;
		}
	}
	var email = $("#email"),
		password = $("#password"),
		allFields = $([]).add(email).add(password);

	$("#loginContainer").dialog({
		autoOpen: false,
		height: 320,
		width: 500,
		modal: true,
		show: 'fade',
		hide: 'fade',
		title: 'Login to HomeFree',
		buttons: {
			'Login': function()
			{
				var bValid = true;
				allFields.removeClass('ui-state-error');

				bValid = bValid && checkLength(email, "email", 1);
				bValid = bValid && checkLength(password, "password", 1);

				if (bValid)
				{
					$("#loginForm").submit();
				}
			},
			Cancel: function()
			{
				$(this).dialog('close');
			}
		},
		close: function()
		{
			allFields.val('').removeClass('ui-state-error');
		}
	});

	$('#loginOpen').click(function() {
		$("#loginContainer").dialog('open');
	});
});

$(function(){
	$("#remember").button({icons: {primary: 'ui-icon-check'}});
});
