﻿// 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(formName) {
    pageIsValid = true;

    if (formName == "reviewer") {
        ShowErrorVal("lblName", true, "txtName");
        ValidateEmail("lblEmail", true, "txtEmail");
    } else if (formName == "standard") {
        ShowErrorVal("s_lblName", true, "s_txtName");
        ValidateEmail("s_lblEmail", true, "s_txtEmail");   
    }
    else if (formName == "bloomberg") {
        ShowErrorVal("b_lblName", true, "b_txtName");
        ValidateEmail("b_lblEmail", true, "b_txtEmail");   
    }
    
    
    if (!pageIsValid) {
        alert("Please complete all required fields (marked with a red asterisk)");
    }

    return pageIsValid;
}

addLoadEvent(function() { $("#div_reviewer").hide(); }); // Hide Super Reviewer form
addLoadEvent(function() { $("#div_standard").hide(); }); // Hide Standard form
addLoadEvent(function() { $("#div_bloomberg").hide(); }); // Hide Bloomberg form