function addAnItemToSelect(anItem, ListBox, FormName) {
    var Selectobj = eval(FormName + "." + ListBox) ;
    var newElem = document.createElement("OPTION");
    newElem.text = anItem;
    newElem.value = anItem;

    Selectobj.options.add(newElem);
}

function addAnItemToSelectValueDifferent(aValue, anItem, ListBox, FormName) {
    var Selectobj = eval(FormName + "." + ListBox) ;
    var newElem = document.createElement("OPTION");
    newElem.text = anItem;
    newElem.value = aValue;

    Selectobj.options.add(newElem);
}


function addAnItemToSelectDifValue(anItem, aValue, ListBox, FormName) {
    var Selectobj = eval(FormName + "." + ListBox) ;
    var newElem = document.createElement("OPTION");
    newElem.text = anItem;
    newElem.value = aValue;

    Selectobj.options.add(newElem);
}


function LoadArrayIntoSelect(anArray, ListBox, FormName) {
    var Selectobj = eval(FormName + "." + ListBox) ;
    for(G=0; G < anArray.length; G++) {
        addAnItemToSelect(anArray[G], ListBox, FormName);
    }
}

function NoDuplicateInListBox(anArray, ListBox, FormName) {

    var Selectobj = eval(FormName + "." + ListBox) ;
    Q = anArray.length;
    for(Z = 0;Z < Q; Z++) {
        found = "N";
        for(L=0; L < Selectobj.length; L++) {
            if(Selectobj(L).value == anArray[Z]) {
                found = "Y";
                break;
            }
        }
        if(found == "N") {
            addAnItemToSelect(anArray[Z], ListBox, FormName)
        }
    }
    
}

function NoDuplicateInListBoxOneItem(anItem, ListBox, FormName) {

    var Selectobj = eval(FormName + "." + ListBox) ;
    found = "N";
    for(L=0; L < Selectobj.length; L++) {
        if(Selectobj(L).value == anItem) {
            found = "Y";
            break;
        }
    }
    if(found == "N") {
        addAnItemToSelect(anItem, ListBox, FormName)
    }
    
}

function writeToText(TextBox, ListBox, FormName){
    var Textobj = eval(FormName + "." + TextBox);
    var Selectobj = eval(FormName + "." + ListBox) ;
    Textobj.value = Selectobj.options[Selectobj.selectedIndex].value;
}

function OverIt(atd) {
    ColorItWas = atd.bgColor;
    atd.bgColor = "red";
}

function OffIt(atd) {
    atd.bgColor = ColorItWas;
}

function CloseAllDiv(aDiv, SpanList, theFormName) {
    tempDiv = aDiv;
    for(x=0; x < SpanList.length; x++) {
        DivShow("none", SpanList[x], theFormName);
    }
    
    if(aDiv != "") DivShow("", aDiv, theFormName);
}

function DivShow(YN, theDiv, theFormName) {
    aDiv = eval(theFormName + ".all." + theDiv);
    aDiv.style.display = YN;
}

function DivLeftTop(LeftAmount, TopAmount, theDiv, theFormName) {
    aDiv = eval(theFormName + ".all." + theDiv);
    aDiv.style.left = LeftAmount;
    aDiv.style.top = TopAmount;
}

function DivHeightWidth(HeightAmount, WidthAmount, theDiv, theFormName) {
    aDiv = eval(theFormName + ".all." + theDiv);
    aDiv.style.height = HeightAmount;
    aDiv.style.width = WidthAmount;
}


function ClickIt(atd, FormName) {
    IsAllowed = false;
    var aDiv;
    var divId = new String(atd.id);
    aDiv = eval(FormName + ".all." + divId);
//    Validate(); 
    if(IsAllowed == false) {
 //       ValidateForm();
    }
    else {
        atd.bgColor = "blue";
        ColorItWas = atd.bgColor;
        for(X=0; X < aDiv.length; X++) {
            if(atd.title != aDiv(X).title ) {
                if((aDiv(X).title == "Report" && IsAllowed == false) || (aDiv(X).title == "Calculate" && IsAllowed == false) || (aDiv(X).title == "Save" && IsAllowed == false)) {
                     aDiv(X).bgColor = "#cccccc";
                }
                else {
                    aDiv(X).bgColor = "gray";
                }
            }
        }
    }

}

function PopRow(R, FormName, TextBoxName) {
    EditableRow = R;
    theTextbox = eval(FormName + "." + TextBoxName);
    theTextbox.value = R + 1;
}
    
function checkKey(){
   if ( window.event.keyCode > 57 || window.event.keyCode < 45 || window.event.keyCode == 47 ) {
      //alert("Please enter only digits in this box")
      window.event.returnValue=false
   }
}
    
function checkKeyT(){
   if ( window.event.keyCode == 47 || window.event.keyCode == 38 || window.event.keyCode == 34 || window.event.keyCode == 39 || window.event.keyCode == 43){
	  window.event.returnValue=false;
   }
}

function checkKeyD(){
   if ( window.event.keyCode > 57 || window.event.keyCode < 45) {
	  window.event.returnValue=false;
   }
}

