<!--

function sortTable(tableName, startRow, skip, column, lastColum, lastOrder) {
    if (!document.getElementById)
        return false;

    var table = document.getElementById(tableName);
    var numOfRows = (table.rows.length - startRow)/skip;
    var columnNames = new Array(numOfRows);
    var columnNamesMap = new Array(numOfRows);
    for (i = 0; i < numOfRows; i++) {
        rowIndex = startRow + (i*skip);
        row = table.rows[rowIndex];
        value = row.cells[column].innerHTML;
        value = value.replace(/<[^>]*>/g, '');
        columnNames[i] = value;
        columnNamesMap[columnNames[i]] = table.rows[rowIndex];
   }

   if (lastColumn == column) {
       lastOrder = 1 - lastOrder;
       order = lastOrder;
   }
   else {
       order = 0;
       lastOrder = 0;
   }
     

   columnNames.sort();
   var allRows = new Array(table.rows.length - startRow + 1);
   for (i = startRow; i < table.rows.length; i++) {
       allRows[i-startRow] = table.rows[i];
   }


   for (i = 0; i < numOfRows; i++) {
       rowIndex = startRow + (i*skip);
       j = i;
       if (lastOrder == 1)
          j = numOfRows - j - 1;
       newRowIndex = columnNamesMap[columnNames[j]];
       alert("row[" + newRowIndex + "]=" + table.rows[newRowIndex]);
       allRows[rowIndex] = columnNamesMap[columnNames[j]];
   }

   for (i = startRow; i < table.rows.length; i++) {
       table.deleteRow(i);
   }

   for (i = 0; i < allRows.length; i++) {
       alert("allRows[" + i + "]:" + allRows[i]);
       table.appendChild(allRows[i]);
   }

}

function calculateTotal() {
    total = 0;
    for (i = 0; i < amounts.length; i++) {
        total += amounts[i];
    }
    document.forms[0].total.value = total;
}


function updateTotal(input, i) {
    value = input.value;
    amount = 0;
    if (trimString(value) != "") {
        amount = parseFloat(value);
        if (isNaN(amount) || amount <= 0) {
            alert("Invalid input amount!");
            input.value = "";
            input.focus();
            return false;
        }
    }

    amounts[i] = amount;
    calculateTotal();
}


function changeTitleToEdit() {
    if (document.getElementById) {
        var title = document.getElementById('title');
        title.innerHTML = titleEdit;
        document.forms[0].method.value = "update";
    }
}


function changeTitleToNew() {
    if (document.getElementById) {
        var title = document.getElementById('title');
        title.innerHTML = titleNew;
        document.forms[0].method.value = "create";
    }
}


function protectTextInput()
{
   this.blur();
   return false;
}


function protectRadioButton()
{
    var buttons = document.forms[0].elements[this.name];
    for (var i = 0; i < buttons.length; i++) {
        if (buttons[i].defaultChecked == true) {
            buttons[i].checked = true;
        }
        else
            buttons[i].checked = false;
          
    } 
    return false;
}

function protectSelect()
{
    for (var i = 0; i < this.options.length; i++)
    {
        this.options[i].selected = this.options[i].frozenStatus;
    }
    return false;
}


function initPageForProtection() {
    var protectedElements = new Array();
    var elements = document.forms[0].protectedElements.value;
    if (trimString(elements) == "")
        return;
    var i = elements.indexOf(",");
    var pos = 0;
    while (i >= 0) {
        protectedElements[pos] = elements.substring(0, i);
        elements = elements.substring(i+1);
        i = elements.indexOf(",")
        pos++;
    }
    protectedElements[pos] = elements;
    initElements(protectedElements);
    return false;
}


function protectElement(ele) {
    if (ele == undefined)
        return;
    if (ele.type.substr(0,6) == "select") {
        for (var j = 0; j < ele.options.length; j++){
            ele.options[j].frozenStatus = ele.options[j].selected
        }
        ele.onchange = protectSelect;
        ele.onclick = protectSelect;
        ele.onkeyup = protectSelect;
    }
    else if (ele.type.substr(0,5) == "radio") {
        ele.onclick = protectRadioButton;
    }
    else if (ele.type.substr(0,4) == "text") {
        ele.onclick = protectTextInput;
        ele.onkeypress = doNothing;
    }
    else if (ele.type.substr(0,8) == "textarea") {
        ele.onclick = protectTextInput;
        ele.onkeypress = doNothing;
    }
    else if (ele.type.substr(0,8) == "checkbox") {
        ele.onclick = protectTextInput;
    }
}



function initElements(protectedElements)
{

    var first = protectedElements[0];
    if (first == "_all_") {
        for (var i = 0; i < document.forms[0].elements.length; i++) {
            var obj = document.forms[0].elements[i];
            var found = false;
            for (var j = 1; j < protectedElements.length; j++) {
                if (obj.name == protectedElements[j]) {
                    found = true;
                    break;
                }
            }
            if (found == false) {
                protectElement(obj);
            }
        }
    }
    else {
        for (var i = 0; i < protectedElements.length; i++) {
            var obj = document.forms[0].elements[protectedElements[i]];
            protectElement(obj);
        }
    }
}





function protect(field)
{
	mode = document.forms[0].method.value;
	if(mode != 'create')
	{
		protectedFields = document.forms[0].protectedFields.value;
		if(document.forms[0].fieldOnFocus && (protectedFields.indexOf(field.name) >= 0))
		{
			selectedField = document.forms[0]['fieldOnFocus'].value;
			//alert(selectedField);
			
			document.forms[0][selectedField].focus();
			document.forms[0][selectedField].select();
//			document.forms[0][document.forms[0].fieldOnFocus.value].focus();
		}
	}
	return false;
}

function doSave()
{
	document.forms[0].submit();
	return false;
}

function doReset()
{
	document.forms[0].reset();
	return false;
}

function doResetSubmit(){
	document.forms[0].method.value="reset";
	document.forms[0].submit();
	return false;
}

function doAddCourseSectionComment(anchorName)
{ 
	document.forms[0].courseSectionProfilePageDisplayed.value = "addComment";
  document.forms[0].anchor.value = anchorName;   
	document.forms[0].method.value = "addComment";

	document.forms[0].submit();

	return false;
}

  function addEnrollmentRestriction(anchorName) {
      var form = document.forms[0];
      form.anchor.value = anchorName;   
      form.method.value = "addEnrollmentRestriction";
      form.submit();
  
      return false;
  }
  
  
  function editEnrollmentRestriction(restrictionIndex, anchorName) {
      var form = document.forms[0];
      form.anchor.value = anchorName;
      form.method.value = "editEnrollmentRestriction";
      form.restrictionIndex.value = restrictionIndex;
      form.submit();
  
      return false;
  }
  
  function deleteEnrollmentRestriction(restrictionIndex, anchorName) {
      var form = document.forms[0];
      form.anchor.value = anchorName;    
      form.method.value = "removeEnrollmentRestriction";
      form.restrictionIndex.value = restrictionIndex;
      form.submit();
  
      return false;
  }

function doRemoveCourseSectionComment(commentIdx, anchorName)
{
	document.forms[0].courseSectionProfilePageDisplayed.value = "removeComment";
	document.forms[0].method.value = "removeComment";
  document.forms[0].anchor.value = anchorName;   
  document.forms[0].commentIndex.value = commentIdx;

	document.forms[0].submit();

	return false;
}

function doAddCourseSectionSchedule()
{
	document.forms[0].courseSectionProfilePageDisplayed.value = "addSchedule";
	document.forms[0].method.value = "addSchedule";

	document.forms[0].submit();

	return false;

}

function doEditCourseSectionSchedule(scheduleIdx)
{
	document.forms[0].courseSectionProfilePageDisplayed.value = "editSchedule";
	document.forms[0].method.value = "editSchedule";
        document.forms[0].scheduleIndex.value = scheduleIdx;

	document.forms[0].submit();

	return false;
}

function doCancelCourseSectionSchedule()
{
	document.forms[0].courseSectionProfilePageDisplayed.value = "cancelSchedule";
	document.forms[0].method.value = "cancelSchedule";

	document.forms[0].submit();

	return false;
}

function doRemoveCourseSectionSchedule(scheduleIdx)
{
	document.forms[0].courseSectionProfilePageDisplayed.value = "removeSchedule";
	document.forms[0].method.value = "removeSchedule";
        document.forms[0].scheduleIndex.value = scheduleIdx;

	document.forms[0].submit();

	return false;
}

function doSearchForCourses()
{
	document.forms[0].method.value = "search";
	document.forms[0].action = document.forms[0].action + "#results";
	document.forms[0].submit();

	return false;

}
/*
function doRegisterForCourse(cspIndex)
{
	document.forms[0].method.value = "registerForCourse";
        document.forms[0].cspIndex.value = cspIndex;
	document.forms[0].submit();

	return false;

}

function doWaitlistForCourse(cspIndex)
{
	document.forms[0].method.value = "waitlistForCourse";
        document.forms[0].cspIndex.value = cspIndex;
	document.forms[0].submit();

	return false;

}

function doOverrideAndRegisterForCourse(cspIndex)
{
//alert("doOverrideAndRegisterForCourse" + cspIndex);
	document.forms[0].method.value = "overrideAndRegisterForCourse";
        document.forms[0].cspIndex.value = cspIndex;
	document.forms[0].submit();

	return false;

}

function doRemoveFromTransactionBasket(form,courseSectionInfoIndex, studentId, activityCode)
{

	form.method.value = "removeFromTransactionBasket";
	form.csiIndex.value = courseSectionInfoIndex;
	form.csiStudentId.value = studentId;
	form.csiActivityCode.value = activityCode;

	form.submit();

	return false;
}

function doRemoveSpecialRequestFromTransactionBasket(srPosition)
{
    document.forms[0].method.value = "removeFromTransactionBasket";
    document.forms[0].srPosition.value = srPosition;
    document.forms[0].csiIndex.value = "-1";
    // alert(document.forms[0].srPosition.value);
    document.forms[0].submit();

    return false;
}


function doCalculateSelectedCourses(form)
{
	form.method.value = "calculate";
	form.submit();

	return false;

}
*/
function doOptimize()
{
	document.forms[0].method.value = "optimize";
	document.forms[0].submit();

	return false;

}

function doAddNewSectionBasedOnCopy(url)
{

	if (document.forms[0].sectionId.length) {
   		for (var i = 0; i < document.forms[0].sectionId.length; i++) {
			if (document.forms[0].sectionId[i].checked) { 
		    	sectionId = document.forms[0].sectionId[i].value       
			}   
		}
	}
	else {
		sectionId = document.forms[0].sectionId.value;       
	}
   
	var concaturl = url + "&" + "sectionId=" + sectionId;

	document.location = concaturl;

	return false;
}



function trimString (str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}


function clearcombo(combo)
{
	for (var i=combo.options.length-1; i>=0; i--)
	{
		combo.options[i] = null;
	}
	combo.selectedIndex = -1;
}

function clearcombo(combo, allButThisIndex)
{
	for (var i=combo.options.length-1; i>=0; i--)
	{
		if(i != allButThisIndex)
		{
			combo.options[i] = null;
		}
	}
	combo.selectedIndex = -1;
}

function addOption(combo, label, value)
{
	lastIndex = combo.options.length;
	combo.options[lastIndex] = new Option(label, value);
}

function lockForm(form, lock)
{

if(lock)
	for(i=0; i<form.length; i++)
	{
		if(lock)
		{
			form[i].onclick = disableField;
//			form[i].onfocus = disableField;
		}
		else
		{
			form[i].onfocus = null; // we don't restore handlers for now
			form[i].onclick = null;
		}
	}
}

function disableField()
{
	this.blur();
	return false;
}

function doNothing(){

}


function decimalFormat(aField, formatNonNumber)
{
	var wd="w";
	var tempnum = aField.value;
	if(isNaN(tempnum) || (tempnum == ''))
	{

		if (formatNonNumber == undefined) {
                     tempnum = 0;
                }
                else
		     return;
	}
	for (i=0;i<tempnum.length;i++)
	{
		if (tempnum.charAt(i) == ".")
		{
			wd="d"
			break
		}
	}
	if (wd == "w")
	{
		aField.value = tempnum + ".00"
	}
	else
	{
		if (tempnum.charAt(tempnum.length-3) == ".")
                {
                       return;
                }
		if (tempnum.charAt(tempnum.length-2) == ".")
		{
			aField.value = tempnum + "0"
		}
		else
		{
			tempnum = Math.round(tempnum * 100)/100;
                        if (tempnum == 0) {
                            aField.value = "0.00";
                        }
                        else if ((tempnum + "").charAt(tempnum.length-2) == ".") {
		            aField.value = tempnum + "0";
                        }
                        else
                            aField.value = tempnum + "";
		}
	}
}

function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g,'');
    if (isNaN(num))
        num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if (cents < 10)
    cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
        num = num.substring(0,num.length-(4*i+3))+','+
            num.substring(num.length-(4*i+3));
   return (((sign)?'':'-') +  num + '.' + cents);
}


var allcostingUnits;
var allValues = {};

function changeSelection1(sourceSelection, dependentSelection) {
    mainForm = document.forms[0];
    source = mainForm[sourceSelection]; 

    var cvValue = null;

    // Save all the initial options contained in the dependentSelection box.
    //
    if (allValues[dependentSelection] == null) {
         var oldOptions = mainForm[dependentSelection].options;
         allValues[dependentSelection] = new Array();
         for (i = 0; i < oldOptions.length; i++) {
             //allValues[i] = oldOptions[i];
	     allValues[dependentSelection][i] =
		new Option(oldOptions[i].text, oldOptions[i].value, false, oldOptions[i].selected );
             allValues[dependentSelection][i].selected = oldOptions[i].selected;
         }
    }

    currentSourceValue = source.options[source.selectedIndex].value;
    dependentValues = eval(sourceSelection + "_" + dependentSelection +  "_mapping['" + currentSourceValue + "']");
    var options = mainForm[dependentSelection].options;
    numOfOptions = options.length;
    for (i = numOfOptions-1; i >= 0; i--) {
        options[i] = null;
    }

    if (dependentValues==null || dependentValues.length == 0) {
        options[0] = new Option("                               ", '-1', false, false);
        options[0].selected = false;
        return;
    }

    var n = 0;
    for (i = 0; i < allValues[dependentSelection].length; i++) {
        cv = allValues[dependentSelection][i];
        for (j = 0; j < dependentValues.length; j++) {
            dv = dependentValues[j];
            if (dv == cv.value) {
                options[n] = new Option(cv.text, cv.value, false, cv.selected);
                options[n].selected = cv.selected;
                n++;
                break;
            } 
        }
    }

}


function submitFormWithAnchor(form, anchor) {
    form.action = form.action + '#' + anchor;
    form.submit();
    return false;
}

function submitMethod(method, formElement) {
  theForm=document.forms[0];
  if (formElement!=null) {
    theForm = formElement;
  }
  theForm.method.value=method;
  theForm.submit();

  return false;
}

function checkForAnchors(error) {

  if (document.forms[0].anchor!=null) {
    if (error==false) {
      if (document.forms[0].anchor.value!="") {

        document.location.hash=document.forms[0].anchor.value;
      }
    }
    document.forms[0].anchor.value="";
  }
}

function addStyleSheets(elementVar) {
  return (elementVar.value);
}

function replaceQuotes(quoteStr) {
  quoteStr = quoteStr.replace(/\u2019/gi,"&#39;").replace(/\u2018/gi,"&#39;")
  return quoteStr;
}

function notAvailable() {
  alert('This functionality is not currently available.');
  return false;
}
function doSubmit(formName) {
    var form = document.forms[formName];
    form.submit();
    return false;
}
function doSubmit(formName, methodName) {
	var form = document.forms[formName];

    form.method.value = methodName;
    form.submit();

    return false;
}

function doSubmitMethodWithForm(form, methodName) {
    form.method.value = methodName;
    form.submit();

    return false;
}

function doSubmitAnchor(form, value, anchorValue) {

  form.anchor.value = anchorValue;

  return doSubmit(form.name, value)
}

function doSubmitWithVariable(form, value, variable, variableValue)
{
	form.method.value = value;
	form[variable].value = variableValue;
	form.submit();
	return false;
}

function doRemoveItem(form, method, removeId) {

  form.anchor.value = method;
  form.method.value = method;
  form.removeId.value=removeId;
  form.submit();

  return false;
}

function doRemoveItem(form, method, removeId, anchorVal) {

  form.anchor.value = anchorVal;
  form.method.value = method;
  form.removeId.value=removeId;
  form.submit();

  return false;
}


//-->

