﻿/*------------------------------------------------------
    Change Image Source
------------------------------------------------------*/
function ChangeImgSrc(imgObj, strSrc)
{
    imgObj.src = strSrc;
}

/*------------------------------------------------------
    Get Query String																							
------------------------------------------------------*/
function GetQueryString(strKey,strDefault)
{
    // get the query string, ignore the ? at the front.
	var querystring=location.search.substring(1,location.search.length);

    // parse out name/value pairs separated via &
	var args = querystring.split('&');

    // split out each name = value pair
	for (var i=0;i<args.length;i++)
	{
		var pair = args[i].split('=');

		// Fix broken unescaping
		temp = unescape(pair[0]).split('+');
		name = temp.join(' ');

		temp = unescape(pair[1]).split('+');
		value = temp.join(' ');
        
        if(name == strKey)
        {
            return value;
        }		
	}
    
    return strDefault;
}

function updateClock() {
    var currentTime = new Date();
    var currentHours = currentTime.getHours();
    var currentMinutes = currentTime.getMinutes();
    var currentSeconds = currentTime.getSeconds();

    // Pad the minutes and seconds with leading zeros, if required
    currentMinutes = (currentMinutes < 10 ? "0" : "") + currentMinutes;
    currentSeconds = (currentSeconds < 10 ? "0" : "") + currentSeconds;

    // Choose either "AM" or "PM" as appropriate
    var timeOfDay = (currentHours < 12) ? "AM" : "PM";

    // Convert the hours component to 12-hour format if needed
    currentHours = (currentHours > 12) ? currentHours - 12 : currentHours;

    // Convert an hours component of "0" to "12"
    currentHours = (currentHours == 0) ? 12 : currentHours;

    // Compose the string for display
    //var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;
    var currentTimeString = currentHours + ":" + currentMinutes + " GMT+7 ";
    // Update the time display
    document.getElementById("clock").firstChild.nodeValue = currentTimeString;
}

function WriteCurrentDate() {
    d = new Array("Chủ Nhật", "Thứ Hai", "Thứ Ba", "Thứ Tư", "Thứ Năm", "Thứ Sáu", "Thứ Bảy");
    m = new Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");

    today = new Date();
    day = today.getDate();
    year = today.getYear();

    if (year < 2000)    // Y2K Fix, Isaac Powell
        year = year + 1900; // http://onyx.idbsu.edu/~ipowell

    end = "";
    if (day == 1 || day == 21 || day == 31) end = " ";
    if (day == 2 || day == 22) end = " ";
    if (day == 3 || day == 23) end = " ";
    day += end;
    
    document.write(d[today.getDay()]);
    document.write(", ");
    document.write(day + "." + m[today.getMonth()]);
    document.write("." + year);
    document.write("");
}

function metis_init_frame() {
    url_array = window.location.href.split('#');
    hash_param = '';
    if (url_array[1] != null) {
        hash_param = url_array[1];
    }

    iframe = document.getElementById('metis_iframe');
    if (iframe) {
        iframe_src = 'http://www.metis.vn/export_content/main/' + hash_param;
        document.getElementById('metis_iframe').src = iframe_src;
    }
}


//============================
function SearchOnFocus(field) {
    if (field.value == 'Từ khóa tìm kiếm') { field.value = ''; }
}

function SearchOnBlur(field) {
    if (field.value == '') { field.value = 'Từ khóa tìm kiếm'; }
}

function NameOnFocus(field) {
    if (field.value == 'Họ tên') { field.value = ''; field.className = 'adword-textbox2' }
}

function NameOnBlur(field) {
    if (field.value == '') { field.value = 'Họ tên'; field.className = 'adword-textbox' }
}

function EmailOnFocus(field) {
    if (field.value == 'Email') { field.value = ''; field.className = 'adword-textbox2' }
}

function EmailOnBlur(field) {
    if (field.value == '') { field.value = 'Email'; field.className = 'adword-textbox' }
}

//=============================
function showDialog(url, width, height) {
    return showWindow(url, false, false, false, false, false, false, true, true, width, height, 0, 0);
}

function showWindow(url, isStatus, isResizeable, isScrollbars, isToolbar, isLocation, isFullscreen, isTitlebar, isCentered, width, height, top, left) {
    if (isCentered) {
        top = (screen.height - height) / 2;
        left = (screen.width - width) / 2;
    }

    open(url, '_blank', 'status=' + (isStatus ? 'yes' : 'no') + ','
	+ 'resizable=' + (isResizeable ? 'yes' : 'no') + ','
	+ 'scrollbars=' + (isScrollbars ? 'yes' : 'no') + ','
	+ 'toolbar=' + (isToolbar ? 'yes' : 'no') + ','
	+ 'location=' + (isLocation ? 'yes' : 'no') + ','
	+ 'fullscreen=' + (isFullscreen ? 'yes' : 'no') + ','
	+ 'titlebar=' + (isTitlebar ? 'yes' : 'no') + ','
	+ 'height=' + height + ',' + 'width=' + width + ','
	+ 'top=' + top + ',' + 'left=' + left);
}

function displayInfo(info) {
    if (info == 'weather')
        showWindow('http://sgtt.vn/Page/Weather.aspx', false, false, false, false, false, false, true, true, 550, 550, 0, 0);
    if (info == 'forex')
        showWindow('http://sgtt.vn/Page/TyGia.htm', false, false, false, false, false, false, true, true, 800, 550, 0, 0);
    if (info == 'gold')
        showWindow('http://sgtt.vn/Page/giavang.htm', false, false, false, false, false, false, true, true, 500, 300, 0, 0);
    if (info == 'tvguide')
        showWindow('http://sgtt.vn/Page/truyenhinh.htm', false, false, true, false, false, false, true, true, 450, 354, 0, 0);
    if (info == 'lottery')
        showWindow('http://sgtt.vn/Page/xoso.htm', false, false, false, false, false, false, true, true, 500, 450, 0, 0);
    if (info == 'stock_ho')
        showWindow('http://sgtt.vn/Page/chungkhoan_hose.htm', false, false, false, false, false, true, true, true, 996, 770);
    if (info == 'stock_ha')
        showWindow('http://sgtt.vn/Page/chungkhoan_hastc.htm', false, false, false, false, false, true, true, true, 996, 770);
}

//=======SET HOMEOPAGE
function setHomepage() {
    if (document.all) {
        document.body.style.behavior = 'url(#default#homepage)';
        document.body.setHomePage('http://sgtt.vn');

    }
    else if (window.sidebar) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {

            }
        }
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
        prefs.setCharPref('browser.startup.homepage', 'http://sgtt.vn');
    }
}