﻿function AtLeastOneContactNo_ClientValidate(source, args)
{
    var txtAreaCode = document.getElementById("crContactDetails_txtAreaCode");
    var txtTelNumber = document.getElementById("crContactDetails_txtTelNumber");
    var txtWorkArea = document.getElementById("crContactDetails_txtWorkArea");
    var txtWorkTel = document.getElementById("crContactDetails_txtWorkTel");
    var txtCell = document.getElementById("crContactDetails_txtCell");
        
    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 ClubCardNoRequired_ClientValidate(source, args)
{
    var ClubCardNo = "";
    for (var i = 1; i <= 13; i += 1)
        ClubCardNo = ClubCardNo + document.getElementById("txtMembershipNo" + i).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 + document.getElementById("txtMembershipNo" + i).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;
                        
}