// epc.js

   var req;
  // ePC child window
   var ePCChildWd;
   // eTE child window
   var eTEChildWd;
 
   
 // getting the cookie    
 function get_cookie(Name) {
	var search = Name + "=";
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
		// if cookie exists
		if (offset != -1) {
			offset += search.length;
			// set index of beginning of value
			end = document.cookie.indexOf(";", offset);
			// set index of end of cookie value
			if (end == -1) {
			 	end = document.cookie.length;
				returnvalue=unescape(document.cookie.substring(offset, end));
			}
		}
	}
	return returnvalue;
 }

	function footerLinkWindow(url) {
		var legal =window.open(url,'legal','toolbar=no,menubar=no,scrollbars,resizable,location=no,status,width=800,height=500');
		legal.focus();
	}
	function tourLinkWindow(url) {
		var legal =window.open(url,'legal','toolbar=no,menubar=no,scrollbars,resizable,location=no,status,width=800,height=500');
		legal.focus();
	}
	
	function tourLinkTeacherLanding() {
		// we have to identify the user is eval user or not. Check the user is eval or not based on cookie value
		var loginTypeValue = get_cookie('loginTypeCookie');

		if (loginTypeValue == 'eval') {
			// This is EVAL user
			tourLinkWindow('/content/help/html/eval/path3.html');
		} else {
			// This is Regular ePC user
			tourLinkWindow('/content/help/html/path3.html');
		}
	}
		
	function doLogout() {
		//Reverted back for defect 567 as it got defered for ePC 1.2
		/*added for defect 567
		alert("You have successfully logged out. Thank you for using Harcourt eProducts!");
		*/
		if (closeWindow()==true)  {
			document.location.href="logout.do";
		}
	}
                                                                
    function newMyWindow(url, name, w, h) {
		var l = (screen.availWidth-10 - w) / 2;
		var t = (screen.availHeight-20 - h) / 2;
		var features = "width="+w+",height="+h+",left="+l+",top="+t;
		features += ",screenX="+l+",screenY="+t;
		features += ",scrollbars=0,resizable=1,location=0";
		features += ",menubar=0,toolbar=0,status=0";
		ePCChildWindow = window.open(url, name, features);
		ePCChildWindow.close();
	}
    
	function closeWindow() {
  	  if (get_cookie("ePCChildView")=="on" || get_cookie("eTEView")=="on") {

		if (confirm("You chose to exit the system. All windows will be closed.\nDo you want to continue?")) {
			if (get_cookie("ePCChildView")=="on") {
				// Let's remove a cookie to identify child window is opened
				document.cookie="ePCChildView=off";
				newMyWindow("/WEB-INF/tiles/planner/close.html","ePCChildView",1000,688);
			}
	
			if (get_cookie("eTEView")=="on") {
	
				// Let's remove a cookie to identify child window is opened
				document.cookie="eTEView=off";
				newMyWindow("/WEB-INF/tiles/planner/close.html","eTE",1000,688);
			}
			return true;
		} else {
			return false;
		}

	  }
  	  return true;
	}
	
 function getElementByIdAllBrowsers(elementId)
  {
  	var elementObject = document.getElementById(elementId);

  	if (elementObject == null)
  	{
  	  var elements = document.getElementsByName(elementId);
  	  if (elements != null)
  	  {
        elementObject = elements[0];
  	  }
  	}

	return elementObject;
  }
   
    /**
	 Added Newly For The Enhancement Support Of Private Organization 
	 This function will invoke the AJAX method to update the specified drop down box.
	 This will be usually called to load the schools both the private and public schools in 
	 the Login Page after a district is selected.
	*/
    function updateListOptionsPrivateDistrict(selection,action, elementToUpdate,state)
    {
		var element = getElementByIdAllBrowsers(elementToUpdate);  
	    element.disabled = true;
   	    organizationId = selection.options[selection.selectedIndex].value;
	       
		/* Getting the Name Of the Private Organization Selected */
		var privateOrganization = selection.options[selection.selectedIndex].innerHTML;

		   /* Passing extra parameters OrganizationType and State so that to differentiate
		      between Public and private organization and also for retireving the private 
		      schools we need the selected state also so only we are passing selected state
		      also along with the parameter. This is the usual scenario for selecting the public 
		      schools given a district 
		  */
	    var url = "xml/retrieveOrganizationXML?method="+action+"&elementId="+elementToUpdate+"&requestId="
	    		   +organizationId+"&organizationType=public";//&state="+state;

		 /* The switch case is used to see if the selected district is any of the following district if 
		    so then we are passing different paramters to the URL so that private schools are retreived
		 */  
		   switch (organizationId)
		   {
		      case '01':
              case '02':
              case '03':
              case '04':
              case '06':
              case '08':
			  case '09':	
              case '10':
              case '11':
              case '12':
              case '13':
              case '14':
              case '15':
              case '16':
              case '17':
	 		      url = "xml/retrieveOrganizationXML?method="+action+"&elementId="+elementToUpdate+"&requestId="
			            +organizationId+"&organizationType=private&state="+state;
			   break;	
			}
			
		 
		  /* switch (privateOrganization)
		   {
		      case 'State Department':
              case 'State Operated School':       
              case 'County Center':        
	 		  case 'County Operated School':     
			  case 'Public School District':         
	    	  case 'Canadian District':    
		      case 'Public School':        
      		  case 'Canadian Public School':      
   		      case 'Private School':        
        	  case 'Catholic School':      
     		  case 'Canadian Private School':     
	       	  case 'College':      
        	  case 'Bureau of Indian Affairs School':        
		      case 'Regional Center':     
        	  case 'Diocesan Office':      
        	  case 'Library':       
		      case 'Day Care Center':
			   url = "xml/retrieveOrganizationXML?method="+action+"&elementId="+elementToUpdate+"&requestId="
			         +organizationId+"&organizationType=private&state="+state;
			   break;	
			}
			*/
	     
	    
	      if (window.XMLHttpRequest) {
	         req = new XMLHttpRequest();
		  } else if (window.ActiveXObject) {
	        req = new ActiveXObject("Microsoft.XMLHTTP");
	      }
		  
	     req.open("GET", url, true);
	     req.onreadystatechange = optionFetchCallback;
	     req.send(null);     
    } 
   
    /*
	 This function will invoke the AJAX method to update the specified drop down box	
	*/
    function updateListOptions(selection,action, elementToUpdate)
    {
		var element = getElementByIdAllBrowsers(elementToUpdate);  
	    element.disabled = true;
    	organizationId = selection.options[selection.selectedIndex].value;

		/* Modified For The Enhancement Support Of Private Organization 
		   Passing extra parameters OrganizationType and State as we are setting the values
		   For these in the OrganizationXMLFetchServlet.java file otherwise Null Pointer exception 
		   arises */
	    var url = "xml/retrieveOrganizationXML?method="+action+"&elementId="+elementToUpdate+"&requestId="+organizationId;
	    //&organizationType=public&state=state";
	    if (window.XMLHttpRequest) {
	         req = new XMLHttpRequest();
		  } else if (window.ActiveXObject) {
	        req = new ActiveXObject("Microsoft.XMLHTTP");
	      }
		 req.open("GET", url, true);
	     req.onreadystatechange = optionFetchCallback;
	     req.send(null);     
    } 
    
    function enableElement(sourceElem,targetElem)
    {
        if (sourceElem.selectedIndex > 0)
           targetElem.disabled = false;    
    
    }

   /*
	 This function is the call back function for the ajax response
	*/
   function optionFetchCallback() 
  {
    // check whether it is a good response
     if (req.readyState == 4) {
         if (req.status == 200) {

			// Get nodes from XML
		    var nodes=req.responseXML.getElementsByTagName("option");   
		    var elementIdNode=req.responseXML.getElementsByTagName("elementId");   
		    var elementId = getNodeText(elementIdNode.item(0));

			// enable element
			var element = getElementByIdAllBrowsers(elementId);
			element.disabled = false;

			// Remove all option if the select box to update
		    removeAllOptionsComponent(elementId);

            for (i=0; i<nodes.length; i = i + 1)
	        {   

	            var optionValue = getNodeText(nodes.item(i).childNodes.item(0));  
	            var optionText = getNodeText(nodes.item(i).childNodes.item(1));  

	           addOptionComponent(optionValue,
	                	 optionText,
						 elementId);
	          }
	         } else {
// TODO - add error handle	when response is bad
// request return error code - not 200	        	 
	         }	 
	     }
   }
   /*
	 This function adds a new option to a dropdown box
	*/
   function addOptionComponent(optionValue,optionText,elementId)
	 {
	 
	 //alert("optionValue >"+optionValue+"< optionText >"+optionText+"< elementId >"+elementId);
	 
	  var elSel = getElementByIdAllBrowsers(elementId);
	  var elOptNew = document.createElement('option');
	     elOptNew.text = optionText;
	     elOptNew.value = optionValue;    

	     try {
	      elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
	     }
	     catch(ex) {
	      elSel.add(elOptNew); // IE only
	     }

	     if (elSel.selectedIndex < 0)
	     {
	       elSel.selected = true;
	     }
	  
	 }
	 /*
	 This function removes all options from the dropdown box
	*/
	 function removeAllOptionsComponent(elementId)
	 {
	  var elSel = getElementByIdAllBrowsers(elementId);
	    var i;
	    for (i = elSel.length - 1; i>=0; i--) 
	    {
	        elSel.remove(i);   
	    }
	 }
 
    /*
	 This function gets the text of a node
	*/
   function getNodeText(oNode)
	 {
	  var sText = "";
	  for (var i =0; i < oNode.childNodes.length; i++)
	  {
	   if (oNode.childNodes[i].hasChildNodes())
	   {
	    sText += getNodeText(oNode.childNodes[i]);
	   } else
	   {
	    sText += oNode.childNodes[i].nodeValue;
	   }
	  }
	  return sText;
	}
	
    /**************************************************************************
  	         C L A S S     M A N A G E M E N T     J A V A S C R I P T
	***************************************************************************/
	
/*
	 This function will invoke the AJAX method to update the specified drop down box	
	*/
    function updateProductTable(selection)
    {
    	  var gradeId = document.getElementById("gradeLevel").value;
//          var schoolId = document.getElementById("schoolId").value;		  
          var teacherId = document.getElementById("teacherId").value;
          
          //alert("gradeId >"+gradeId+"< teacherId >"+teacherId);
//		  if (gradeId != null && gradeId != "0" && schoolId != null)
//		  {
		       //organizationId = selection.options[selection.selectedIndex].value;
		       
//		       var url = "xml/retrieveProductXML?gradeId="+gradeId+"&schoolId="+schoolId+"&teacherId="+teacherId;
			var url = "xml/retrieveProductXML?gradeId="+gradeId+"&teacherId="+teacherId;
		//alert(url);
		
			  if (window.XMLHttpRequest) {
		         req = new XMLHttpRequest();
		     
			  } else if (window.ActiveXObject) {
		        req = new ActiveXObject("Microsoft.XMLHTTP");
		      } 
		     
		     req.open("GET", url, true);
		     req.onreadystatechange = productFetchCallback;
		     req.send(null);     
//		  }
    } 
    
   
 

   /*
	 This function is the call back function for the ajax response
	*/
   function productFetchCallback() 
  {
    // check whether it is a good response
     if (req.readyState == 4) {
         if (req.status == 200) {

			// Get nodes from XML
		    var nodes=req.responseXML.getElementsByTagName("product");   

			// Remove all option if the select box to update
		    removeProductTableRows();
		
            for (i=0; i<nodes.length; i = i + 1)
	        {     
	            var productId = getNodeText(nodes.item(i).childNodes.item(0));  
	            var productName = getNodeText(nodes.item(i).childNodes.item(1));  
	            var isbn = getNodeText(nodes.item(i).childNodes.item(2));  
	 
	           addProductTableRow(productId,
	                	          productName,
						          isbn);
	          }
	         } else {
// TODO add error handler to bad response	        	 
	         }
		         
	     }
   }
    
 function addProductTableRow(productId,
	                	      productName,
						      isbn)
  {
	   tableElement = document.getElementById("programsProducts");
	   tBodyElement = document.getElementById("programsProductsBody");
       currRow = document.createElement("TR");
       currRow.align = "left";
	   currRow.valign="middle";

	   // Column 1
       currCell = document.createElement("TD");
	   currCell.align="center";
	   currCell.className ="cellContent";
	   var chkbox = document.createElement("INPUT");
	   chkbox.type = "CHECKBOX";	
	   chkbox.id = "classProducts"; 
       chkbox.name = "classProducts"; 
       chkbox.value = productId;  

       currCell.appendChild(chkbox);
	   currID = "Col1"+productId;
       currCell.setAttribute("id",currID);
       currRow.appendChild(currCell);

	   // Column 2
       currCell = document.createElement("TD");
	   currCell.className ="cellContent";
	   currText = document.createTextNode(productName);
       currCell.appendChild(currText);
	   currID = "Col2"+productId;
       currCell.setAttribute("id",currID);
       currRow.appendChild(currCell);

	   // Column 3
       currCell = document.createElement("TD");
	   currCell.align="center";
	   currCell.className ="cellContent";
	   currText = document.createTextNode(isbn);
       currCell.appendChild(currText);
	   currID = "Col3"+productId;
       currCell.setAttribute("id",currID);
       currRow.appendChild(currCell);
        

       tBodyElement.appendChild(currRow);			
	   curRowID = "Row" + productId;
	   currRow.setAttribute("id",curRowID);
  	   tableElement.appendChild(tBodyElement);

  }
    	
    function removeProductTableRows()
    {
  	   tBodyElement = document.getElementById("programsProductsBody");
  	   if (tBodyElement.childNodes.length >1)
  	   {
	  	   for (var i =0; i < tBodyElement.childNodes.length; i++)
		  {
		     if(tBodyElement.childNodes[i].id != "headerRow")
		     {
		       tBodyElement.removeChild(tBodyElement.childNodes[i]);
		     }
		  }
		  removeProductTableRows();
		}
    }
    
    function addAllStudentsToRoster()
    {
      addAllSourceToTarget("studentList","classStudents");
    }
    
    function addSelectedStudentsToRoster()
    {
       	addSelectedSourceToTarget("studentList","classStudents");
	}

    function removeAllStudentsToRoster()
    {
      addAllSourceToTarget("classStudents","studentList");
    }
    
    function removeSelectedStudentsToRoster()
    {
 		addSelectedSourceToTarget("classStudents","studentList");     	
	}
	
    function addAllSourceToTarget(source,target)
    {
      var elSel = document.getElementById(source);
	  var targetList = document.getElementById(target);
	  var new_list = new Array(elSel.length);
	  var emptyOptionValue = null;
	  var emptyOptionText = null;
	  removeEmptyOption(target);
	  var j=0;
	  sortSelect(target);
	  for (i = elSel.length - 1; i>=0; i--) {
		
		  addOptionComponent(elSel[i].value,elSel[i].text,target);	
			document.getElementById(source).remove(i);	
			/* added for defect 1579 */
    	/*new_list[j] = elSel[i].text;
    	j++;*/
	  }
	 sortList(target);
	  
	  
/* added for defect 1579 */
	  			
	 /* for (i = targetList.length - 1; i>=0; i--) {
		new_list[j] = targetList[i].text;
		j++;
	  }
	  
	  new_list.sort();

	  var z;
	  var flag = 0;
	    for (i = 0; i < new_list.length; i++) {
	        flag = 0;
	        for (z = elSel.length - 1; z>=0; z--) {
	            if (new_list[i] == elSel[z].text){
			          if (!targetOptionExists(target, new_list[i]))
			          {
			    	    addOptionComponent(elSel[z].value,elSel[z].text,target);	
			    	    flag = 1;
			    	    document.getElementById(source).remove(z);		 	    
			      	  } 
			      	  break;
		    	}
		    }
		    if(flag == 0){
			    for (z = targetList.length - 1; z>=0; z--) {
		            if (new_list[i] == targetList[z].text){
				          if (!targetOptionExists(target, new_list[i]))
				          {
				    	    addOptionComponent(targetList[z].value,targetList[z].text,target);	
				    	    document.getElementById(target).remove(z);		 	    
				      	  } 
				      	  break;
			    	}
			    }
		    }
	    }*/
	    	     
    }

/*added for defect 1579 */
    
function sortList(target) 
{ 
	var lb = document.getElementById(target); 
	arrTexts = new Array(); 
	for(i=0; i<lb.length; i++) { 
	     arrTexts[i] = lb.options[i].text+':'+lb.options[i].value; 
	} 
	arrTexts.sort(function(x,y){ 
      var a = String(x).toUpperCase(); 
      var b = String(y).toUpperCase(); 
      if (a > b) 
         return 1 
      if (a < b) 
         return -1 
      return 0; 
    }); 
	for(i=0; i<lb.length; i++) { 
	     el = arrTexts[i].split(':'); 
	     lb.options[i].text = el[0]; 
	     lb.options[i].value = el[1]; 
	 } 
}
    
     function targetOptionExists(target, option)
     {
	  var targetOptionExistsFlag = false;
	  
	  if (option != null && target != null)
	  {
		  var elSel = document.getElementById(target);
	
		    var i;
		    for (i = 0; i < elSel.length; i++) 
		    {
		        if (elSel[i].value != "" && elSel[i].value == option.value)
		        {
		    	  targetOptionExistsFlag = true;
		    	  
		    	} 
		    }
		}    	
	    return targetOptionExistsFlag;	
    }
   
      
    function addSelectedSourceToTarget(source,target)
    {
	  var elSel = document.getElementById(source);
	  var targetList = document.getElementById(target);
	  removeEmptyOption(target);
	  var new_list = new Array(elSel.length);
	  var emptyOptionValue = null;
	  var emptyOptionText = null;
	  var i;
	  var j = 0;
	  
	  for (i = elSel.length - 1; i>=0; i--) {
        if(elSel[i].value != "" && elSel[i].selected){
        	//Added for defect 1429
			addOptionComponent(elSel[i].value,elSel[i].text,target);	
			document.getElementById(source).remove(i);	
			/* Commented for Defect 1429
			new_list[j] = elSel[i].text;
			j++; */
        }
	  }
	  
	  sortSelect(targetList);
	  
	  
  	  /* Commented for Defect 1429
	  if(targetList.length > 0){
	      for (i = targetList.length - 1; i>=0; i--) {
			new_list[j]= targetList[i].text;
			j++;
	  	  }
	  }
		  
      new_list.sort(); 

	    var z;
	    var flag = 0;
	    for (i = 0; i < j; i++) {
	        flag = 0;
	        for (z = elSel.length - 1; z>=0; z--) {
	            if (new_list[i] == elSel[z].text){
			          if (!targetOptionExists(target, new_list[i]))
			          {
			    	    addOptionComponent(elSel[z].value,elSel[z].text,target);	
			    	    flag = 1;
			    	    document.getElementById(source).remove(z);		 	    
			      	  } 
			      	  break;
		    	}
		    }
		    if(flag == 0){
			    for (z = targetList.length - 1; z>=0; z--) {
		            if (new_list[i] == targetList[z].text){
				          if (!targetOptionExists(target, new_list[i]))
				          {
				    	    addOptionComponent(targetList[z].value,targetList[z].text,target);	
				    	    document.getElementById(target).remove(z);		 	    
				      	  } 
				      	  break;
			    	}
			    }
		    }
	    } */
	    
   }
   
   function sortSelect(obj) {
    var o = new Array();
    if (!hasOptions(obj)) { return; }
    for (var i=0; i<obj.options.length; i++) {
    	//alert("value"+ obj.options[i].text.toUpperCase());
        o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
        }
    if (o.length==0) { return; }
    o = o.sort(
        function(a,b) {
        	//alert("A"+a.text+" B"+b.text);
            if ((a.text+"") < (b.text+"")) { return -1; }
            if ((a.text+"") > (b.text+"")) { return 1; }
            return 0;
            }
        );

    for (var i=0; i<o.length; i++) {
        obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
        }
    }
    
    function hasOptions(obj) {
    if (obj!=null && obj.options!=null) {return true; }
     return false;
    }
     
    function getEmptyOption(elementId)
    {
      var elSel = document.getElementById(elementId);
	  
	  var emptyOption=null;
	  
	    var i;
	    for (i = elSel.length - 1; i>=0; i--) 
	    {
	        if (elSel[i].value == "")
	        {
	    	  emptyOption = elSel[i];
	    	} 
	   
	    }
	   
	   return emptyOption;
    }
   
    function removeEmptyOption(elementId)
    {
      var elSel = document.getElementById(elementId);
	  
	    var i;
	    for (i = elSel.length - 1; i>=0; i--) 
	    {
	        if (elSel[i].value == "")
	        {
	    	  elSel.remove(i);
	    	} 
	   
	    }	  
    }   

  
  function selectAllRosterStudents()
    {
	  var elSel = document.getElementById("classStudents");
	  
	    var i;
	    for (i = elSel.length - 1; i>=0; i--) 
	    {
	        if (elSel[i].value != "")
	        {
				elSel[i].selected = true;	    	
            } 
	       
	    }
	    
    }
    
    function openRosterWindow(url)
    {
       
    	window.open(url,'PR','toolbar=0,status=0,menubar=0,location=0,width=800,height=800');    
    
    }

	 function removeDropDownOptions(elementId)
	 {
	  var elSel = document.getElementById(elementId);
	    var i;
	    for (i = elSel.length - 1; i>=0; i--) 
	    {
	       if (elSel.value != "" && elSel.value != "0")
	       {
	        elSel.remove(i);   
	        }
	    }
	 }
	 
  function disableElement(elementId)
  {
  		var element = document.getElementById(elementId);  		
		element.disabled = true;  
  }
 
  function clearSubElements(target)
  {
    if (target == "districtId")
    {
    	removeDropDownOptions("schoolId");
	    removeDropDownOptions("teacherId");
    
	    disableElement("schoolId");
	    disableElement("teacherId");
	    
    } else if (target == "schoolId")
    {
   	    removeDropDownOptions("teacherId");
        disableElement("teacherId");
    }    
  }

  function submitFormAction(formId, action)
  {
  		var form = document.getElementById(formId);  		
  		form.action = action;
		
  }
  
   function submitFormResetAction(formId, action)
  {
  		var form = document.getElementById(formId);  		
  		form.action = action;
  		form.reset();
		
  }

 function submitSpecifiedForm(formId, action)
  {
  		var form = document.getElementById(formId);  		
  		form.action = action;		
  		form.submit();
  }
  
  /** added for defect 83*/
  function submitDoneFormAction(form){
  
	  var selectedStudents = form.classStudents.length;
	  
	  if(selectedStudents==0){
	  var conf = confirm("Do you wish to assign students to this class?");
	  
	  if(conf){
	  	return false;
	  	}
	  else{
	  	return true;
	  	}
	  }
  }
  
  function initializeFormSelects(form)
	 {
	    var elem;
 		for (var i=0; i < form.elements.length; i++)
 		{ 		    
 			elem = form.elements[i]; 			 		
 			if (elem.type == "select-one" && i==1)
 			{
 				elem.selectedIndex = 0; 			
 			} 		
 			if (elem.type == "select-one" && i>1)
 			{
 				elem.options.length = 1;
 				elem.selectedIndex = 0; 			
 			} 		
 		}
 		if (form.find)
 			form.find.disabled=true;
	 }
 
   function enableButtonsTchr()
   {
   
    if (document.getElementById("assignStudents"))
	    document.getElementById("assignStudents").disabled = false;
	    
    if (document.getElementById("viewRoster"))
	    document.getElementById("viewRoster").disabled = false;

    if (document.getElementById("editClass"))
	    document.getElementById("editClass").disabled = false;   
   
   }
   
   function submitFormForClass(form,action,classid)
   {
   
		form.action = action;
   		form.classId.value = classid;
   		form.submit();   
   
   }
   
  function moveStudents(source, target)		{
	
		var elSel = document.getElementById(source);
		 
		if(elSel.options.selectedIndex == -1)		{
			alert("You must select a student to change the group membership");
		}
		else	{
			addSelectedSourceToTarget(source, target);
			doButtons();
		}

	}
   
   function clearMoveStudents(form)
   {
   		if (form.classIdFrom)
   			form.classIdFrom.selectedIndex = 0;
   
   		if (form.classIdTo)
   			form.classIdTo.selectedIndex = 0;
   
   		if (form.school)
   			form.school.selectedIndex = 0;
   
   }
   
    function onChangeSchool(selectElem)
   {
   
   		if (selectElem.selectedIndex > 0)
   		{
   			updateListOptions(selectElem,'retrieveTeachers', 'teacher');   	
   			document.getElementById('find').disabled = false;	  
   			document.forms[0].teacher.disabled=false; 		
   		}
   		
	   		clearSubElementsNew('teacher');
   			document.forms[0].teacher.selectedIndex = 0;
   			document.forms[0].teacher.disabled=true;
   		
   
   }
   
   function onChangeDistrict(selectElem)
   {   
   
   		if (selectElem.selectedIndex > 0)
   		{   
   			updateListOptions(selectElem,'retrieveSchools', 'school');   	   
   			//document.getElementById('find').disabled = false;	   		
			document.forms[0].school.disabled=false;
			document.getElementById('find').disabled = false;
   		}
   		
	   		clearSubElementsNew('school');
	   		clearSubElementsNew('teacher');
   			document.forms[0].school.selectedIndex = 0;
			document.forms[0].school.disabled=true;
   			document.forms[0].teacher.selectedIndex = 0;
			document.forms[0].teacher.disabled=true;
   		
   		
   
   }
   
   
   function onChangeState(selectElem)
   {
   		if (selectElem.selectedIndex > 0)
   		{   	
   			updateListOptions(selectElem,'retrieveDistricts', 'district');   	
   			document.forms[0].district.disabled=false;
   		}
	   		document.forms[0].district.selectedIndex = 0;
		   	clearSubElementsNew('district');
		   	clearSubElementsNew('school');
		   	clearSubElementsNew('teacher');
	   		document.forms[0].district.selectedIndex = 0;
	   		document.forms[0].district.disabled=true;
	   		document.forms[0].school.selectedIndex = 0;
			document.forms[0].school.disabled=true;
	   		document.forms[0].teacher.selectedIndex = 0;
			document.forms[0].teacher.disabled=true;
			document.getElementById('find').disabled = true;

  }

  function clearSubElementsNew(target)
  {
    if (target == "district")
    {
    	removeDropDownOptions("school");
	    removeDropDownOptions("teacher");
    
	    disableElement("school");
	    disableElement("teacher");
	    
    } else if (target == "school")
    {
   	    removeDropDownOptions("teacher");
        disableElement("teacher");
    }    
  }
   
   function onChangeSchoolNew(selectElem)
   {
   		if (selectElem.selectedIndex > 0)
   		{
   			updateListOptions(selectElem,'retrieveTeachers', 'teacher');   	
   			document.forms[0].teacher.disabled=false; 		
   			document.forms[0].find.disabled=false; 		
   		} else {
	   		clearSubElementsNew('teacher');
   			document.forms[0].teacher.selectedIndex = 0;
   			document.forms[0].teacher.disabled=true;
   			document.forms[0].find.disabled=true; 	
   		}
   
   }

/****************************************************************
********************HELP API - Begin****************************
*****************************************************************
*/
// method to prepare the help link. 
// Help link is context sensitive - based on screen and user role.
// These attributes are part of the base layout.
function generateHelpLink()
{
    var helpPage ;
    var userRole ;
    var eval='';
    var helpPath = "/content/help/html/";
    
    // helpPage.value is the screen code that is provided for each screen, which needs help content.
    helpPage = document.helpForm.helpPage.value;
    userRole = document.helpForm.userRoleInSession.value;
    if(document.helpForm.evalUser!=null)
    {
	eval = document.helpForm.evalUser.value;
	}
	if(eval=='eval')
	{
	 evaluser='Y'
	 }
	else
	{
     evaluser='N'
     }
	launchHelp(helpPage,userRole,helpPath,evaluser);
	
}

// method to prepare the help link for home page. 
// These attributes are part of the login layout.
function generateLoginHelpLink()
{
    var helpPage ;
    var userRole ;
    var eval='';
    var loginHelpPath = "/content/help/html/";  // TC-537
    
    // helpPage.value is the screen code that is provided for screen, which needs help content.
    helpPage = document.helpForm.helpPage.value;
    userRole = document.helpForm.userRoleInSession.value;
    if(document.helpForm.evalUser!=null)
    {
    eval = document.helpForm.evalUser.value;
    }
	if(eval=='eval')
	{
	 evaluser='Y';
	}
	else
	{
     evaluser='N';
    }
	launchHelp(helpPage,userRole,loginHelpPath,evaluser);
	
}

// launch the help window at the correct size
// This API is provided by digital media team 
//George Pavlovich x4252

function launchHelp(scrn,role,helpPath,evaluser){
//alert("Inside launch help: Screencode="+scrn + " and role =" + role);
/*	for dynamic window 50% of screen
	var sw = (screen.availWidth-10);
	var sh = (screen.availHeight-20);
	var w = sw/2;
	var h = sh/2;
	var l = (sw - w) / 2;
	var t = (sh - h) / 2;
*/
	// for static viewing window based on 1024x768 screen

	var w = 736;  // TC-494 Increased width by 15%
	var h = 600;
	var l = 0;
	var t = 0;
	var fn = helpPath + "launchHelp.html?screen="+scrn+"&role="+role+"&evaluser="+evaluser;
	
	var features = "width="+w+",height="+h+",left="+l+",top="+t;
	features += ",screenX="+l+",screenY="+t;
	features += ",scrollbars=1,resizable=1,location=0";
	features += ",menubar=0,toolbar=0,status=1";
	var win = "launchHelp";
	var retVal = window.open(fn, win, features);
	retVal.focus();
}

   
   function onChangeClassMoveStudent(selectElem)
   {
   		if (selectElem.selectedIndex > 0)
   		{
   			 	document.forms[0].move.disabled=false; 		
   		} else {
	   		
   			document.forms[0].move.disabled=true; 	
   		}
   
   }



/****************************************************************
********************HELP API - End****************************
*****************************************************************
*/

// added newly for open and close menu
function toggleLayer(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
}

var toggleState= 'expanded';
function toggleMenu()
{

	var menuWidth = "19%";
	var bodyWidth = "81%";

	menuCell = document.getElementById('leftMenuCell');

	var menuDivValue = document.getElementById('leftMenuDiv');

	if (toggleState == 'expanded')
	{
		toggleState = 'collapsed';
 		menuWidth = "0%";
 		bodyWidth = "100%";
		menuDivValue.style.display = "none";
	}
	else
	{
		// transition from collapsed to expanded
		toggleState = 'expanded';
		menuDivValue.style.display = "block";
	}

	menuCell.style.width = menuWidth;
	bodyCell = document.getElementById('contentCell');
	bodyCell.style.width = bodyWidth ;

}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function setClassIdValue(radioObj,elem)
{
	elem.value = getCheckedValue(radioObj);

}

/*** This method TRIM the String value passed in to the method.***/
function trimString(sText)
{
	/*if(sText != null)
	{
	    var nTxtLen=sText.length-1;
	    for (var nStart=0;nStart<=nTxtLen && sText.charAt(nStart)==' ';nStart++);
	    if (nStart>nTxtLen)
	        return '';
	    for (var nEnd=nTxtLen;nEnd>=0 && sText.charAt(nEnd)==' ';nEnd--);
		    return sText.substring(nStart,nEnd+1);
	}*/
	
	var allText = new String(sText);
	allText = allText.trim();
	return allText;
} 

/*** Validate the Date Based on the Entered Value ***/
function validateDateEntered(psDate,psFormat)
{
	if(!isDate(psDate, psFormat))		
	{
		alert('Please enter valid date. Date should be entered in the format MM/dd/yyyy');
		return false;
	}
	else
	{
		return true;
	}
}

/*******************************************************
Added since CALENDAR PRINT  functionality PRINTS the 
Content not the Entire PAGE 
********************************************************/
function delegatePrinting()
{
	if(document.forms[0].calendarPrintIdentifier == "" || document.forms[0].calendarPrintIdentifier == null)
	{
		if((document.forms[0].methodName != null) &&
			(document.viewAllAssignmentsForm != null) &&
			(document.viewAllAssignmentsForm.methodName.value == "fromPlanning" || document.viewAllAssignmentsForm.methodName.value == "fromAssessments" || document.viewAllAssignmentsForm.methodName.value == "FindClick" || document.viewAllAssignmentsForm.methodName.value == "ClearClick"))	
		{
		   	sFromDate=document.viewAllAssignmentsForm.fromDate.value;
		   	sToDate=document.viewAllAssignmentsForm.toDate.value;
		   	sStudentclass=document.viewAllAssignmentsForm.studentclass.value;	   	
		   	sSubject=document.viewAllAssignmentsForm.subject.value;
		   	sStudent=document.viewAllAssignmentsForm.student.value;
	
			printAllAssignments=window.open('','assignments','width=985,height=650,scrollbars=yes,dependent=yes');
			printAllAssignments.location.href = 'viewAllAssignments.do?method=viewAllAssignments&methodName=printing&fromDate='+sFromDate+'&toDate='+sToDate+'&studentclass='+sStudentclass+'&subject='+sSubject+'&student='+sStudent;
		}
		else
		{
			printSpecial();
		}
	}
	else
	{
		printBlocks();
	}
}
/***********************************************************

 This method is used to hide an element                              *

************************************************************/

 

function showElement(objectName) {

 

      var elem =document.getElementById(objectName);

      elem.style.visibility = 'visible';

      elem.style.zIndex = '999';

}

/***********************************************************

 This method is used to show an element                        *

************************************************************/

 

function hideElement(objectName) {

      var elem =document.getElementById(objectName);

      elem.style.visibility = 'hidden';

}


/***********************************************************

 This method is change the cursor                        *

************************************************************/

function hideCursor(elem) {

      elem.style.cursor = "none";

}

function ignoreClick()
{
}
 

/***********************************************************
 This method is used to trim the STRING                    *
 The Following method is TESTED to work for all the        *
 BROWSER                                                   *
************************************************************/
String.prototype.trim = function () 
{
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}   

/**--**ch **/
function clearAll(form){
 	for (var i=0; i < form.elements.length; i++)
 	{ 		    
 		elem = form.elements[i]; 	
		if (elem.type == 'text'){
			elem.value='';
		}
 		if (elem.type == "select-one")
 		{
 			elem.selectedIndex = 0; 			
 		} 	

 	}

}

/* printerFriendly.js */

//=========================================
//  Function:  applyReadOnly
//  Description: Makes every element in specific div read-only
//  Arguments: objDiv - div tag as object
//  Returns:  none
//  Type:   Generic
//=========================================


var goto_findex = 0;

function checkval(c,l)
{
  var c = c; //Current Field Index
  var i = i ; //Go to this field Index
  var l = l; //max number of characters

  for (var z = 0; z < c.form.length; z++)
  {
      if (c.form[z].name == c.name)
      {
        goto_findex = z;	
        break;
    }
  }

  if (l > 0)
  {
    if (c.form[goto_findex].value.length == l)
    {
      goto_findex = goto_findex +1;
    }
  }

  if (l == 0)
  {
    goto_findex = goto_findex +1;
  }
  
  if (l < 0)
  {
      goto_findex = goto_findex +1;
  }

	for (var v = goto_findex;v <c.form.length;v++)
  {
			if (c.form[v].type == "hidden")
      {
				continue;	
			}
      else
      {
				if (v > goto_findex)
        {
					goto_findex = v;
					break;
				}
        else
        {
					break;
				}			
			}
	}
	c.form[goto_findex].focus();
	return (false);

}

var gAutoPrint = true; // Flag for whether or not to automatically call the print function
var printWin;


function printSpecial()
{

	var pagetitle = "";
	var pagetitle_orig = "";

	for (var i = 0;i < printSpecial.arguments.length;i++){
		pagetitle += printSpecial.arguments[i];
	}
	 
	if (document.getElementById != null)
	{
		var html = '<HTML>\n<HEAD>\n';

		if (document.getElementsByTagName != null)
		{
			var headTags = document.getElementsByTagName("head");
			if (headTags.length > 0)
				html += headTags[0].innerHTML;
		}

		    
		html += '\n</HE' + 'AD>\n<BODY onload="applyReadOnly()">\n';
		
		html += '<div class=';
		html += "titleText";
		html += '>';
		html += pagetitle_orig;
		html += '</div>';
		
		var printReadyElem = document.getElementById("printReady");
		var printReadyElem2 = document.getElementById("printReady2");
		var printReadyElem3 = document.getElementById("printReady3");
		html += '<div align="left"><input type="button" value="Close Window" onclick="javascript:window.close()" alt="Close Window"> </div><br>';	
		if (printReadyElem != null)
		{
    	html += '<div id="printSection" >';
			html += printReadyElem.innerHTML;
      html += '</div>';
		} 
		if (printReadyElem2 != null){
			html += printReadyElem2.innerHTML;
		}
		if (printReadyElem3 != null){
			html += printReadyElem3.innerHTML;
		}
	
		if ((printReadyElem == null) && (printReadyElem2 == null) && (printReadyElem3 == null))
		{
			alert("Could not find the printReady section in the HTML");
			return;
		}	
			
		
    html += '\n<SCRIPT language="JavaScript" type="text/JavaScript">';
    html += '\n';
    html += ' applyReadOnly();';
    html += '\n';
    html += ' <\/SCRIPT>';
    html += '\n</BO' + 'DY>';
    html += '\n</HT' + 'ML>';
		
		printWin = window.open("", "PCprintWindow");
    printWin.focus();
    printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
		if (gAutoPrint)
			printWin.print();
	}
	else
	{
		alert("Please note: The 'Printer Friendly' feature is not available on this page.");
	}
}

function applyReadOnly()
{
 var iElements;
 var strTagName;
 var strType;
 var objDiv = document.getElementById("printSection");
 walkNodePrint(objDiv);
}

function walkNodePrint(objDiv) {
   if (objDiv == null){
      return;   	
   }  

  strTagName = objDiv.tagName;
  strType= objDiv.type;
  var newStrTagName = new String(strTagName);
  var upperStrTagName = newStrTagName.toUpperCase();

  if (upperStrTagName == "A")
  {    
      var temp = objDiv.innerHTML;
      var innerEl = document.createElement("DIV");
      innerEl.innerHTML = temp;
//    var theText1 = document.createTextNode(temp);
      var par = objDiv.parentNode;
      objDiv.parentNode.removeChild(objDiv);
//    par.appendChild(theText1);
      par.appendChild(innerEl);
  }
  else if (upperStrTagName == "SELECT")
  {
    objDiv.readOnly = true;
    objDiv.disabled = true; 
  }
  else if (upperStrTagName == "INPUT")
  {
    objDiv.readOnly = true;
    objDiv.disabled = true; 
  }
 else if (upperStrTagName == "TEXTAREA")
  {
    objDiv.readOnly = true;
    objDiv.disabled = true; 
  }
  else if (strType != undefined)
  {
    objDiv.onclick = "javascript: void(0)";
    objDiv.readOnly = true;
    objDiv.disabled = true;
  }
   for (var i = 0; i < objDiv.childNodes.length; i++) {
      walkNodePrint(objDiv.childNodes[i]);
   }
}


/* multiScroll.js */


var finalizeMe = (function(){
	var global = this,base,safe = false,svType = (global.addEventListener && 2)||(global.attachEvent && 3)|| 0;
	function addFnc(next, f){function t(ev){if(next)next(ev);f(ev);};t.addItem = function(d){if(f != d.getFunc()){if(next){next.addItem(d);}else{next = d;}}return this;};t.remove = function(d){if(f == d){f = null;return next;}else if(next){next = next.remove(d);}return this;};t.getFunc = function(){return f;};t.finalize = function(){if(next)next = next.finalize();return (f = null);};return t;};
	function addFunction(f){if(base){base = base.addItem(addFnc(null, f));}else{base = addFnc(null, f);}};
	function ulQue(f){addFunction(f);if(!safe){switch(svType){case 2:global.addEventListener("unload", base, false);safe = true;break;case 3:global.attachEvent("onunload", base);safe = true;break;default:if(global.onunload != base){if(global.onunload)addFunction(global.onunload);global.onunload = base;}break;}}};
	ulQue.remove = function(f){if(base)base.remove(f);};
	function finalize(){if(base){base.finalize();switch(svType){case 3:global.detachEvent("onunload", base);break;case 2:global.removeEventListener("unload", base, false);break;default:global.onunload = null;break;}base = null;}safe = false;};
	ulQue(finalize);return ulQue;
})();


var InitializeMe = (function(){
	var global = this,base = null,safe = false;
	var listenerType = (global.addEventListener && 2)||(global.attachEvent && 3)|| 0;
	function getStackFunc(next, funcRef, arg1,arg2,arg3,arg4){function l(ev){funcRef((ev?ev:global.event), arg1,arg2,arg3,arg4);if(next)next = next(ev);return (funcRef = null);};l.addItem = function(d){if(next){next.addItem(d);}else{next = d;}};return l;};
	return (function(funcRef, arg1,arg2,arg3,arg4){if(base){base.addItem(getStackFunc(null, funcRef, arg1,arg2,arg3,arg4));}else{base = getStackFunc(null, funcRef, arg1,arg2,arg3,arg4);}if(!safe){switch(listenerType){case 2:global.addEventListener("load", base, false);safe = true;break;case 3:global.attachEvent("onload", base);safe = true;break;default:if(global.onload != base){if(global.onload){base.addItem(getStackFunc(null, global.onload));}global.onload = base;}break;}}});
})();
var queryStrings = (function(out){
    if(typeof location != 'undefined'){
        var temp = location.search||location.href||'';
        var nvp, ofSet;
        if((ofSet = temp.indexOf('?')) > -1){
            temp = temp.split("#")[0];
            temp = temp.substring((ofSet+1), temp.length);
            var workAr = temp.split('&');
            for(var c = workAr.length;c--;){
                nvp = workAr[c].split('=');
                if(nvp.length > 1){out[nvp[0]] = nvp[1];}
            }
        }
    }
    return out;
})({});

var TimedQue = (function(){
	var base, timer;
	var interval = 60;
	var newFncs = null;
	function addFnc(next, f){function t(){next = next&&next();if(f()){return t;}else{f = null;return next;}}t.addItem = function(d){if(next){next.addItem(d);}else{next = d;}return this;};t.finalize = function(){return ((next)&&(next = next.finalize())||(f = null));};return t;}
	function tmQue(fc){if(newFncs){newFncs = newFncs.addItem(addFnc(null, fc));}else{newFncs = addFnc(null, fc);}if(!timer){timer = setTimeout(tmQue.act, interval);}}
	tmQue.act = function(){var fn = newFncs, strt = new Date().getTime();if(fn){newFncs = null;if(base){base.addItem(fn);}else{base = fn;}}base = base&&base();if(base||newFncs){var t = interval - (new Date().getTime() - strt);timer = setTimeout(tmQue.act, ((t > 0)?t:1));}else{timer = null;}};
	tmQue.act.toString = function(){return 'TimedQue.act()';};
	tmQue.finalize = function(){timer = timer&&clearTimeout(timer);base = base&&base.finalize();newFncs = null;};
	return tmQue;
})();

var getElementWithId = (function(){if(document.getElementById){return (function(id){return document.getElementById(id);});}else if(document.all){return (function(id){return document.all[id];});}return (function(id){return null;});})();

function getSimpleExtPxIn(el){
	var temp, temp2, tick = 0, getBorders = retFalse, doCompStyle = retFalse,defaultView,objList = [];
	function retFalse(){return false;}
	retFalse.elTest = retFalse;
	retFalse.iY = retFalse.iX = retFalse.y = retFalse.x = retFalse.w = retFalse.h = retFalse.bb = retFalse.bt = retFalse.bl = retFalse.br = 0;
	function retThis(){return retThis;}
	function gCompStyleBorders(p, el){doCompStyle(p, defaultView.getComputedStyle(el, '' ));}
	function doComputedStyleFloat(p, cs){p.bt = (cs.getPropertyCSSValue('border-top-width').getFloatValue(5));p.bl = (cs.getPropertyCSSValue('border-left-width').getFloatValue(5));p.br = (cs.getPropertyCSSValue('border-right-width').getFloatValue(5));p.bb = (cs.getPropertyCSSValue('border-bottom-width').getFloatValue(5));}
	function doComputedStyleValue(p, cs){p.bt = Math.ceil(parseFloat(s.getPropertyValue('border-top-width')))|0;p.bl = Math.ceil(parseFloat(s.getPropertyValue('border-left-width')))|0;p.br = Math.ceil(parseFloat(s.getPropertyValue('border-right-width')))|0;p.bb = Math.ceil(parseFloat(s.getPropertyValue('border-bottom-width')))|0;}
	function gClientBorders(p, el){if(el.clientWidth||el.clientHeight){p.bb = (el.offsetHeight - (el.clientHeight + (p.bt = el.clientTop|0)))|0;p.br = (el.offsetWidth - (el.clientWidth + (p.bl = el.clientLeft|0)))|0;}}
	function getInterfaceObj(el){var lastTick = NaN;var offsetParent = getSimpleExtPxInFn(el.offsetParent)||retFalse;function p(doTick){if(doTick){tick = (1+tick)%0xEFFFFFFF;}if(tick != lastTick){lastTick = tick;offsetParent();getBorders(p, el);p.iY = (p.y = (offsetParent.iY + (el.offsetTop|0))) + p.bt;p.iX = (p.x = (offsetParent.iX + (el.offsetLeft|0))) + p.bl;p.w = el.offsetWidth|0;p.h = el.offsetHeight|0;}return p;}p.elTest = function(elmnt){return (elmnt == el);};p.iY = p.iX = p.w = p.h = p.y = p.x = p.bb = p.bt = p.bl = p.br = 0;return (objList[objList.length] = p);}
	function getSimpleExtPxInFn(el){if((!el)||(el == document)){return retFalse;}for(var c = objList.length;c--;){if(objList[c].elTest(el)){return objList[c];}}return getInterfaceObj(el);}
	function setSpecialObj(el){var lastTick = NaN;function p(doTick){if(doTick){tick = (1+tick)%0xEFFFFFFF;}return p;}p.elTest = function(elmnt){return (elmnt == el);};p.iY = p.iX = p.w = p.h = p.y = p.x = p.bb = p.bt = p.bl = p.br = 0;objList[objList.length] = p;}
	if((typeof el.offsetParent != 'undefined')&&(typeof el.offsetTop == 'number')&&(typeof el.offsetWidth == 'number')){if((typeof el.clientTop == 'number')&&(typeof el.clientWidth == 'number')){getBorders = gClientBorders;}else if((defaultView = document.defaultView)&&defaultView.getComputedStyle &&(temp = defaultView.getComputedStyle(el, '' ))&&(((temp.getPropertyCSSValue)&&(temp2 = temp.getPropertyCSSValue('border-top-width'))&&(temp2.getFloatValue)&&(doCompStyle = doComputedStyleFloat))||((temp.getPropertyValue)&&(doCompStyle = doComputedStyleValue)))){getBorders = gCompStyleBorders;temp2 = temp = null;}if(document.documentElement){setSpecialObj(document.documentElement);}if(document.body){setSpecialObj(document.body);}return (getSimpleExtPxIn = getSimpleExtPxInFn)(el);}else{retThis.elTest = retFalse;retThis.iY = retThis.iX = retThis.y = retThis.x = retThis.w = retThis.h = retThis.bb = retThis.bt = retThis.bl = retThis.br = NaN;return (getSimpleExtPxIn = retThis);}
}

function getNewFILCFncStac(fnc){function getNewFnc(f){var next = null;function t(a){next = next&&next(a);return (f(a))?t:next;}t.finalize = function(){next = next&&next.finalize();return (f = null);};t.addItem = function(d){if(f != d){if(next){next.addItem(d);}else{next = getNewFnc(d);}}return this;};return t;}var base = getNewFnc(fnc);fnc = function(a){base = base&&base(a);};fnc.addItem = function(d){if(base){base.addItem(d)}else{base = getNewFnc(d);}};fnc.finalize = function(){return (base = base&&base.finalize());};return fnc;}

function GlobalEventMonitor(eventName, functinRef){
	var finalize, global = this;
	var monitors = {};
	var onName = ['on',''];
	function mainMonitor(eventName, functinRef){
		var monitor = monitors[eventName];
		if(monitor){
			monitor(functinRef);
		}else{
			setEventMonitor(eventName, functinRef);
		}
	}
	function setListener(eventName, longName, fncStack){
		global.addEventListener(eventName, fncStack, false);
		return true;
	}
	function setListener_aE(eventName, longName, fncStack){
		global.attachEvent(longName, fncStack);
		return true;
	}
	function oldHandler(f){return (function(e){f(e);return true;});}
	function retFalse(){return false;}
	function setEventMonitor(eventName, functinRef){
		var fncStack, longName;
		onName[1] = eventName;
		longName = onName.join('');
		function main(funcRef){
			if(funcRef){
				fncStack.addItem(funcRef);
				globalCheck();
			}
		}
		function globalCheck(){
			if(global[longName] != fncStack){
				if(global[longName]){
					fncStack.addItem(oldHandler(global[longName]));
				}
				global[longName] = fncStack;
			}
		}
		fncStack = getNewFILCFncStac(functinRef);
		if(setListener(eventName, longName, fncStack)){
			globalCheck = retFalse;
		}else{
			globalCheck();
		}
		finalize.addItem(fncStack.finalize);
		monitors[eventName] = main;
		functinRef = null;
	}
	if(!global.addEventListener){
		if(global.attachEvent){
			setListener = setListener_aE;
		}else{
			setListener = retFalse;
		}
	}
	finalizeMe((finalize = getNewFILCFncStac(
		function(){
			finalize = monitors = null;
		})
	));
	(GlobalEventMonitor = mainMonitor)(eventName, functinRef);
	functinRef = null;
}

var tableScroll = (function(){
	var global = this, finalise, tableList = {};
	var notOnScroll = true, notAbort = true;
	var overrideStyles = {
		margin:[{keys:['margin','marginBottom','marginLeft','marginRight','marginTop'],value:'0px'}],
		padding:[{keys:['padding','paddingBottom','paddingLeft','paddingRight','paddingTop'],value:'0px'}],
		border:[
			{keys:['border','borderBottom','borderLeft','borderRight','borderTop'],value:'0px none #FFFFFF'},
			{keys:['borderWidth','borderLeftWidth','borderRightWidth','borderBottomWidth','borderTopWidth'],value:'0px'},
			{keys:['borderStyle','borderRightStyle','borderLeftStyle','borderBottomStyle','borderTopStyle'],value:'none'}
		],
		overflow:[{keys:['overflow'],value:'hidden'}],
		positionRel:[{keys:['position'],value:'relative'}],
		positionAbs:[{keys:['position'],value:'absolute'}],
		top:[{keys:['top'],value:'0px'}],
		left:[{keys:['left'],value:'0px'}],
		zIndex:[{keys:['zIndex'],value:2}]
	};
	function setStyleProps(styleObj){
		var data, dArray;
		for(var c = 1;c < arguments.length;c++){
			if((data = overrideStyles[arguments[c]])){
				for(var d = data.length;d--;){
					dArray = data[d].keys;
					for(var e = dArray.length;e--;){
						styleObj[dArray[e]] = data[d].value;
					}
				}
			}
		}
		return true;
	}
	function setClass(el,val){
		if(el.setAttribute){el.setAttribute('class',val);}
		return (el.className = val);
	}
	function retFalse(){return false;}
	function TableScroll(id){
		var midAbsDiv, parent, vHeaderAbsStyle, vHeaderRelStyle, hHeaderAbsStyle, hHeaderRelStyle;
		var midAbsDivStyle, midAbsinerDivStyle, inRelDivStyle, outRelDivDim;
		var lastScrollTop = NaN, lastScrollLeft = NaN, lastWidth = NaN, lastHeight = NaN, tableDim, table = getElementWithId(id);
		var midRelinerDivStyle, midRelinerDiv, testCellDim;
		function position(){
				var nh,nw,size,th,tw,cellWidth,celHeight,st = midAbsDiv.scrollTop, sl = midAbsDiv.scrollLeft, h = outRelDivDim(true).h, w = outRelDivDim.w;
				if((size = ((w != lastWidth)||(h != lastHeight)))||(st != lastScrollTop)||(sl != lastScrollLeft)){
					hHeaderRelStyle.left = (((cellWidth = (testCellDim().x - tableDim().iX)) + (lastScrollLeft = sl)) * -1)+'px';//position
					vHeaderRelStyle.top = (((celHeight = (testCellDim.y - tableDim.iY)) + (lastScrollTop = st)) * -1)+'px';
					if(size){
						vHeaderRelStyle.width = vHeaderAbsStyle.width = midAbsDivStyle.left = hHeaderAbsStyle.left = (cellWidth+'px');
						hHeaderRelStyle.height = hHeaderAbsStyle.height = midAbsDivStyle.top = vHeaderAbsStyle.top = (celHeight+'px');
						inRelDivStyle.left = (cellWidth * -1)+'px';
						inRelDivStyle.top = (celHeight * -1)+'px';
						midRelinerDivStyle.width = midAbsinerDivStyle.width = ((tw = tableDim.w) - cellWidth)+'px';
						midRelinerDivStyle.height = midAbsinerDivStyle.height = ((th = tableDim.h) - celHeight)+'px';
						midAbsDivStyle.height = vHeaderAbsStyle.height = (((nh = ((lastHeight = h) - celHeight)) > celHeight)?nh:celHeight)+'px';
						midAbsDivStyle.width = hHeaderAbsStyle.width = (((nw = ((lastWidth = w) - cellWidth)) > cellWidth)?nw:cellWidth)+'px';
						hHeaderRelStyle.width = inRelDivStyle.width = tw + 'px';
						vHeaderRelStyle.height = inRelDivStyle.height = th + 'px';
					}
				}
				return notOnScroll;
		}
		function onScroll(){
			notOnScroll = false;
			position();
		}
		function onSize(){
			position();
			return true;
		}
		finalise.addItem(function(){
			testCellDim = midRelinerDivStyle = midRelinerDiv = 
			midAbsinerDivStyle =  tableDim = vHeaderAbsStyle = vHeaderRelStyle = hHeaderAbsStyle = hHeaderRelStyle = inRelDivStyle = outRelDivDim = midAbsDiv = parent = table = null;
			})
		if(
			table&&
			(typeof table.scrollTop == 'number')&&
			(typeof table.offsetHeight == 'number')&&
			table.tagName&&
			table.appendChild&&
			table.cloneNode&&
			table.getAttribute&&
			table.getElementsByTagName&&
			(parent = table.parentNode)&&
			parent.insertBefore
		   ){
			InitializeMe(function(){
				var newTable, testCell;
				var vHeaderAbs, vHeaderRel, hHeaderAbs, hHeaderRel,outRelDiv, midAbsinerDiv, inRelDiv;
				if(
					(notAbort)&&
					(testCell = table.getElementsByTagName('td')[0])&&
					(newTable = table.cloneNode(true))&&
					(outRelDiv = document.createElement('DIV'))&&
					(setClass(outRelDiv, 'tableBoxOuter'))&&
					(midAbsDiv = document.createElement('DIV'))&&
					(midRelinerDiv = document.createElement('DIV'))&&
					(midAbsinerDiv = document.createElement('DIV'))&&
					(inRelDiv = document.createElement('DIV'))&&
					(vHeaderAbs = document.createElement('DIV'))&&
					(vHeaderRel = document.createElement('DIV'))&&
					(hHeaderAbs = document.createElement('DIV'))&&
					(hHeaderRel = document.createElement('DIV'))&&
					(setStyleProps(outRelDiv.style, 'positionRel', 'padding'))&&
					(midAbsDivStyle = midAbsDiv.style)&&
					(setStyleProps(midAbsDivStyle, 'positionAbs', 'padding', 'margin', 'border', 'zIndex'))&&
					(midRelinerDivStyle = midRelinerDiv.style)&&
					(setStyleProps(midRelinerDivStyle, 'positionRel', 'padding', 'margin', 'border', 'top', 'left'))&&
					(midAbsinerDivStyle = midAbsinerDiv.style)&&
					(setStyleProps(midAbsinerDivStyle, 'positionAbs', 'overflow', 'padding', 'margin', 'border', 'top', 'left'))&&
					(inRelDivStyle = inRelDiv.style)&&
					(setStyleProps(inRelDivStyle, 'positionRel', 'padding', 'margin', 'border', 'top', 'left'))&&
					(vHeaderAbsStyle = vHeaderAbs.style)&&
					(setStyleProps(vHeaderAbsStyle, 'positionAbs', 'overflow', 'padding', 'margin', 'border', 'top', 'left', 'zIndex'))&&
					(vHeaderRelStyle = vHeaderRel.style)&&
					(setStyleProps(vHeaderRelStyle, 'positionRel', 'padding', 'margin', 'border', 'top', 'left'))&&
					(hHeaderAbsStyle = hHeaderAbs.style)&&
					(setStyleProps(hHeaderAbsStyle, 'positionAbs', 'overflow', 'padding', 'margin', 'border', 'top', 'left', 'zIndex'))&&
					(hHeaderRelStyle = hHeaderRel.style)&&
					(setStyleProps(hHeaderRelStyle, 'positionRel', 'padding', 'margin', 'border', 'top', 'left'))&&
					(setStyleProps(table.style, 'margin'))&&
					(midAbsDiv.appendChild(midRelinerDiv))&&
					(midRelinerDiv.appendChild(midAbsinerDiv))&&
					(midAbsinerDiv.appendChild(inRelDiv))&&
					(outRelDiv.appendChild(midAbsDiv))&&
					(vHeaderAbs.appendChild(vHeaderRel))&&
					(hHeaderAbs.appendChild(hHeaderRel))&&
					(outRelDiv.appendChild(vHeaderAbs))&&
					(outRelDiv.appendChild(hHeaderAbs))&&
					(parent.insertBefore(outRelDiv, table))&&
					(!isNaN((outRelDivDim = getSimpleExtPxIn(outRelDiv)).w))&&
					(inRelDiv.appendChild(table))&&
					(!isNaN((testCellDim = getSimpleExtPxIn(testCell)).w))&&
					(!isNaN((tableDim = getSimpleExtPxIn(table)).w))&&
					(hHeaderRel.appendChild(newTable))&&
					(newTable = table.cloneNode(true))&&
					(vHeaderRel.appendChild(newTable))
				   ){
					midAbsDivStyle.overflow = 'scroll';
					if(midAbsDiv.addEventListener){
						midAbsDiv.addEventListener('scroll', onScroll, false);
					}else if(midAbsDiv.attachEvent){
						midAbsDiv.attachEvent('onscroll', onScroll);
					}else{
						midAbsDiv.onscroll = onScroll;
					}
					GlobalEventMonitor('resize', onSize);
					position();
					TimedQue(position);
				}else{
					notAbort = false;
				}
			});
		}else{
			notAbort = false;
		}
		return true;
	}
	function main(){
		var id;
		for(var c = 0;c < arguments.length;c++){
			id = arguments[c];
			if(notAbort&&!tableList[id]){
				tableList[id] = TableScroll(id);
			}
		}
	}
	if(
		(!global.queryStrings||!queryStrings['noTableScroll'])&&
		global.setTimeout&&
		global.document&&
		document.createElement
	){
		finalizeMe((finalise = getNewFILCFncStac(function(){
			finalise = tableList = null;
		})));
		return main;
	}else{
		return retFalse;
	}
})();

function disableElementsInContainer(el) {
    try {
        if (el.tagName) {
			if ((el.tagName.toLowerCase() == "input") && 
					((el.type.toLowerCase() == "button") || (el.type.toLowerCase() = "submit") || (el.type.toLowerCase() == "reset")))
	            el.disabled = true;
        } 
        if (el.style) {
          	el.style.cursor = "wait";
          	el.style.color = "#848484";
        }
        var doNothing = function() { return false; }
      	el.onclick = doNothing;
      	el.onchange = doNothing;
      	el.onmouseover = doNothing;
      	el.onmouseout = doNothing;
    }
    catch (x){}
    
    if (el.childNodes && el.childNodes.length > 0) {
        for (var x = 0; x < el.childNodes.length; x++) {
        	disableElementsInContainer(el.childNodes[x]);
        }
    }
}	
