function areYouSure(text) {
     return confirm(text);
}

function preloadPage(preloadElement, postloadElement) { 
if (document.getElementById) {
    document.getElementById(preloadElement).style.display = 'none';
    document.getElementById(postloadElement).style.display = 'block';
}
    return;
}

function setElement(element, value) {
    var theElement = document.getElementById(element);
    theElement.value = value;
    return;
}

function toggleVisibility(element, elementId) {
    var theElement = document.getElementById(element);
    if(theElement.style.display == 'none') {
        theElement.style.display = 'block';
    }
    else {
        theElement.style.display = 'none';
    }
    if(elementId != undefined)
    {
        var toggleTextObject = document.getElementById(elementId);
        //if(toggleTextObject.innerHTML == '+')
	//    toggleTextObject.innerHTML = '-';
	//else
	//    toggleTextObject.innerHTML = '+';
    }
    return;
}

/**
 * Delete all child nodes for a given Id
 */
function deleteChildNodes(Id)
{
    var parentElement = document.getElementById(Id);

    if ( parentElement.hasChildNodes() )
    {
        while ( parentElement.childNodes.length >= 1 )
        {
            parentElement.removeChild( parentElement.firstChild );       
        } 
    }
    return;
}

activateMenu = function(nav) {

    /* currentStyle restricts the Javascript to IE only */
	if (document.all && document.getElementById(nav).currentStyle) {  
        var navroot = document.getElementById(nav);
        
        /* Get all the list items within the menu */
        var lis = navroot.getElementsByTagName("LI");  
        for (i=0; i<lis.length; i++) {
        
           /* If the LI has another menu level */
            if(lis[i].lastChild.tagName=="UL"){
            
                /* assign the function to the LI */
             	lis[i].onmouseover=function() {	
                
                   /* display the inner menu */
                   this.lastChild.style.display="block";
                }
                lis[i].onmouseout=function() {                       
                   this.lastChild.style.display="none";
                }
            }
        }
    }
}

window.onload= function(){
    /* pass the function the id of the top level UL */
    /* remove one, when only using one menu */
    activateMenu('nav'); 
    /* activateMenu('vertnav'); */
}
/**
 * popup()
 * Loads up a simple popup window.
 */
function popup(url,windowName) {
    /* newwindow=window.open(url,windowName,'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=600'); */
    var newwindow = window.open(url,windowName,'toolbar=0,scrollbars=1,location=no,statusbar=0,menubar=0,resizable=1,fullscreen=no');
    if (window.focus) {newwindow.focus()}
        return false;
}
function popupsize(url,windowName,width,height) {
    newwindow=window.open(url,windowName,'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width='+width+',height='+height);
    if (window.focus) {newwindow.focus()}
        return false;
}


function selectAllCheckboxes(formName, selected)
{
    targetform = document.getElementById(formName);
    for (i = 0; i < targetform.elements.length; i++)
    {
        if (targetform.elements[i].type == "checkbox")
	{
	    targetform.elements[i].checked = selected;
	}
    }
}

function toggleCheckBoxes(formName)
{
   targetform = document.getElementById(formName);
   for (i = 0; i < targetform.elements.length; i++)
   {
     if (targetform.elements[i].type == "checkbox")
     {
       if(targetform.elements[i].checked == false)
       {
         targetform.elements[i].checked = true;
       }
       else
       {
         targetform.elements[i].checked = false;
       }
     }
   }
}

function toggleCheckBox(checkBoxId)
{
    checkBox = document.getElementById(checkBoxId);
    if(checkBox.checked == false)
    {
        checkBox.checked = true;
    }
    else
    {
        checkBox.checked = false;
    }
}

/*
function ToggleCheckBoxes(FormName, FieldName, CheckValue)
{
    if(!document.forms[FormName])
        return;
    var objCheckBoxes = document.forms[FormName].elements[FieldName];
    if(!objCheckBoxes)
        return;
    var countCheckBoxes = objCheckBoxes.length;
    if(!countCheckBoxes)
        objCheckBoxes.checked = CheckValue;
    else
        // set the check value for all check boxes
        for(var i = 0; i < countCheckBoxes; i++)
            objCheckBoxes[i].checked = CheckValue;
}
*/

function replaceMMText(text)
{
    var chrTest=text.value.charCodeAt(0);

    var chr8217=String.fromCharCode(8217);
    var chr39=String.fromCharCode(39);
    var lineIn=text.value;
    var lineOut="";

    lineOut = lineIn.replace(new RegExp(chr8217,"g"),chr39);
    text.value = lineOut;
}

function getSelectedCheckbox(buttonGroup) 
{
    // Go through all the check boxes. return an array of all the ones
    // that are selected (their position numbers). if no boxes were checked,
    // returned array will be empty (length will be zero)
    var retArr = new Array();
    var lastElement = 0;
    if (buttonGroup[0]) 
    { // if the button group is an array (one check box is not an array)
        for (var i=0; i<buttonGroup.length; i++) 
	{
	    if (buttonGroup[i].checked) 
	    {
	        retArr.length = lastElement;
		retArr[lastElement] = i;
		lastElement++;
	    }
	}
    } else { // There is only one check box (it's not an array)
	if (buttonGroup.checked) 
	{ // if the one check box is checked
	    retArr.length = lastElement;
	    retArr[lastElement] = 0; // return zero as the only array value
	}
    }
    return retArr;
} // Ends the "getSelectedCheckbox" function

function getSelectedCheckboxValue(buttonGroup) 
{
    // return an array of values selected in the check box group. if no boxes
    // were checked, returned array will be empty (length will be zero)
    var retArr = new Array(); // set up empty array for the return values
    var selectedItems = getSelectedCheckbox(buttonGroup);
    if (selectedItems.length != 0) 
    { // if there was something selected
        retArr.length = selectedItems.length;
	for (var i=0; i<selectedItems.length; i++) 
	{
	    if (buttonGroup[selectedItems[i]]) 
	    { // Make sure it's an array
	        retArr[i] = buttonGroup[selectedItems[i]].value;
	    } else { // It's not an array (there's just one check box and it's selected)
	        retArr[i] = buttonGroup.value;// return that value
	    }
	}
    }
    return retArr;
} // Ends the "getSelectedCheckBoxValue" function

