﻿/*!
 * dtinews JavaScript Library v1.0
 * http://dtinews.vn/
 *
 * Copyright 2011, Hoang Manh Gioi
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://manhgioi.tk/license
 *
 * Date: Tues Dec 6 17:32:23 2011
 */
 
function init_search_text(_frm, _show, _hide) {
    var show, hide, text;
    show = $('#' + _show);
    hide = $('#' + _hide);
    text = show.val();

    if (hide.val() != '')
        show.val(hide.val());

    $('#' + _frm).submit(function() {
        if (show.val() != text)
            hide.val(show.val());
    });
    show.keyup(function() {
        hide.val(show.val());
    });
    show.blur(function() {
        hide.val(show.val());
        if (show.val() == '') show.val(text);
    });
    show.focus(function() {
        $(this).val(hide.val());
    });
}
function loadUtilsBlock(_oid, _act){
	try {
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		if(obj!=null) obj.innerHTML = '<img alt="Loading" src="/images/assets/indicator.gif" />';
		var actionURL = "/ajax/actions.aspx?type=" + _act + "&rd=" + Math.random();
                
		var indicator = document.getElementById('processDiv');
		if(indicator!=null){
			indicator.style.display = 'block';
		}
		HttpRequest.open("GET",actionURL);
		HttpRequest.onreadystatechange = function()
		{
		   if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
		   {
			   if(HttpRequest.responseText.indexOf('err=')!=0){
				       obj.innerHTML = HttpRequest.responseText;					  
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
function loadCommentBlock(_oid, _act, _newsId, _page){
	try {
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		if(obj!=null) obj.innerHTML = '<img alt="Loading" src="/images/assets/indicator.gif" />';
		var actionURL = "/ajax/actions.aspx?type=" + _act + "&newsId=" + _newsId + "&page=" + _page + "&rd=" + Math.random();
                
		var indicator = document.getElementById('processDiv');
		if(indicator!=null){
			indicator.style.display = 'block';
		}
		HttpRequest.open("GET",actionURL);
		HttpRequest.onreadystatechange = function()
		{
		   if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
		   {
			   if(HttpRequest.responseText.indexOf('err=')!=0){
				       obj.innerHTML = HttpRequest.responseText;					  
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
function loadNewsBlock(_oid, _act, _catid){
	try {
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		if(obj!=null) obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "/ajax/actions.aspx?type=" + _act + "&cat=" + _catid + "&rd=" + Math.random();
                
		var indicator = document.getElementById('processDiv');
		if(indicator!=null){
			indicator.style.display = 'block';
		}
		HttpRequest.open("GET",actionURL);
		HttpRequest.onreadystatechange = function()
		{
		   if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
		   {
			   if(HttpRequest.responseText.indexOf('err=')!=0){
				       obj.innerHTML = HttpRequest.responseText;					  
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
function changeLang(_lang, _rewrite) {
    try {
        var getStr = "type=language&lang=" + _lang + "&rd=" + Math.random();
        var actionURL = "/ajax/actions.aspx";

        $.ajax({
            type: "POST",
            url: actionURL,
            data: getStr,
            success: function(msg) {
                if (msg.indexOf('err=') != 0) {
                    if (_rewrite == 'true') {
                        if (_lang == 'VN') {
                            window.location = _lang.toLowerCase() + "/trang-chu.html";
                        }
                        else {
                            window.location = _lang.toLowerCase() + "/index.html";
                        }
                    }
                    else {
                        if (_lang == 'VN') {
                            window.location = "default.aspx?lang=vn";
                        }
                        else {
                            window.location = "default.aspx?lang=en";
                        }
                    }
                }
            }
        });
        return;
    } catch (ex) { }
}
function init_search_text_top(_frm, _show, _hide) {
    var show, hide, text;
    show = $('#' + _show);
    hide = $('#' + _hide);
    text = show.val();

    if (hide.val() != '')
        show.val(hide.val());

    $('#' + _frm).submit(function() {
        if (show.val() != text)
            hide.val(show.val());
    });
    show.keyup(function() {
        hide.val(show.val());
    });
    show.blur(function() {
        hide.val(show.val());
        if (show.val() == '') show.val(text);
    });
    show.focus(function() {
        $(this).val(hide.val());
    });
}
function process_enter(_frm) {
    try {
        $('#' + _frm + ' :input').each(function(i) {
            $(this).keydown(function(event) {
                if (event.keyCode == 13) {
                    if (_btn == '' || !_btn)
                        $('#' + _frm).submit();
                    else
                        $("#" + _btn).click();
                }
            });
        });
    } catch (ex) { }
}
function sendmail(_title, _body) {
    window.location = "mailto:example@iboss.com.vn?subject=" + encodeURIComponent(_title) + '&body=' + window.encodeURIComponent(_body);
}
function ChuyenTVKhongDau(strVietNamese) {
    if (!strVietNamese) return '';
    var FindText = "áàảãạâấầẩẫậăắằẳẵặđéèẻẽẹêếềểễệíìỉĩịóòỏõọôốồổỗộơớờởỡợúùủũụưứừửữựýỳỷỹỵÁÀẢÃẠÂẤẦẨẪẬĂẮẰẲẴẶĐÉÈẺẼẸÊẾỀỂỄỆÍÌỈĨỊÓÒỎÕỌÔỐỒỔỖỘƠỚỜỞỠỢÚÙỦŨỤƯỨỪỬỮỰÝỲỶỸỴqwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM";
    var ReplText = "aaaaaaaaaaaaaaaaadeeeeeeeeeeeiiiiiooooooooooooooooouuuuuuuuuuuyyyyyAAAAAAAAAAAAAAAAADEEEEEEEEEEEIIIIIOOOOOOOOOOOOOOOOOUUUUUUUUUUUYYYYYqwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM";
    var index = -1;
    var tmp = strVietNamese.split("");
    var length = tmp.length;
    for (var i = 0; i < length; i++) {
        if (i >= tmp.length) break;
        index = FindText.indexOf(tmp[i]);
        if (index >= 0) {
            tmp[i] = ReplText.substr(index, 1);
        }
        else {
            tmp[i] = "-";
        }
    }
    return tmp.join("");
}
function viewTab(_oid, _site, _curTab) {
    try {
        var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
        if (!HttpRequest) return;
        if ((_oid == null) || (_oid == '') || (_curTab == null)) { return; }
        var obj = document.getElementById(_oid);
        if (!obj) { return; }
        obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
        var actionURL = "/ajax/actions.aspx?type=" + _curTab + "&site=" + _site + "&rd=" + Math.random();

        var indicator = document.getElementById('processDiv');
        if (indicator != null) {
            indicator.style.display = 'block';
        }
        HttpRequest.open("GET", actionURL);
        HttpRequest.onreadystatechange = function() {
            if (HttpRequest.readyState == 4 && HttpRequest.status == 200) {
                if (HttpRequest.responseText.indexOf('err=') != 0) {
                    obj.innerHTML = HttpRequest.responseText;
                }
                if (indicator != null) { indicator.style.display = 'none'; }
            }
        }
        HttpRequest.send(null);
        return;
    } catch (ex) { alert(ex.tostring); }
}
function viewnews_search(_oid, _key, _page) {
    try {
        var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
        if (!HttpRequest) return;
        if ((_oid == null) || (_oid == '')) { return; }
        var obj = document.getElementById(_oid);
        if (!obj) { return; }
        obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
        var actionURL = "/ajax/actions.aspx?type=news_search&keyword=" + window.encodeURIComponent(_key) + "&page=" + window.encodeURIComponent(_page) + "&rd=" + Math.random();
        var indicator = document.getElementById('processDiv');
        if (indicator != null) {
            indicator.style.display = 'block';
        }
        HttpRequest.open("GET", actionURL);
        HttpRequest.onreadystatechange = function() {
            if (HttpRequest.readyState == 4 && HttpRequest.status == 200) {
                if (HttpRequest.responseText.indexOf('err=') != 0) {
                    obj.innerHTML = HttpRequest.responseText;
                }
                if (indicator != null) { indicator.style.display = 'none'; }
            }
        }
        HttpRequest.send(null);
        return;
    } catch (ex) { }
}
function viewnews(_oid, _cid, _page) {
    try {
        var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
        if (!HttpRequest) return;
        if ((_oid == null) || (_oid == '')) { return; }
        var obj = document.getElementById(_oid);
        if (!obj) { return; }
        obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
        var actionURL = "/ajax/actions.aspx?type=news&cat=" + window.encodeURIComponent(_cid) + "&page=" + window.encodeURIComponent(_page) + "&rd=" + Math.random();

        var indicator = document.getElementById('processDiv');
        if (indicator != null) {
            indicator.style.display = 'block';
        }
        HttpRequest.open("GET", actionURL);
        HttpRequest.onreadystatechange = function() {
            if (HttpRequest.readyState == 4 && HttpRequest.status == 200) {
                if (HttpRequest.responseText.indexOf('err=') != 0) {
                    obj.innerHTML = HttpRequest.responseText;
                }
                if (indicator != null) { indicator.style.display = 'none'; }
            }
        }
        HttpRequest.send(null);
        return;
    } catch (ex) { }
}
function newsType(_oid, _cid, _page) {
    try {
        var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
        if (!HttpRequest) return;
        if ((_oid == null) || (_oid == '')) { return; }
        var obj = document.getElementById(_oid);
        if (!obj) { return; }
        obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
        var actionURL = "/ajax/actions.aspx?type=newslist&newstype=" + window.encodeURIComponent(_cid) + "&page=" + window.encodeURIComponent(_page) + "&rd=" + Math.random();

        var indicator = document.getElementById('processDiv');
        if (indicator != null) {
            indicator.style.display = 'block';
        }
        HttpRequest.open("GET", actionURL);
        HttpRequest.onreadystatechange = function() {
            if (HttpRequest.readyState == 4 && HttpRequest.status == 200) {
                if (HttpRequest.responseText.indexOf('err=') != 0) {
                    obj.innerHTML = HttpRequest.responseText;
                }
                if (indicator != null) { indicator.style.display = 'none'; }
            }
        }
        HttpRequest.send(null);
        return;
    } catch (ex) { }
}
function newsOtherWeb(_oid, _site, _page, _type) {
    try {
        var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
        if (!HttpRequest) return;
        if ((_oid == null) || (_oid == '')) { return; }
        var obj = document.getElementById(_oid);
        if (!obj) { return; }
        if (obj != null) obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
        var actionURL = "/ajax/actions.aspx?type=newsfromothersite&site=" + window.encodeURIComponent(_site) + "&page=" + window.encodeURIComponent(_page) + "&rd=" + Math.random();

        var indicator = document.getElementById('processDiv');
        if (indicator != null) {
            indicator.style.display = 'block';
        }
        HttpRequest.open("GET", actionURL);
        HttpRequest.onreadystatechange = function() {
            if (HttpRequest.readyState == 4 && HttpRequest.status == 200) {
                if (HttpRequest.responseText.indexOf('err=') != 0) {
                    obj.innerHTML = HttpRequest.responseText;
                }
                if (indicator != null) { indicator.style.display = 'none'; }
            }
        }
        HttpRequest.send(null);
        return;
    } catch (ex) { }
}
function print_page(_type, _cid, _id, _page, _search) {
    try {
        if (rewrite) {
            $('#print').after("<form action='" + baseURL + "print/" + (!_type ? "print" : _type) + "/" + (!_cid ? "0" : _cid) + "/" + (!_id ? "0" : _id) + "/" + (!_page ? "1" : _page) + "/" + (!_search ? "print" : ChuyenTVKhongDau(_search)) + ".html' id='print_form' method='post'><input type='hidden' name='keyword' value='" + _search + "' /></form>");
        } else {
            $('#print').after("<form action='" + baseURL + "print.aspx' id='print_form' method='post'></form>");
            $('#print_form').append("<input type='hidden' name='type' value='" + _type + "' />");
            $('#print_form').append("<input type='hidden' name='cat' value='" + _cid + "' />");
            $('#print_form').append("<input type='hidden' name='nid' value='" + _id + "' />");
            $('#print_form').append("<input type='hidden' name='page' value='" + _page + "' />");
            $('#print_form').append("<input type='hidden' name='keyword' value='" + _search + "' />");
        }
        $('#print_form').submit();
    } catch (ex) { /*alert(ex.message)*/ }
}
function email_page(_title, _body) {
    try {
        if (!_body) { _body = window.location.toString(); }
        if (!_title) { _title = document.title; }
        window.location = "mailto:your-friend@email.com?subject=" + encodeURIComponent(_title) + '&body=' + window.encodeURIComponent(_body);
    } catch (ex) { }
}
function bookmark_page(_title) {
    try {
        var title = _title; var url = window.location.toString();
        if (!title) title = document.title;
        if (window.sidebar) // firefox
            window.sidebar.addPanel(title, url, "");
        else if (window.opera && window.print) { // opera
            var elem = document.createElement('a');
            elem.setAttribute('href', url);
            elem.setAttribute('title', title);
            elem.setAttribute('rel', 'sidebar');
            elem.click();
        } else if (document.all)// ie
            window.external.AddFavorite(url, title);
    } catch (ex) { }
}
function url_anchor() {
    return unescape(self.document.location.hash.substring(1));
}
function setHomepage(url) {
    try {
        if (document.all) {
            document.body.style.behavior = 'url(#default#homepage)';
            document.body.setHomePage(url);
        } else if (window.sidebar) {
            if (window.netscape) {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', url);
        }
    } catch (ex) { bookmark_page(document.title, url) }
}
function viewGoldRate(_oid, _loai) {
    try {
        var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
        if (!HttpRequest) return;
        if ((_oid == null) || (_oid == '')) { return; }
        var obj = document.getElementById(_oid);
        if (!obj) { return; }
        if (obj != null) obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
        var actionURL = "/ajax/actions.aspx?type=loadgoldratesite&loai=" + window.encodeURIComponent(_loai) + "&rd=" + Math.random();

        var indicator = document.getElementById('processDiv');
        if (indicator != null) {
            indicator.style.display = 'block';
        }
        HttpRequest.open("GET", actionURL);
        HttpRequest.onreadystatechange = function() {
            if (HttpRequest.readyState == 4 && HttpRequest.status == 200) {
                if (HttpRequest.responseText.indexOf('err=') != 0) {
                    obj.innerHTML = HttpRequest.responseText;
                }
                if (indicator != null) { indicator.style.display = 'none'; }
            }
        }
        HttpRequest.send(null);
        return;
    } catch (ex) { }
}
function loadWeather(_oid) {
    try {
        var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
        if (!HttpRequest) return;
        if ((_oid == null) || (_oid == '')) { return; }
        var obj = document.getElementById(_oid);
        if (!obj) { return; }
        if (obj != null) obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
        var actionURL = "/ajax/actions.aspx?type=loadweather" + "&rd=" + Math.random();

        var indicator = document.getElementById('processDiv');
        if (indicator != null) {
            indicator.style.display = 'block';
        }
        HttpRequest.open("GET", actionURL);
        HttpRequest.onreadystatechange = function() {
            if (HttpRequest.readyState == 4 && HttpRequest.status == 200) {
                if (HttpRequest.responseText.indexOf('err=') != 0) {
                    obj.innerHTML = HttpRequest.responseText;
                }
                if (indicator != null) { indicator.style.display = 'none'; }
            }
        }
        HttpRequest.send(null);
        return;
    } catch (ex) { }
}
// footer
function initFooter(nid3, seq3) {
    nav3 = document.getElementById(nid3);
    nav3.menu3 = new Array();
    nav3.current = null;
    nav3.menuseq3 = 0;
    navLen3 = nav3.childNodes.length;

    allA3 = nav3.getElementsByTagName("a")
    for (q = 0; q < allA3.length; q++) {
        allA3.item(q).onmouseover = allA3.item(q).onfocus = function() {
            nav3.isOver = true;
        }
        allA3.item(q).onmouseout = allA3.item(q).onblur = function() {
            nav3.isOver = false;
            setTimeout(function() {
                if (nav3.isOver == false) {
                    if (nav3.menu3[seq3])
                        nav3.menu3[seq3].onmouseover();
                    else if (nav3.current) {
                        if (nav3.current.submenu)
                            nav3.current.submenu.style.display = "none";
                        nav3.current = null;
                    }
                }
            }, 500);
        }
    }

    for (r = 0; r < navLen3; r++) {
        navItem3 = nav3.childNodes.item(r);
        if (navItem3.tagName != "LI")
            continue;

        navAnchor3 = navItem3.getElementsByTagName("a").item(0);
        navAnchor3.submenu = navItem3.getElementsByTagName("ul").item(0);

        navAnchor3.onmouseover = navAnchor3.onfocus = function() {
            if (nav3.current) {
                if (nav3.current.submenu)
                    nav3.current.submenu.style.display = "none";
                nav3.current = null;
            }
            if (nav3.current != this) {
                if (this.submenu)
                    this.submenu.style.display = "block";
                nav3.current = this;
            }
            nav3.isOver = true;
        }
        nav3.menuseq3++;
        nav3.menu3[nav3.menuseq3] = navAnchor3;
    }
    if (nav3.menu3[seq3])
        nav3.menu3[seq3].onmouseover();
}
function saveComment(_oid, _newsId, _name, _email, _tel, _location, _comment){
	try {
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		var actionURL = "/ajax/actions.aspx?type=comment&newsId=" + _newsId + "&fullname=" + _name + "&email=" + _email + "&tel=" + _tel + "&location=" + _location + "&comment=" + _comment + "&rd=" + Math.random();
     
		HttpRequest.open("POST",actionURL);		
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
$(document).ready(function () {
    $('#frmsearch').submit(function(event){
        var _keyword = $("#txthidden").attr('value');
        if (_rewrite == true){
        $(this).attr('action', (_lang=='en'?'/en/search/':'/vn/tim-kiem/') + (!_keyword?"":ChuyenTVKhongDau(_keyword) + '/') + 'index' + _ext);
        }
        else{
        $(this).attr('action', $(this).attr('action')+"?lang=" + _lang + "&keyword="+ ChuyenTVKhongDau(_keyword));
        }
    });
    init_search_text('frmsearch','txtsearch','txthidden');
    process_enter('frmsearch');
    $('#dotlist a').click(function(){
        document.getElementById("clipvieoTitle").innerHTML =this.rel;
    });
    $('#email').click(function(event){
        event.preventDefault();
        email_page();
    });
    $('#bookmark').click(function(event){
        event.preventDefault();
        bookmark_page();
    }); 
    var CURRENT_URL = '';
    var _sCurCat = $("#txtCurCat").attr('value');
    $("#datepicker").datepicker({
        dateFormat:'m-d-yy',
        maxDate: 0,
        onSelect: function(dateText, inst) {
        if (_rewrite == true){
            CURRENT_URL = (_lang=='en'?'/en/date-search/':'/vn/tin-ngay/') + dateText + "/" + _sCurCat + "/index" + _ext;
        }
        else{
            CURRENT_URL = "DateSearch.aspx?lang=" + _lang + "&dts=" + dateText + "&cat=" + _sCurCat;
        }
        window.location = CURRENT_URL;
    }}); 
}); 
