﻿$(document).ready(
   function() {
   
    var strForValidNum ="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`~!@#$%^&*()_=+[]{},.'<>/?\|;:-" + '"';    
    
//    if(txtDated != null){
//        $('#'+txtDated.id).blur(function(){
//           if(!isDate(this.value)) this.value = "";
//        });
//    }
    
        
//    if(txtBirthDate != null){
//        $('#'+txtBirthDate.id).blur(function(){
//           if(!isDate(this.value)) this.value = "";
//        });
//    }
    
//    $("#btnGo").live("click", function(){
//      var userid = txtLogon.value;
//      if(userid == ""){
//        alert("Please enter login id !!!");
//        return false;
//      }
//      userid = '"userid":"' + userid + '"';
//      $.ajax({
//          type: "POST",
//          contentType: "application/json; charset=utf-8",
//          dataType: "json",
//          url:"./NewReg.aspx/IsUserNameExists",
//          data:"{" +  userid + "}",
//          error: function(XMLHttpRequest, textStatus, errorThrown){
//              alert(textStatus);
//          },
//          success: function(result){
//             if(result.d){
//                alert("Congratulation, ID is available !!!"); 
//             }else{
//                alert("ID is not available, Please select another id !!!"); 
//                txtLogon.value ="";
//             }
//          }
//       });
//       return false;
//    });

        if (txtLogon != null)
        {
            $('#'+txtLogon.id).blur(function(){
              var userid = txtLogon.value;
              if(userid == ""){        
                $("#checkuserid").find("span").remove(); 
                return false;
              }
              
              $("#checkuserid").find("span").remove();
              $("#checkuserid").append($("<span><img src='Admin/L4IFiles/Images/Search.gif' /></span>"));
              userid = '"userid":"' + userid + '"';
              $.ajax({
                  type: "POST",
                  contentType: "application/json; charset=utf-8",
                  dataType: "json",
                  url:"./NewReg.aspx/IsUserNameExists",
                  data:"{" +  userid + "}",
                  error: function(XMLHttpRequest, textStatus, errorThrown){
                      alert(textStatus);
                  },
                  success: function(result){
                     if(result.d){                
                        $("#checkuserid").find("span").remove();               
                        $("#checkuserid").append($("<span style ='color:green;' ><br />Congratulation, ID is available !!!</span>"));                
                     }else{                              
                        $("#checkuserid").find("span").remove();   
                        $("#checkuserid").append($("<span style ='color:Red;'><br />ID is not available, Please select another id !!!</span>"));
                        txtLogon.value ="";
                     }
                  }
               });
               
               return false;
            });
        }

        
//    $('#'+ddlPaymentMode.id).blur(function(){
//       if(!isDate(this.value)) this.value = "";
//    });    
        
        if(ddlPaymentMode != null){            
            $('#'+ddlPaymentMode.id).live("click", function(){                
                    SetPaymentMode(this.value);
            });
            
            
            $('#'+ddlPaymentMode.id).change(function (){
            
                    SetPaymentMode(this.value);            
            });
            
            
            
            //*************** Default page onload ****************
            
            var PaymentType;
            PaymentType = "ChequeDDSubscription.html";  
            PaymentType = '"PaymentType":"' + PaymentType + '"';
            $.ajax({
                  type: "POST",
                  contentType: "application/json; charset=utf-8",
                  dataType: "json",
                  url: "./NewReg.aspx/PaymentInfo",
                  data:"{" +  PaymentType + "}",
                  error: function(XMLHttpRequest, textStatus, errorThrown){
                      alert(textStatus);
                  },
                  success: function(result){
                     $("#info").text("");                                                 
                     $("#info").append(result.d)
                  }
            });
            
            
        }

        
        
        if (txtEmail != null)
        {
            $('#'+txtEmail.id).blur(function(){
              var emailid = txtEmail.value;
              if(emailid == ""){        
                $("#checkemailid").find("span").remove(); 
                return false;
              }
              $("#checkuserid").find("span").remove();  
              $("#checkemailid").append($("<span><img src='Admin/L4IFiles/Images/Search.gif' /></span>"));              
              emailid = '"emailid":"' + emailid + '"';
              $.ajax({
                  type: "POST",
                  contentType: "application/json; charset=utf-8",
                  dataType: "json",
                  url:"./NewReg.aspx/IsEmailExists",
                  data:"{" +  emailid + "}",
                  error: function(XMLHttpRequest, textStatus, errorThrown){
                      alert(textStatus);
                  },
                  success: function(result){
                     if(result.d){         
                        $("#checkemailid").find("span").remove();                                                     
                        $("#checkemailid").append($("<span style ='color:Red;'><br />Can't create user ,EmailID is already used by another user</span>"));
                        txtEmail.value ="";                                                
                     }
                     else
                        $("#checkemailid").find("span").remove();
                  }
               });
               
               return false;
            });
        }
        
        if(txtZip != null)
        {
            $('#'+txtZip.id).keypress(function (e) {
                
                var KeyValue = String.fromCharCode(e.which);
                var re = /^[0-9]+$/;                              
                
                if (strForValidNum.indexOf(KeyValue) !=  -1)
                    {
                    var OK = re.exec(KeyValue);                   
                    if (!OK)
                       e.preventDefault();  
                    } 
                });
         }
    
        if (txtOfficePhone != null)
        {            
            $('#'+txtOfficePhone.id).keypress(function (e) {            
                var KeyValue = String.fromCharCode(e.which);
                var re = /^[0-9-]+$/;
                var Value = txtOfficePhone.value; 
                
                if (strForValidNum.indexOf(KeyValue) !=  -1)
                    {                                    
                    var OK = re.exec(KeyValue);                                   
                    if (!OK)
                       e.preventDefault();    
                    if (KeyValue  == "-")
                        if (Value.indexOf("-") !=  -1)
                            e.preventDefault();    
                        
                    }                         
                });     
         }   
        
        if (txtRecidentPhone != null)
        {
            $('#'+txtRecidentPhone.id).keypress(function (e) {            
                var KeyValue = String.fromCharCode(e.which);
                var re = /^[0-9-]+$/;
                var Value = txtRecidentPhone.value; 

                if (strForValidNum.indexOf(KeyValue) !=  -1)
                    {                 
                    var OK = re.exec(KeyValue);                                                          
                    if (!OK)
                       e.preventDefault();   
                    if (KeyValue  == "-")
                        if (Value.indexOf("-") !=  -1)
                            e.preventDefault(); 
                    }
                });   
         }   
        
        if(txtFax != null)
        {
            $('#'+txtFax.id).keypress(function (e) {            
                var KeyValue = String.fromCharCode(e.which);
                var re = /^[0-9-]+$/;                
                var Value = txtFax.value;            
                
                if (strForValidNum.indexOf(KeyValue) !=  -1)
                    {                 
                    var OK = re.exec(KeyValue);                               
                    if (!OK)
                       e.preventDefault();   
                    if (KeyValue  == "-")
                        if (Value.indexOf("-") !=  -1)
                            e.preventDefault(); 
                    }
                }); 
          }                    
        
          if (txtDDNo != null)
          {
            $('#'+txtDDNo.id).keypress(function (e) {            
                var KeyValue = String.fromCharCode(e.which);
                var re = /^[0-9]+$/;
                var Value = txtDDNo.value;            

                if (strForValidNum.indexOf(KeyValue) !=  -1)
                    {                                                                                   
                    var OK = re.exec(KeyValue);                   
                    if (!OK)
                       e.preventDefault(); 
                    }        
                }); 
           } 
           
           
        if(txtDated != null){
            $('#'+txtDated.id).keypress(function(e){
        
                var KeyValue = String.fromCharCode(e.which);
                var re = /^[0-9]+$/;
                var Value = txtDated.value; 
                
                if (strForValidNum.indexOf(KeyValue) !=  -1)
                    {                                    
                    var OK = re.exec(KeyValue);                                   
                    if (!OK)
                       e.preventDefault();     
                    }   
                 
                if (Value.length == 10)    
                    e.preventDefault();     
                                        
                if (Value.length == 2)
                    txtDated.value = txtDated.value + "/";                 
                else if (Value.length == 5)
                    txtDated.value = txtDated.value + "/";                       
                        
            });
        }           

    
 });    
    
function makePayment(){
    alert("Work in progress !!!" );
}
	 
function ValidateNums_PinNo(obj)
{
    var strValue;
    var re = /^[0-9]+$/;         
    strValue=obj.value;  
      
    if(strValue!="")
        {
        var OK = re.exec(strValue);                   
        if (!OK)
            {
         
            obj.value = "";            
            alert("Enter Numerals Only");
            return false;
            }                
        }
    
}

function ValidateNums_phoneNo(obj)
{
    var strValue;
    var re = /^[0-9-]+$/;         
    strValue=obj.value;  
      
    if(strValue!="")
        {
        var OK = re.exec(strValue);                   
        if (!OK)
            {
         
            obj.value = "";            
            alert("Enter Numerals Only");
            return false;
            }                
        }
    
}


function SetPayModeValidator(state)
{
    var RqFldValidatorDDNo = Page_Validators[2];
    var RqFldValidatorDate = Page_Validators[3];
    var RqFldValidatorDrownOn = Page_Validators[4];
    var RqFldValidatorBranch = Page_Validators[5];
                                  
    ValidatorEnable( RqFldValidatorDDNo,state);                
    ValidatorEnable( RqFldValidatorDate,state);                
    ValidatorEnable( RqFldValidatorDrownOn,state);                
    ValidatorEnable( RqFldValidatorBranch,state); 
}

function SetPaymentMode(value)
{
        var PaymentType;
        SetPayModeValidator(true); 
        pnlPaymentDetails.style.display="block";
        $("#spBranch").find("span").remove();      
        $("#spBranch").append($("<span>Branch</span>"));         
        if (value == "DP")
            {                    
            pnlPaymentDetails.style.display="none"; 
            SetPayModeValidator(false);    
            PaymentType = "OnlinePaymentSubscription.htm";             
            }
        else if (value == "DT")
            {
            $("#spBranch").find("span").remove(); 
            $("#spBranch").append($("<span>Branch where<br>Cheque Deposited</span>"));  
            PaymentType = "DirectDepositSubscription.htm";                                                             
            }
        else if (value == "DD")
            PaymentType = "ChequeDDSubscription.html";  
        else if (value == "FT")
            {
            pnlPaymentDetails.style.display="none"; 
            SetPayModeValidator(false);
            PaymentType = "FreeTrialSubscription.htm"; 
             }
             
        PaymentType = '"PaymentType":"' + PaymentType + '"';
        $.ajax({
              type: "POST",
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              url: "./NewReg.aspx/PaymentInfo",
              data:"{" +  PaymentType + "}",
              error: function(XMLHttpRequest, textStatus, errorThrown){
                  alert(textStatus);
              },
              success: function(result){
                 $("#info").text("");                                                 
                 $("#info").append(result.d)
              }
        });
                
}
