/* 
 * @author Anand Kumar
 *
 * Created on : Jul 6, 2008, 02:37:40 AM
 * 
 * Created for the second stage of registration
 * 
 */


function ValidationRegForm()
{
    //alert("OK");
    document.RegForm.Submit.disabled = true;
    
    if(IsEmpty(document.RegForm.email,"text"))
    {
        alert("Please enter a valid E-mail address");
        document.RegForm.Submit.disabled = false;
        document.RegForm.email.focus();
        return false;
    }
    
    if(!ValidateEmail(document.RegForm.email.value))
    {
        alert("Please enter a valid E-mail address");
        document.RegForm.Submit.disabled = false;
        document.RegForm.email.focus();
        return false;
    }
    
    if(IsEmpty(document.RegForm.password1,"text"))
    {
        alert("Please enter your password");
        document.RegForm.Submit.disabled = false;
        document.RegForm.password1.focus();
        return false;
    }    
    
    if (document.RegForm.password1.value.length < 4 )
    {
        alert("Password must have a minimum of 4 characters");
        document.RegForm.Submit.disabled = false;
        document.RegForm.password1.focus();
        return false;
    }
        
    var pwd1=document.RegForm.password1.value;
    pwd1=pwd1.toUpperCase()
    var email=document.RegForm.email.value.substring(0, document.RegForm.email.value.indexOf("@"));
    email=email.toUpperCase()    
    
    if (pwd1 == email)    
    {
        alert("The E-mail address and password cannot be the same. Please change the password");
        document.RegForm.Submit.disabled = false;
        document.RegForm.password1.focus();
        return false;
    }  

    var tmpPass = document.RegForm.password1.value;
    var validPasswd = 1;    
    for( var idx=0; idx< tmpPass.length; idx++ )
    {
        ch = tmpPass.charAt(idx);
        if( !((ch>='a') && (ch<='z')) && !((ch>='A') && (ch<='Z')) && !((ch>=0) && (ch <=9)) )
        {
            validPasswd = 0;
            break;
        }
    }   

    if(validPasswd ==0)
    {
        alert("Spaces or special characters are not allowed in the password");
        document.RegForm.Submit.disabled = false;
        document.RegForm.password1.focus();
        return false;        
    }
    
    if(IsEmpty(document.RegForm.password2,"text"))
    {
        alert("Please confirm your password");
        document.RegForm.Submit.disabled = false;
        document.RegForm.password2.focus();
        return false;
    }
    
    if(document.RegForm.password2.value != document.RegForm.password1.value)
    {
        alert("Sorry, both the passwords do not match");
        document.RegForm.Submit.disabled = false;
        document.RegForm.password1.focus();
        return false;        
    }   
    
    if(IsEmpty(document.RegForm.terms,"checkbox"))
    {
        alert("Please accept the  terms of use of Saathimere.com");
        document.RegForm.Submit.disabled = false;
        document.RegForm.terms.focus();
        return false;
    }   
    
    document.RegForm.Submit.disabled = false;
    document.RegForm.action = "./RegStepOne";
    return true;

}