﻿// ------------------------------------------------------------------------- //
// JavaScript Function Library for Thanh Nien Online Newspaper               //
// Written by: VanHNN <vanhnn@hcm.fpt.vn>                                    //
// ------------------------------------------------------------------------- //

var clockID = 0;
var DayInWeek=new Array("Chủ Nhật","Thứ Hai","Thứ Ba","Thứ Tư","Thứ Năm","Thứ Sáu","Thứ Bảy");
var SangTruaChieu="";
var tDate = "";
var tHour="";
var tMinute="";
var tSecond="";

function UpdateClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
	
	tDate.setSeconds(tDate.getSeconds()+1);
	tNgay=tDate.getDate();
	if (tNgay<10) tNgay="0"+tNgay;
	tThang=tDate.getMonth()+1;
	if (tThang<10) tThang="0"+tThang;
	
	tHour=tDate.getHours();
	if (tHour<10) tHour="0"+tHour;
	tMinute=tDate.getMinutes();
	if (tMinute<10) tMinute="0"+tMinute;
	tSecond=tDate.getSeconds();
	if (tSecond<10) tSecond="0"+tSecond;

	if (tHour<4) SangTruaChieu="rạng sáng";
	else if (tHour<10) SangTruaChieu="sáng";
	else if (tHour<15) SangTruaChieu="trưa";
	else if (tHour<18) SangTruaChieu="chiều";
	else if (tHour<22) SangTruaChieu="tối";
	else  SangTruaChieu="khuya";
	
   document.getElementById("ThoiGian").innerHTML="" ;
   document.getElementById("ThoiGian").innerHTML="Việt nam bây giờ là " 
   		+tHour + ":" + tMinute + ":" + tSecond +" " +SangTruaChieu 
   		+" "+ DayInWeek[tDate.getDay()] +" "+ tNgay + "/"  +tThang +"/"+tDate.getFullYear() ;

	clockID = setTimeout("UpdateClock()", 1000);
}

function StartClock(s) {
	tDate=new Date(s);
	clockID = setTimeout("UpdateClock()", 500);
}

function KillClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
}


function displayDate(dDate) {
	var today;
	if (dDate)
		today = new Date(dDate);
	else
		today = new Date(); 
//var mmm = 
//    ( 1==m)?'Jan':( 2==m)?'Feb':(3==m)?'Mar':
//    ( 4==m)?'Apr':( 5==m)?'May':(6==m)?'Jun':
//    ( 7==m)?'Jul':( 8==m)?'Aug':(9==m)?'Sep':
//    (10==m)?'Oct':(11==m)?'Nov':'Dec';

	var dow = new Array('Chủ Nhật', 'Thứ Hai', 'Thứ Ba', 'Thứ Tư', 'Thứ Năm', 'Thứ Sáu', 'Thứ Bảy');
	var months = new Array('01','02','03','04','05','06','07','08','09','10','11','12');
	var year = today.getNam();
	year = (year <= 1888) ? (1900 + year) : year;
//	document.write(dow[today.getNgay()] + ' ngày ' + today.getDate() + ' tháng ' + months[today.getThang()] + ' năm ' + year );
	document.write(MsgDateTime);
}

function OpenWindow(list) {
newWindow = window.open(list.options[list.selectedIndex].value, 'NewWindow', 'width='+screen.width+',height='+screen.height+',top=0,left=0,toolbar,location,status,menubar,scrollbars,resizable');
//  location.href = list.options[list.selectedIndex].value  --> Mo window tai cho
}

function OpenWindowJPG(JPGFile) {
newWindow = window.open(JPGFile, 'JPGWindow', 'width='+screen.width+',height='+screen.height+',top=0,left=0');
//  location.href = list.options[list.selectedIndex].value  --> Mo window tai cho
}

