﻿var isIE = (navigator.userAgent.indexOf('MSIE') != -1);

// 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 onLinkClick(link)
{
    if (isIE)	
    {	
        //Mozilla and FireFox don't support non-standard attribute
	    window.open(link.href, '', +
	    'toolbar=' + link.toolbar +
	    ',location=' + link.location +
	    ',status=' + link.statusbar +
	    ',menubar=' + link.menubar +
	    ',scrollbars=' + link.scrollbars +
	    ',resizable=' + link.resizable +
	    ',width=' + link.width +
	    ',height=' + link.height +
	    ',top=' + link.top + 
	    ',left=' + link.left);
	    return false;
    }
    else
    {
	    window.open(link.href, 'name', 'height=800, width=1024, left=0, top=0, resizable=yes, scrollbars=yes, toolbar=yes, status=yes');
	    return false;
    }
}

function onLinkClickFull(link)
{
    if (isIE)	
    {	
        //Mozilla and FireFox don't support non-standard attribute
	    window.open(link.href, '', + 
	    'toolbar=' + link.toolbar +
	    ',location=' + link.location +
	    ',status=' + link.statusbar+
	    ',menubar=' + link.menubar+
	    ',scrollbars=yes' +
	    ',resizable=yes' +
	    ',width=800' +
	    ',height=1024' +
	    ',top=' + link.top +
	    ',left=' + link.left);
	    
	    return false;
    }
}

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 writeTime(s) 
{
    var mydate = new Date(s)

    var year = mydate.getYear()
    if (year < 1000)
        year += 1900
    var month = mydate.getMonth() + 1
    if (month < 10)
        month = "0" + month
    var day = mydate.getDate()
    if (day < 10)
        day = "0" + day

    var dayw = mydate.getDay()

    var hour = mydate.getHours()
    if (hour < 10)
        hour = "0" + hour

    var minute = mydate.getMinutes()
    if (minute < 10)
        minute = "0" + minute
        
    var dayarray = new Array("Ch&#7911; Nh&#7853;t", "Th&#7913; Hai", "Th&#7913; Ba", "Th&#7913; T&#432;", "Th&#7913; N&#259;m", "Th&#7913; S&#225;u", "Th&#7913; B&#7843;y")
    document.write(dayarray[dayw] + ", " + day + "/" + month + "/" + year + ",&nbsp;" + hour + ":" + minute + " (GMT+7)")
}

function ReloadPage()
{
	setTimeout("ReloadPage()", 300000);
	
	if(document.location.href.toLowerCase().indexOf('index.html') < 0)
    {                
        return;
	}
	else
	{
		location.reload();
	}
}

function LoadData(channelid, divData) 
{
    jQuery.ajax({
        type: "POST",
        url: '../Ajax/ChannelSample.aspx?ChannelID=' + channelid,
        data: "",
        beforeSend: function() {
            jQuery(divData).html('<div style="width:100%;height:100px;vertical-align:top;text-align:center;" id="loading"><img src="../images/loading.gif" style="margin-top:30px;" /></div>');
        },
        success: function(req) { jQuery(divData).html(req); }
    });
}

function LoadDataTopic(TopicID, divData) 
{
    jQuery.ajax({
        type: "POST",
        url: '../Ajax/TopicSample.aspx?TopicID=' + TopicID,
        data: "",
        beforeSend: function() {
            jQuery(divData).html('<div style="width:100%;height:100px;vertical-align:top;text-align:center;" id="loading"><img src="../images/loading.gif" style="margin-top:30px;" /></div>');
        },
        success: function(req) { jQuery(divData).html(req); }
    });
}

function OnPageLoad() 
{    try 
    {
        LoadData(3, '#divDataChinhTriXaHoi');
        LoadData(2, '#divDataThegioi');
        LoadData(7, '#divDataNhipsongtre');
        LoadData(13, '#divDatagiaoduc');
        LoadData(11, '#divDatakinhte');
        LoadData(14, '#divDataThethao');
        LoadData(10, '#divDataVanhoagiaitri');
        LoadData(16, '#divDataNhipsongso');
        LoadData(118, '#divDataBandoc');
    }
    catch (err){ }
}

function setSelected2Tab(id1, id2) 
{
    try 
    {
        document.getElementById(id1).className = "txt_16_bold";
        document.getElementById(id2).className = "txt_12";        
    } catch (err) { }
}

function setSelected3Tab(id1, id2, id3) 
{
    try {
        document.getElementById(id1).className = "txt_16_bold";
        document.getElementById(id2).className = "txt_12";
        document.getElementById(id3).className = "txt_12";
    } catch (err) { }
}

function setSelected4Tab(id1, id2, id3,id4) 
{
    try {        
        document.getElementById(id1).className = "txt_16_bold";
        document.getElementById(id2).className = "txt_12";
        document.getElementById(id3).className = "txt_12";
        document.getElementById(id4).className = "txt_12";
    } catch (err) { }
}

function setSelected5Tab(id1, id2, id3, id4,id5) {
    try {
        document.getElementById(id1).className = "txt_16_bold";
        document.getElementById(id2).className = "txt_12";
        document.getElementById(id3).className = "txt_12";
        document.getElementById(id4).className = "txt_12";
        document.getElementById(id5).className = "txt_12";
    } catch (err) { }
}

function displayInfo(info) 
{
    if (info == 'weather')
    //showDialog('http://www3.tuoitre.com.vn/Transweb/Weather.aspx', 500, 600);
        showWindow('http://www3.tuoitre.com.vn/Transweb/Weather.aspx', false, false, false, false, false, false, true, true, 550, 550, 0, 0);
    if (info == 'forex')
    //showDialog('http://www.tuoitre.com.vn/tianyon/transweb/TyGia.htm', 500, 600);
        showWindow('http://phienbancu.tuoitre.vn/tianyon/transweb/TyGia.htm', false, false, false, false, false, false, true, true, 800, 550, 0, 0);
    if (info == 'gold')
    //showDialog('http://www3.tuoitre.com.vn/transweb/giavang.htm', 500, 300);
        showWindow('http://www3.tuoitre.com.vn/transweb/giavang.htm', false, false, false, false, false, false, true, true, 500, 300, 0, 0);
    if (info == 'tvguide')
        showWindow('http://www3.tuoitre.com.vn/transweb/truyenhinh.htm', false, false, true, false, false, false, true, true, 450, 354, 0, 0);
    if (info == 'lottery')
        showWindow('http://phienbancu.tuoitre.vn/tianyon/transweb/xoso.htm', false, false, false, false, false, false, true, true, 500, 450, 0, 0);
    if (info == 'stock_ho')
        showWindow('http://www3.tuoitre.com.vn/transweb/chungkhoan_ho.htm', false, false, false, false, false, true, true, true, 996, 770);
    if (info == 'stock_ha')
        showWindow('http://www3.tuoitre.com.vn/transweb/chungkhoan_ha.htm', false, false, false, false, false, true, true, true, 996, 770);
}

function setHomepage() 
{
    if (document.all) 
    {
        document.body.style.behavior = 'url(#default#homepage)';
        document.body.setHomePage('http://tuoitre.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://tuoitre.vn');
    }
}

var status = "collapse";
function expand(obj, idhiden, idleft, idcenter, idright, idheight) 
{
    if (status == "expand") 
    {
        document.getElementById(idhiden).style.display = "block";
        document.getElementById(idleft).style.height = idheight + "px";
        document.getElementById(idcenter).style.height = idheight + "px";
        document.getElementById(idright).style.height = idheight + "px";
        obj.src = "../App_Themes/TTOBlue/Images/collapse.gif";
        status = "collapse";
    }
    else 
    {
        document.getElementById(idhiden).style.display = "none";
        obj.src = "../App_Themes/TTOBlue/Images/expand.gif";
        document.getElementById(idleft).style.height = "28px";
        document.getElementById(idcenter).style.height ="28px";
        document.getElementById(idright).style.height = "28px";
        status = "expand";
    }
    //cookieUser.setSubValue('hidenid', idhiden);
}

//Initialize varible Cookies
if (!cookieUser.cookieExists()) 
{
    cookieUser.setSubValue("keyCookie", "clientCookie");
}

var theme = 'http://tuoitre.vn/App_Themes/TTOBlue/TTOBlue.css';

//Get value current theme from cookie
if (!cookieUser.getSubValue('theme')) 
{
    cookieUser.setSubValue('theme', 'http://tuoitre.vn/App_Themes/TTOBlue/TTOBlue.css');
}
else 
{
    theme = cookieUser.getSubValue('theme');
}

var css = document.createElement('link');
css.rel = 'stylesheet';
css.type = 'text/css';
css.href = theme;

var $j=jQuery.noConflict();

$j(document).ready(function() 
{
    document.body.appendChild(css);
    if (debug) 
    {
        monitor(dynStyles, theme);
    }
    cookieUser.setSubValue('theme', theme);
});

//text change on text box
//thanhnt
function textboxChange(tb, f, sb) 
{
    if (!f) 
    {
        if (tb.value == "") 
        {
            tb.value = sb;
        }
    }
    else 
    {
        if (tb.value == sb)
        {
            tb.value = "";
        }
    }
}
function displayObject(showID, hideID1) {
    // show elment                       
    document.getElementById(showID).style.display = "block";
    // hide element                
    document.getElementById(hideID1).style.display = "none";
}
function OnCmdSubmitClick(Option, suveryid) {
    var opt = document.getElementsByName(Option);
    for (i = 0; i < opt.length; i++) {
        try {
            if (opt[i].checked) {
                showDialog('http://123.30.128.12/SurveyResult.aspx?SurveyID=' + suveryid + '&SurveyDetailID=' + opt[i].value, 600, 430);
                return;
            }
        } catch (err) { }
    }
    alert('Bạn cần chọn một câu trả lời trước khi nhấn nút!1');
}
function OnCmdViewClick(suveryid) {
    showDialog('http://123.30.128.12/SurveyResult.aspx?SurveyID=' + suveryid, 600, 430);
}