﻿/*viết cho phần tìm kiếm*/
function ddlTinhSelectChange(idTinh, ddlHuyen) {
    //var ddlHuyen = document.getElementById(ddl); alert(ddl);
    resetDdl(ddlHuyen); 
    if (!HttpRequest) return;
    if (idTinh < 1) return; 
    var url = "Modul/VungMien/getVungmienByGID.aspx?id=" + idTinh;
    HttpRequest.open("GET", url); 
    HttpRequest.onreadystatechange = function() {

        if (HttpRequest.readyState == 4 && HttpRequest.status == 200) {
            var xml = HttpRequest.responseXML;
            var c = xml.getElementsByTagName("vungmien");

            ddlHuyen.options.length = 0; //Xóa dữ liệu cũ

            for (i = 0; i < c.length; i++) {
                var value = c[i].firstChild.nodeValue;
                var id = c[i].attributes[0].value;
                ddlHuyen.options[i] = new Option(value, id);
            }

            ddlHuyen.disabled = false;
            ddlHuyen.focus();
        }
    }
    HttpRequest.send(null);
}
//an hien ddl
function resetDdl(ddl) {
    ddl.options.length = 0;
    ddl.disabled = 'disabled';
}
//kiem tra chi duoc nhap so
function checkNumber(e, id) {
    var alphaNumericCode = e.keyCode ? e.keyCode : e.charCode
    if ((alphaNumericCode <= 48 /*a*/ || alphaNumericCode >= 57) && (alphaNumericCode <= 95 || alphaNumericCode > 106) && (alphaNumericCode != 8) && (alphaNumericCode < 37 || alphaNumericCode > 40) && (alphaNumericCode != 46)) {
        alert("Chỉ được phép nhập số!!!");
        id.value = "";
    }
}
//xu ly cac su kien click cua loai giao dich
function caseId(id) {
    
    switch (id) {
        case 1: { document.getElementById("dCanban").className = "stSelectBg"; document.getElementById("dfCanban").className = "stSelectLeftConcert"; document.getElementById("drCanban").className = "stSelectRightConcert"; break; }
        case 2: { document.getElementById("dCanmua").className = "stSelectBg"; document.getElementById("dfCanmua").className = "stSelectLeftConcert"; document.getElementById("drCanmua").className = "stSelectRightConcert"; break; }
        case 3: { document.getElementById("dCanthue").className = "stSelectBg"; document.getElementById("dfCanthue").className = "stSelectLeftConcert"; document.getElementById("drCanthue").className = "stSelectRightConcert"; break; }
        case 4: { document.getElementById("dChothue").className = "stSelectBg"; document.getElementById("dfChothue").className = "stSelectLeftConcert"; document.getElementById("drChothue").className = "stSelectRightConcert"; break; }
        case 5: { document.getElementById("dThuemua").className = "stSelectBg"; document.getElementById("dfThuemua").className = "stSelectLeftConcert"; document.getElementById("drThuemua").className = "stSelectRightConcert"; break; }
    }
}
function clickGD(id) {
    var hTimkiem = document.getElementById("ctl00_hTimkiem");
    
    switch (hTimkiem.value) {
        case "1": { document.getElementById("dCanban").className = "stBg"; document.getElementById("dfCanban").className = "stLeftConcert"; document.getElementById("drCanban").className = "stRightConcert";  caseId(id); break; }
        case "2": { document.getElementById("dCanmua").className = "stBg"; document.getElementById("dfCanmua").className = "stLeftConcert"; document.getElementById("drCanmua").className = "stRightConcert"; caseId(id); break; }
        case "3": { document.getElementById("dCanthue").className = "stBg"; document.getElementById("dfCanthue").className = "stLeftConcert"; document.getElementById("drCanthue").className = "stRightConcert";  caseId(id); break; }
        case "4": { document.getElementById("dChothue").className = "stBg"; document.getElementById("dfChothue").className = "stLeftConcert"; document.getElementById("drChothue").className = "stRightConcert";  caseId(id); break; }
        case "5": { document.getElementById("dThuemua").className = "stBg"; document.getElementById("dfThuemua").className = "stLeftConcert"; document.getElementById("drThuemua").className = "stRightConcert";  caseId(id); break; }
    }
    hTimkiem.value = id;
}

 function delText(id) {
     id.focus();
     id.select();
 }
 function checkDate(e, id) {
     var alphaNumericCode = e.keyCode ? e.keyCode : e.charCode
     if ((alphaNumericCode < 48 /*a*/ || alphaNumericCode > 57) && (alphaNumericCode <= 95 || alphaNumericCode > 106) && (alphaNumericCode != 8/*z*/) && (alphaNumericCode != 111) && (alphaNumericCode != 191) && (alphaNumericCode < 37 || alphaNumericCode > 40) && (alphaNumericCode != 46)) {
         alert("Lỗi, Nhập: tháng/ngày/năm. Ex:12/31/2002" + alphaNumericCode);
         id.value = "";
     }
 }
 function validateDate(id) {
     var idate = id.value;
     var dmang = idate.split("/");
     if (dmang.length != 3) {
         if (idate != "") {
             alert("Lỗi, Nhập: tháng/ngày/năm. Ex:12/31/2002");
             id.value = "";
         }
     }
     else {
         var month = dmang[0];
         var day = dmang[1];
         var year = dmang[2];
         /* year is wrong if year = 0000 */
         if (year == 0) {
             alert("Năm phải lơn hơn 0");
             id.value = "";
         }
         /* Validation of month*/
         if ((month < 1) || (month > 12)) {
             alert("Tháng phải lơn hơn 0 và nhỏ hơn 12");
             id.value = "";
         }
         /* Validation of day*/
         if (day < 1) {
             alert("Ngày phải lơn hơn 0");
             id.value = "";
         }
         var lead = 0;
         /* Validation leap-year / february / day */
         if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
             leap = 1;
         }
         if ((month == 2) && (leap == 1) && (day > 29)) {
             alert("Tháng 2 năm này ngày không lớn hơn 29");
             id.value = "";
         }
         if ((month == 2) && (leap != 1) && (day > 28)) {
             alert("Tháng hai năm này ngày nhỏ hơn 28");
             id.value = "";
         }
         /* Validation of other months */
         if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
             alert("Ngày trong tháng này nhỏ hơn 31");
             id.value = "";
         }
         if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
             alert("Ngày tháng này nhỏ hơn 30");
             id.value = "";
         }
         /* if 00 ist entered, no error, deleting the entry */
         if ((day == 0) && (month == 0) && (year == 00)) {
             alert("Ngày tháng năm lớn hơn 0");
             id.value = "";
         }
     }
 }
 function ddlHuyenSelectChange(value,htm) {
     htm.value = value;
 }
