function prsutilVersion() {
    return("prsutil[3.0.1.2]")
}

function setColors() {
    document.bgColor = "#C7C7B1"
    document.fgColor = "#000000"
    document.linkColor = "#000000"
    document.vlinkColor = "#000000"
    document.alinkColor = "#000000"
}


function convertYear(oldDate) {
    var newDate

    if (oldDate < 100) {
	newDate = oldDate + 1900
    } else {
	newDate = oldDate
    }

    return (newDate)
}

function onSubmit() {
    return(confirm ("Start Report Now?"));
}

function loadNow() {
    document.forms[1].elements[19].focus();
    var BD = document.getElementById("NOW_BEGIN_DATE");
    if (BD != null && BD != "undefined") {
        var now = new Date();
        BD.value = (now.getMonth()+1) + "/" + now.getDate() + "/" + (convertYear(now.getYear()));
        var BT = document.getElementById("NOW_BEGIN_TIME");
        BT.value = (now.getHours() + ":" + now.getMinutes());
        var ED = document.getElementById("NOW_END_DATE");
        ED.value = (now.getMonth()+1) + "/" + now.getDate() + "/" + (convertYear(now.getYear()));
        var ET = document.getElementById("NOW_END_TIME");
        ET.value = (now.getHours() + ":" + now.getMinutes());
    }
}

function getToday() {
    var date = new Date()
    return((date.getMonth()+1) + "/" + date.getDate() + "/" + (convertYear(date.getYear())))
}

function setToday(input) {
    if (input.value.length == 0) {
        var date = new Date()
        input.value = (date.getMonth()+1) + "/" + date.getDate() + "/" + (convertYear(date.getYear()))
    }
}

function checkNull(input) {
    // Display status message
    status = prsutilVersion() + " checkNull()"

    // Check for null value
	   if (input.value.length == 0) {
	       alert("A value must be entered in this field!")
        input.focus()
    }
}

function checkDate(input) {
    var text = input.value
    var separators = ".-/, "
    var ndx, cnt
    var found
    var separator = "/"
    var arrDate = new Array("", "", "")
    var arrndx, arrcnt
    var date
    var month, day, year

    // Display status message
    status = prsutilVersion() + " checkDate("+text+")"

    // Do NOT process if date formula
    var digit = text.charAt(0)
    if (digit < "0" || digit > "9") {
        status = "Skipping date conversion. [" + text + "] must be a date formula!"
        return
    } 

    // Check for a null value
    if (input.value.length == 0) {
        checkNull(input)
        return
    }

	// Determine which separator is being used
    cnt = separators.length

    for (ndx = 0; ndx < cnt; ndx++) {
        found = text.indexOf(separators.charAt(ndx))
        if (found > 0) {
            separator = separators.charAt(ndx)
            break
        }
    }

    // Parse date string and store elements in array
    arrcnt = arrDate.length

    ndx = 0; cnt = text.length
    for (arrndx = 0; arrndx < arrcnt; arrndx++) {
        for (ndx = ndx; ndx < cnt; ndx++) {
            if (text.charAt(ndx) == separator) {
                ndx++
                break
            }
            if (text.charAt(ndx) >= "0" && text.charAt(ndx) <= "9") {
                arrDate[arrndx] += text.charAt(ndx)
            }
        }
    }

    /* If month, day, or year is missing, force date to be re-entered */
    if (arrDate[0].length == 0 || arrDate[0].length > 2 || 
	       arrDate[1].length == 0 || arrDate[1].length > 2 ||
		      arrDate[2].length < 4) {
        alert(text + " is an invalid date!\nPlease enter a valid date!")
        input.value = ""
        input.focus()
      		return
	   }

    // Default to current year if year missing
/*  
    if (arrDate[2].length == 0) {
        var currDate = new Date()
        arrDate[2] = convertYear(currDate.getYear())
    }
*/

    // Create new date object using month,day,year from date string
    date = new Date(arrDate[2], arrDate[0]-1, arrDate[1], 0,0,0)

    // Validate date value
    if ((date.getMonth()+1)==12 && date.getDate()==31 && (convertYear(date.getYear()))==1969) {
        alert(text + " is an invalid date!\nPlease enter a valid date!")
        input.value = ""
        input.focus()
    } else {
        input.value = (date.getMonth()+1) + "/" + date.getDate() + "/" + (convertYear(date.getYear()))
    }
}

function checkTime(input) {
    var text = input.value
    var separators = ":.-/, "
    var ndx, cnt
    var found
    var separator = ":"
    var arrTime = new Array("", "", "")
    var arrndx, arrcnt
    var time
    var hour, minute, second

    // Display status message
    status = prsutilVersion() + " checkTime("+text+")"

    // Check for a null value
    if (input.value.length == 0) {
	    alert("A value must be entered in this field!")
        input.focus()
        return
    }

    // Determine which separator is being used
    cnt = separators.length

    for (ndx = 0; ndx < cnt; ndx++) {
        found = text.indexOf(separators.charAt(ndx))
        if (found > 0) {
            separator = separators.charAt(ndx)
            break
        }
    }

    // Parse time string and store elements in array
    arrcnt = arrTime.length

    ndx = 0; cnt = text.length
    for (arrndx = 0; arrndx < arrcnt; arrndx++) {
        for (ndx = ndx; ndx < cnt; ndx++) {
            if (text.charAt(ndx) == separator) {
                ndx++
                break
            }
            if (text.charAt(ndx) >= "0" && text.charAt(ndx) <= "9") {
                arrTime[arrndx] += text.charAt(ndx)
            }
        }
    }

    /* If hour or minute is missing, force time to be re-entered */
    if (arrTime[0].length == 0 || arrTime[0].length > 2 || 
	       arrTime[1].length == 0 || arrTime[1].length > 2) {
        alert(text + " is an invalid time!\nPlease enter a valid time!")
        input.value = ""
        input.focus()
		      return
	   }

    // Create new date object using hour, minute, second from time string
    var currDate = new Date()
    time = new Date(convertYear(currDate.getYear()), currDate.getMonth()+1, currDate.getDate(), arrTime[0], arrTime[1], arrTime[2])

    // Format time value
    arrTime[0] = time.getHours()
	   arrTime[1] = time.getMinutes()
	   arrTime[2] = time.getSeconds()
    if (arrTime[0] <= 9) arrTime[0] = "0" + arrTime[0]
    if (arrTime[1] <= 9) arrTime[1] = "0" + arrTime[1]
    var value = arrTime[0] + ":" + arrTime[1]
    if (arrTime[2] != 0) {
        if (arrTime[2] <= 9) value += "0"
        value += arrTime[2]
    }
    input.value = value
}

function getPageButton(theForm, name) {
    theForm.NAME.value = name
    theForm.submit()
}

function getPageCheckbox(theForm, theBox, name) {
    theBox.checked = false;
    theForm.NAME.value = name
    theForm.submit()
}

function getReportForm(theForm, theBox, report) {
    theBox.checked = false;
    theForm.REPORT.value = report
    theForm.submit()
}
