var pTimeout;
var oElements;
var lastMenu;

//Used to show/hide submenus
function setMenu(MenuNbr,CellName,OnOff){
        //hide if prior menu open
        if(lastMenu){
            var oLast = document.getElementById(lastMenu);
            var oALast= oLast.childNodes[0];
            oLast.className ="topMenuItemOff";
            oALast.className = oLast.className;
        }
        //clear all the subs
        clearIFrames();
        if(CellName){
            var oParent = document.getElementById(CellName);
            var oChild = oParent.childNodes[0];
            oParent.className = (OnOff==1)?"topMenuItemOn":"topMenuItemOff";
            oChild.className = oParent.className;
            lastMenu = CellName;
            if(!eval(oElements[MenuNbr])){
                return false;
            }
            oParent.className = (OnOff==1)?"topMenuItemOn":"topMenuItemOff";
            oChild.className = oParent.className;
            oElements[MenuNbr].className=(OnOff==1)?"subMenuOn":"subMenuOff";
        }
        return false;
}


//oElements defined in main page that uses this file
function clearIFrames(){
    if(oElements){
	for(var i=0;i<oElements.length;i++){
		oElements[i].className="subMenuOff";
	}
    }
	return true;
}

//Used for the image rollovers
//assumes gif type image
function swapThis(imgObj, imgFlag){
    var oImg = document.getElementById(imgObj);
    var sTmp = oImg.src;
    var re = (imgFlag)?/.gif/:/_over.gif/;
    var nTmp = (imgFlag)?'_over.gif':'.gif';
    sTmp = sTmp.replace(re,nTmp);
    oImg.src = sTmp;
    return false;
}

//Used by the tr to close rows in Grid Tables
function showorhide(var1){
	var oTR = document.getElementById(var1);
	var sName = oTR.className;
        oTR.className=(sName=="row_off")?"row_on":"row_off";
	return false;
}

//Used to change a row and possibly a link's style
//Used on sub menu items
function setRow(CellID,OnOff){
	var oTD = document.getElementById(CellID);
        var sTmp = oTD.className
        var re = (OnOff==1)?/_off/:/_on/;
        var nTmp = (OnOff==1)?'_on':'_off';
        sTmp = sTmp.replace(re,nTmp);
        oTD.className = sTmp;
        if(oTD.childNodes.length){
            var oChild = oTD.childNodes[0];
            if(oChild.nodeType==1){
                oChild.className=sTmp;
            }
        }
        return true;
}

//Used to change a row and possibly a link's style
//Used on the grid tables
function setGridRow(RowID,OnOff){
	var oTR = document.getElementById(RowID);
        if(oTR.childNodes.length){
            for(var i=0;i<oTR.childNodes.length;i++){
                var oChild = oTR.childNodes[i];
                if(oChild.nodeType==1 && oChild.id!="notCell"){
                    var sTmp = oChild.className
                    var re = (OnOff==1)?/_off/:/_on/;
                    var nTmp = (OnOff==1)?'_on':'_off';
                    sTmp = sTmp.replace(re,nTmp);
                    oChild.className = sTmp;
                }   
            }
        }
        return true;
}

//Submit Form
function sendForm(formName){
	if(eval(document.forms[formName])){
		document.forms[formName].submit();
	}
	return false;
}



function openWindow(Page,SearchString,Title,WidthSize,HeightSize){
    toolBar = (window.print)?'no':'yes';
    winObj=window.open(Page+SearchString,Title,'location=no,toolbar='+toolBar+',statusbar=yes,height='+HeightSize+',width='+WidthSize+',scrollbars=yes,resizable=yes');
    return false;
}

function goPage(NewLocation){
    self.location=NewLocation;
    return false;
}

function printPage() { 
         if (window.print) { 
                 window.print(); 
         } 
         else if(navigator.appVersion.indexOf("Mac")!=-1){ 
                alert("Your system does not support this function. Use the 'print' button from your browser."); 
         } 
        else{   
                alert("Your system does not support this function. Use the 'print' button from your browser."); 
         } 
         return false; 
}

function setClient(CID, CName){
    oForm = document.forms["main"];
    oForm.clientId.value=CID;
    oForm.clientName.value=CName;
    oForm.submit();
    return false;
}

function setProgram(){
    oForm = document.forms["main"];
    oElement=oForm.progId;
    oForm.pid.value=oElement.value;
    oForm.pname.value=oElement.options[oElement.selectedIndex].text;
    oForm.submit();
    return false;
}

function setDate(DateMon){
        oForm = document.forms["main"];
        oForm.apptDate.value=DateMon;
        oForm.submit();
        return false;
}

//Used to change a td cell and possibly a link's style
//Used on the grid tables
function setCell(CellID,OnOff){
	var oTD = document.getElementById(CellID);
	var sTmp=oTD.className;
    var re = (OnOff==1)?/_off/:/_on/;
    var nTmp = (OnOff==1)?'_on':'_off';
     sTmp = sTmp.replace(re,nTmp);
     oTD.className=sTmp;
        if(oTD.childNodes.length){
            for(var i=0;i<oTD.childNodes.length;i++){
                var oChild = oTD.childNodes[i];
                if(oChild.nodeType==1 && oChild.id!="notCell"){
                    sTmp = oChild.className
                    re = (OnOff==1)?/_off/:/_on/;
                    nTmp = (OnOff==1)?'_on':'_off';
                    sTmp = sTmp.replace(re,nTmp);
                    oChild.className = sTmp;
                }   
            }
        }
        return true;
}