var defaultEmptyOK = false;

var daysInMonth = new Array(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

//-----------------------------------------------------
// Will set progress layer to visible if the fields are
// valid. 
//-----------------------------------------------------
function validateRequiredFieldsWithProgressLayer(objForm) {
    var result = validateRequiredFields(objForm);
    if (result) {
        setProgressLayerVisible(true);
    }

    return result;
}

function validateRequiredFields(objForm) {

    if (document.images) {
        var password = "";
        var password2 = "";
        var login = "";
        var startDate;
        var endDate;

        for (i = 0; i < objForm.length; i++) {

            var objElement = objForm.elements[i];

            if (objElement.name.substring(0, 3) == "REQ") {

                if (objElement.value == "") {
                    alert("Please fill in required fields.");
                    return false;
                    break;
                }
            }

            if (objElement.name == "REQpassword") {
                password = objElement.value;
            }

            if (objElement.name == "REQpassword2") {
                password2 = objElement.value;
            }

            if (objElement.name == "REQStartDate") {
                if (!checkDate(objElement.value)) {
                    alert("Please supply a valid Start Date");
                    return checkDate(objElement.value);
                    break;
                } else {
                    startDate = objElement.value;
                }
            }

            if (objElement.name == "REQEndDate") {
                if (!checkDate(objElement.value)) {

                    alert("Please supply a valid End Date");
                    return checkDate(objElement.value);
                    break;

                } else {
                    endDate = objElement.value;
                }
            }

            if (objElement.name == "REQlogin") {
                login = objElement.value;
            }

            if (objElement.name == "REQStartYear") {
                if (!isYear(objElement.value)) {
                    alert("Please supply a valid Start Year");
                    return false;
                }
            }

            if (objElement.name == "REQEndYear") {
                if (!isYear(objElement.value)) {
                    alert("Please supply a valid End Year");
                    return false;
                }
            }

        }

        if (password != password2) {
            alert("The passwords you entered did not match.");
            return false;
        }

        if (login != "") {
            if (!isAlphanumeric(login)) {
                alert("Please use only letters for login.");
                return false;
            }
        }
    }

    return true;
}

function checkDate(strDate) {
    var parseDate;
    parseDate = strDate.split("/");

    if (parseDate.length < 3) {

        return false;
    } else {

        return isDate(parseDate[2], parseDate[0], parseDate[1]);
    }
}

//-----------------------------------------------------
//THE FOLLOWING CODE ARE TAKEN FROM FormChek.js
// 18 Feb 97 created Eric Krock
// (c) 1997 Netscape Communications Corporation
//-----------------------------------------------------
function isDate(year, month, day) {
    //alert(isYear(year)+" "+year);
    //alert(isMonth(month)+" "+month);
    //alert(isDay(day)+" "+day);

    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;

    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    if (intDay > daysInMonth[intMonth]) return false;

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}

function isYear(s) {
    if (isEmpty(s))

        if (isYear.arguments.length == 1) return defaultEmptyOK;
        else return (isYear.arguments[1] == true);

    if (!isNonnegativeInteger(s)) return false;

    return ((s.length == 2) || (s.length == 4));
}

function isMonth(s) {
    if (isEmpty(s)) {
        if (isMonth.arguments.length == 1) return defaultEmptyOK;
        else return (isMonth.arguments[1] == true);
    }
    return isIntegerInRange(s, 1, 12);
}

function isDay(s) {
    if (isEmpty(s)) {
        if (isDay.arguments.length == 1) return defaultEmptyOK;
        else return (isDay.arguments[1] == true);
    }
    return isIntegerInRange(s, 1, 31);
}

function daysInFebruary(year) {
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

function isEmpty(s) {
    return ((s == null) || (s.length == 0))
}

function isNonnegativeInteger(s) {

    var secondArg = defaultEmptyOK;

    if (isNonnegativeInteger.arguments.length > 1) {
        secondArg = isNonnegativeInteger.arguments[1];
    }
    return (isSignedInteger(s, secondArg)
            && ( (isEmpty(s) && secondArg) || (parseInt(s) >= 0) ) );
}

function isIntegerInRange(s, a, b) {
    if (isEmpty(s)) {
        if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
        else return (isIntegerInRange.arguments[1] == true);
    }

    if (!isInteger(s, false)) return false;

    var num = (s);

    return ((num >= a) && (num <= b));
}

function isInteger(s) {
    var i;

    if (isEmpty(s))
        if (isInteger.arguments.length == 1) return defaultEmptyOK;
        else return (isInteger.arguments[1] == true);

    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }

    return true;
}

function isDigit(c) {
    return ((c >= "0") && (c <= "9"))
}

function isSignedInteger(s) {
    if (isEmpty(s))
        if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
        else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        if ((s.charAt(0) == "-") || (s.charAt(0) == "+"))
            startPos = 1;
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}

function isAlphanumeric(s) {

    var i;

    if (isEmpty(s)) {
        if (isAlphanumeric.arguments.length == 1) {
            return defaultEmptyOK;
        } else {
            return (isAlphanumeric.arguments[1] == true);
        }
    }

    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);

        //alert (c);
        //alert (!isLetter(c));
        //alert (isDigit(c));

        if ((!isLetter(c) || isDigit(c))) {

            return false;
        }
    }

    return true;
}

function isLetter(c) {
    return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}


//-----------------------------------------------------
// Progress Layer
//-----------------------------------------------------
function hideProgressLayer() {
    setTimeout("setProgressLayerVisible(false)", 1000)
}

function setProgressLayerVisible(b) {

    if (document.layers) {//netscape 4.5
        //document.progress.visibility="show";
        //window.scroll(0,0);
        //document.content.visibility="hide";
    }

    if (document.all) {//ie
        if (b) {
            document.all.progress.style.visibility = "visible";
            document.all.content.style.visibility = "hidden";
        } else {
            document.all.progress.style.visibility = "hidden";
            document.all.content.style.visibility = "visible";
        }
        window.scroll(0, 0);
        writeForIE();
        return;
    }

    if (document.getElementById) {
        if (b) {
            document.getElementById("progress").style.visibility = "visible";
            document.getElementById("content").style.visibility = "hidden";
        } else {
            document.getElementById("progress").style.visibility = "hidden";
            document.getElementById("content").style.visibility = "visible";
        }

        window.scroll(0, 0);

    }
}

var index = 0;

function writeForIE() {
    document.all["image"].innerHTML = "<img src='./images/loading" + (index + 1) + ".gif' width=70 height=20/>";
    setTimeout("writeForIE()", 800);
    index = index + 1;
    index = index % 5;

}
		
