	
	function validEmail(email){
		invalidChars = " /:,;";
		
		if (email == ""){
			alert(email+" [ Invalid e-Mail Address ]");
			return false;
		}
		
		for (i=0; i<invalidChars.length; i++){
			badChar = invalidChars.charAt(i);
			if (email.indexOf(badChar,0) > -1){
				alert(email+" [ Invalid e-Mail Address ]");				
				return false;
			}
		}
		atPos = email.indexOf("@",1);
		if (atPos == -1){
			alert(email+" [ Invalid e-Mail Address ]");
			return false;
		}
		if (email.indexOf("@",atPos+1) > -1){
			alert(email+" [ Invalid e-Mail Address ]");
			return false;
		}
		periodPos = email.indexOf(".",atPos);
		if (periodPos+3 > email.length){
			alert(email+" [ Invalid e-Mail Address ]");
			return false;
		}
		return true;
	}
	
	
	//Function to create an XMLHttp Object.
	function getxmlhttp (){
		//Create a boolean variable to check for a valid microsoft active X instance.
		var xmlhttp = false;
		
		//Check if we are using internet explorer.
		try {
			//If the javascript version is greater than 5.
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			//If not, then use the older active x object.
			try {
				//If we are using internet explorer.
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				//Else we must be using a non-internet explorer browser.
				xmlhttp = false;
			}
		}
		
		//If we are using a non-internet explorer browser, create a javascript instance of the object.
		if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
			xmlhttp = new XMLHttpRequest();
		}
		
		return xmlhttp;
	}
	
	//Function to process an XMLHttpRequest.
	function processajax (obj){
		if(obj == "delItem"){
			if(confirm("Are you sure you want to delete this/these item(s)?")){	
				document.obj.submit();
				return true;
			}
			return false;
		}else{
			if(confirm("NB: \n Pls, are you sure that all input with red asteriks \n are correctly entered?")){
				document.obj.submit();
				return true;
			}
			return false;
		}
		return false;
	}
	
	//Function to process an XMLHttpRequest.
	
	function ajaxLoadMain(serverPage, obj,obj1,obj2){
		
		showLoadMsg ('Loading...',obj);
		document.getElementById(obj).style.visibility = "visible";
		
		xmlhttp = getxmlhttp();
		var url = serverPage+"?ID="+obj1+"&action="+obj2;
		//alert(url);
		xmlhttp.open("POST", url, true);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				document.getElementById(obj).innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
		
	}
	
	
	function ajaxLoadMainPagnate(serverPage, obj,obj1,obj2,obj3){
		
		showLoadMsg ('Loading...',obj);
		document.getElementById(obj).style.visibility = "visible";
		if(obj2 == 'delete'){
			if(confirm("Are you sure you want to delete this item(s)?")){
				xmlhttp = getxmlhttp();
				var url = serverPage+"?ID="+obj1+"&action="+obj2+"&page="+obj3;
				//alert(url);
				xmlhttp.open("POST", url, true);
				xmlhttp.onreadystatechange = function() {
					if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
						document.getElementById(obj).innerHTML = xmlhttp.responseText;
					}
				}
				xmlhttp.send(null);
			}else{
				xmlhttp = getxmlhttp();
				var url = serverPage+"?ID="+obj1+"&action=disp&page=1";
				//alert(url);
				xmlhttp.open("POST", url, true);
				xmlhttp.onreadystatechange = function() {
					if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
						document.getElementById(obj).innerHTML = xmlhttp.responseText;
					}
				}
				xmlhttp.send(null);
			}
		}else{
			xmlhttp = getxmlhttp();
			var url = serverPage+"?ID="+obj1+"&action="+obj2+"&page="+obj3;
			//alert(url);
			xmlhttp.open("POST", url, true);
			xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					document.getElementById(obj).innerHTML = xmlhttp.responseText;
				}
			}
			xmlhttp.send(null);
		}
		
	}
	
	function ajaxLoadMainAction(serverPage, obj,obj1,obj2){
		showLoadMsg ('Loading...',obj);
		document.getElementById(obj).style.visibility = "visible";
		if(obj2 == 'delete'){
			if(confirm("Are you sure you want to delete this item(s)?")){
				xmlhttp = getxmlhttp();
				var url = serverPage+"?ID="+obj1+"&action="+obj2;
				//alert(url);
				xmlhttp.open("POST", url, true);
				xmlhttp.onreadystatechange = function() {
					if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
						//alert(obj);
						document.getElementById(obj).innerHTML = xmlhttp.responseText;	
					}
				}
				xmlhttp.send(null);
			}else{
				ajaxLoadMain(serverPage, obj,obj1,'disp');
			}
		}
	}
	
	//Function to output a loading message.
	function showLoadMsg (msg,obj){
		//var addobj = '';
		document.getElementById(obj).innerHTML = '<img src="images/wait.gif" alt="Loading..." /> ' + msg;
	}

	function processajaxFORM (serverPage, obj, str, theform){
		showLoadMsg ('Loading...',obj);
		document.getElementById(obj).style.visibility = "visible";
		
		xmlhttp = getxmlhttp();
		xmlhttp.open("POST", serverPage, true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				document.getElementById(obj).innerHTML = xmlhttp.responseText;
				//ajaxLoadMain(serverPage, 'main','','disp');
			}
		}
		xmlhttp.send(str);
	}
	
	//function ajax search
	function processajaxSEARCH (serverPage, obj, str, theform){
		showLoadMsg ('Loading...',obj);
		document.getElementById(obj).style.visibility = "visible";
		
		xmlhttp = getxmlhttp();
		xmlhttp.open("POST", serverPage, true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				document.getElementById(obj).innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(str);
	}
	
	//Functions to submit a form.
	function getformvalues (fobj){
		
		var str = "";
				
		//Run through a list of all objects contained within the form.
		//alert(fobj);
		for(var i = 0; i < fobj.elements.length; i++){
			str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
		}
		//Then return the string values.
		return str;
	}
	
	function SetChecked(val,chkName, form) {
		dml=document.forms[form];
		len = dml.elements.length;
		var i=0;
		for( i=0 ; i<len ; i++) {
			if (dml.elements[i].type=='checkbox') {
				dml.elements[i].checked=val;
			}
		}
	}
	
	function go_there(){
	 var where_to= confirm("Do you really want to delete this message(s)");
		 if (where_to== true){
			document.form1.submit();
		 }
	}
	
	function dispModeTitle (title,obj){
		document.getElementById(obj).innerHTML = title;	
	}
	
	
	function shw(obj){
		if(document.getElementById(obj).style.display == 'none'){
			document.getElementById(obj).style.display = 'block';
		}else if(document.getElementById(obj).style.display == 'block'){
			document.getElementById(obj).style.display = 'none';
		}
	}
		
	
	function f_desc(obj){
		if(document.getElementById(obj)){ 		
          	document.getElementById(obj).src='../images/desc.png';
        }
	}
	
	function f_asc(obj){
		if(document.getElementById(obj)){ 
			document.getElementById(obj).src='../images/asc.png';
		}
	}
	
	function getNotice(id,disp){
		document.getElementById(id).innerHTML = "&nbsp; &raquo;&nbsp;"+disp;
	}
	
	function validateForm(){
		if(	document.regForm.surName.value == '' ||
			document.regForm.firstName.value == '' ||
			document.regForm.middleName.value == '' ||
			document.regForm.curr_lev.value == '' ||
			document.regForm.curr_class.value == '' ||
			document.regForm.st_sex.value == '' ||
			document.regForm.st_dob.value == '' ||
			document.regForm.m_status.value == '' ||
			document.regForm.Address.value == '' ||
			document.regForm.stState.value == '' ||
			document.regForm.language.value == '' ||
			document.regForm.sp_name.value == '' ||
			document.regForm.sp_relatn.value == '' ||
			document.regForm.sp_address.value == '' ||
			document.regForm.sp_phone.value == '' ||
			document.regForm.sp_occupatn.value == '' ||
			document.regForm.adm_academic_lev.value == '' ||
			document.regForm.adm_academic_class.value == '' ||
			document.regForm.date_adm.value == ''){
			alert("NB.\n All fields with red asteriks must be properly filled in.");
		}else if(confirm("Are you sure that you want to submit this form?")){
				processajaxFORM ('import.class/student.enroll.php', 'main', getformvalues(document.regForm),document.regForm);
				return false;
		}
	}
	
	function updateStudentAcadSession(){
		if(confirm("Do you want to UPDATE every ACTIVE student academic session \n to the current academic session?")){
			ajaxLoadMain('import.class/update.student.academic.session.php', 'main','','now');
		}else{
			alert("Updating cancelled");
		}
	}
	
	function loadLog(url){
		window.open(url,'_parent','','');	
	}
	
	// load moon shadow effect on object
	function display(id){
		var DivMain=document.getElementById(id)
		
		if (DivMain !=null)
		{
			DivMain.style.display="block";
		}
	}
	//hide the modal form
	function unDisplay(id){
		var DivMain=document.getElementById(id)
		
		if (DivMain !=null)
		{
			DivMain.style.display="none";
		}
	}
	
	var popUpWin=0;

	function popUpWindow(URLStr, left, top, width, height){
		if(popUpWin){
			if(!popUpWin.closed) popUpWin.close();
		}

  		popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	}
	
	function calTOTAL(id){
		var scoreA = 0;
		var scoreB = 0;
		var totSCore = 0;
			scoreA = parseInt(document.getElementById('scoreA'+id).value) * 1;
			scoreB = parseInt(document.getElementById('scoreB'+id).value) * 1;
			totSCore = scoreA + scoreB;
			//alert(isNaN(scoreB));
			
		if(isNaN(scoreB) && !isNaN(scoreA)){
			document.getElementById('totALL'+id).value = scoreA;
		}else if(isNaN(scoreA) && !isNaN(scoreB)){
			document.getElementById('totALL'+id).value = scoreB;
		}else{
			document.getElementById('totALL'+id).value = totSCore;
		}
	}


