function submitForm()
{	
	
	if(trimSpace($('#txtMahocsinh').val())=="" )
	{
		alert("Vui long nhap Ma Hoc Sinh!");
		$('#txtMahocsinh').focus();
		return false;
	}
	if(trimSpace($('#txtPassword').val())=="")
	{
		alert("Vui long nhap Mat Khau!");
		$('#txtPassword').focus();
		return false;
	}
	return true;
}

function checkRequired()
{	
	
	if(trimSpace($('#txtName').val())=="" )
	{
		alert("Vui long nhap Ho Ten!");
		$('#txtName').focus();
		return false;
	}
	if(trimSpace($('#drpClass').val())=="" )
	{
		alert("Vui long chon Ten Lop!");
		$('#drpClass').focus();
		return false;
	}
	if(trimSpace($('#txtForgotMahocsinh').val())=="")
	{
		alert("Vui long nhap Ma Hoc Sinh!");
		$('#txtForgotMahocsinh').focus();
		return false;
	}
	return true;
}
function checkSend()
{	
	
	if(trimSpace($('#txtCurrentPass').val())=="" )
	{
		alert("Vui long nhap Mat khau hien tai!");
		$('#txtCurrentPass').focus();
		return false;
	}
	if(trimSpace($('#txtNewpass').val())=="" )
	{
		alert("Vui long nhap Mat khau moi!");
		$('#txtNewpass').focus();
		return false;
	}
	if(trimSpace($('#txtConfirmpass').val())=="")
	{
		alert("Vui long xac nhan lai Mat khau moi!");
		$('#txtConfirmpass').focus();
		return false;
	}
	if(trimSpace($('#txtConfirmpass').val()) != trimSpace($('#txtNewpass').val()))
	{
		alert("Mat khau xac nhan lai khong hop le!");
		$('#txtConfirmpass').focus();
		return false;
	}
	return true;
}
function checkView()
{	
	
	if(trimSpace($('#drpNamHoc').val())=="" )
	{
		alert("Vui long chon nam hoc!");
		$('#drpNamHoc').focus();
		return false;
	}
	if(trimSpace($('#drpHocky').val())=="" )
	{
		alert("Vui long chon hoc ky!");
		$('#drpHocky').focus();
		return false;
	}
	return true;
}
function checkgetCode()
{	
	
	if(trimSpace($('#txtName_').val())=="" )
	{
		alert("Vui long nhap Ho Ten!");
		$('#txtName_').focus();
		return false;
	}
	if(trimSpace($('#drpClass_').val())=="" )
	{
		alert("Vui long chon Ten Lop!");
		$('#drpClass_').focus();
		return false;
	}
	return true;
}



function Login()
{		
	catid = $('#hidCatid').val() ;
	if(submitForm())
	{
		$.ajax({			   	
				type:"POST",
				url: "./modules/resultmark/login.asp",
				data:{
					'mahocsinh':$('#txtMahocsinh').val(),
					'password':$('#txtPassword').val()
				},
				success:function(data) {
					$error = data;	
					if ( $error == "OK" ) {
						window.location="?catid=" + catid ;
					} else {
						alert('Ma hoc sinh hoac Mat khau khong hop le \n Vui long kiem tra lai!') ;
					}
				},
				error:function() {
					alert('May chu qua tai \n Vui long thu lai sau!');
				}
		});
	}
}
function Logout()
{		
	catid = $('#hidCatid').val() ;
	$.ajax({			   	
	type:"POST",
	url: "./modules/resultmark/logout.asp",
	data:{'catid':catid},
	success:function() {
		window.location="?catid=" + catid ;
		},
	error:function() {
		}
	});
}
function showForm()
{		
	$('#showForm').attr('style', 'display:');
	$('#showMaHocSinh').attr('style', 'display:none');
	
}
function closeForm()
{		
	$('#showForm').attr('style', 'display:none');	
}

function showMaHocSinh()
{		
	$('#showMaHocSinh').attr('style', 'display:');
	$('#showForm').attr('style', 'display:none');	
	
}
function closeFormMahocsinh()
{		
	$('#showMaHocSinh').attr('style', 'display:none');	
}



function sendRequired()
{		
	catid = $('#hidCatid').val() ;
	if(checkRequired())
	{
		$.ajax({			   	
				type:"POST",
				url: "./modules/resultmark/forgotpass.asp",
				data:{
					'mahocsinh':$('#txtForgotMahocsinh').val(),
					'classid':$('#drpClass').val(),
					'name':$('#txtName').val()
				},
				success:function(data) {
					$error = data;	
					if ( $error == "OK" ) {
						$('#showForm').html('');
						$('#showResult').html("<table cellpadding='2' cellspacing='2' width='100%'><tr><td><hr></td></tr><tr><td align=center><font color='#E9645B'>Thông tin đã được gởi ! <br> Hệ thống sẽ thiết lập lại mật khẩu trong thời gian sớm nhất<br>[ <a href='?catid=56'>Trở lại </a> ] </font></td></tr></table>");
						
					} else {
						alert('Du lieu nhap vao khong phu hop \n Vui long kiem tra lai!') ;
					}
				},
				error:function() {
					alert('May chu qua tai \n Vui long thu lai sau!');
				}
		});
		
		
	}
}
function changePass()
{		
	catid = $('#hidCatid').val() ;
	if(checkSend())
	{
		$.ajax({			   	
				type:"POST",
				url: "./modules/resultmark/changepass.asp",
				data:{
					'password':$('#txtCurrentPass').val(),
					'newPasswords':$('#txtNewpass').val()
				},
				success:function(data) {
					$error = data;
					switch ($error){
						case "ErrorCurrentpass":		
							alert("Mat khau hien tai khong dung \n Vui long kiem tra lai!")
							$('#txtCurrentPass').focus();
							break;
						case "OK":			
							$('#showForm').html('');
							$('#showResult').html("<table cellpadding='5' bgcolor='#fffffF' cellspacing='5' width='100%'><tr><td align=center>Mật khẩu đã được thay đổi thành công<br>[ <a href='?catid=56'> Trở lại </a> ]</td></tr></table>");
							break;
						}
					
				},
				error:function() {
					alert('May chu qua tai \n Vui long thu lai sau!');
				}
		});
		
		
	}
}
function Viewmark()
{		
	if(checkView())
	{
		$.ajax({			   	
				type:"POST",
				url: "./modules/resultmark/resultview.asp",
				data:{
					'subjectid':$('#drpHocky').val(),
					'yearid':$('#drpNamHoc').val()
				},
				success:function(data) {
					$('#formResult').html("<center><img src='./interface/loading.gif' border=0 > <br><strong>Đang tải dữ liệu vui lòng chờ...</strong></center>");
					$('#formResult').html(data);					
				},
				error:function() {
					alert('Error!');
				}
		});
		
		
	}
}

function getCode()
{		
	catid = $('#hidCatid').val() ;
	if(checkgetCode())
	{
		$.ajax({			   	
				type:"POST",
				url: "./modules/resultmark/forgotcode.asp",
				data:{					
					'classid':$('#drpClass_').val(),
					'name':$('#txtName_').val()
				},
				success:function(data) {					
					var mahocsinh =	document.getElementById("txtForgotMahocsinh_")
					
					mahocsinh.value = data ;
				},
				error:function() {
					alert('May chu qua tai \n Vui long thu lai sau!');
				}
		});
		
		
	}
}






