﻿// JScript File
function _page_init(){
    _showTime();
    for (var i=0; i<advCount; i++){
       AdvObjectList[i].init(); 
    }
    if (typeof(_local_init)=="function"){
        _local_init();
    }
}
var daynames = ["Chủ nhật", "Thứ hai", "Thứ ba", "Thứ tư", "Thứ năm", "Thứ sáu", "Thứ bảy"];
function _showTime(){
    d = new Date();
    document.getElementById("statusBar").innerHTML = daynames[d.getDay()]+", "+zeroLead(d.getDate(), 2)+"/"+zeroLead(d.getMonth()+1, 2)+"/"+d.getFullYear()+", "+zeroLead(d.getHours(), 2)+":"+zeroLead(d.getMinutes(), 2);
    setTimeout("_showTime()", 60000);
}
var advCount = 0;
var AdvObjectList = new Array();
function AdvObject(id){
    this.idx = advCount;
    advCount++;
    this.len = 0;
    this.id = id;
    this.off = 0;
    this.theImages = new Array();
    this.theLinks = new Array();
    this.theTitles = new Array();
    this.len = 0;
    this.theLinkObj = null;
    this.theImageObj = null;
    this.init = _init;
    this.show = _show;
    this.add = _add;
}

function _init(){
    this.len = this.theImages.length;
    this.theLinkObj = document.getElementById("theAdLink"+this.id);
    this.theImageObj = document.getElementById("theAdImage"+this.id);
    this.show();
}
function _show(){
    if (this.off<this.len){
        this.theLinkObj.setAttribute("href", this.theLinks[this.off]);
        this.theLinkObj.setAttribute("title", this.theTitles[this.off]);
        this.theImageObj.src = this.theImages[this.off];
        this.theImageObj.alt = this.theTitles[this.off];
        if (this.len>1) setTimeout("replay("+this.idx+")", 3000);
        this.off++;
        if (this.off==this.len) this.off=0;
    }
}
function _add(img, link, title){
    this.theImages[this.len] = img;
    this.theLinks[this.len] = link;
    this.theTitles[this.len] = title;
    this.len++;
}
function replay(idx){
    AdvObjectList[idx].show();
}
window.onload = _page_init;