﻿//created by roberto to find control by ID match
function GetControlByIDMatch(clientid) {
    var doc = document.forms[0];
    for (var i = 0; i < doc.length; i++) {
        if (doc[i].id.match(clientid) != null && doc[i].id.match('ignoreLBL_'+clientid) == null) {
            return doc[i];
            break;
        }
    }
}

//created by alex to do async call 09-02-2009
function CheckDupe(control1, control2) {

    var e1 = GetControlByIDMatch(control1).value;
    var e2 = GetControlByIDMatch(control2).value;
    if (e1 != '' && e2 != '' && e1 == e2) {
        var pattern = new RegExp(/^(('[\w-\s]+')|([\w-]+(?:\.[\w-]+)*)|('[\w-\s]')([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
        if (pattern.test(e2)) {
            $.get('/dupescan.aspx?e=' + e2);
        }
    }
}
//Created by alex to do async dupe phone check 09-16-2009
function CheckDupePhones(control1, control2) {

    var e1 = GetControlByIDMatch(control1).value;
    var e2 = GetControlByIDMatch(control2).value;

    e1 = cleanphone(e1);
    e2 = cleanphone(e2);
    if (e2==null||e2 == '') {
        e2 = e1;
    }

    if (e1 != '' && e2 != '' && e1.length == 10 && e2.length == 10) {
        $.get('/dupescan.aspx?t1=' + e1 + '&t2=' + e2);
    }
}

function cleanphone(p)
{
    if (p != null && p != '') {
        p = p.replace(/-/g, "");
        p = p.replace("(", "");
        p = p.replace(")", "");
        p = p.replace(/_/g, "");
        p = p.replace(" ", "");
    }

    return p;
}
