/*
 * Begin script for CSS horizontal menu.
 */
var cssmenuids=["cssmenu1"] //Enter id(s) of CSS Horizontal UL menus, separated by commas
var csssubmenuoffset=-1 //Offset of submenus from main menu. Default is 0 pixels.

function createcssmenu2(){
for (var i=0; i<cssmenuids.length; i++){
  var ultags=document.getElementById(cssmenuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
			ultags[t].style.top=ultags[t].parentNode.offsetHeight+csssubmenuoffset+"px"
    	var spanref=document.createElement("span")
			spanref.className="arrowdiv"
			spanref.innerHTML="&nbsp;&nbsp;&nbsp;&nbsp;"
			ultags[t].parentNode.getElementsByTagName("a")[0].appendChild(spanref)
    	ultags[t].parentNode.onmouseover=function(){
    	this.getElementsByTagName("ul")[0].style.visibility="visible"
    	}
    	ultags[t].parentNode.onmouseout=function(){
			this.getElementsByTagName("ul")[0].style.visibility="hidden"
    }
    }
  }
}

if (window.addEventListener)
window.addEventListener("load", createcssmenu2, false)
else if (window.attachEvent)
window.attachEvent("onload", createcssmenu2)

/*
 * End script for CSS horizontal menu.
 */
 
/*
 * Determine if the item in the worksheet table needs a <tr>.
 *
 * Limitation: totalItemCount must be evenly divisible by tableColumnCount.
 */
function getWorksheetOpeningTableRowTag(
    horizontalNumbering, 
    itemId,
    tableColumnCount,
    totalItemCount)
{
    var tag = "";
    
    if (itemId == 1)
    {
        tag = "<tr>";
    }
    else if (tableColumnCount == 0)
    {
        // prevent divide-by-zero
    }
    else if (horizontalNumbering)
    {
       var maxIdInLastColumn = (totalItemCount / tableColumnCount) - 1;
       
       if (itemId <= maxIdInLastColumn)
       {
           tag = "<tr>";
       }
    }
    else
    {
        if ((itemId - 1) % tableColumnCount == 0)
        {
            tag = "<tr>";
        }
    }

    return tag;
}

/*
 * Determine if the item in the worksheet table needs a </tr>.
 *
 * Limitation: totalItemCount must be evenly divisible by tableColumnCount.
 */
function getWorksheetClosingTableRowTag(
    horizontalNumbering, 
    itemId,
    tableColumnCount,
    totalItemCount)
{
    var tag = "";
    
    if (itemId == totalItemCount)
    {
        tag = "</tr>";
    }
    else if (tableColumnCount == 0)
    {
        // prevent divide-by-zero
    }
    else if (horizontalNumbering)
    {
       var minIdInLastColumn = (totalItemCount - totalItemCount / tableColumnCount) + 1;
       
       if (itemId >= minIdInLastColumn)
       {
           tag = "</tr>";
       }
    }
    else
    {
       if (itemId % tableColumnCount == 0)
       {
           tag = "</tr>";
       }
    }

    return tag;
} 
 
/*
 * Avoid hard-coded email address.
 */
function getX()
{
  var x = "admin";
  x += "@";
  x += "mathta";
  x += ".com";

  return x;
}

/*
 * Ensure only integers in the textbox.
 *
 * see http://www.codingforums.com/archive/index.php?t-80091.html
 */
function integersOnly(textbox) 
{
   // enable leading minus sign
   if (textbox.value == "-")
   {
       // allow leading minus sign
   }
   else if (textbox.value != parseInt(textbox.value))
   {
       var newValue = parseInt(textbox.value);

       if (newValue + "" == "NaN" ||
           newValue == "")
       {
           newValue = 0;
       }

       textbox.value = newValue;
   }
}

/*
 * Ensure only integers or decimals in the textbox.
 */
function numbersOnly(textbox) 
{
   if (textbox.value == "" ||     // allow blank value
       textbox.value == "-" ||    // allow negative sign
       textbox.value == "-." ||   // allow negative decimal
       textbox.value == ".")      // allow leading decimal point
   {
       // NOOP
   }
   else if (textbox.value != parseFloat(textbox.value))
   {
       var newValue = parseFloat(textbox.value);

       if (newValue + "" == "NaN" ||
           newValue == "")
       {
           newValue = 0;
       }

       textbox.value = newValue;
   }
}

/*
 * Select the specified value in the dropdown box.
 */
function selectDropDownValue(controlId, value)
{
   var dropDownList = document.getElementById(controlId);
   
   if (dropDownList != null &&
       dropDownList.options != null)
   {
      for (var i = 0; i < dropDownList.options.length; i++)
      {
         if (value == dropDownList.options[i].value)
         {
            dropDownList.selectedIndex = i;
            break;
         }
      }
   }
}

/*
 * Push the value into the hidden input control.
 */
function setHiddenValue(controlId, value)
{
   var hiddenControl = document.getElementById(controlId);
   
   if (hiddenControl != null)
   {
   	  hiddenControl.value = value;
   }
}

function disableControl(controlId)
{
   var inputControl = document.getElementById(controlId);

   if (inputControl != null)
   {
      inputControl.disabled = true;
   }   
}

function enableControl(controlId)
{
   var inputControl = document.getElementById(controlId);
   
   if (inputControl != null)
   {
      inputControl.disabled = false;
   }
}

function enableAndCheckControl(controlId)
{
	var inputControl = document.getElementById(controlId);
    
    if (inputControl != null)
    {
    	inputControl.disabled = false;
    	inputControl.checked = true;
    	
    }	
}

/*
 * Enable radio buttons for selecting horizontal or vertical alignment.
 */
function enableAllExerciseAlignments()
{
	enableControl("exerciseAlignmentVertical");
	enableControl("exerciseAlignmentHorizontal");
}

/*
 * Select the radio button for horizontal alignment.
 * Disable the radio button for vertical alignment.
 */
function enforceHorizontalExerciseAlignment(exerciseAlignment)
{
	disableControl("exerciseAlignmentVertical");    
	enableAndCheckControl("exerciseAlignmentHorizontal");
	setHiddenValue("exerciseAlignment", exerciseAlignment);
}

/*
 * Select the radio button for vertical alignment.
 * Disable the radio button for horizontal alignment.
 */
function enforceVerticalExerciseAlignment(exerciseAlignment)
{
	disableControl("exerciseAlignmentHorizontal");	
	enableAndCheckControl("exerciseAlignmentVertical");
	setHiddenValue("exerciseAlignment", exerciseAlignment);
}

function hideElement(id)
{
    var element = document.getElementById(id);
    
    if (element != null)
    {
        element.style.display = "none";
    }
}

function showElement(id)
{
    var element = document.getElementById(id);
    
    if (element != null)
    {
        element.style.display = "";
    }
}

