﻿// JScript File

function ValidateLoginData()
{   
 
    var strLoginData;
    var strPassData;
        
    strLoginData = getObjectById(txt_LoginData_Id).value;
    strPassData = getObjectById(txt_PassData_Id).value;       

    // Trim the strings.
    strLoginData = RemoveWhiteSpaces(strLoginData);
    strPassData = RemoveWhiteSpaces(strPassData);   
    
    // Remove withe spaces from the string.
    strLoginData = RemoveWhiteSpaces(strLoginData);
    strPassData = RemoveWhiteSpaces(strPassData);
    
    /***** General validations. *****/
    
    // Not empty LOGIN data.
    if(strLoginData == "")
    {               
        if(intLanguage == intSpanish)  
        {
            alert("Por favor proporcione su " + strLoginDataLabel + "." );
        }
        if(intLanguage == intEnglish)
        {
            alert("Please provide your " + strLoginDataLabel + "." );            
        }
        
        return(false);
        
    } // if(strLoginData == "").
    
    
    // Not empty PASS data.
    if(strPassData == "")
    {
        if(intLanguage == intSpanish)  
        {
            alert("Por favor proporcione su " + strPassDataLabel + "." );
        }
        if(intLanguage == intEnglish)
        {
            alert("Please provide your " + strPassDataLabel + "." );            
        }
        
        return(false);
        
    } // if(strLoginData == "").
    
    
    /***** Validations based on the login case. *****/    
  
       
    // Login case client id and pin.   
    if(intLoginCase == intClientIdAndPin)
    {
    
        // Client id only numeric chars.
        var blnIsNumeric;
        blnIsNumeric = IsNumeric(strLoginData);
        if(blnIsNumeric == false)
        {
            if(intLanguage == intSpanish)  
            {
                alert("Su número de cliente debe de estar conformado únicamente por caráracteres numéricos.");
            }
            if(intLanguage == intEnglish)
            {
                alert("Your Client Id must be conformed only by numeric characters.");            
            }
        
            return(false);
        
        } // if(blnIsNumeric == false).
        
    } // if(intLoginCase == intClientIdAndPin).
    
    
    // Login case people id and pin.   
    if(intLoginCase == intPeopleIdAndPinNumber)
    {
        
        // People id only numeric chars.
        var blnIsNumeric;
        blnIsNumeric = IsNumeric(strLoginData);
        if(blnIsNumeric == false)
        {
            if(intLanguage == intSpanish)  
            {
                alert("Su número personal debe de estar conformado únicamente por caráracteres numéricos.");
            }
            if(intLanguage == intEnglish)
            {
                alert("Your Personal Id must be conformed only by numeric characters.");            
            }
        
            return(false);
        
        } // if(blnIsNumeric == false).
        
    } // if(intLoginCase == intPeopleIdAndPinNumber).
            
    
    
    // Login case email and pin.              
    if(intLoginCase == intEmailAndPinNumber)
    {
        
        // Valid email address.
        var blnValidEmail;
        blnValidEmail = IsValidEmail(strLoginData);
        if(blnValidEmail == false)
        {
            if(intLanguage == intSpanish)  
            {
                alert("Su dirección de email es incorrecta. Por favor proporcionela nuevamente.");
            }
            if(intLanguage == intEnglish)
            {
                alert("Your email address is invalid. Please type it again.");            
            }
        
            return(false);
        
        } // if(blnIsNumeric == false).
        
    } // if(intLoginCase == int_EmailAndPinNumber).
          
    return(true);
        
} // function ValidateLoginData().

/*====================================================================================*/

//Removes all white spaces from a given string.
function RemoveWhiteSpaces(strValue)
{
    var TrimAllWitheSpaces = /\s/g;
    strValue = strValue.replace(TrimAllWitheSpaces, "");
        
    return(strValue);

}//function RemoveWhiteSpaces(strValue).

/*====================================================================================*/

//Remove leading and trailing white spaces.
function Trim(strValue)
{	
    var LeftTrim = /\s*((\S+\s*)*)/;
    var RigthTrim = /((\s*\S+)*)\s*/;                

    strValue = Value.replace(LeftTrim, "$1");
    strValue = Value.replace(RigthTrim, "$1");
        	        
    return(strValue);

}//function Trim(strValue).
    
/*====================================================================================*/

// Only numbers validation function.
function IsNumeric(ValueToTest) 
{           
    var blnIsNumeric;
    var reNumeric = /^\d+$/;
                        
    if ((ValueToTest.length = 0)||(!reNumeric.test(ValueToTest)))
    {
        blnIsNumeric = false;
    }
    else
    {
        blnIsNumeric = true;
    }        
            
    return(blnIsNumeric);
    
}//function IsNumeric(ValueToTest).

/*====================================================================================*/

// Email validation function.
function IsValidEmail(strEmail)
{

    var reEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var blnValidEmail;
                        
    if (reEmail.test(strEmail))
    {
        blnValidEmail = true;
    }
    else
    {
        blnValidEmail = false;
    }
            
    return(blnValidEmail);
    
}//function IsValidEmail(strEmail).

/*====================================================================================*/

// Check the supported way the navigator reads vars and use it.
function getObjectById(strObjectId)
{
    var Object = -1;
    
    if (document.getElementById)
        Object = document.getElementById(strObjectId);
    else if (document.all)
        Object = document.all[strObjectId];
    else if (document.layers)
        Object = document.layers[strObjectId];
            
    return(Object);
    
}//function getObjectById(strObjectId).

/*====================================================================================*/