$(window).load( function() {
	
	
	$(".fck").each(function(i)
	{
		
		var val = $(this).attr('id');
		
		var w = $(this).css('width');
		var h = $(this).css('height');
		
		var oFCKeditor = new FCKeditor(val);
		oFCKeditor.BasePath = siteUrl+"js/fckeditor/" ;			
		oFCKeditor.Width = w; 
		oFCKeditor.Height = h;
		oFCKeditor.ToolbarSet = "Basic" ;
		oFCKeditor.ReplaceTextarea() ;
		
	});
			
		
});
	
	
$(document).ready( function() {


	/* ---------------------------------------------------------*
	 * Function : PreIntermediatupdates.doc,					|
	 * ID 		: Feb2010-DeleteStudent							|
	 * Issue 	: Related to Delete Student From Teacher		|
	 * Author 	: Mr. Gourav Ku. Sharma
	 * Modified by 	: GK											|
	 -----------------------------------------------------------*/
	
	$('.deleteStudent').bind('click', function(){
		var controller = $(this).attr('name');
		var obj = document.getElementsByName("studentid[]");
		var cnt =0;
		for(i=0; i < obj.length; i++)
		{
			if (obj[i].checked) 
			{
				cnt++;
				val = obj[i].value;
			}
		}
		if(cnt == 0) {
			jAlert("You must first select a student to delete them") ;
			return false; 
		} else {
			jConfirm('Are you sure you want to delete the student('+cnt+')?',null, function(result){
				if (result) {
					document.getElementById("frmTeacherPeriod").action =  siteUrl + controller + '/deletestudent' ;			
					$("#frmTeacherPeriod").submit();
				}
			});
		}
	});
	
	
	/* -------------------------------------- */
	/* Function End No. Feb2010-DeleteStudent */
	/* -------------------------------------- */	


	$('#chkProcess').bind('click', function(){
		var controller = $(this).attr('controllers');
		jConfirm('Are you sure to delete student?',null, function(result){
			if (result) {
				document.getElementById("frmTeacherPeriod").action =  siteUrl + controller + '/deletestudent' ;			
				$("#frmTeacherPeriod").submit();
			}			
		});
	});
	
	
	
	$('.jounalWriteFormSave').click(function(){
		jConfirm('Saving your paper allows you to work on it later. The paper is not submitted to your teacher. Do you wish to save now?', null, function(result){
			if(result) {
				$('.clickButton').val('save');
				document.FormJWrite.submit();
			}
		});
	});
		
		
		
	$('.jounalWriteFormSimpleSave').click(function(){
		$('.clickButton').val('save');
		document.FormJWrite.submit();	
	});



	$('.jounalWriteFormSubmit').click(function(){
		jConfirm('When you submit your paper it goes to your teacher. Do you wish to submit your paper now?', null, function(result){
			if(result) {
				$('.clickButton').val('submit');
				document.FormJWrite.submit();
			}
		});
	});
	


	$('.eventFormSave').click(function(){
		var valid = checkValidationCurrentEvent();
		if(valid) { 	
			jConfirm('Saving your article allows you to work on it later. The article is not submitted to your teacher. Do you wish to save now?', null, function(result){
				if(result) {
					$('.clickButton').val('save');
					document.CurrentEventNewsForm.submit();
				}
			});			
		}
	});



	$('.eventFormSimpleSave').click(function(){	
		var valid = checkValidationCurrentEvent();
		if(valid) { 	
			$('.clickButton').val('save');
			document.CurrentEventNewsForm.submit();
		}
	});



	$('.eventFormSubmit').click(function(){
		var valid = checkValidationCurrentEvent();
		if(valid) {
			jConfirm('When you submit your article it goes to your teacher. Do you wish to submit your article now?', null, function(result){
				if(result) {
					$('.clickButton').val('submit');
					document.CurrentEventNewsForm.submit();
				}
			});
		}
	});

		
	//======== New function to save drafts  ========//
	
	
	$(".mwfinalizefun").bind("click", function() {   
		var str 	= $(this).attr('name');
		var actions = $(this).attr('actions');
		
		var no 		= str.charAt(str.length-1);
		$("#isfinal"+no).val(1);
		
		var oEditor = FCKeditorAPI.GetInstance('Draft'+no) ;
		
		var con = oEditor.GetXHTML(true);
		$("#Draft"+no).val(con);
			
		jConfirm('Finalizing your draft means you have completed your draft. You will not be able to work on this draft and will have to start another draft to continue to work on your assignment. Are you sure you want to finalize your draft? Click "Ok" to continue.',null,function(result){
			if(result) {
				var options = { 
						target:        '#output'+no,   	// target element(s) to be updated with server response 
						beforeSubmit:  showRequest,  	// pre-submit callback 
						type:  'post',  				// pre-submit callback 				
						//success:       showResponseDesc,
						url:    siteUrl + actions + "/updatedraft",// post-submit callback 
						error: 	function(xhr, ajaxOptions, thrownError) {
							jAlert("Error in saving draft.");
						},
						success: function(){
							window.location = siteUrl+actions+"/thanks2";	
						}
				};
				$("#mwfrmessay"+no).ajaxSubmit(options); 
				return false; 
			}	  
		});
	});
	
	
	
	$(".mwfinalizeclass").bind("click",function(){
		jConfirm('Finalizing your draft means you have completed your draft. You will not be able to work on this draft and will have to start another draft to continue to work on your assignment. Are you sure you want to finalize your draft? Click "Ok" to continue.',null,function(result){
			if (result) {
				$("#isfinal").val(1);
				$("#frm2").submit();
			}
		}) 
	});
	
	
	$("#mwfinalizeid").bind("click", function() {
		jConfirm('Finalizing your draft means you have completed your draft. You will not be able to work on this draft and will have to start another draft to continue to work on your assignment. Are you sure you want to finalize your draft? Click "Ok" to continue.',null,function(result){
			if(result) {
				$("#isfinaledraft").val(1);	
				$("#frm2").submit();
			}
		}) ;
	});
	
	
	
	$(".mwdeletewriting").bind("click", function(){
		var id = $(this).attr('id');
		var controllers = $(this).attr('controllers');
		var actions = $(this).attr('actions');
		jConfirm('Are you sure you want to delete this assignment?',null,function(result){
			if(result) {
				$("#writingid").val(id);
				document.getElementById("mwdeletefrm").action =  siteUrl + controllers + "/" + actions ;			
				$("#mwdeletefrm").submit();
			}
		});
	});
	
	
	
	$("#narrativeessaygraph").bind("click",function(){
		//alert('test') ;
		//$("#frm2").action = 'narrativeessay/secondtab';
		document.frm1.action = 'secondtab';
		document.frm1.submit();
	});
	
	
	
	$("#additionaluser").click(function(){
	
		var date_diff = $(this).attr("datediff")
		var expiredate = $(this).attr("expiredate") ;
		if(date_diff == 1) {
			jConfirm("Your subscription is expiring on ' " + expiredate + " ' so we recommend you not to purchase additional user at this time. Would you like to continue?",null,function(result){
				if( result) {
					$("#showrequestuser").removeClass('displaynone') ;	
					$("#additionaluser").addClass('displaynone') ;	
					$("#additionaluserviewstatus").addClass('displaynone') ;	
					
				} else {
					return false ;
				}
			}) ;
		} else {
			$("#showrequestuser").removeClass('displaynone') ;	
			$("#additionaluser").addClass('displaynone') ;
			$("#additionaluserviewstatus").addClass('displaynone') ;	
		}
		
			
	}) ;
	
	
	$("#requestsend").click(function(){
		var requestno = $("#requestuserno").val() ;
		var controllers = $("#controllers").val() ;
		
		if(requestno<=0) {
			jAlert('Please enter the numer for additional user?') ;
			return false;
		}

		if(isNaN(requestno)) {
			jAlert('Please enter the numeric value?') ;
		} else {
			var arrParts = requestno.split('.'); 
			if(arrParts.length > 1) {
				jAlert('Additional user number should be decimal?') ;
				return false;
			} else {
				document.frmadditionaluser.action = '' ; 
				document.frmadditionaluser.action = siteUrl + controllers + '/additionaluser';
				document.frmadditionaluser.submit() ;
			}
		}
		
		
	
	}) ;
	
	
	$("#requestcancel").click(function(){
		$("#showrequestuser").addClass('displaynone') ;	
		$("#additionaluser").removeClass('displaynone') ;	
		$("#additionaluserviewstatus").removeClass('displaynone') ;	
	});
	
	$('#endsemester').bind('click', function(){
		jConfirm('Are you sure to "End Semester" ?',null, function(result){
			if (result) {
				document.getElementById("frmTeacherPeriod").action =  siteUrl + 'semester/name' ;			
				$("#frmTeacherPeriod").submit();
			}			
		});
	});
	

//////////////////////////////////////////////////////////////////////////////////

		$('#tabs').tabs();	
		
		$('.mytooltip a').tooltip({ 
			track: true,
			delay: 0,
			showURL: false,
			showBody: " : ",
			fade: 250
		});
		
		$("#mwjlanguage").bind("change", function(){
			var lang = $(this).val();
			if(lang=="")
			{
				jAlert("Please select a language.");
			}
			else
			{	
				$("#frmlang").submit();
			}
		});
		
		$(".homeplan").bind("click", function() {		
			
			var plantype = $(this).attr('id');
			$(".plantype").val(plantype);
			
			$("#schoolplan").removeClass('tab_green_new') ;
			$("#schoolplan").addClass('tab_green_newinactive') ;
			
			$("#homeplan").removeClass('tab_green_newinactive') ;
			$("#homeplan").addClass('tab_green_new') ;
			
			$("#schoolplandiv").hide();	
			$("#homeplandiv").show();	
			
			//$("#frmLoginInfo").submit();											  
		});
		
		$(".finalizefirstsciencedraft").bind("click",function(){
			jConfirm('Finalizing your draft means you have completed your draft. You will not be able to work on this draft and will have to start another draft to continue to work on your assignment. Are you sure you want to finalize your draft? Click "Ok" to continue.', null, function(result){
				if(result) {
					$("#isfinal").val(1);
					$("#sciencefrm").submit();
				}
			}) ;
			 							  
		});
	/*	$(".finalizedescrdraft").bind("click",function(){
			jConfirm('Finalizing your draft means you have completed your draft. You will not be able to work on this draft and will have to start another draft to continue to work on your assignment. Are you sure you want to finalize your draft? Click "Ok" to continue.',null,function(result){
				if (result) {
					$("#isfinal").val(1);
					$("#frm2").submit();
				}
			}) 
		});*/
		
		$(".schoolplan").bind("click", function() {			 
			var plantype = $(this).attr('id');
			$(".plantype").val(plantype);
			$("#homeplandiv").hide();
			$("#schoolplandiv").show();	
			$("#homeplan").removeClass('tab_green_new') ;
			$("#homeplan").addClass('tab_green_newinactive') ;
			
			$("#schoolplan").removeClass('tab_green_newinactive') ;
			$("#schoolplan").addClass('tab_green_new') ;
			//$("#frmLoginInfo").submit();											  
		});
		
		$(".showexamplediv").bind("click", function() { 
			var opt = $(this).val();
			if(opt == 'Yes')
			{
				$("#showfshadow").show();
			}
			else
			{
				$("#showfshadow").hide();
			}
		});
		
		
		$(".addfriend").bind("click", function() {			
			$("#frmViewFriend").submit();											  
		});
		/////////********************js for timer *************///////////////////
		$(".stime").bind("click", function() {		
				
				var t = $(this).val();	
				if(t=='c')
				{					
					t = $("#customtime").val();				
				}
				
				$("#mwtimerdiv").html(t)
		});
				
		
		$("#mwtimerButton").bind("click", function() {
												   
				var mytime;
				
						var temptime = $('input[name=rtime]:checked').val();
						
						if(temptime == '')
						{
							jAlert("Please select or enter a time first.");
							return false;
						}
						else if(temptime == 'c')
						{
							mytime = $("#customtime").val();	
						}
						else
						{
							mytime = temptime;	
						}
						
				
				if(isNaN(mytime))
				{
					jAlert("Please select time.");
				}
				else
				{		
					$("#timerouterdiv").find('input').attr('disabled', 'disabled');
					timer(mytime);
				}
				
			});
		$("#mwstoptimerButton").bind("click", function() {
				
				$('#mwtimerdiv').countdown('pause');
				$("#timerouterdiv").find('input').removeAttr('disabled');
			});
		/////////******************** end of js for timer *************///////////////////
		
		
		$(".limitcommshare").bind("keyup", function() {
			var mylength = $(this).val();
			var mylimit = 400;
			if(mylength.length > mylimit)
			{
				jAlert("Limit of "+mylimit+" exceeded");
				var mycontent = mylength.substr(0,mylimit-1);
				$(".limitcommshare").val(mycontent);
			}
		});
		
		$(".limitintropers").bind("keyup", function() {
			var mylength = $(this).val();
			var mylimit = 300;
			if(mylength.length > mylimit)
			{
				jAlert("Limit of 300 exceeded");
				var mycontent = mylength.substr(0,mylimit-1);
				$(".limitintropers").val(mycontent);
			}
		});
		
		
		$(".limitpointpers").bind("keyup", function() {
			var myid = $(this).attr('id');
			
			var mylength = $(this).val();
			var mylimit = 300;
			if(mylength.length > mylimit)
			{
				jAlert("Limit of 300 exceeded");
				var mycontent = mylength.substr(0,mylimit-1);
				$("#"+myid).val(mycontent);
			}
		});
		
		$(".limitcounterpers").bind("keyup", function() {
			var mylength = $(this).val();
			var mylimit = 300;
			if(mylength.length > mylimit)
			{
				jAlert("Limit of 300 exceeded");
				var mycontent = mylength.substr(0,mylimit-1);
				$(".limitcounterpers").val(mycontent);
			}
		});
		
		$(".limithelpnarr").bind("keyup", function() {
			var mylength = $(this).val();
			var mylimit = 300;
			if(mylength.length > mylimit)
			{
				jAlert("Limit of 300 exceeded");
				var mycontent = mylength.substr(0,mylimit-1);
				$(".limithelpnarr").val(mycontent);
			}
		});
		
		$(".limithelppers").bind("keyup", function() {
			var mylength = $(this).val();
			var mylimit = 300;
			if(mylength.length > mylimit)
			{
				jAlert("Limit of 300 exceeded");
				var mycontent = mylength.substr(0,mylimit-1);
				$(".limithelppers").val(mycontent);
			}
		});
		
		$(".limithelpexpo").bind("keyup", function() {
			var mylength = $(this).val();
			var mylimit = 300;
			if(mylength.length > mylimit)
			{
				jAlert("Limit of 300 exceeded");
				var mycontent = mylength.substr(0,mylimit-1);
				$(".limithelpexpo").val(mycontent);
			}
		});
		
		$("#mwhelpmessage").bind("keyup", function() {
			var mylength = $(this).val();
			var mylimit = 300;
			if(mylength.length > mylimit)
			{
				jAlert("Limit of 300 exceeded");
				var mycontent = mylength.substr(0,mylimit-1);
				$("#mwhelpmessage").val(mycontent);
			}
			
		});
		
		$(".limitexamplediv").bind("keyup", function() {
			var mylength = $(this).val();
			var mylimit = 300;
			if(mylength.length > mylimit)
			{
				jAlert("Limit of 300 exceeded");
				var mycontent = mylength.substr(0,mylimit-1);
				$(".limitexamplediv").val(mycontent);
			}
			
		});
		
		$(".limitnarrprob").bind("keyup", function() {
			var mylength = $(this).val();
			var mylimit = 400;
			if(mylength.length > mylimit)
			{
				jAlert("Limit of 400 exceeded");
				var mycontent = mylength.substr(0,mylimit-1);
				$(".limitnarrprob").val(mycontent);
			}
		});
		
		$(".limitnarractr").bind("keyup", function() {
			var myid = $(this).attr('id');

			var mylength = $(this).val();
			var mylimit = 400;
			if(mylength.length > mylimit)
			{
				jAlert("Limit of 400 exceeded");
				var mycontent = mylength.substr(0,mylimit-1);
				$("#"+myid).val(mycontent);
			}
		});
		
		$(".limitnarrclimax").bind("keyup", function() {
			var mylength = $(this).val();
			var mylimit = 400;
			if(mylength.length > mylimit)
			{
				jAlert("Limit of 400 exceeded");
				var mycontent = mylength.substr(0,mylimit-1);
				$(".limitnarrclimax").val(mycontent);
			}
		});
		
		$(".limitnarractf").bind("keyup", function() {
			var myid = $(this).attr('id');

			var mylength = $(this).val();
			var mylimit = 400;
			if(mylength.length > mylimit)
			{
				jAlert("Limit of 400 exceeded");
				var mycontent = mylength.substr(0,mylimit-1);
				$("#"+myid).val(mycontent);
			}
		});
		
		$(".limitnarrresolution").bind("keyup", function() {
			var mylength = $(this).val();
			var mylimit = 400;
			if(mylength.length > mylimit)
			{
				jAlert("Limit of 400 exceeded");
				var mycontent = mylength.substr(0,mylimit-1);
				$(".limitnarrresolution").val(mycontent);
			}
		});
		
		$(".plan").bind("click", function() {								  
			var plan = $(this).attr('id');
			$(".planvalue").val(plan);
			$("#frmRegisterInfo").submit();											  
		});
		
		
		
		$(".emoticon").bind("click", function() {			 
				var con =  $("#emoticoncontroller").val() ;	
			showPage( $(this).attr('id'),  $(this).attr('title') ,con);
		});
		
		$(".getnewcode").bind("click", function() {
				var conc =  $("#mwcontroller").val() ;
			getClassCode( $(this).attr('id'), conc);
		});
		
		$(".requestadduser").bind("click", function() {
				$(".additionalusers").toggle();														
		});
		
		
		$(".sharingstatus").bind("click", function() {	
				$("#frmSharing").submit();
		});
		
		$(".blit").bind("click", function() {
			var lit = $(this).attr('id');	
			var st = document.getElementById(lit).checked;
			
			$(".blit").each( function() {									  
				$(".blit").removeAttr('checked');						  
 		   });
			//document.getElementById(lit).checked = true;			
			if(st == false)
			{
				document.getElementById(lit).checked = false;	
			}
			else
			{
				document.getElementById(lit).checked = true;
			}
		});
		
		$(".actionadd").bind("click", function() {	
			var Ids = $(this).attr('id').split("AND");

			$(".StudentId").val(Ids[0]);
			$(".TeacherId").val(Ids[1]);
			$(".TPeriodNo").val(Ids[2]);
			$(".TPeriodId").val(Ids[3]);
			$(".Action").val(Ids[4]);
			$("#frmListStudent").submit();
		});
		
		$(".actionaddFren").bind("click", function() {	
			var Ids = $(this).attr('id').split('AND');
			$(".RequestId").val(Ids[0]);
			$(".Action").val(Ids[1]);			
			$("#frmJoinFriend").submit();
		});		
		
		
		$(".viewfriend").bind("click", function() {	
			var Ids = $(this).attr('id').split("AND");
			
			$(".friendid").val(Ids[0]);
			$(".frienduserid").val(Ids[1]);
			$("#frmFriend").submit();
		});
		
		$(".editteacher").bind("click", function() {	
				//jAlert($(this).attr('id'));												 
//				$("#frmSchoolProfile").submit();
		});
		
		$(".delteacher").bind("click", function() {	
				$("#frmSchoolProfile").submit();
		});
		//////---- Grading.......
		
		$(".point").bind("click", function() 
			{					
				var pointcount = $(".pointcount").val();
				var id = $(this).attr('id');
				var valid =id.split('_');
				
				for(var i=0; i<= pointcount; i++)
				{
					$("#"+valid[0]+"_"+i).attr('src',  siteUrl +  "images/blankcircle.jpg");
				}
				
				
				
				$(".rubricpoint"+valid[0]).val(valid[1]);
				$(this).attr('src', siteUrl + "images/filledcircle.jpg");
				
				
		});
		
		$(".commentcheck").bind("keyup", function() {
			var mylength = $(this).val();
			var mylimit = 1200;
			if(mylength.length > mylimit)
			{
				jAlert("Limit of "+mylimit+" exceeded");
				var mycontent = mylength.substr(0,mylimit-1);
				$(".commentcheck").val(mycontent);
			}			
		});
		///view graded essay's
		$(".viewgradedessay").bind("click", function () {
				var essaytype = $(this).attr('id');
				$("#tessayg").val(essaytype);
				//jAlert($("#tessayg").val()); 
				$("#tfrmessayg").submit();
		});
		
		$(".teacheressayid").bind("click", function() {	
				var Ids = $(this).attr('id').split("AND");
				document.frmGradeEssay.EssayId.value = Ids[0];
				//document.frmGradeEssay.SubWork.value = Ids[1];
				//document.frmGradeEssay.StudentWorkId.value = Ids[2];
				$("#frmGradeEssay").submit();
		});
		//////end of view graded essay's
		
		//////----- Start Journal Grading.....
		$(".studid").bind("click", function() {	
				document.frmListJournal.StudentId.value = $(this).attr('id');
				$("#frmListJournal").submit();
		});
		
		$(".promptid").bind("click", function() {	
				var Ids = $(this).attr('id').split("AND");
				
				document.frmGradeJournal.PromptId.value = Ids[0];
				document.frmGradeJournal.CategoryId.value = Ids[1];
				document.frmGradeJournal.StudentWorkId.value = Ids[2];
				$("#frmGradeJournal").submit();
		});
		
		$(".grade").bind("click", function() {	
			var comment = $(".commentcheck").val();
			var flag = 0;
			
				var catCount = $(".categorycount").val();
				for(var i=0; i < catCount; i++)
				{
					if($(".rubricpoint"+i).val() == "")
					{
						var flag = 1;
					}
				}
				
				if(flag == 1)
				{
					jAlert("Grade the work before submitting.");	
				}
				else
				{
					$("#frmGradeJ").submit();
				}
				
		
		});
		///////--- End Journal Grading -----
		//////----- Start Current event Grading.....
		$(".pointc").bind("click", function() 
			{			
				
				var pointcount = $(".pointcount").val();
				var id = $(this).attr('id');
				var idarray = id.split('AND');
				var catid = idarray[1];
				var cattitle = idarray[2];
				var valid =idarray[0].split('_');
				$(".pointc").attr('src',  siteUrl +  "images/blankcircle.jpg");
				$(".rubricpoint").val(valid[1]);
				$(this).attr('src', siteUrl +  "images/filledcircle.jpg");
				$(".categorycc").val(catid);
				$(".categorytitlecc").val(cattitle);
				
			});
		
		$(".gradecc").bind("click", function() {	

			var comment = $(".commentcheck").val();
			var flag = 0;
			/*if(comment.length == 0 )
			{
				jAlert("Enter comment for the work. ");
				return false;
			}
			else
			{*/
				/*var catCount = $(".categorycount").val();
				for(var i=0; i < catCount; i++)
				{	
					if($(".rubricpoint"+i).val() == "")
					{
						var flag = 1;
					}
				}*/
				if($(".rubricpoint").val() == "")
				{
					var flag = 1;
				}
					
				if(flag == 1)
				{
					jAlert("Grade the work before submitting.");	
				}
				else
				{
					$("#frmGradecc").submit();
				}
				
			/*}*/
		});
		///////--- End current event Grading -----
		//////----- Start BOOK Report Grading.....
		$(".studidb").bind("click", function() {	
				document.frmListBook.StudentId.value = $(this).attr('id');
				$("#frmListBook").submit();
		});
		
		$(".bookid").bind("click", function() {	
				var Ids = $(this).attr('id').split("AND");
				document.frmGradeBook.BookId.value = Ids[0];
				document.frmGradeBook.StudentWorkId.value = Ids[1];
				$("#frmGradeBook").submit();
		});
		
		$(".gradeb").bind("click", function() {	
			var comment = $(".commentcheck").val();
			var flag = 0;
			/*if(comment.length == 0 )
			{
				jAlert("Enter comment for the work. ");
				return false;
			}
			else
			{*/
				var catCount = $(".categorycount").val();
				for(var i=0; i < catCount; i++)
				{
					
					if($(".rubricpoint"+i).val() == "")
					{
						var flag = 1;
					}
				}
				
				if(flag == 1)
				{
					jAlert("Grade the work before submitting.");	
				}
				else
				{
					$("#frmGradeB").submit();
				}
				
			/*}*/
		});
		///////--- End BOOK Report Grading -----
		
		//////----- Start Science Writing  Grading.....
		$(".studids").bind("click", function() {	
				document.frmListScience.StudentId.value = $(this).attr('id');
				$("#frmListScience").submit();
		});
		
		$(".scienceid").bind("click", function() {	
				var Ids = $(this).attr('id').split("AND");
				
				document.frmGradeScience.ScienceId.value = Ids[0];
				document.frmGradeScience.StudentWorkId.value = Ids[1];
				$("#frmGradeScience").submit();
		});
		
		$(".grades").bind("click", function() {	
			var comment = $(".commentcheck").val();
			var flag = 0;
			/*if(comment.length == 0 )
			{
				jAlert("Enter comment for the work. ");
				return false;
			}
			else
			{*/
				var catCount = $(".categorycount").val();
				for(var i=0; i < catCount; i++)
				{
					
					if($(".rubricpoint"+i).val() == "")
					{
						var flag = 1;
					}
				}
				
				if(flag == 1)
				{
					jAlert("Grade the work before submitting.");	
				}
				else
				{
					$("#frmGradeS").submit();
				}
				
			/*}*/
		});
		///////--- End Science Writing Grading -----
		
		//////----- Start Essay Writing  Grading.....
		$(".studide").bind("click", function() {	
				document.frmListEssay.StudentId.value = $(this).attr('id');
				$("#frmListEssay").submit();
		});
		
		$(".essayid").bind("click", function() {	
				var Ids = $(this).attr('id').split("AND");
				document.frmGradeEssay.EssayId.value = Ids[0];
				document.frmGradeEssay.SubWork.value = Ids[1];
				document.frmGradeEssay.StudentWorkId.value = Ids[2];
				$("#frmGradeEssay").submit();
		});
		
		$(".gradee").bind("click", function() {	
			var comment = $(".commentcheck").val();
			var flag = 0;
			/*if(comment.length == 0 )
			{
				jAlert("Enter comment for the work. ");
				return false;
			}
			else
			{*/
				var catCount = $(".categorycount").val();
				for(var i=0; i < catCount; i++)
				{
					
					if($(".rubricpoint"+i).val() == "")
					{
						var flag = 1;
					}
				}
				
				if(flag == 1)
				{
					jAlert("Grade the work before submitting.");	
				}
				else
				{
					$("#frmGradeE").submit();
				}
				
			/*}*/
		});
		///////--- End Essay Writing Grading -----
		
		
		//////////********* transfer student functionality ***********///////////////
		$(".teacheraction").bind("change", function() {	
			var cont =  $("#mwcontroller").val() ;	
			var actionSelect  = $(this).val(); 		
			
			if(actionSelect == 'T')
			{
				document.getElementById("frmTeacherPeriod").action =  siteUrl +  ""+cont+"/transferstudent";
			}
			if ( $(".studentstatus").is(":checked") ) 
			{
				$("#frmTeacherPeriod").submit();
			} else {	
				jAlert("Please select atleast one student.");
				return false;
			}
		});
		
		$(".teachertransferto").bind("click", function(){
				var val = $(this).val();
				if(val == 'mPeriod')
				{
					$("#teachertransfer").show();	
					$("#middletransfer").hide();
				}
				else if(val == 'mTeacher')	
				{
					$("#middletransfer").show();
					$("#teachertransfer").hide();	
				}
				else if(val == 'eTeacher')
				{
					$("#elementarytransfer").show();
				}
		});
		
		$(".mwdistransferperiod").change( function() {  
			var no = $(this).val();
			//jAlert(no);
					
			 var options = { 
				target: '#midperiods',   				// target element(s) to be updated with server response 
				beforeSubmit:  showRequestTransfer,  	// pre-submit callback 
				type:  'post',  						// pre-submit callback 				
				success: showResponseTransfer,
				url:  siteUrl +  "teacher/displayperioddropdown",// post-submit callback 
				dataType: "html", 
				error: function(xhr, ajaxOptions, thrownError) {
					jAlert("Error in processing.");	
					//jAlert(xhr.status);
					//jAlert(xhr.errorno);	
				}
			 };
				$("#frmTransfer").ajaxSubmit(options); 
				return false; 
		});
		function showRequestTransfer(formData, jqForm, options) { 
			var queryString = $.param(formData); 		 
			//jAlert('About to submit: \n\n' + queryString); 
			return true; 
		} 
		function showResponseTransfer(data)  {
			//jAlert(data)
			$("#teachertransfer").show();
			$("#midperiods").html(data);
			//jAlert("inside showresponse");
		}
		//////////*********end of transfer student functionality ***********///////////////
		
		$(".studentview").bind("click", function() {
			if($(this).attr('name') == 'B')
			{
				jAlert("Student is Barred no view available.");
			}
			else
			{
				var conc =  $("#mwcontroller").val() ;
				document.getElementById("frmTeacherPeriod").action =  siteUrl +  ""+conc+"/viewstudent";
				
				$("#studentid").val($(this).attr('id'));
				$("#frmTeacherPeriod").submit();
			}
			
			
			
		});
		
		
		$(".enableperiod").bind("click", function() {			 
			var cone =  $("#mwcontroller").val() ;	
			if($(this).attr('checked'))
			{
				$("#rostershow").show();
				enablePeriod( $(this).attr('checked'), $(this).attr('id'), cone );
			}
			else
			{
				var checked = $(this).attr('checked');
				var id = $(this).attr('id');
				jConfirm('While the period is disabled your students will not be able to send you any of their writing assignments. Would you like to continue to disable the period? You can always enable the period at a later date.', null, function(result){
					if (result) 
					{			
						$("#rostershow").hide();
						enablePeriod(checked, id, cone);
					}
					else
					{
					  $(".enableperiod").attr('checked','checked');
					}
				});
			}
			
		});
		
		
		/////////////for journal sharing
		$(".mwsjprompt").bind("click", function() {
			var value = $(this).attr('id');
			$("#jpromptid").val(value);
			$("#sharefrm").submit();
		});
		$(".mwjridshare").bind("click", function() {
			var value = $(this).attr('id');
			$("#jresponseid").val(value);
			$("#sharejresponse").submit();
		});
		
		$(".index_mwjridshare").bind("click", function() {
			var values = $(this).attr('id').split('AND');
			$("#jcatid").val(values[0]);
			$("#jpromptid").val(values[1]);
			$("#jresponseid").val(values[2]);			
			$("#sharejresponse").submit();
		});		
		
		$(".jcommentbutton").bind("click", function() {
			$("#postjcomment").toggle();
		});
		$(".mwjrate").bind("click", function() {
			var ratestr = $(this).attr('id');
			var rate = ratestr.substring(4,5);
			for(var i=1; i<=5; i++)
			{
				$("#rate"+i).attr('src', siteUrl +  "images/star.jpg");
			}
			for(var i=1; i<=rate; i++)
			{
				$("#rate"+i).attr('src', siteUrl +  "images/red_star.jpg");
			}
			$("#rating").val(rate);
		});
		
		$(".mwsharejournal").bind("click", function() {
			var jrval = $(this).attr('id'); 
			$("#jrid").val(jrval);	
			
			jConfirm('You are sharing this journal topic. Do you wish to continue?', null, function(result){
				if (result) 
				{			
					document.getElementById("journalfrm").action =  siteUrl +  "journal/share";
					$("#journalfrm").submit();
				}
			});
			
		});
		
		$(".mwunsharejournal").bind("click", function() {
			var jrval = $(this).attr('id'); 
			$("#jrid").val(jrval);
			
			jConfirm('You are unsharing this journal topic. Do you wish to continue?', null, function(result){
				if (result) 
				{			
					document.getElementById("journalfrm").action =  siteUrl +  "journal/unshare";
					$("#journalfrm").submit();
				}
			});			
			
			
		});
		
		$(".mweditjournal").bind("click", function(){
			var id = $(this).attr('id');
			$("#jrid").val(id);
			document.getElementById("journalfrm").action =  siteUrl +  "journal/editjournal";			
			$("#journalfrm").submit();
			
		});
		///journal sharing closed
		/////////////for book sharing
		$(".mwbshare").bind("click", function() {
			var value = $(this).attr('id');
			$("#bookid").val(value);
			$("#sharebookfrm").submit();								  
		});
		
		$(".mwbshare1").bind("click", function() {
			var value = $(this).attr('id');
			$("#bookid1").val(value);
			$("#sharebookfrm1").submit();								  
		});
		$(".mwbshare2").bind("click", function() {
			var value = $(this).attr('id');
			$("#bookid2").val(value);
			$("#sharebookfrm2").submit();								  
		});
		$(".mwbshare3").bind("click", function() {
			var value = $(this).attr('id');
			$("#bookid3").val(value);
			$("#sharebookfrm3").submit();								  
		});
		$(".mwbshare4").bind("click", function() {
			var value = $(this).attr('id');
			$("#bookid4").val(value);
			$("#sharebookfrm4").submit();								  
		});
		
		$(".index_mwbshare").bind("click", function() {
			var formId = $(this).attr('name');
			var value = $(this).attr('id');			
			//jAlert(value);
			$("#bookid_"+formId).val(value);
			$("#"+formId).submit();								  
		});		
		
		$(".bcommentbutton").bind("click", function() {
			$("#postbcomment").toggle();
		});
		/////////
		///////////////////////for book report //////////////////////////////////////
		$("#mwaddevent").bind("click", function() {		
			var risingno = $("#risingeventno").val();
			
			if(risingno<=7)
			{
				document.getElementById("textrising"+risingno).style.display ="block";		
				inserttextarea(risingno);
				
				document.getElementById("removebuttondiv").style.display ="block";
			}else
			{
				jAlert("You cannot add more than 7 rising events.")	
			}
		});
		
		
		$("#mwaddpoint").bind("click", function() {		
			var pointno= $("#mwpoint").val();
			insertpointarea(pointno);
		});
		
		$("#mwaddfallingevent").bind("click", function() {	
			var fallingno= $("#fallingeventno").val();
			if(fallingno<=5)
			{
				document.getElementById("textfalling"+fallingno).style.display ="block";	
				insertfallingarea(fallingno);
				document.getElementById("fallingremovebuttondiv").style.display ="block";
			}
			else
			{
					jAlert("You cannot add more than 5 falling events.")	
			}
		});
		
		
		/** 
		 * This Function is used for "SAVE" Book Report
		 */
		$(".mwbookgraphdecskip").bind("click", function(){
														
			var actions = $(this).attr('action');
			var valid 	= validationBookGraphSkip();
			var isAlert = $(this).attr('id');

			if (valid == true) {
				
				if(isAlert != 'NoAlert') {
					jConfirm('Saving your book report allows you to work on it later. The book report is not submitted to your teacher. Do you wish to save now?', null, function(result){
						if(result) {
							$("#submitgraph").val(1);
							$("#book2").action = siteUrl +  "book/"+actions;
							$("#book2").submit();
						}
					});	
				} else {
					
					$("#submitgraph").val(1);
					$("#book2").action = siteUrl +  "book/"+actions;
					$("#book2").submit();
				
				}
				
			} else {
				
				$("#submitgraph").val(0);
				var valid = validationBookGraphSkip1() ;
				
				if (valid == true ) {
					
					if(isAlert != 'NoAlert') {
						
						jConfirm('Saving your book report allows you to work on it later. The book report is not submitted to your teacher. Do you wish to save now?', null, function(result){
							
							if(result) {
								$("#book2").action = siteUrl +  "book/" + actions;
								$("#book2").submit();
							}
							
						});
						
					} else {
						
						$("#book2").action = siteUrl +  "book/" + actions;
						$("#book2").submit();
						
					}
					
				} else {
					
					jAlert('It seems that you have partially filled up the form. You can either leave all fields blank or fill all of them.' ) ;
				
				}

			}
			
		});
		

		/** 
		  * This Function is used for "SUBMIT" Book Report
		  */
		$(".mwbookgraphdec").bind("click", function(){
			
			var actions = $(this).attr('action');
			$('#isFinal').val(1);
			var valid 	= validationBookGraphSkip();
			
			//var valid = checkValidation();
			if( valid == true ) 
			{ 	
				jConfirm('When you submit your book report it goes to your teacher. Do you wish to submit your book report now?', null, function(result){
						if(result) {
							$("#submitgraph").val(1);
							$("#book2").action = siteUrl +  "book/"+actions;
							$("#book2").submit();
						}
				});	
				
			}  else {
				
				
				var valid = validationBookGraphSkip1() ;
				
				if (valid == true ) {
						
				jConfirm('When you submit your book report it goes to your teacher. Do you wish to submit your book report now?', null, function(result){
							
					if(result) {
						$("#submitgraph").val(0);
						$("#book2").action = siteUrl +  "book/"+actions;
						$("#book2").submit();
					}
							
				});
						

				} else {
					
					jAlert('It seems that you have partially filled up the form. You can either leave all fields blank or fill all of them.' ) ;
				
				}

			}			
		});		



		/** 
		  * This Function is used for "SUBMIT" Book Report
		  */
		$(".mwbookgraphdecupdate").bind("click", function(){
			
			$("#submitgraph").val(1);
			$('#isFinal').val(1);
			var valid = checkValidation();
			
			if( valid == true ) 
			{ 	
				jConfirm('When you submit your book report it goes to your teacher. Do you wish to submit your book report now?', null, function(result){
					if(result) {
						$("#book2").action = siteUrl +  "book/editgraph";
						$("#book2").submit();
					}
				});	
			}
			
		});
	
		
		$(".mweditbookreport").bind("click", function(){
			var id = $(this).attr('id');
			$("#bookid").val(id);
			document.getElementById("sharebookfrm").action =  siteUrl +  "book/editbookreport";						
			$("#sharebookfrm").submit();
			
		});	
		
		
		$(".mwbrate").bind("click", function() {
			var ratestr = $(this).attr('id');
			var rate = ratestr.substring(4,5);
			for(var i=1; i<=3; i++)
			{
				$("#rate"+i).attr('src', siteUrl +  "images/star.jpg");
			}
			var image;
			if(rate==1)
			{	image = "red_star.jpg";	
			}
			else if(rate==2)
			{	image = "yellow_star.jpg";	
			}
			else if(rate==3)
			{	image = "green_star.jpg";	
			}
			for(var i=1; i<=rate; i++)
			{
				$("#rate"+i).attr('src', siteUrl +  "images/"+image);
			}
			$("#rating").val(rate);
		});
		
		
		/////book report closed
		
		
		
		///////////////////for current event /////////////////////////////////
		//for current event sharing
		$(".mwcurrentshare").bind("click", function() {
			var value = $(this).attr('id');
			
			$("#bookid").val(value);
			$("#sharebookfrm").submit();								  
		});
		$(".mweditcurrentevent").bind("click", function(){
			var id = $(this).attr('id');
			$("#mwdeid").val(id);
			document.getElementById("demanagefrm").action =  siteUrl +  "currentevent/editcurrentevent";			
			$("#demanagefrm").submit();
			
		});		
		/////////////////end of for current event ////////////////////////////
	
		
		////////////for the share button on the manage descriptive draft page/////////////
		//for automatic submit/saving of the draft in the backgroud.
		//script on the page itself
		
		//for the save this draft button
		$(".mwupdatedescrdraft").bind("click", function() {  

			var str = $(this).attr('name');
			var no = str.charAt(str.length-1);
			
			var oEditor = FCKeditorAPI.GetInstance('Draft'+no) ;
			var con = oEditor.GetXHTML(true);
			$("#Draft"+no).val(con);
			
			 var options = { 
				target:        '#output'+no,   	// target element(s) to be updated with server response 
				beforeSubmit:  showRequest,  	// pre-submit callback 
				type:  'post',  				// pre-submit callback 				
				success:       showResponseDraft,
				url:       siteUrl +  "descriptiveessay/updatedraft",// post-submit callback 
				error: function(xhr, ajaxOptions, thrownError) {
					jAlert("Error in saving draft.");
					//jAlert(xhr.status);
					//jAlert(xhr.errorno);					
				}
			 };
				$("#mwfrmessay"+no).ajaxSubmit(options); 
				return false; 
		});
		
		function showRequest(formData, jqForm, options) { 
			var queryString = $.param(formData); 		 
			//jAlert('About to submit: \n\n' + queryString); 
			return true; 
		} 
		
		function showResponseDraft(data)  {
			//jAlert("inside showresponse");
		}
	
		function showRequest(formData, jqForm, options) { 
			var queryString = $.param(formData); 		 
			return true; 
		} 
		
		/*function showResponseDesc(data)  {
			window.location = siteUrl+"descriptiveessay/thanks2"
		}*/
		
		$(".mwdescdraft").bind("click", function() {
			var sval= $(this).attr('id'); 
			$("#mwdeid").val(sval);	
			document.getElementById("demanagefrm").action =  siteUrl +  "descriptiveessay/draftagain";
			$("#demanagefrm").submit();
		});
		
		/////for the share button
		$(".mwdescshare").bind("click", function() {
			var sval= $(this).attr('id'); 
			$("#mwdeid").val(sval);		
			document.getElementById("demanagefrm").action =  siteUrl +  "descriptiveessay/share";
			$("#demanagefrm").submit();
		});
		
		///for the publish button on the manage descriptive draft page
		$(".mwdescpublish").bind("click", function() {
			var sval= $(this).attr('id');
			jConfirm('When you publish your essay you will be able to share with your friends and your teacher will be able to grade it. Only the latest draft submitted by you will be published.', null, function(result){
				if (result) 
				{			
					$("#mwdeid").val(sval);			
					document.getElementById("demanagefrm").action =  siteUrl +  "descriptiveessay/publish";
					$("#demanagefrm").submit();
				}
			});			
			
		});
		
		/////for the help button
		$(".mwdeschelp").bind("click", function() {
			var sval= $(this).attr('id'); 
			$("#mwdeid").val(sval);		
			document.getElementById("demanagefrm").action =  siteUrl +  "descriptiveessay/help";
			$("#demanagefrm").submit();
		});
		//////////////////////////////////////////////////////////////////////////////
		
		////////////for the expository section/////////////
		//for the save this draft button
		$(".mwupdateexpodraft").bind("click", function() {  

			var str = $(this).attr('name');
			var no = str.charAt(str.length-1);
			
			var oEditor = FCKeditorAPI.GetInstance('Draft'+no) ;
			var con = oEditor.GetXHTML(true);
			$("#Draft"+no).val(con);
			
			 var options = { 
				target:        '#output'+no,   	// target element(s) to be updated with server response 
				beforeSubmit:  showRequest,  	// pre-submit callback 
				type:  'post',  				// pre-submit callback 				
				success:       showResponseDraft,
				url:       siteUrl +  "expositoryessay/updatedraft",// post-submit callback 
				error: function(xhr, ajaxOptions, thrownError) {
					jAlert("Error in saving draft.");
					//jAlert(xhr.status);
					//jAlert(xhr.errorno);					
				}
			 };
				$("#mwfrmessay"+no).ajaxSubmit(options); 
				return false; 
		});
		
		
		
		//for the finalize draft button
/*		$(".mwfinalizeexpodraft").bind("click", function() {   

			var str = $(this).attr('name');
			var actions = $(this).attr('actions');
			
			
			var no = str.charAt(str.length-1);
			$("#isfinal"+no).val(1);
			
			var oEditor = FCKeditorAPI.GetInstance('Draft'+no) ;
			var con = oEditor.GetXHTML(true);
			$("#Draft"+no).val(con);
			
			 var options = { 
				target:        '#output'+no,   	// target element(s) to be updated with server response 
				beforeSubmit:  showRequest,  	// pre-submit callback 
				type:  'post',  				// pre-submit callback 				
				success:       showResponseExpo,
				url:       siteUrl + actions+"/updatedraft",// post-submit callback 
				error: function(xhr, ajaxOptions, thrownError) {
					jAlert("Error in saving draft.");
					//jAlert(xhr.status);
					//jAlert(xhr.errorno);					
				}
			 };
				$("#mwfrmessay"+no).ajaxSubmit(options); 
				return false; 
		});
		 */
		function showResponseExpo(data)  {
			window.location = siteUrl+"expositoryessay/thanks2"
		}
		
		
		$("#subdraftagainexpofinal").bind("click", function() {
			$("#isfinalexpodraft").val(1);	
			$("#frm2").submit();
		});
		///for the draft button on the manage expository draft page
		$(".mwexpodraft").bind("click", function() {
			var sval= $(this).attr('id'); 
			$("#mwdeid").val(sval);	
			document.getElementById("demanagefrm").action =  siteUrl +  "expositoryessay/draftagain";
			$("#demanagefrm").submit();
		});
		/////for the share button
		$(".mwexposhare").bind("click", function() {
			var sval= $(this).attr('id'); 
			$("#mwdeid").val(sval);		
			document.getElementById("demanagefrm").action =  siteUrl +  "expositoryessay/share";
			$("#demanagefrm").submit();
		});
		///for the publish button on the manage expository draft page
		$(".mwexpopublish").bind("click", function() {
			var sval= $(this).attr('id');
			jConfirm('When you publish your essay you will be able to share with your friends and your teacher will be able to grade it. Only the latest draft submitted by you will be published.', null, function(result){
				if (result) 
				{			
					$("#mwdeid").val(sval);			
					document.getElementById("demanagefrm").action =  siteUrl +  "expositoryessay/publish";
					$("#demanagefrm").submit();
				}
			});			
			
		});
		$(".mwexpohelp").bind("click", function() {
			var sval= $(this).attr('id'); 
			$("#mwdeid").val(sval);	
			document.getElementById("demanagefrm").action =  siteUrl +  "expositoryessay/help";
			$("#demanagefrm").submit();
		});
		//////////////////////**** persuasive essay ****////////////////////////////////////////////////////
/*		$("#subdraftagainpersfinal").bind("click", function() {
			$("#isfinalpersdraft").val(1);	
			$("#frm2").submit();
		});
*/		//for the save this draft button
		$(".mwupdatepersdraft").bind("click", function() {  
													   
			var str = $(this).attr('name');
			var no = str.charAt(str.length-1);
		
			
			var oEditor = FCKeditorAPI.GetInstance('introduction') ;
			var intro = oEditor.GetXHTML(true);  //jAlert(intro);
			$("#introduction").val(intro);
			
			var oEditor = FCKeditorAPI.GetInstance('body') ;
			var bo = oEditor.GetXHTML(true);	//jAlert(bo);
			$("#body").val(bo);
			
			var oEditor = FCKeditorAPI.GetInstance('conclusion') ;
			var con = oEditor.GetXHTML(true);	//jAlert(con);
			$("#conclusion").val(con);
			
			 var options = { 
				target:        '#output'+no,   		// target element(s) to be updated with server response 
				beforeSubmit:  showRequestPers,  	// pre-submit callback 
				type:  'post',  					// pre-submit callback 				
				success:       showResponseDraft,
				url:       siteUrl +  "persuasiveessay/updatedraft",// post-submit callback 
				error: function(xhr, ajaxOptions, thrownError) {
					jAlert("Error in saving draft.");
					//jAlert(xhr.status);
					//jAlert(xhr.errorno);					
				}
			 };
				$("#mwfrmessay"+no).ajaxSubmit(options); 
				return false; 
		});
		function showRequestPers(formData, jqForm, options) { 
			var queryString = $.param(formData); 	
			//jAlert('About to submit: \n\n' + queryString); 
			return true; 
		} 
		
		
		//for the finalize draft button
		$(".mwfinalizepersdraft").bind("click", function() {   
														  
			var str = $(this).attr('name');
			var no = str.charAt(str.length-1);
			$("#isfinal"+no).val(1);
			
			var oEditor = FCKeditorAPI.GetInstance('introduction') ;
			var intro = oEditor.GetXHTML(true);  //jAlert(intro);
			$("#introduction").val(intro);
			
			var oEditor = FCKeditorAPI.GetInstance('body') ;
			var bo = oEditor.GetXHTML(true);	//jAlert(bo);
			$("#body").val(bo);
			
			var oEditor = FCKeditorAPI.GetInstance('conclusion') ;
			var con = oEditor.GetXHTML(true);	//jAlert(con);
			$("#conclusion").val(con);
			jConfirm('Finalizing your draft means you have completed your draft. You will not be able to work on this draft and will have to start another draft to continue to work on your assignment. Are you sure you want to finalize your draft? Click "Ok" to continue.',null,function(result){
				if(result) {
					 var options = { 
						target:        '#output'+no,   	// target element(s) to be updated with server response 
						beforeSubmit:  showRequest,  	// pre-submit callback 
						type:  'post',  				// pre-submit callback 				
						success:       showResponsePers,
						url:       siteUrl +  "persuasiveessay/updatedraft",// post-submit callback 
						error: function(xhr, ajaxOptions, thrownError) {
							jAlert("Error in saving draft.");
						}
					 };
					$("#mwfrmessay"+no).ajaxSubmit(options); 
					return false; 
				}
			});
			
		});
		 
		function showResponsePers(data)  {
			window.location = siteUrl + "persuasiveessay/thanks2"
		}
		////////////for the share button on the manage persuasive draft page/////////////
		$(".mwpersshare").bind("click", function() {
			var sval= $(this).attr('id'); 
			$("#mwpeid").val(sval);		
			document.getElementById("demanagefrm").action =  siteUrl +  "persuasiveessay/share";
			$("#demanagefrm").submit();
		});
		///for the draft button on the manage persuasive draft page
		$(".mwpersdraft").bind("click", function() {
			var sval= $(this).attr('id'); 
			$("#mwpeid").val(sval);	
			document.getElementById("demanagefrm").action =  siteUrl +  "persuasiveessay/draftagain";
			$("#demanagefrm").submit();
		});
		
		
		
		///for the publish button on the manage persuasive draft page
		$(".mwperspublish").bind("click", function() {
			var sval= $(this).attr('id');
			jConfirm('When you publish your essay you will be able to share with your friends and your teacher will be able to grade it. Only the latest draft submitted by you will be published.', null, function(result){
				if (result) 
				{			
					$("#mwpeid").val(sval);			
					document.getElementById("demanagefrm").action =  siteUrl +  "persuasiveessay/publish";
					$("#demanagefrm").submit();
				}
			});	
			
		});
		
		
		
		$(".mwpershelp").bind("click", function() {
			var sval= $(this).attr('id'); 
			$("#mwpeid").val(sval);		
			document.getElementById("demanagefrm").action =  siteUrl +  "persuasiveessay/help";
			$("#demanagefrm").submit();
		});
		
		
		
		//////////////////////////////////////////////////////////////////////////////
		///Current event section
		$(".mwnewstitle").bind("click", function() {
			var id = $(this).attr('id');
			$("#currenteventid").val(id); //3
			$("#newsfrm").submit();	
		})
		$(".mwcurrentshare").bind("click", function() {
			var sval= $(this).attr('id'); 
			$("#mwdeid").val(sval);		
			document.getElementById("demanagefrm").action =  siteUrl +  "currentevent/share";
			$("#demanagefrm").submit();
		});
		$(".ccommentbutton").bind("click", function() {
			$("#postccomment").toggle();
		});
		
		//////end of current event section
		
		////////////for the draft button on the manage science wtiting page
		//for the save this draft button
		$(".mwupdatesciencedraft").bind("click", function() {  
													   
			var str = $(this).attr('name');
			var no = str.charAt(str.length-1);
		
						
			var oEditor = FCKeditorAPI.GetInstance('question') ;
			var field1 = oEditor.GetXHTML(true);  //jAlert(field1);
			$("#question").val(field1);
			
			var oEditor = FCKeditorAPI.GetInstance('research') ;
			var field2 = oEditor.GetXHTML(true);	//jAlert(field2);
			$("#research").val(field2);
			
			var oEditor = FCKeditorAPI.GetInstance('hypothesis') ;
			var field3 = oEditor.GetXHTML(true);	//jAlert(field3);
			$("#hypothesis").val(field3);
			
			var oEditor = FCKeditorAPI.GetInstance('procedure') ;
			var field4 = oEditor.GetXHTML(true);	//jAlert(field4);
			$("#procedure").val(field4);
			
			var oEditor = FCKeditorAPI.GetInstance('observation') ;
			var field5 = oEditor.GetXHTML(true);	//jAlert(field5);
			$("#observation").val(field5);
			
			var oEditor = FCKeditorAPI.GetInstance('conclusion') ;
			var field6 = oEditor.GetXHTML(true);	//jAlert(field6);
			$("#conclusion").val(field6);
					
			 var options = { 
				//target:        '#output'+no,   		// target element(s) to be updated with server response 
				beforeSubmit:  showRequestScie,  	// pre-submit callback 
				type:  'post',  					// pre-submit callback 				
				success:       showResponseDraftScience,
				url:       siteUrl +  "science/updatedraft",// post-submit callback 
				dataType: "json", 
				error: function(xhr, ajaxOptions, thrownError) {
					jAlert("Error in saving draft. " + thrownError);
					//jAlert(xhr.status);
					//jAlert(xhr.errorno);					
				}
			 };
				$("#mwfrmessay"+no).ajaxSubmit(options); 
				return false; 
		});
		function showRequestScie(formData, jqForm, options) { 
			var queryString = $.param(formData); 	
			//jAlert('About to submit: \n\n' + queryString); 
			return true; 
		} 
		function showResponseDraftScience(data)  {
			//jAlert(data);
			//return false;
			var no = data.no;
			var image = data.imgg;
			
			$("#output"+no).html(data.msg);
			
			if(data.imgg != '')
			{
				//jAlert("inside dataimg")
				//$("#scienceimg"+no).remove();
				if($("#draftimage"+no).val()=='')
				{
					$("#science_image_box"+no).prepend("<img id='scienceimg"+no+"' />");
				}
				$("#scienceimg"+no).attr('src',siteUrl+'science/'+image);
				$("#draftimage"+no).val(image);
			}
			
		}
		
			 
		 
		
		
		//for the finalize draft button
		$(".mwfinalizesciencedraft").bind("click", function() {   
														  
			var str = $(this).attr('name');
			var no = str.charAt(str.length-1);
			$("#isfinal"+no).val(1);
			
			var oEditor = FCKeditorAPI.GetInstance('question') ;
			var field1 = oEditor.GetXHTML(true);  //jAlert(field1);
			$("#question").val(field1);
			
			var oEditor = FCKeditorAPI.GetInstance('research') ;
			var field2 = oEditor.GetXHTML(true);	//jAlert(field2);
			$("#research").val(field2);
			
			var oEditor = FCKeditorAPI.GetInstance('hypothesis') ;
			var field3 = oEditor.GetXHTML(true);	//jAlert(field3);
			$("#hypothesis").val(field3);
			
			var oEditor = FCKeditorAPI.GetInstance('procedure') ;
			var field4 = oEditor.GetXHTML(true);	//jAlert(field4);
			$("#procedure").val(field4);
			
			var oEditor = FCKeditorAPI.GetInstance('observation') ;
			var field5 = oEditor.GetXHTML(true);	//jAlert(field5);
			$("#observation").val(field5);
			
			var oEditor = FCKeditorAPI.GetInstance('conclusion') ;
			var field6 = oEditor.GetXHTML(true);	//jAlert(field6);
			$("#conclusion").val(field6);
			
			jConfirm('Finalizing your draft means you have completed your draft. You will not be able to work on this draft and will have to start another draft to continue to work on your assignment. Are you sure you want to finalize your draft? Click "Ok" to continue.',null,function(result){
				if(result) {
					var options = { 
						//target:        '#output'+no,   	// target element(s) to be updated with server response 
						beforeSubmit:  showRequestScie,  	// pre-submit callback 
						type:  'post',  				// pre-submit callback 				
						success:       showResponseScience,
						url:       siteUrl +  "science/updatedraft",// post-submit callback 
						dataType: "json", 
						error: function(xhr, ajaxOptions, thrownError) {
							jAlert("Error in saving draft.");
						}
			 };
					$("#mwfrmessay"+no).ajaxSubmit(options); 
					return false;		
				}
			});
			  
		});
		 
		function showResponseScience(data)  {
			var no = data.no;
			$("#output"+no).html(data.msg);
			window.location = siteUrl + "science/thanks2"
		}
		
		/////////////////////////////////////////////////////////////////////
		
		$("#subdraftagainsciencefinal").bind("click", function() {
			jConfirm('Finalizing your draft means you have completed your draft. You will not be able to work on this draft and will have to start another draft to continue to work on your assignment. Are you sure you want to finalize your draft? Click "Ok" to continue.',null,function(result){
				if(result) {
					$("#isfinalsciencedraft").val(1);	
					$("#sciencefrm").submit();
				}
			});
		});
		
		$(".mwsciencedraft").bind("click", function() {
			var sval= $(this).attr('id'); 
			$("#mwsid").val(sval);			
			document.getElementById("smanage").action =  siteUrl +  "science/draftagain";
			$("#smanage").submit();
		});
		
		//for the share button on the manage science wtiting page
		$(".mwscienceshare").bind("click", function() {
			var sval= $(this).attr('id');
			$("#mwsid").val(sval);			
			document.getElementById("smanage").action =  siteUrl +  "science/share";
			$("#smanage").submit();
		});
		
		
		//for the publish button on the manage science wtiting page
		$(".mwsciencepublish").bind("click", function() {
			var sval= $(this).attr('id');
			
			jConfirm('When you publish your essay you will be able to share with your friends and your teacher will be able to grade it. Only the latest draft submitted by you will be published.', null, function(result){
				if (result) 
				{	
					$("#mwsid").val(sval);
					document.getElementById("smanage").action =  siteUrl +  "science/publish";
					$("#smanage").submit();
				}
			});	
			
		});
		
				
		
		//////////////for narrative essay/////////////////////////////////
		//for the save this draft button
		$(".mwupdatenarrdraft").bind("click", function() {  

			var str = $(this).attr('name');
			var no = str.charAt(str.length-1);
			
			var oEditor = FCKeditorAPI.GetInstance('Draft'+no) ;
			var con = oEditor.GetXHTML(true);
			$("#Draft"+no).val(con);
			
			 var options = { 
				target:        '#output'+no,   	// target element(s) to be updated with server response 
				beforeSubmit:  showRequest,  	// pre-submit callback 
				type:  'post',  				// pre-submit callback 				
				success:       showResponseDraft,
				url:       siteUrl +  "narrativeessay/updatedraft",// post-submit callback 
				error: function(xhr, ajaxOptions, thrownError) {
					jAlert("Error in saving draft.");
					//jAlert(xhr.status);
					//jAlert(xhr.errorno);					
				}
			 };
				$("#mwfrmessay"+no).ajaxSubmit(options); 
				return false; 
		});
		function showRequest(formData, jqForm, options) { 
			var queryString = $.param(formData); 		 
			//jAlert('About to submit: \n\n' + queryString); 
			return true; 
		} 
		function showResponseDraft(data)  {
			//jAlert("inside showresponse");
		}
		
		//for the finalize draft button
		/*$(".mwfinalizenarrdraft").bind("click", function() {   
														  
			var str = $(this).attr('name');
			var no = str.charAt(str.length-1);
			$("#isfinal"+no).val(1);
			
			var oEditor = FCKeditorAPI.GetInstance('Draft'+no) ;
			var con = oEditor.GetXHTML(true);
			$("#Draft"+no).val(con);
			
			 var options = { 
				target:        '#output'+no,   	// target element(s) to be updated with server response 
				beforeSubmit:  showRequest,  	// pre-submit callback 
				type:  'post',  				// pre-submit callback 				
				success:       showResponseNarr,
				url:       siteUrl +  "narrativeessay/updatedraft",// post-submit callback 
				error: function(xhr, ajaxOptions, thrownError) {
					jAlert("Error in saving draft.");
					//jAlert(xhr.status);
					//jAlert(xhr.errorno);					
				}
			 };
				$("#mwfrmessay"+no).ajaxSubmit(options); 
				return false; 
		});*/
		function showRequest(formData, jqForm, options) { 
			var queryString = $.param(formData); 		 
			return true; 
		} 
		function showResponseNarr(data)  {
			window.location = siteUrl+"narrativeessay/thanks2"
		}
		
/*		$("#subdraftagainnarrfinal").bind("click", function() {
			$("#isfinalnarrdraft").val(1);	
			$("#frm2").submit();
		});
*/		
		$("#mwaddcharacter").bind("click", function() {		
			var pointno= $("#ncharacterno").val();
			insertpcharacterarea(pointno);
		});
		$("#mwpaddevent").bind("click", function() {
			var pointno= $("#nrisingeventno").val();
			if(pointno<=7) {
				insertprisingeventarea(pointno);
			} else {
				jAlert("You cannot add more than 7 rising events.")	
			}
		});
		$("#mwnaddfallingevent").bind("click", function() {
			var pointno= $("#nfallingeventno").val();

			if(pointno<=5)	{
				insertpfallingeventarea(pointno);			
			} else	{
					jAlert("You cannot add more than 5 falling events.")	
			}
		});
		$(".mwnarrpublish").bind("click", function() {	
			var sval= $(this).attr('id');			
			jConfirm('When you publish your essay you will be able to share with your friends and your teacher will be able to grade it. Only the latest draft submitted by you will be published.', null, function(result){
				if (result) 
				{			
					$("#mwdeid").val(sval);	
					document.getElementById("demanagefrm").action =  siteUrl +  "narrativeessay/publish";				
					$("#demanagefrm").submit();
				}
			});
			
		});
		$(".mwnarrshare").bind("click", function() {
			var sval= $(this).attr('id'); 
			
			$("#mwdeid").val(sval);		
			document.getElementById("demanagefrm").action =  siteUrl +  "narrativeessay/share";
			$("#demanagefrm").submit();
		});
		$(".mwnarrdraft").bind("click", function() {
			var sval= $(this).attr('id'); 
			$("#mwdeid").val(sval);			
			document.getElementById("demanagefrm").action =  siteUrl +  "narrativeessay/draftagain";
			$("#demanagefrm").submit();
		});
		$(".mwnarrhelp").bind("click", function() {
			var sval= $(this).attr('id'); 
			$("#mwdeid").val(sval);		
			document.getElementById("demanagefrm").action =  siteUrl +  "narrativeessay/help";
			$("#demanagefrm").submit();
		});
		/////////end of for narrative essay////////////////////////////////////
		
		
		// --- Search Friends ...
		$(".friendreq").bind("click", function() {
											   	
			var Ids = $(this).attr('id').split("AND");
			
			var userid = Ids[1];
			var studentid = Ids[0];
			$(".studentid").val(studentid);
			$(".userid").val(userid);
			$("#frmFriendList").submit();
		});
		
		//---- End Search Friends .....
		
		
		//---- Help Response ....
		$('.index_helpresponse').bind('click', function() {
			var helpid =  $(this).attr('id');
			$("#helpresponseid").val(helpid);
			$('#frmHelpResponse').submit();
		});
		// End Help Response
		
	});   //end of $(document).ready( function() 
	
	/*function validatepers(frm)
	{
		jAlert("jitender");
		var po = $("#mwpoint").val();
			jAlert(po);
			var flag = 0?
		for(var i=1; i<po ; i++)
		{
				var mylength = $(".limitpointpers"+i).val();
				var mylimit = 10;
				if(mylength.length > mylimit)
				{
					jAlert("Limit of 300 exceeded");
					var mycontent = mylength.substr(0,mylimit-1);
					$(".limitpointpers"+i).val(mycontent);
					$(".limitpointpers"+i).focus();
					return false;
				}
		}
	}*/

	function removerisingdiv()
	{
		var risingno= document.getElementById("risingeventno").value ;
		var deldiv = risingno-1;		
		document.getElementById("textrising"+deldiv).innerHTML ="";
		document.getElementById("risingeventno").value = deldiv;
	}
	function editremoverisingdiv()
	{
		var risingno= document.getElementById("risingeventno").value ;
		var deldiv = risingno-1;
		
		if(deldiv==4)
		{
			document.getElementById("removebuttondiv").innerHTML ="";
			document.getElementById("textrising"+deldiv).innerHTML ="";
			document.getElementById("risingeventno").value = deldiv;
			
			document.getElementById("textrising"+deldiv).style.display ="none";		
			document.getElementById("removebuttondiv").style.display ="none";
		}
		else
		{
			document.getElementById("textrising"+deldiv).innerHTML ="";
			document.getElementById("risingeventno").value = deldiv;
		}
	}
	
	/*function updatedescrdraft(no)
	{		
		$.ajax({
		  type: "GET",
		  url:  siteUrl +  "descriptiveessay/updatedraft", 
		  data: 'id='+id, 
		  dataType: "html",
		  
		  error: function(msg) { 
		  	//jAlert("There is an error: " + msg);		  	
		  },
		  
		  success: function(msg) {
		  	//$("#mwtextpfallingevent"+id).html(msg);
			//var newval= parseInt(id)+1;
			//document.getElementById("nfallingeventno").value = newval;
		  },
		  
		  complete: function(html) {
		  	//jAlert("completed");
		  }
		  
		});
	}*/
	
	function insertpfallingeventarea(id)
	{		
		$.ajax({
		  type: "GET",
		//url: "http://ksiprojects.net/projects/school/book/insertrisingdiv", 
		  url:  siteUrl +  "narrativeessay/insertpfallingeventdiv", 
		  data: 'id='+id, 
		  dataType: "html",
		  
		  error: function(msg) { 
		  	//jAlert("There is an error: " + msg);		  	
		  },
		  
		  success: function(msg) {
		  	$("#mwtextpfallingevent"+id).html(msg);
			var newval= parseInt(id)+1;
			document.getElementById("nfallingeventno").value = newval;
		  },
		  
		  complete: function(html) {
		  	//jAlert("completed");
		  }
		  
		});
	}
	function removepfallingeventdiv()
	{
		var risingno= document.getElementById("nfallingeventno").value ;
		var deldiv = risingno-1;
		document.getElementById("mwtextpfallingevent"+deldiv).innerHTML ="";
		document.getElementById("nfallingeventno").value = deldiv;
	}
	function insertprisingeventarea(id)
	{		
		$.ajax({
		  type: "GET",
		//url: "http://ksiprojects.net/projects/school/book/insertrisingdiv", 
		  url:  siteUrl +  "narrativeessay/insertprisingeventdiv", 
		  data: 'id='+id, 
		  dataType: "html",
		  
		  error: function(msg) { 
		  	//jAlert("There is an error: " + msg);		  	
		  },
		  
		  success: function(msg) {
		  	$("#mwtextpevent"+id).html(msg);
			var newval= parseInt(id)+1;
			document.getElementById("nrisingeventno").value = newval;
		  },
		  
		  complete: function(html) {
		  	//jAlert("completed");
		  }
		  
		});
	}
	function removeprisingeventdiv()
	{
		var risingno= document.getElementById("nrisingeventno").value ;
		var deldiv = risingno-1;
		document.getElementById("mwtextpevent"+deldiv).innerHTML ="";
		document.getElementById("nrisingeventno").value = deldiv;
	}
	function insertpcharacterarea(id)
	{		
		$.ajax({
		  type: "GET",
		//url: "http://ksiprojects.net/projects/school/book/insertrisingdiv", 
		  url:  siteUrl +  "narrativeessay/insertcharacterdiv", 
		  data: 'id='+id, 
		  dataType: "html",
		  
		  error: function(msg) { 
		  	//jAlert("There is an error: " + msg);		  	
		  },
		  
		  success: function(msg) {
		  	$("#mwtextcharacter"+id).html(msg);
			var newval= parseInt(id)+1;
			document.getElementById("ncharacterno").value = newval;
		  },
		  
		  complete: function(html) {
		  	//jAlert("completed");
		  }
		  
		});
	}
	function removepcharacterdiv()
	{
		var divno= document.getElementById("ncharacterno").value ;
		var deldiv = divno-1;
		document.getElementById("mwtextcharacter"+deldiv).innerHTML ="";
		document.getElementById("ncharacterno").value = deldiv;
	}
	function inserttextarea(id)
	{			
		$.ajax({
		  type: "GET",
		//url: "http://ksiprojects.net/projects/school/book/insertrisingdiv", 
		  url:  siteUrl +  "book/insertrisingdiv", 
		  data: 'id='+id, 
		  dataType: "html",
		  
		  error: function(msg) { 
		  	//jAlert("There is an error: " + msg);		  	
		  },
		  
		  success: function(msg) {
		  	$("#textrising"+id).html(msg);
			var newval= parseInt(id)+1;
			document.getElementById("risingeventno").value = newval;
		  },
		  
		  complete: function(html) {
		  	//jAlert("completed");
		  }
		  
		});
	}
	 ////////////////////////////////////
	 function removefallingdiv()
	{
		var risingno= document.getElementById("fallingeventno").value ;
		var deldiv = risingno-1;
		document.getElementById("textfalling"+deldiv).innerHTML ="";
		document.getElementById("fallingeventno").value = deldiv;
	}
	
	function editremovefallingdiv()
	{
		var risingno= document.getElementById("fallingeventno").value ;
		var deldiv = risingno-1; 
		//jAlert(deldiv)
		//jAlert(document.getElementById("textfalling"+deldiv));
		if(deldiv==2)
		{
			document.getElementById("fallingremovebuttondiv").innerHTML ="";
			
			document.getElementById("textfalling"+deldiv).innerHTML ="";
			document.getElementById("fallingeventno").value = deldiv;
			
			document.getElementById("textfalling"+deldiv).style.display ="none";	
			document.getElementById("fallingremovebuttondiv").style.display ="none";
		}
		else
		{
			document.getElementById("textfalling"+deldiv).innerHTML ="";
			document.getElementById("fallingeventno").value = deldiv;
		}
	}
	
	function insertfallingarea(id)
	{			
		$.ajax({
		  type: "GET",
		  url:  siteUrl +  "book/insertfallingdiv", 
		  data: 'id='+id,
		  dataType: "html", 
		  
		  error: function(msg) { 
		  	//jAlert("There is an error: " + msg);		  	
		  },
		  
		  success: function(msg) {
		  	$("#textfalling"+id).html(msg);
			var newval= parseInt(id)+1;
			document.getElementById("fallingeventno").value = newval;
		  },
		  
		  complete: function(html) {
		  	//jAlert("completed");
		  }
		  
		});
	}
	//////////////////
	////for point in persuasive essay
	function insertpointarea(id)
	{	
		
		$.ajax({
		  type: "GET",
		//url: "http://ksiprojects.net/projects/school/book/insertrisingdiv", 
		  url:  siteUrl +  "persuasiveessay/insertpointdiv", 
		  data: 'id='+id, 
		  dataType: "html",
		  
		  error: function(msg) { 
		  	//jAlert("There is an error: " + msg);		  	
		  },
		  
		  success: function(msg) {
		  	$("#mwpointtext"+id).html(msg);
			var newval= parseInt(id)+1;
			document.getElementById("mwpoint").value = newval;
		  },
		  
		  complete: function(html) {
		  	//jAlert("completed");
		  }
		  
		});
	}
	
	function removepointdiv()
	{	
		var pointno = document.getElementById("mwpoint").value ;
		var deldiv = pointno-1;
		document.getElementById("mwpointtext"+deldiv).innerHTML ="";
		document.getElementById("mwpoint").value = deldiv;
	}
	//end of point in persusasive essay
	
	
	function showPage( id, title ,con )
	{		
		
		$.ajax({
		  type: "GET",
		  url:  siteUrl +  ""+con+"/setemotions",
		  data: 'eid='+id+'&etitle='+title, 
		  dataType: "json",  
		  
		  error: function(msg) {
		  	//jAlert("There is an error: " + msg);		  	
		  },
		  
		  success: function(msg) {
		  	$("#myemoticon").html(msg.imgObj);
			$("#myemoticonheader").html(msg.imgSObj);
		  	$("#etitle").html(msg.title);	
			$("#emoticontitle").html(msg.title);
		  },
		  
		  complete: function(html) {
		  	//jAlert("completed");
		  }
		  
		});
	}
	
	
	function timer(sedtime)
	{
			
				var newYear = new Date(2009,2,14);
				var mytime= sedtime*60;
				$("#mwtimerdiv").removeClass('hasCountdown');

				$('#mwtimerdiv').countdown({until: mytime, format:'M : S', onExpiry: function() { jAlert('Time Up') }});
				
				$('#mwtimerdiv').toggle(function() {
				 },     function() {     //$(this).text('Remove');
							
							$('#mwtimerdiv').countdown({until: newYear});
					 } );
	}
		
	function showPeriod(id)
	{	
		$.ajax({
		  type: "GET",
		  url:  siteUrl +  "student/setprofileperiod", 
		  data: 'PId='+id, 
		  dataType: "html", 
		  
		  error: function(msg) {
		  	//jAlert("There is an error: " + msg);		  	
		  },
		  
		  success: function(msg) {
		  	$("#TeacherName").html(msg.Teachername);
		  },
		  
		  complete: function(html) {
		  	//jAlert("completed");
		  }
		  
		});
	}
	
	function getClassCode(Id,conc)
	{
		$.ajax({
		  type: "GET",
		  url:  siteUrl +  "" + conc + "/classcode",
		  data: 'TID='+Id,
		  dataType: "html", 
		  
		  error: function(msg) {
		  	//jAlert("There is an error: " + msg);		  	
		  },
		  
		  success: function(msg) {
		 	$("#placenewcode").html(msg);
		  },
		  
		  complete: function(html) {
		  //	jAlert("completed");
		  }
		  
		});
	}
	
	function enablePeriod(Value, id, cone)
	{
		if( Value ) {
			Value = 0;	
		} else {
			Value = 1;	
		}
		
		$.ajax({
		  type: "GET",
		  url:  siteUrl +  ""+cone+"/enableperiod",
		  data: 'status='+Value+"&PeriodNo="+id, 
		  dataType: "json",  
		  
		  error: function(msg) {
		  	//jAlert("There is an error: " + msg);		  	
		  },
		  
		  success: function(msg) {
	 		$("#periodstatus").html(msg.activity);
			
		  },
		  
		  complete: function(html) {
		  	//jAlert("completed");
		  }
		  
		});
	}
	
	function SetAllCheckBoxes(FormName, currName, FieldName)
	{
		if(document.forms[FormName].elements[currName].checked)
		{
			CheckValue = true;
		}
		else
		{
			CheckValue = false;
		}
			
		if(!document.forms[FormName])
			return;
		
		
		var objCheckBoxes = document.forms[FormName].elements[FieldName];
		
		if(!objCheckBoxes)
			return;
			
		var countCheckBoxes = objCheckBoxes.length;
		
		if(!countCheckBoxes)
			objCheckBoxes.checked = CheckValue;
		else
			// set the check value for all check boxes
			for(var i = 0; i < countCheckBoxes; i++)
				objCheckBoxes[i].checked = CheckValue;
	}
	
	function validatejcomment(frm)
	{
			if($("#rating").val() == "")
			{
				jAlert("Please rate the journal by clicking on the stars.");
				$("#rating").focus();
				return false;
			}
			if($("#postcomment").val() == "")
			{
				jAlert("Please enter your comments on the journal.");
				$("#postcomment").focus();
				return false;
			}
		return true;
	}
	
	function validatehelpresponse(frm)
	{
			if($("#postcomment").val() == "")
			{
				jAlert("Please enter your help response.");
				$("#postcomment").focus();
				return false;
			}
		return true;
	}	
	
	function validatebcomment(frm) {			
	
		if($("#postcomment").val() == "") {	
			jAlert("Please enter your comments on the book report.");
			$("#postcomment").focus();
			return false;
		}
		return true;
	}
	
	
	function validateccomment(frm) {		
		
		if($("#title").val() == "") {	
			jAlert("Please enter a title for your article.");
			$("#title").focus();
			return false;
		}
		
		if($("#writer").val() == "") {	
			jAlert("Please enter a writer for your article.");
			$("#writer").focus();
			return false;
		}
		
		if($("#newssource").val() == ""){	
			jAlert("Please enter a news source for your article.");
			$("#newssource").focus();
			return false;
		}
		
		var oEditor = FCKeditorAPI.GetInstance('summary') ;
		var con = oEditor.GetXHTML(true);
		
		if(con == "") {	
			jAlert("Please enter a summary for your article.");
			return false;
		}
			/*var oEditor = FCKeditorAPI.GetInstance('Draft'+no) ;
			var con = oEditor.GetXHTML(true);
			$("#Draft"+no).val(con);	summary
			*/		
		return true;
			
	}
	
	
	function validatehelp(frm) {
		
		if($("#mwhelpmessage").val() ==""){
			jAlert("Enter a message for your help");
			$("#mwhelpmessage").focus();
			return false;
		}
		
		flag = 0;
		var obj = document.getElementsByName("friendid[]");
		
		for(i=0; i < obj.length; i++){
			if(obj[i].checked==true) {
				flag = 1;
			}
		}
		
		if(flag==0){
			jAlert("Choose atleast one friend first.");	
			return false;
		}
		
		return true;
	}
	
	
	function limitnarractr(elem) {
		var mylength = elem.value;
		var mylimit = 400;
		if(mylength.length > mylimit){
			jAlert("Limit of 400 exceeded");
			var mycontent = mylength.substr(0,mylimit-1);
			document.getElementById(elem.id).value = mycontent;
		}
	}
	
	
	function limitnarractf(elem) {		
		var mylength = elem.value;
		var mylimit  = 400;
		if(mylength.length > mylimit){
			jAlert("Limit of 400 exceeded");
			var mycontent = mylength.substr(0,mylimit-1);
			document.getElementById(elem.id).value = mycontent;
		}
	}
	
	
	function limitpointpers(elem) {		
		var mylength = elem.value;
		var mylimit  = 300;
		if(mylength.length > mylimit) {
			jAlert("Limit of 300 exceeded");
			var mycontent = mylength.substr(0,mylimit-1);
			document.getElementById(elem.id).value = mycontent;
		}
	}
	
	
	function showHelpForm() {
		$(".helpform").removeClass('hidden');	
	}
	
	
	function submitjsharepage()	{
		$("#jsharepage").submit();
	}
	
	
	function submitcsharepage()	{
		$("#jsharepage").submit();
	}
	
	
	function submitessaysharepage() {
		$("#jsharepage").submit();
	}
	

	function finalizefirstexpodraft() {		
		$("#isfinal").val(1);
		$("#frm2").submit();
	}
	
	
	function finalizefirstsciencedraft(){		
		
		jConfirm('Finalizing your draft means you have completed your draft. You will not be able to work on this draft and will have to start another draft to continue to work on your assignment. Are you sure you want to finalize your draft? Click "Ok" to continue.', null, function(result){
			if(result) {
				$("#isfinal").val(1);
				$("#sciencefrm").submit();
			}		
		}) ;
	}
	
	
	function checkValidationCurrentEvent(){	
			
		if($("#title").val()=="")
		{
			jAlert("Please enter the event title.");
			$("#title").focus();
			return false;
		}
		if($("#writer").val()=="")
		{
			jAlert("Please enter the writer name.");
			$("#writer").focus();
			return false;
		}
		if($("#newssource").val()=="")
		{
			jAlert("Please enter the news source.");
			$("#newssource").focus();
			return false;
		}
		var oEditor = FCKeditorAPI.GetInstance('summary') ;
		var con = oEditor.GetXHTML(true);
		if(con == "")
		{	
			jAlert("Please enter the summary for this event.");
			return false;
		}


		return true;	
	}


   // use for validation of book graph skip   
	function validationBookGraphSkip() {	
		
		//return false ;
		var temp = true ; 
		var countrisingevent = 0;
		if($("#problem").val() && $("#climax").val() && $("#resolution").val() )
		{
			countrisingevent = $('#risingeventno').val();
			for(var k=1; k<countrisingevent; k++)
			{
				if($("#rising"+k).val()) {
				} else {
					temp = false ;
					break ;
				}
			}
			if (temp == true ) {
				countfallingevent = $('#fallingeventno').val();
				for(var f=1; f<countfallingevent; f++)
				{
					if($("#falling"+f).val()) {
					} else {
						temp = false ;
					}
				}
			}
			
		} else {
			temp = false ;
		}
		return temp ;		
	}
	
	
	function validationBookGraphSkip1() {	
		
		//return false ;
		var temp = true ; 
		var countrisingevent = 0;
		if( ($("#problem").val() == "") && ($("#climax").val() =="") && ($("#resolution").val() == "") ) {
			
			countrisingevent = $('#risingeventno').val();
			
			for(var k=1; k<countrisingevent; k++){
				if($("#rising"+k).val()=="") {
				} else {
					temp = false ;
					break ;
				}
			}
			
			if (temp == true ) {
				countfallingevent = $('#fallingeventno').val();
				for(var f=1; f<countfallingevent; f++)
				{
					if($("#falling"+f).val()=="") {
					} else {
						temp = false ;
					}
				}
			}
			
		} else {
			temp = false ;
		}
		return temp ;		
	}
	
	
	//for plot a graph at the time of creating a new book report
	function checkValidation() {	
	
		var countrisingevent = 0;
		var countfallingevent = 0;
		
		if($("#problem").val()=="")	{
			jAlert("Please enter the Problem/Conflict for your graph.");
			$("#problem").focus();
			return false;
		}
		countrisingevent = $('#nrisingeventno').val();
		
		for(var k=1; k<countrisingevent; k++) {
			if($("#risingevent"+k).val()==""){
				jAlert("Please enter the rising action event "+k+" for your graph.");
				$("#risingevent"+k).focus();
				return false;
			}
		}
		
		if($("#climax").val()==""){
			jAlert("Please enter the Climax for your graph.");
			$("#climax").focus();
			return false;
		}
		
		countfallingevent = $('#nfallingeventno').val();
		for(var f=1; f<countfallingevent; f++){
			if($("#fallingevent"+f).val()=="")
			{
				jAlert("Please enter the falling action event "+f+" for your graph.");
				$("#fallingevent"+f).focus();
				return false;
			}
		}
		
		if($("#resolution").val()==""){
			jAlert("Please enter the Resolution for your graph.");
			$("#resolution").focus();
			return false;
		}
				
		return true;	
	}
	
	
	function checkValidationBookReport() {	
	
		var countrisingevent 	= 0;
		var countfallingevent 	= 0;
		
		if($("#problem").val()==""){
			jAlert("Please enter the Problem/Conflict for your graph.");
			$("#problem").focus();
			return false;
		}
		
		countrisingevent = $('#risingeventno').val();
		for(var k=1; k<=countrisingevent; k++) {
			if($("#rising"+k).val()=="")
			{
				jAlert("Please enter the rising action event "+k+" for your graph.");
				$("#rising"+k).focus();
				return false;
			}
		}
		
		if($("#climax").val()==""){
			jAlert("Please enter the Climax for your graph.");
			$("#climax").focus();
			return false;
		}
		
		countfallingevent = $('#fallingeventno').val();
		for(var f=1; f<=countfallingevent; f++) {
			if($("#falling"+f).val()=="") {
				jAlert("Please enter the falling action event "+f+" for your graph.");
				$("#falling"+f).focus();
				return false;
			}
		}
		
		if($("#resolution").val()=="") {	
			jAlert("Please enter the Resolution for your graph.");
			$("#resolution").focus();
			return false;
		}
				
		return true;	
	}
	
	
	//ajax function for the graph at the time of creating a book report 
	function createGraph() {
		var options = { 
			//target:        '#output'+no,   	// target element(s) to be updated with server response 
			//beforeSubmit:  showRequest,  	// pre-submit callback 
			type:  'post',  				// pre-submit callback 				
			beforeSubmit:  plotBeforeSubmit, 
			success:       showGraph,
			//dataType: 'html', 
			complete: function() {	
				
					//$("#bookreportgraph_wrapper").html(data);
			},
			url:       siteUrl +  "book/plotgraph",// post-submit callback 
			error: function(xhr, ajaxOptions, thrownError) {
				jAlert("Error in ploting graph.");
									
			}
		};
		$("#book2").ajaxSubmit(options); 
	}
	
	
	function createGraphNarrative() {
		var options = { 
			//target:        '#output'+no,   	// target element(s) to be updated with server response 
			//beforeSubmit:  showRequest,  	// pre-submit callback 
			type:  'post',  				// pre-submit callback 				
			beforeSubmit:  plotBeforeSubmit1, 
			success:       showGraph1,
			//dataType: 'html', 
			complete: function() {	
				
					//$("#bookreportgraph_wrapper").html(data);
			},
			url:       siteUrl +  "narrativeessay/plotgraph",// post-submit callback 
			error: function(xhr, ajaxOptions, thrownError) {
				jAlert("Error in ploting graph.");
									
			}
		};
		$("#frm1").ajaxSubmit(options); 
	}
	
	
	function showGraph(data) {
		$(".plot_graph").css('display', 'block');
		//("#plotgraphmainbox").slideDown(800);		
		$("#plotgraphmainbox").animate({height:'350px'},800);
		$("#bookreportgraph_wrapper").html(data);

	}
	
	
	function showGraph1(data) {
		$(".plot_graph").css('display', 'block');
		//("#plotgraphmainbox").slideDown(800);		
		$("#plotgraphmainbox").animate({height:'350px'},800);
		$("#bookreportgraph_wrapper").html(data);

	}
	
	
	function plotBeforeSubmit() {
		var valid = checkValidationBookReport();
		if( valid == true ) { 		
			$("#plotgraphmainbox").animate({height:'0px'},800);
		} else {
			return false;
		}
	}
	
	
	function plotBeforeSubmit1() {
		var valid = checkValidation();
		if( valid == true ) { 		
			$("#plotgraphmainbox").animate({height:'0px'},800);
		} else {
			return false;
		}
		return true ;
	}
	
	//ajax function for the graph at the time of displaying a book report 
	function displayGraph() {
		var options = { 
			type:  'post',  				// pre-submit callback 				
			beforeSubmit:  displayBeforeSubmit, 
			success:       displayPlotGraph,
			//dataType: 'json',
			complete: function() {	},
			url:       siteUrl +  "book/plotgraph",// post-submit callback 
			error: function(xhr, ajaxOptions, thrownError) {
				jAlert("Error in ploting graph.");
									
			}
		};
		$("#book2").ajaxSubmit(options); 
	}
	
	function displayPlotGraph(data) {

		$(".plot_graph").css('display', 'block');
		$("#plotgraphmainbox").animate({height:'350px'},800);
		$("#bookreportgraph_wrapper").html(data);

	}
	
	function displayBeforeSubmit() {
		$("#plotgraphmainbox").animate({height:'0px'},800);
	}