function MM_findObj(n, d) { //v4.0
    var p,i,x;
    if (!d) d = document;
    if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n];
    for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && document.getElementById) x = document.getElementById(n);
    return x;
}

function findObj(id)
{
    return MM_findObj(id);
}

function showObj(id)
{
    var obj = findObj(id);
    if (obj)
        obj.style.display = "block";
}

function hideObj(id)
{
    var obj = findObj(id);
    if (obj)
        obj.style.display = "none";
}

function validateRequiredCustom(value)
{
    return value != "";
}

function validateEmailCustom(value) {
    var v_Expr = "[\\w-_\\.]+@[\\w-_\\.]+\\.[\\w-_]+";
    return validateRegExp(value, v_Expr);
}

function checkValuesEquality(control0, label0, control1, label1, ignoreCase) {
    var equal = isComponentValuesEqual(control0, label0, control1, label1, ignoreCase);
    if (!equal) {
        alert("You have incorrectly entered information into the fields that are\n"
                + "highlighted in red text. Please click OK and correct your entries.");
    }
    return equal;
}

function validateEmailOpt(value)
{
    if (value == "") return true;
    var v_Expr = "[\\w-_\\.]+@[\\w-_\\.]+\\.[\\w-_]+";
    return validateRegExp(value, v_Expr);
}

function validateZip(value)
{
    var v_Expr = "[0-9]{5}[0-9 \\-]{0,5}";
    return validateRegExp(value, v_Expr);
}

function validateNameOpt(value)
{
    if (value == "") return true;
    var v_Expr = "[A-Za-z]{1}[A-Za-z \\-\\.\\',]*";
    return validateRegExp(value, v_Expr);
}

function validateName(value)
{
    var v_Expr = "[A-Za-z]{1}[A-Za-z \\-\\.\\',]*";
    return validateRegExp(value, v_Expr);
}

function validateAddressOpt(value)
{
    if (value == "") return true;
    var v_Expr = "[A-Za-z0-9]{1}[A-Za-z0-9 \\-\\.\\',]*";
    return validateRegExp(value, v_Expr);
}

function validateAddress(value)
{
    var v_Expr = "[A-Za-z0-9]{1}[A-Za-z0-9 \\-\\.\\',]*";
    return validateRegExp(value, v_Expr);
}

function validatePhone(value)
{
    if (value == "") return true;

    var v_Expr = "[0-9\(]{1}[A-Za-z0-9 \(\)\\.\\-]*";
    if (validateRegExp(value, v_Expr) == false)
        return false;

    var stripped = value.replace(/[\(\)\.\-\ ]/g, '');
    if (stripped.length != 10)
        return false;

    return true;
}

function validateNumber(value)
{
    var v_Expr = "[0-9]*";
    return validateRegExp(value, v_Expr);
}

function validateChecksum(value)
{
    if (value == "" || value == "00000000000") return false;

    var v_Expr = "[0-9]{11}";
    if (validateRegExp(value, v_Expr) == false)
        return false;

    var digits = value.split("");
    var sum = 0;
    for (i = 0; i < 9; i++)
        sum += parseInt(digits[i]);
    var chksum = parseInt(digits[9] + digits[10], 10);
    return (sum == chksum);
}

function validateRegExp(value, expr)
{
    var v_RegExp = new RegExp(expr);
    return (v_RegExp.exec(value) == value);
}

function isComponentValuesEqual(control0, label0, control1, label1, ignoreCase) {
    var obj0 = findObj(control0);
    var lbl0 = findObj(label0);
    var obj1 = findObj(control1);
    var lbl1 = findObj(label1);

    if (obj0 == null || obj1 == null) {
        return false;
    }

    var ok = ignoreCase ? obj0.value.toLowerCase() == obj1.value.toLowerCase() : obj0.value == obj1.value;
    if (!ok) {
        if (lbl0) lbl0.style.color = "red";
        if (lbl1) lbl1.style.color = "red";
    } else {
        if (lbl0) lbl0.style.color = "black";
        if (lbl1) lbl1.style.color = "black";
    }
    return ok;
}

function cleanupFormGlobalErrors() {
    var formGlobalErrors = document.getElementById('form_global_errors');
    if (formGlobalErrors) {
/*
		while (formGlobalErrors.hasChildNodes()) {
			formGlobalErrors.removeChild(holder.lastChild);
		}
*/
		formGlobalErrors.innerHTML = '';
	}
}