
function getRZMemberId(){
    return ($("input[name='patient.rzMembershipId']").val());
}
function validateRZMemberId() {
    if(!checkRewardZoneId(getRZMemberId())) {
        showRZAlert("Please enter a valid BestBuy RewardZone Membership Id. If you do not have your RewardZone number with you, you can provide the number when you attend your FREE LASIK Eye Exam");
        return false;
    }
    else{
        hideRZAlert();
        return true;
    }
}
function showRZAlert(msg){
   $('#rzAlertText').text(msg);
}
function hideRZAlert(){
    $('#rzAlertText').text('');
}
function checkRewardZoneId(memberId) {
    //up to 10 digits or blank
    if ( memberId.length == 0 )
        return true;
    if ( memberId.length < 11 && isNumeric(memberId) && validate_RZ(memberId)  )
        return true;
    return false;
}
function validate_RZ(memberId) {
    //alert(memberId) ;
    var tempMemberId = memberId, temp = "";
    if ( memberId.length < 10 ) {
         temp = temp.concat("0000000000", memberId);   //zero fill
         //alert('temp: ' + temp) ;
         tempMemberId =  temp.substr(temp.length - 10,10);
    }
    var chkDigit = tempMemberId.substr(9);  //10th digit
    var tempSum = 0, temp_product = 0;
    for (var i=0; i<9; i++) {
       if ( (i+1) % 2 == 1)  //choose only odd-digit places (1,3,5,7,9)
           temp_product = parseInt(tempMemberId.charAt(i)) * 3;  //multiply by 3
       else
           temp_product = parseInt(tempMemberId.charAt(i)) ;
       tempSum = tempSum + temp_product;
    }
    var tempChkDigit = tempSum % 10;
    if  (tempChkDigit != 0) tempChkDigit = parseInt(10 - tempChkDigit);
    //alert (tempMemberId + ', chkdigit: ' + chkDigit + ', calc_chkdigit: ' + tempChkDigit);
    if (tempChkDigit == chkDigit)
       return true;
    return false;
}

