﻿function checkDate(inputstr) {
    for (var i = 0; i < inputstr.length; i++) {
        var onechar = inputstr.charAt(i);
        if ((onechar < "0" || onechar > "9") && (onechar!="-")) {
            return false;
        }
    }

    if (inputstr.length != 10) {
        return false;
    }
    var v_yyyy = inputstr.substring(0,4);
    var v_mm = inputstr.substring(5,2);
    var v_dd = inputstr.substring(8,2);
    if (v_yyyy == null || v_yyyy == "") {
        return false;
    }
    if (v_yyyy == "0000") {
        return false;
    }
    if (v_mm < 1 || v_mm > 12) {
        return false;
    }
    if (v_mm == 4 || v_mm == 6 || v_mm == 9 || v_mm == 11) {
        if (v_dd < 1 || v_dd > 30) {
            return false;
        }
    }
    else if (v_mm == 2 ) {
        if ((v_yyyy % 400 == 0) || ((v_yyyy % 4 == 0) && (v_yyyy % 100 != 0))){
            if (v_dd < 1 || v_dd > 29) {
                return false;
            }
        }
        else {
            if (v_dd < 1 || v_dd > 28) {
                return false;
            }
        }
    }
    else {
        if (v_dd < 1 || v_dd > 31) {
            return false;
        }
    }
    return true;
}

function checkAll(){	
	var checks = document.getElementsByName('chon[]');
	for (i = 0; i < checks.length; i++)
		checks[i].checked = true ;	
}

function uncheckAll(field){
	var checks = document.getElementsByName('chon[]');
	for (i = 0; i < checks.length; i++)
		checks[i].checked = false ;	
}

function ktthemtv(){
	if (document.frmthemtv.tendn.value==""){
		alert("Bạn phải nhập tên đăng nhập cho thành viên mới");
		document.frmthemtv.tendn.focus();
		return false;
	}
	if (document.frmthemtv.matma.value==""){
		alert("Bạn chưa nhập mật mã");
		document.frmthemtv.matma.focus();
		return false;
	}
	if (document.frmthemtv.laplaimatma.value==""){
		alert("Xin vui lòng xác nhận lại mật mã");
		document.frmthemtv.laplaimatma.focus();
		return false;
	}
	if (document.frmthemtv.hoten.value==""){
		alert("Phải có họ tên cho thành viên mới");
		document.frmthemtv.hoten.focus();
		return false;
	}
	if (document.frmthemtv.laplaimatma.value != document.frmthemtv.matma.value){
		alert("Xác nhận mật mã chưa đúng");
		document.frmthemtv.laplaimatma.focus();
		return false;
	}	
}
function ktxoantv(){	
	return confirm("Bạn chắc chắn muốn xoá các thành viên được chọn?");
	
}
function xoacn(){	
	return confirm("Bạn chắc chắn muốn xoá chức năng này?");
	
}
function acnhomtin(){	
	return confirm("Bạn chắc chắn muốn xoá các nhóm đã nhọn?");
	
}
function acloaitin(){	
	return confirm("Bạn chắc chắn muốn xoá các loại tin đã nhọn?");
}
function ktdoimatmatv(){
	if (document.frmthemtv.matma.value==""){
		alert("Bạn chưa nhập mật mã");
		document.frmthemtv.matma.focus();
		return false;
	}
	if (document.frmthemtv.laplaimatma.value==""){
		alert("Xin vui lòng xác nhận lại mật mã");
		document.frmthemtv.laplaimatma.focus();
		return false;
	}
	if (document.frmthemtv.laplaimatma.value != document.frmthemtv.matma.value){
		alert("Xác nhận mật mã chưa đúng");
		document.frmthemtv.laplaimatma.focus();
		return false;
	}
	return true;
}
function kttencn(){	
	var checks = document.getElementsByName('tencn[]');
	for (i = 0; i < checks.length; i++)
		if (checks[i].value == ""){
			alert("Thông tin chưa đầy đủ.");
			checks[i].focus();
			return false;
		}
}
function ktthemcn(){	
	if (document.frmthemcn.macn.value == ""){
			alert("Chưa nhập mã chức năng.");
			document.frmthemcn.macn.focus();
			return false;
	}	
	if (document.frmthemcn.tencn.value == ""){
			alert("Chưa nhập tên chức năng.");
			document.frmthemcn.tencn.focus();
			return false;
	}
}
function ktnhomtin(){
	if (document.frmthemnhomtin.tennhom.value==""){
		alert("Bạn chưa nhập tên nhóm");
		document.frmthemnhomtin.tennhom.focus();
		return false;
	}
	if (document.frmthemnhomtin.tennhom_en.value==""){
		alert("Bạn chưa nhập tên nhóm bằng tiếng Anh");
		document.frmthemnhomtin.tennhom_en.focus();
		return false;
	}	
	
	return true;
}
function ktsuanhomtin(){
	if (document.frmsuanhomtin.tennhom.value==""){
		alert("Bạn chưa nhập tên nhóm");
		document.frmsuanhomtin.tennhom.focus();
		return false;
	}
	return true;
}
function ktthemloaitin(){
	if (document.frmthemloaitin.tenloai.value==""){
		alert("Bạn chưa nhập tên loại tin");
		document.frmthemloaitin.tenloai.focus();
		return false;
	}
	if (document.frmthemloaitin.tenloaien.value==""){
		alert("Bạn chưa nhập tên tiếng Anh cho loại tin");
		document.frmthemloaitin.tenloaien.focus();
		return false;
	}
	if (document.frmthemloaitin.thuocnhom.value==""){
		alert("Bạn phải chọn một nhóm cho loại này");
		document.frmthemloaitin.thuocnhom.focus();
		return false;
	}
	
	return true;
}
function ktdangtin(){
	if (document.frmdangtin.tieude.value==""){
		alert("Nhập tiêu đề cho tin mới");
		document.frmdangtin.tieude.focus();
		return false;
	}
	if (document.frmdangtin.manhom.value==""){
		alert("Chưa chọn nhóm cho mẫu tin");
		document.frmdangtin.manhom.focus();
		return false;
	}	
}
function acxoatin(){	
	return confirm("Bạn chắc chắn muốn xoá các mẫu tin này?");
}
function ktthemlink(){
	if (document.frmthemlink.tendn.value==""){
		alert("Chưa cho biết tên doanh nghiệp");		
		document.frmthemlink.tendn.focus();
		return false;
	}
	if ((document.frmthemlink.url.value=="") || (document.frmthemlink.url.value=="http://")){
		alert("Nhập URL cho site muốn trỏ tới");		
		document.frmthemlink.url.focus();
		return false;
	}
	if ((document.getElementById("filelogo").checked) && (document.frmthemlink.userfile.value==""))
	{
		alert("Click Browse để chọn một hình làm Logo");		
		document.frmthemlink.userfile.focus();
		return false;
	}else if ((document.getElementById("linklogo").checked) && ((document.frmthemlink.duongdan.value=="") || (document.frmthemlink.duongdan.value=="http://")))
	{
		alert("Nhập đường dẫn cho file logo");		
		document.frmthemlink.duongdan.focus();
		return false;
	}	
}
function ktthemlinksite(){
	if (document.frmthemlink.tendn.value==""){
		alert("Chưa cho biết tên doanh nghiệp");		
		document.frmthemlink.tendn.focus();
		return false;
	}
	if ((document.frmthemlink.url.value=="") || (document.frmthemlink.url.value=="http://")){
		alert("Nhập URL cho site muốn trỏ tới");		
		document.frmthemlink.url.focus();
		return false;
	}		
}
function ktcapnhatvb(){	
	var checks = document.getElementsByName('tenvb[]');
	for (i = 0; i < checks.length; i++)
		if (checks[i].value == ""){
			alert("Thông tin chưa đầy đủ.");
			checks[i].focus();
			return false;
		}
}
function checkMail()
{
	with(document.guitinnhan)
	{		

		if( hoten.value == "")
		{
			alert('Họ tên chưa được nhập.');
			hoten.focus();
			return false;
		}

		if( diachi.value == "")
		{
			alert('Địa chỉ trống.');
			diachi.focus();
			return false;
		}

		reg = /^\w+([\.-]?\w+)*@\w+(\.\w+){1,4}$/;
		if( reg.test(email.value) == false )
		{
			alert('Email không hợp lệ.');
			email.focus();
			return false;
		}

		if( tieude.value == "")
		{
			alert('Cần có một tiêu đề để gửi.');
			tieude.focus();
			return false;
		}

		if( noidung.value == "")
		{
			alert('Bắt buộc phải có nội dung.');
			noidung.focus();
			return false;
		}		

		return true;
	}
}
function kthocsinh(){	
	if (document.frmthemhocsinh.hs_mahs.value == ""){
		alert("Chưa nhập mã học sinh");
		document.frmthemhocsinh.hs_mahs.focus();
		return false;	
	}
	if (document.frmthemhocsinh.hs_hohs.value == ""){
		alert("Chưa nhập họ học sinh");
		document.frmthemhocsinh.hs_hohs.focus();
		return false;	
	}
	if (document.frmthemhocsinh.hs_tenhs.value == ""){
		alert("Chưa nhập tên học sinh");
		document.frmthemhocsinh.hs_tenhs.focus();
		return false;	
	}
	if(!checkDate(document.frmthemhocsinh.hs_ngaysinh.value)){
		alert("Ngày sinh không hợp lệ");
		document.frmthemhocsinh.hs_ngaysinh.focus();
		return false;	
	}
}
function ktxoahocsinh(){
	if(confirm("Khi bạn xóa học sinh này thì toàn bộ dữ liệu điểm của học sinh sẽ mất theo. Bạn chắc chắn muốn xóa?")){
		return confirm("Xác nhận lần cuối: bạn sẽ xóa các học sinh và điểm của các học sinh này?")
	}
}

function ktgiaovien(){	
	if (document.frmthemgiaovien.gv_magv.value == ""){
		alert("Chưa nhập mã giáo viên");
		document.frmthemgiaovien.gv_magv.focus();
		return false;	
	}
	if (document.frmthemgiaovien.gv_tengv.value == ""){
		alert("Chưa nhập tên giáo viên");
		document.frmthemgiaovien.gv_tengv.focus();
		return false;	
	}	
	if(!checkDate(document.frmthemgiaovien.gv_ngaysinh.value)){
		alert("Ngày sinh không hợp lệ");
		document.frmthemgiaovien.gv_ngaysinh.focus();
		return false;	
	}
}
function ktxoagiaovien(){
	return confirm("Bạn chắc chắn muốn xoá các giáo viên được chọn?");
}
function ktmonhoc(){
	var checks1 = document.getElementsByName('mamh[]');
	var checks2 = document.getElementsByName('tenmh[]');
	for (i = 0; i < checks1.length; i++)
	{
		if (checks1[i].value == ""){
			alert("Thông tin chưa đầy đủ.");
			checks1[i].focus();
			return false;
		}	
		if (checks2[i].value == ""){
			alert("Thông tin chưa đầy đủ.");
			checks2[i].focus();
			return false;
		}
	}
	if (document.frmMonHoc.newmamh.value != ""){		
		if (document.frmMonHoc.newtenmh.value == ""){
			alert("Chưa nhập tên môn học");
			document.frmMonHoc.newtenmh.focus();
			return false;	
		}	
	}
	if (document.frmMonHoc.newtenmh.value != ""){		
		if (document.frmMonHoc.newmamh.value == ""){
			alert("Chưa nhập mã môn học");
			document.frmMonHoc.newmamh.focus();
			return false;	
		}	
	}
}
function ktxoamonhoc(){
	if(confirm("Khi bạn xóa môn học này thì toàn bộ dữ liệu điểm của các học sinh học môn học này sẽ mất theo. Bạn chắc chắn muốn xóa?")){
		return confirm("Xác nhận lần cuối: bạn sẽ xóa môn học và điểm của các học sinh học môn này?")
	}
}

function ktchuyenban(){
	var checks1 = document.getElementsByName('macb[]');
	var checks2 = document.getElementsByName('tencb[]');
	for (i = 0; i < checks1.length; i++)
	{
		if (checks1[i].value == ""){
			alert("Thông tin chưa đầy đủ.");
			checks1[i].focus();
			return false;
		}	
		if (checks2[i].value == ""){
			alert("Thông tin chưa đầy đủ.");
			checks2[i].focus();
			return false;
		}
	}		
}
function ktdantoc(){
	var checks1 = document.getElementsByName('madt[]');
	var checks2 = document.getElementsByName('tendt[]');
	for (i = 0; i < checks1.length; i++)
	{
		if (checks1[i].value == ""){
			alert("Thông tin chưa đầy đủ.");
			checks1[i].focus();
			return false;
		}	
		if (checks2[i].value == ""){
			alert("Thông tin chưa đầy đủ.");
			checks2[i].focus();
			return false;
		}
	}		
}
function kthesochuyenban(){
	var checks = document.getElementsByName('heso[]');	
	for (i = 0; i < checks.length; i++)
	{
		if (checks[i].value == "" ||checks[i].value == '0'){
			alert("Hệ số môn học không thõa mãn");
			checks[i].focus();
			return false;
		}
	}		
}
function inputDiem(objform,objinput){	
	var checks = document.getElementsByName(objinput);
	for (i = 0; i < checks.length; i++)
	{
		if (checks[i] == "") 
		{
			return;
		}
		if(isNaN(checks[i].value) || (checks[i].value < 0)||(checks[i].value>10)){
			checks[i].value="";
			return;
		}
	}
}
function inputNgayNghi(objform,objinput){	
	var checks = document.getElementsByName(objinput);
	for (i = 0; i < checks.length; i++)
	{
		if (checks[i] == "") 
		{
			return;
		}
		if(isNaN(checks[i].value) || (checks[i].value < 0)||(checks[i].value>100)){
			checks[i].value="";
			return;
		}
	}
}
function ktxoamedia(){
	return confirm("Bạn chắc chắn muốn xoá các media được chọn?");
}
function ktmedia(){	
	if (document.frmmedia.media_name.value == ""){
		alert("Chưa nhập tên media");
		document.frmmedia.media_name.focus();
		return false;	
	}	
	if ((document.getElementById("file").checked) && (document.frmmedia.media_file.value==""))
	{
		alert("Click Browse để chọn file upload");		
		document.frmmedia.media_file.focus();
		return false;		
	}else if ((document.getElementById("file_link").checked) && ((document.frmmedia.media_link.value=="") || (document.frmmedia.media_link.value=="http://")))
	{
		alert("Nhập đường dẫn cho file video");		
		document.frmmedia.media_link.focus();
		return false;		
	}
	if((document.getElementById("file").checked) && ((document.frmmedia.media_file.value.lastIndexOf(".flv")==-1)&&(document.frmmedia.media_file.value.lastIndexOf(".mp3")==-1)))
	{
		alert("Bạn chỉ được upload file có đuôi .flv");
		return false;
	}
}
function ktthemtg(){
    
	if (document.frmthemtg.tentacgia.value==""){
		alert("Bạn chưa nhập tên tác giả");
		document.frmthemtg.tentacgia.focus();
		return false;
	}
		reg = /^\w+([\.-]?\w+)*@\w+(\.\w+){1,4}$/;
		if( reg.test(document.frmthemtg.email.value) == false )
		{
			alert('Email không hợp lệ.');
			document.frmthemtg.email.focus();
			return false;
		}
		
	return true;
}
function ktdangmucluc(){
	if (document.frmdangtin.tieude.value==""){
		alert("Nhập tiêu đề cho mục lục");
		document.frmdangtin.tieude.focus();
		return false;
	}
	if (document.frmdangtin.matin.value==""){
		alert("Chưa chọn tài liệu cho mục lục");
		document.frmdangtin.matin.focus();
		return false;
	}
        return true;
}
