var EMAIL_INVALID     	= -925;
var SUCCESS             = 0;
var EMAIL_IS_NOT_UNIQUE = -926;
var EMPTY_FIELD        	= -924;
var EMPTY_EMAIL        	= -923;
var ERROR_EMPTY_EMAIL   = 'Please enter your email address.';
var ERROR_EMAIL_NOT_VALID = 'Please enter a valid email addresses.';


var AjaxObject = {

 handleSuccess_email:function(o){
    document.getElementById("error_email").innerHTML = o.responseText;

    if(o.responseText == 'Not Available')
      {
	error_code = EMAIL_IS_NOT_UNIQUE;
      }
    else
      {
	error_code = 0;
      }
  },
 handleFailure_email:function(o){
  }
};


// validate email id 
/*! 
 * \param val=>string type contains email value
 * \param base_url contains BASE URL Value
 */
function login_validationEmail(val, base_url)
{ 
   var email = document.getElementById('email').value;

   if(email =="" || email == null || email == "Enter ur new email id")
   {
	//document.getElementById('error_email').innerHTML="Please enter valid Email address.";
	return false;
   }
   else
   {                                                                                                     
      var params    = Array();
      params['email'] = email;

      var error_email = login_validateEmail(params);
      if(error_email)
      {
	  //document.getElementById('error_email').innerHTML="Please enter valid Email address.";
	  return false;
      }
      else
	{
	  login_emailCheckDb(params['email'],base_url);	  
	}
    }   
}


// checks email id is available  to db(Using AJAX)
/*! 
 * \param email=>string type contains email value
 * \param basr_url contains BASE URL Value
 */
function login_emailCheckDb(email,base_url)
{ 
  YAHOO.util.Connect.asyncRequest('POST',base_url+'ajax/signup/is_user_unique/email_id/'+email, callback_email);       
}

/*
 * Define the callback object for success and failure
 * handlers as well as object scope.
 */
var callback_email =
  {
  success:AjaxObject.handleSuccess_email,
  failure:AjaxObject.handleFailure_email,
  scope: AjaxObject
  };


//! Method to validate email address
/*!
 * params associative array consisting following keys
 * email  => string, user's email address
 * return Boolean True on success, negative error code on failure
 */

function login_validateEmail(params)
{
  var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

  if(params['email'].length == 0 || params['email'] == '')
    {
      return EMPTY_EMAIL;
    }
  else if(!filter.test(params['email']))
    {
      return EMAIL_INVALID;
    }
  else 
    {
      return SUCCESS;
    }
}


function login_validate_required(field,alerttxt)
{
  with (field)
    {
      if (value==null||value=="")
	{//document.getElementById('errormessage').innerHTML=alerttxt;
	 return false;}
      else {return true}
    }
}


function login_validate_form(thisform)
{
  with (thisform)
    {
      if (login_validate_required(login,"Please enter Login details.")==false)
	{login.focus();return false;}
      else if (login_validate_required(password,"Please enter Password.")==false)
	{password.focus();return false;}
    }
    return true;
}


function login_submit_form()
{
  var frm = document.getElementById('frmLogin');

  if(login_validate_form(frm))
     {
       document.frmLogin.submit(frm);
     } 
}
