$(document).ready( function()
{

	if ($.browser.msie)
	{
		if (parseInt($.browser.version) <= 6)
		{
			$("#oldBrowser").show();
		}
	}

	$(".lostUsername").click(function () {
		$("#loginForm").hide();
		$("#lostUsernameForm").show();
		
	});
	
	
	$(".lostPassword").click(function () {
		$("#loginForm").hide();
		$("#lostPasswordForm").show();
	});

	$(".lostCancel").click(function () {
		$("#loginForm").show();
		$("#lostUsernameForm").hide();
		$("#lostPasswordForm").hide();
		
	});
	
	$(".retrievePassword").click(function () {
		lostPassword();
	});
	
	$(".retrieveUsername").click(function () {
		lostUsername();
	});
	
	
	
});

function lostPassword()
{	
	var retrieval = $("#lostPasswordForm").serializeArray();
	
	retrieval.push({
		name:'currentView',
		value:'JSON'
	});
	
	$.post("/lostPassword", retrieval, function(j)
	{
		lostPasswordReturn(j);
	},"json");	
}


function lostPasswordReturn(j)
{		
	if (j.error.count > 0)
	{
		genError(j.error,'Sorry, we had errors...', $("#lostPasswordForm"));
	}
	else if (j.success == true)
	{
		clearMessages($("#lostPasswordForm"));
		
		$(".lostCancel").click();
		genSuccess('Your password was successfully retrieved and sent',$("#loginForm"));
	}
}

function lostUsername()
{	
	var retrieval = $("#lostUsernameForm").serializeArray();
	
	retrieval.push({
		name:'currentView',
		value:'JSON'
	});
	
	$.post("/lostUsername", retrieval, function(j)
	{
		lostUsernameReturn(j);
	},"json");	
}


function lostUsernameReturn(j)
{		
	if (j.error.count > 0)
	{
		genError(j.error,'Sorry, we had errors...', $("#lostUsernameForm"));
	}
	else if (j.success == true)
	{
		clearMessages($("#lostUsernameForm"));
		
		$(".lostCancel").click();
		genSuccess('Your username was successfully retrieved and sent',$("#loginForm"));
	}
}

