//To handle mouse events for all the pages
try{
document.onmousedown = window.status='Learning Management System';
document.dir="ltr"			// rtl="Right" ltr="Left"
}catch (ex) {}

		/* 
		Purpose		: To trim a given string 
		Created On	: 5th August 2002
		Created By	: Muzammil Ahmed*/
		
		function IsLeapYear(intYear)
		{
			if((intYear % 4) == 0)
			{
				return true;
			}				
			else
			{
				return false;
			}
		}
	
			
		function checkisnumber(num,cid)
		{
			for (i=0;i <= num.length - 1;i++)
			{
				if (isNaN(num.charAt(i)) == true)
				{
					
					alert(GetMessage('W2553',strPath));
					setfocus(cid);
					return false;
				}
			}
			return true;
		}
		
		function trim(s)
		{	
			SRet = ltrim(s);
			SRet = rtrim(SRet);
			return SRet;
		}

		function ltrim(s)
		{
			var i=0;
			var sp = " ";
			var nl = "\n";
			var cr = "\r";
			var ta = "\t";
			var SRet=s;
			
			while((s.charAt(i) == sp) || (s.charAt(i) == nl) || (s.charAt(i) == ta) || (s.charAt(i) == cr))
			{
				i++;		
			}
			if(i > 0)
			{
				SRet = s.substring(i,s.length);
				return SRet;
			}
			
			return SRet;
		}
		
		function rtrim(s)
		{
			var count=0;
			var i = s.length;
			i=i-1;
			var sp = " ";
			var nl = "\n";
			var cr = "\r";
			var ta = "\t";
			var SRet =s;
			while((SRet.charAt(i) == sp) || (SRet.charAt(i) == nl) || (SRet.charAt(i) == ta) || (SRet.charAt(i) == cr))
			{
				count++;
				i=i-1;
			}
			
			if(count > 0)
			{
				SRet = s.substring(0,s.length-count);
				return SRet;
			}
			
			return SRet;
		}
		/* end trim function*/
		
		/*to select all the checkboxes in a form*/
		function SelectAll()
		{
			var i 
			
			for(i=0;i < document.forms(0).length;i++)
			{	
				if(document.forms(0).elements[i].type == "checkbox") 
				{ 
				document.forms(0).elements[i].checked = true;
				} 
			}			 
		}				 
		/*end select all*/
		
		
		/*to clear all the checkboxes in a form*/
		function ClearAll() 
		{ 
			var i 
			for(i=0;i<document.forms(0).length;i++) 
			{ 
				if(document.forms(0).elements[i].type == "checkbox") 
				{ 
				document.forms(0).elements[i].checked = false; 
				} 
			}  
		} 
		/*end clear all*/
		
		function UsersWinOp(checkbox)
		{
			
			var URL = '../frmSelectUsersGeneral.aspx?Checkbox=' + checkbox
			window.open(URL,'','width=700,height=550,scrollbars=yes,toolbars=no')
		}
		
		function SelectUsersWinOpen(checkbox, AddSubmit, CloseSubmit)
		{
			var URL = '../frmSelectUsersGeneral.aspx?Checkbox=' + checkbox + '&AddSubmit=' + AddSubmit + '&CloseSubmit=' + CloseSubmit
			window.open(URL,'','width=700,height=425,scrollbars=yes,toolbars=no')
		}
		
		function SelectUsersWinOpen_Rep(checkbox, AddSubmit, CloseSubmit)
		{
			var URL = '../frmSelectUsersGeneral.aspx?Checkbox=' + checkbox + '&AddSubmit=' + AddSubmit + '&CloseSubmit=' + CloseSubmit +'&rep=1'
			window.open(URL,'','width=700,height=425,scrollbars=yes,toolbars=no')
		}
		
		function SelectUsersWinOpenAllowcation(checkbox, AddSubmit, CloseSubmit,isFlag)
		{
			var URL = '../frmSelectUsersGeneral.aspx?isFlag='+ isFlag + '&Checkbox=' + checkbox + '&AddSubmit=' + AddSubmit + '&CloseSubmit=' + CloseSubmit
			window.open(URL,'','width=760,height=425,scrollbars=yes,toolbars=no')
		}
		
		function SelectMultipleUsers(checkbox, AddSubmit, CloseSubmit, ctrlid)
		{
			var URL = '../frmSelectUsersGeneral.aspx?Checkbox=' + checkbox + '&AddSubmit=' + AddSubmit + '&CloseSubmit=' + CloseSubmit + '&name=yes' +  '&cntrlId='	+ ctrlid
			window.open(URL,'','width=700,height=425,scrollbars=yes,toolbars=no')
		}
		
		function GetSingleRole(cid, from)
		{
			var URL;
			if(from != "")
			{
				URL='../frmSelectUsersGeneral.aspx?Checkbox=no&ctrlid=' + cid + '&From=' + from;  
			}
			else
			{
				URL='../frmSelectUsersGeneral.aspx?Checkbox=no&ctrlid=' + cid;
			}
			//var URL = '../frmSelectUsersGeneral.aspx?Checkbox=no&ctrlid=' + cid;
			window.open(URL,'','width=700,height=550,scrollbars=yes,toolbars=no');
		}
		
		function GetSingleUser(cid,from)
		{
			//this is used for returning single user name in textbox
			var URL;
			if(from != "")
			{
				URL = '../frmSelectUsersGeneral.aspx?Checkbox=no&NameInTextBox=1&txtCtrlID=' + cid  + '&From=' + from; 
			}
			else
			{
				URL = '../frmSelectUsersGeneral.aspx?Checkbox=no&NameInTextBox=1&txtCtrlID=' + cid ;
			}
			//var URL = '../frmSelectUsersGeneral.aspx?Checkbox=no&NameInTextBox=1&txtCtrlID=' + cid ;
			window.open(URL,'','width=700,height=550,scrollbars=yes,toolbars=no');
		}
		
		
		/*to determine whether the checkboxes are checked, if checked it will confirm the deletion, just pass 
			the context specific record name  */
			
		function confirmSelect(str)
		{
			var i 
			
			for(i=0;i<document.forms(0).length;i++) 
			{ 
				if(document.forms(0).elements[i].type == "checkbox") 
				{ 
					if (document.forms(0).elements[i].checked == true) 
					{
						return confirm(GetMessage('S605',strPath));
					}
				} 
			}
			//alert('Select the ' + str + '(s) to delete');
			alert(GetMessage('W2551',strPath) + ' ' + str + ' ' + GetMessage('W2552',strPath))
			return false;
		}
		
		
		/*to determine whether the checkboxes are checked, if checked it will confirm the deletion, just pass 
			the context specific record name  */
		function Selectconfirm(strSucc,strFail)
		{
			var i 
			for(i=0;i<document.forms(0).length;i++) 
			{ 
				if(document.forms(0).elements[i].type == "checkbox") 
				{ 
					if (document.forms(0).elements[i].checked == true) 
					{
						return confirm(strSucc);
					}
				} 
			}
			alert(strFail);
			return false;
		}
		
			
		
		/*to set the focus to a control, just pass the name of the control*/
		function setfocus(controlname)
		{
			var str;
					
			str = 'document.forms(0).' + controlname + '.focus();' 
			eval(str);
		}
		
		
		
		
		
		
		
		
			
		
		/* 
		To check the selected check boxes in Tutors allocation page
		*/
		function Selectconfirmation(strSucc,strFail)
		{
		document.Form1.hidfromPopup.value='1';
		var objchk=	document.Form1.getElementsByTagName("input")
		var z
		var flag=false
		for(z=0;z<=objchk.length-1;z++)
		{
			if (objchk[z].type=="checkbox")
			{
				var chkname=objchk[z].name
				if (chkname.indexOf('subjChk')==-1)
				{
					if(objchk[z].checked)
					{
						flag=true
						break
					}
							
				}
			}
		}
		if(flag)
		{
			
			return confirm(strSucc);
			
		}
		else
		{
			alert(strFail)
			return false;
		}
		}		
		
		
		function setCookie(name, value, expire) {
		   document.cookie = name + "=" + escape(value)+ ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
		}
		function GetMessage(MsgID, strPath)
		{
			if (strPath.length == 0)
				return "Missing XML File Path"
			var ObjXML, objElement;
			xmlDoc_messageFile = new ActiveXObject("Msxml2.DOMDocument");
			if (xmlDoc_messageFile != null)
			{
				xmlDoc_messageFile.async="false"
				xmlDoc_messageFile.load(strPath)
				if (xmlDoc_messageFile.parseError == 0)
				{
					objElement = xmlDoc_messageFile.documentElement.selectSingleNode("//Message[@Id='" + MsgID + "']/@Description");
					return (objElement.text)
				}
				else
					return("Error: in Loading -> " + xmlDoc_messageFile.parseError.reason)
			}
			else
				return("Error: in Object Creation -> " + xmlDoc_messageFile.parseError.reason);
		}
function getCookie(Name) {
   var search = Name + "="
   if (document.cookie.length > 0) { // if there are any cookies
      offset = document.cookie.indexOf(search) 
      if (offset != -1) { // if cookie exists 
         offset += search.length 
         // set index of beginning of value
         end = document.cookie.indexOf(";", offset) 
         // set index of end of cookie value
         if (end == -1) 
            end = document.cookie.length
         return unescape(document.cookie.substring(offset, end))

      } 
   }
   
}

/*File Path validator*/

function filepath(path)
{
	var strlen,i,temp,flag;
	strlen=path.length;
   for(i=0;i<=strlen;i++)
    {  
		temp=path.charAt(i);
	    if( temp=='|')
	    {
			flag=1;
			break; 
		} 
	}
	 if(flag==1) return 2;	
}


