//=========================== Menu Highlighting ===========================
var navBGColor;
var navColor;
var navHighlightBGColor = "#999";
var navSelectionBGColor = "#555";

function navHighlight(pElement) {
    navBGColor = pElement.style.backgroundColor;
    navColor = pElement.style.color;
    pElement.style.background = navHighlightBGColor;
    pElement.style.color = "#000000";
}
function navNormal(pElement) {
    pElement.style.backgroundColor = navBGColor;
    pElement.style.color = navColor;
}
function navClick(pElement) {
    pElement.style.backgroundColor = navSelectionBGColor;
}
//===========================================================================

//=========================== Column Highlighting ===========================
var columnBGColor;
var columnColor;
var columnHighlightBGColor = "#aaa";
var columnSelectionBGColor = "#777";

function columnHighlight(pElement) {
    columnBGColor = pElement.style.backgroundColor;
    columnColor = pElement.style.color;
    pElement.style.background = columnHighlightBGColor;
    pElement.style.color = "#000000";
}
function columnNormal(pElement) {
    pElement.style.backgroundColor = columnBGColor;
    pElement.style.color = columnColor;
}
//===========================================================================

//======================== Check For Page Updates ===========================

var l_strFocusValue = "";
var l_blnHasChanged = false; 

//--- Store Original Field Value ---
function FieldFocus(pField) {
    l_strFocusValue = pField.value;
}

//--- Compare Original Value and Exiting Value ---
function FieldBlur(pField) {
    if (pField.value != l_strFocusValue) l_blnHasChanged = true;
}

//--- If Any page values have changed, promt the user to save changes.
function changePage(pForm, pNewPage, pQueryString) {
    if (l_blnHasChanged) {
        var l_blnResult = confirm("Do you want to save your changes to this page?");
        if (l_blnResult == true) {
            pForm.hdnNextPage.value = pNewPage;
            validate(pForm);
        } else {
            document.location = pNewPage+pQueryString;
        }
     } else {
        document.location = pNewPage+pQueryString;
     }
}
//===========================================================================

//======================== Show/Hide/Swap Table Rows ========================
//--- Show Table Rows ---
function showRows(pRowsToShow) {
    var l_elmRow = document.getElementById(pRowsToShow);
        //alert('showRows:'+pRowsToShow+">"+l_elmRow.style.display);
    if (document.all)
        l_elmRow.style.display = "inline";
    else
        l_elmRow.style.display = "table-row";
}
//------

//--- Hide Table Rows ---
function hideRows(pRowsToHide) {
    var l_elmRow = document.getElementById(pRowsToHide);
    //alert('hideRows:'+pRowsToHide+">"+l_elmRow.style.display);
    l_elmRow.style.display = "none";
}
//------

//--- Swap Show/Hide Table Rows ---
function swapRows(pRowsToShow,pRowsToHide) {
    //Display rows
    var l_elmRow = document.getElementById(pRowsToShow);
    //alert('swapRows-Display:'+pRowsToShow+">"+l_elmRow.style.display);
    if (document.all)
        l_elmRow.style.display = "inline";
    else
        l_elmRow.style.display = "table-row";
    //Hide Rows
    l_elmRow = document.getElementById(pRowsToHide);
    //alert('hideRows-Display:'+pRowsToHide+">"+l_elmRow.style.display);
    l_elmRow.style.display = "none";
}
//------

//===========================================================================


//=========================== Add/Edit Table Rows ===========================
//==== Allow Data Row Edit ====
function editRow(pHdnType, pHdnID, pRowId, pType) {
    //Hide any previously open edit rows.
    var l_strOldType = pHdnType.value;
    if (l_strOldType == '') l_strOldType = pType;
    
    if (pHdnID.value != "") {
      var l_strOldID = pHdnID.value;
      showRows(l_strOldType+'DisplayRow'+l_strOldID);
      hideRows(l_strOldType+'EditRow'+l_strOldID);
    }   
     
    //Hide any previously opened add rows.
    hideRows(l_strOldType+'AddRow');
    
    //Update hidden values
    pHdnType.value = pType;
    pHdnID.value = pRowId; 
       
    //Display data edit fields.
    showRows(pType+'EditRow'+pRowId);
    hideRows(pType+'DisplayRow'+pRowId);
    hideRows(pType+'DisplayBtnRow');
    if (pType != "") showRows(pType+'EditRowButtons'+pRowId);
}
//==============================

//==== Cancel Data Row Edit ====
function cancelEdit(pHdnType, pHdnID) {
    var l_strType = pHdnType.value;
    var l_strID = pHdnID.value;
    
    //Hide data edit row and show display row
    showRows(l_strType+'DisplayRow'+l_strID);
    hideRows(l_strType+'EditRow'+l_strID);
    showRows(l_strType+'DisplayBtnRow');
    if (l_strType != "") hideRows(l_strType+'EditRowButtons'+l_strID);
    //Reset hidden values
    pHdnType.value = "";
    pHdnID.value = "";
}
//==============================

//==== Add New Data Row ====
function addRow(pHdnType, pHdnID, pType) {
    //Hide any previously open add/edit rows.
    var l_strOldType = pHdnType.value;
    if (l_strOldType == '') l_strOldType = pType;

    if (pHdnID.value != "") {
      var l_strOldID = pHdnID.value;
      swapRows(l_strOldType+"DisplayRow"+l_strOldID,l_strOldType+"EditRow"+l_strOldID) 
    }
    showRows(l_strOldType+'AddRow');
    hideRows(l_strOldType+'DisplayBtnRow');
    if (l_strOldType != "") showRows(l_strOldType+'AddRowButtons');
    
    
    //Reset Hidden Values and show Add Row
    pHdnType.value = pType;
    pHdnID.value = "";
    //swapRows(pType+'AddRow',pType+'DisplayRow');
}
//==============================

//==== Cancel New Data Row ====
function cancelAdd(pHdnType) {
    var l_strType = pHdnType.value;
    hideRows(l_strType+'AddRow');
    showRows(l_strType+'DisplayBtnRow');
    
    if (l_strType != "") {
        hideRows(l_strType+'AddRowButtons');
    }
    pHdnType.value = '';
}
//==============================

//===========================================================================

//=========================== Delete Functions ===========================    
function toggleGroup(pElement, pForm) {  
        for (var i = 0; i < pForm.elements.length; i++) {
            var lElement = pForm.elements[i];
            if (lElement.type == 'checkbox' && lElement.name != 'selectCategory') lElement.checked = pElement.checked;       
        }
    }
 
function deleteGroup(pTitle, pPage) {  
        if (confirm("WARNING:  This will permanently delete any checked " + pTitle + " entry(s).  Continue?")) {
            document.forms[0].action = pPage
            document.forms[0].pDelete.value = "true"
            document.forms[0].method = "get"
            document.forms[0].submit();
        }
    }
   
//===========================================================================

function popupPreview(pInt) {
    alert(pInt)
    helpwin=open('preview.asp','rrnHelpWin','scrollbars=yes,width=500,height=500');
    if (helpwin.opener == null) helpwin.opener = self;
    helpwin.focus()
}


function popupHelp(filepath, size) {
	filepath = "help/" + filepath
	if (size == "small") {
	    helpwin=open(filepath,'rrnHelpWin','scrollbars=yes,width=300,height=300');
    } else {
        helpwin=open(filepath,'rrnHelpWin','scrollbars=yes,width=400,height=450');
    }
    if (helpwin.opener == null) helpwin.opener = self;
    helpwin.focus()
}
