
// this JS is used by forgot_password.js for validation

function onSub()  // called when enter button is clicked
{
   validate();
   return false;
}


function onLoad1()   // called when onLoad
{
   document.onLoad = document.nam.txt_user_name.focus();
}



function validate(l_int_min_username)  // called when the user submits the forgot_password.jsp page
{
    var user_name=trim(document.nam.txt_user_name.value);
    var email_id=trim(document.nam.txt_email_id.value);
    var l_bln_user=true;
    var l_bln_email=true;
    
    if(user_name=='' && email_id=='')
    {
        document.nam.txt_user_name.focus();
        alert(TXT_Var14006);
        return false;
    }
    
    if(user_name!='')
        l_bln_user=checkUserName(document.nam.txt_user_name,l_int_min_username);
        
    if(email_id!='')    
        l_bln_email=checkEmail(document.nam.txt_email_id);
    
    if(user_name!='' || email_id!='')
    {
        if(l_bln_user && l_bln_email)  // checks for user name
        {   
      
            document.nam.action = "../sebase/password_forgotpasswordsuccess.jsp";
            document.nam.submit();
            return true;
        }
        else  // if user name is not entered correctly
        {
            return false;
        }
    }
    else    
    {
         return false;
    }
     
}// function is over here.

// function returns true/false
function checkEmail(l_frm_control)
{
    
   var l_str_string = ""; // local variable to store the string
   var l_int_length = -1; // local variable to store the length of string

   l_str_string = trim(l_frm_control.value);
   l_int_length = l_str_string.length;
   if (checkNotNull(l_frm_control) == false) // check for not null function
   {
      return false;
   } // end of checknotnull if

   l_str_string = l_frm_control.value;
   l_int_length = l_str_string.length;

   if (l_str_string.indexOf(STR_AT) == -1) // checks for @ character
   {
      alert(TXT_Var14030);
      l_frm_control.select();
      l_frm_control.focus();
      return false;
   } // end of STR_AT character check if
   else
   {
      if (!(l_str_string.substring(l_str_string.indexOf(STR_AT) + 1).indexOf(STR_AT) == -1))
      { // checks for the consecutive '@' character
         alert(TXT_Var14031);
         l_frm_control.select();
         l_frm_control.focus();
         return false;
      } // end of consecutive STR_AT character check if
   } // end of STR_AT character check else
   if (l_str_string.substring(l_str_string.indexOf(STR_AT) + 1).indexOf(STR_DOT) == -1)
   { // checks for dot operatore
      alert(TXT_Var14032);
      l_frm_control.select();
      l_frm_control.focus();
      return false;
   } // end of dot operator
   if(!(checkForm4UnicodeText(l_str_string,'-||_||.||@')))
   {
      alert(TXT_Var14032)
      l_frm_control.select();
      l_frm_control.focus();
      return false;
   }
   for(l_int_i = 0; l_int_i < l_int_length; l_int_i++) // start of for loop
   {

       // checks for allowed characters
      if (l_str_string.charAt(l_int_i) == STR_AT || l_str_string.charAt(l_int_i) == STR_UNDERSCORE || l_str_string.charAt(l_int_i) == STR_MINUS ||l_str_string.charAt(l_int_i) == STR_DOT)
      {
         // checks for allowed consecutive character
         if (!(((l_str_string.charCodeAt(l_int_i + 1) >= INT_CCODE_UP_STARTS && l_str_string.charCodeAt(l_int_i + 1) < INT_CCODE_UP_CLOSE) ||  (l_str_string.charCodeAt(l_int_i + 1) >= INT_CCODE_MID_STARTS && l_str_string.charCodeAt(l_int_i + 1) < INT_CCODE_MID_CLOSE) || (l_str_string.charCodeAt(l_int_i + 1) >= INT_CCODE_LOW_STARTS && l_str_string.charCodeAt(l_int_i + 1) <= INT_CCODE_LOW_CLOSE)) && ((l_str_string.charCodeAt(l_int_i - 1) >= INT_CCODE_UP_STARTS && l_str_string.charCodeAt(l_int_i - 1) < INT_CCODE_UP_CLOSE) ||  (l_str_string.charCodeAt(l_int_i - 1) >= INT_CCODE_MID_STARTS && l_str_string.charCodeAt(l_int_i - 1) < INT_CCODE_MID_CLOSE) || (l_str_string.charCodeAt(l_int_i - 1) >= INT_CCODE_LOW_STARTS && l_str_string.charCodeAt(l_int_i - 1) <= INT_CCODE_LOW_CLOSE))))
         {
            alert(TXT_Var14032);
            l_frm_control.select();
            l_frm_control.focus();
            return false;
         } // end of allowed conscutive character if
      } // end of allowed character if
   } // end of for loop

return true;
} // end of checkEmail function

// function returns true/false
function checkUserName(l_frm_control, l_int_min_length)
{
   var l_str_string = ""; // local variable to store the string
  
   l_str_string = l_frm_control.value;

   if (newcheckAlphaNumericOnlyUN(l_frm_control) == false) // checks for alphanumeric value
   {
      return false;
   } // end of alphanumeric value check if

   if((l_str_string.substring(0,1)).match(/[^a-zA-Z]/))   //for checking the allowed chars
   //if(!(checkForm4UnicodeText(l_str_string,'-||_||.')))   //for checking the allowed chars
   {
      alert(TXT_Var14048);
      l_frm_control.select();
      l_frm_control.focus();
      return false;
   }

   if (l_str_string.length < l_int_min_length) // check for minimum length
   {
      alert(TXT_Var14049 + l_int_min_length + " " + TXT_Var14050);
      l_frm_control.select();
      l_frm_control.focus();
      return false;
   } // end of minimum length if

return true;
} // end of checkUserName function
