﻿var pageType = 0;
var reDate = /(?=\d)^(?:(?!(?:10\D(?:0?[5-9]|1[0-4])\D(?:1582))|(?:0?9\D(?:0?[3-9]|1[0-3])\D(?:1752)))((?:0?[13578]|1[02])|(?:0?[469]|11)(?!\/31)(?!-31)(?!\.31)|(?:0?2(?=.?(?:(?:29.(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:(?:\d\d)(?:[02468][048]|[13579][26])(?!\x20BC))|(?:00(?:42|3[0369]|2[147]|1[258]|09)\x20BC))))))|(?:0?2(?=.(?:(?:\d\D)|(?:[01]\d)|(?:2[0-8])))))([-.\/])(0?[1-9]|[12]\d|3[01])\2(?!0000)((?=(?:00(?:4[0-5]|[0-3]?\d)\x20BC)|(?:\d{4}(?!\x20BC)))\d{4}(?:\x20BC)?)(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$/;
var email = /^[a-zA-Z0-9\-\.\_]+\@(\[?)[a-zA-Z0-9\-\.\_]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;

function isDate(tb)
{
    if (tb.value.length > 0)
    {
        if (!tb.value.match(reDate))
        {
            alert('Date entered is not valid.  Please use MM/DD/YYYY format.');
            tb.focus();
            tb.select();
        }
    }
}

function isEmail(tb)
{
    if(!tb.value.match(email) && tb.value.length > 0)
    {
        alert('Email address entered is not valid.');
        tb.focus();
        tb.select();
    }
}

function isLen(tb, len)
{
    if (tb.value.length != 0 && tb.value.length != len)
    {
        alert('Value entered is not valid.  Value must be ' + len.toString() + ' characters long.');
        tb.focus();
        tb.select();
    }
}

function isLenNumbers(tb, len)
{
    tb.value = tb.value.replace(/[^\d]/g, '')
    if (tb.value.length != 0 && tb.value.length != len)
    {
        alert('Value entered is not valid.  Value must be ' + len.toString() + ' numeric characters.');
        tb.focus();
        tb.select();
    }
}

function isNumber(evt)
{
    if (window.event)
        kc = evt.keyCode;
    else
        kc = evt.which;
    return (kc >= '0'.charCodeAt() && kc <= '9'.charCodeAt()) || (kc == 0) || (kc == 13) || (kc == 8);
}

function openWindow(page, w, h) {
    window.open(page, 'newWin', 'width=' + w + ',height=' + h + ',toolbar=yes,location=yes,status=yes,menubar=yes,resizable=yes,copyhistory=no,scrollbars=yes');
}

function preparePage()
{
    if (window.location.toString().toLowerCase().indexOf('illinoisceb') > 0)
        pageType = 1;
    else
        pageType = 2;
}

function setRowColor(ctrl)
{
    tb = ctrl.parentNode;
    if (tb.childNodes[tb.childNodes.length - 1].childNodes.length == 1 || navigator.appName != 'Microsoft Internet Explorer')
        c = tb.childNodes.length - 1;
    else
        c = tb.childNodes.length;
    for (i=1; i <  c; i++)
    {
        if ((i % 2) == 0)
            clr = '#E7E7E7';
        else
            clr = '#FFFFFF';
        tb.childNodes[i].style.backgroundColor = clr;
    }
    
    if (pageType == 1)
        ctrl.style.backgroundColor = '#84A5C4';
    else
        ctrl.style.backgroundColor = '#7CD584';
}
