function checkPasses(one,two)
{
   var pass=document.getElementById(one).value;
   var pass2=document.getElementById(two).value;

   if(pass!=pass2)
   {
    alert ("Passwords dont match!");
   }
}

function checkMail(email,frm)
{
      var mail=document.getElementById(email).value;
      
      if(mail=="")
      {
         alert("Please, fill in valid e-mail address.");
	 return false;
      }
      
      if(mail.indexOf("@")<2||mail.indexOf(".")<5)
      {
         alert("Please, fill in valid e-mail address.");
	 return false;
      }

      document.getElementById(frm).submit();
}

function confirmAction(frm)
{
   if(confirm("Are you sure?"))
   {
      frm.submit();
   }
   return true;
}

function centerWin(filename,width,height,name)
{
   var x=(screen.availWidth-width)/2;
   var y=(screen.availHeight-height)/2-50;

   if(name="") name='win'

   newWin=window.open(filename, name,"width="+width+",height="+height+", resizable=yes,scrollbars=yes,toolbar=no,status=yes");
   try
   {
   	  newWin.moveTo(x,y); 
   }
   catch(e)
   {
	   noError=false;
   }
   if (noError) 
   { 
	   newWin.resizeTo(width,height);
   }
  
}
function add(from,to) 
{
	var hidlen = document.getElementById('cntcmb').value;
	//alert( hidlen);
	//for (var i = 0;i < hidlen;i++)
	for (var i = 0;i < from.options.length;i++)
	{
	 	if (from.options[i].selected)
	 	{
			if(to.options.length>0)
			{
				var a=0;
				for(var j=0;j<to.options.length;j++)
				{
					//alert(from.options[i].text+" == "+to.options[j].text);
					if(from.options[i].text == to.options[j].text)
					{
						a=1;
						alert("Already Exist");
					}
				}
				if(a==0)
				{
					var optn = document.createElement("OPTION");
					optn.text = from.options[i].text;
					optn.value = from.options[i].value;
					to.options.add(optn);
					from.remove(i);
					i--;
					//to.options[to.options.length] = new Option(from.options[i].text);
				}
			}
			else
			{
				var optn = document.createElement("OPTION");
				optn.text = from.options[i].text;
				optn.value = from.options[i].value;
				to.options.add(optn);
				from.remove(i);
				i--;
				//old filling
				//to.options[to.options.length] = new Option(from.options[i].text); 
			}
				//alert(from.options[i].selected);
		}
		
	}
	
	
	
}
////when u remove the option will not add that in to from list box .
function removeAllOptions (from,to)

{

    for (var i = 0;i < to.options.length;i++)
	{
		if (to.options[i].selected)
		{	
			from.options[from.options.length] = new Option(to.options[i].text,to.options[i].value);
			to.remove (i);
			i--;
		}
		
	}

}
//when u remove the option add that in to from list box .
function removeAllOptions1 (from,to)
{
    for (var i = 0;i<to.options.length;i++)
	{
		if (to.options[i].selected==true)
		{	
			from.options[from.options.length] = new Option(to.options[i].text,to.options[i].value);
			//from.options.add(optn);
			to.remove (i);
			i--;
		}
		
	}
}

function openwindow(filename,width,height,name){
window.open(filename, name,"width="+width+",height="+height+", resizable=yes,scrollbars=yes,toolbar=no,status=yes");
//window.open('../whiteBoard.php?inst_id=$inst_id&studentname=$studentname&schedule_id=$schedule_id&student_id=$student_id','joinclass','fullscreen=1')	
}

function poponload(file)
{
var x=(screen.availWidth-480)/2;
var y=(screen.availHeight-275)/2-50;
var testwindow= window.open ("../upload_files/media_files/audioplay.php?audio_array="+file, "audio","scrollbars=1,fullscreen=0,width=480,height=275,resizable=1");
testwindow.moveTo(x,y);
}
function addAuthtopics(from,to) 
{
	var hidlen = document.getElementById('cntcmb').value;
	//alert( hidlen);
	//for (var i = 0;i < hidlen;i++)
	for (var i = 0;i < from.options.length;i++)
	{
	 	if (from.options[i].selected)
	 	{
			
			if(to.options.length>=0)
			{//alert(i);
				var a=0;
				for(var j=0;j<to.options.length;j++)
				{
					//alert(from.options[i].text+" == "+to.options[j].text);
					if(from.options[i].text == to.options[j].text)
					{
						a=1;
						alert("Already Exist");
					}
				}
				if(a==0)
				{
					var optn = document.createElement("OPTION");
					optn.text = from.options[i].text;
					optn.value = from.options[i].value;
					to.options.add(optn);
					//alert(from.options[i].value);
					xajax_loadchapter(from.options[i].value,'chapter');
					//to.options[to.options.length] = new Option(from.options[i].text);
				}
			}
			else
			{
				var optn = document.createElement("OPTION");
				optn.text = from.options[i].text;
				optn.value = from.options[i].value;
				to.options.add(optn);
				//old filling
				//to.options[to.options.length] = new Option(from.options[i].text); 
			}
				//alert(from.options[i].selected);
		}
		
	}
	
	
	
}

function removeAllAuthOptions (from,to)
{
	var len =to.options.length;
   // for (var i = ;i >=0;i--)
	for (var i = 0;i<to.options.length;i++)
	{
		if (to.options[i].selected==true)
		{
			//alert(i);
			xajax_Removechapters(to.options[i].value);
			to.remove (i);
			i--;
		}
	}

}
function removelistchap(id){
var len=document.getElementById('chapter').options.length;
  for (var i = 0;i<len;i++){
	if (document.getElementById('chapter').options[i].value==id){
		document.getElementById('chapter').remove (i);
	}
	
  }
  
}
function Removeselectedchapters(id){
var len1=document.getElementById('listchap').options.length;
if(len1>0){
	for (var j = 0;j<len1;j++){
		//alert(id+" "+document.getElementById('listchap').options[j].value);
		if (document.getElementById('listchap').options[j].value==id){
			document.getElementById('listchap').remove (j);
		}
  	}
  }
}

function indexvalidatelogin(){
var flg=true;
var usrname_alert = "Please Enter the UserName";
var passwd_alert = "Please Enter the Password";
var userpassalert= "Please Enter the User Name and Password";
document.getElementById('vf_submit').disabled='true';
var a=document.loginfrm;
	//var regpassverify = /^[A-Za-z]+[0-9]*[!@#\$>?,<%\^&\*\/\.]+[A-Za-z0-9]*$/;
	if(document.getElementById("vf_user").value=="" && document.getElementById("vf_password").value==""){
		alert("User Name and Pasword Fields are Empty");
		document.getElementById('vf_submit').disabled='';
		document.getElementById('vf_submit').value='Login';
		document.getElementById("vf_user").focus();
		flg=false;
	}else if(document.getElementById("vf_user").value==""){
		alert("User Name Field is Empty");
		document.getElementById('vf_submit').disabled='';
		document.getElementById('vf_submit').value='Login';
		document.getElementById("vf_user").focus();
		flg=false;
		//return false;
	}/*else if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("vf_user").value)){
		alert("Invalid User Name");
		document.getElementById("vf_user").value="";
		document.getElementById("vf_user").focus();
		flg=false;
		//return false;
	}*/else if(document.getElementById("vf_password").value==""){
		alert("Password field is Empty");
		document.getElementById('vf_submit').disabled='';
		document.getElementById('vf_submit').value='Login';
		document.getElementById("vf_password").focus();
		flg=false;
		//return false;
	}/*else if(!regpassverify.test(document.getElementById("vf_password").value)){
		alert("Password field must start with alphabet and it should contain atleast one numerical and one special character");				
		document.getElementById("vf_password").value="";
		document.getElementById("vf_password").focus();
		flg=false;				
	}else if((document.getElementById("vf_password").value.length)<6){
		alert("Password should be Minimum 6 Charecters");
		document.getElementById("vf_password").focus();
		flg=false;	
	}*/
	if(flg){
		a.action="indexcheck.php";
		a.submit();
	}else{
	return false;
	}
}
function validatelogin(){
	//alert("anbu");
var flg=true;
var usrname_alert = "Please enter the user name";
var passwd_alert = "Please enter the password";
var userpassalert= "Please enter the user name and password";
document.getElementById('vf_submit').disabled='true';
var a=document.loginfrm;
	//var regpassverify = /^[A-Za-z]+[0-9]*[!@#\$>?,<%\^&\*\/\.]+[A-Za-z0-9]*$/;
	if(document.getElementById("vf_user").value=="" && document.getElementById("vf_password").value==""){
		document.getElementById('loginerror').style['display']='';
		//document.getElementById('sessionerror').style['display']='none';
		document.getElementById('loginerror').innerHTML=userpassalert;
		document.getElementById('vf_submit').disabled='';
		document.getElementById('vf_submit').value='Login';
		document.getElementById("vf_user").focus();
		flg=false;
	}else if(document.getElementById("vf_user").value==""){
		document.getElementById('loginerror').style['display']='';
		//document.getElementById('sessionerror').style['display']='none';
		document.getElementById('loginerror').innerHTML=usrname_alert;
		document.getElementById('vf_submit').disabled='';
		document.getElementById('vf_submit').value='Login';
		document.getElementById("vf_user").focus();
		flg=false;
		//return false;
	}/*else if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("vf_user").value)){
		alert("Invalid User Name");
		document.getElementById("vf_user").value="";
		document.getElementById("vf_user").focus();
		flg=false;
		//return false;
	}*/else if(document.getElementById("vf_password").value==""){
		document.getElementById('loginerror').style['display']='';
		//document.getElementById('sessionerror').style['display']='none';
		document.getElementById('loginerror').innerHTML=passwd_alert;
		document.getElementById('vf_password').value='';
		document.getElementById('vf_password').focus();
		document.getElementById('vf_submit').disabled='';
		document.getElementById('vf_submit').value='Login';
		flg=false;
		//return false;
	}/*else if(!regpassverify.test(document.getElementById("vf_password").value)){
		alert("Password field must start with alphabet and it should contain atleast one numerical and one special character");				
		document.getElementById("vf_password").value="";
		document.getElementById("vf_password").focus();
		flg=false;				
	}else if((document.getElementById("vf_password").value.length)<6){
		alert("Password should be Minimum 6 Charecters");
		document.getElementById("vf_password").focus();
		flg=false;	
	}*/
	if(flg){
		a.action="logincheck.php";
		a.submit();
	}else{
	return false;
	}
}
function validateindex(){
	//alert("anbu");
var flg=true;
var usrname_alert = "Please enter the user name";
var passwd_alert = "Please enter the password";
var userpassalert= "Please enter the user name and password";
var a=document.loginfrm;
	//var regpassverify = /^[A-Za-z]+[0-9]*[!@#\$>?,<%\^&\*\/\.]+[A-Za-z0-9]*$/;
	if(document.getElementById("vf_user").value=="" && document.getElementById("vf_password").value==""){
		//document.getElementById('sessionerror').style['display']='none';
		alert(userpassalert);
		document.getElementById("vf_user").focus();
		flg=false;
	}else if(document.getElementById("vf_user").value==""){
		//document.getElementById('sessionerror').style['display']='none';
		alert(usrname_alert);
		document.getElementById("vf_user").focus();
		flg=false;
		//return false;
	}/*else if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("vf_user").value)){
		alert("Invalid User Name");
		document.getElementById("vf_user").value="";
		document.getElementById("vf_user").focus();
		flg=false;
		//return false;
	}*/else if(document.getElementById("vf_password").value==""){
		alert(passwd_alert);
		document.getElementById('vf_password').focus();
		flg=false;
		//return false;
	}/*else if(!regpassverify.test(document.getElementById("vf_password").value)){
		alert("Password field must start with alphabet and it should contain atleast one numerical and one special character");				
		document.getElementById("vf_password").value="";
		document.getElementById("vf_password").focus();
		flg=false;				
	}else if((document.getElementById("vf_password").value.length)<6){
		alert("Password should be Minimum 6 Charecters");
		document.getElementById("vf_password").focus();
		flg=false;	
	}*/
	if(flg){
		a.action="logincheck.php";
		a.submit();
	}else{
	return false;
	}
}
/*function forgetpass_validate(){
	if(document.getElementById("vf_email").value==""){
		alert("Email field is Empty");
		document.getElementById("vf_email").focus();
		return false;
	}else if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("vf_email").value)){
		alert("Invalid Email Address");
		document.getElementById("vf_email").value="";
		document.getElementById("vf_email").focus();
		return false;
	}
}*/

function loginsubmit(){
//	alert('adsa');
	document.getElementById('chklogin').action='login.php';
	document.getElementById('chklogin').submit();
}
function indexsubmit(){
//	alert('adsa');
	document.getElementById('chklogin').action='index.php';
	document.getElementById('chklogin').submit();
}
function submitform(myform)
{alert('submitting');
  document.myform.submit();
}
////////////////////////////////forget password validation/////////////////////////////////////////
function forgetpass_validate(){
	var forgetmailerror = document.getElementById("forgetmailerror");
	if(document.getElementById("vf_email").value==""){
		forgetmailerror.style["display"]="" ;
		forgetmailerror.innerHTML = "Please enter the e-mail address";
		//forgetmailerror.style.color="red";
		//alert("Email field is Empty");
		document.getElementById("vf_email").focus();
		return false;
	}else if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("vf_email").value)){
		forgetmailerror.style["display"]="" ;
		forgetmailerror.innerHTML = "Please enter valid e-mail address";
		//forgetmailerror.style.color="red";
		//alert("Invalid Email Address");
		document.getElementById("vf_email").value="";
		document.getElementById("vf_email").focus();
		return false;
	}
		
return true;
}
///////////////////////////////End forget password//////////////////////////////////////////////
function hideflds()
{	
	if(document.getElementById('qtype').value!=2)
	{
		document.getElementById('ch1').style.display='none';
		document.getElementById('ch2').style.display='none';
		document.getElementById('ch3').style.display='none';
		document.getElementById('ch4').style.display='none';
		document.getElementById('ch5').style.display='none';
	}
	else
	{
		document.getElementById('ch1').style.display='';
		document.getElementById('ch2').style.display='';		
		document.getElementById('ch3').style.display='';
		document.getElementById('ch4').style.display='';
		document.getElementById('ch5').style.display='';
	}		
}

function chkkey(evt)
{
	evt = (evt) ? evt : window.event
	var charCode = (evt.which) ? evt.which : evt.keyCode
	if (charCode == 9 || charCode == 46 || charCode == 8 || charCode == 37 || charCode == 39 || (charCode >= 48 && charCode <= 57))
	{
		return true;
	}
	else
	{
		alert("Please enter numbers.");
		return false;
	}
}
// disable select and copy paste  //
function blockError()
{
	window.location.reload(true);
	return true;
}

function disabletext(e)
{
	return false;
}

function reEnable()
{
	return true;
}

//if the browser is IE4+
document.onselectstart=new Function ("return false");
document.ondragstart=new Function ("return false");

//if the browser is NS6
function dissel()
{
	if (window.sidebar)
	{
		document.onmousedown=disabletext;
		document.onclick=reEnable;
	}
}

function keylock()
{
	if (event.ctrlKey)
	{
		return false;
	}
	else
	{
		return true;
	}
}
function validateSearch(filenameandpath){
	if(document.getElementById('searchfield').value=="" || document.getElementById('searchfield').value=="Type to Search"){
		alert("Please enter the search criteria.");
		document.getElementById('searchfield').focus();
		return false;
	}else{
		document.getElementById('searchfrm').action=filenameandpath;
		document.getElementById('searchfrm').submit();
	}
}