$(window).load( function() {

  $(".fck2").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/" ;	




		var oFCKeditor = new FCKeditor(val);
		oFCKeditor.BasePath = siteUrl+"js/fckeditor/" ;	
				oFCKeditor.Config["CustomConfigurationsPath"] = siteUrl+"js/fckeditor/wordcountconfig.js"  ;
				
		oFCKeditor.Width = w; 
		oFCKeditor.Height = h;
		oFCKeditor.ToolbarSet = "Basic2" ;
		oFCKeditor.ReplaceTextarea();

 
		
	});
		
		
	$(".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() ;
		
	});

		$(".Tfck").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.Config["CustomConfigurationsPath"] = siteUrl+"js/fckeditor/myconfig.js"  ;
		oFCKeditor.Width = w; 
		oFCKeditor.Height = h;
		oFCKeditor.ToolbarSet = "Mytoolbar" ;
		oFCKeditor.ReplaceTextarea() ;
		
	});
 
	//document.getElementById('mainpassword').type='text';	
	document.getElementById('mainpassword').defaultValue='Enter Password';	
});


	

 
	
	
$('.tchanges').bind("contextmenu",function(e){
    return false;
});	
	
	
	
	
$(function(){
	$.extend($.fn.disableTextSelect = function() {
		return this.each(function(){
			if($.browser.mozilla){//Firefox
				$(this).css('MozUserSelect','none');
			}else if($.browser.msie){//IE
				$(this).bind('selectstart',function(){return false;});
			}else{//Opera, etc.
				$(this).mousedown(function(){return false;});
			}
		});
	});
	$('.tchanges').disableTextSelect();//No text selection on elements with a class of 'noSelect'
});	
	



	
var fck_Array=new Array();
var TotFck=0;
 
function clearText(thefield) {
	/*if(document.getElementById('mainpassword').type=='text')
	{
		document.getElementById('mainpassword').type='password';		
	}
*/
  if (thefield.defaultValue==thefield.value) { thefield.value = "" }
} 
function replaceText(thefield) {

//alert(thefield);
//if(document.getElementById('password').type='password')
	//{
		//document.getElementById('password').type='text';		
	//}
  if (thefield.value=="") { thefield.value = thefield.defaultValue }
  	
}



function FCKeditor_OnComplete(editorInstance) {
   fck_Array[TotFck++]=editorInstance;
   
 
    fckeditor_word_count(editorInstance);
    editorInstance.Events.AttachEvent('OnSelectionChange', fckeditor_word_count);
	
	  editorInstance.Events.AttachEvent('OnSelectionChange', fckeditor_word_count1);
   
}



function fckeditor_word_count(editorInstance) {
    var matches = editorInstance.GetData().replace(/<[^<|>]+?>|&nbsp;/gi,' ').match(/\b/g);
    var count = 0;
    if(matches) {
        count = matches.length/2;
    } 
 count=count_totword_fck();
 document.getElementById('display_count').innerHTML = count + "  ";

}

function echeck(str) {
	
			var at="@"
			var dot="."
			var lat=str.indexOf(at)
			var lstr=str.length
			var ldot=str.indexOf(dot)
			if (str.indexOf(at)==-1){
			 //  alert("Invalid Email")
			   return false
			}
	
			if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			  // alert("Invalid Email")
			   return false
			}
	
			if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
				//alert("Invalid Email")
				return false
			}
	
			 if (str.indexOf(at,(lat+1))!=-1){
			//	alert("Invalid Email")
				return false
			 }
	
			 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
				//alert("Invalid Email")
				return false
			 }
	
			 if (str.indexOf(dot,(lat+2))==-1){
				//alert("Invalid Email")
				return false
			 }
			
			 if (str.indexOf(" ")!=-1){
				//alert("Invalid Email")
				return false
			 }
	
			 return true					
		}	

function validateform()
{
		if(!echeck(document.getElementById('email').value))
		{	
		alert('Enter valid E-mail.');
		return false;					
		}
		if(!echeck(document.getElementById('cemail').value))
		{	
		alert('Enter valid Confirm E-mail.');
		return false;					
		}
		
		if(document.getElementById('email').value!=document.getElementById('cemail').value)
		{
		alert('E-mail and Confirm E-mail must be same');
		return false;
		}
		
		if(document.getElementById('password').value=='')
		{	
		alert('Enter Password.');
		return false;					
		}

		if(document.getElementById('password').value.length<5)
		{	
		alert('Password must be greather than 5 character.');
		return false;					
		}
		
		if(document.getElementById('password').value!=document.getElementById('confirmPassword').value)
		{	
		alert('Password and Confirm Password must be same');
		return false;					
		}
}



function count_totword_fck(){
	var tot_f=fck_Array.length;
var count=0;
	for(i=0;i<tot_f;i++){
		
		var editorInstance=fck_Array[i];
	 
		
	//	if(est.Name!=editorInstance.Name){
		var matches = editorInstance.GetData().replace(/<[^<|>]+?>|&nbsp;/gi,' ').match(/\b/g);
			if(matches) {
			count += matches.length/2;
			}
			//}
		
		
		}
		return count;
	
	}
function fckeditor_word_count_old(editorInstance) {  

	var matches = editorInstance.GetData().replace(/<[^<|>]+?>|&nbsp;/gi,' ').match(/\b/g);
	
/*	 var totfck=count_totword_fck(editorInstance);

  var  fck_Word_count=0;
    if(matches) {*/
      var  totfck = matches.length/2;
   /* }
		 fck_Word_count+=totfck;*/
	try
	{document.getElementById('display_count').innerHTML = totfck+" ";
    	//document.getElementById('display_count'+editorInstance.Name).innerHTML =totfck+" ";
	}catch(e)
	{
		try
		{
	    	document.getElementById('display_count').innerHTML = totfck+" ";
		}catch(e){var a='ss';}
	
	}
	  
	
	//getTotalCount_28_07();
}
	
	
function getTotalCount_28_07()
{
	
	try
	{
		n1=parseInt(document.getElementById("display_countquestion").innerHTML);
		n2=parseInt(document.getElementById("display_countresearch").innerHTML);
		n3=parseInt(document.getElementById("display_counthypothesis").innerHTML);
		n4=parseInt(document.getElementById("display_countprocedure").innerHTML);
		n5=parseInt(document.getElementById("display_countobservation").innerHTML);
		n6=parseInt(document.getElementById("display_countconclusion").innerHTML);
		n=n1+n2+n3+n4+n5+n6;
		document.getElementById("display_total").innerHTML=n;
	}catch(ex)
	{
		var a='ss';
	}
}


function containsAlphabets(checkString) {
        var tempString="";
        var regExp = /^[A-Za-z]$/;
        if(checkString != null && checkString != "")
        {
          for(var i = 0; i < checkString.length; i++)
          { 
            if (!checkString.charAt(i).match(regExp))
            {
              return false;
            }
          }
        }
        else
        {
          return false;
        }
        return true;
}
 
 

function isZip(s) 
{

     // Check for correct zip code
     reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);

     if (!reZip.test(s)) {
        //  alert("Zip Code Is Not Valid");
          return false;
     }

return true;
}

function isDate(txtDate){
  var objDate;  // date object initialized from the txtDate string
  var mSeconds; // milliseconds from txtDate

	// date length should be 10 characters - no more, no less
  if (txtDate.length != 10) return false;

	// extract day, month and year from the txtDate string
	// expected format is mm/dd/yyyy
	// subtraction will cast variables to integer implicitly
  var day   = txtDate.substring(3,5)  - 0;
  var month = txtDate.substring(0,2)  - 1; // because months in JS start with 0
  var year  = txtDate.substring(6,10) - 0;

	// third and sixth character should be /
	if (txtDate.substring(2,3) != '/') return false;
	if (txtDate.substring(5,6) != '/') return false;

  // test year range
  if (year < 999 || year > 3000) return false;

  // convert txtDate to the milliseconds
  mSeconds = (new Date(year, month, day)).getTime();

  // initialize Date() object from calculated milliseconds
  objDate = new Date();
  objDate.setTime(mSeconds);

  // compare input parameter date and created Date() object
  // if difference exists then date isn't valid
  if (objDate.getFullYear() != year)  return false;
  if (objDate.getMonth()    != month) return false;
  if (objDate.getDate()     != day)   return false;

	// otherwise return true
  return true;
}



$(document).ready( function() {
							
				//js validate Addstudent  form

	if(document.getElementById('TeacherProfileAddStudent')){	 	   
		var checkFirst = function (password) {
			var cpassword = $('#screenname').val(); 
			 $("#screenname_js ul li").html("");
				$("#screenname_div").removeClass();
			if(cpassword == '') {  
				$("#screenname_js ul li").html("Please enter a screen name");
				$("#screenname_div").removeClass().addClass('error_flag').fadeIn("slow");
				 
			}else{
				if(cpassword.length<=3){
					$("#screenname_js ul li").html("Enter your Screen Name of Length greater then 3.");
					$("#screenname_div").removeClass().addClass('error_flag').fadeIn("slow");
					
					}else {if(1!=1){
						// 21.04.2011 if condition content( !containsAlphabets(cpassword))
			//	$("#screenname_js ul li").html("Enter only letters for your Screen Name.");
				//$("#screenname_div").removeClass().addClass('error_flag').fadeIn("slow");
				}else{
					
					$("#screenname_div").removeClass().addClass('loading_flag').fadeIn("slow");
					$.ajax({
						  url: siteUrl +  "app/checkscreenname/screenname/"+cpassword,
						  success: function(data) {
							 
							if(data==0){
								
							$("#screenname_div").removeClass().fadeIn("slow");	
							}else{
								$("#screenname_js ul li").html("That screen name is not available.");
								$("#screenname_div").removeClass().addClass('error_flag').fadeIn("slow");
								
								}
							
							
						  }
						});
					
				 
 				
					
					}
				 
			}	
			
			}
		}
		
		var chkpassword = function (password) { 
			var tmpname='password';
			$('#'+tmpname+"_js ul li").html("");
			 $('#'+tmpname+"_div").removeClass();
			 
			var cpassword = $('#'+tmpname).val(); 
			if(cpassword == '') {
				$('#'+tmpname+"_js ul li").html("Enter your Password.");
				$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}
			else {
				if(cpassword.length<6){
					$('#'+tmpname+"_js ul li").html("Enter at least 6 characters.");
					$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
					
					}else{$('#'+tmpname+"_js ul li").html("");
						$('#'+tmpname+"_div").removeClass().addClass('right_flag').fadeIn("slow");
					}
			}		
		}
		
		var chkconfirmPassword = function (password) { 
			var tmpname='confirmPassword';
			$('#'+tmpname+"_js ul li").html("");
			 $('#'+tmpname+"_div").removeClass();
			 
			var cpassword = $('#'+tmpname).val(); 
			
			var password1 = $('#password').val(); 
			if(cpassword == '') {
				$('#'+tmpname+"_js ul li").html("Enter Confirm Password.");
				$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}
			else {
				if(cpassword.length<6){
					$('#'+tmpname+"_js ul li").html("Enter at least 6 characters.");
					$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
					
					}else{
						if(cpassword!=password1){
							
							$('#'+tmpname+"_js ul li").html("Passwords do not match");
							$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
							}else{
						
						$('#'+tmpname+"_js ul li").html("");
						$('#'+tmpname+"_div").removeClass().addClass('right_flag').fadeIn("slow");
						
						}
					}
			}		
		}
		
		
		var checkemail=function (password) { 
			var tmpname='email';
			$('#'+tmpname+"_js ul li").html("");
			 $('#'+tmpname+"_div").removeClass();
			 
			var cpassword = $('#'+tmpname).val(); 
			if(cpassword == '') {
				$('#'+tmpname+"_js ul li").html("Enter your Email.");
				$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}else {
				if(!echeck(cpassword)){
					$('#'+tmpname+"_js ul li").html("Please enter a valid email");
					$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
					
					}else{
						
						$('#'+tmpname+"_div").removeClass().addClass('loading_flag').fadeIn("slow");
					
					$('#'+tmpname+"_div").removeClass().addClass('loading_flag').fadeIn("slow");
					$.ajax({
						  url: siteUrl +  "app/checkscreenname/email/"+cpassword,
						  success: function(data) {
							 
							if(data==0){
								
							$('#'+tmpname+"_div").removeClass().addClass('right_flag').fadeIn("slow");	
							}else{
								$('#'+tmpname+"_js ul li").html("That email already registered.");
								$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
								
								}
							
							
						  }
						});
					
				 
 				
					
					 
					}
			}	
			
			
				var password1 = $('#email').val(); 
			var tmpname1='cemail';
			var cpassword = $('#'+tmpname1).val(); 
			if(cpassword!=password1 && cpassword!=''){
							
							$('#'+tmpname1+"_js ul li").html("Email and Confirm email do not match.");
							$('#'+tmpname1+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}
		}
		
		
			var chkconfirmemail1 = function (password) { 
			var tmpname='cemail';
			$('#'+tmpname+"_js ul li").html("");
			 $('#'+tmpname+"_div").removeClass();
			 
			var cpassword = $('#'+tmpname).val(); 
			
			var password1 = $('#email').val(); 
			if(cpassword == '') {
				$('#'+tmpname+"_js ul li").html("Enter  Confirm  email.");
				$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}
			else {
				if(!echeck(cpassword)){
					$('#'+tmpname+"_js ul li").html("Enter valid Confirm  email.");
					$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
					
					}else{
						if(cpassword!=password1){
							
							$('#'+tmpname+"_js ul li").html("Email and Confirm email do not match.");
							$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
							}else{
						
						$('#'+tmpname+"_js ul li").html("");
						$('#'+tmpname+"_div").removeClass().addClass('right_flag').fadeIn("slow");
						
						}
					}
			}		
		}
		
		var checkinitials =	function (password) { 
			var tmpname='initials';
			$('#'+tmpname+"_js ul li").html("");
			 $('#'+tmpname+"_div").removeClass();
			 
			var cpassword = $('#'+tmpname).val(); 
			if(cpassword == '') {
				$('#'+tmpname+"_js ul li").html("Please enter your first initial.");
				$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}
			else {
				if(!containsAlphabets(cpassword)){
					$('#'+tmpname+"_js ul li").html("Enter only alphabets in your Initials no space.");
					$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
					
					}else{$('#'+tmpname+"_js ul li").html("");
						$('#'+tmpname+"_div").removeClass().fadeIn("slow");
					}
			}		
		}
		
		 var checklastName =	function (password) { 
			var tmpname='lastName';
			$('#'+tmpname+"_js ul li").html("");
			 $('#'+tmpname+"_div").removeClass();
			 
			var cpassword = $('#'+tmpname).val(); 
			if(cpassword == '') {
				$('#'+tmpname+"_js ul li").html("Please enter your first initial.");
				$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}
			else {
					 $('#'+tmpname+"_js ul li").html("");
						$('#'+tmpname+"_div").removeClass().fadeIn("slow");
					
			}		
		}
		
 
		
		
  

 
		
		
		/////// extra functions shipping address
	  
	
		if(document.getElementById('screenname')){
			$("#screenname").blur(checkFirst);
		}
		if(document.getElementById('password')){	
		 
			$("#password").blur(chkpassword);
		}
		if(document.getElementById('confirmPassword')){	
		 
			$("#confirmPassword").blur(chkconfirmPassword);
		}
		if(document.getElementById('email')){	
			 
			$("#email").blur(checkemail);
		}
		if(document.getElementById('cemail')){	
			 
			$("#cemail").blur(chkconfirmemail1);
		}
		if(document.getElementById('initials')){	
 
			$("#initials").blur(checkinitials);
		}
		if(document.getElementById('lastName')){	
		 
			$("#lastName").blur(checklastName);
		}
	 
		
		
	}

//end of reg validate					
							
	//js validate reg form

	if(document.getElementById('registration')){	 	   
		var checkFirst = function (password) {
			var cpassword = $('#screenname').val(); 
			 $("#screen_js ul li").html(""); 
				$("#screen_div").removeClass();
			if(cpassword == '') {  
				$("#screen_js ul li").html("Please enter a screen name");
				$("#screen_div").removeClass().addClass('error_flag').fadeIn("slow");
				 
			}else{
				if(cpassword.length<=3){
					$("#screen_js ul li").html("Enter your Screen Name of Length greater then 3.");
					$("#screen_div").removeClass().addClass('error_flag').fadeIn("slow");
					
					}else {if(1!=1){
						// (if condition content) !containsAlphabets(cpassword)
				//$("#screen_js ul li").html("Enter only letters for your Screen Name.");
				//$("#screen_div").removeClass().addClass('error_flag').fadeIn("slow");
				}else{
					//alert(siteUrl);
					$("#screen_div").removeClass().addClass('loading_flag').fadeIn("slow");
					$.ajax({
						  url: siteUrls +  "register/checkscreenname/screenname/"+cpassword,
						 success: function(data) {
							 
							if(data==0){
								
							$("#screen_div").removeClass().addClass('right_flag').fadeIn("slow");	
							}else{
								$("#screen_js ul li").html("That screen name is not available.");
								$("#screen_div").removeClass().addClass('error_flag').fadeIn("slow");
								
								}
							
							
						  },
			error:function(msg){
				//alert(msg);
			}
						});
					
				 
 				
					
					}
				 
			}	
			
			}
		}
		
		var chkpassword = function (password) { 
			var tmpname='password1';
			$('#'+tmpname+"_js ul li").html("");
			 $('#'+tmpname+"_div").removeClass();
			 
			var cpassword = $('#'+tmpname).val(); 
			if(cpassword == '') {
				$('#'+tmpname+"_js ul li").html("Enter your Password.");
				$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}
			else {
				if(cpassword.length<6){
					$('#'+tmpname+"_js ul li").html("Enter at least 6 characters.");
					$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
					
					}else{$('#'+tmpname+"_js ul li").html("");
						$('#'+tmpname+"_div").removeClass().addClass('right_flag').fadeIn("slow");
					}
			}		
		}
		
		var chkconfirmPassword = function (password) { 
			var tmpname='confirmPassword';
			$('#'+tmpname+"_js ul li").html("");
			 $('#'+tmpname+"_div").removeClass();
			 
			var cpassword = $('#'+tmpname).val(); 
			
			var password1 = $('#password1').val(); 
			if(cpassword == '') {
				$('#'+tmpname+"_js ul li").html("Enter Confirm Password.");
				$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}
			else {
				if(cpassword.length<6){
					$('#'+tmpname+"_js ul li").html("Enter at least 6 characters.");
					$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
					
					}else{
						if(cpassword!=password1){
							
							$('#'+tmpname+"_js ul li").html("Passwords do not match");
							$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
							}else{
						
						$('#'+tmpname+"_js ul li").html("");
						$('#'+tmpname+"_div").removeClass().addClass('right_flag').fadeIn("slow");
						
						}
					}
			}		
		}
		
		
		var checkemail=function (password) { 
			var tmpname='email';
			$('#'+tmpname+"_js ul li").html("");
			 $('#'+tmpname+"_div").removeClass();
			 
			var cpassword = $('#'+tmpname).val(); 
			if(cpassword == '') {
				$('#'+tmpname+"_js ul li").html("Enter your Email.");
				$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}else {
				if(!echeck(cpassword)){
					$('#'+tmpname+"_js ul li").html("Please enter a valid email");
					$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
					
					}else{
						
						$('#'+tmpname+"_div").removeClass().addClass('loading_flag').fadeIn("slow");
					
					$('#'+tmpname+"_div").removeClass().addClass('loading_flag').fadeIn("slow");
					$.ajax({
						  url: siteUrls +  "register/checkscreenname/email/"+cpassword,
						  success: function(data) {
							 
							if(data==0){
								
							$('#'+tmpname+"_div").removeClass().addClass('right_flag').fadeIn("slow");	
							}else{
								$('#'+tmpname+"_js ul li").html("That email already registered.");
								$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
								
								}
							
							
						  }
						});
					
				 
 				
					
					 
					}
			}	
			
			
				var password1 = $('#email').val(); 
			var tmpname1='confirmemail1';
			var cpassword = $('#'+tmpname1).val(); 
			if(cpassword!=password1 && cpassword!=''){
							
							$('#'+tmpname1+"_js ul li").html("Email and Confirm email do not match.");
							$('#'+tmpname1+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}
		}
		
		
			var chkconfirmemail1 = function (password) { 
			var tmpname='confirmemail1';
			$('#'+tmpname+"_js ul li").html("");
			 $('#'+tmpname+"_div").removeClass();
			 
			var cpassword = $('#'+tmpname).val(); 
			
			var password1 = $('#email').val(); 
			if(cpassword == '') {
				$('#'+tmpname+"_js ul li").html("Enter  Confirm  email.");
				$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}
			else {
				if(!echeck(cpassword)){
					$('#'+tmpname+"_js ul li").html("Enter valid Confirm  email.");
					$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
					
					}else{
						if(cpassword!=password1){
							
							$('#'+tmpname+"_js ul li").html("Email and Confirm email do not match.");
							$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
							}else{
						
						$('#'+tmpname+"_js ul li").html("");
						$('#'+tmpname+"_div").removeClass().addClass('right_flag').fadeIn("slow");
						
						}
					}
			}		
		}
		
		var checkinitials =	function (password) { 
			var tmpname='initials';
			$('#'+tmpname+"_js ul li").html("");
			 $('#'+tmpname+"_div").removeClass();
			 
			var cpassword = $('#'+tmpname).val(); 
			if(cpassword == '') {
				$('#'+tmpname+"_js ul li").html("Please enter your first initial.");
				$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}
			else {
				if(!containsAlphabets(cpassword)){
					$('#'+tmpname+"_js ul li").html("Enter only alphabets in your Initials no space.");
					$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
					
					}else{$('#'+tmpname+"_js ul li").html("");
						$('#'+tmpname+"_div").removeClass().fadeIn("slow");
					}
			}		
		}
		
		 var checklastName =	function (password) { 
			var tmpname='lastName';
			$('#'+tmpname+"_js ul li").html("");
			 $('#'+tmpname+"_div").removeClass();
			 
			var cpassword = $('#'+tmpname).val(); 
			if(cpassword == '') {
				$('#'+tmpname+"_js ul li").html("Please enter your last name");
				$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}
			else {
					 $('#'+tmpname+"_js ul li").html("");
						$('#'+tmpname+"_div").removeClass().fadeIn("slow");
					
			}		
		}
		
		
		
	var chkdate=function (password) {
		
					var tmpname='birthdate';
			$('#'+tmpname+"_js ul li").html("");
			 $('#'+tmpname+"_div").removeClass();
			 
			var month = $('#birthmonth').val(); 
			var date = $('#birthdate').val(); 
			var year = $('#birthyear').val(); 
			
			var date=month+"/"+date+"/"+year;
			
			if(!isDate(date)) {
				$('#'+tmpname+"_js ul li").html("Please select a birth date");
				$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}
			else {
					 $('#'+tmpname+"_js ul li").html("");
						$('#'+tmpname+"_div").removeClass().fadeIn("slow");
					
			}
		 
		} 	
		
	var chkzip=function (password) { 
			var tmpname='zipcode';
			$('#'+tmpname+"_js ul li").html("");
			 $('#'+tmpname+"_div").removeClass();
			 
			var cpassword = $('#'+tmpname).val(); 
			if(cpassword == '') {
				$('#'+tmpname+"_js ul li").html("Please enter your zip code");
				$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}
			else {
					if(!isZip(cpassword)){
						
						$('#'+tmpname+"_js ul li").html("Enter valid Zip Code.");
				$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");}else{
				
					 $('#'+tmpname+"_js ul li").html("");
						$('#'+tmpname+"_div").removeClass().fadeIn("slow");}
					
			}		
		} 	
			
		
		
		var chkstate=function (password) { 
			var tmpname='state';
			$('#'+tmpname+"_js ul li").html("");
			 $('#'+tmpname+"_div").removeClass();
			 
			var cpassword = $('#'+tmpname).val(); 
			if(cpassword == '') {
				$('#'+tmpname+"_js ul li").html("Enter your State.");
				$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}
			else {
					  $('#'+tmpname+"_js ul li").html("");
						$('#'+tmpname+"_div").removeClass().fadeIn("slow");		
		} 	
		}
		
		
		
			var chkcardtype=function (password) { 
			 var tmpname='cardtype';
			$('#'+tmpname+"_js ul li").html("");
			 $('#'+tmpname+"_div").removeClass();
			 
			var cpassword = $('#'+tmpname).val(); 
			if(cpassword == '') {
				$('#'+tmpname+"_js ul li").html("Please a payment type.");
				$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}
			else {
					  $('#'+tmpname+"_js ul li").html("");
						$('#'+tmpname+"_div").removeClass().fadeIn("slow");		
		} 	
		}
		 
		
		 
		 
		 var chkcardnumber=function (password) { 
			 var tmpname='cardnumber';
			 var name="Card Number";
			$('#'+tmpname+"_js ul li").html("");
			 $('#'+tmpname+"_div").removeClass();
			 
			var cpassword = $('#'+tmpname).val(); 
			if(cpassword == '') {
				$('#'+tmpname+"_js ul li").html("Enter your "+name+".");
				$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}
			else {
					  $('#'+tmpname+"_js ul li").html("");
						$('#'+tmpname+"_div").removeClass().fadeIn("slow");		
		} 	
		}
		 
		 
		 var chkCVV=function (password) { 
			 var tmpname='cvv';
			 var name="CVV Number";
			$('#'+tmpname+"_js ul li").html("");
			 $('#'+tmpname+"_div").removeClass();
			 
			var cpassword = $('#'+tmpname).val(); 
			if(cpassword == '') {
				$('#'+tmpname+"_js ul li").html("Enter your "+name+".");
				$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}
			else {
					  $('#'+tmpname+"_js ul li").html("");
						$('#'+tmpname+"_div").removeClass().fadeIn("slow");		
		} 	
		}
		 
		 
		var chkexpirymonth=function (password) { 
			 var tmpname='expirymonth';
			 var name="Expiration Date";
			$('#'+tmpname+"_js ul li").html("");
			 $('#'+tmpname+"_div").removeClass();
			 
			var cpassword = $('#expirymonth').val()+ $('#expiryyear').val(); 
			
			if(cpassword == '') {
				$('#'+tmpname+"_js ul li").html("elect expiry month and year.");
				$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}
			else {
					  $('#'+tmpname+"_js ul li").html("");
						$('#'+tmpname+"_div").removeClass().fadeIn("slow");		
		} 	
		} 
		
		
		
		var chkexfirstname1=function (password) { 
			 var tmpname='firstname';
			 var name="Name on Card";
			$('#'+tmpname+"_js ul li").html("");
			 $('#'+tmpname+"_div").removeClass();
			 
			var cpassword = $('#firstname').val(); 
			
			if(cpassword == '') {
				$('#'+tmpname+"_js ul li").html(" Enter First Name.");
				$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}
			else {
					  $('#'+tmpname+"_js ul li").html("");
						$('#'+tmpname+"_div").removeClass().fadeIn("slow");		
		} 	
		}
		
		
	var chkstate1=function (password) { 
			 var tmpname='state1';
			 var name="State";
			$('#'+tmpname+"_js ul li").html("");
			 $('#'+tmpname+"_div").removeClass();
			 
			var cpassword = $('#'+tmpname).val(); 
			if(cpassword == '') {
				$('#'+tmpname+"_js ul li").html("Select your "+name+".");
				$('#'+tmpname+"_div").removeClass().addClass('error_flag').fadeIn("slow");
			}
			else {
					  $('#'+tmpname+"_js ul li").html("");
						$('#'+tmpname+"_div").removeClass().fadeIn("slow");		
		} 	
		}
		
		

 
		
		
		/////// extra functions shipping address
	  
	
		if(document.getElementById('screenname')){
			$("#screenname").blur(checkFirst);
		}
		if(document.getElementById('password1')){	
		 
			$("#password1").blur(chkpassword);
		}
		if(document.getElementById('confirmPassword')){	
		 
			$("#confirmPassword").blur(chkconfirmPassword);
		}
		if(document.getElementById('email')){	
			 
			$("#email").blur(checkemail);
		}
		if(document.getElementById('confirmemail1')){	
			 
			$("#confirmemail1").blur(chkconfirmemail1);
		}
		if(document.getElementById('initials')){	
 
			$("#initials").blur(checkinitials);
		}
		if(document.getElementById('lastName')){	
		 
			$("#lastName").blur(checklastName);
		}
		if(document.getElementById('birthmonth')){	
			 
			$("#birthmonth").blur(chkdate);
			$("#birthdate").blur(chkdate);
			$("#birthyear").blur(chkdate);
		}	
		if(document.getElementById('lastName')){	
		 
			$("#zipcode").blur(chkzip);
		}
		if(document.getElementById('state')){	
		 
			$("#state").blur(chkstate);
		}
		
	  if(document.getElementById('cardtype')){	
		 
			$("#cardtype").blur(chkcardtype);
		}
		
		
		
		  if(document.getElementById('cardnumber')){	
		 
			$("#cardnumber").blur(chkcardnumber);
		}
		
		
		  if(document.getElementById('cvv')){	
		 
			$("#cvv").blur(chkCVV);
		}
		
		
 
		
		  if(document.getElementById('expirymonth')){	
		 
			$("#expirymonth").blur(chkexpirymonth);$("#expiryyear").blur(chkexpirymonth);
		}
		
		
		  if(document.getElementById('firstname')){	
		 
			$("#firstname").blur(chkexfirstname1);$("#firstname").blur(chkexfirstname1);
		}
		
		  if(document.getElementById('state1')){	
		 
			$("#state1").blur(chkstate1); 
		}
		
		
		
	}

//end of reg validate						
							
							
							
							
							
							
							

$('.enableshare').bind('click', function(){
			 
						 
	 
jConfirm('You are enabling the sharing option. Your students will now be able to share their writing assignments with each other. Do you wish to continue?',null, function(result){
				if (result) {
					
					$('#enables').val(1);
					 $('#eSharing').submit();
				}
			});
						
	 });


$('.regsubmit').bind('click', function(){
										
				alert("DD");
				$("#registration").submit();
					
					});




$('.disableshare').bind('click', function(){
				 			 
	 
	jConfirm('You are disabling the sharing option. Your students will not be able to share their writing assignments with each other. Do you wish to continue?',null, function(result){
				if (result) {
					
					$('#enables').val(0);
					 $('#eSharing').submit();
				}
			});
						
});

$(".draftblank").bind("click", function() {

		jAlert("Please compelte the draft before publishing.");

});

$(".stoppublish").bind("click", function() {

		jAlert("You can only publish a writing assignment when you are enrolled in a class.");

});



$(".disableMlink").bind("click", function() {

		jAlert("This feature is available in the Wizard Preimium and Wizard Family accounts.");

});


$(".lockTfeature").bind("click", function() {
										  
	jAlert("This feature is available in the Small Group and Classroom Premium.");									  
	});

//For saving teacher edit part
		$(".jornalteachersave").bind("click", function() {  
    		$("#ajaxmode").val(1);
 			var oEditor = FCKeditorAPI.GetInstance('editor1') ;
			var con = oEditor.GetXHTML(true);
			$("#editor1").val(con);
			
			
				$("#editmode").val(1); 
			 var options = { 
				target:        '#output',   	// target element(s) to be updated with server response 
				beforeSubmit:  showRequest,  	// pre-submit callback 
				type:  'post',  				// pre-submit callback 				
				success:       showResponseAutosave,
				url:       siteUrl +  "journal/ajaxsaveteacher",// post-submit callback 
				error: function(xhr, ajaxOptions, thrownError) {
					jAlert("Error in saving draft.");
					//jAlert(xhr.status);
					//jAlert(xhr.errorno);					
				}
			 }; 
				$("#frmGradeJ").ajaxSubmit(options); 
				return false; 
		});
		
		
		$(".assessmentteachersave").bind("click", function() {  
    		$("#ajaxmode").val(1);
 			var oEditor = FCKeditorAPI.GetInstance('editor1') ;
			var con = oEditor.GetXHTML(true);
			$("#editor1").val(con);

			$("#editmode").val(1); 
			 var options = { 
				target:        '#output',   	// target element(s) to be updated with server response 
				beforeSubmit:  showRequest,  	// pre-submit callback 
				type:  'post',  				// pre-submit callback 				
				success:       showResponseAutosave,
				url:       siteUrl +  "assessment/ajaxsaveteacher",// post-submit callback 
				error: function(xhr, ajaxOptions, thrownError) {
					jAlert("Error in saving draft.");
					//jAlert(xhr.status);
					//jAlert(xhr.errorno);					
				}
			 }; 
				$("#ass").ajaxSubmit(options); 
				return false; 
		});
		
		
		 $(".bugsendnew").bind("click", function() 
		{  		
			if(document.getElementById('bug_mail').value=='')
			{
				jAlert("Please enter bug report.");				
				return false;	
			}
			$("#ajaxmode").val(1);
			var options = { 
			target:        '#output',   	// target element(s) to be updated with server response 
			beforeSubmit:  showRequest,  	// pre-submit callback 
			type:  'post',  				// pre-submit callback 				
			success:       showResponseAutosave,
			url:       siteUrl +  "bug/index",// post-submit callback 
				error: function(xhr, ajaxOptions, thrownError) 
				{
					document.getElementById('bugdiv').style.display='none';
					document.getElementById('videodiv2').style.display='none';
					jAlert("Error in Sending Bug.");				
				}
			}; 
				$("#ass").ajaxSubmit(options); 
				document.getElementById('bug_mail').value='';
				document.getElementById('box').style.display='none';
				document.getElementById('videodiv2').style.display='none';
				jAlert("Bug report send successfully.");				
					return false; 
		});
		
		
		$(".bugsend").bind("click", function() 
		{  		
			if(document.getElementById('bug_mail').value=='')
			{
				jAlert("Please enter bug report.");				
				return false;	
			}
			$("#ajaxmode").val(1);
			var options = { 
			target:        '#output',   	// target element(s) to be updated with server response 
			beforeSubmit:  showRequest,  	// pre-submit callback 
			type:  'post',  				// pre-submit callback 				
			success:       showResponseAutosave,
			url:       siteUrl +  "bug/index",// post-submit callback 
				error: function(xhr, ajaxOptions, thrownError) 
				{
					document.getElementById('bugdiv').style.display='none';
					document.getElementById('videodiv2').style.display='none';
					jAlert("Error in Sending Bug.");				
				}
			}; 
				$("#ass").ajaxSubmit(options); 
				document.getElementById('bug_mail').value='';
				document.getElementById('bugdiv').style.display='none';
				document.getElementById('videodiv2').style.display='none';
				jAlert("Bug report send successfully.");				
					return false; 
		});
		
		
		$(".essayteachersave").bind("click", function() {
    		$("#ajaxmode").val(1);
			
 		if($("#editor1").val()){
		var oEditor = FCKeditorAPI.GetInstance('editor1') ;
			var con = oEditor.GetXHTML(true);
			$("#editor1").val(con);
		}
		if($("#Introduction").val()){
			
			var oEditor = FCKeditorAPI.GetInstance('Introduction') ;
			var con = oEditor.GetXHTML(true);
			$("#Introduction").val(con);
			
						var oEditor = FCKeditorAPI.GetInstance('Body') ;
			var con = oEditor.GetXHTML(true);
			$("#Body").val(con);



			var oEditor = FCKeditorAPI.GetInstance('Conclusion') ;
			var con = oEditor.GetXHTML(true);
			$("#Conclusion").val(con);

			
			}
			
				$("#editmode").val(1); 
			 var options = { 
				target:        '#output',   	// target element(s) to be updated with server response 
				beforeSubmit:  showRequest,  	// pre-submit callback 
				type:  'post',  				// pre-submit callback 				
				success:       showResponseAutosave,
				url:       siteUrl +  "essay/ajaxsaveteacher",// post-submit callback 
				error: function(xhr, ajaxOptions, thrownError) {
					jAlert("Error in saving draft.");
					//jAlert(xhr.status);
					//jAlert(xhr.errorno);					
				}
			 }; 
				$("#frmGradeE").ajaxSubmit(options); 
				return false; 
		});
		
		
		
		
		
		
		
		
		
		
 	$(".currentteachersave").bind("click", function() {  
  			var oEditor = FCKeditorAPI.GetInstance('editor1') ;
			var con = oEditor.GetXHTML(true);
			
			$("#editor1").val(con);
			//var oEditor = FCKeditorAPI.GetInstance('ddd') ;
			//oEditor.InsertHtml(con)
				$("#editmode").val(1); 
			 var options = { 
				target:        '#output',   	// target element(s) to be updated with server response 
				beforeSubmit:  showRequest,  	// pre-submit callback 
				type:  'post',  				// pre-submit callback 				
				success:       showResponseAutosave,
				url:       siteUrl +  "currentevent/ajaxsaveteacher",// post-submit callback 
				error: function(xhr, ajaxOptions, thrownError) {
					jAlert("Error in saving draft.");
					//jAlert(xhr.status);
					//jAlert(xhr.errorno);					
				}
			 }; 
				$("#frmGradecc").ajaxSubmit(options); 
				return false; 
		});	
		
		
		
		
	$(".scienceteachersave").bind("click", function() {  
 			
			var oEditor = FCKeditorAPI.GetInstance('topic') ;
			var field1 = oEditor.GetXHTML(true);  //jAlert(field1);
			$("#topic").val(field1);
			   	
			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('Observations') ;
			var field5 = oEditor.GetXHTML(true);	//jAlert(field5);
			$("#Observations").val(field5);
			
			var oEditor = FCKeditorAPI.GetInstance('Conclusion') ;
			var field6 = oEditor.GetXHTML(true);	//jAlert(field6);
			$("#Conclusion").val(field6);
			
			var oEditor = FCKeditorAPI.GetInstance('bibliography') ;
			var field7 = oEditor.GetXHTML(true);	//jAlert(field6);
			$("#bibliography").val(field7);
		
			 var options = { 
				target:        '#output',   	// target element(s) to be updated with server response 
				beforeSubmit:  showRequest,  	// pre-submit callback 
				type:  'post',  				// pre-submit callback 				
				success:       showResponseAutosave,
				url:       siteUrl +  "science/ajaxsaveteacher",// post-submit callback 
				error: function(xhr, ajaxOptions, thrownError) {
					jAlert("Error in saving draft.");
					//jAlert(xhr.status);
					//jAlert(xhr.errorno);					
				}
			 }; 
				$("#frmGradeS").ajaxSubmit(options); 
				return false; 
		});	
		
		

		$(".bookteachersave").bind("click", function() {  
  			var oEditor = FCKeditorAPI.GetInstance('editor1') ;
			var con = oEditor.GetXHTML(true);
			$("#editor1").val(con);

			$("#editmode").val(1); 
			
			
			var fcount=$("#fcount").val();
			
			for(i=1;i<=fcount;i++)
			{
			var oEditor = FCKeditorAPI.GetInstance('falling'+i) ;
			var con2 = oEditor.GetXHTML(true);
			$("#falling"+i).val(con2);
			
			}
			
			var rcount=$("#rcount").val();
			
			for(i=1;i<=rcount;i++)
			{
			var oEditor = FCKeditorAPI.GetInstance('rising'+i) ;
			var con2 = oEditor.GetXHTML(true);
			$("#rising"+i).val(con2);
			
			}
			
 
			var oEditor = FCKeditorAPI.GetInstance('editor2') ;
			var con2 = oEditor.GetXHTML(true);
			$("#editor2").val(con2);
			
		
			
			var oEditor = FCKeditorAPI.GetInstance('editor3') ;
			var con3 = oEditor.GetXHTML(true);
			$("#editor3").val(con3);
			
			var oEditor = FCKeditorAPI.GetInstance('editor4') ;
			var con4 = oEditor.GetXHTML(true);
			$("#editor4").val(con4);
			
			var oEditor = FCKeditorAPI.GetInstance('editor5') ;
			var con5 = oEditor.GetXHTML(true);
			$("#editor5").val(con5);
			
			var oEditor = FCKeditorAPI.GetInstance('editor6') ;
			var con6 = oEditor.GetXHTML(true);
			$("#editor6").val(con6);
			
			

			var options = { 
				target:        '#output',   	// target element(s) to be updated with server response 
				beforeSubmit:  showRequest,  	// pre-submit callback 
				type:  'post',  				// pre-submit callback 				
				success:       showResponseAutosave,
				url:       siteUrl +  "book/ajaxsaveteacher",// post-submit callback 
				error: function(xhr, ajaxOptions, thrownError) {
					jAlert("Error in saving draft.");
					//jAlert(xhr.status);
					//jAlert(xhr.errorno);					
				}
			 }; 
				$("#frmGradeB").ajaxSubmit(options); 
				return false; 
		});




	 
		function showResponseAutosave(data)  {
				 $("#ajaxmode").val(0);
 
			$("#output").html(data.msg);
			
		}









	/* ---------------------------------------------------------*
	 * Function : PreIntermediatupdates.doc,					|
	 * ID 		: Feb2010-DeleteStudent							|
	 * Issue 	: Related to Delete Student From Teacher		|
	 * Author 	: Mr. Gourav Ku. Sharma
	 * Modified by 	: GK											|
	 -----------------------------------------------------------*/
	 
	
 $('.activeEdit').bind('click', function(){  
												  
												  
		$('#editmode').val(1);
		$('.text_draftgarde').hide();
		$('.edit_textdraft').show();
		
	 /*
	 if($('#editmode').val()==0){
	 	$('#editmode').val(1);
		$('.text_draftgarde').hide();
		$('.edit_textdraft').show();
	//	$('#edit_text').html('Close Edit');
		
	 }else{
		 $('#editmode').val(0);
		 $('.text_draftgarde').show();
		 $('.edit_textdraft').hide();
		 //$('#edit_text').html('Edit');
		 
		 }*/
	 
	 
});		
	
	
	
	 
		 $('.delteacher1').bind('click', function(){
			 var href=$(this).attr('href')
							 
 
			jConfirm('Are you sure you want to delete this teacher from the system? This action is permanent.',null, function(result){
				if (result) { 
 				window.location=href;
				}
			});
					return false;	
		});	  

		 $('.delstudent1').bind('click', function(){
			 var href=$(this).attr('href')
							 
 
			jConfirm('Are you sure you want to delete this student?',null, function(result){
				if (result) { 
 				window.location=href;
				}
			});
					return false;	
		});	  


		 $('.delneedhelp').bind('click', function(){
			 var href=$(this).attr('href')
							 
	  
				jConfirm('Are you sure you want to delete help request?',null, function(result){
				if (result) { 

				window.location=href;
				}
			});
					return false;	
		});	  
	  
		 
	 $('.delmessage').bind('click', function(){
			 var href=$(this).attr('href')
							 
	  
				jConfirm('Are you sure you want to delete this message?',null, function(result){
				if (result) { 

				window.location=href;
				}
			});
					return false;	
		});	  
	 
	 
	 
	 
	 
	 
	 $('.delfrnd').bind('click', function(){
			 var href=$(this).attr('href')
							 
	  
				jConfirm('Are you sure you want to delete this Friend.?',null, function(result){
				if (result) { 

				window.location=href;
				}
			});
					return false;	
		});	 
	 
	 
		$('.newdraft').bind('click', function(){
				 $('#frm2').hide();
						 
	 
				jConfirm('Are you sure you want to create a new draft?',null, function(result){
				if (result) {
					 $('#frm2').show();
				}
			});
						
		});	 
	 
	
	$('.chk_Period').bind('click', function(){
						
				if($('#period').val()==''){
				jAlert("Please select a folder.") ;
					return false; 
					
				}
						
		});									
	
	$('.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();
			}
		});
	});
	
	
	$('.AssFormSend').click(function(){
	if(valid()){								 
		jConfirm('Do you wish to save and send assessment now?', null, function(result){
			if(result) 
			{ 
				$('.clickButton').val('send');
				$("#ass").submit();
			
			}
		});
	}	
	});
	
			$('.AssFormSave').click(function(){
		$('.clickButton').val('save');

				});
			
			
			$('.AssSFormSend').click(function(){
								 
		jConfirm('Do you wish to save and submit assessment now?', null, function(result){
			if(result) 
			{ 
				$('.clickButton').val('send');
				$("#ass").submit();
			
			}
		});

	});
	
			$('.AssSFormSave').click(function(){
		$('.clickButton').val('save');

				});
		
		
		
		
	$('.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){*/
																																																																						  
	jConfirm('When you publish your essay you will be able to share with your friends and your teacher will be able to grade it.', 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){*/
																																																																						  jConfirm('When you publish your essay you will be able to share with your friends and your teacher will be able to grade it.', 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 that you want to delete checked book reports.',null,function(result){
			if(result) {
				$("#writingid").val(id);
				document.getElementById("mwdeletefrm").action =  siteUrl + controllers + "/" + actions ;			
				$("#mwdeletefrm").submit();
			}
		});
	});
	
	
	
	
	
	 $(".mwdeletediary").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 topic?',null,function(result){
			if(result) {
				$("#diaryid").val(id);
				document.getElementById("mwdeletefrm").action =  siteUrl + controllers + "/" + actions ;	
				$("#mwdeletefrm").submit();
			}
		});
	});
	 
	 
	$(".mwdeletegraphic").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 Graphic?',null,function(result){
			if(result) {
				$("#studentId").val(id);
				document.getElementById("mwgraphicfrm").action =  siteUrl + controllers + "/" + actions ;	
				$("#mwgraphicfrm").submit();
			}
		});
	});
 
	 
	 
	  $(".mwdeleteass").bind("click", function(){
		var id = $(this).attr('id');
		var period = $(this).attr('period');
		var controllers = $(this).attr('controllers');
		var actions = $(this).attr('actions');
	
		jConfirm('Are you sure you want to delete this topic?',null,function(result){
			if(result) {
				$("#assid").val(id);
				$("#period").val(period);
				document.getElementById("mwdeletefrm").action =  siteUrl + controllers + "/" + actions ;	
				$("#mwdeletefrm").submit();
			}
		});
	});
	 
	 
	 $(".mwcancelass").bind("click", function(){ 
		var id = $(this).attr('id');
		var period = $(this).attr('period');
		var controllers = $(this).attr('controllers');
		var actions = $(this).attr('actions');
	
		jConfirm('Are you sure you want to cancel this assignment ?',null,function(result){
			if(result) {
				$("#assid").val(id);
				$("#period").val(period);
				document.getElementById("mwdeletefrm").action =  siteUrl + controllers + "/" + actions ;	
				$("#mwdeletefrm").submit();
			}
		});
	});
	 
	 $(".mweditdiary").bind("click", function(){
		var id = $(this).attr('id');
		var controllers = $(this).attr('controllers');
		var actions = $(this).attr('actions');
		
		$("#diaryid").val(id);
		document.getElementById("mwdeletefrm").action =  siteUrl + controllers + "/" + actions ;	
		//alert(document.getElementById("mwdeletefrm").action =  siteUrl + controllers + "/" + actions);
		$("#mwdeletefrm").submit();
	
	});
	
	$(".mweditvenndia").bind("click", function(){
		var id = $(this).attr('studentId');
		var diaid = $(this).attr('diagramId');
		var controllers = $(this).attr('controllers');
		var actions = $(this).attr('actions');
		
		$("#studentId").val(id);
		$("#diagramId").val(diaid);
		document.getElementById("mwgraphicfrm").action =  siteUrl + controllers + "/" + actions ;	
		//alert(document.getElementById("mwdeletefrm").action =  siteUrl + controllers + "/" + actions);
		$("#mwgraphicfrm").submit();
	
	});

	
	 $(".mweditass").bind("click", function(){
		var id = $(this).attr('id');
		var controllers = $(this).attr('controllers');
		var actions = $(this).attr('actions');
		$("#assid").val(id);
		document.getElementById("mwdeletefrm").action =  siteUrl + controllers + "/" + actions ;	
		//alert(document.getElementById("mwdeletefrm").action =  siteUrl + controllers + "/" + actions);
		$("#mwdeletefrm").submit();
	
	});
	 
	  $(".mwstartass").bind("click", function(){
		var id = $(this).attr('id');
		var teacher = $(this).attr('teacher');
		var period = $(this).attr('period');
		
		var controllers = $(this).attr('controllers');
		var actions = $(this).attr('actions');
		$("#assid").val(id);
		$("#teacher").val(teacher);
		$("#period").val(period);
		document.getElementById("mwdeletefrm").action =  siteUrl + controllers + "/" + actions ;	
		//alert(document.getElementById("mwdeletefrm").action =  siteUrl + controllers + "/" + actions);
		$("#mwdeletefrm").submit();
	
	});
	
	
	
	
	$("#narrativeessaygraph").bind("click",function(){
		//alert('test') ;
		//$("#frm2").action = 'narrativeessay/secondtab';
		$("#continue").val(0);
		document.frm1.action = 'secondtab';
		document.frm1.submit();
	});
 $("#narrativeessaygraph_C").bind("click",function(){
												 $("#continue").val(1);
		//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)
		});
		
		
		$("#mwtimerSButton").bind("click", function() {
												   
				var mytime;

					
				mytime = $("#customtime").val();	
	
				if(mytime=='')
				{
					jAlert("Please Enter time.");
					$("#timerouterdiv").find('input').attr('disabled', 'disabled');
					timer('');
				}
			
				else if(mytime>120)
				{
					jAlert("Time does not greater then 120 minutes.");
					$("#timerouterdiv").find('input').attr('disabled', 'disabled');
					timer('');

				}
		
				else
				{		
					$("#timerouterdiv").find('input').attr('disabled', 'disabled');
					timer(mytime);
				}
				
			});
		
		$("#mwstoptimerSButton").bind("click", function() {
				
				$('#mwtimerdiv').countdown('pause');
				$("#timerouterdiv").find('input').removeAttr('disabled');
			});
		
		/////////////////////////////
		
		$("#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);
			}
		});
		
		$(".limitasstopic").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);
				$(".limitasstopic").val(mycontent);
			}
		});
		
		$(".limitasstopic2").bind("keyup", function() {
			var mylength = $(this).val();
			var mylimit = 1500;
			if(mylength.length > mylimit)
			{
				jAlert("Limit of 1500 exceeded");
				var mycontent = mylength.substr(0,mylimit-1);
				$(".limitasstopic").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;
			
			//alert(lit);
			
			$(".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;
				if((lit=='lit15') || (lit=='lit16') || (lit=='lit17') || (lit=='lit18') || (lit=='lit19') || (lit=='lit20') || (lit=='lit21'))
				{
						document.getElementById('nonfict').checked = true;
						document.getElementById('fict').checked = false;
				}
				if((lit=='lit1') || (lit=='lit2') || (lit=='lit3') || (lit=='lit4') || (lit=='lit5') || (lit=='lit6') || (lit=='lit7') || (lit=='lit8') || (lit=='lit9') || (lit=='lit10') || (lit=='li11') || (lit=='lit12') || (lit=='lit13') || (lit=='lit14'))
				{
						document.getElementById('nonfict').checked = false;
						document.getElementById('fict').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('_');
								
				//alert(id);
				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();
		});
		
		
		$(".viewgradedass").bind("click", function () {
				var essaytype = $(this).attr('id');
				$("#tassg").val(essaytype);
				//jAlert($("#tessayg").val()); 
				$("#tfrmassg").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() {	
			  $("#ajaxmode").val(0);
			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 -----
		
		$(".gradeeAss").bind("click", function() {	
			var comment = $(".comment").val();
			var flag = 0;
			if(document.getElementById('comment').value=='')
				{
				jAlert("Enter comment for the work.");
				return false;
				}
			
				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
				{
					$("#ass").submit();
				}
				
		});
		
		
		//////////********* 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'))
			{ var id = $(this).attr('id'); 
			$("#T"+id).html("Disable ");
			
				$("#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) 
					{			
						$("#T"+id).html("Enable ");
					
						$("#rostershow").hide();
						enablePeriod(checked, id, cone);
					}
					else
					{	$("#T"+id).html("Disable ");
					  $(".enableperiod").attr('checked','checked');
					}
				});
			}
			
		});*/
		
		
		
		$(".enableperiod").bind("click", function() {			 
			var cone =  $("#mwcontroller").val() ;	
			if($(this).attr('checked')==false)
			{ 
				var id = $(this).attr('id'); 
				$("#T"+id).html("Disable ");
				$("#rostershow").show();
				enablePeriod( false, $(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) 
					{			
						$("#T"+id).html("Enable ");
					
						$("#rostershow").hide();
						enablePeriod(true, id, cone);
					}
					else
					{	
					$("#T"+id).html("Disable ");
					  $(".enableperiod").attr('checked','');
					}
				});
			}
			
		});
		
		
	function enablePeriod(Value, id, cone)
	{
		if( Value ) {
			Value = 1;	
		} else {
			Value = 0;	
		}
		
		$.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");
		  }
		  
		});
	}		
		
		/////////////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();
				}
			});
			
		});
		
		
		$(".active_sem").bind("click", function() {
 		var mid = $(this).attr('id'); 
		   var val=	$(this).val();
			
			jConfirm('Do You want to change Active Semester?', null, function(result){
				if (result) 
				{			
				document.getElementById(mid).checked=true;
				//alert(siteUrl +  "teacher/semester/sem/"+val);
				 window.location=siteUrl +  "teacher/semester/sem/"+val;
				 
				}else{
					
				return false;	
				}
			});			
	 	
			return false;	
		})
		
		$(".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();
				}
			});			
			
			
		});
		
		
		$(".mwjournalhelp").bind("click", function() {
			var id = $(this).attr('id');
			$("#jrid").val(id); 
			document.getElementById("journalfrm").action =  siteUrl +  "journal/help";			
			$("#journalfrm").submit();
		});
	
	
			
		$(".responseJournal").bind("click", function() {
			var id = $(this).attr('id');
			$("#jrid").val(id);
			document.getElementById("journalfrm").action =  siteUrl +  "journal/help";			
			$("#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);
			
			jConfirm('You are sharing this Assignment. Do you wish to continue?', null, function(result){
				if (result) 
				{			
					document.getElementById("sharebookfrm").action =  siteUrl +  "book/share";
					$("#sharebookfrm").submit();
				}
			});
			
		});
	
	$(".mwbunshare").bind("click", function() {
			var value = $(this).attr('id');
			$("#bookid").val(value);
			
			jConfirm('You are unsharing this  Assignment. Do you wish to continue?', null, function(result){
				if (result) 
				{			
					document.getElementById("sharebookfrm").action =  siteUrl +  "book/unshare";
					$("#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();
			var mode= $("#mode").val();
			insertpointarea(pointno,mode);
		});
		
		$("#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(){
			
			//alert("aaaaaaaaa");
			
			var actions = $(this).attr('action');
			//alert(actions);
			$('#isFinal').val(1);
			var valid 	= validationBookGraphSkip();
			//alert(valid);
			//var valid = checkValidation();
			if( valid == true ) 
			{ 	
				//alert(siteUrl +  "book/"+actions);
				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() ;
				//alert(valid);
				
				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();
					}
				});	
			}
			
		});
	
	
	
		
		
		$(".mwbookhelp").bind("click", function(){
			var id = $(this).attr('id');
			$("#bookid").val(id);
			document.getElementById("sharebookfrm").action =  siteUrl +  "book/help";			
			$("#sharebookfrm").submit();
			
		});
	
	
			$(".responseBook").bind("click", function(){
			var id = $(this).attr('id');
			$("#bookid").val(id);
			document.getElementById("sharebookfrm").action =  siteUrl +  "book/help";			
			$("#sharebookfrm").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 id = $(this).attr('id');
			$("#mwdeid").val(id);
			
			jConfirm('You are sharing this Current Event. Do you wish to continue?', null, function(result){
				if (result) 
				{			
					document.getElementById("demanagefrm").action =  siteUrl +  "currentevent/share";
					$("#demanagefrm").submit();
				}
			});
			
		});
		
		
	
		
		
	$(".mwcurrentunshare").bind("click", function() {
		var id = $(this).attr('id');
			$("#mwdeid").val(id);
			
			jConfirm('You are unsharing this Current Event. Do you wish to continue?', null, function(result){
				if (result) 
				{			
					document.getElementById("demanagefrm").action =  siteUrl +  "currentevent/unshare";
					$("#demanagefrm").submit();
				}
			});
			
		});	
		
		
		
		$(".mweditcurrentevent").bind("click", function(){
			var id = $(this).attr('id');
			$("#mwdeid").val(id);
			document.getElementById("demanagefrm").action =  siteUrl +  "currentevent/editcurrentevent";			
			$("#demanagefrm").submit();
			
		});		
		
		$(".mwcurrenteventhelp").bind("click", function() {
		var id = $(this).attr('id');
			$("#mwdeid").val(id);
			document.getElementById("demanagefrm").action =  siteUrl +  "currentevent/help";			
			$("#demanagefrm").submit();
		});
		$(".responseCurrentevent").bind("click", function() {
		var id = $(this).attr('id');
			$("#mwdeid").val(id);
			document.getElementById("demanagefrm").action =  siteUrl +  "currentevent/help";			
			$("#demanagefrm").submit();
		});		
		
		$(".mwcurrentpublish").bind("click", function() {
		var id = $(this).attr('id');
			$("#mwdeid").val(id);
			
			jConfirm('When you publish your article it goes to your teacher. Do you wish to submit your article now?', null, function(result){
				if (result) 
				{	
				
				document.getElementById("demanagefrm").action =  siteUrl +  "currentevent/publish";			
			$("#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);
			$("#isfinal"+no).val(0);
			
			 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);	
			
			jConfirm('You are sharing this Essay. Do you wish to continue?', null, function(result){
				if (result) 
				{			
			document.getElementById("demanagefrm").action =  siteUrl +  "descriptiveessay/share";
			$("#demanagefrm").submit();
				}
			});
			
		});
		
$(".mwdescunshare").bind("click", function() {
			var sval= $(this).attr('id'); 
			$("#mwdeid").val(sval);	
			
			jConfirm('You are unsharing this Essay. Do you wish to continue?', null, function(result){
				if (result) 
				{			
			document.getElementById("demanagefrm").action =  siteUrl +  "descriptiveessay/unshare";
			$("#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();
		});
		
	$(".responseDE").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);
				$("#isfinal"+no).val(0); 
			 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);	
			
			jConfirm('You are sharing this Essay. Do you wish to continue?', null, function(result){
				if (result) 
				{			
		document.getElementById("demanagefrm").action =  siteUrl +  "expositoryessay/share";
			$("#demanagefrm").submit();
				}
			});
			
		});
		
	
		
		
		$(".mwexpounshare").bind("click", function() {
			var sval= $(this).attr('id'); 
			$("#mwdeid").val(sval);	
			
			jConfirm('You are unsharing this Essay. Do you wish to continue?', null, function(result){
				if (result) 
				{			
		document.getElementById("demanagefrm").action =  siteUrl +  "expositoryessay/unshare";
			$("#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();
		});
		
		 $(".responseEE").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){*/
																																																																							  jConfirm('When you publish your essay you will be able to share with your friends and your teacher will be able to grade it.', 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);		
			
			jConfirm('You are sharing this Essay. Do you wish to continue?', null, function(result){
				if (result) 
				{			
		document.getElementById("demanagefrm").action =  siteUrl +  "persuasiveessay/share";
			$("#demanagefrm").submit();
				}
			});
			
		});
		
		
		
		
		$(".mwpersunshare").bind("click", function() {
				var sval= $(this).attr('id'); 
			$("#mwpeid").val(sval);	
			
			jConfirm('You are unsharing this Essay. Do you wish to continue?', null, function(result){
				if (result) 
				{			
		document.getElementById("demanagefrm").action =  siteUrl +  "persuasiveessay/unshare";
			$("#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();
		});
		
		$(".responsePE").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();	
		})

		$(".ccommentbutton").bind("click", function() {
			$("#postccomment").toggle();
		});
		
		//////end of current event section
		
		
		///Blank Current event section
		$(".mwblankCE").bind("click", function() {
			var id = $(this).attr('id');
			$("#currenteventid").val(id); //3
			$("#newsfrm").attr("action","blankevent");
			$("#newsfrm").submit();	
		})

		$(".techmwblankCE").bind("click", function() {
			var id = $(this).attr('id');
			$("#currenteventid").val(id); //3
			$("#newsfrm").attr("action","teacherblankevent");
			$("#newsfrm").submit();	
		})
		//////end of Blank 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 oEditor = FCKeditorAPI.GetInstance('bibliography') ;
			var field7 = oEditor.GetXHTML(true);	//jAlert(field6);
			$("#bibliography").val(field7);
					
			 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(0);
			
			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){*/
	 jConfirm('When you publish your essay you will be able to share with your friends and your teacher will be able to grade it.', null, function(result){	
				if(result) {$("#isfinal"+no).val(1);
					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();
				}
			});
		});
		
		
	$(".mwsciencehelp").bind("click", function(){
			var sval= $(this).attr('id'); 
			$("#mwsid").val(sval);		
			document.getElementById("smanage").action =  siteUrl +  "science/help";
			$("#smanage").submit();
		});
	
			
	$(".responseScience").bind("click", function(){
			var sval= $(this).attr('id'); 
			$("#mwsid").val(sval);	alert(sval);			
			document.getElementById("smanage").action =  siteUrl +  "science/help";
			$("#smanage").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);			
			
			jConfirm('You are sharing this Science Writing. Do you wish to continue?', null, function(result){
				if (result) 
				{			
			document.getElementById("smanage").action =  siteUrl +  "science/share";
			$("#smanage").submit();
				}
			});
		
		});
		
		
		$(".mwscienceunshare").bind("click", function() {
			var sval= $(this).attr('id');
			$("#mwsid").val(sval);		
			
			jConfirm('You are unsharing this Science Writing. Do you wish to continue?', null, function(result){
				if (result) 
				{			
							document.getElementById("smanage").action =  siteUrl +  "science/unshare";
							$("#smanage").submit();
				}
			});			
			
			
	
		});
		
		
		//for the publish button on the manage science wtiting page
		$(".mwsciencepublish").bind("click", function() {
			var sval= $(this).attr('id');
			//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.
			jConfirm('When you submit your paper it goes to your parent. Do you wish to submit your paper now?', null, function(result){
				if (result) 
				{	
					$("#mwsid").val(sval);
					document.getElementById("smanage").action =  siteUrl +  "science/publish";
					$("#smanage").submit();
				}
			});	
			
		});
		
		
		
		$(".mwjournalpublish").bind("click", function() {
													
			var id = $(this).attr('id');
			$("#jrid").val(id);
											  
			var sval= $(this).attr('id');
			
			jConfirm('When you publish your paper it goes to your teacher. Do you wish to publish your paper now?', null, function(result){
				if (result) 
				{	
					document.getElementById("journalfrm").action =  siteUrl +  "journal/publish";			
					$("#journalfrm").submit();
				}
			});	
			
		});
		
		
		
		
		
		
			
		$(".mwpublishbookreport").bind("click", function() {
						 
			var id = $(this).attr('id');
			$("#bookid").val(id);
		
			
  
			
			jConfirm('When you publish your assignment it goes to your teacher. Do you wish to publish your assignment now?', null, function(result){
				if (result) 
				{	
			 document.getElementById("sharebookfrm").action =  siteUrl +  "book/publish";						
			$("#sharebookfrm").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);	
			
			jConfirm('You are sharing this Essay. Do you wish to continue?', null, function(result){
				if (result) 
				{			
			document.getElementById("demanagefrm").action =  siteUrl +  "narrativeessay/share";
			$("#demanagefrm").submit();
				}
			});
			
		});
		
	 $(".mwnarrunshare").bind("click", function() {
			var sval= $(this).attr('id'); 
			
			$("#mwdeid").val(sval);	
			
			jConfirm('You are unsharing this Essay. Do you wish to continue?', null, function(result){
				if (result) 
				{			
			document.getElementById("demanagefrm").action =  siteUrl +  "narrativeessay/unshare";
			$("#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();
		});
		
		$(".responseNE").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);
 
			document.getElementById("frmHelpResponse").action = siteUrl +  "essay/helpresponse" ;			
			$('#frmHelpResponse').submit();
		});
		
		
		
 $('.journal_helpresponse').bind('click', function() {
			var helpid =  $(this).attr('id');
			$("#helpresponseid").val(helpid);
 
			document.getElementById("frmHelpResponse").action = siteUrl +  "journal/helpresponse" ;			
			$('#frmHelpResponse').submit();
		});
		
 $('.science_helpresponse').bind('click', function() {
			var helpid =  $(this).attr('id');
			$("#helpresponseid").val(helpid);
 
			document.getElementById("frmHelpResponse").action = siteUrl +  "science/helpresponse" ;			
			$('#frmHelpResponse').submit();
		});	
 
 $('.current_helpresponse').bind('click', function() {
			var helpid =  $(this).attr('id');
			$("#helpresponseid").val(helpid);
 
			document.getElementById("frmHelpResponse").action = siteUrl +  "currentevent/helpresponse" ;			
			$('#frmHelpResponse').submit();
		});	
 
 $('.book_helpresponse').bind('click', function() {
			var helpid =  $(this).attr('id');
			$("#helpresponseid").val(helpid);
 
			document.getElementById("frmHelpResponse").action = siteUrl +  "book/helpresponse" ;			
			$('#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,md)
	{	
		$.ajax({
		  type: "GET",
		//url: "http://ksiprojects.net/projects/school/book/insertrisingdiv", 
		  url:  siteUrl +  "persuasiveessay/insertpointdiv", 
		  data: 'id='+id+'&md='+md, 
		  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 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){*/
																																																																							 jConfirm('When you publish your essay you will be able to share with your friends and your teacher will be able to grade it.', null, function(result){	
			if(result) {
				$("#isfinal").val(1);
				$("#sciencefrm").submit();
			}		
		}) ;
	}
	
	
	function checkValidationCurrentEvent(){	
			
		if($('#period').val()==''){
				jAlert("Please select a Period.") ;
					return false; 
					
				}
			
		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);
	}
	
function trim(value) {
	//alert(value);
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   //document.write(obj); exit;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = / +/g;
   temp = temp.replace(obj, " ");
   if (temp == " ") { temp = ""; }
   return temp;
	}


