﻿function AtLeastOneContactNo_ClientValidate(source, args)
{
    var txtAreaCode = $("*[id$='txtAreaCode']")[0];
    var txtTelNumber = $("*[id$='txtTelNumber']")[0];
    var txtWorkArea = $("*[id$='txtWorkArea']")[0];
    var txtWorkTel = $("*[id$='txtWorkTel']")[0];
    var txtCell = $("*[id$='txtCell']")[0];
        
    if ((txtCell != null && txtCell.value != "") 
          || (txtAreaCode != null && txtTelNumber != null && txtAreaCode.value != "" && txtTelNumber.value != "")
          || (txtAreaCode == null && txtTelNumber != null && txtTelNumber.value != "")
          || (txtWorkArea != null && txtWorkTel != null && txtWorkArea.value != "" && txtWorkTel.value != "")
          || (txtWorkArea == null && txtWorkTel != null && txtWorkTel.value != ""))
        args.IsValid = true;
    else
        args.IsValid = false;
}

function CellphoneValidate_ClientValidate(source, args) {
    var txtCell1 = $("*[id$='txtCell1']")[0];
    var txtCell2 = $("*[id$='txtCell2']")[0];
    var txtCell3 = $("*[id$='txtCell3']")[0];
    var txtCell4 = $("*[id$='txtCell4']")[0];
    var txtCell5 = $("*[id$='txtCell5']")[0];
    var txtCell6 = $("*[id$='txtCell6']")[0];
    var txtCell7 = $("*[id$='txtCell7']")[0];
    var txtCell8 = $("*[id$='txtCell8']")[0];
    var txtCell9 = $("*[id$='txtCell9']")[0];
    var txtCell10 = $("*[id$='txtCell10']")[0];

    if ((txtCell1 != null && txtCell1.value != "") && (txtCell2 != null && txtCell2.value != "") 
        && (txtCell3 != null && txtCell3.value != "") && (txtCell4 != null && txtCell4.value != "") 
        && (txtCell5 != null && txtCell5.value != "") && (txtCell6 != null && txtCell6.value != "") 
        && (txtCell7 != null && txtCell7.value != "") && (txtCell8 != null && txtCell8.value != "")
        && (txtCell9 != null && txtCell9.value != "") && (txtCell10 != null && txtCell10.value != ""))

        args.IsValid = true;
    else
        args.IsValid = false;
}

function ClubCardNoRequired_ClientValidate(source, args)
{
    var ClubCardNo = "";
    for (var i = 1; i <= 13; i += 1)
        ClubCardNo = ClubCardNo + $("*[id$='txtMembershipNo" + i + "']")[0].value;    
        
    if (!(ClubCardNo == ""))
    
        args.IsValid = true;
    else
        args.IsValid = false;    
    
}

function ValidateClubCardNo_ClientValidate(source, args)
{
    var ClubCardNo = "";
    var RexMemNo = /^\d{13}$/;
    
    for (var i = 1; i <= 13; i += 1)
        ClubCardNo = ClubCardNo + $("*[id$='txtMembershipNo" + i + "']")[0].value;  
    
    args.IsValid = false;
    
    if ((ClubCardNo.match(RexMemNo)))
        var check1 = 0;
        var check2 = 0;
        var checkSum = 0;
        var sumDiv = 0;
        var sum = 0;

        for (var i = 1; i < 12; i += 2)
        check1 += parseInt(ClubCardNo.charAt(i),10);
         
        check1 *= 3;

        for (var i = 0; i < 11; i += 2)
        check2 += parseInt(ClubCardNo.charAt(i),10);

        checkSum = check1 + check2;

        sumDiv = checkSum % 10;
        
        if (sumDiv == 0)
        {
            sum = 0;
            args.IsValid = true;
        }
         else
         {
            sum = 10 - sumDiv;    
         }
            
        if (sum == ClubCardNo.charAt(12))
        args.IsValid = true;
                        
}
