﻿
/* COOKIE FUNCTION */
function Set_Cookie(name, value, expires, path, domain, secure) {
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime(today.getTime());

    /*
    if the expires variable is set, make the correct
    expires time, the current script below will set
    it for x number of days, to make it for hours,
    delete * 24, for minutes, delete * 60 * 24
    */
    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));

    document.cookie = name + "=" + escape(value) +
((expires) ? ";expires=" + expires_date.toGMTString() : "") +
((path) ? ";path=" + path : "") +
((domain) ? ";domain=" + domain : "") +
((secure) ? ";secure" : "");
}
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie(check_name) {
    // first we'll split this cookie up into name/value pairs
    // note: document.cookie only returns name=value, not the other components
    var a_all_cookies = document.cookie.split(';');
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false; // set boolean t/f default f

    for (i = 0; i < a_all_cookies.length; i++) {
        // now we'll split apart each name=value pair
        a_temp_cookie = a_all_cookies[i].split('=');


        // and trim left/right whitespace while we're at it
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

        // if the extracted name matches passed check_name
        if (cookie_name == check_name) {
            b_cookie_found = true;
            // we need to handle case where cookie has no value but exists (no = sign, that is):
            if (a_temp_cookie.length > 1) {
                cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
            }
            // note that in cases where cookie is initialized but no value, null is returned
            return cookie_value;
            break;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    if (!b_cookie_found) {
        return null;
    }
}
// this function gets the cookie, if it exists
// don't use this, it's weak and does not handle some cases
// correctly, this is just to maintain legacy information
function Get_Cookie(name) {

    var start = document.cookie.indexOf(name + "=");
    var len = start + name.length + 1;
    if ((!start) &&
(name != document.cookie.substring(0, name.length))) {
        return null;
    }
    if (start == -1) return null;
    var end = document.cookie.indexOf(";", len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len, end));
}
// this deletes the cookie when called
function Delete_Cookie(name, path, domain) {
    if (Get_Cookie(name)) document.cookie = name + "=" +
((path) ? ";path=" + path : "") +
((domain) ? ";domain=" + domain : "") +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}



/* move tool home hightlight*/
var maxh = 75;
var minh = 28;
var scrolling = false;
var showed = false;
var curent = 28;
var cancelev = false;
function HightLineOver(actived, sender) {
    if (scrolling) return;
    scrolling = true;
    setTimeout(function () { HightLineOver1(actived, sender); }, 200);
}
function AbotedEvent() { cancelev = true; }
function ResumingEvent() { cancelev = false; if (showed) scrolling = false; }
function HightLineOver1(actived, sender) {
    //alert('abc');

    if (actived) {
        actionOver(actived, sender);
    }
    else {
        actionOver(actived, sender); ;
    }
}
function actionOver(actived, sender) {
    scrolling = true;
    sender = document.getElementById('contexth');
    //document.getElementById('lblsms').innerHTML=sender.style.height;

    if (actived) {

        if (curent >= maxh) { curent = maxh; }
        sender.style.height = curent + 'px';
        if (curent >= maxh) { showed = true; scrolling = false; return; }
        curent += 5;
        setTimeout(function () { actionOver(actived, sender, curent); }, 10);
    }
    else {

        if (cancelev) return;
        if (curent <= minh) { curent = minh; }
        sender.style.height = curent + 'px';
        if (curent <= minh) { showed = false; scrolling = false; return; }
        curent -= 5;
        setTimeout(function () { actionOver(actived, sender); }, 10);
    }

}

function submitZone(id) {
    var zoneid = document.getElementById(id).getAttribute('fl');
    //alert(zoneid);
    strCookieZone = '';
    //strCookie="datviet1";
    var objs = document.getElementById(id).getElementsByTagName('input');
    for (var z = 0; z < objs.length; z++) {
        //alert(objs[z]);
        //alert(objs[z].checked);
        if (objs[z].checked) {
            if (z > 0) {
                strCookieZone += '-' + objs[z].getAttribute('value');
            }
            else {
                strCookieZone += objs[z].getAttribute('value');
            }
        }
    }
    //alert(strCookieZone);
    Set_Cookie('ChildOfZone_' + zoneid, strCookieZone, 100, '/', '', '');
    document.location = document.location;
}


//Cac chuc nang chia se ben dan tri
function share_twitter() { u = location.href; t = document.title; window.open("http://twitter.com/home?status=" + encodeURIComponent(u)); }
function share_facebook() { u = location.href; t = document.title; window.open("https://www.facebook.com/share.php?u=" + encodeURIComponent(u) + "&t=" + encodeURIComponent(t)); }
function share_google() { u = location.href; t = document.title; window.open("http://www.google.com/bookmarks/mark?op=edit&bkmk=" + encodeURIComponent(u) + "&title=" + t + "&annotation=" + t); }
function share_buzz() { u = location.href; t = document.title; window.open("http://buzz.yahoo.com/buzz?publisherurn=DanTri&targetUrl=" + encodeURIComponent(u)); } if (!DanTri_NewsWidgetCollection) {
    var DanTri_NewsWidgetCollection = Array();
}
function OpenPrint() {
    var hidDistID = document.getElementById("hidDistID");
    if (hidDistID != null) {
        window.open("/Print-" + hidDistID.value + ".htm", "Print", "");
        return false;
    }
}
function ShowHideComment() {
    var objdivComment = document.getElementById("divComment"); if (objdivComment != null) {
        var hidSendComment = document.getElementById("hidSendComment"); var hidViewComment = document.getElementById("hidViewComment"); var ifSendComment = document.getElementById("ifSendComment"); var ifViewComment = document.getElementById("ifViewComment"); objdivComment.style.display = objdivComment.style.display == "" ? "none" : ""; if (ifSendComment != null && hidSendComment != null)
        { ifSendComment.src = hidSendComment.value; }
        if (ifViewComment != null && hidViewComment != null)
        { ifViewComment.src = hidViewComment.value; }
    }
}
function ShowHideSendComment() {
    var objSend = document.getElementById("divSendComment");
    if (objSend) objSend.style.display = objSend.style.display == "" ? "none" : "";
    var hidSendComment = document.getElementById("hidSendComment");
    var ifSendComment = document.getElementById("ifSendComment");
    if (ifSendComment != null && hidSendComment != null)
        ifSendComment.src = hidSendComment.value;
}

function setAsHomePage(i) {
    if (document.all) {
        i.style.behavior = 'url(#default#homepage)';
        i.setHomePage('http://vnexpress.net');
    }
}
//Thoi tiet,ty gia vang

function gmobj(o) {
    if (document.getElementById) { m = document.getElementById(o); }
    else if (document.all) { m = document.all[o]; }
    else if (document.layers) { m = document[o]; }
    return m;
}
function ShowWeatherBox(vId) {
    var sLink = '';

    sLink = '/Resources/Weather/';
    //sLink = 'http: //vnexpress.net/ListFile/Weather/';
    switch (parseInt(vId)) {
        case 1: sLink = sLink.concat('Sonla.xml'); break;
        case 2: sLink = sLink.concat('Viettri.xml'); break;
        case 3: sLink = sLink.concat('Haiphong.xml'); break;
        case 4: sLink = sLink.concat('Hanoi.xml'); break;
        case 5: sLink = sLink.concat('Vinh.xml'); break;
        case 6: sLink = sLink.concat('Danang.xml'); break;
        case 7: sLink = sLink.concat('Nhatrang.xml'); break;
        case 8: sLink = sLink.concat('Pleicu.xml'); break;
        case 9: sLink = sLink.concat('HCM.xml'); break;
        default: sLink = sLink.concat('Hanoi.xml'); break;

    }

    AjaxRequest.get(
		{
		    'url': sLink
			, 'onSuccess': function (req) {
			    var vAdImg, vAdImg1, vAdImg2, vAdImg3, vAdImg4, vAdImg5, vWeather;
			   
			    vAdImg = req.responseXML.getElementsByTagName('AdImg').item(0).firstChild.nodeValue;
			    vAdImg1 = req.responseXML.getElementsByTagName('AdImg1').item(0).firstChild.nodeValue;
			    if (req.responseXML.getElementsByTagName('AdImg2').item(0).firstChild != null)
			        vAdImg2 = req.responseXML.getElementsByTagName('AdImg2').item(0).firstChild.nodeValue;
			    if (req.responseXML.getElementsByTagName('AdImg3').item(0).firstChild != null)
			        vAdImg3 = req.responseXML.getElementsByTagName('AdImg3').item(0).firstChild.nodeValue;
			    if (req.responseXML.getElementsByTagName('AdImg4').item(0).firstChild != null)
			        vAdImg4 = req.responseXML.getElementsByTagName('AdImg4').item(0).firstChild.nodeValue;
			    if (req.responseXML.getElementsByTagName('AdImg5').item(0).firstChild != null)
			        vAdImg5 = req.responseXML.getElementsByTagName('AdImg5').item(0).firstChild.nodeValue;
			    vWeather = req.responseXML.getElementsByTagName('Weather').item(0).firstChild.nodeValue;
			    GetWeatherBox(vAdImg, vAdImg1, vAdImg2, vAdImg3, vAdImg4, vAdImg5, vWeather);
			}
			, 'onError': function (req) { alert(req) }

		}
	)
    //GetWeatherBox("i_nhieumay.gif", "2.gif", "9.gif", "9.gif", "9.gif", "9.gif", "<b>Nhiều mây</b><br>&#272;&#7897; &#7849;m 64%<br>Gió tây tây bắc<br>tốc độ 4 m/s");
    // var vWeather = '<b>Nhiều mây</b><br>&#272;&#7897; &#7849;m 64%<br>Gió tây tây bắc<br>tốc độ 4 m/s';
    //gmobj('txt-Weather').innerHTML = vWeather;
   
}

function GetWeatherBox(vImg, vImg1, vImg2, vImg3, vImg4, vImg5, vWeather) {
    var sHTML = '';

    sHTML = sHTML.concat('<img src="http://vnexpress.net/Images/Weather/').concat(vImg).concat('" class="img-weather" alt="" />&nbsp;');
    sHTML = sHTML.concat('<img src="http://vnexpress.net/Images/Weather/').concat(vImg1).concat('" class="img-weather" alt="" />');
    if (vImg2 != null) sHTML = sHTML.concat('<img src="http://vnexpress.net/Images/Weather/').concat(vImg2).concat('" class="img-weather" alt="" />');
    if (vImg3 != null) sHTML = sHTML.concat('<img src="http://vnexpress.net/Images/Weather/').concat(vImg3).concat('" class="img-weather" alt="" />');
    if (vImg4 != null) sHTML = sHTML.concat('<img src="http://vnexpress.net/Images/Weather/').concat(vImg4).concat('" class="img-weather" alt="" />');
    if (vImg5 != null) sHTML = sHTML.concat('<img src="http://vnexpress.net/Images/Weather/').concat(vImg5).concat('" class="img-weather" alt="" />');
    sHTML = sHTML.concat('<img src="http://vnexpress.net/Images/Weather/c.gif" class="img-weather" alt="" />');

    gmobj('img-Do').innerHTML = sHTML;
    gmobj('txt-Weather').innerHTML = vWeather;

}


function ShowGoldPrice() {
    var sHTML = '';
    sHTML = sHTML.concat('<div style="text-align:right;color:#8A0000;font:bold 10px arial;">ĐVT: tr.&#273;/l&#432;&#7907;ng</div>');
    if (vGoldSbjBuy == '{0}' || vGoldSbjSell == '{1}' || vGoldSjcBuy == '{2}' || vGoldSjcSell == '{3}') {
        sHTML = sHTML.concat('<table border="0px" cellpadding="2px" cellspacing="1px" class="tbl-goldprice">');
        sHTML = sHTML.concat('	<tr>');
        sHTML = sHTML.concat('		<td class="td-weather-title" style="text-align:center;font-size:10px;width:35%;font-weight:bold">D&#7919; li&#7879;u &#273;ang &#273;&#432;&#7907;c c&#7853;p nh&#7853;t</td>');
        sHTML = sHTML.concat('	</tr>');
        sHTML = sHTML.concat('</table>');
    }
    else {
        sHTML = sHTML.concat('<table border="0px" cellpadding="2px" cellspacing="1px" class="tbl-goldprice">');
        sHTML = sHTML.concat('	<tr>');
        sHTML = sHTML.concat('		<td class="td-weather-title" style="font-size:10px;width:30%;">Lo&#7841;i</td>');
        sHTML = sHTML.concat('		<td class="td-weather-title" style="text-align:center;font-size:10px;width:35%;">Mua</td>');
        sHTML = sHTML.concat('		<td class="td-weather-title" style="text-align:center;font-size:10px;width:35%;">B&#225;n</td>');
        sHTML = sHTML.concat('	</tr>');
        sHTML = sHTML.concat('	<tr>');
        sHTML = sHTML.concat('		<td class="td-weather-title">SBJ</td>');
        sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSbjBuy).concat('</td>');
        sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSbjSell).concat('</td>');
        sHTML = sHTML.concat('	</tr>');
        sHTML = sHTML.concat('	<tr>');
        sHTML = sHTML.concat('		<td class="td-weather-title">SJC</td>');
        sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSjcBuy).concat('</td>');
        sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vGoldSjcSell).concat('</td>');
        sHTML = sHTML.concat('	</tr>');
        sHTML = sHTML.concat('</table>');
    }
    gmobj('eGold').innerHTML = sHTML;

}

function ShowForexRate() {
    var sHTML = '';
    sHTML = sHTML.concat('<table border="0px" cellpadding="2px" cellspacing="1px" class="tbl-weather">');
    for (var i = 0; i < vForexs.length; i++) {
        sHTML = sHTML.concat('	<tr>');
        sHTML = sHTML.concat('		<td class="td-weather-title">').concat(vForexs[i]).concat('</td>');
        sHTML = sHTML.concat('		<td class="td-weather-data txtr">').concat(vCosts[i]).concat('</td>');
        sHTML = sHTML.concat('	</tr>');
    }
    sHTML = sHTML.concat('</table>');
    gmobj('eForex').innerHTML = sHTML;
}


