	$(window).load( function() {
		
		//alert($(".fck").parent().attr('id'));
		//alert($(".fck").parent().attr('name'));		
		
		$(".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() {

		//alert($('.fckeditor').attr('class'));

		$('#tabs').tabs();	
		
		$('.mytooltip a').tooltip({ 
			track: true,
			delay: 0,
			showURL: false,
			showBody: " : ",
			fade: 250
		});
		
		$("#mwjlanguage").bind("change", function(){
			var lang = $(this).val();
			if(lang=="")
			{
				alert("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();											  
		});
		
		$(".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 == '')
						{
							alert("Please select or enter a time first.")	
							return false;
						}
						else if(temptime == 'c')
						{
							mytime = $("#customtime").val();	
						}
						else
						{
							mytime = temptime;	
						}
						
				
				if(isNaN(mytime))
				{
					alert("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)
			{
				alert("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)
			{
				alert("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)
			{
				alert("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)
			{
				alert("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)
			{
				alert("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)
			{
				alert("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)
			{
				alert("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)
			{
				alert("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)
			{
				alert("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)
			{
				alert("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)
			{
				alert("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)
			{
				alert("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)
			{
				alert("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)
			{
				alert("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");
			//alert(Ids);
			$(".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() {	
				//alert($(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("blur", function() {	
												   
				var limit = $(".commentlimit").val();
				limit = limit -1 ;
				//alert(limit)
				var comment = $(".commentcheck").val();
				var commentlength = comment.length
				if(commentlength > limit )
				{
					alert("Enter comment only up to 10 characters.");
					return false;
				}
				else
				{
					return true;
				}
		});*/
		$(".commentcheck").bind("keyup", function() {
			var mylength = $(this).val();
			var mylimit = 1200;
			if(mylength.length > mylimit)
			{
				alert("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);
				//alert($("#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;
			if(comment.length == 0 )
			{
				alert("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)
				{
					alert("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 )
			{
				alert("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)
				{
					alert("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 )
			{
				alert("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)
				{
					alert("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 )
			{
				alert("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)
				{
					alert("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 )
			{
				alert("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)
				{
					alert("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 {	
				alert("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();
			//alert(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) {
					alert("Error in processing.");	
					//alert(xhr.status);
					//alert(xhr.errorno);	
				}
			 };
				$("#frmTransfer").ajaxSubmit(options); 
				return false; 
		});
		function showRequestTransfer(formData, jqForm, options) { 
			var queryString = $.param(formData); 		 
			//alert('About to submit: \n\n' + queryString); 
			return true; 
		} 
		function showResponseTransfer(data)  {
			//alert(data)
			$("#teachertransfer").show();
			$("#midperiods").html(data);
			//alert("inside showresponse");
		}
		//////////*********end of transfer student functionality ***********///////////////
		
		$(".studentview").bind("click", function() {
			if($(this).attr('name') == 'B')
			{
				alert("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 check =	window.confirm("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.");
				if(check)
				{
					$("#rostershow").hide();
					enablePeriod( $(this).attr('checked'), $(this).attr('id'), cone );
				}
				else
				{
					$(this).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);	
			var check = window.confirm("You are sharing this journal topic. Do you wish to continue ?");
			if(check)
			{
				document.getElementById("journalfrm").action =  siteUrl +  "journal/share";
				$("#journalfrm").submit();
			}
		});
		
		$(".mwunsharejournal").bind("click", function() {
			var jrval = $(this).attr('id'); 
			$("#jrid").val(jrval);	
			var check = window.confirm("You are unsharing this journal topic. Do you wish to continue ?");
			if(check)
			{
				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');			
			//alert(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
			{
				alert("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
			{
					alert("You cannot add more than 5 falling events.")	
			}
		});
		
		$(".mwbookgraphdec").bind("click", function(){
			$("#submitgraph").val(1);
			var valid = checkValidation();
			if( valid == true ) 
			{ 	
				$("#book2").action = siteUrl +  "book/bookgraph";
				$("#book2").submit();
			} 			
		});
		
		$(".mwbookgraphdecskip").bind("click", function(){
			$("#submitgraph").val(0);
			$("#book2").action = siteUrl +  "book/bookgraph";
			$("#book2").submit();			
		});
		
		$(".mwbookgraphdecupdate").bind("click", function(){
			$("#submitgraph").val(1);
			var valid = checkValidation();
			if( valid == true ) 
			{ 	
				$("#book2").action = siteUrl +  "book/editgraph";
				$("#book2").submit();
			} 			
		});
		
		$(".mwbookgraphdecskipupdate").bind("click", function(){
			$("#submitgraph").val(0);
			$("#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) {
					alert("Error in saving draft.");
					//alert(xhr.status);
					//alert(xhr.errorno);					
				}
			 };
				$("#mwfrmessay"+no).ajaxSubmit(options); 
				return false; 
		});
		function showRequest(formData, jqForm, options) { 
			var queryString = $.param(formData); 		 
			//alert('About to submit: \n\n' + queryString); 
			return true; 
		} 
		function showResponseDraft(data)  {
			//alert("inside showresponse");
		}
		
		//for the finalize draft button
		$(".mwfinalizedescrdraft").bind("click", function() {   
														  
			var str = $(this).attr('name');
			var no = str.charAt(str.length-1);
			$("#isfinal"+no).val(1);
			//alert($("#isfinal").val())
			
			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:       showResponseDesc,
				url:       siteUrl +  "descriptiveessay/updatedraft",// post-submit callback 
				error: function(xhr, ajaxOptions, thrownError) {
					alert("Error in saving draft.");
					//alert(xhr.status);
					//alert(xhr.errorno);					
				}
			 };
				$("#mwfrmessay"+no).ajaxSubmit(options); 
				return false; 
		});
		function showRequest(formData, jqForm, options) { 
			var queryString = $.param(formData); 		 
			return true; 
		} 
		function showResponseDesc(data)  {
			//alert("inside showresponse");
			//$.reloadPageDOM();
			//window.location.reload(true);
			window.location = siteUrl+"descriptiveessay/thanks2"
		}
		
		/*//for the finalize button when first saving the draft
		//$("#finalizedesc").bind("click", function(){			
		$(".finalizedesc").bind("click", function(){													  			
			//alert("hello")
			$("#isfinal").val(1);
			//alert($("#isfinal").val());
			//alert($("#frm2").attr('action'))
			$("#frm2").submit();
			//alert(document.getElementById("frm2"));
			//document.getElementById("frm2").submit();
			//document.frm2.submit();
		});*/
		
		///for the draft button on the manage descriptive draft page
		
		$("#subdraftagainfinal").bind("click", function() {
			$("#isfinaldescdraft").val(1);	
			$("#frm2").submit();
		});
		$(".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 conf = window.confirm("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.");			
			if(conf)
			{	
				var sval= $(this).attr('id');
				$("#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) {
					alert("Error in saving draft.");
					//alert(xhr.status);
					//alert(xhr.errorno);					
				}
			 };
				$("#mwfrmessay"+no).ajaxSubmit(options); 
				return false; 
		});
		
		
		
		//for the finalize draft button
		$(".mwfinalizeexpodraft").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:       showResponseExpo,
				url:       siteUrl +  "expositoryessay/updatedraft",// post-submit callback 
				error: function(xhr, ajaxOptions, thrownError) {
					alert("Error in saving draft.");
					//alert(xhr.status);
					//alert(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 conf = window.confirm("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.");			
			if(conf)
			{
				var sval= $(this).attr('id');
				$("#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);  //alert(intro);
			$("#introduction").val(intro);
			
			var oEditor = FCKeditorAPI.GetInstance('body') ;
			var bo = oEditor.GetXHTML(true);	//alert(bo);
			$("#body").val(bo);
			
			var oEditor = FCKeditorAPI.GetInstance('conclusion') ;
			var con = oEditor.GetXHTML(true);	//alert(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) {
					alert("Error in saving draft.");
					//alert(xhr.status);
					//alert(xhr.errorno);					
				}
			 };
				$("#mwfrmessay"+no).ajaxSubmit(options); 
				return false; 
		});
		function showRequestPers(formData, jqForm, options) { 
			var queryString = $.param(formData); 	
			//alert('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);  //alert(intro);
			$("#introduction").val(intro);
			
			var oEditor = FCKeditorAPI.GetInstance('body') ;
			var bo = oEditor.GetXHTML(true);	//alert(bo);
			$("#body").val(bo);
			
			var oEditor = FCKeditorAPI.GetInstance('conclusion') ;
			var con = oEditor.GetXHTML(true);	//alert(con);
			$("#conclusion").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:       showResponsePers,
				url:       siteUrl +  "persuasiveessay/updatedraft",// post-submit callback 
				error: function(xhr, ajaxOptions, thrownError) {
					alert("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 conf = window.confirm("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.");			
			if(conf)
			{
				var sval= $(this).attr('id');
				$("#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);  //alert(field1);
			$("#question").val(field1);
			
			var oEditor = FCKeditorAPI.GetInstance('research') ;
			var field2 = oEditor.GetXHTML(true);	//alert(field2);
			$("#research").val(field2);
			
			var oEditor = FCKeditorAPI.GetInstance('hypothesis') ;
			var field3 = oEditor.GetXHTML(true);	//alert(field3);
			$("#hypothesis").val(field3);
			
			var oEditor = FCKeditorAPI.GetInstance('procedure') ;
			var field4 = oEditor.GetXHTML(true);	//alert(field4);
			$("#procedure").val(field4);
			
			var oEditor = FCKeditorAPI.GetInstance('observation') ;
			var field5 = oEditor.GetXHTML(true);	//alert(field5);
			$("#observation").val(field5);
			
			var oEditor = FCKeditorAPI.GetInstance('conclusion') ;
			var field6 = oEditor.GetXHTML(true);	//alert(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) {
					alert("Error in saving draft. " + thrownError);
					//alert(xhr.status);
					//alert(xhr.errorno);					
				}
			 };
				$("#mwfrmessay"+no).ajaxSubmit(options); 
				return false; 
		});
		function showRequestScie(formData, jqForm, options) { 
			var queryString = $.param(formData); 	
			//alert('About to submit: \n\n' + queryString); 
			return true; 
		} 
		function showResponseDraftScience(data)  {
			//alert(data);
			//return false;
			var no = data.no;
			var image = data.imgg;
			
			$("#output"+no).html(data.msg);
			
			if(data.imgg != '')
			{
				//alert("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);  //alert(field1);
			$("#question").val(field1);
			
			var oEditor = FCKeditorAPI.GetInstance('research') ;
			var field2 = oEditor.GetXHTML(true);	//alert(field2);
			$("#research").val(field2);
			
			var oEditor = FCKeditorAPI.GetInstance('hypothesis') ;
			var field3 = oEditor.GetXHTML(true);	//alert(field3);
			$("#hypothesis").val(field3);
			
			var oEditor = FCKeditorAPI.GetInstance('procedure') ;
			var field4 = oEditor.GetXHTML(true);	//alert(field4);
			$("#procedure").val(field4);
			
			var oEditor = FCKeditorAPI.GetInstance('observation') ;
			var field5 = oEditor.GetXHTML(true);	//alert(field5);
			$("#observation").val(field5);
			
			var oEditor = FCKeditorAPI.GetInstance('conclusion') ;
			var field6 = oEditor.GetXHTML(true);	//alert(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:       showResponseScience,
				url:       siteUrl +  "science/updatedraft",// post-submit callback 
				dataType: "json", 
				error: function(xhr, ajaxOptions, thrownError) {
					alert("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() {
			$("#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 conf = window.confirm("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.");			
			if(conf)
			{	
				var sval= $(this).attr('id');
				$("#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) {
					alert("Error in saving draft.");
					//alert(xhr.status);
					//alert(xhr.errorno);					
				}
			 };
				$("#mwfrmessay"+no).ajaxSubmit(options); 
				return false; 
		});
		function showRequest(formData, jqForm, options) { 
			var queryString = $.param(formData); 		 
			//alert('About to submit: \n\n' + queryString); 
			return true; 
		} 
		function showResponseDraft(data)  {
			//alert("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) {
					alert("Error in saving draft.");
					//alert(xhr.status);
					//alert(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();
			insertprisingeventarea(pointno);
		});
		$("#mwnaddfallingevent").bind("click", function() {
			var pointno= $("#nfallingeventno").val();
			insertpfallingeventarea(pointno);
		});
		$(".mwnarrpublish").bind("click", function() {	
			var conf = window.confirm("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.");			
			if(conf)
			{
				var sval= $(this).attr('id');
				$("#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)
	{
		alert("jitender");
		var po = $("#mwpoint").val();
			alert(po);
			var flag = 0?
		for(var i=1; i<po ; i++)
		{
				var mylength = $(".limitpointpers"+i).val();
				var mylimit = 10;
				if(mylength.length > mylimit)
				{
					alert("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) { 
		  	//alert("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) {
		  	//alert("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) { 
		  	//alert("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) {
		  	//alert("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) { 
		  	//alert("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) {
		  	//alert("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) { 
		  	//alert("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) {
		  	//alert("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) { 
		  	//alert("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) {
		  	//alert("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; 
		//alert(deldiv)
		//alert(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) { 
		  	//alert("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) {
		  	//alert("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) { 
		  	//alert("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) {
		  	//alert("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) {
		  	//alert("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) {
		  	//alert("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() { alert('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) {
		  	//alert("There is an error: " + msg);		  	
		  },
		  
		  success: function(msg) {
		  	$("#TeacherName").html(msg.Teachername);
		  },
		  
		  complete: function(html) {
		  	//alert("completed");
		  }
		  
		});
	}
	
	function getClassCode(Id,conc)
	{
		$.ajax({
		  type: "GET",
		  url:  siteUrl +  "" + conc + "/classcode",
		  data: 'TID='+Id,
		  dataType: "html", 
		  
		  error: function(msg) {
		  	//alert("There is an error: " + msg);		  	
		  },
		  
		  success: function(msg) {
		 	$("#placenewcode").html(msg);
		  },
		  
		  complete: function(html) {
		  //	alert("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) {
		  	//alert("There is an error: " + msg);		  	
		  },
		  
		  success: function(msg) {
	 		$("#periodstatus").html(msg.activity);
			
		  },
		  
		  complete: function(html) {
		  	//alert("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() == "")
			{
				alert("Please rate the journal by clicking on the stars.");
				$("#rating").focus();
				return false;
			}
			if($("#postcomment").val() == "")
			{
				alert("Please enter your comments on the journal.");
				$("#postcomment").focus();
				return false;
			}
		return true;
	}
	
	function validatehelpresponse(frm)
	{
			if($("#postcomment").val() == "")
			{
				alert("Please enter your help response.");
				$("#postcomment").focus();
				return false;
			}
		return true;
	}	
	
	function validatebcomment(frm)
	{			
			if($("#postcomment").val() == "")
			{	
				alert("Please enter your comments on the book report.");
				$("#postcomment").focus();
				return false;
			}
		return true;
	}
	function validateccomment(frm)
	{		
			if($("#title").val() == "")
			{	
				alert("Please enter a title for your article.");
				$("#title").focus();
				return false;
			}
			if($("#writer").val() == "")
			{	
				alert("Please enter a writer for your article.");
				$("#writer").focus();
				return false;
			}
			if($("#newssource").val() == "")
			{	
				alert("Please enter a news source for your article.");
				$("#newssource").focus();
				return false;
			}
			var oEditor = FCKeditorAPI.GetInstance('summary') ;
			var con = oEditor.GetXHTML(true);
			if(con == "")
			{	
				alert("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() =="")
			{
				alert("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)
			{
				alert("Choose atleast one friend first.");	
				return false;
			}
			
			return true;
	}
	
	function limitnarractr(elem) 
	{			
			var mylength = elem.value;
			var mylimit = 400;
			if(mylength.length > mylimit)
			{
				alert("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)
			{
				alert("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)
			{
				alert("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 finalizedescrdraft()
	{		
		$("#isfinal").val(1);
		$("#frm2").submit();
	}
	function finalizefirstexpodraft()
	{		
		$("#isfinal").val(1);
		$("#frm2").submit();
	}
	function finalizefirstpersdraft()
	{		
		$("#isfinal").val(1);
		$("#frm2").submit();
	}
	function finalizefirstnarrdraft()
	{		
		$("#isfinal").val(1);
		$("#frm2").submit();
	}
	function finalizefirstsciencedraft()
	{		
		$("#isfinal").val(1);
		$("#sciencefrm").submit();
	}
	
	//for plot a graph at the time of creating a new book report
	function checkValidation()
	{	
		var countrisingevent = 0;
		if($("#problem").val()=="")
		{
			alert("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()=="")
			{
				alert("Please enter the rising action event "+k+" for your graph.");
				$("#rising"+k).focus();
				return false;
			}
		}
		
		countfallingevent = $('#fallingeventno').val();
		for(var f=1; f<countfallingevent; f++)
		{
			if($("#falling"+f).val()=="")
			{
				alert("Please enter the falling action event "+f+" for your graph.");
				$("#falling"+f).focus();
				return false;
			}
		}
		if($("#resolution").val()=="")
		{
			alert("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) {
			alert("Error in ploting graph.");
								
		}
		};
		$("#book2").ajaxSubmit(options); 
	}
	
	function showGraph(data) {
		$(".plot_graph").css('display', 'block');
		//("#plotgraphmainbox").slideDown(800);		
		$("#plotgraphmainbox").animate({height:'350px'},800);
		$("#bookreportgraph_wrapper").html(data);

	}
	
	function plotBeforeSubmit() {
		var valid = checkValidation();
		if( valid == true ) 
		{ 		
			$("#plotgraphmainbox").animate({height:'0px'},800);
		} else {
			return false;
		}
	}
	
	//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) {
			alert("Error in ploting graph.");
								
		}
		};
		$("#book2").ajaxSubmit(options); 
	}
	
	function displayPlotGraph(data) {
		//alert(data)
		$(".plot_graph").css('display', 'block');
		$("#plotgraphmainbox").animate({height:'350px'},800);
		$("#bookreportgraph_wrapper").html(data);

	}
	
	function displayBeforeSubmit() {
		$("#plotgraphmainbox").animate({height:'0px'},800);
	}
	
	/*function transfer(data)
	{
		alert(data);
		alert(document.getElementByName(data).value);
	}*/