/*
 $Source: /web/cvs/classware/webapps/classware/WEB-INF/xslt/shared/common.js,v $
 $Revision: 1.53.8.20.2.1 $
 $Author: sbhattac $
 $Date: 2010/01/15 11:01:22 $
*/

/* 
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   Generic DHTML scripts, reusable anywhere
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

function getObj(name) {
	if (name) {
		if (document.getElementById) {
			if (document.getElementById(name)) {
				this.obj = document.getElementById(name);
				this.style = document.getElementById(name).style;
			} else {
				// no matching object found.  Do not display an error, because this may be on purpose.
				return false;
			}
		} else if (document.all) {
			this.obj = document.all[name];
			this.style = document.all[name].style;
		} else if (document.layers) {
			this.obj = document.layers[name];
			this.style = document.layers[name];
		} else {
			// no matching object found.  Do not display an error, because this may be on purpose.
			return false;
		}
		return this;
	}
}

function getWindowWidth() {
	// how's this for a tangle of browser incompatibilities?
	if (document.body) {
		if ((typeof(document.body.clientWidth) != "undefined") && (document.body.clientWidth != 0)) {
			return document.body.clientWidth;
		} else {
			return window.innerWidth - 16;
		}
	} else {
		return window.innerWidth - 16;
	}
}

function getWindowHeight() {
	// how's this for a tangle of browser incompatibilities?
	if (document.body) {
		if ((typeof(document.body.clientHeight) != "undefined") && (document.body.clientHeight != 0)) {
			return document.body.clientHeight;
		} else {
			return window.innerHeight - 16;
		}
	} else {
		return window.innerHeight - 16;
	}
}

function getTop(myName) {
	var myObj = new getObj(myName);
	if (myObj.style.pixelTop) {
		return Number(myObj.style.pixelTop);
	} else {
		var testPx = myObj.style.top;
		if (typeof myObj.style.top == "string") {
			return Number(myObj.style.top.substring(0,myObj.style.top.indexOf("px")));
		} else {
			return Number(myObj.style.top);
		}
	}
}

function setTop(myName, i) {
	var myObj = new getObj(myName);
	if (myObj.style) {
		if (myObj.style.pixelTop) {
			myObj.style.pixelTop = i;
		} else {
			myObj.style.top = i;
		}
	} else {
		// error... invalid div?
	}
}

function setLeft(myName, i) {
	var myObj = new getObj(myName);
	if (myObj.style.pixelLeft) {
		myObj.style.pixelLeft = i;
	} else {
		myObj.style.left = i;
	}
}

function showLayer(myName) {
	var myObj = new getObj(myName);
	if(myObj!=null && myObj.style!=null){
		myObj.style.visibility="visible";

		//NS6 only has a bug regarding the display style
		if(!window.find && navigator.appName == "Netscape"){
			if(myName != "divNavClass" && myName != "divNavContents"){myObj.style.display="block";}
		}else{myObj.style.display="inline";}

	}
}

function hideLayer(myName) {
	var myObj = new getObj(myName);
	if(myObj!=null && myObj.style!=null){
		myObj.style.visibility="hidden";

		//NS6 only has a bug regarding the display style
		if(!window.find && navigator.appName == "Netscape"){
			if(myName != "divNavClass" && myName != "divNavContents"){myObj.style.display="none";}
		}else{myObj.style.display="none";}
	}
}

function setZindex(myName, newZindex) {
	var myObj = new getObj(myName);
	if (myObj) {
		if (myObj.style.zIndex) {
			myObj.style.zIndex = newZindex;
		} 
	}
}
/*
var mouseX=0;
var mouseY=0;
function getMouseLoc(e) {
	if (window.Event) { // Navigator 4.0x
			
			mouseX = e.pageX;
			mouseY = e.pageY;
		
	} else { // IE, NS6
		mouseX = (window.event.clientX + document.body.scrollLeft);
		mouseY = (window.event.clientY + document.body.scrollTop);
	}
}
if (window.Event) {document.captureEvents(Event.MOUSEDOWN)}
document.onmousedown = getMouseLoc;
*/

/* 
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   Generic cookie scripts, reusable anywhere
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

function getCookie(cookieName) {
	var myCookie = document.cookie;
	var prefix = cookieName + "=";
	var begin = myCookie.indexOf("; " + prefix);
	if (begin == -1) {
		begin = myCookie.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	
	var end = myCookie.indexOf(";",begin);
	if (end == -1) end = myCookie.length;
	
	var returnString = unescape(myCookie.substring(begin + prefix.length, end));
	if (returnString) {
		return returnString;
	} else {
		return false;
	}
}

function setCookie(cookieName, cookieValue) {
	var nextyear = new Date();
	nextyear.setFullYear(nextyear.getFullYear()+1);
	document.cookie = cookieName + "=" + escape(cookieValue) + "; path=/; expires=" + nextyear.toGMTString();
}

function setSessionCookie(cookieName, cookieValue) {
	document.cookie = cookieName + "=" + escape(cookieValue) + "; path=/; ";
}

function getCookieVal(cookieName, key) {
	// parses a pipe-separated list of key=value pairs, returns the value of key or null
	if (getCookie(cookieName)) {
		var Array = getCookie(cookieName).split("\|");
		var testKey, testVal;
		for (var i = 0; i < Array.length; i++) {
			testKey = Array[i].substring(0,Array[i].indexOf("="));
			if (testKey == key) {
				return(Array[i].substring(Array[i].indexOf("=")+1,Array[i].length));
			}
		}
	}
	return "";
}

function deleteCookie(cookieName) {
	var lastyear = new Date();
	lastyear.setFullYear(lastyear.getFullYear()-1);
	
	// First try deleting without specifying a domain:
	document.cookie = cookieName + "=''; value=''; path=/; expires=" + lastyear.toGMTString();

	if (getCookie(cookieName)) {
		// that didn't work, try removing the subdomain:
		var theHost = location.host;
		var hostBits = theHost.split("\.");
		var shortHost =  "." + hostBits[hostBits.length-2] + "." + hostBits[hostBits.length-1];
		if (shortHost.indexOf(":") > -1) { 
			shortHost = shortHost.substring(0,shortHost.indexOf(":"));
		}
		document.cookie = cookieName + "=''; value=''; domain=" + shortHost + "; path=/; expires=" + lastyear.toGMTString();
	}
}

/* 
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   Form field validation routines
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/


function setFormDates(f,e,m,d,y) {
	/* 
		Sets date fields eMonth, eDay, and eYear in form f to the values in m,d,y 
	*/
	var form = document.forms[f];
	if (form) {
		var formMonth = eval("form."+e+"Month");
		if (formMonth) {
			formMonth.selectedIndex = m;	// safe to assume months will be listed in order...
		}
		var formDay = eval("form."+e+"Day");
		if (formDay) {
			formDay.selectedIndex = d;
		}
		var formYear = eval("form."+e+"Year");
		if (formYear) {
			var fyMatched=0;
			for (i=0; i < formYear.options.length; i++) {
				if (formYear[i].value == y) {
					formYear.selectedIndex = i;
					fyMatched=1;
				}
			}
			if (fyMatched == 0) {
				// the popup contained a year not represented here
				var newOpt = new Option(y,y,false,true);
				formYear.options[formYear.length] = newOpt;
			}
		}
	} else {
		alert ("ERROR: couldn't find form");
	}
}

/* this function is specific to mathiq brand */
function setFormDatesForMathiq(e,m,d,y) {
	var yearString = new String(y);  // ex. year = 2006
	var yearInTwoDigit = yearString.substring(2); // ex. year = 06
	
	if(m < 10){
		m = '0' + m;
	}	
	if(d < 10){
		d = '0' + d;
	}	
	var dateString = m + '/' + d + '/' + yearInTwoDigit;
	
	// getting the element first, then setting date
	var dateType = e + "Date";  
	var inputDate = document.getElementById(dateType);
	if (inputDate) {
		inputDate.value = dateString;
	}	
}

function validateFormDates(f) {
	/* checks startDate, endDate, extendDate fields; makes sure they are valid dates in the right order. */
	// startDate
	if (f.startMonth) {
		if (f.startMonth.selectedIndex==0) {
			f.startMonth.focus();return langNeedStartMonth;
		}
		if (f.startDay.selectedIndex == 0) {
			f.startDay.focus();return langNeedStartDate;
		}
		if (f.startYear.selectedIndex == 0) {
			f.startYear.focus();return langNeedStartYear;
		}
	}
	// endDate
	if (f.endMonth) {
		if (f.endMonth.selectedIndex==0) {
			f.endMonth.focus();return langNeedEndMonth;
		}
		if (f.endDay.selectedIndex == 0) {
			f.endDay.focus();return langNeedEndDate;
		}
		if (f.endYear.selectedIndex == 0) {
			f.endYear.focus();return langNeedEndYear;
		}
	}
	/*if(f.endYear.value < f.startYear.value){
		return langBadStartBeforeToday;
	}
	
	} else if()*/
	// extendDate
	if (f.extendPassword && !(isWhitespace(f.extendPassword.value))) {
		if (f.extendMonth.selectedIndex==0) {
			f.extendMonth.focus();return langNeedExtendMonth;
		}
		if (f.extendDay.selectedIndex == 0) {
			f.extendDay.focus();return langNeedExtendDate;
		}
		if (f.extendYear.selectedIndex == 0) {
			f.extendYear.focus();return langNeedExtendYear;
		}
	}

	// sloppy but functional:
	var badDay="";
	if (f.startMonth) {badDay = validateMonthLength(f.startMonth[f.startMonth.selectedIndex].value, f.startDay[f.startDay.selectedIndex].value,f.startYear[f.startYear.selectedIndex].value)}
	if (badDay != "") {return badDay};
	if (f.endMonth) {badDay = validateMonthLength(f.endMonth[f.endMonth.selectedIndex].value, f.endDay[f.endDay.selectedIndex].value,f.endYear[f.endYear.selectedIndex].value)}
	if (badDay != "") {return badDay};
	if (f.extendMonth) {badDay = validateMonthLength(f.extendMonth[f.extendMonth.selectedIndex].value, f.extendDay[f.extendDay.selectedIndex].value,f.extendYear[f.extendYear.selectedIndex].value)}
	if (badDay != "") {return badDay};
	
	
	// date order
	var d1 = f.startYear[f.startYear.selectedIndex].value + "" + f.startMonth[f.startMonth.selectedIndex].value + "" + f.startDay[f.startDay.selectedIndex].value + "" + f.startHour[f.startHour.selectedIndex].value + "" + f.startMinute[f.startMinute.selectedIndex].value;
	var d11 = f.startYear[f.startYear.selectedIndex].value + "" + f.startMonth[f.startMonth.selectedIndex].value + "" + f.startDay[f.startDay.selectedIndex].value;
	var d2 ="";
	var d21="";
	if(f.endYear)
	{
	     d2 = f.endYear[f.endYear.selectedIndex].value + "" + f.endMonth[f.endMonth.selectedIndex].value + "" + f.endDay[f.endDay.selectedIndex].value + "" + f.endHour[f.endHour.selectedIndex].value + "" + f.endMinute[f.endMinute.selectedIndex].value;
	     d21 = f.endYear[f.endYear.selectedIndex].value + "" + f.endMonth[f.endMonth.selectedIndex].value + "" + f.endDay[f.endDay.selectedIndex].value;
    }

    var d4 = "";
    var d5 = "";
      if(f.courseStartDate) {
        d4 = f.courseStartDate.value.substring(0, 8);
    }

    if(f.courseEndDate) {
        d5 = f.courseEndDate.value.substring(0, 8);
    }

	if (d2!="" && d1 >= d2) {
		return langBadDateOrder;
	}
	// special case for extend dates (assignment_edit):
	if (f.extendPassword && !(isWhitespace(f.extendPassword.value))) {
		var d3 = f.extendYear[f.extendYear.selectedIndex].value + "" + f.extendMonth[f.extendMonth.selectedIndex].value + "" + f.extendDay[f.extendDay.selectedIndex].value + "" + f.extendHour[f.extendHour.selectedIndex].value + "" + f.extendMinute[f.extendMinute.selectedIndex].value;
		var d31 = f.extendYear[f.extendYear.selectedIndex].value + "" + f.extendMonth[f.extendMonth.selectedIndex].value + "" + f.extendDay[f.extendDay.selectedIndex].value;
		if (d2 >= d3) {
			return langBadDateExtendOrder;
		}


		if(f.courseEndDate && (d31 > d5)) {
		    return "The extension date must be before the end of the course.";
		}


	}
	// special case: must start after today (currently only in announcement create, but could come later on too.)
	// current date is assumed to be in hidden form fields!
	if (f.mustEndAfterToday) {
		var d3 = f.currentYear.value + "" + f.currentMonth.value + "" + f.currentDay.value + "" + f.currentHour.value + "" + f.currentMinute.value;
		if (d2 < d3) {
			return "The end date cannot be before today.";
		}
	}
	
	//Milan: for bug #3408 start
	//special case: must send after after today
	// current date is assumed to be in hidden form fields!
	if (f.mustStartAfterToday) {
		var d3 = f.currentYear.value + "" + f.currentMonth.value + "" + f.currentDay.value;
		if (d11 < d3) {
			return "The send date cannot be before today.";
		}
	}
	//Milan: end

	if(f.courseStartDate && (d11 < d4)) {
	    return "The assignment start or due dates are out of course start or end date bounds.";
	}

	if(f.courseEndDate && (d21 > d5)) {
	    return "The assignment start or due dates are out of course start or end date bounds.";
	}
	// 
	// all ok
	return ""; // should be blank
	
}

function validateFormDates_adoptcourse(f){
	var err = "";
	var errMsg = "";
	
	errMsg = validateDate(f.startDate);
    if(errMsg != ""){
      err += "Please enter valid Course Start Date in mm/dd/yyyy format\n";
    }
    
	errMsg = validateHour(f.startHour);
    if(errMsg != ""){
      err += "Please enter valid Course Start Hour\n";
    }
	
	errMsg = validateMinute(f.startMinute);
	if(errMsg != ""){
	  err += "Please enter valid Course Start minute. Valid values are 00,15,30,45.\n";
	}
	
	if(err != ''){
	  return err;
	}
	
	var badDay="";
	badDay = validateMonthLength(f.startDate.value.substr(0,2), f.startDate.value.substr(3,2),f.startDate.value.substr(6,4));
	if (badDay != "") {return badDay};

}

function toggleFormDateAMPMDisplay(val, name) {
	if (val < 12) {
		hideLayer(name + "dispPM");
		showLayer(name + "dispAM");
	} else {
		hideLayer(name + "dispAM");
		showLayer(name + "dispPM");
	}
}

function validateMonthLength(m,d,y) {
	var maxLength;
	if (m == 2) {
		if ( ((y % 4 == 0) && !(y % 100 == 0)) || y % 400 == 0) { // because this will surely still be in use 396 years from now
			maxLength = 29;
		} else {
			maxLength = 28;
		}
	} else if (m == 4 || m == 6 || m == 9 || m == 11) {
		maxLength = 30;
	} else {
		maxLength = 31;
	}
	if (d > maxLength) {
		return "An invalid date was selected.";
	} else {
		return ""; // bare return is NOT sufficient
	}
}


function isEmpty(s) {
	return ((s == null) || (s.length == 0) || isWhitespace(s))
}
	
function isEmail(s) {
	if (isWhitespace(s)) return false;
	var i = 1;
	var sLength = s.length;
	while ((i < sLength) && (s.charAt(i) != "@")){ 
		i++
	}
	if ((i >= sLength) || (s.charAt(i) != "@")) return false;
	else i += 2;
	while ((i < sLength) && (s.charAt(i) != ".")){ 
		i++
	}
	if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
	else return true;
}

function isWhitespace (s){   
	var whitespace = " \t\n\r";
	var i;
	for (i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
	}
	return true;
}

function isValidPassword(s){
	if (s.length < 4 || s.length > 20) {
		return false;
	} else {
		var allowed = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
		var i;
		for (i=0; i<s.length;i++) {
			var c = s.charAt(i);
			if (allowed.indexOf(c) == -1) return false;
		}
	}
	return true;
}

function convertSpaces(str) {
	var out = "",flag=0;
	for (i = 0; i < str.length; i++) {
		if (str.charAt(i) != " ") {
				out += str.charAt(i);
		} else{
				out += "%20";
		}
	}
	return out;
}

function hasChecked(e) {
	// returns true if at least one element in the set is checked
	if (e.length) {
		for (i=0; i<e.length; i++) {
			if (e[i].checked) {return true}
		}
	} else {
		return e.checked;
	}
	return false;
}

function checkedVal(e) {
	// convenience function; returns value of first checked element in set
	if (e.length) {
		for (i=0; i<e.length; i++) {
			if (e[i].checked) {return e[i].value}
		}
	} else {
		return e.checked ? e.value : false;
	}
	return false;
}

function setPrecision(e,digits) {
	// round off a form field value to the indicated number of digits after the decimal

	if (isWhitespace(e.value)) {
		e.value = "";
	} else {
		if (isNaN(e.value)) {
			e.style.backgroundColor="FCC";
		} else {
			e.style.backgroundColor="FFF";
			e.value = (Math.round(e.value * Math.pow(10,digits))) / Math.pow(10,digits);
		}
	}
}
/* 
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   Form focus and selection capture
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

var focusedElement = "";	// handler so javascript can tell which form element is in focus
var selectedRange = "";

function captureFocus(myElement) {
	// to get all browsers, must trigger this with all 3 of: onChange, onClick, onFocus
	focusedElement=myElement;
	if (myElement.createTextRange) {
		selectedRange = document.selection.createRange();
	}
}

function pushSelectedChar(theChar) {
	// pops the character onto the end of the last form element that triggered captureFocus
	// (or, in IE5, places it at the selectedRange instead)
	
	if (focusedElement) {
		if (selectedRange) {
			selectedRange.text = theChar;
		} else {
			focusedElement.value = focusedElement.value + theChar;
		}
	} else {
		alert("Please click inside the field you want to add this character to.");
	}
}


/* 
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   Simplified browser sniffer. Growing more complex, though.
   
   Please avoid using this whenever possible: it's much better
   to do capability testing than version testing.  Currently, this is used for:
   - Drawer speed control (NS6 was way too slow)
   - Mouse location detection (IE5/Mac returns locations relative to the div, not the window)
   - Profile drawer (NS4 can't write profile data into the form)
   
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

function BrowserIs () {
	var agt=navigator.userAgent.toLowerCase()
	this.agent = agt;

	this.ns    = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1)));
	this.ie    = (agt.indexOf("msie") != -1);
	this.opera = (agt.indexOf("opera") != -1);

	// Mozilla always claims to be version 5. Bastards. 
	// The "real" version number is tucked away at the end of the string.
	if (this.ns && (parseInt(navigator.appVersion) == 5)) {
	
		// not only that, but different versions seem to handle substring differently???
		var versionString = agt.substring(agt.indexOf('netscape')+9);
		if (versionString.indexOf('/') == -1) {
			this.major = parseInt(versionString);
			this.minor = parseFloat(versionString);
		} else {
			this.major = parseInt(versionString.substring(1));
			this.minor = parseFloat(versionString.substring(1));
		}
	} else {
		this.major = parseInt(navigator.appVersion);
		this.minor = parseFloat(navigator.appVersion);
	}

	this.win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) )
	this.mac    = (agt.indexOf("mac")!=-1)
}

var browserIs = new BrowserIs();


/* 
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   Querystring routines
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

function getQueryVal(arg) {
	// checks the querystring for an argument, returns its value
	var query = location.search.substring(1);
	var pairs = query.split("&");
	for (var i=0; i < pairs.length; i++) {
		var pos = pairs[i].indexOf('=');
		if (pos == -1) continue;
		if (pairs[i].substring(0,pos) == arg) {
			return pairs[i].substring(pos+1);
			break;
		}
	}
	return false;
}

/*
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 Validate the file extension
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

function isValidFileType(s) {
	// currently word and PDF, but let's make this extendable
	if (checkFileExtension(s,'pdf') || checkFileExtension(s,'doc') || checkFileExtension(s,'jpg') || checkFileExtension(s,'jpeg') || checkFileExtension(s,'ppt') || checkFileExtension(s,'gif') || checkFileExtension(s,'xls') || checkFileExtension(s,'xlsx') || checkFileExtension(s,'docx') || checkFileExtension(s,'pptx')||checkFileExtension(s,'jnt')) {
		return true;
	} else {
		return false;
	}
}

function checkFileExtension(name,ext) {
	var lname = name.toLowerCase();
	var index = lname.lastIndexOf(".");
	if (lname.substring(index+1)!=ext) return false;
	return true;

}

/*
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 Validate the file name (This method is a varity of FormCheck.js from novella )
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/
function checkFileName(s) {
	var i, baseName;
	var re1, re2, result1, result2;
	var separator = ( navigator.platform == "Win32" ) ? "\\" : "/" ;
	if ( (i = s.lastIndexOf(separator)) != -1 ) {
		baseName = s.substring(i+1, s.length );
	} else {
		baseName = s;
	}
	if ( baseName == null || baseName.length == 0 ){
		return false;
	}
	//make sure base name has only "a-z", "0-9", " ", "_", "-", "."
    re2 = new RegExp(" ","g");              // find the character is white space
    baseName =baseName.replace(re2,"_")     //replace the whitespace to "_"

    //make sure base name has only "a-z", "0-9", " ", "_", "-", "."    
    re1 = new RegExp("[^a-zA-Z0-9_\.\-]");   //find the character is not "a-z", "0-9","_", "-", "."
    result1 = re1.exec(baseName);

    if ( result1 != null ){
        alert("File names cannot contain character '" + result1[0] +"'");
        return false;
    }

	return true;
}


/*
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//show OR hide funtion depends on if element is shown or hidden
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/
function showOrHideDiv(id, flag) {

        window.location="#top"
        if (document.getElementById) { // DOM3 = IE5, NS6
                if (flag == true){
                        document.getElementById(id).style.display = 'block';
                } else {
                        document.getElementById(id).style.display = 'none';
                }
        } else {
                if (document.layers) {
                        if (flag == true){
                                document.id.display = 'block';
                        } else {
                                document.id.display = 'none';
                        }
                } else {
                        if (flag == true){
                                document.all.id.style.display = 'block';
                        } else {
                                document.all.id.style.display = 'none';
                        }
                }
        }
}

/*
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
If thisCheckBox is checked, check all the nameOfCheckbox as well, vice vera
for uncheck.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/
function toggleCheckBox(thisCheckBox, nameOfCheckbox, formName) {
    var setValue =false;
    if (thisCheckBox.checked == true){
        setValue= true;
    }

    if(setValue) checkAll(eval(formName + "."+nameOfCheckbox));
    else uncheckAll(eval(formName + "."+ nameOfCheckbox));
}

/*
:::::::::::::::::::::::::::::::
Check all the field (checkbox)
:::::::::::::::::::::::::::::::
*/
function checkAll(field)
{
   if (field)
   {
     if (field.length>1)
     {
         for (i = 0; i < field.length; i++)
            field[i].checked = true ;
     }
     else field.checked=true;
   }
}

/*
:::::::::::::::::::::::::::::::
Uncheck all the field (checkbox)
:::::::::::::::::::::::::::::::
*/
function uncheckAll(field)
{
    if (field)
    {
        if (field.length>1)
        {
            for (i = 0; i < field.length; i++)
                field[i].checked = false ;
        }
        else   field.checked=false;
    }

}


/*
:::::::::::::::::::::::::::::::
disable  all the field (checkbox)
:::::::::::::::::::::::::::::::
*/
function disableAll(field, flag)
{
   if (field)
   {
     if (field.length>1)
     {
         for (i = 0; i < field.length; i++)
         {
            field[i].disabled = flag ;
         }
     }
     else field.disabled=flag;
   }
}

function gotoPage(pageNum,sort,lockedView){
       //if(pageNum=="") return;
       document.gotoPageForm.page.value=pageNum;
       document.gotoPageForm.sort.value=sort;
       document.gotoPageForm.lockedView.value=lockedView;
//       if (navigator.appName == 'Microsoft Internet Explorer') {
//            document.forms.gotoPageForm.submit();
//       }else {
            setTimeout('document.forms.gotoPageForm.submit();',10);
//       }
}


function hasSubmit(){
    if(!submitted) {
        submitted = true;
        return false;
    }else{
        if(!displaySubmittedMsg){
            alert("You have already submitted the form. You cannot submit it again.");
            displaySubmittedMsg=true;
        }
        return true;
    }
}

function changeDefaultPage(value1) {
   var url = '/classware/gradebookForwardAction.do?action=Update&preference='+value1;
   location.href=url;
}

function Mtools() {
	var msg='<div  width="100" height="100" > <b>Mastery Requirement Enabled </b> <br> Students need  to meet minimum mastery </br> requirement  before their scores will be<br>recorded into the gradebook</br> </div>';
	Tip(msg, BGCOLOR, '#FFFFFF',BORDERCOLOR, '#000000',FONTCOLOR,'000000');
}

function Qtools() {
	var msg='<div width="100" height="100" ><b> Quick Retake Enabled</b><br>Students only need to answer the</br> Questions that they have skipped<br>or previously answered incorrectly.</br> </div>';
	Tip(msg, BGCOLOR, '#FFFFFF',BORDERCOLOR, '#000000',FONTCOLOR,'000000');
}

function masteryPrefTip() {
	var msg='<div width="100" height="100" > Student must meet Mastery <br>Requirement before scores be </br>recorded in gradebook. </div>';
   Tip(msg, BGCOLOR, '#FFFFFF',BORDERCOLOR, '#000000',FONTCOLOR,'000000');
}

function quickRetakePrefTip()  {
	var msg='<div  width="100" height="100" > QUICK RETAKE will only make <br> students answer problems they </br> missed in previous attempts.  </div>';
	Tip(msg, BGCOLOR, '#FFFFFF',BORDERCOLOR, '#000000',FONTCOLOR,'000000');
}

function showRollover() {
	var msg='<div width="100" height="100" style="top:5; left:700; z-index:5">';
	msg = msg + '<span style=" color:#FF6600; font-size:13px;">Rollover message</span>';
	msg = msg + '<br/><br/><span style=" color:#000000; font-size:13px;">';
	msg = msg + 'Your instructor has enabled &quot;Quick Retake&quot; feature.';
	msg = msg + '<br/><br/>When you retake this assignment, you only need to work on questions';
	msg = msg + ' <br/>that you have skipped or answered incorrectly.';
	msg = msg + '<br/><br/>Questions that you answered correctly before and not shown here';
	msg = msg + ' <br/>will be counted for full credit when you submit this retake.';
	msg = msg + '</span></div>';
	Tip(msg, BGCOLOR, '#FFFFFF',BORDERCOLOR, '#000000',FONTCOLOR,'000000',ABOVE,'true');
}

function showChangeAssignDatesHelp() {

	var msg='Use <b>Change Dates Individually</b> to make a \
			unique change to the start or end date for\
			one or more assignments. Choose <b>Change\
			Selected Dates</b> and you will be asked to\
			make changes to more than one\
			assignment start or end date at-a-time.\
			<b>Change Dates Relatively</b> lets you push\
			one or more assignments backward or\
			forward down the timeline. Go to the help\
			section for more information.';
	Tip(msg, BALLOON, true, ABOVE, true,WIDTH, 270)
}

function showRepetitionHelp() {

	var msg = '<div style="width:380px; height:200px;padding: 12px; z-index:5">\
			  <p>Repetition controls how many times your students are allowed to repeat assignments and the rules around that.</p>\
			  <p>For assignments with more than one attempt, you can select two options</p>\
			  <ol>\
			  <li><b>MASTERY</b> allows you to set a level students must reach before their grades will post.</li>\
			  <li><b>QUICK RETAKE</b> will only make students answer problems they missed in previous attempts.</li>\
			  </ol>\
			  </div>';
	Tip(msg, BALLOON, true, ABOVE, true)
}

  function showAutoCollectHelp() {
	var msg = '<div style="width:280px; height:120px;padding: 10px; z-index:5">\
			  <p><b>NOTE:</b> System will automatically collect any student attempts\
			  which have not been submitted before the due date.\
			  For most accurate results when using the "Auto Collect" feature for any category,\
			  please set the repeatable assignment option in grade policy to "Best Attempt".\
			  </p></div>';
	Tip(msg, BALLOON, true, ABOVE, true)
}

function showRescheduleAssignmentsHelp() {

	var msg='Check this box if you want child sections\
			to be able to change the start dates and\
			end dates of required assignments.';
	Tip(msg, BALLOON, true, ABOVE, true,WIDTH, 270)
}

function showAddNewAssignmentsHelp() {

	var msg='Check this box if you want child sections\
			to be able to create new assignments.';
	Tip(msg, BALLOON, true, ABOVE, true,WIDTH, 270)
}

function showModifyGradebookPoliciesHelp() {

	var msg='Check this box if you want child sections\
			to be able to various characteristics of\
			how assignments are graded.';
	Tip(msg, BALLOON, true, ABOVE, true,WIDTH, 270)
}

  function validateDate(dateField, assignNo) {
    dateField.value = dateField.value.split(' ').join('');	
	var err = "";
	var errorMessage = 'Please enter valid date in mm/dd/yyyy format';
	if(assignNo != null && assignNo != ''){
	   var assignmentNumber = Math.floor(assignNo) + 1;
	   errorMessage = errorMessage 
	                + ' for Assignment No. '
	                + assignmentNumber
	                + ' .';
	}
	
	var RegExPattern = "^([1-9]|[1-9]|0[1-9]|1[0-2])/([1-9]|[0-2][1-9]|[1-3][0]|[3][1])/(20[0-2][0-9])$";
    if ((dateField.value.match(RegExPattern)) && (dateField.value!='')) {
      var month = dateField.value.substring(0, dateField.value.indexOf('/'));
	  var monthIndex = dateField.value.indexOf('/') + 1;
	  if(month.length == 1){//single digit
        month = '0' + month;
	  }
	  
	  var day = dateField.value.substring(monthIndex, dateField.value.indexOf('/',monthIndex));
	  var dayIndex = dateField.value.indexOf('/',monthIndex) + 1;
	  if(day.length == 1){//single digit
        day = '0' + day;
	  }

	  var year = dateField.value.substring(dayIndex);
	  dateField.value = month + "/" + day + "/" + year;
    } else {
	    alert(errorMessage);
	    err = errorMessage;
    }
    return err; 
  }
  
function validateDate(dateField) {
    dateField.value = dateField.value.split(' ').join('');	
	var err = "";
	var errorMessage = 'Please enter valid date in mm/dd/yyyy format';
	var RegExPattern = "^([1-9]|[1-9]|0[1-9]|1[0-2])/([1-9]|[0-2][1-9]|[1-3][0]|[3][1])/(20[0-2][0-9])$";
    if ((dateField.value.match(RegExPattern)) && (dateField.value!='')) {
      var month = dateField.value.substring(0, dateField.value.indexOf('/'));
	  var monthIndex = dateField.value.indexOf('/') + 1;
	  if(month.length == 1){//single digit
        month = '0' + month;
	  }
	  
	  var day = dateField.value.substring(monthIndex, dateField.value.indexOf('/',monthIndex));
	  var dayIndex = dateField.value.indexOf('/',monthIndex) + 1;
	  if(day.length == 1){//single digit
        day = '0' + day;
	  }

	  var year = dateField.value.substring(dayIndex);
	  dateField.value = month + "/" + day + "/" + year;
    } else {
	    return errorMessage;
    }
    return ""; 
  }  

  function validateHour(hourField, assignNo) {
    var err = "";
    var errorMessage = 'Please enter valid hour';
	var RegExPattern = "^([1-9]|0[1-9]|1[0-2])$";
	if(assignNo != null && assignNo != ''){
	   var assignmentNumber = Math.floor(assignNo) + 1;
	   errorMessage = errorMessage 
	                + ' for Assignment No. '
	                + assignmentNumber;
	}
	if ((hourField.value.match(RegExPattern)) && (hourField.value!='')) {
      var hour = hourField.value;
	  if(hour.length == 1){//single digit
        hour = '0' + hour;
	  }
	  
	  hourField.value = hour;
    } else {
	    alert(errorMessage);
	    err = errorMessage;
	}
	return err; 
  }
  
  function validateHour(hourField) {
    var err = "";
    var errorMessage = 'Please enter valid hour';
	var RegExPattern = "^([1-9]|0[1-9]|1[0-2])$";
	if ((hourField.value.match(RegExPattern)) && (hourField.value!='')) {
      var hour = hourField.value;
	  if(hour.length == 1){//single digit
        hour = '0' + hour;
	  }
	  
	  hourField.value = hour;
    } else {
	    return errorMessage;
	}
	return ""; 
  }  
  
    function validateMinute(minuteField, assignNo) {
    var err = "";
    var errorMessage = 'Please enter valid minute';
	var RegExPattern = "^([0][0]|[1][5]|[3][0]|[4][5])$";
	if(assignNo != null && assignNo != ''){
	   var assignmentNumber = Math.floor(assignNo) + 1;
	   errorMessage = errorMessage 
	                + ' for Assignment No. '
	                + assignmentNumber;
	}
	errorMessage = errorMessage + '.Valid values are 00,15,30,45';
	
	if ((minuteField.value.match(RegExPattern)) && (minuteField.value!='')) {      
	  var minute = minuteField.value;	  
	  minuteField.value = minute;
    } else {
	    alert(errorMessage);
	    err = errorMessage;
	}
	return err; 
  }
  
  function validateMinute(minuteField) {
    var err = "";
    var errorMessage = 'Please enter valid minute. Valid values are 00,15,30,45';
	var RegExPattern = "^([0][0]|[1][5]|[3][0]|[4][5])$";
	
	if ((minuteField.value.match(RegExPattern)) && (minuteField.value!='')) {      
	  var minute = minuteField.value;	  
	  minuteField.value = minute;
    } else {
	    return errorMessage;
	}
	return ""; 
  }  
  
  function validateFormDates_editCourse(f) {
	/* checks startDate, endDate, extendDate fields; makes sure they are valid dates in the right order. */
	// startDate
	var err = "";
	var errMsg = "";
	
	errMsg = validateDate(f.editCourseStartDate);
    if(errMsg != ""){
      err += "Please enter valid Course Start Date in mm/dd/yyyy format\n";
    }
    
	errMsg = validateHour(f.editCourseStartHour);
    if(errMsg != ""){
      err += "Please enter valid Course Start Hour\n";
    }
	
	errMsg = validateMinute(f.editCourseStartMinute);
	if(errMsg != ""){
	  err += "Please enter valid Course Start minute. Valid values are 00,15,30,45.\n";
	}
	
	errMsg = validateDate(f.editCourseEndDate);
	if(errMsg != ""){
	  err += "Please enter valid Course End Date in mm/dd/yyyy format\n";
	}
	
	errMsg = validateHour(f.editCourseEndHour);
	if(errMsg != ""){
	  err += "Please enter valid Course End Hour\n";
	}
	
	errMsg = validateMinute(f.editCourseEndMinute);
	if(errMsg != ""){
	  err += "Please enter valid Course End minute. Valid values are 00,15,30,45.\n";
	}
	
	if(err != ''){
	  return err;
	}
	
	var badDay="";
	badDay = validateMonthLength(f.editCourseStartDate.value.substr(0,2), f.editCourseStartDate.value.substr(3,2),f.editCourseStartDate.value.substr(6,4));
	if (badDay != "") {return badDay};
	
	badDay = validateMonthLength(f.editCourseEndDate.value.substr(0,2), f.editCourseEndDate.value.substr(3,2),f.editCourseEndDate.value.substr(6,4));
	if (badDay != "") {return badDay};
	
	
	// date order
	var newStartHour = f.editCourseStartHour.value;
    var newEndHour = f.editCourseEndHour.value;
    var startAmPm = f.editCourseStartAmPm.value;
    var endAmPm = f.editCourseEndAmPm.value;
    if(startAmPm == 'AM' && newStartHour >= '12'){
      newStartHour = Math.floor(newStartHour) - 12;
      if(newStartHour < 10){
        newStartHour = '0' + newStartHour;
      } 
    } else if(startAmPm == 'PM' && newStartHour != '12'){
      newStartHour = Math.floor(newStartHour) + 12;
    }
    
    if(endAmPm == 'AM' && newEndHour >= '12'){
      newEndHour = Math.floor(newEndHour) - 12;
      if(newEndHour < 10){
        newEndHour = '0' + newEndHour;
      }
    } else if(endAmPm == 'PM' && newEndHour != '12'){
      newEndHour = Math.floor(newEndHour) + 12;
    }
	var d1 = f.editCourseStartDate.value.substr(6,4) + "" + f.editCourseStartDate.value.substr(0,2) + "" + f.editCourseStartDate.value.substr(3,2) + "" + newStartHour + "" + f.editCourseStartMinute.value;
	var d11 = f.editCourseStartDate.value.substr(6,4) + "" + f.editCourseStartDate.value.substr(0,2) + "" + f.editCourseStartDate.value.substr(3,2);
	var d2 ="";
	var d21="";
	if(f.editCourseEndDate)
	{
	     d2 = f.editCourseEndDate.value.substr(6,4) + "" + f.editCourseEndDate.value.substr(0,2) + "" + f.editCourseEndDate.value.substr(3,2) + "" + newEndHour + "" + f.editCourseEndMinute.value;
	     d21 = f.editCourseEndDate.value.substr(6,4) + "" + f.editCourseEndDate.value.substr(0,2) + "" + f.editCourseEndDate.value.substr(3,2);
    }

    var d4 = "";
    var d5 = "";
    if(f.courseStartDate) {
        d4 = f.courseStartDate.value.substring(0, 8);
    }

    if(f.courseEndDate) {
        d5 = f.courseEndDate.value.substring(0, 8);
    }

	if (d2!="" && d1 >= d2) {
		return "The Course End Date must be after the Course Start Date.";
	}
	
	/*
	if(f.courseStartDate && (d11 < d4)) {
	    return "The assignment start or due dates are out of course start or end date bounds.";
	}

	if(f.courseEndDate && (d21 > d5)) {
	    return "The assignment start or due dates are out of course start or end date bounds.";
	}
	*/ 
	
	return ""; // should be blank
	
}
  
  function validateFormDates_RestoreArchive(f) {
	/* checks startDate, endDate, extendDate fields; makes sure they are valid dates in the right order. */
	// startDate
	var err = "";
	var errMsg = "";
	
	errMsg = validateDate(f.restoreStartDate);
    if(errMsg != ""){
      err += "Please enter valid New Start Date in mm/dd/yyyy format\n";
    }
    
	errMsg = validateHour(f.restoreStartHour);
    if(errMsg != ""){
      err += "Please enter valid New Start Hour\n";
    }
	
	errMsg = validateMinute(f.restoreStartMinute);
	if(errMsg != ""){
	  err += "Please enter valid New Start minute. Valid values are 00,15,30,45.\n";
	}
	
	errMsg = validateDate(f.restoreEndDate);
	if(errMsg != ""){
	  err += "Please enter valid New End Date in mm/dd/yyyy format\n";
	}
	
	errMsg = validateHour(f.restoreEndHour);
	if(errMsg != ""){
	  err += "Please enter valid New End Hour\n";
	}
	
	errMsg = validateMinute(f.restoreEndMinute);
	if(errMsg != ""){
	  err += "Please enter valid New End minute. Valid values are 00,15,30,45.\n";
	}
	
	if(err != ''){
	  return err;
	}
	
	var badDay="";
	badDay = validateMonthLength(f.restoreStartDate.value.substr(0,2), f.restoreStartDate.value.substr(3,2),f.restoreStartDate.value.substr(6,4));
	if (badDay != "") {return badDay};
	
	badDay = validateMonthLength(f.restoreEndDate.value.substr(0,2), f.restoreEndDate.value.substr(3,2),f.restoreEndDate.value.substr(6,4));
	if (badDay != "") {return badDay};
	
	
	// date order
	var newStartHour = f.restoreStartHour.value;
    var newEndHour = f.restoreEndHour.value;
    var startAmPm = f.restoreStartAmPm.value;
    var endAmPm = f.restoreEndAmPm.value;
    if(startAmPm == 'AM' && newStartHour >= '12'){
      newStartHour = Math.floor(newStartHour) - 12;
      if(newStartHour < 10){
        newStartHour = '0' + newStartHour;
      } 
    } else if(startAmPm == 'PM' && newStartHour != '12'){
      newStartHour = Math.floor(newStartHour) + 12;
    }
    
    if(endAmPm == 'AM' && newEndHour >= '12'){
      newEndHour = Math.floor(newEndHour) - 12;
      if(newEndHour < 10){
        newEndHour = '0' + newEndHour;
      }
    } else if(endAmPm == 'PM' && newEndHour != '12'){
      newEndHour = Math.floor(newEndHour) + 12;
    }
	var d1 = f.restoreStartDate.value.substr(6,4) + "" + f.restoreStartDate.value.substr(0,2) + "" + f.restoreStartDate.value.substr(3,2) + "" + newStartHour + "" + f.restoreStartMinute.value;
	var d11 = f.restoreStartDate.value.substr(6,4) + "" + f.restoreStartDate.value.substr(0,2) + "" + f.restoreStartDate.value.substr(3,2);
	var d2 ="";
	var d21="";
	if(f.restoreEndDate)
	{
	     d2 = f.restoreEndDate.value.substr(6,4) + "" + f.restoreEndDate.value.substr(0,2) + "" + f.restoreEndDate.value.substr(3,2) + "" + newEndHour + "" + f.restoreEndMinute.value;
	     d21 = f.restoreEndDate.value.substr(6,4) + "" + f.restoreEndDate.value.substr(0,2) + "" + f.restoreEndDate.value.substr(3,2);
    }

	if (d2!="" && d1 >= d2) {
		return "The New Course End Date must be after the New Course Start Date.";
	}
	
	return ""; // should be blank
  }  

function getHourIn24Format(hour, displayAmPm){
  if(displayAmPm == 'AM' && hour >= '12'){
    hour = Math.floor(hour) - 12;
    if(hour < 10){
	  hour = '0' + hour;
    }
  } else if(displayAmPm == 'PM' && hour != '12'){
    hour = Math.floor(hour) + 12;
  }
  return hour;
}





 //script functions for date validation.
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    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;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

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 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   }
   return this
}

function isValidDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	/*if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}*/
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

/* Added by Sujoy Bhattacharya for Edit Master Syllabus */
function getDomAdapter()
{
	var adapter = '';
	if ('undefined' != typeof ActiveXObject) {
		adapter = 'MS';
	} else if ('undefined' != typeof document
		&&document.implementation
		&& document.implementation.createDocument
		&& 'undefined' != typeof DOMParser)
	{
		adapter = 'default';
	}
	switch (adapter) {
		case 'MS':
			return new (function () {
				this.createDocument = function () {
					var names = ["Msxml2.DOMDocument.6.0",
						"Msxml2.DOMDocument.3.0", "MSXML2.DOMDocument",
						"MSXML.DOMDocument", "Microsoft.XMLDOM"];
					for (var key in names) {
						try {
							return new ActiveXObject(names[key]);
						} catch (e) {}
					}
					throw new Error('Unable to create DOMDocument');
				};
				this.serialize = function (doc) {
					return doc.xml;
				};
				this.parseXml = function (xml) {
					var doc = this.createDocument();
					if (!doc.loadXML(xml)) {
						throw new Error('Parse error');
					}
					return doc;
				};
			})();
		case 'default':
			return new (function () {
				this.createDocument = function () {
					return document.implementation.createDocument("", "", null);
				};
				this.serialize = function (doc) {
					return new XMLSerializer().serializeToString(doc);
				};
				this.parseXml = function (xml) {
					var doc = new DOMParser().parseFromString(xml, "text/xml");
					if ("parsererror" == doc.documentElement.nodeName) {
						throw new Error('Parse error');
					}
					return doc;
				};
			})();
		default:
			throw new Error('Unable to select the DOM adapter');
	}
};

function getSelectAssignment(selObj){
			  if(selObj.className == 'master_assignment_selected'){
				selObj.className = 'master_assignment';
			  }else{
				selObj.className = 'master_assignment_selected';
			  }
			}
			
			function createNewAssignmentNode(targetSectionId,textNodeValue,divId){
			  var targetDivObj = document.getElementById(targetSectionId);
			  var newDiv = document.createElement('div');
			  var text = document.createTextNode(textNodeValue);
			  newDiv.id = divId;
			  newDiv.className = 'master_assignment';
			  newDiv.appendChild(text);
			  newDiv.onclick = new Function('getSelectAssignment(this)');
			  targetDivObj.appendChild(newDiv);
			}
			
			function addToSection(sourse, dest){
			  masterObj = document.getElementById(sourse);
			  //alert(masterObj.childNodes[0].tagName);
			  //alert(masterAssignmentNo);
			  var nodeList = masterObj.childNodes;
			  var removeAssignmentList = Array();
			  for(var i=0; i < nodeList.length; i++){
			    if(masterObj.childNodes[i].nodeName == 'DIV'){
				  if(masterObj.childNodes[i].className == 'master_assignment_selected'){
					createNewAssignmentNode(dest,masterObj.childNodes[i].firstChild.nodeValue, masterObj.childNodes[i].id);
					//masterObj.removeChild(masterObj.childNodes[i]);
					removeAssignmentList.push(masterObj.childNodes[i]);
				  }
				}
			  }
			  for(j=0; j < removeAssignmentList.length; j++){
				masterObj.removeChild(removeAssignmentList[j]);
			  } 
			}
/* Added by Sujoy Bhattacharya for Edit Master Syllabus ends */

function changeCourseMgmtHeader(pageTitle, subTitle){
	var el_pageTitle=document.getElementById("PageTitle");
	if (el_pageTitle!=null){
	  if(subTitle != null && subTitle != ""){
	      el_pageTitle.innerHTML = '<span style="color:B1B1B1;font-weight:bold;font-size:15px;">' + pageTitle + '</span>\
	                                <br/>\
	                                <span style="font-size:17pt;color: #474646;font-family:Arial,Helvetica,sans-serif;font-weight: bold;text-align: left;vertical-align: middle;">' + subTitle + '</span>';
	  } else {
	      el_pageTitle.innerHTML = '<span style="font-size:17pt;color: #474646;font-family:Arial,Helvetica,sans-serif;font-weight: bold;text-align: left;vertical-align: middle;">' + pageTitle + '</span>';
	    
	  }
	}
}

  function openAssignment(alaid, assignmentId){
    var url = "/classware/ala.do?alaid=ala_" + alaid + "&assignmentId=" + assignmentId;
    window.location = url;
  }

