﻿/*----------------------------------------------------------------------------         
        Description			    :	 Registration.js used in Registration.aspx
        Create on			    :    23-08-2008
        Initial Code Created    :    Sathish.M
------------------------------------------------------------------------------*/
 
 //For OffLine Store Work
 
 function funChkDOB()
 {  
    try
    {
       if($F('txtOffLogDOB')=='' || $F('txtOffLogDOB')=='DD/MM/YYYY')
        {
            alert('Please submit the below required details.\r\n-------------------------------------------------\rDate of birth Missing / Invalid');  
            return false;            
        }
        else
            return true          
    }
    catch(e)
    {
        alert('@ funChkDOB');
    }
 } 
 function funByDOB()
 {
    try
    {
        $('trDOB').style.display='block';
        $('trOffLogin').style.display='none';
        $('trOffPwd').style.display='none';
        $('btnOffLogin').style.display='none'; 
        if($('rbDOB').checked==true)
        $('lblOffSample').innerHTML='(Enter DOB as [DD/MM/YYYY] and password as DDMMYYYY)';
    }
    catch(e)
    {
        alert('@ funByDOB');
    }
 } 
 function funNotByDOB()
 {
    try
    {
        $('trDOB').style.display='none';
        $('trOffLogin').style.display='block';
        $('txtOffLogin').style.display='block';
        $('ddlOffLogin').style.display='none';
        $('trOffPwd').style.display='block';
        $('btnOffLogin').style.display='block';    
        if($('rbMobile').checked==true)
            $('lblOffSample').innerHTML='(Enter mobile no with country code)';   
        else if($('rbPhone').checked==true)
            $('lblOffSample').innerHTML='(Enter phone no with country & state code)';        
    }
    catch(e)
    {
        alert('@ funNotByDOB');
    }
 } 
 function funCpyPwd()
 {
    try
    {
        $('txtOffPassword').value=$F('txtOffLogin'); 
    }
    catch(e)
    {
        alert('@ funCpyPwd');
    }
 }
 function funChkOffNewUsers()
 {
    var ErrMsg='';
    try
    {
        if($('txtOffDob').value=='' || $('txtOffDob').value=='DD/MM/YYYY')
            ErrMsg='\n Date of birth';  
        if(numericCheck($('txtOffDob').value)==false || funValidDob($('txtOffDob').value)==false)
            ErrMsg='\n Date of birth invalid';   
        if($('txtOffFName').value=='')
            ErrMsg+='\n Name';   
        if(InvalidText($('txtOffFName').value)==false)
            ErrMsg+='\n Name invalid'; 
        if(numericCheck($('txtOffMobile1').value)==false || numericCheck($('txtOffMobile2').value)==false || numericCheck($('txtOffPhone1').value)==false || numericCheck($('txtOffPhone2').value)==false || numericCheck($('txtOffPhone3').value)==false)
            ErrMsg+='\n Mobile or Phone number invalid';            
        if(ErrMsg!='')
        {
            alert('Please submit the below required details.\r\n-------------------------------------------------\r'+ErrMsg);  
            return false;            
        }
        else    
           return true; 
    }
    catch(e)
    {
        alert('@ funChkOffNewUsers');
    }
 }
 function funChkOffLogin()
 {
    var ErrMsg='';
    try
    {   
        if($('rbDOB').checked==false)
        {
            if($F('txtOffLogin')=='')
                ErrMsg='\n Login Id Missing / Invalid';   
        }
        if($('rbDOB').checked==true)
        {
            if($F('ddlOffLogin')=='-- Select Login --')
                ErrMsg='\n Login Id Missing / Invalid';   
        }
        if($F('txtOffPassword')=='')
            ErrMsg+='\n Password';   
         if(ErrMsg!='')
        {
            alert('Please submit the below required details.\r\n-------------------------------------------------\r'+ErrMsg);  
            return false;            
        }
        else    
           return true; 
    }
    catch(e)
    {
        alert('@ funChkOffLogin');
    }
 }
 
 //Used to assign the LoginId to Email & Confirm EmailId.
function funLstFocus()
{   
    if(document.getElementById('txtLoginName').style.visibility='visible')
    {    
        document.getElementById('txtEmailAddress').value=document.getElementById('txtLoginName').value;
        document.getElementById('txtConfirmEmail').value=document.getElementById('txtLoginName').value;                        
    }
}

//Used to Check Password Length.
function funChkPwdLen()
{
    var pwdLen;
    pwdLen=document.getElementById('txtPassword').value;        
    if(pwdLen.length<6 || pwdLen.length>20)   
        alert('Password should be minimum of 6 & maximum of 20 characters');
}
//Used to Check Password Mismatch or not.
function funChkPwdMisMtch()
{   
    if(document.getElementById('txtPassword').value!=document.getElementById('txtConfirmPassword').value)    
        alert('Password Mismatch');  
}

//Used to Check Available Registration.      
function funChkAvalilable()   
{  
    var ErrMsg='';
    if(document.getElementById('txtLoginName').value=='' || funValidateEmail(document.getElementById('txtLoginName').value)==false )    
        ErrMsg='\n Login id should be in email id format';    
    if(ErrMsg!='')
    {
        alert('Please submit the below required details.\r\n-------------------------------------------------\r'+ErrMsg);  
        return false;            
    }
    else    
       return true;            
}

//Used to validate Registration Form
function funInvalidSplSymbols(param)
 {
  flg=0;
  str="";
  spc=""
  arw="";
  for (var i=0;i< param.length;i++){
   cmp="<>?;'%$&"
   tst=param.substring(i,i+1)
   if (cmp.indexOf(tst)>-1){
    flg++;
    str+=" "+tst;
    spc+=tst;
    arw+="^";
   }
   else{arw+=" ";}
  }
  if (flg!=0){
   if (spc.indexOf(" ")>-1) {
    str+=" and a space";
    }
   //alert(param+"\r"+arw+"\rThis entry must be a Valid Text. I found "+flg+" unacceptable: "+str+".");
  //return(param+"\r"+arw+"\rThis entry must be a Valid Text. I found "+flg+" unacceptable: "+str+".");
  return false;
  }
 }


//Used to check valid for New Registration & to Update Existing Registration.
function funErrMsg()  
{   
    var ErrMsg=''; 
    var arrErr=new Array(20);  
    var regExp = /^([A-Za-z0-9_\-\.\@])*$/;        
    for(var i=0;i<20;i++)
    {   
        arrErr[i]='';
    }
    if(document.getElementById('txtLoginName').style.visibility=='visible')
    {   
        if(document.getElementById('txtLoginName').value=='' || funValidateEmail(document.getElementById('txtLoginName').value)==false || regExp.test(document.getElementById('txtLoginName').value) == false)    
            arrErr[0]='\n Login-ID Missing/Invalid';     
        if(document.getElementById('txtLoginName').value.length>75)
            arrErr[0]='\n Login-ID should not exceed 75 characters';     
    }
    if(document.getElementById('txtName').value=='' || numericCheck(document.getElementById('txtName').value)!=false)    
        arrErr[1]='\n First Name Missing/Invalid';    
    if(document.getElementById('txtName').value.length>50)
        arrErr[1]='\n First Name should not exceed 50 characters';  
    if(funInvalidSplSymbols(document.getElementById('txtName').value)==false)  
        arrErr[1]='\n Invalid First Name'   
    if((document.getElementById('txtPassword').value).trim()=='')    
        arrErr[2]='\n Password';    
    if((document.getElementById('txtConfirmPassword').value).trim()=='')    
        arrErr[3]='\n Confirm password mismatch';            
    if(document.getElementById('ddlGender').value=='-1')    
        arrErr[4]='\n Gender';   
    if((document.getElementById('txtAddress1').value).trim()=='')
        arrErr[5]='\n Address1';   
    if(funInvalidSplSymbols(document.getElementById('txtAddress1').value)==false)  
        arrErr[5]='\n Invalid Address 1'       
    if(document.getElementById('txtAddress1').value.length>100)
        arrErr[5]='\n Address1 should not exceed 100 characters';   
    if(document.getElementById('ddlCountry').value=='-- Select Country --')
        arrErr[6]='\n Country';
    if(document.getElementById('hdntxtState').value=='0')
    {
        if(document.getElementById('txtState').value=='' || numericCheck(document.getElementById('txtState').value)!=false)
            arrErr[7]='\n State Missing/Invalid';   
        if(funInvalidSplSymbols(document.getElementById('txtState').value)==false)  
            arrErr[7]='\n Invalid State'  
        if(document.getElementById('txtState').value.length>30)
            arrErr[7]='\n State should not exceed 30 characters';   
    }
    if(document.getElementById('hdntxtState').value=='1')
    {
        if(document.getElementById('ddlState').value=='-- Select State --')
            arrErr[7]='\n State';
    }
    if(document.getElementById('txtCity').value=='' || numericCheck(document.getElementById('txtCity').value)!=false)
        arrErr[8]='\n City Missing/Invalid';
    if(funInvalidSplSymbols(document.getElementById('txtCity').value)==false)  
        arrErr[8]='\n Invalid City'  
    if(document.getElementById('txtCity').value.length>30)
        arrErr[8]='\n City should not exceed 30 characters';
    if(document.getElementById('txtPinZipPost').value=='')
        arrErr[9]='\n ZIP/PIN/POST Code';
    if(funInvalidSplSymbols(document.getElementById('txtPinZipPost').value)==false)  
        arrErr[9]='\n Invalid Zip / Postal Code'
    if(document.getElementById('txtPinZipPost').value.length<5 || document.getElementById('txtPinZipPost').value.length>10)
        arrErr[9]='\n ZIP/PIN/POST Code should not exceed 10 characters or below 5 characters';
    if(document.getElementById('txtPhone').value==''|| numericCheck(document.getElementById('txtPhone').value)==false)
        arrErr[10]='\n Phone No. Missing/Invalid';
    if(funInvalidSplSymbols(document.getElementById('txtPhone').value)==false)  
        arrErr[9]='\n Invalid Phone No...'
    if(document.getElementById('txtPhone').value.length>15)
        arrErr[10]='\n Phone No. should not exceed 15 characters';    
    if(document.getElementById('txtEmailAddress').value==''||emailCheck(document.getElementById('txtEmailAddress').value)==false || regExp.test(document.getElementById('txtEmailAddress').value) == false)
        arrErr[11]='\n Email Address Missing/Invalid';
    if(document.getElementById('txtEmailAddress').value.length>75)
        arrErr[11]='\n Email Address should not exceed 75 characters';    
    if(document.getElementById('ddlIndustry').value=='-1')
        arrErr[12]='\n Industry';   
    if(document.getElementById('txtDOB').value=='')
    { 
        if(numericCheck(document.getElementById('txtDOB').value)==false || funValidDob(document.getElementById('txtDOB').value)==false)
            arrErr[13]='\n DOB Missing/Invalid';
        else
            arrErr[13]='\n DOB Missing/Invalid';       
    }
    if(document.getElementById('txtAnniversary').value!='')
    { 
        if(numericCheck(document.getElementById('txtAnniversary').value)==false || funValidDob(document.getElementById('txtAnniversary').value)==false)
            arrErr[14]='\n Enter valid Anniversary Date'; 
    }  
    if(numericCheck(document.getElementById('txtMobile').value)==false)
        arrErr[15]='\n Mobile No. Missing/Invalid.'; 
    if(funInvalidSplSymbols(document.getElementById('txtMobile').value)==false)  
        arrErr[9]='\n Invalid Mobile No...'
    if(document.getElementById('txtMobile').value.length>15)
        arrErr[15]='\n Mobile No. should not exceed 15 characters'; 
    if(document.getElementById('txtLName').value!='')
    {
        if(funInvalidSplSymbols(document.getElementById('txtLName').value)==false)  
            arrErr[16]='\n Invalid Last Name'  
        if(document.getElementById('txtLName').value.length>50)
            arrErr[16]='\n Last Name should not exceed 50 characters';
    }   
    if(document.getElementById('txtAddress2').value!='')
    {
        if(funInvalidSplSymbols(document.getElementById('txtAddress2').value)==false)  
            arrErr[17]='\n Invalid Address 2'  
        if(document.getElementById('txtAddress2').value.length>100)
            arrErr[17]='\n Address2 should not exceed 100 characters';
    } 
    if(document.getElementById('txtConfirmEmail').value!='')
    {
        if(document.getElementById('txtConfirmEmail').value.length>75)
        arrErr[18]='\n Confirm Email should not exceed 75 characters';
    }
    if((document.getElementById('txtPassword').value).trim()!=(document.getElementById('txtConfirmPassword').value).trim())    
        arrErr[19]='\n Password Mismatch'; 
    
    for(var i=0;i<20;i++)
    {
        if(arrErr[i]!='')
        {
            ErrMsg=ErrMsg+arrErr[i];
        }
    }     
    if(ErrMsg!='')
    {   
        alert('Please submit the below required details.\r\n-------------------------------------------------\r'+ErrMsg);                      
        return false;            
    }
    return true;  
}

function funValidRegistration()
{
    var Msg;    
	if (document.getElementById('hdnOp').value=='Add')	
		Msg = 'Confirm by clicking OK if the above details are correct.';	
	if (document.getElementById('hdnOp').value=='Edit')
		Msg= 'Confirm by clicking OK if the above details are correct for updation.';
	var validate = funErrMsg();	
	if (validate == true)
	{	    
	    if (confirm(Msg))
	    {  
	        if (document.getElementById('hdnOp').value=='Add')
	        {	 
	            alert('Congratulations your Login account is successfully created...!');
                alert('Your Login Id for future reference is ' + document.getElementById('txtLoginName').value);
            }
            else
            {
                alert('Your profile is successfully updated...!');
            }
            return true;
        }
	}
	return false;
}

//Used in UsrLogin.aspx
 function funChkLogin()
  {         
      var regExp = /^([A-Za-z0-9_\-\.\@])*$/;
      var regExpPwd = /([<>])/;
      var ErrMsg='';      
      if(document.getElementById('txtLoginExist').value=='' || regExp.test(document.getElementById('txtLoginExist').value) == false)   
         ErrMsg='\n Login-ID Missing';
      if(document.getElementById('txtPasswordExist').value=='' || regExpPwd.test(document.getElementById('txtPasswordExist').value) == true)
         ErrMsg=ErrMsg + '\n Password';    
      if(ErrMsg!='')
      {   
        alert('Please submit the below required details.\r\n-------------------------------------------------\r'+ErrMsg);                      
        return false;            
      }
      else
       return true;  
  }

function funChkNewLogin()
{
    var ErrMsg='';
    var regExpPwd = /([<>])/;
    if(document.getElementById('txtLogin').value=='' || funValidateEmail(document.getElementById('txtLogin').value)==false)    
        ErrMsg='\n Login-ID Missing/Invalid';
    if(document.getElementById('txtName').value=='' || numericCheck(document.getElementById('txtName').value)!=false ||(funInvalidSplSymbols(document.getElementById('txtName').value)==false))    
        ErrMsg=ErrMsg=ErrMsg +'\n Name Missing/Invalid';    
    if(document.getElementById('txtName').value.length>50)
        ErrMsg=ErrMsg=ErrMsg +'\n Name should not exceed 50 characters';                                    
    if(document.getElementById('txtPassword').value=='' || regExpPwd.test(document.getElementById('txtPassword').value) == true)
        ErrMsg=ErrMsg=ErrMsg +'\n Password';                                    
    if(document.getElementById('txtConfirmPassword').value=='' || regExpPwd.test(document.getElementById('txtConfirmPassword').value) == true)
        ErrMsg=ErrMsg=ErrMsg +'\n Confirm Password';            
    if(ErrMsg!='')
      {   
        alert('Please submit the below required details.\r\n-------------------------------------------------\r'+ErrMsg);                      
        return false;            
      }
    else
        return true;  
}


