// JavaScript Document

function trim(inputString) {
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") {
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") {
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   return retValue;
}
function checkLogin(tform){
	if (trim(tform.txtUsername.value) == ""){
		alert("Please Enter Your Username");
		tform.txtUsername.value = "";
		tform.txtUsername.focus();
		return false;
	}
	if (trim(tform.txtPassword.value) == ""){
		alert("Please Enter Your Password");
		tform.txtPassword.value = "";
		tform.txtPassword.focus();
		return false;
	}	
}
function checkLogin2(tform){
	if (trim(tform.BtxtUsername.value) == ""){
		alert("Please Enter Your Username");
		tform.BtxtUsername.value = "";
		tform.BtxtUsername.focus();
		return false;
	}
	if (trim(tform.BtxtPassword.value) == ""){
		alert("Please Enter Your Password");
		tform.BtxtPassword.value = "";
		tform.BtxtPassword.focus();
		return false;
	}	
}

function change_subject(level) {

		if(level > 3) {			
			//alert("show level2");
			document.getElementById("ass_subject1").style.display = "none";
			document.getElementById("ass_subject2").style.display = "";
		} else {
			//alert("show level1");
			document.getElementById("ass_subject1").style.display = "";
			document.getElementById("ass_subject2").style.display = "none";
		}

}

function change_grade(level) {

		if(level > 3) {			
			//alert("show level2");
			document.getElementById("level1").style.display = "none";
			document.getElementById("level2").style.display = "";
		} else {
			//alert("show level1");
			document.getElementById("level1").style.display = "";
			document.getElementById("level2").style.display = "none";
		}

}

function change_grade2(Blevel, BsID) {

		change_subject = new Ajax.Updater("Ssubjects","change_subjects.php", {method: 'post', postBody:
									"bLC_id="+Blevel+"&bS_id="+BsID, asynchronous:true, evalScripts:true,
									onLoading: function() { $("load_edit").style.display = "" }, 
									onComplete: function() { $("load_edit").style.display = "none" }
								});
	

}

function del_confirm(name, id) {
	var c = confirm( 'Are you sure you want to delete "'+name+'" records?' );
	if (c){ 
		window.location.href = 'delete_student.php?sid='+id;
	}
}

function del_record(name, tid, id) {
	var c = confirm( 'Are you sure you want to delete "'+name+'" records?\n*Note: This record will delete permanently to the database.' );
	if (c){ 
		window.location.href = 'delete_student.php?sid='+id+'&delper=1&tid='+tid;
	}
}

function change_record(name, status, tid, id) {
	var c = confirm( 'Are you sure you want to set "'+name+'" as '+status+' student?' );
	if (c){ 
		window.location.href = 'change_student.php?sid='+id+'&status='+status+'&tid='+tid;
	}
}

function showtransfer_div(status,id) {
	var divtrans = $("div"+status+"_"+id);
	if(divtrans.style.display == "none") {		
		divtrans.style.display = ""; 
	} else {
		divtrans.style.display = "none";	
	}
}

function del_record2(name, tid, id) {
	var c = confirm( 'Are you sure you want to delete "'+name+'" records?\n*Note: This record will delete permanently to the database.' );
	if (c){ 
		window.location.href = 'user_delete_student.php?sid='+id+'&delper=1&tid='+tid;
	}
}

function del_faculty(name, pid, id) {
	var c = confirm( 'Are you sure you want to delete "'+name+'" records?\n*Note: This record will delete permanently to the database.' );
	if (c){ 
		window.location.href = 'del_update_list.php?delf=1&pageadmin='+pid+'&fid='+id;
	}
}

function change_record2(name, status, tid, id) {
	var c = confirm( 'Are you sure you want to set "'+name+'" as '+status+' student?' );
	if (c){ 
		window.location.href = 'user_change_student.php?sid='+id+'&status='+status+'&tid='+tid;
	}
}

function change_record3(name, status, id) {
	var c = confirm( 'Are you sure you want to set "'+name+'" as '+status+' student?' );
	if (c){ 
		window.location.href = 'change_student.php?cid='+id+'&status='+status;
	}
}

function edit_staff(staff_id,mode) {
		
	if(mode == 2) {		
		$("add").style.display = "none";
		$("edit").style.display = "";
	} else {
		$("add").style.display = "";
		$("edit").style.display = "none";	
	}	
	faculty_edit = new Ajax.Updater("edit_table","edit_staff.php", {method: 'post', postBody:
									"fid="+staff_id+"&mode="+mode, asynchronous:true, evalScripts:true,
									onLoading: function() { $("load_edit").style.display = "" }, 
									onComplete: function() { $("load_edit").style.display = "none" }
								});
	
}

function load_updates(div_id,updates_id,url,u_mode) {
	
	updates = new Ajax.Updater(div_id,url+".php", {method: 'post', postBody:
									"upid="+updates_id+"&umode="+u_mode, asynchronous:true, evalScripts:true,
									onLoading: function() { if($("load_list"+u_mode) != null) $("load_list"+u_mode).style.display = "" }, 
									onComplete: function() { if($("load_list"+u_mode) != null) $("load_list"+u_mode).style.display = "none" }
								});
	
}

function filter_cal(div_id,url,mode_id) {
	
	/*if($("Lmonth") != null) {
		var m = $F("Lmonth");
	
		if(m<=9) var zro = 0; else var zro = '';
		m = zro+''+m;
		var y = $F("Lyear");*/
		filter = new Ajax.Updater(div_id, url+".php", {method: 'post', postBody:
										//"Lmonth="+m+"&Lyear="+y+"&umode="+mode_id, asynchronous:true, evalScripts:false,
										"umode="+mode_id, asynchronous:true, evalScripts:false,
										onLoading: function() { $("load_list").style.display = "" }, 
										onComplete: function() { $("load_list").style.display = "none" }
									});
	//}
	
}

function filter_cal2(div_id2,url2,mode_id2) {
	
	var m2 = $F("Lmonth2");

	if(m2<=9) var zro2 = 0; else var zro2 = '';
	m2 = zro2+''+m2;
	var y2 = $F("Lyear2");
	filter2 = new Ajax.Updater(div_id2, url2+".php", {method: 'post', postBody:
									"Lmonth2="+m2+"&Lyear2="+y2+"&umode="+mode_id2, asynchronous:true, evalScripts:false,
									onLoading: function() { $("load_list2").style.display = "" }, 
									onComplete: function() { $("load_list2").style.display = "none" }
								});
	
}

function filter_cal3(div_id3,url3,mode_id3) {
	
	var m3 = $F("Lmonth3");
	//var cat = $F("ass_category");
	//var level = $F("ass_level");
	if(m3<=9) var zro3 = 0; else var zro3 = '';
	m3 = zro3+''+m3;
	var y3 = $F("Lyear3");
	filter3 = new Ajax.Updater(div_id3, url3+".php", {method: 'post', postBody:
									"Lmonth3="+m3+"&Lyear3="+y3+"&umode="+mode_id3, asynchronous:true, evalScripts:false,
									onLoading: function() { $("load_list3").style.display = "" }, 
									onComplete: function() { $("load_list3").style.display = "none" }
								});
	
}

function filter_assign() {
	
	//var m3 = $F("Lmonth3");
	//var y3 = $F("Lyear3");
	//var cate = $F("ass_category");
	//var leve = $F("ass_level");
	
	filter3 = new Ajax.Updater("main_assign", "update_list.php", {method: 'post', postBody:
									//"umode=3&Lmonth3="+m3+"&Lyear3="+y3, asynchronous:true, evalScripts:false,
									"umode=3", asynchronous:true, evalScripts:false,
									onLoading: function() { $("load_list3").style.display = "" }, 
									onComplete: function() { $("load_list3").style.display = "none" }
								});
	
}

function pop_image(galid, gall_album) {
	//alert(url+"sdsdf");
	newwindow=window.open('slideshow.php?galid='+galid+'&gall_al='+gall_album,'name','height=600,width=800,scrollbars=yes,resizable=yes');
	if (window.focus) {newwindow.focus()}
	return false;
}

function blinkIt() {
 if (!document.all) return;
 else {
   for(i=0;i<document.all.tags('blink').length;i++){
      s=document.all.tags('blink')[i];
      s.style.visibility=(s.style.visibility=='visible')?'hidden':'visible';
   }
 }
}

function show_hide(table_id) {
	var objTable = $(table_id);
	var objImg = $("img_"+table_id);
	if(objTable.style.display == "none") {		
		objTable.style.display = ""; 
		objImg.src = "../images/minus.jpg";
	} else {
		objTable.style.display = "none";	
		objImg.src = "../images/plus.jpg";
	}	
}

function popup(url,sid) 
{
 var width  = 600;
 var height = 600;
 var left   = (screen.width  - width)/2;
 var top    = (screen.height - height)/2;
 var params = 'width='+width+', height='+height;
 params += ', top='+top+', left='+left;
 params += ', directories=no';
 params += ', location=no';
 params += ', menubar=no';
 params += ', resizable=no';
 params += ', scrollbars=yes';
 params += ', status=no';
 params += ', toolbar=no';
 newwin=window.open(url,'windowname'+sid, params);
 if (window.focus) {newwin.focus()}
 return false;
}

