﻿// JScript File
var ie4=document.all;
document.onmousemove = getMouseXY;
// Temporary variables to hold mouse x-y pos.
var mouseX = 0;
var mouseY = 0;

function dumpHTML() {
    var myTBody  = document.getElementById("mainTable");
    var tmp = myTBody.innerHTML;
    alert(tmp);
}

// answers the row in any array that matches the searchValue for the given searchName field.
// if no row is found, answers -1.
function findRow(theArray, searchName, searchValue) {
    var iSize = theArray.length;
    for( i=0; i<iSize; i++ ) {
        if(searchValue == theArray[i][searchName]) {
            return i;
        }
    }
    return -1;
}

// Common cell manipulation functions 
function disableCell(eleName) { 
    var aCell = document.getElementById(eleName); 
    aCell.style.opacity = .5; 
    aCell.style.MozOpacity = .5; 
    aCell.style.KhtmlOpacity = .5; 
    aCell.style.filter = "alpha(opacity=50)"; 
    aCell.setAttribute("disabled", "disabled"); 
} 

function enableCell(eleName) { 
    var aCell = document.getElementById(eleName); 
    aCell.style.opacity = 1; 
    aCell.style.MozOpacity = 1; 
    aCell.style.KhtmlOpacity = 1; 
    aCell.style.filter = "alpha(opacity=100)"; 
    aCell.removeAttribute("disabled"); 
}

var calendarWin;
var seenCalendar = false;
function calendarWindow(fld, keepTime) {
    if(seenCalendar && !calendarWin.closed) {
        calendarWin.close()
    }
    var ktLit = "";
    if(keepTime) {
        ktLit = '&keepTime='+keepTime;
        var frmVal = eval('document.aspnetForm.ctl00_ContentPlaceHolder1_'+fld+'.value');
        ktLit += '&curVal='+frmVal;
    }
    seenCalendar = true;
    // set width and height
    var wdth=235, hght=215;
    if(ie4) { wdth=220; hght=225; }
    var styls = "location=no,menubar=no,status=no,toolbar=no,scrollbars=no,resizable=no";
    styls += ",width=" + wdth + ",height=" + hght;
    // set position
    styls += ",left=" + Math.round(mouseX - (wdth / 2));
    styls += ",top="  + Math.round(mouseY - (hght / 2));
    calendarWin = window.open('calendar.aspx?formname=aspnetForm.ctl00_ContentPlaceHolder1_'+fld+ktLit,'calendar_window',styls);
    calendarWin.focus()
}

// replaces the time portion of at DateTime value in dateControl with the Hr, Mn, AmPm values found in timeRoot
function replaceTime(dateControl, timeRoot) {
    var formDate = eval("document.aspnetForm.ctl00_ContentPlaceHolder1_" + dateControl);
    var dateValue = formDate.value;
    var hr = eval("document.aspnetForm.ctl00_ContentPlaceHolder1_" + timeRoot + "Hr[document.aspnetForm.ctl00_ContentPlaceHolder1_" + timeRoot + "Hr.selectedIndex].value");
    var mn = eval("document.aspnetForm.ctl00_ContentPlaceHolder1_" + timeRoot + "Mn[document.aspnetForm.ctl00_ContentPlaceHolder1_" + timeRoot + "Mn.selectedIndex].value");
    var amPm = eval("document.aspnetForm.ctl00_ContentPlaceHolder1_" + timeRoot + "AmPm[document.aspnetForm.ctl00_ContentPlaceHolder1_" + timeRoot + "AmPm.selectedIndex].value");
    var tm = hr + ":" + mn + ":00 " + amPm;
    var newDateValue = dateValue.substring(0, dateValue.indexOf(" "));
    newDateValue += " " + tm;
    formDate.value = newDateValue;
}

function clearSelections(listControl) {
    var formList = eval("document.aspnetForm.ctl00_ContentPlaceHolder1_" + listControl);
    var iSize = formList.length;
    for(var i=0; i<iSize; i++ ) {
        formList[i].selected = false;
    }
}

// Main function to retrieve mouse x-y pos.
function getMouseXY(e) {
    if (ie4) { // grab the x-y pos.s if browser is IE
        mouseX = event.screenX;
        mouseY = event.screenY;
    } else {  // grab the x-y pos.s if browser is not IE
        mouseX = e.screenX;
        mouseY = e.screenY;
    }  
    // catch possible negative values in NS4
    if (mouseX < 0){mouseX = 0;}
    if (mouseY < 0){mouseY = 0;}  
    return true;
}

// Populates list box (list) with the array (array) and sets the current selection to (selection).
// Puts array[][indexVal] as option value and array[][indexTxt] as option text.
function optionsList( list, array, indexVal, indexTxt, selection, startAt, selectOne ) {
    // zap out the list box
	clearList(list);

    listIndex = startAt;
    selIndex = -1;
    var o = new Array();
    iSize = array.length;

    // build options list array
    for( i=0; i<iSize; i++ ) {
        o[listIndex++] = new Option( array[i][indexVal], array[i][indexTxt] );
    }

    // populate list box with options list array
    for( i=startAt; i<listIndex; i++ ) {
        eval(list + ".options["+i+"] = o["+i+"]" );
    }

    // select the currently selected row (if there is one)
    if(selectOne) {
	    if( selection > -1 )
	        eval( list + ".selectedIndex = " + selection );
	    else
	        eval( list + ".selectedIndex = 0" );
	}

    return listIndex;
}

// Clears a list box of its contents except for the first entry.
function clearList(list) {
    var iSize = eval( list + ".length" );
    for( i=iSize; i>=0; i-- ) {
        eval( list + ".options["+i+"] = null" );
    }
    eval( list + ".selectedIndex = 0" );
}