// JavaScript Document

/* 
	Function to Update the meal type for the member 
	With Prototype style Ajax request
*/





function LoginCheck()
{

	/* Serialiaze the form to send param to inc_registration.asp */
	//frmValue = $('frmLogin').serialize()
	
	/* Collect Form data */
	var form = $('frmLoginBar');
	var email = form['email_address'];
	var pass = form['password'];
	
	
	var passHash = hex_sha256($F(pass));

	

	var url = "login_bar.asp?sysAction=login&email_address=" + $F(email) + "&password=" + passHash  ;

		/* Prototype style Ajax Request */
		new	Ajax.Request(url, {
			method: 'get',
			
			/* Prototype Ajax.Request when receive 2xx status */
			onSuccess: function(transport) 
			{
				
				/* Email found on the database abort the registration */
				if (transport.responseText.match("Login Sucessful"))
				funcSucessful();
	
				//* Invalid Email Address */
				if (transport.responseText.match("Invalid Email Address"))
				funcEmail();
		
				/* Invalid Password */
				if (transport.responseText.match("Invalid Password"))
				funcPassword();
				
				/* Expired account */
				if (transport.responseText.match("Subscription Expired"))
				funcExpired();
				
				/* Unfinished account */
				if (transport.responseText.match("unfinished"))
				funcUnfinished();
												
				/* Disabled account */
				if (transport.responseText.match("Your account has been disabled"))
				funcDisabled();
				

			}
	
		});
}


function funcDisabled()
{
	/* Define the divisions */
	var loginError = $('loginError');
	window.location = "login.asp?msg=disabled";
	//loginError.update('It appears you\'ve cancelled your account.  Please create a new account, or email us at YourTeam@HastyChef.com to re-activate your old one.  Please include your name and the email address associated with your old account.  Thank you.');
}

function checkEnter(event)
{
	if(event.keyCode == 13) 
	{
		LoginCheck();
	}	
}

function funcUnfinished()
{
	window.location = "https://www.hastychef.com/sign_up_continue.asp";
	
};

function funcSucessful()
{
		var d = new Date()
		var t = d.getTime()

	//alert('success');
	window.location = "weeks-recipe.asp?cache=" + t ;
}

function funcEmail()
{
	//alert('Email');
	window.location = "login.asp?msg=email";
}

function funcPassword()
{
	window.location = "login.asp?msg=pass";
}

function funcExpired()
{
	window.location = "profile-expired.asp";
}
