﻿// JScript File    
var timer;
var dday = new Date();

function fetch_object(idname)
{
	if (document.getElementById)
	{
		return document.getElementById(idname);
	}
	else if (document.all)
	{
		return document.all[idname];
	}
	else if (document.layers)
	{
		return document.layers[idname];
	}
	else
	{
		return null;
	}
}
    
function Hide_panel(obj1,obj2,obj3)
{
    if(obj1 != null && obj2 != null && obj3 != null)
    {
    	document.getElementById(obj1).style.display = "";
   	 	document.getElementById(obj2).style.display = "none";
   		document.getElementById(obj3).style.display = "";

    }
} 

function Show_panel(obj1,obj2,obj3)
{
   if(obj1 != null && obj2 != null && obj3 != null)
    {
         document.getElementById(obj1).style.display = "none";
         document.getElementById(obj3).style.display = "none";
         document.getElementById(obj2).style.display = "";
    }
}

function initToday(idate, imonth, iyear, ihour, iminute, isecond)
{
    initDate(idate, imonth, iyear);
    initTime(ihour, iminute, isecond);
    show_date();
}

function initDate(idate, imonth, iyear)
{
    dday.setFullYear(iyear,imonth,idate);
}

function initTime(ihour, iminute, isecond)
{
    dday.setHours(ihour);
    dday.setMinutes(iminute);
    dday.setSeconds(isecond);
}

function get_Day()
{
    dday = new Date();
    switch(dday.getDay()){
        case 0: return "Chủ nhật";
        case 1: return "Thứ hai";
        case 2: return "Thứ ba";
        case 3: return "Thứ tư";
        case 4: return "Thứ năm";
        case 5: return "Thứ sáu";
        case 6: return "Thứ bảy";
    }
}

function get_Date()
{   
    dday = new Date();
    var strDate = "";
    var date_today = dday.getDate();
    var month_today = dday.getMonth()+1;
    var year_today = dday.getFullYear();
    if(date_today < 10){
        date_today = "0" + date_today;
    }
    if(month_today < 10){
        month_today = "0" + month_today;
    }
    strDate = date_today + "/" + month_today + "/" + year_today;
    return strDate;
}

function get_Time()
{
    var time = "";
    var hour_today = dday.getHours();
    var minute_today = dday.getMinutes();
    var second_today = dday.getSeconds();
    if(hour_today < 10){
        hour_today = "0" + hour_today;
    }
    if(minute_today < 10){
        minute_today = "0" + minute_today;
    }
    if(second_today < 10){
        second_today = "0" + second_today;
    }
    time = hour_today + ":" + minute_today + ":" + second_today;
    return time;
}

function checkDate(iDate)
{
    var iMonth = dday.getMonth();
    var iYear = dday.getFullYear();
    
    // Tang ngay
    if(iMonth == 4 || iMonth == 6 || iMonth == 9 || iMonth == 11)
    {
        if(iDate > 30)
        {
            iDate = 1;
            iMonth = iMonth + 1;
            
        }
    }else if (iMonth == 2)
    {
        if(iYear % 4 == 0 || iYear % 100 == 0)
        {
            if(iDate > 29)
            {
                iDate = 1;
                iMonth = iMonth + 1;
            }
        }
        else
        {
            if(iDate > 1)
            {
                iDate = 28;
                iMonth = iMonth + 1;
            }
        }
    }
    else
    {
        if(iDate > 31)
        {
            iDate = 1;
            iMonth = iMonth + 1;
        }
    }
    
    // Tang thang
    if(iMonth > 12)
    {
        iMonth = iMonth + 1;
        iYear = iYear + 1;
    }
    initDate(iDate,iMonth,iYear);
}

function runTime()
{
    var sc = dday.getSeconds();
    var mn = dday.getMinutes();
    var hr = dday.getHours();
    var dt = dday.getDate();
    var mt = dday.getMonth();
    var yr = dday.getFullYear();
    sc = sc + 1;
    if(sc > 60)
    {
        sc = 0;
        mn = mn + 1;
    }
    if(mn > 60)
    {
        mn = 0;
        hr = hr + 1;
    }
    if(hr > 24)
    {
        hr = 0;
        dt = dt + 1;
    }
    checkDate(dt);
    initTime(hr,mn,sc);
}

function show_date()
{
    var labelDate = fetch_object("txtDate");
    var strDay = "";
    strDay = get_Day();
    strDay = strDay + ", " + get_Date() + " " + get_Time() + " GMT+7";
    labelDate.value = strDay;
    runTime();
    timer = setTimeout("show_date()",1000);
}

function checkAllCheckBox(idAll, idCheckboxs)
{
    var ckAll = fetch_object(idAll);
    var arrID = new Array();
    arrID = idCheckboxs.split(',');
    
    var bool = ckAll.checked;
    
    for(i = 0; i < arrID.length; i++)
    {
        var ckItem = fetch_object(arrID[i]);
        ckItem.checked = bool;
    }
}


