function GetXmlHttpObject(){
	var xmlHttp=null;
	try{
	  	// Firefox, Opera 8.0+, Safari
	  	xmlHttp=new XMLHttpRequest();
  	}
	catch (e){
	  // Internet Explorer
	  try{
	    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	  catch (e){
	    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	}
	return xmlHttp;
}


function trim(stringToTrim){
	return stringToTrim.replace(/^\s+|\s+$/g,'');
}

function PostDiscussion(sumid){
var resc = sumid;
var tit = document.discussion.title.value;


if(resc!=2 && resc!=3 && resc!=4 && resc!=5 && resc!=6 && resc!=7 && resc!=8){

var cat = document.discussion.parts.value;}
var des = document.discussion.desc.value;
var ruid = document.discussion.rid.value;
var parid = document.discussion.partid.value;


if(trim(tit)=='')
	{
		alert("Please enter title");
		document.discussion.title.focus();
		return false;
	}
else
   {

	var flag=false;
		var iChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
			for (var i = 0; i < tit.length; i++)
			 {
				if (iChars.indexOf(tit.charAt(i)) != -1)
				  {

						flag=true;
						break;
				  }
			 }

			if(flag==false)
				{
					alert ("Title contains illegal characters!");
					document.discussion.title.value='';
					document.discussion.title.focus();
					return false;
				}
	}

if(resc!=2){
	if(cat =='0')
		{
			alert("please select any course");
			document.discussion.parts.focus();
			return false;
		}
}
if(trim(des)=='')
	{
		alert("Please enter description");
		document.discussion.desc.focus();
		return false;
	}
else
   {
   		if(resc!=2){
			var params = "title=" +tit+"&categ="+cat+"&desc="+des+"&real="+ruid+"&partid="+parid;
		}else{
			var params = "title=" +tit+"&desc="+des+"&real="+ruid+"&partid="+parid;
		}
		xmlHttp=GetXmlHttpObject();
		url="postdiscussion.php";
		xmlHttp.open("POST",url,true);
		xmlHttp.onreadystatechange=stateChanged2;
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		return false;

   }
   return true;

}


function stateChanged2()
{
    if (xmlHttp.readyState==4 && xmlHttp.status == 200)
 	{
		document.getElementById("newmahistartnewtopic").style.display="block";
		document.getElementById("newmahi2startnewtopic").style.display="block";
		document.getElementById("navin").style.display="block";
		document.discussion.title.value='';
		//document.discussion.parts.value='0';
		document.discussion.desc.value='';
		document.getElementById("navin").innerHTML='<img src="/education_images/sendsuccess.jpg">&nbsp;&nbsp;Your question has been posted successfully';
		document.getElementById("webdesigner").innerHTML=xmlHttp.responseText;

		setTimeout("toggle_newTopic('close');document.getElementById('navin').innerHTML='';",1000);
    }
    else
    {
    	document.getElementById("dispost").disabled=true;
		document.getElementById("navin").innerHTML='<img src="/education_images/ajax_loader.gif">&nbsp;&nbsp;Processing....';
    }

}


/*------------Request to join popup height adjustment--------------*/
function getScrollHeight(){
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
   return h ? h : 0;
}
/*------------------------------End---------------------------------*/

//function replyPopup(what,id){
function replyPopup(what,id,ct){

var vr =  document.getElementById('replyforthhis'+id);
var scrollHeight = getScrollHeight();

for(i=0;i<ct;i++){
	if(i!=id){
			document.getElementById('replyforthhis'+i).style.display='none';
	}
}



	if(what=='open')
			{
				vr.style.display = "block";
				//vr.style.focus=Number(scrollHeight+20)+"px";
				//alert(Number(scrollHeight+20));
				//window.scrollBy(0,Number(scrollHeight-50));
				//return false;
				vr.scrollIntoView(true);


			}
		else if(what=='close')
		{
			vr.style.display = "none";

		}

}


function searchDiscussion(real){

var searchkey = document.searchpart.searchstring.value;
if(trim(searchkey)=='')
	{

		alert("Please enter search string");
		document.searchpart.searchstring.value='';
		document.searchpart.searchstring.focus();
		return false;
	}
 document.searchpart.action="searchdiscussion.php?"+real;
 document.searchpart.submit();
 return true;
}



function toggle_newTopic(what,newid)
	{




		var v1 = document.getElementById("newmahistartnewtopic");
		var v2 = document.getElementById("newmahi2startnewtopic");
		//var v3 = document.getElementById("navin");
			if(what=='open')
			{
				v1.style.display = "block";
				v2.style.display = "block";
				//v3.style.display = "none";
			}
			else if(what=='close')
			{
				v1.style.display = "none";
				v2.style.display = "none";
			}
	}


function toggle_videoDisplay(rid,videoid,vidname)


	{
	    if(videoid=='' && vidname=='')
	    	{
	    		alert("There is no video for this chapter.");
	    		return false;
	    	}
        else
           {
				var v1 = document.getElementById("newvideo");
				var v2 = vidname;

						newwindow=window.open('/onlineeducation/viewvideo1.php?'+rid+"&vid="+videoid+"&vnam="+vidname,'vidname','height=620,width=950');
							if (window.focus) {newwindow.focus()}
							return false;
			}

	 }

function toggle_newTopic(what)
	{
		var v1 = document.getElementById("newmahistartnewtopic");
		var v2 = document.getElementById("newmahi2startnewtopic");
			if(what=='open')
			{
				v1.style.display = "block";
				v2.style.display = "block";
			}
			else if(what=='close')
			{
				v1.style.display = "none";
				v2.style.display = "none";
			}
	}

function toggle_replyDelete(what,Did,ct1)
	{

		var vr1 =  document.getElementById('naveendeletemain'+Did);
		var v1 = document.getElementById("naveendeletemain"+Did);

		for(i=0;i<ct1;i++)
			{
				if(i!=Did)
					{

						document.getElementById("naveendeletemain"+i).style.display='none';
					}
			}


			if(what=='open')
			{
				vr1.style.display = "block";
				vr1.scrollIntoView(true);
				//v1.style.display = "block";
			}
			else if(what=='close')
			{
				v1.style.display = "none";
			}
	}

function toggle_replyDeletequestion(what,Did)
	{
		var v1 = document.getElementById("naveendeletemainquestion");

			if(what=='open')
			{
				v1.style.display = "block";
			}
			else if(what=='close')
			{
				v1.style.display = "none";
			}
	}


/*All & None function*/
function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
	var ins = document.getElementsByName('mycheckbox');

	if(CheckValue==false)
	{
		for(i=0;i<ins.length;i++)
			ins[i].checked=false;
	}
	else if(CheckValue==true)
	{
		for(i=0;i<ins.length;i++)
			ins[i].checked=true;
	}
}
/*----------END-----------*/





/*	Methods for delete sent items using checkbox	*/
function dropdownmenu3(select,FormName, FieldName , realuserid, pgid)
{

	var ins = document.getElementsByName('mycheckbox');
	var divarr = document.getElementsByName('sentdivid');
	var i;
	var j=0;
	var vals= new Array();
	var sentdivvals= new Array();
	for(i=0;i<ins.length;i++)
		{
			if(ins[i].checked==true)
				{
					vals[j]=ins[i].value;
					sentdivvals[j]=divarr[i].value;
					j++;
				}

		}


		if((j=='0')&&(select.value!=''))
			{
				alert("Please select message(s) using checkbox(es)");
				document.myForm.actionDropdown.value='';
				return false;
			}
	  	else
			{
				document.myForm.vals.value=vals;
				if(select.value=='deletemsgs')
					{
						var params = "rid="+realuserid+"&dist=sentmessages&vals="+vals+"&pgid="+pgid;
						xmlHttp6=GetXmlHttpObject();
						var url="/onlineeducation/deletemsg3.php";
						xmlHttp6.open("POST",url,true);
						xmlHttp6.onreadystatechange=function(){
							if(xmlHttp6.readyState == 4 && xmlHttp6.status == 200)
							{
								document.getElementById('inbox1main').innerHTML = xmlHttp6.responseText;
							}
							else
							{
								for(var k=0;k<sentdivvals.length;k++){
									animatedcollapse.addDiv('messagecover'+sentdivvals[k],'fade=1,height=80px')// adding collapse divname
									animatedcollapse.addDiv('forline'+sentdivvals[k],'fade=1,height=80px')
									animatedcollapse.init()	// initializing.
									animatedcollapse.hide('messagecover'+sentdivvals[k])
									if(divarr[divarr.length-1].value!=sentdivvals[sentdivvals.length-1])	//for identify the last message.
										animatedcollapse.hide('forline'+sentdivvals[k])
								}
							}
						}
						xmlHttp6.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
						xmlHttp6.setRequestHeader("Content-length", params.length);
						xmlHttp6.setRequestHeader("Connection", "close");
						xmlHttp6.send(params);

					}

			}
}




/*	Methods for delete sent items using directly	*/
function selectDelete(select,FormName, FieldName , realuserid, pid, divid, pgid)
{


    var divarr = document.getElementsByName('sentdivid');

	animatedcollapse.addDiv('messagecover'+divid,'fade=1,height=80px');// adding collapse divname
	animatedcollapse.addDiv('forline'+divid,'fade=1,height=80px');
	animatedcollapse.init();	// initializing.
	animatedcollapse.hide('messagecover'+divid);
	if(divarr[divarr.length-1].value!=divid)
		animatedcollapse.hide('forline'+divid);

	var params = "rid="+realuserid+"&dist=sentmessages&vals="+pid+"&pgid="+pgid;
	xmlHttp5=GetXmlHttpObject();
	var url="/onlineeducation/deletemsg3.php";
	xmlHttp5.open("POST",url,true);

	xmlHttp5.onreadystatechange=function(){
		if(xmlHttp5.readyState == 4 && xmlHttp5.status == 200)
		{
			document.getElementById('inbox1main').innerHTML =xmlHttp5.responseText;
		}
	}
	xmlHttp5.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp5.setRequestHeader("Content-length", params.length);
	xmlHttp5.setRequestHeader("Connection", "close");
	xmlHttp5.send(params);
	return false;



}



/*	Methods for delete search items using checkbox	*/
function dropdownmenu2(select,FormName, FieldName , realuserid,  pid, fromname, toname, stext, pgnum, days)
{


	var ins = document.getElementsByName('mycheckbox');
	var res= document.myForm.reds.value;
	var divarr = document.getElementsByName('searchdivid');

	var i;
	var j=0;
	var vals= new Array();
	var searchdivvals= new Array();
	for(i=0;i<ins.length;i++)
		{
			if(ins[i].checked==true)
				{
					vals[j]=ins[i].value;
					searchdivvals[j]=divarr[i].value;
					j++;
				}
		}

	if(ins.length)
		{

		}
	else
		{
		}

		if((j=='0')&&(select.value!=''))
			{
				alert("Please select message(s) using checkbox(es)");
				document.myForm.actionDropdown.value='';
				return false;
			}
		else
			{
				document.myForm.vals.value=vals;

				if((select=='deletemsgs')&& (res=='1'))
					{


						var params = "rid="+realuserid+"&dist=searchmessages&vals="+vals+"&pgid="+pgnum+"&from="+fromname+"&To="+toname+"&search="+stext+"&days="+days;
						xmlHttp6=GetXmlHttpObject();
						var url="/onlineeducation/deletemsg4.php";
						xmlHttp6.open("POST",url,true);
						xmlHttp6.onreadystatechange=function(){
							if(xmlHttp6.readyState == 4 && xmlHttp6.status == 200)
							{
								document.getElementById('inbox1main').innerHTML = xmlHttp6.responseText;
							}
							else
							{
								for(var k=0;k<searchdivvals.length;k++){
									animatedcollapse.addDiv('messagecover'+searchdivvals[k],'fade=1,height=80px')// adding collapse divname
									animatedcollapse.addDiv('forline'+searchdivvals[k],'fade=1,height=80px')
									animatedcollapse.init()	// initializing.
									animatedcollapse.hide('messagecover'+searchdivvals[k])
									if(divarr[divarr.length-1].value!=searchdivvals[searchdivvals.length-1])	//for identify the last message.
										animatedcollapse.hide('forline'+searchdivvals[k])
								}
							}
						}
						xmlHttp6.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
						xmlHttp6.setRequestHeader("Content-length", params.length);
						xmlHttp6.setRequestHeader("Connection", "close");
						xmlHttp6.send(params);


					}

				if((select=='deletemsgs')&& (res=='2'))
					{

						var params = "rid="+realuserid+"&dist=searchpage&vals="+vals+"&pgid="+pgnum+"&from="+fromname+"&To="+toname+"&search="+stext+"&days="+days;
						xmlHttp6=GetXmlHttpObject();
						var url="/onlineeducation/deletemsg3.php";
						xmlHttp6.open("POST",url,true);
						xmlHttp6.onreadystatechange=function(){
							if(xmlHttp6.readyState == 4 && xmlHttp6.status == 200)
							{
								document.getElementById('inbox1main').innerHTML = xmlHttp6.responseText;
							}
							else
							{
								for(var k=0;k<searchdivvals.length;k++){
									animatedcollapse.addDiv('messagecover'+searchdivvals[k],'fade=1,height=80px')// adding collapse divname
									animatedcollapse.addDiv('forline'+searchdivvals[k],'fade=1,height=80px')
									animatedcollapse.init()	// initializing.
									animatedcollapse.hide('messagecover'+searchdivvals[k])
									if(divarr[divarr.length-1].value!=searchdivvals[searchdivvals.length-1])	//for identify the last message.
										animatedcollapse.hide('forline'+searchdivvals[k])
								}
							}
						}
						xmlHttp6.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
						xmlHttp6.setRequestHeader("Content-length", params.length);
						xmlHttp6.setRequestHeader("Connection", "close");
						xmlHttp6.send(params);

					}

			}
}

/*-------------------End------------------------*/



/*	Methods for delete search items using directly	*/
function selectDelete1(select,FormName, FieldName , realuserid, pid, fromname, toname, stext, pgnum, days, divid)
{


	var ins = document.getElementsByName('mycheckbox');
	var res= document.myForm.reds.value;
	var i;
	var j=0;
	var vals =pid;


				document.myForm.vals.value=vals;
				if((select=='deletemsgs')&& (res=='1'))
					{
						var divarr = document.getElementsByName('searchdivid');
						animatedcollapse.addDiv('messagecover'+divid,'fade=1,height=80px');// adding collapse divname
						animatedcollapse.addDiv('forline'+divid,'fade=1,height=80px');
						animatedcollapse.init();	// initializing.
						animatedcollapse.hide('messagecover'+divid);
						if(divarr[divarr.length-1].value!=divid)
							animatedcollapse.hide('forline'+divid);

						var params = "rid="+realuserid+"&dist=searchmessages_from&vals="+pid+"&pgid="+pgnum+"&from="+fromname+"&To="+toname+"&search="+stext+"&days="+days;

						xmlHttp5=GetXmlHttpObject();
						var url="/onlineeducation/deletemsg4.php";
						xmlHttp5.open("POST",url,true);

						xmlHttp5.onreadystatechange=function(){
							if(xmlHttp5.readyState == 4 && xmlHttp5.status == 200)
							{
								document.getElementById('inbox1main').innerHTML =xmlHttp5.responseText;
							}
						}
						xmlHttp5.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
						xmlHttp5.setRequestHeader("Content-length", params.length);
						xmlHttp5.setRequestHeader("Connection", "close");
						xmlHttp5.send(params);
						return false;
					}

				if((select=='deletemsgs')&& (res=='2'))
					{
						var divarr = document.getElementsByName('searchdivid');
						animatedcollapse.addDiv('messagecover'+divid,'fade=1,height=80px');// adding collapse divname
						animatedcollapse.addDiv('forline'+divid,'fade=1,height=80px');
						animatedcollapse.init();	// initializing.
						animatedcollapse.hide('messagecover'+divid);
						if(divarr[divarr.length-1].value!=divid)
							animatedcollapse.hide('forline'+divid);

						var params = "rid="+realuserid+"&dist=searchpage&vals="+pid+"&pgid="+pgnum+"&from="+fromname+"&To="+toname+"&search="+stext+"&days="+days;



						xmlHttp5=GetXmlHttpObject();
						var url="/onlineeducation/deletemsg3.php";
						xmlHttp5.open("POST",url,true);

						xmlHttp5.onreadystatechange=function(){
							if(xmlHttp5.readyState == 4 && xmlHttp5.status == 200)
							{
								document.getElementById('inbox1main').innerHTML =xmlHttp5.responseText;
							}
						}
						xmlHttp5.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
						xmlHttp5.setRequestHeader("Content-length", params.length);
						xmlHttp5.setRequestHeader("Connection", "close");
						xmlHttp5.send(params);
						return false;




					}

}



/*------Validation for searchmessages page------*/
function validatedays()
{
	var str11=document.search.days.value;
	var str22 = document.search.from.value;
	var str33 = document.search.to.value;

   if(str22=="" && str33=="")
   		{
	   		alert("Please enter from or to name");
	   		return false;
   		}
   	if(str22!="" && str33!="")
   		{


   			alert("Enter either from name or to name");


   			return false;
   		}

   	if(str11==0)
   {
   		alert("Please select days");
   		document.search.days.focus();
   		return false;
   }

}

/*----------------------End---------------------*/


function replyValidate(){

if(trim(document.reply.replyans.value)=='')
	{
		alert("Please enter your reply");
		document.reply.replyans.value='';
		document.reply.replyans.focus();
		return false;
	}

	return true;

}


/*----------Function to check file extension while assignment uploading---------*/

function fileUpload()
	{
		var upl = document.upload.upassign.value;
		var myArray = upl.split('.');

		var extcheck = myArray[1];
		var myCars=new Array("gif","bmp","jpeg","jpg","png","pdf","xls","csv","exe","tpl");

		if(upl=='')
				{
					alert("Please browse your assignment to upload.");
					document.upload.upassign.focus();
					return false;
				}

		for(var i=0;i<myCars.length;i++)
			{
				if(extcheck==myCars[i])
					{
						alert("Invalid file format selected");
						document.upload.upassign.value='';
						return false;
					}
			}

		return true;
	}

/*----------------------End------------------------*/



/*---------------------Function to make cursor focus inside text area in reply page----*/
function makeFocus()
	{
		document.reply.replyans.value='';
		document.reply.replyans.focus();
	}
/*--------------------------------End-----------------------------*/
