﻿// Copyright (c) 2006 - 2007 Global Relay Communications, Inc. All Rights Reserved.

var pageIsValid = true;
var place = "master_ContentPlaceHolder1_";

function ShowError(lbl_id, precondition, valid) {   
    var lbl = document.getElementById(place + lbl_id);
    if (precondition && !valid)
    {
        // Invalid
        pageIsValid = false;
        lbl.className = "error_on";
        return true;
    }
    // Valid
    lbl.className = "error_off";
    return false;
}
function ShowErrorCbl(lbl_id, precondition, cbl_id) {
    var tr = document.getElementById(cbl_id);
    var inputs = tr.getElementsByTagName("input");
    var checked = false;
    for (var i = 0; i < inputs.length; i++) {
        if (inputs[i].checked) {
            checked = true;
        }
    }
    ShowError(lbl_id, precondition, checked);
}
function ShowErrorVal(lbl_id, precondition, tb_id) {
    var tb = document.getElementById(place + tb_id);
    ShowError(lbl_id, precondition, tb.value.length > 0);
}
function ValidateEmail(lbl_id, precondition, tb_id) {
    var tb = document.getElementById(place + tb_id);
    var pattern = new RegExp("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$", "i");
    ShowError(lbl_id, precondition, tb.value.length > 0 && pattern.test(tb.value));
}
function ValidateForm() {
    pageIsValid = true;

    // Contact Information
    ShowErrorVal("lblCompany", true, "txtCompany");
    ShowErrorVal("lblDomain", true, "txtDomain");
    ShowErrorVal("lblName", true, "txtName");
    ShowErrorVal("lblPhone", true, "txtPhone");
    ValidateEmail("lblEmail", true, "txtEmail");
    ShowErrorCbl("lblContact", true, "trContact");
    ShowErrorVal("lblCountry", true, "ddlCountry");
    ShowErrorCbl("lblServices", true, "trServices");
    ShowErrorVal("lblUsers", true, "txtUsers");

    if (!pageIsValid) {
        alert("Please complete all required fields (marked with a red asterisk)");
    }

    return pageIsValid;
}