// JavaScript Document
var studentManagement=new students();
function manageStudent(){
	
	/*var head = document.getElementsByTagName('head').item(0);
	url="CSS/default_course_editor.css"
	q = document.getElementById("style");
	if(q){
		head.removeChild(q)
	}
	var s=document.createElement('link');
	sid = 'style'
	void(s.id = sid );
	void(s.rel='stylesheet');
	void(s.href=url +"?" + Date());
	void(s.type="text/css");
	void(head.appendChild(s));
	s = null;
	q=null;
	head = null;*/
	loadCSS("default_course_editor.css");
	if(document.getElementById("window_mngStudent_" + arguments[1] + "_"+ arguments[0])){
		clearElements(document.getElementById("window_mngStudent_" + arguments[1] + "_"+ arguments[0]));
	}				
	createObject("mngStudent_" + arguments[1] + "_" + arguments[0], arguments[2], "lesson", clientWidth-192,clientHeight-38,190,37,fireCloseEditWin);
	var contentWindow = document.createElement("div");
	document.getElementById("window_mngStudent_" + arguments[1] + "_"+arguments[0]).appendChild(contentWindow);
	//alert("window_mngStudent" + arguments[1] + "_"+arguments[0])
	//alert(document.getElementById("window_mngStudent" + arguments[1] + "_"+arguments[0]).childNodes[1].childNodes[1].id)
	contentWindow.id= "window_mngStudent_" + arguments[1] + "_" + arguments[0] + "_content";
	contentWindow.className= "window_Editor_content";
//contentWindow.style.height= "95%"
	contentWindow.style.height=clientHeight-38-20; //clientHeight-38-15;
	contentWindow.style.width= "100%"//clientWidth-192;
	loadXMLDoc("dynamicpages/lms_course_student_manage.asp", "studentID=" + arguments[0], "courseID=" + arguments[1],"title=" + escape("Manage Student:"), "handleTitle=HandleTitle_mngStudent_"+ arguments[1] + "_" + arguments[0]);//.childNodes[0].innerHTML + " " + document.getElementById("btnGroupTitle_" + arguments[0]).innerHTML);
	target= null
	accessContainer = null;
	accessContainerTitle= null;
}
function tutorStudent(){
	
	/*var head = document.getElementsByTagName('head').item(0);
	url="CSS/default_course_editor.css"
	q = document.getElementById("style");
	if(q){
		head.removeChild(q)
	}
	var s=document.createElement('link');
	sid = 'style'
	void(s.id = sid );
	void(s.rel='stylesheet');
	void(s.href=url +"?" + Date());
	void(s.type="text/css");
	void(head.appendChild(s));
	s = null;
	q=null;
	head = null;*/
	//alert(arguments[1]);
	loadCSS("default_course_editor.css");
	if(document.getElementById("window_mngStudent_" + arguments[1] + "_"+ arguments[0])){
		clearElements(document.getElementById("window_mngStudent_" + arguments[1] + "_"+ arguments[0]));
	}				
	createObject("mngStudent_" + arguments[1] + "_" + arguments[0], arguments[2], "lesson", clientWidth-192,clientHeight-38,190,37,fireCloseEditWin);
	//alert("mngStudent_" + arguments[1] + "_" + arguments[0]);
	var contentWindow = document.createElement("div");
	document.getElementById("window_mngStudent_" + arguments[1] + "_"+arguments[0]).appendChild(contentWindow);
	//alert("window_mngStudent" + arguments[1] + "_"+arguments[0])
	//alert(document.getElementById("window_mngStudent" + arguments[1] + "_"+arguments[0]).childNodes[1].childNodes[1].id)
	contentWindow.id= "window_mngStudent_" + arguments[1] + "_" + arguments[0] + "_content";
	contentWindow.className= "window_Editor_content";
//contentWindow.style.height= "95%"
	contentWindow.style.height=clientHeight-38-20; //clientHeight-38-15;
	contentWindow.style.width= "100%"//clientWidth-192;
	loadXMLDoc("dynamicpages/lms_course_student_tutor.asp", "studentID=" + arguments[0], "courseID=" + arguments[1],"title=" + escape("Manage Student:"), "handleTitle=HandleTitle_mngStudent_"+ arguments[1] + "_" + arguments[0]);//.childNodes[0].innerHTML + " " + document.getElementById("btnGroupTitle_" + arguments[0]).innerHTML);
	target= null
	accessContainer = null;
	accessContainerTitle= null;
}
function tutorCourseSyllabus(){
	loadCSS("default_course_editor.css");
	var crseID=arguments[0].split("_")[arguments[0].split("_").length-1];
	
	//alert(crseID);
	if(document.getElementById("window_syllabus_" + crseID)){
		clearElements(document.getElementById("window_syllabus_" + crseID));
	}				
	createObject("syllabus_" + crseID, crseID, "syllabus", clientWidth-192,clientHeight-38,190,37,fireCloseEditWin);
	var contentWindow = document.createElement("div");
	document.getElementById("window_syllabus_" + crseID).appendChild(contentWindow);
	//alert("window_mngStudent" + arguments[1] + "_"+arguments[0])
	//alert(document.getElementById("window_mngStudent" + arguments[1] + "_"+arguments[0]).childNodes[1].childNodes[1].id)
	contentWindow.id= "window_tutorSyllabus_" + crseID + "_content";
	contentWindow.className= "window_Editor_content";
//contentWindow.style.height= "95%"
	contentWindow.style.height=clientHeight-38-20; //clientHeight-38-15;
	contentWindow.style.width= "100%"//clientWidth-192;
	contentWindow.onscroll=headScrollTop;
	loadXMLDoc("dynamicpages/lms_course_syllabus_tutor.asp", "courseID=" + crseID,"title=" + escape("Manage Student:"), "handleTitle=HandleTitle_mngStudent_"+ arguments[1] + "_" + arguments[0]);//.childNodes[0].innerHTML + " " + document.getElementById("btnGroupTitle_" + arguments[0]).innerHTML);
	target= null
	accessContainer = null;
	accessContainerTitle= null;
}
function newTutorSyllabusItems(){
	var target=document.getElementById("window_tutorSyllabus_" + arguments[0] + "_content");
	var container=target//document.getElementById("container_tutorSyllabus_" + arguments[0]);
	var syllLine=document.createElement("div");		
	var description = document.createElement("div");
	var passingGrade= document.createElement("div");
	var pointsAvailable=document.createElement("div");
	if(container.childNodes.length<1){
		
		//container=document.createElement("div");
		//container.onscroll=scrollTitle;
		//target.appendChild(container);
		//container.id="container_tutorSyllabus_" + arguments[0];
		//container.className="syllabusContainer";
		description.className="syllDescrip_header";
		passingGrade.className="passing_header";
		pointsAvailable.className="pointsAvail_header";
		description.innerHTML="Name";
		passingGrade.innerHTML="Points To Pass";
		pointsAvailable.innerHTML="Points Available"
		syllLine.className="syllabusLine_header";
		syllLine.id="syllHeader";
		container.appendChild(syllLine);
		syllLine.appendChild(description);
		syllLine.appendChild(passingGrade);
		syllLine.appendChild(pointsAvailable);
		syllLine=null;
		description=null;
		passingGrade=null;
		pointsAvailable=null;
		syllLine=document.createElement("div");
		description = document.createElement("div");
		passingGrade= document.createElement("div");
		pointsAvailable=document.createElement("div");

	}
	syllLine.className="syllabusLine";
	description.className="syllDescription";
	passingGrade.className="passing";
	pointsAvailable.className="pointsAvail";
	container.appendChild(syllLine);	
	description.innerHTML=arguments[7];
	if(arguments[23]!='-1'){
		passingGrade.innerHTML=arguments[23];
	}
	if(arguments[22]!='-1'){
		pointsAvailable.innerHTML=arguments[22];
	}
	syllLine.id=arguments[2] + "_" + arguments[9];
	syllLine.onmousedown=fireContextMenu;
	syllLine.appendChild(description);
	syllLine.appendChild(passingGrade);
	syllLine.appendChild(pointsAvailable);
	
	description=null;
	passingGrade=null;
	pointsAvailable=null;
	syllLine=null;
	container=null;
	target=null;
}
function students(){
	this.stdnts=new Array();
	this.add=function(){
		this.stdnts.push(new student(arguments));
	}
	this.update=function(){
		this.stdnts[this.findStudent(arguments[0])].attributes=arguments;
	}
	this.remove=function(index){
		this.stdnts[index].cleanup();
		this.stdnts.splice(i,1);
	}
	this.findStudent=function(stdntID){
		var fnd=-1;
		for(var i=0;i<this.stdnts.length;i++){
			if(this.stdnts[i].getID()==stdntID){
				fnd=i;
			}
		}
		return fnd;
	}
	this.getStudentById=function(stdntID){
		var fnd=-1;
		for(var i=0;i<this.stdnts.length;i++){
			if(this.stdnts[i].getID()==stdntID){
				fnd=this.stdnts[i];
			}
		}
		return fnd;
	}
	this.cleanupStudent=function(){
		var stdntIndex=this.findStudent(arguments[0]);
		this.getStudentById(arguments[0]).cleanup();
		this.stdnts.splice(stdntIndex,1);
	}
	this.cleanup=function(){
		for(var i=0;i<this.stdnts.length;i++){
			this.stdnts[i].cleanup();
		}
		this.stdnts = null;
		this.add=null;
		this.remove=null;
		this.findStudent=null;
		this.cleanup=null;
	}
}
function student(){
	this.attributes = arguments[0];
	this.attributeNames= new Array("user_id",	"UserDBID",	"user_active",	"user_email",	"user_passwordText",	"user_fName",	"user_mInitial",	"user_lName",	"user_expiration",	"user_address1",	"user_address2",	"user_city",	"user_state",	"user_zipCode",	"user_phone","accessLevel");
	this.courses=new Array();
	this.addCourse=function(){
		this.courses.push(new course(arguments))
	}
	this.getID = function(){
		return this.getAttribute("user_id");
	}
	this.getCourseById=function(courseID){
		var fnd=-1;
		for(var i=0;i<this.courses.length;i++){
			if(this.courses[i].getID()==courseID){
				fnd=this.courses[i];
			}
		}
		return fnd;
	}
	this.getAttribute=function(elem){
		var retval=-1;
		if(isNaN(elem)){
			for(var i=0;i<this.attributeNames.length;i++){
				if(elem==this.attributeNames[i]){
					retval=this.attributes[i];
				}
			}
		}else{
			retval=this.attributes[elem];
		}
		return retval;
	}
	this.cleanup=function(){
		for(var i=0;i<this.courses.length;i++){
			this.courses[i].cleanup();
		}
		this.courses=null;
		this.attributes=null;	
		this.attributeNames=null;
		this.addCourse=null;
		this.getID=null;
		this.getCourseById=null;
		this.getAttribute=null;
		this.cleanup=null;
	}
}
function course(){
	this.attributes=arguments[0];
	this.attributeNames=new Array("courseID",	"CourseDesc")
	this.syllabusItems = new Array()
	this.addSyllabusItem=function(){
		this.syllabusItems.push(new syllabusItem(arguments));
	}
	this.getID=function(){
		return this.getAttribute("courseID");
	}
	this.getAttribute=function(elem){
		var retval=-1;
		if(isNaN(elem)){
			for(var i=0;i<this.attributeNames.length;i++){
				if(elem==this.attributeNames[i]){
					retval=this.attributes[i];
				}
			}
		}else{
			retval=this.attributes[elem];
		}
		return retval;
	}
	this.cleanup=function(){
		for(var i=0;i<this.syllabusItems.length;i++){
			this.syllabusItems[i].cleanup();
		}
		this.syllabusItems=null;
		this.attributes=null;
		this.attributeNames=null;
		this.getID=null;
		this.getAttribute=null;
		this.cleanup=null;
	}
}
function syllabusItem(){
	this.attributes= arguments[0];
	this.attributeNames=new Array("SyllID",	"Description",	"start",	"grde",	"poss",	"pass",	"complte",	"dComplte","type","file","graded");
	this.getAttribute=function(elem){
		var retval=-1;
		if(isNaN(elem)){
			for(var i=0;i<this.attributeNames.length;i++){
				if(elem==this.attributeNames[i]){
					retval=this.attributes[i];
				}
			}
		}else{
			retval=this.attributes[elem];
		}
		return retval;
	}
	this.getID=function(){
		return this.getAttribute("SyllID");
	}
	this.cleanup=function(){
		this.attributes=null;
		this.attributeNames=null;
		this.getAttribute=null;
		this.cleanup=null;
	}
}
function syllabusItemType(itm){
	var retval
	switch(parseInt(itm)){
		case 1:
			retval = "Lesson"
		break;
		case 2:
			retval = "Assignment"
		break;
		case 3:
			retval = "Quiz"
		break;
		case 4:
			retval = "Test"
		break;
		case 5:
			retval = "Survey"
		break;
	}
	return retval;
}
function layoutStudent(){
	//try{
	
	var student=studentManagement.stdnts[studentManagement.stdnts.length-1];
	var target
	//alert(student.courses.length);
	for(var q=0;q<student.courses.length;q++){
		//alert(student.courses.length);
		//alert("window_mngStudent_" + student.courses[q].getID() + "_"+ student.getID() + "_content");
		if(document.getElementById("window_mngStudent_" + student.courses[q].getID() + "_"+ student.getID() + "_content")){
			target=	document.getElementById("window_mngStudent_" + student.courses[q].getID() + "_"+ student.getID() + "_content");
			break;
		}
		
	}
	
	var studentBio=document.createElement('div');
	var bioLine1=document.createElement('div');
	var bioLine2=document.createElement('div');
	var bioLine3=document.createElement('div');
	var bioLine4=document.createElement('div');
	var bioLine5=document.createElement('div');
	var bioLine6=document.createElement('div');
	var bioLine7=document.createElement('div');
	var editBio=document.createElement('a');
	var studentCourses=document.createElement('div');
	
	var courseLine=document.createElement('div');
	var courseDescrip
	var courseIndication
	var studentSyll
	var syllLine
	var syllDescription
	var syllStarted
	var syllGrade
	var syllCompleted
	var course;
	var syll;
	var targetSplit=target.id.split("_")
	target.appendChild(studentBio);	
	studentBio.appendChild(bioLine1);
	studentBio.appendChild(bioLine2);
	studentBio.appendChild(bioLine3);
	studentBio.appendChild(bioLine4);
	studentBio.appendChild(bioLine5);
	studentBio.appendChild(bioLine6);
	studentBio.appendChild(bioLine7);
	bioLine7.appendChild(editBio);
	bioLine7.className="bioLine";
	bioLine7.style.height="20px";
	editBio.innerHTML="edit";
	editBio.href="#";
	editBio.id="student_"+ targetSplit[2]+"_"+student.getAttribute("user_id");
	
	editBio.onclick=editStudent;
	editBio.className="btnEditBio";
	studentBio.className='bioContainer';
	bioLine1.innerHTML=student.getAttribute("user_email");
	bioLine2.innerHTML=student.getAttribute("user_fName") + " " + student.getAttribute("user_mInitial") + " " + student.getAttribute("user_lName");
	bioLine3.innerHTML=student.getAttribute("user_address1");
	bioLine4.innerHTML=student.getAttribute("user_address2");
	bioLine5.innerHTML=student.getAttribute("user_city") + ", " + student.getAttribute("user_state") + " " +student.getAttribute("user_zipCode");
	bioLine6.innerHTML=student.getAttribute("user_phone");
	bioLine1.className='bioLine';
	bioLine2.className='bioLine';
	bioLine3.className='bioLine';
	bioLine4.className='bioLine';
	bioLine5.className='bioLine';
	bioLine6.className='bioLine';

	studentBio.id="studentBio_"+student.getID();
	bioLine1.id="bioLine1_"+student.getID();
	bioLine2.id="bioLine2_"+student.getID();
	bioLine3.id="bioLine3_"+student.getID();
	bioLine4.id="bioLine4_"+student.getID();
	bioLine5.id="bioLine5_"+student.getID();
	bioLine6.id="bioLine6_"+student.getID();
	target.appendChild(studentCourses);
	studentCourses.id="studentCourses_"+student.getID();
	studentCourses.className="courseGroup";
	if(arguments[0]){
		var dwnloader=document.createElement("iframe");
		dwnloader.id="downLoaderTutor";
		dwnloader.className="downLoader";
		target.appendChild(dwnloader);	
		dwnloader=null;
	}
	for(i=0;i<student.courses.length;i++){
		course=student.courses[i];
		courseLine=document.createElement('div');
		courseDescrip=document.createElement('div');
		courseIndication=document.createElement('div');
		studentSyll=document.createElement('div');
		
		studentCourses.appendChild(courseLine);
		courseLine.appendChild(courseDescrip);
		courseLine.appendChild(courseIndication);
		courseLine.className="courseLine";
		courseLine.id="courseLine_"+student.getID() + "_" + student.courses[i].getID();
		courseDescrip.id="courseDescrip_"+student.getID() + "_" + student.courses[i].getID();
		//courseIndication.id="courseIndication_"+student.getID() + "_" + student.courses[i].getID();
		courseDescrip.innerHTML=course.getAttribute("CourseDesc");
		courseDescrip.className="courseDescrip";
		//courseIndication.innerHTML="";
		courseLine.appendChild(studentSyll);
		if(arguments[0]){
			studentSyll.id="container_studentTutorSyll_"+student.getID() + "_" + student.courses[i].getID();
			
		}else{
			studentSyll.id="container_studentSyll_"+student.getID() + "_" + student.courses[i].getID();
		}
		studentSyll.className="studentSyll";
		studentSyll.onscroll=headScrollTop;
		for(z=-1;z<course.syllabusItems.length;z++){
			syllLine=document.createElement('div');
			syllDescription=document.createElement('div');
			syllStarted=document.createElement('div');
			syllGrade=document.createElement('div');
			syllCompleted=document.createElement('div');
			syll=course.syllabusItems[z];
			studentSyll.appendChild(syllLine);
			syllLine.appendChild(syllDescription);
			syllLine.appendChild(syllStarted);
			syllLine.appendChild(syllGrade);
			syllLine.appendChild(syllCompleted);
			syllLine.className="syllLine";
			
			syllDescription.className="syllDescrip";
			syllStarted.className="syllStart";
			syllGrade.className="syllGrade";
			syllCompleted.className="syllEnd";
			
			
			if(z>-1){
			syllLine.id="container_syllLine_"+student.getID()	+ "_" + student.courses[i].getID() + "_" + student.courses[i].syllabusItems[z].getID();							   
			syllLine.onmousedown=fireContextMenu;
			syllDescription.id="container_syllDescription_"+student.getID()+ "_" + student.courses[i].getID()+ "_" + student.courses[i].syllabusItems[z].getID();
			syllStarted.id="container_syllStarted_"+student.getID()+ "_" + student.courses[i].getID()+ "_" + student.courses[i].syllabusItems[z].getID();
			syllGrade.id="container_syllGrade_"+student.getID()+ "_" + student.courses[i].getID()+ "_" + student.courses[i].syllabusItems[z].getID();
			syllCompleted.id="container_syllCompleted_"+student.getID()+ "_" + student.courses[i].getID()+ "_" + student.courses[i].syllabusItems[z].getID();
			syllDescription.innerHTML=syll.getAttribute("Description");
			if(arguments[0]){
				syllDescription.innerHTML=syllabusItemType(syll.getAttribute("type")) +" " +  syll.getAttribute("Description");//studentSyll.id="container_studentTutorSyll_"+student.getID() + "_" + student.courses[i].getID();
			}else{
				syllDescription.innerHTML=syll.getAttribute("Description");//studentSyll.id="container_studentSyll_"+student.getID() + "_" + student.courses[i].getID();
			}
			syllStarted.innerHTML=dateFormat(syll.getAttribute("start"));
			if(syll.getAttribute("poss")!=""){
			syllGrade.innerHTML=syll.getAttribute("grde") + " out of " + syll.getAttribute("poss") + "(" + Math.round(parseFloat(syll.getAttribute("grde"))/parseFloat(syll.getAttribute("poss"))*100) + "%)";
			syllGrade.onmousedown=fireContextMenu;
				if(arguments[0]){
					if(parseInt(syll.getAttribute("type"))==2){
						if(syll.getAttribute("file")!=""){
							var fileDnld = document.createElement("a");
							fileDnld.id=syll.getAttribute("file");
							syllGrade.appendChild(fileDnld);
							fileDnld.innerHTML="Get File";
							fileDnld.className="btnEditBio";
							fileDnld.onclick=fireAssignmentDownload;
							
							var fileUpld = document.createElement("a");
							fileUpld.id=syll.getAttribute("file")+"\\grade";
							syllGrade.appendChild(fileUpld);
							fileUpld.innerHTML="Put File";
							fileUpld.className="btnEditBio";
							fileUpld.onclick=fireAssignmentUpload;
						}
					}
				}
			}
			syllCompleted.innerHTML=dateFormat(syll.getAttribute("dComplte"));
			}else{
				syllLine.id="container_syllLine1_"+student.getID()	+ "_" + student.courses[i].getID() + "_header";
				syllLine.style.position="relative";
				syllLine.style.backgroundColor="#cce";
				syllDescription.innerHTML="Syllabus Item";
				syllStarted.innerHTML="Start Date";
				syllGrade.innerHTML="Grade";

				syllCompleted.innerHTML="Finish Date";
			}
			syllLine=null;
			syllDescription=null;
			syllStarted=null;
			syllGrade=null;
			syllCompleted=null;
			syll=null;
		}
		courseLine=null;
		courseDescrip=null;
		courseIndication=null;
		studentSyll=null;
	}	
	course=null;
	syll=null;
	target=null;
	studentBio=null;
	bioLine1=null;
	bioLine2=null;
	bioLine3=null;
	bioLine4=null;
	bioLine5=null;
	bioLine6=null;
	studentCourses=null;
	//}catch(error){}
}
function fireAssignmentDownload(){
	getFileByName(this.id)
	//alert(this.id);
}
function fireAssignmentUpload(){
	var q=this.id.split("\\");
	var newID="tmpContainer|" + q[2] + "|" + q[3] + "|" + q[4] +"||||||1";
	//alert(newID);
	putFile(newID);

	//getFileByName(this.id)
	//alert(this.id);
}

function clearProgression(){
	var progClear=arguments[0].split("_");
	var parentNode = document.getElementById(arguments[0]).parentNode.id;
	var tutorParent = document.getElementById(arguments[0]).parentNode.parentNode.parentNode.parentNode.id.split("_");
	//alert(parentNode + " " + progClear[0] + " " + progClear[4] + " " + parentNode.substr(parentNode.lastIndexOf("_")+1));
	if(arguments[1]){
		//alert(tutorParent);
		loadXMLDoc("dynamicpages/lms_course_student_clearProgress.asp","studentID=" + progClear[2], "crseSylID=" + progClear[4],"courseID=" + parentNode.substr(parentNode.lastIndexOf("_")+1),"tutor=true","parent="+tutorParent[2]);
	}else{
		loadXMLDoc("dynamicpages/lms_course_student_clearProgress.asp","studentID=" + progClear[2], "crseSylID=" + progClear[4],"courseID=" + parentNode.substr(parentNode.lastIndexOf("_")+1));
	}
}
function gradeElement(){
	var elemDetails=arguments[0].split("_");
	loadXMLDoc("dynamicpages/lms_course_student_gradeSyllItem.asp","studentID="+elemDetails[3],"syllID="+elemDetails[5]);
}
function loadGradeElement(){
	if(arguments[1]>2){
		tutorTestQuiz(arguments[0],arguments[5]);
	}
}
function deleteStudent(){
	
	var element=arguments[0].substr(arguments[0].indexOf("_")+1)
	var itm=element.split("_");
	if(confirm('Clicking OK will delete "' + document.getElementById(element).innerHTML + '"?')){
		//alert()
		loadXMLDoc("dynamicpages/lms_course_student_delete.asp","courseID=" + document.getElementById(element).parentNode.id.split("_")[2], "studentID=" + itm[2],"container="+element);
	}else{
		alert("Not deleted.");
	}
}
