/*******************************************************************
						Function Index
********************************************************************
1.) function Rtrim(thestr)
2.) function errNumeric(formField,fieldLabel, min, max, len, noBlank, round, showalert)
		- check field for numeric, alert them or return error, round
3.) function errNumPunc(formField,fieldLabel,delims,numdigits,showalert)
		- Checks a field for numbers and punctuation. Allows user to specify the punctuation 
		and required length
4.) function dollarFormat(expr)
5.) function decimalFormat(expr, decplaces)
6.) function getRadioIndex(buttonGroup)
		- returns the index of the selected radio button (ex: getRadioIndex(this.form.active_ind))
7.) function getRadioValue(buttonGroup)
		- returns the value of the selected radio button (ex: getRadioValue(this.form.active_ind))
8.) function getRadioValues(buttonGroup)
		- returns comma delim list of all values within the radio button group 
		(ex: getRadioValues(this.form.active_ind))
9.) function confirmButton(buttonGroup,prevvalue_field,confirmStr)
10.) function setRadioButton(buttonGroup,theValue)
11.) function isInteger (s)
12.) function isYear (s)
		- isYear returns true if string s is a valid Year number.  Must be 4 digits only.
13.) function isIntegerInRange (s, a, b)
		- isIntegerInRange returns true if string s is an integer within the range of integer arguments a and b, inclusive.
14.) function isMonth (s)
		- isMonth returns true if string s is a valid month number between 1 and 12.
15.) function isDay (s)
		- isDay returns true if string s is a valid day number between 1 and 31.
16.) function daysInFebruary (year)
		- daysInFebruary (INTEGER year) returns number of days in February of that year.
17.) function isDate (year, month, day, fieldLabel, noBlank, showalert)
		- isDate checks if string arguments year, month, and day form a valid date.  Error string returned with/out data.
18.) function errDate(thefield, fieldLabel, noBlank, showalert)
19.) function CompareDates(firstDate, secondDate)
		- Compares two dates in format 01/01/1999 and returns -1 if first one less, 0 if same, 
		and 1 if second greater.  Assumes that dates have already been validated
		if firstDate < secondDate function returns the number of years as negative
20.) function errCompareDates(firstDate, secondDate)
		- Compares two dates in format 01/01/1999 and returns -1 if first one less, 0 if same, 
		and 1 if second greater.  Returns -999 if firstDate has error, +999 if second has error
		if firstDate < secondDate function returns the number of years as negative
21.) function GetPickList(thelist)
		- GetPickList returns the value from a single selection SELECT list
22.) function GetPickListText(thelist)
		- GetPickListText returns the Text from a single selection SELECT list
23.) function ItemSelected(thelist)
		- Check to see if the default item is selected
24.) function setPickList(thelist, thevalue)
		- Sets specific value in list
25.) function setPickListMulti(thelist, thevalue)
		- Sets specific value in list
26.) function setPickListLike(thelist, thevalue)
		- Sets similar value in list used in places like quick fill 
27.) function setPickListLikeMulti(thelist, thevalue)
		- Sets similar value in list
28.) function GetPickListMulti(thelist)
		- Returns comma delimited list of values from a MULTI-Select box 
29.) function GetPickListMultiQuoted(thelist)
		- Returns QUOTED comma delimited list of values from a MULTI-Select box 
30.) function GetPickListTextMulti(thelist)
		- Returns comma delimited list of text from a MULTI-Select box 
31.) function RemovePickListMulti(thelist)
		- Removes all selected options from a MULTI-Select box 
32.) function MovePickListMulti(fromlist,tolist)
		- Moves options FROM a multi Select box to another 
33.) function GetPickListMultiAll(thelist)
		- Returns comma delimited list of ALL values from a MULTI-Select box 
34.) function GetPickListTextMultiAll(thelist)
		- Returns comma delimited list of ALL text from a MULTI-Select box 
35.) function checkbox_check_all() 
		- Check all checkboxs on the page
36.) function checkbox_un_check_all()
		- Un-check all checkboxs on the page
37.) function checkbox_check_all_v2(form, startwith) 
		- Check all checkboxs on the page who's ids start with 'startwith'
38.) function checkbox_un_check_all_v2(form, startwith)
		- Un-check all checkboxs on the page who's ids start with 'startwith'
39.) function make_textarea_larger(objName, icols, irows)
		- for a textarea, pass in the number of cols and rows you want to increase by
40.) function getCheckBoxValues(form, btn_name)
		- returns comm delimited list of all values from textboxes
41.) function IsNumeric(sText)
42.) function loading(text, color, load_height, load_width)
		- displays a loading window in the center of the screen with color being the border color
43.) function fakeAJAX([serverscript],[function], [var1], [var2], [var3],...)
		- emulates AJAX by calling a server side script in a hidden IFRAME and then calling a javascript function after the serverside script is complete.
		- serverscript: the file that will be loaded on the server.  Use /fakeAJAX_temp.asp as a template
		- function: the name of the function that will be called when the server is finished (do not use parenthesis)
		- var1, var2, var3: will be sent along with the fakeAJAX return value when "function" is called. (Ex: tempFunct(returnVal, var1, var2, var3))
44.) object BrowserDetect
		- Used for pulling the browser, version, and OS off of the client: BrowserDetect.browser, BrowserDetect.version, BrowserDectect.OS
44.) function getIndex(field)
		- returns a integer value that can be used in the form.elements collection to reference "field"
45.) function moveUpDown(e, currentField)
		- used to move up and down columns of fields named <field_name>_<id> with arrow keys.
		- to use place 'onKeyDown="moveUpDown(event, this);"' into every field you wish the action to be fired
		- Note: requires getIndex(field)
		- Note: this function disables any normal function of the up and down arrow keys for the input field in question. For instance select boxes!!
	

*******************************************************************
*******************************************************************/
function OpenTechPaths(Target)
{
	self.location = "/external/from_pt_2_techpaths.asp?Target=" + Target
}
function OpenTechPathsMap(go_to_courseid)
{
	self.location = "/external/from_pt_2_techpaths.asp?go_to_courseid=" + go_to_courseid;
}
function OpenTechPathsMap_report_popup(go_to_class_map_id)
{
	var win_location;
	win_location = "/external/from_pt_2_techpaths.asp?Target=view_map_report&go_to_class_map_id=" + go_to_class_map_id;
	/*	this shows how to open a resizable window 
			of a particular height and width, 
			with a defined offset from the top and left, 
			displaying the status, menubar and location showing:
	*/
	//sessionwin = window.open(win_location,"newwindow","height=400,width=800,left=50,top=50,resizable,scrollbars,status,menubar,location,toolbar,copyhistory,directories")
	sessionwin = window.open(win_location, '_blank','resizable=yes, scrollbars=yes, status=yes, menubar=yes');
	if(sessionwin) {
		sessionwin.focus();
	}
}
function OpenWindow(vNewWin, url) 
{
	var win_location;
	var NewWinInd;
	NewWinInd = vNewWin;
	//NewWinInd = 1 //for right now always open a new window, until the link finally works
	win_location = url;
	if (NewWinInd == 1) {
		/*	this shows how to open a resizable window 
				of a particular height and width, 
				with a defined offset from the top and left, 
				displaying the status, menubar and location showing:
		*/
		//sessionwin = window.open(url,"newwindow","height=400,width=800,left=50,top=50,resizable,scrollbars,status,menubar,location,toolbar,copyhistory,directories")
		sessionwin = window.open(win_location, '_blank','resizable=yes, scrollbars=yes, status=yes, menubar=yes');
		if(sessionwin) {
			sessionwin.focus();
		}
	}
	else {
		self.location = win_location;
	}
}
function windowpopup_view_cb_question(cb_question_id, assessment_question_id)
{
	/*	
	If you don't have an assessment_question_id, pass empty string
	*/
	var url;
		url = "/content_builder/question_view_popup.asp?cb_question_id=" + cb_question_id + "&assessment_question_id=" + assessment_question_id;
	//sessionwin = window.open(url,"newwindow","height=400,width=800,left=50,top=50,resizable,scrollbars,status,menubar,location,toolbar,copyhistory,directories")
	//sessionwin = window.open(url,"newwindow","height=250,width=450,left=50,top=50,resizable,scrollbars")
	sessionwin = window.open(url,"newwindow","height=400,width=500,left=50,top=50,resizable,scrollbars")
	// this shows how to refocus on the above window (so that we don't continuously open new windows)
	if(sessionwin){
		sessionwin.focus();
	}
}

function Rtrim(thestr){
	var cont = true;
	while (cont){
		trailing = thestr.substring(thestr.length-1,thestr.length);
		// if last char is a space, strip it off and continue testing the last space 
		if(trailing==" "){
			thestr = thestr.substring(0,thestr.length-1);
		}
		else{
			cont = false;
		}
	}
	return thestr;
}



/*******************************************************************
*                 NUMERIC CHECKS                                   *
*                                                                  *
*                                                                  *
*******************************************************************/

// check field for numeric, alert them or return error, round
function errNumeric(formField,fieldLabel, min, max, len, noBlank, round, showalert) {
// numeric field check
    var errorStr = ""
    var numcomma = 0;
	var notanum = false;
	if(formField.value.length > 0)
	{
		notanum = isNaN(parseFloat(formField.value));
		//alert("parseFloat(formField.value) = " + parseFloat(formField.value));
		//alert("isNaN(formField.value) = " + isNaN(formField.value));
	}
	if(notanum){
		errorStr += fieldLabel + " is not a number.\n";
		// rich added to return the error
		if (showalert){
			alert(errorStr);
		}
		else{
		  return errorStr;
		}
	}
	
    // no blanks & if length is 0, then just return
    if (formField.value.length == 0) {
	if (noBlank == true) {
        errorStr += fieldLabel + " cannot be blank.\n"
        if (showalert == true) 
		alert(errorStr);
	  return errorStr
	}
	else {
		return errorStr;
	}
    }
    // if field ends in period, truncate
    var vlength = formField.value.length;
    if (formField.value.substring(vlength-1,vlength) == '.') {
        formField.value = formField.value.substring(0,vlength-1);
    }
    // field must be numeric or comma or period
    for (var i = 0; i < formField.value.length; i++) {
        var ch = formField.value.substring(i, i + 1)
        if (ch == ",")
           numcomma++

        if ((ch < "0" || ch > "9") && (ch != ",") && (ch != ".") && (ch != "-")) {
           errorStr += fieldLabel + " must be numeric.\n"
           if (showalert == true) 
		   alert(errorStr);
           return errorStr
        }
    }
    // add rounding back to number
    if (round == true) {
	    // Check for decimal and round value past decimal
	    var decindex = formField.value.lastIndexOf(".");
	    var dec=0;
          var left = '0';
	    if (decindex > -1) {
	      // if number in front of decimal
            if (decindex > 0) { 
 	         left = formField.value.substring(0,decindex);
            }
	      dec = 0 + Math.round(formField.value.substring(decindex,formField.value.length));
    	    }
    	    else
    	      left = formField.value;
          // get string with only digits and store string + round back
	    var numwoutcomma = "";
	    for (var i = 0; i < left.length; i++) {
	        var ch = left.substring(i, i + 1)
	        if (ch != ",")
	           numwoutcomma += ch;
	    }
              if (parseInt(numwoutcomma) >= 0)
  	            formField.value = parseInt(numwoutcomma,10) + dec;
              else
  	            formField.value = parseInt(numwoutcomma,10) - dec;
    }

    // max/min
    if ((min != 0 || max != 0) && len > -1) {
        if ((formField.value < min) || (formField.value > max)) {
            errorStr += fieldLabel + " must be between " + min + " and " + max + ".\n";
            if (showalert == true) 
	  	    alert(errorStr);
            return errorStr
        }
    }
    // max/min when only warning for negatives
    // only alert if -1, -2 means do not alert (used in CheckAndSubmit)
    if ((min != 0 || max != 0) && len < 0) {
        if ((((parseInt(formField.value) < 0) && (Math.abs(parseInt(formField.value))) > Math.abs(min)) && ((parseInt(formField.value) > 0) && (Math.abs(parseInt(formField.value))) < Math.abs(min))) || (Math.abs(parseInt(formField.value)) < Math.abs(max))) {
            // within bounds so check if need to warn (do not return since not error)
            if ((len != -2) && ((formField.value < min) || (formField.value > max))) {
                errorStr += fieldLabel + " is typically between between " + min + " and " + max + ".\n";
                if (showalert == true) 
    	    	        alert(errorStr);
            }
        }
	  else {
		// outside bounds
            if ((formField.value < min) || (formField.value > max)) {
				if (len == -1)
	                errorStr += fieldLabel + " is typically between between " + min + " and " + max + ".\n";
				else
				     errorStr += fieldLabel + " must be between " + min + " and " + max + ".\n";
                if (showalert == true) 
		      	    alert(errorStr);
                return errorStr
            }
        }
    }
    // length
    if (len > 0 && formField.value.length != len-numcomma && formField.value.length > 0) {
        errorStr += fieldLabel + " must be " + len + " characters long.\n"
	    if (showalert == true)
	        alert(errorStr);
    }
    return errorStr
}

//
// Checks a field for numbers and punctuation.
// allows user to specify the punctuation and required length
function errNumPunc(formField,fieldLabel,delims,numdigits,showalert) {
    var errorStr = ""
    var testStr = "";

    testStr = stripCharsNotInBag(formField.value,delims+'0123456789');
	if (testStr.length != formField.value.length) {
		errorStr += fieldLabel + " contains invalid characters.\n"
		if (showalert == true)
			alert(errorStr);
    }
	else {
		testStr = stripCharsNotInBag(formField.value,'0123456789');
		// normal check is length vs number of digits
		if (numdigits != 0) {
			if (formField.value.length != numdigits) {
				// but if created by system will include single alpha
				//if ((numdigits < 0) && (testStr.length < (Math.abs(numdigits)-1))) {
					errorStr += fieldLabel + " must be " + Math.abs(numdigits) + " digits.\n"
					if (showalert == true)
						alert(errorStr);
				//}
			} 
		}
	}
	return errorStr
}
function dollarFormat(expr){
	return "$" + decimalFormat(expr, 2);
}
function decimalFormat(expr, decplaces){
	// raise by power of 10 times the decplaces; round to an int; convert to str
	var str = "" + Math.round (eval(expr) * Math.pow(10,decplaces));
	// pad with zeros 
	while (str.length <= decplaces){
		str = "0" + str	;
	}
	// get location of decimal point
	var decpoint = str.length - decplaces;
	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}



// returns the index of the selected radio button (ex: getRadioIndex(this.form.active_ind))
function getRadioIndex(buttonGroup){
	theindex = "";
	for (var i=0; i < buttonGroup.length; i++){
		if (buttonGroup[i].checked) {
			theindex =  i;
		}
	}
	return theindex;
}
// returns the value of the selected radio button (ex: getRadioValue(this.form.active_ind))
function getRadioValue(buttonGroup){
	var thevalue = "";
	//6/12/2007 - DLynch - Fix if button is not a group
	if (!buttonGroup.length || buttonGroup.length==""){
		//alert("Not a group");
		if (buttonGroup.checked) {
			thevalue = buttonGroup.value;
		}
	}
	else
	//alert("It is a group");
	{
		for (var i=0; i < buttonGroup.length; i++){
			if (buttonGroup[i].checked) {
				thevalue = buttonGroup[i].value;
			}
		}
	}
	return thevalue;
}

// returns comma delim list of all values within the radio button group (ex: getRadioValues(this.form.active_ind))
function getRadioValues(buttonGroup){
	var listValues = "";
	for (var i=0; i < buttonGroup.length; i++){
		if(listValues > ""){
			listValues += ",";
		}
		listValues += buttonGroup[i].value;
	}
	return listValues;
}

function confirmButton(buttonGroup,prevvalue_field,confirmStr){
	var rUstr = "Are you sure you want to:\n"; 
	var oldIndex = "";
	var oldValue = "";
	var currentIndex = "";
	var currentValue = "";

	confirmStr = rUstr + confirmStr;
	oldValue = prevvalue_field.value;
	currentIndex = getRadioIndex(buttonGroup); // returns the selected button's index
	currentValue = getRadioValue(buttonGroup); // returns the selected button's value
	var listValues = getRadioValues(buttonGroup); // returns list of all values for the radio button group
//	alert("listValues: " + listValues + "\ncurrentIndex: " + currentIndex + "\ncurrentValue: " + currentValue);

	var arrayValues = listValues.split(","); // convert returned list into an array, loop thru and get the index of the old value
	for (var i=0; i < arrayValues.length; i++) {
		if(oldValue == arrayValues[i]){
			oldIndex = i;
			break;
		}			
	}
	// make sure the user didn't click the currently selected button
	if(oldIndex!=currentIndex){
		if(confirm(confirmStr)){
			buttonGroup[currentIndex].checked = true;
			prevvalue_field.value = currentValue;	
			return true;
		}
		else{
			buttonGroup[oldIndex].checked = true;
			return false;
		}
	}
}
function setRadioButton(buttonGroup,theValue){
	var theIndex = "";
	var listValues = getRadioValues(buttonGroup);
	var arrayValues = listValues.split(","); // convert returned list into an array
	//	alert(listValues);
	// loop thru and find the index of the value
	for (var i=0; i < arrayValues.length; i++) {
		if(theValue == arrayValues[i]){
			theIndex = i;
			break;
		}			
	}
	if(theIndex > -1){
		buttonGroup[theIndex].checked = true;
	}
}

function isInteger (s)
{   var i;
    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (!((c >= "0") && (c <= "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

/*******************************************************************
*                 DATE CHECKS                                      *
*                                                                  *
*                                                                  *
*******************************************************************/
// define number of days for month - except february which is checked
var daysInMonth = new Array(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;
// isYear returns true if string s is a valid 
// Year number.  Must be 4 digits only.
function isYear (s)
{
	if (!isIntegerInRange (s, 1900, 2100)) return false;
    return (s.length == 4);

}
// isIntegerInRange returns true if string s is an integer 
// within the range of integer arguments a and b, inclusive.
function isIntegerInRange (s, a, b)
{
    // Catch non-integer strings to avoid creating a NaN below,
    // which isn't available on JavaScript 1.0 for Windows.
    if (!isInteger(s, false)) return false;
	// check if leading 0 and remove
	if ((s.substring(0,1) == "0") && (s.length > 1))
		s = s.substring(1,s.length);
	
    // Now, explicitly change the type to integer via parseInt
    // for JS 1.1/1.2 compatability
	var num = parseInt (s,10);
    return ((num >= a) && (num <= b));
}
// isMonth returns true if string s is a valid 
// month number between 1 and 12.
//
function isMonth (s)
{
   return isIntegerInRange (s, 1, 12);
}
// isDay returns true if string s is a valid 
// day number between 1 and 31.
// 
function isDay (s)
{
    return isIntegerInRange (s, 1, 31);
}
// daysInFebruary (INTEGER year)
// 
// returns number of days in February of that year.
function daysInFebruary (year)
{   // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}
// isDate checks if string arguments year, month, and day 
// form a valid date.  Error string returned with/out data.
// 
function isDate (year, month, day, fieldLabel, noBlank, showalert)
{
    var errorStr="";
	// check for missing values & exit
    if ((year.length == 0) || (month.length== 0) || (day.length == 0)) {
    	if (noBlank == true) {
        errorStr += fieldLabel + " cannot be blank.\n";
        if (showalert == true)
		alert(errorStr);
	}
	  return errorStr;
    }
    // catch invalid years (not 2- or 4-digit) and invalid months and days.
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) {
        errorStr += "Please enter " + fieldLabel + " in mm/dd/yyyy format.\nFor example, 08/01/1999.\n";
        if (showalert == true)
		alert(errorStr);
	  return errorStr
    }
    // Explicitly change type to integer to make code work in both
    // JavaScript 1.1 and JavaScript 1.2.
    var intYear = parseInt(year,10);
    var intMonth = parseInt(month,10);
    var intDay = parseInt(day,10);
    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) {
        errorStr += "Please enter " + fieldLabel + " in mm/dd/yyyy format.\nFor example, 08/01/1999.\n";
        if (showalert == true)
		alert(errorStr);
	  return errorStr
    }
    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) {
        errorStr += "Please enter " + fieldLabel + " in mm/dd/yyyy format.\nFor example, 08/01/1999.\n";
        if (showalert == true)
		alert(errorStr);
	  return errorStr
    }
    return errorStr;
}
function errDate(thefield, fieldLabel, noBlank, showalert) 
{
	var errorStr="";
	var isplit=0;
	var sMonth="";
	var sDay="";
	var sYear="";
			
	if (thefield.value.length == 0) {
	if (noBlank == true) {
        errorStr += "Please enter " + fieldLabel + " in mm/dd/yyyy format.\nFor example, 08/01/1999.\n";
        if (showalert == true)
		alert(errorStr);
      }
	  return errorStr;
	}
	//Returns true if value is a date in the mm/dd/yyyy format
	isplit = thefield.value.indexOf('/');

	// Added the 2nd 'OR' clause below to catch dates added with '/' as the first character
	if (isplit == -1 || isplit == thefield.value.length || thefield.value.substring(0,1) == "/"){
        errorStr += "Please enter " + fieldLabel + " in mm/dd/yyyy format.\nFor example, 08/01/1999.\n";
        if (showalert == true)
		alert(errorStr);
        return errorStr;
	}

	sMonth = thefield.value.substring(0, isplit);
	isplit = thefield.value.indexOf('/', isplit + 1);

	if (isplit == -1 || (isplit + 1 ) == thefield.value.length){
        errorStr += "Please enter " + fieldLabel + " in mm/dd/yyyy format.\nFor example, 08/01/1999.\n";
        if (showalert == true)
		alert(errorStr);
        return errorStr;
	}
	sDay = thefield.value.substring((sMonth.length + 1), isplit);
	sYear = thefield.value.substring(isplit + 1);
	// to pickup the following formats as errors:
	//  0101//2000 OR //01012000
	//	001/1/2000 OR 1/001/2000
	//	0101//2000 OR /0101/2000
	if (thefield.value.indexOf('//')>-1){
        errorStr += "Please enter " + fieldLabel + " in mm/dd/yyyy format.\nFor example, 08/01/1999.\n";
        if (showalert == true)
		alert(errorStr);
        return errorStr;
	}
	if (sMonth.length ==3 || sMonth.length ==4 || sDay.length ==3 || sDay.length ==4){
        errorStr += "Please enter " + fieldLabel + " in mm/dd/yyyy format.\nFor example, 08/01/1999.\n";
        if (showalert == true)
		alert(errorStr);
        return errorStr;
	}
	return isDate (sYear, sMonth, sDay, fieldLabel, noBlank, showalert)
    }
// Compares two dates in format 01/01/1999 and returns -1 if first one less, 0 if same, 
// and 1 if second greater.  Assumes that dates have already been validated
// if firstDate < secondDate function returns the number of years as negative
function CompareDates(firstDate, secondDate)
{
	var isplit=0;
	var s1Month="";
	var s1Day="";
	var s1Year="";
	var s2Month="";
	var s2Day="";
	var s2Year="";

	isplit = firstDate.value.indexOf('/');
	s1Month = firstDate.value.substring(0, isplit);
	isplit = firstDate.value.indexOf('/', isplit + 1);
	s1Day = firstDate.value.substring((s1Month.length + 1), isplit);
	s1Year = firstDate.value.substring(isplit + 1);
	
	isplit = secondDate.value.indexOf('/');
	s2Month = secondDate.value.substring(0, isplit);
	isplit = secondDate.value.indexOf('/', isplit + 1);
	s2Day = secondDate.value.substring((s2Month.length + 1), isplit);
	s2Year = secondDate.value.substring(isplit + 1);
	
	date1 = new Date(s1Year,s1Month-1,s1Day);
	date2 = new Date(s2Year,s2Month-1,s2Day);
	
	if (date1 < date2) 
		return 	-1*Math.round(.51+(date2-date1)/31536000000);

	if (date1 > date2)
		return 1;
	else
		return 0;
}
// Compares two dates in format 01/01/1999 and returns -1 if first one less, 0 if same, 
// and 1 if second greater.  Returns -999 if firstDate has error, +999 if second has error
// if firstDate < secondDate function returns the number of years as negative
function errCompareDates(firstDate, secondDate)
{
	if (firstDate.value.length > 0) {
		isplit = firstDate.value.indexOf('/');
		if (isplit == -1 || isplit == firstDate.value.length)
			return -999;
		s1Month = firstDate.value.substring(0, isplit);
		isplit = firstDate.value.indexOf('/', isplit + 1);
		if (isplit == -1 || (isplit + 1 ) == firstDate.value.length)
			return -999;
		s1Day = firstDate.value.substring((s1Month.length + 1), isplit);
		s1Year = firstDate.value.substring(isplit + 1);
	    if (! (isYear(s1Year, false) && isMonth(s1Month, false) && isDay(s1Day, false)))
			return -999;
	    var intYear = parseInt(s1Year,10);
    	var intMonth = parseInt(s1Month,10);
    	var intDay = parseInt(s1Day,10);
  		if (intDay > daysInMonth[intMonth])
			return -999;
		if ((intMonth == 2) && (intDay > daysInFebruary(intYear)))
			return -999;
		date1 = new Date(s1Year,s1Month-1,s1Day);
	}	
	if (secondDate.value.length > 0) {
		isplit = secondDate.value.indexOf('/');
		if (isplit == -1 || isplit == secondDate.value.length)
			return 999;
		s2Month = secondDate.value.substring(0, isplit);
		isplit = secondDate.value.indexOf('/', isplit + 1);
		if (isplit == -1 || isplit == secondDate.value.length)
			return 999;
		s2Day = secondDate.value.substring((s2Month.length + 1), isplit);
		s2Year = secondDate.value.substring(isplit + 1);
	    if (! (isYear(s2Year, false) && isMonth(s2Month, false) && isDay(s2Day, false)))
			return 999;
	    var intYear = parseInt(s2Year,10);
    	var intMonth = parseInt(s2Month,10);
    	var intDay = parseInt(s2Day,10);
  		if (intDay > daysInMonth[intMonth])
			return 999;
		if ((intMonth == 2) && (intDay > daysInFebruary(intYear)))
			return 999;
		date2 = new Date(s2Year,s2Month-1,s2Day);
	}
	if ((firstDate.value.length > 2) && (secondDate.value.length > 2)) {
		if (date1 < date2) 
			return 	-1*Math.round(.51+(date2-date1)/31536000000);
		if (date1 > date2)
			return 1;
	}
	return 0;
}


/*******************************************************************
*                 PICK LISTS                                       *
*                                                                  *
*                                                                  *
*******************************************************************/
// GetPickList returns the value from a single selection SELECT list
function GetPickList(thelist){
  var PickList='';
  for (var i=0; i < thelist.length; i++) {
    if (thelist.options[i].selected) {
      PickList = thelist.options[i].value;
      return PickList;
    }
  }
  return PickList;
}

// GetPickListText returns the Text from a single selection SELECT list
function GetPickListText(thelist){
  var PickList='';
  for (var i=0; i < thelist.length; i++) {
    if (thelist.options[i].selected) {
      PickList = thelist.options[i].text;
      return PickList;
    }
  }
  return PickList;
}

// Check to see if the default item is selected
function ItemSelected(thelist){
  for (var i=0; i < thelist.length; i++) {
    if (thelist.options[i].selected)
      return i;
  }
  return -1;
}
// Sets specific value in list
function setPickList(thelist, thevalue) {
  for (var i=0; i < thelist.length; i++) {
    if (thelist.options[i].value == thevalue) {
      thelist.options[i].selected = true;
      break;
    }
  }
}
// Sets specific value in list
function setPickListMulti(thelist, thevalue) {
  // first clear all previously selected options
  for (var i=0; i < thelist.length; i++) {
	thelist.options[i].selected = false;
  }
  for (var i=0; i < thelist.length; i++) {
    if (thelist.options[i].value == thevalue) {
      thelist.options[i].selected = true;
    }
  }
}
// Sets similar value in list used in places like quick fill 
function setPickListLike(thelist, thevalue) {
	for (var i=0; i < thelist.length; i++) {
		var thelistvalue = thelist.options[i].value.toLowerCase();
    	if (thelistvalue.substring(0,thevalue.length) == thevalue) {
	 		thelist.options[i].selected = true;
		break;
		}
	}
}
// Sets similar value in list
function setPickListLikeMulti(thelist, thevalue) {
	// first clear all previously selected options
	for (var i=0; i < thelist.length; i++) {
		thelist.options[i].selected = false;
	}
	// if the value is not null then loop thru
	if(thevalue.length>0){
		for (var i=0; i < thelist.length; i++) {
			var thelistvalue = thelist.options[i].value.toLowerCase();
	    	if (thelistvalue.substring(0,thevalue.length) == thevalue) {
		 		thelist.options[i].selected = true;
			}
		}
	}
}

// Returns comma delimited list of values from a MULTI-Select box 
function GetPickListMulti(thelist){
	var picklist = "";
	for (var i=0; i < thelist.length; i++) {
		if (thelist.options[i].selected) {
			// determine if we need to start separating with commas 
			if(picklist > ""){
				picklist += ",";
			}
			picklist += String(thelist.options[i].value);
		}
	}
	return picklist;
}
// Returns QUOTED comma delimited list of values from a MULTI-Select box 
function GetPickListMultiQuoted(thelist){
	var picklist = "";
	for (var i=0; i < thelist.length; i++) {
		if (thelist.options[i].selected) {
			// determine if we need to start separating with commas 
			if(picklist > ""){
				picklist += ",";
			}
			picklist += "'" + String(thelist.options[i].value) + "'";
		}
	}
	return picklist;
}
// Returns comma delimited list of text from a MULTI-Select box 
function GetPickListTextMulti(thelist){
	var picklist = "";
	for (var i=0; i < thelist.length; i++) {
		if (thelist.options[i].selected) {
			// determine if we need to start separating with commas 
			if(picklist > ""){
				picklist += ",";
			}
			picklist += String(thelist.options[i].text);
		}
	}
	return picklist;
}

// Removes all selected options from a MULTI-Select box 
function RemovePickListMulti(thelist){
	var picklist = "";
	for (var i=0; i < thelist.length; i++) {
		if (thelist.options[i].selected) {
			thelist.options[i] = null;
			// recursively call itself until all are found and removed
			RemovePickListMulti(thelist);
		}
	}
}
// Moves options FROM a multi Select box to another 
function MovePickListMulti(fromlist,tolist){
	// create comma delim lists
	tempindex = GetPickListMulti(fromlist);
	temptext = GetPickListTextMulti(fromlist);

	// now remove the options from the fromlist
	temp = RemovePickListMulti(fromlist);

	// create arrays, loop thru and add to the tolist 
	var arrayindex = tempindex.split(",");
	var arraytext = temptext.split(",");
	var startat = tolist.length;
	for (var i=0; i < arrayindex.length; i++) {
		var newoption = startat + i;
		tolist.options[newoption] = new Option (arraytext[i], arrayindex[i]);
	}
}

// Returns comma delimited list of ALL values from a MULTI-Select box 
function GetPickListMultiAll(thelist){
	var picklist = "";
	for (var i=0; i < thelist.length; i++) {
		if(picklist > ""){
			picklist += ",";
		}
		picklist += String(thelist.options[i].value);
	}
	return picklist;
}

// Returns comma delimited list of ALL text from a MULTI-Select box 
function GetPickListTextMultiAll(thelist){
	var picklist = "";
	for (var i=0; i < thelist.length; i++) {
		if(picklist > ""){
			picklist += ",";
		}
		picklist += String(thelist.options[i].text);
	}
	return picklist;
}

function windowpopup(url)
{
	/*	this shows how to open a resizable window 
			of a particular height and width, 
			with a defined offset from the top and left, 
			displaying the status, menubar and location showing:
	*/
	//sessionwin = window.open(url,"newwindow","height=400,width=800,left=50,top=50,resizable,scrollbars,status,menubar,location,toolbar,copyhistory,directories")
	sessionwin = window.open(url,"newwindow","height=400,width=800,left=50,top=50,resizable,scrollbars,status,menubar")
	// this shows how to refocus on the above window (so that we don't continuously open new windows)
	if(sessionwin){
		sessionwin.focus();
	}
}

//Check  all checkboxs on the page
function checkbox_check_all(form)
{
	var i;
	for (i=0; i< form.length; i++) 
	{
	   if (form.elements[i].type == "checkbox") 
	   {
	     	form.elements[i].checked = true;
	   }
	}
}

//un-check all checkboxs on the page
function checkbox_un_check_all(form)
{
	var i;
	for (i=0; i< form.length; i++) 
	{
		if (form.elements[i].type == "checkbox") 
		{
			form.elements[i].checked = false;
		}
	}
}

//Check  all checkboxs on the page who's names start with 'startwith'
function checkbox_check_all_v2(form, startswith)
{
	var i;
	for (i=0; i< form.length; i++) 
	{
	   if (form.elements[i].type == "checkbox" && form.elements[i].name.indexOf(startswith) == 0) 
	   {
	     	form.elements[i].checked = true;
	   }
	}
}

//un-check all checkboxs on the page who's names start with 'startwith'
function checkbox_un_check_all_v2(form, startswith)
{
	var i;
	for (i=0; i< form.length; i++) {
		if (form.elements[i].type == "checkbox" && form.elements[i].name.indexOf(startswith) == 0) 
		{
			form.elements[i].checked = false;
		}
	}
}

function make_textarea_larger(objName,icols,irows)
	{
	var field = objName;
	var current_rows;
	var current_cols;
	
	current_rows = field.rows
	current_cols = field.cols
	
	field.rows = (current_rows + irows)
	field.cols = (current_cols + icols)
	field.focus()
	}
	
function deleteCurriculum(id) {
	var confirm_ret;
	confirm_ret = confirm("Are you sure you want to delete this curriculum set? \n\n (WARNING: this action cannot be undone.)");
	if (confirm_ret == true)
	{	
		window.location = "DeleteCurriculum.asp?curriculum_id=" + id ;				
	}					
	else
	{
		return;			
	}
}

function deleteDepartment(id) {
	var confirm_ret;
	confirm_ret = confirm("Are you sure you want to delete this department? \n\n (WARNING: this action cannot be undone.)");
	if (confirm_ret == true)
	{	
		window.location = "DeleteDepartment.asp?department_id=" + id ;				
	}					
	else
	{
		return;			
	}
}
function deleteCourse(id) {
	var confirm_ret;
	confirm_ret = confirm("Are you sure you want to delete this course? \n\n (WARNING: this action cannot be undone.)");
	if (confirm_ret == true)
	{	
		window.location = "DeleteCourse.asp?course_id=" + id ;				
	}					
	else
	{
		return;			
	}
}

// returns comma delim list of all values within the checkbox group (ex: getCheckBoxValues(this.form.active_ind))
function getCheckBoxValues(form, btn_name)
	{
	var listValues = "";
	var i;
	for (i=0; i< form.length; i++) 
	{
	   if ((form.elements[i].type == "checkbox") && (form.elements[i].name == btn_name))
		   {
			if (form.elements[i].checked == true)
			   {
				if(listValues > "")
				{
					listValues += ",";
				}
				listValues += form.elements[i].value;
			   }

			}
	}
		return listValues;
	}

function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
   
   
function HideSelects() {
	var form;
	for (i=0; i<document.forms.length; i++) {
		form = document.forms[i]
		for (j=0; j<form.length; j++) {
			if (form.elements[j].type == "select-one") 
			{
			  	form.elements[j].style.visibility = 'hidden';
			}
		}
	}
}

function ShowSelects() {
	var form;
	for (i=0; i<document.forms.length; i++) {
		form = document.forms[i]
		for (j=0; j<form.length; j++) {
			if (form.elements[j].type == "select-one") 
			{
			  	form.elements[j].style.visibility = 'visible';
			}
		}
	}
}

function loading(text, color, load_height, load_width) {
	var loading_layer = document.createElement('div')
	loading_layer.id = 'loading_layer';
	
	document.getElementsByTagName('BODY')[0].appendChild(loading_layer);	//document.appendChild(loading_layer);
		with(document.getElementById('loading_layer')) {
		style.backgroundColor = '#FFFFFF';
		style.border = 'solid 3px ' + color;
		style.textAlign = 'center';
		style.verticalAlign = 'text-bottom';
				style.height = load_height;		style.width = load_width;	
		style.position = 'absolute';
				style.top = '50%';
		style.left = '50%';				style.top = offsetTop - offsetHeight/2;		style.left = offsetLeft - offsetWidth/2;				
		style.display = 'block';
	}		var closeurl = location.href;	
	document.getElementById('loading_layer').innerHTML = '' +
		'<div style="position: absolute; top: 0; left: 0; width: ' + load_width + '; height: ' + load_height + ';">' +
			'<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">' +
				'<tr>' +
					'<td align="center" style="font: bold 15px Arial">' +
						text + '<br>' +
						'<img src="/images/loading.gif" name="loading_gif" id="loading_gif" WIDTH="220" HEIGHT="19">' +					'</td>' +				'</tr>' +			'</table>' +
		'</div>' +
		'<div style="position: absolute; top: 0; left: 0; width: ' + load_width + '; height: 10px; background-color: transparent; text-align: right;">' +
			'<a href="' + closeurl + '" style="font-family: Arial; color: Black; text-decoration: none;">' +
				'X&nbsp;&nbsp;&nbsp;' +
			'</a>' +
		'</div>';		
	animate_load();			
}

function animate_load() {
	loading_timer = window.setTimeout('if(document.getElementById("loading_gif")){document.getElementById("loading_gif").src = "/images/loading.gif";}', 200);
}

function fakeAJAX() {
if (typeof(window['showIFrame']) == 'undefined') {	showIFrame = false;}
args = fakeAJAX.arguments;
var script = args[0];
			
var ifrm = document.createElement('IFRAME');
ifrm.setAttribute('src', script);
ifrm.id = 'ifrm';if (showIFrame == true) {
	ifrm.style.display = 'block';} else {	ifrm.style.display = 'none';}
document.body.appendChild(ifrm);

var returnDiv = document.createElement('DIV');
returnDiv.id = 'returnVal';

returnDiv.style.display = 'none';

returnDiv.innerHTML = '-1';
document.body.appendChild(returnDiv);
			
var FAStatus = document.createElement('DIV');
FAStatus.id = 'FAStatus';
FAStatus.style.display = 'none';
returnDiv.innerHTML = '0';
document.body.appendChild(FAStatus);
			
var myCmd = 'if(document.getElementById(FAStatus.id).innerHTML=="1"){clearInterval(myInterval);fakeAJAXstep2("' + ifrm.id + '", "' + returnDiv.id + '", "' + FAStatus.id + '"';
for(i=1; i<args.length; i++) {
	myCmd += ', args[' + i + ']';
}
myCmd += ');}'
			
//alert(myCmd);
myInterval = setInterval(myCmd, 100);
}
		
function fakeAJAXstep2() {
	args = fakeAJAXstep2.arguments;
	var ifrm = document.getElementById(args[0]);
	var returnDiv = document.getElementById(args[1]);
	var FAStatus = document.getElementById(args[2]);
	var returnVal = returnDiv.innerHTML;		if (showIFrame != true) {
		document.body.removeChild(ifrm);	}	
	document.body.removeChild(returnDiv);
	document.body.removeChild(FAStatus);
			
	var myCmd = args[3] + '("' + returnVal + '"';
	for (i=4; i<args.length; i++) {
		myCmd += ', args[' + i + ']';
	}
	myCmd += ');';
	//alert(myCmd);
	setTimeout(myCmd, 1);
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function getIndex(field) {
	var elms = field.form.elements;
	for(var i=0; i<elms.length; i++)
		if (elms[i] == field)
			return i;
	return -1;
}

function moveUpDown(e, currentField) {
	var evt;
	var form = currentField.form;
	var elms = form.elements;
	
	if (window.event)
		evt = e.keyCode;
	else if (e.which)
		evt = e.which;
	
	var fieldIndex;
	if (evt == 38 || evt == 40)
		fieldIndex = getIndex(currentField);
		
	var fieldName
	fieldName = currentField.name.substring(0, currentField.name.lastIndexOf('_'));
	
	var newField
	switch(evt) {
		case 38: //up
			for (i=fieldIndex-1; i>0; i--) {
				if (elms[i].name.substring(0, fieldName.length) == fieldName && elms[i].type != 'hidden') {
					newField = form.elements[i];
					i=0;
				}
			}		
			break;
		case 40: //down
			for (i=fieldIndex+1; i<form.length; i++) {
				if (elms[i].name.substring(0, fieldName.length) == fieldName && elms[i].type != 'hidden') {
					newField = form.elements[i];
					i=form.length;
				}
			}
			break;
		default:
			return true;
			break;
	}
	
	if (newField) {
		newField.focus();
		newField.select();
	} 
	return false;
}