﻿// JScript File
// GetXMLHttpRequest in in Callback.js
var target=null;
function VerifyRequest() 
{
    if (req.readyState == 4) 
    {
      if (req.status == 200) 
      {    
          var result =req.responseText;
          if (result)
          {
                // Update HTML based on the result
                if (result.match("False"))
                {
                    alert("Please enter a valid email address");
                    
                      if (target!=null)
                      {
                        target.focus();
//                            target.value="Invalid Email Address!";
                      }
                      else
                      {
                            document.write(result);
                      }
               }
               else 
               {
                    if (result.match("Occupied"))
                    {
                      alert("Email address has been used in our database!");
                    
                      if (target!=null)
                      {
                        target.focus();
                      }
                    
                    }
               }
          }
      }
      else
      {
                  // An error has occurred.
             document.write(req.statusText);
      }
    }
    return true;
}


function VerifyEmailByObj(curObj, showID)
{
    var email=curObj;
    target=document.getElementById(showID);
    if (email!=null)
    {
        if(validate(email))
         {    
       
            var url="VerifyEmail.aspx?email="+email.value;
            var callback=VerifyRequest;
            GetXMLHttpRequest(callback,url)
        }
    }
    else
    {
        var ermsg="Email Object can't be found!";
        if (target!=null)
        {
             target.value=ermsg;
        }
        else
        {
             document.write(ermsg);
        }    
    }
       
}
function validate(email)
{

	if (!email.value.match(/^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/))
	{
	    email.focus();
		alert("Please enter a valid e-mail address.");
	    email.focus();
		return false;
	}
	else
	{
	    return true;
	}
}
