﻿//clears default value of text fields
function clearText(field){
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
}

function makerequired(field)
{
    if (field.value == '3')
    {
        var mySetting = true;
    } else 
    {
        var mySetting = false;
    }
    ValidatorEnable(document.getElementById('ctl00_ContentPlaceHolder1_RequiredFieldValidator11'), mySetting);
    ValidatorEnable(document.getElementById('ctl00_ContentPlaceHolder1_RequiredFieldValidator12'), mySetting);
    ValidatorEnable(document.getElementById('ctl00_ContentPlaceHolder1_RequiredFieldValidator13'), mySetting);
    ValidatorEnable(document.getElementById('ctl00_ContentPlaceHolder1_RequiredFieldValidator14'), mySetting);
    ValidatorEnable(document.getElementById('ctl00_ContentPlaceHolder1_RequiredFieldValidator15'), mySetting);
}

function checkCC(source, arguments)
{
    arguments.IsValid = true;
    var data = arguments.Value;
    
    arguments.IsValid = cardval(data)
}

function cardval(s) {
    // remove non-numerics
    var v = "0123456789";
    var w = "";
    for (i=0; i < s.length; i++) {
        x = s.charAt(i);
        if (v.indexOf(x,0) != -1)
        w += x;
    }
    // validate number
    j = w.length / 2;
    if (j < 6.5 || j > 8 || j == 7) return false;
    k = Math.floor(j);
    m = Math.ceil(j) - k;
    c = 0;
    for (i=0; i<k; i++) {
        a = w.charAt(i*2+m) * 2;
        c += a > 9 ? Math.floor(a/10 + a%10) : a;
    }
    for (i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
    return (c%10 == 0);
}
