﻿function login()
{
    var email = $("e");
    var pw = $("pw");

    if(email.value.trim().length == 0)
    {
        message("Please enter your email.");
        return;
    }
    else if(!(new RegExp("\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b", "ig").test(email.value)))
    {
        message("Your email is in invalid format. Please make sure it's the right email.");
        return;
    }
    else if(pw.value.length == 0)
    {
        message("Please enter your password.");
        return;
    }

    var callback =
    {
        success: function(o)
        {
            if(o && o.responseXML)
            {
                var xmlDoc = o.responseXML;
                
                if(xmlDoc && xmlDoc.documentElement && xmlDoc.documentElement.firstChild && xmlDoc.documentElement.firstChild.nodeValue.trim().length > 0)
                {
                    message(xmlDoc.documentElement.firstChild.nodeValue.trim());
                }
                else
                {
                    
                    document.location.href = "LoginRedir.aspx";
                }
            }
        }
    };

    YAHOO.util.Connect.asyncRequest("POST", "Ajax/Account/Login.aspx", callback, "e={0}&p={1}".format(email.value.trim().urlEncode(), pw.value.urlEncode()));
}