// JavaScript Document

function chkform(theForm)
{
    
    if (theForm.txtmbrid.value == "")
    {
        alert("You must enter a user ID");
        theForm.txtmbrid.focus();
        return (false);
    }
    
    if (theForm.txtmbrid.value.length < 1)
    {
        alert("You must enter a user ID.");
        theForm.txtmbrid.focus();
        return (false);
    }
    
    if (theForm.txtmbrid.value.length > 64)
    {
        alert("User ID cannot be more than 64 characters.");
        theForm.txtmbrid.focus();
        return (false);
    }
    if (theForm.txtmbrpassword.value == "")
    {
        alert("You must enter a password.");
        theForm.txtmbrpassword.focus();
        return (false);
    }
    
    if (theForm.txtmbrpassword.value.length < 1)
    {
        alert("You must enter a password.");
        theForm.txtmbrpassword.focus();
        return (false);
    }
    
    if (theForm.txtmbrpassword.value.length > 64)
    {
        alert("Password cannot be more than 64 characters.");
        theForm.txtmbrpassword.focus();
        return (false);
    }
       
    // Return clean
    //  return (true);
    return process_Login();
}

function process_Login() {
	Spry.Utils.submitForm('frmlogin', updateResponse_Login);

	// Show loading graphic
	TW_changeStyle('frmlogin','hideme');
	TW_changeStyle('loading_login','loading');
	return false;
}

function updateResponse_Login(req) {
	var returnmsg = req.xhRequest.responseText;
	
	// Restore form
	TW_changeStyle('loading_login','hideme');				
	TW_changeStyle('frmlogin','showme');	
		
	if (returnmsg.indexOf('Failure:') == 0) { // Failed login
		returnmsg = '<p class="alert">' + returnmsg + '</p>';
		Spry.Utils.setInnerHTML('msg_Login',returnmsg);
	} else {	
		Spry.Utils.setInnerHTML('msg_Login','<p class="alert">Success! Redirecting ...</p>');
		switch (returnmsg)
		{
			case "password":
				window.location = "MA_ChangePassword.asp";
			break
			case "hambrget":
				window.location = "hambrget.asp";
			break
			case "approveorders":
				window.location = "MA_ApproveOrders.asp";
			break
			case "savedorders":
				window.location = "MA_SavedOrders.asp";
			break
			case "legacycontract":
				window.location = "legacy/hecontract.asp";
			break				
			default: //success
				window.location = "MA_MyAccount.asp";
			break
		} 
	}

}

