﻿if (!northlich) {
    var northlich = new Object();
}
if (!northlich.validate) {
    northlich.validate = new Object();
}

if (!northlich.validate.Phone) {
    northlich.validate.Phone = new Object();
}

northlich.validate.Phone.CheckError = function(dspName, tagID, oErrorsTracker) {
    var oTxt = document.getElementById(tagID);

    if (oTxt.value.replace(/ /g, '') == '') {
        return;
    }

    //xxx-xxx-xxxx
    var myvalue = oTxt.value;
    myvalue = myvalue.replace(/ /g, '');
    myvalue = myvalue.replace(/-/g, "");
    myvalue = myvalue.replace("(", "");
    myvalue = myvalue.replace(")", "");

    var error_msg = null;



    if (myvalue.length != 10) {
        error_msg = "The format for " + dspName + " should be 'xxx-xxx-xxxx'. There should be 10 numbers entered.";
        oErrorsTracker.appendError(oTxt.id, error_msg);

        return;
    }

    var oRe = /[a-zA-Z0-9]{10}/;
    var matchA = oRe.exec(myvalue);
    if (matchA == null) {
        error_msg = "The format for " + dspName + " should be 'xxx-xxx-xxxx'. There should only be numbers or letters entered.";
        oErrorsTracker.appendError(oTxt.id, error_msg);

        return;
    }

    var format_value = myvalue.substring(0, 3) + "-" + myvalue.substring(3, 6) + "-" + myvalue.substring(6, 10);

    oTxt.value = format_value;
}