﻿// bien su dung chung 
var map = null; // bien map, dung cho ban do
var curWindowSize = utils.windowSize();
var strUrSn = '123';
var flagUser = 0;
var isWard; //= '-1';
var strNamePage = '-1';
var paraCom = null;
var strParamCom = "";
var strAB = "";
var strABResult = "";
var strTypeSearch = 0;
var strParamCom = "";
var myvar;
var strTabCommentNew = "";
var paramCom = null;

var iHotpot = 0;
var timer = null;
var oHotSpot = null;
var imgAdPopup = 'images/ads/banner_map_195x25.gif';
var jsonProduct = null;
var jsonFBOption = null;
var strTabCommentBest = "";
var strTabCommentLastest = "";
var strTabCommentCheckinBest = "";
var strTabCommentCheckinLastest = "";
//var winNews, winMedia;
document.observe("dom:loaded", loadMain);
document.observe("click", docClick);
var strCity = '-1';
var oSendReview = null;
var count = 1; //cho biet so lan click Xem them
var timeout = null;
var arrFeed = null; // Danh sach feed tin tuc cua 1 user
var fID = ''; var vID = ''; var eM = ''; var indexFeed = 0;
var strFeedCheckin = ''; // cache cho danh sach feed checkin
var strFeedExper = ''; //cache cho danh sach feed comment
var indeximg = 1; //index hinh dang load trong music player

var strTabPlay = ""; //cache cho danh sach feed 2Play
var strTabRead = ""; // cache cho danh sach feed 2Read
var strTabGo = ""; //cache cho danh sach feed 2Go
var chkAdv = false; //kiem tra co quang cao
window.onresize = function() {
    resizeWeb();
    mainResize();
    try {
        var box = $('box');
        if (box && box.hasClassName('box_write')) oSendReview.resizeControl();
    } catch (ex) { }
};

function loadMain() {
    //    if (document.URL.toLowerCase().indexOf('/mobiles/index.aspx') != -1) {
    //        if (utils.IE7_Firefox() == 6)
    //            setTimeout(function() { window.location.href = 'http://www.two.vn/Download.aspx'; }, 0);
    //        else window.location.href = 'http://www.two.vn/Download.aspx';

    //    }
    geturllang();
    try {
        setURLMenu();
    } catch (ex) { }
    // lay bien isLang, neu ko co thi set =0;

    loadMainEvents();

    // getHotSpot();

    loadTagCloud(); // top tu khoa
    footerurl();
    try {
        var ele = $('uTabComments').next('.view_more');
        ele.down('.arrow').name = 'more';
        onClickMore_Cate(ele);
    } catch (ex) { }
    // Neu ie 6 thi thay doi layout cho navigation
    //  mypopup();
};
// function gan url vao footer

function footerurl() {
    var lang = langFooter()[isLang];
    var footerpar = $("footerItem");
    var footerstr = "<ul><li>"
	              + '<a href=javascript:poptastic("http://www.diadiem.com");>' + lang[0] + '</a><span></span>'
	              + '<a href=javascript:poptastic("policy.aspx");>' + lang[1] + '</a><span></span>'
	              + '<a href=javascript:poptastic("advertisement/Webs.aspx");>' + lang[2] + '</a><span></span>'
	              + '<a href=javascript:poptastic("advertisement/contact.aspx");>' + lang[3] + '</a><span></span>'
	              + '<div>Sitemap</div><span></span>'
    //	          + '<a href=javascript:poptastic("advertisement/Recruitment.aspx");>TuyÃ¡Â»Æ’n DÃ¡Â»Â¥ng</a><span></span>'
	              + '<div>' + lang[5] + '</div>'
	              + '</li><li class="li_copyright">Copyright &copy; 2004 - 2011 by <strong>DiaDiem JSC</strong>. All rights reserved.</li>'
	              + '</ul>';
    if (footerpar)
        footerpar.innerHTML = footerstr;
};
// function open url trong cua so moi, url: url can open 
var newwindow;
function poptastic(url) {
    //newwindow = 
    window.open(url, 'name', '');

};
function loadMainEvents() {
    loadSearchTabEvent();
    ['txtSearchNearBy', 'txtSearchYP'].each(function(item) {
        if ($(item))
            $(item).onkeydown = function(e) { hideErrorInfo(); }
    }
    );
    try {

        if ($('btnSearch')) {
            $('btnSearch').up().observe('click', function() {
                chkAdv = true;
                clickBoxSearch();
            });
            //$('btnSearch').up().observe('click', clickBoxSearch);


        }
        [$('aRecentA'), $('aRecentB')].invoke('observe', 'click', showRecentBox);
        var aRecentMaps = $('aRecentMaps');
        if (aRecentMaps) aRecentMaps.observe('click', showRecentBox);
        $('divRecentBox').observe('click', clickRecentBox);
        loadEventOtherCity();
    }
    catch (e) { }

    loadPartnerLinks();
    //if ($('divTopKeyWord') != null) $('divTopKeyWord').observe('click', clickKeyWord);
    var divListPopular = $('divListPopular');
    if (divListPopular) {
        divListPopular.select('a[title]').invoke('observe', 'mouseover', hotSpotRollover);
    }
    if ($('txtSearchA') != null || $('txtSearchB') != null) {
        [$('txtSearchA'), $('txtSearchB')].invoke('observe', 'keydown', enterSearchStreet);
    }
    if ($('txtSearchNearBy') != null || $('txtSearchYP') != null) {
        [$('txtSearchNearBy'), $('txtSearchYP')].invoke('observe', 'keydown', enterSearchNearBy);
    }
    try {

        var strUrl = window.location.toString();
        if (strUrl.toLowerCase().indexOf("vnmap.aspx") == -1 & strUrl.toLowerCase().indexOf(".aspx") != -1) {
            getAds();
        }
    } catch (exc) { }
    try {
        if ($('aDDLanguage')) $('aDDLanguage').observe('click', changeLanguage);
    } catch (ex) { alert(ex); };
    try {
        $('spanDDFunction').observe('click', DDFunctionClick);
        // $("aDDMobile").observe('click', linktoMobile);
        //  if ($('aDDLanguage')) $('aDDLanguage').observe('click', ChangeLangVNMap); // tamthoi dong de test thu 
        try {
            ChangeLangVNMap(0, isLang);
        } catch (ex) { }
        //$("aDDContact").onclick = function() { window.open("advertisement/contact.aspx"); };
        //$("aDDAdds").onclick = function() { window.open("advertisement/Webs.aspx"); };
        //$("aDDRecruit").onclick = function() { window.open("Advertisement/Recruitment.aspx"); };
    } catch (hex) { }

    if ($('feedback')) $('feedback').observe('click', loadBoxFeedback);
    var aChageCity = $('aChageCity/Province');

    if (aChageCity) aChageCity.observe('click', clickOtherCity);
};

function setURLMenu() {
    var uLang = (document.URL.toLowerCase().indexOf('en/') != -1) ? 1 : 0;
    var langtabheaders = langtabheader()[0];
    if ($('navRestaurent') != null) { $('navRestaurent').href = "amthuc.aspx?st=" + strState + "&l=" + uLang; }
    if ($('navHotel') != null) { $('navHotel').href = "khachsan.aspx?st=" + strState + "&l=" + uLang; }
    if ($('navBeauty') != null) { $('navBeauty').href = "lamdep.aspx?st=" + strState + "&l=" + uLang; }
    if ($('navEntertain') != null) { $('navEntertain').href = "giaitri.aspx?st=" + strState + "&l=" + uLang; }
    if ($('navMap') != null) { $('navMap').href = "vnmap.aspx?st=" + strState + "&l=" + uLang; }
    if ($('navShopping') != null) { $('navShopping').href = "muasam.aspx?st=" + strState + "&l=" + uLang; }
    if ($('navHome') != null) { $('navHome').href = "index.aspx?st=" + strState + "&l=" + uLang; }
    if ($('navDirectory') != null) { $('navDirectory').href = "directory.aspx?st=" + strState + "&l=" + uLang; }
    if ($('navIndex') != null) { $('navIndex').href = "index.aspx?st=" + strState + "&l=" + uLang; }
    if ($('navCommute') != null) { $('navCommute').href = "congdong.aspx?st=" + strState + "&l=" + uLang; }
    if ($('navEvent') != null) { $('navEvent').href = "Events.aspx?st=" + strState + "&l=" + uLang; }
};
function geturllang() {
    var murl = window.location.href;
    if (murl.toLowerCase().indexOf('vnmap.aspx') == -1 && (murl.toLowerCase().indexOf('.aspx') != -1)) {   //tam thoi chi doi ngon ngu trang vnmap
        isLang = 0;
        return;
    }
    var ulang = 0;
    if (murl.indexOf("?l=") != -1) {
        ulang = murl.substr(murl.indexOf("?l=") + 3, 1);
    }
    else if (murl.indexOf("&l=") != -1) {
        var lang = murl.substr(murl.indexOf("&l=") + 3, 1);
    }
    else if (murl.indexOf("en/") != -1) ulang = 1;
    else ulang = 0;
    isLang = ulang;
    return;
};

function resizeWeb() {
    var windowSize = utils.windowSize();
    var left = 147;
    var leftRB = 996;
    var _leftRB = 7;
    if (utils.IE_Firefox() == -1) {
        if (windowSize[0] == curWindowSize[0] && windowSize[1] == curWindowSize[1]) {
            return;
        }
        left = 154;
        leftRB = 980;
        _leftRB = 13;
    }
    curWindowSize = windowSize;
    if ($('divPopUp')) {
        $('divPopUp').childElements().each(function(ele) {
            if (ele.visible())
                autoCompleteOnResize(ele);
        });
    }
    var divTmp = $('divErrorInfo');
    if (divTmp && divTmp.visible())
        loadErrorInfo($(divTmp.txtid));
    divTmp = $('divLinkDirect');
    if (divTmp && divTmp.visible()) {
        var _leftM = ((curWindowSize[0] > 980 ? curWindowSize[0] : (utils.IE_Firefox() != -1 ? 994 : 980)) - 980) / 2;
        divTmp.style.left = (_leftM + left) + 'px';
    }
    var pagename = document.URL.toLowerCase();
    if (pagename.indexOf('bando.aspx') != -1 || pagename.indexOf('details.aspx') != -1) {
        divTmp = $('DivPosACom');
        if (divTmp && divTmp.visible()) {
            copyPosition(true, null, divTmp, 0, 0);
        } else {
            divTmp = $('DivPos');
            if (divTmp && divTmp.visible()) {
                copyPosition(true, null, divTmp, 0, 0);
            }
            else {
                divTmp = $('divEmail');
                if (divTmp && divTmp.visible()) {
                    copyPosition(true, null, divTmp, 0, 0);
                }
                else {
                    divTmp = $('divLink');
                    if (divTmp && divTmp.visible())
                        copyPosition(true, null, divTmp, 0, 0);
                }
            }
        }
    }
    divTmp = $('divPopupDirect');
    if (divTmp && divTmp.visible()) {
        if (divTmp.name && divTmp.name != "") {
            if (pagename.indexOf('index.aspx') != -1)
                copyPosition(false, $(divTmp.name).up('div').next(), divTmp, -18, 0);
            else if (pagename.indexOf('directory.aspx') != -1)
                copyPosition(false, $(divTmp.name), divTmp, 18, 0);
            else
                divTmp.hide();
        }
        else {
            divTmp.hide();
        }
    }
    if (pagename.indexOf('viewphotos.aspx') != -1) {
        divTmp = $('dPopReport');
        if (divTmp && divTmp.visible())
            copyPosition(true, null, divTmp, 0, 0);
        divTmp = $('dPopEditImage');
        if (divTmp && divTmp.visible())
            copyPosition(false, $('aEditPhoto'), divTmp, 15, 0);
    }
    divTmp = $('divOtherCity');
    if (divTmp && divTmp.visible())
        copyPosition(false, $('divListCity'), divTmp, 35, 0);

    divTmp = $('divRecentBox');
    if (divTmp && divTmp.visible()) {
        var left;
        if (document.URL.toLowerCase().indexOf('index.aspx') != -1) left = _leftRB;
        else left = _leftRB - 10;
        var _leftM = parseInt(((curWindowSize[0] > 980 ? curWindowSize[0] : leftRB) - 980) / 2);
        if (idBox == 'A')
            divTmp.style.left = _leftM + left + 'px';
        else if (idBox == 'B')
            divTmp.style.left = _leftM + left + 295 + 'px';
    }


};

/*-----------------	MENU	-----------------------------------------------------------------------------*/
function changByClick(obj1, obj2, factor, radix, colorFr, colorTo, funcName) {
    try {
        $(obj1).select('a').each(function(obj) {
            $(obj).observe('click', function(e) {
                e = utils.getElementFireEvent(e);

                var _arr = $(this.parentNode.id).childElements();
                var _text = e.innerHTML.toString();
                changByClick_R(_arr, _text, obj2, factor, radix, colorFr, colorTo);
                if (funcName != null) funcName(e);
            });
        });
    } catch (ex) { }
};
function changByClick_R(arr, text, obj, factor, radix, colorFr, colorTo) {

    for (var i = 0; i < arr.length; i++) {
        if (arr[i].innerHTML.toString() == text) {
            $(obj).style.right = factor * i + radix + "px";
            arr[i].style.color = colorFr;
        }
        else {
            arr[i].style.color = ''
        }
    }
};
function changBySlide(obj1, obj2, factor, radix) {
    $(obj1).select('a').each(function(obj, i) {
        $(obj).observe('click', function(e) {
            e.preventDefault();
            e = utils.getElementFireEvent(e);

            if (e.id == 'aWriteComment') {
                setTimeout(function() {
                    window.location.href = "profiles/writeReview.aspx?st=" + strState;
                }, 0);
                return;
            }
            var _arr = $(obj1).childElements();
            var _arrtext = '';
            for (var j = 0; j < _arr.length - 1; j++) {
                _arrtext += _arr[j].down('a').innerHTML.toString() + ',';
            }
            _arr = _arrtext.split(',');
            var _text = e.innerHTML.toString();
            slide(_arr, _text, obj2, factor, radix, i);
        });
    });
};
function slide(arr, text, obj, factor, radix, idex) {
    var indexpage = ['index', 'vnmap', 'amthuc', 'giaitri', 'khachsan', 'muasam', 'lamdep', 'Directory'];
    for (var i = 0; i < arr.length - 1; i++) {
        if (arr[i].toString() == text) {
            new Effect.Parallel([
		        new Effect.Move($(obj), { sync: true, x: factor * i + radix, y: -3, mode: 'absolute' })
 			    ], {
 			        duration: 0.5, //duration: 1.0,
 			        delay: 0.01, //delay: 0.08,
 			        transition: Effect.Transitions.sinoidal,
 			        afterFinish: function() {
 			            try { var st = (strState != 'SaiGon') ? "?st=" + strState : ""; }
 			            catch (ex) { var st = "?st=SaiGon"; strState = "SaiGon"; }
 			            if (indexpage[idex] != '#')
 			                window.location.href = indexpage[idex] + ".aspx" + st;
 			        }
 			    });
        }
    }
};
//thay doi kieu tim kiem: duong di hay dia diem
function changeSearchType(e) {

    var div = $('divMaps');
    if (e.id == "aTabDirection") {
        div.hide();
        div.next().show();
    }
    else if (e.id == "aTabMaps") {
        div.show();
        div.next().hide();
    }
    hideErrorInfo();
};

function hoverDirMenu(e) {
    var divLinkDirect = $('divLinkDirect');
    if (divLinkDirect.visible()) {
        divLinkDirect.hide();
    }
    else {
        var _leftM = parseInt($('divMain').offsetLeft);
        divLinkDirect.style.left = (_leftM + 153) + 'px';
        if (utils.trim(divLinkDirect.innerHTML) == "")
            divLinkDirect.innerHTML = (isLang == 0 ? strDirHover : strDirHoverEN);
        divLinkDirect.show();
        divLinkDirect.observe('click', cateClick);
    }
    Event.stop(e);
};

//event click tren 1 don vi cua category
function cateClick(e) {
    var ele;
    try { ele = Event.element(e); } catch (exx) { ele = e; }
    if (ele.tagName != 'A' && ele.tagName != 'IMG') return;
    if (ele.className == 'aTitle' || ele.tagName == 'IMG') {
        //click tren category name
        if (ele.tagName == 'IMG')
            ele = ele.up();
        loadUnitPopup(ele);
        Event.stop(e);
    }
    else if (ele.className == 'aCloseFrame') {
        $('divPopupDirect').hide();
    }
    else {
        if (ele.id == "") return;
        var arr = ele.id.split('_');

        var sps = strState.substr(strState.length / 2);
        var url = "result.aspx?stpe=2&uID=" + utils.encode(arr[2], sps) + "&uN=" + encodeURIComponent(ele.innerHTML) + "&nID=" + arr[1] + "&st=" + strState;
        if (utils.IE7_Firefox() == 6)
            setTimeout(function() { window.location.href = url }, 0);
        else
            window.location.href = url;
    }
};
//event click tren Goc Binh Luan
function YPClick(e) {

    var ele = Event.element(e);
    if (ele == null) return;
    if (ele.tagName == "IMG")
        ele = ele.up();

    if ((ele.className == 'aTitle' || ele.id.indexOf('aservices') != -1) && ele.tagName == "A") {//click tren title
        var ks = ele.readAttribute('nameUnit').split('_');
        var rsURL = "result.aspx?st=" + strState;
        var sps = strState.substr(strState.length / 2);
        if (ks[2] == 1) // don vi
            rsURL += "&stpe=2&uID=" + ks[0] + "&uN=" + ks[1] + "&dID=" + ks[2];
        else   // nganh nghe
            rsURL += "&stpe=4&cID=" + utils.encode(escape(ks[0]), sps) + "&cN=" + ks[1] + "&dID=" + ks[2];
        setTimeout(function() {
            window.location.href = rsURL;
        }, 0);
    }


};
function loadUnitPopup(ele) {

    var id = parseInt(ele.id.split('_')[1]);
    var cate = oDirectory.dsCategory[id - 1];
    var unit = null;
    var numUnit = Math.ceil(cate.dsUnit.length / 2);
    var currUnit = 0;
    var html = '';

    for (var j = 0; j < 2; j++) {
        html += '<ul class="ulDirect">';
        for (var i = 0; i < numUnit; i++) {
            unit = cate.dsUnit[currUnit++];
            if (!unit) break;
            var name = "unit_" + unit.tDV;
            html += '<li><a name="' + name + '" id="unit_' + cate.m + '_' + unit.mDV + '" href="javascript:void(0);" title="' + unit.tDV + '">' + unit.tDV.truncate(25) + '</a></li>';
        }
        html += '</ul>';
    }

    var divPopupDirect = $('divPopupDirect');
    divPopupDirect.down('.DetailDirect').innerHTML = html;
    divPopupDirect.down('.spanTitleFrame').innerHTML = cate.t;

    var pos = (ele.tagName != "IMG") ? (ele.cumulativeOffset()) : (ele.previous().cumulativeOffset());
    divPopupDirect.setStyle({
        top: pos[1] + 18 + 'px',
        left: pos[0] + 'px'
    });

    divPopupDirect.show();
    divPopupDirect.observe('click', cateClick);
    divPopupDirect.name = (ele.tagName != "IMG") ? (ele.id) : (ele.previous().id);
};
function onclickTabComment(e) {
    e = utils.getElementFireEvent(e);
    if (e.tagName == 'SPAN') e = e.up(); /*kiem tra truong hop click tren mui ten*/
    if (e.tagName == 'LI' || e.tagName == 'UL') return;
    //T.Nguyen 8.7.10
    if (e.parentNode.childNodes[0].className != 'tab_hot') {
        $('uTabComments').select('a').each(function(ex) { ex.parentNode.className = ""; });
        e.parentNode.className = "active";
        count = 1;
        if (e.id == 'aTabOther')
            $('uSubTabComments').hide();
        else if (e.id == 'aTabCheckin' || e.id == 'aTabExper') {
            var langST = langSubTab();
            $('uSubTabComments').show();
            $('uSubTabComments').innerHTML = '<li class="active"><a href="javascript:void(0);"  id="aSubTabLatest">' + langST[0] + '</a></li>' +
                                            '<li><a href="javascript:void(0);" id="aSubTabBest">' + langST[1] + '</a></li>';
            onclickSubtabComment('uSubTabComments');
        }
        changeCommentsType(e);
    }
};
function changeCommentsType(obj) {

    var param = {};
    var window_href = window.location.toString().split('/');
    var url = window_href[window_href.length - 1].toLowerCase().split('.aspx')[0];
    switch (url) {
        case "amthuc": param.stpe = 5; param.id = 1; break;
        case "giaitri": param.stpe = 6; param.id = 4; break;
        case "khachsan": param.stpe = 7; param.id = 2; break;
        case "muasam": param.stpe = 8; param.id = 3; break;
        case "lamdep": param.stpe = 9; param.id = 6; break;
        case "yte": param.stpe = 9; param.id = 9; break;
        case "taichinh": param.stpe = 9; param.id = 7; break;
        case "dulich": param.stpe = 9; param.id = 5; break;
        default: param.stpe = 4; break;
    }
    param.st = strState;
    // onclick tab Xem Nhieu Nhat o cac trang chuyen muc
    var lang = langViewList()[isLang];
    if (obj.id == "aTabLatest") {
        $('divCommentBest').className = "hide";
        $('divCommentNews').className = "";
        var ele = $('uTabComments').next('.view_more');
        ele.down('.arrow').name = 'more';
        ele.down('.arrow').innerHTML = lang[2];
        var divCheckIn = $('tab_1');
        if (divCheckIn != null) divCheckIn.className = "hide";
        param.gt = "latest";
        if (strTabCommentNew == null || strTabCommentNew.length == 0) utils.call("comp.aspx", param, "POST", "loadCommentsNews", "loadCommentsNews");
        else $('divCommentNews').update(strTabCommentNew);
    }
    else if (obj.id == "aTabBest") {
        $('divCommentNews').className = "hide";
        $('divCommentBest').className = "";
        var ele = $('uTabComments').next('.view_more');
        ele.down('.arrow').name = 'more';
        ele.down('.arrow').innerHTML = lang[2];
        var divCheckIn = $('tab_1');
        if (divCheckIn != null) divCheckIn.className = "hide";
        param.gt = "most";
        if (strTabCommentBest.length == 0) utils.call("comp.aspx", param, "POST", "loadCommentsBest", "loadCommentsBest");
        else $('divCommentBest').update(strTabCommentBest);
    }
    else if (obj.id == "aTabHot" && document.URL.toLowerCase().indexOf('addfriend') != -1) {
        utils.call("comp.aspx", { stpe: 199, st: strState }, "POST", "newCheckinResponse", "newCheckinResponse");
    }
    //T.Nguyen 8.7.10, onclick tab Cac Hoat Dong Khac
    else if (obj.id == "aTabOther") {
        $('divCommentExper').className = "hide";
        $('divCommentCheckin').className = "hide";
        $("divCommentOther").className = "module_what_happened";
        $("divCommentOther").update('');
        displayBtnMore();
        //tab Cac Hoat Dong Khac cua trang index.aspx
        if (window.location.href.toLowerCase().indexOf("index") != -1) {
            for (var i = 0; i < 4; i++)
                loadOthers(i);
            $('divCommentOther').observe('click', onClickFeed);
        }
        //tab Cac Hoat Dong Khac trang CongDong.aspx
        /*else if (window.location.href.toLowerCase().indexOf("congdong") != -1) {
        k = 0;
        clearTimeout(timeout);
        for (var i = k; i < record; i++)
        loadItems(i);
        timeout = setTimeout(escalator, 3000);
        $('view_more').className = "hide";
        }*/
    }
    // onclick tab Check in
    else if (obj.id == "aTabCheckin") {
        $("divCommentExper").className = "hide";
        $("divCommentCheckin").className = "";
        $("divCommentOther").className = "hide";
        $('view_more').className = "view_more";
        clearTimeout(timeout);
        displayBtnMore();
        $("divCommentOther").update('');
        param.gt = "0";
        if (strTabCommentCheckinLastest.length == 0) utils.call("comp.aspx", { stpe: 200, st: strState, gt: 0 }, "POST", "loadCheckinLastest", "loadCheckinLastest");
        else $('divCommentCheckin').update(strTabCommentCheckinLastest).removeClassName('hide').siblings().invoke('addClassName', 'hide');
    }
    //onclick tab Cam Nhan
    else if (obj.id == "aTabExper") {
        $("divCommentExper").className = "";
        $("divCommentCheckin").className = "hide";
        $("divCommentOther").className = "hide";
        $('view_more').className = "view_more";
        clearTimeout(timeout);
        displayBtnMore();
        $("divCommentOther").update('');
        param.gt = "latest";
        if (strTabCommentLastest.length == 0) utils.call("comp.aspx", param, "POST", "loadExperLastest", "loadExperLastest");
        else $('divCommentExper').update(strTabCommentLastest);
    }
    else if (obj.id == 'aTabOthers') {
        $("divCommentOther").update("");
        k = 0;
        clearTimeout(timeout);
        for (var i = k; i < record; i++)
            loadItems(i, community);
        timeout = setTimeout(escalator, 3000);
    }

    //onclick tab 2Play
    else if (obj.id == 'aTabPlay') {
        $('divCommentOther').update("");
        if (strTabPlay.length == 0) utils.call("comp.aspx", { stpe: 130, type: "4" }, "POST", "loadPlay", "loadPlay");
        else {
            clearTimeout(timeout);

            for (var i = record - 1; i >= 0; i--)
                loadItems(i, strTabPlay);
            //timeout = setTimeout(escalator, 3000);
        }
    }

    //onclick tab 2Read
    else if (obj.id == 'aTabRead') {
        $('divCommentOther').update("");
        if (strTabRead.length == 0) utils.call("comp.aspx", { stpe: 130, type: "3" }, "POST", "loadRead", "loadRead");
        else {
            clearTimeout(timeout);

            for (var i = record - 1; i >= 0; i--)
                loadItems(i, strTabRead);
            //timeout = setTimeout(escalator, 3000);
        }
    }

    //onclick tab 2Go
    else if (obj.id == 'aTabGo') {
        $('divCommentOther').update("");
        if (strTabGo.length == 0) utils.call("comp.aspx", { stpe: 130, type: "2" }, "POST", "loadGo", "loadGo");
        else {
            clearTimeout(timeout);

            for (var i = record - 1; i >= 0; i--)
                loadItems(i, strTabGo);
            //timeout = setTimeout(escalator, 3000);
        }
    }
};
//Tab Moi checkin response
function newCheckinResponse(html) {
    $('tab_1').update(unescape(html)).removeClassName('hide').siblings().invoke('addClassName', 'hide');
};

function CommentClick(e) {
    var ele = Event.element(e);
    if (ele.tagName == "IMG") ele = ele.up();
    if ((ele.tagName != 'A' || ele.id == "") && ele.className.indexOf('star') == -1) return;
    var arr = ele.id.split('_');
    var pas = strState.substr(strState.length / 2);
    var url = null;
    if (arr[0].indexOf('Title') != -1) {//click tren title comment
        url = "details.aspx?st=" + strState + "&cID=" + utils.encode(arr[2], pas) + "&ll=" + utils.encode(arr[3] + ";" + arr[4], pas) + "&fTab=" + arr[1];
    }
    else if (arr[0].indexOf('cmtComp') != -1) { //click tren ten cong ty 
        url = "details.aspx?st=" + strState + "&cID=" + utils.encode(arr[1], pas) + "&ll=" + utils.encode(arr[3] + ";" + arr[4], pas) + "&fTab=" + arr[5];
    } else if (arr[0].indexOf('cmtMore') != -1) { // click len chi tiet
        url = "details.aspx?st=" + strState + "&cID=" + utils.encode(arr[2], pas) + "&fTab=" + arr[1];
    } else if (ele.className.indexOf('star') != -1) {//click tren ngoi sao 
        ele = ele.up(2).down('a', 0);
        var info = (ele.id).split("_");
        var url = "Profiles/comment.aspx?st=" + strState + "&cID=" + info[2];
    }
    else { // click len ten hinh avatar
        url = "profiles/history.aspx?mid=" + arr[1];
    }
    setTimeout(function() {
        window.location.href = url;
    }, 0);
};

//load khung move map, ID cua div chua khung, class cua div duoc insert vao
function loadFrame(id, cls) {
    var newE = map.setBorder(id, cls);
    newE.select('#aMoveTopLeft', '#aMoveTop', '#aMoveTopRight', '#aMoveLeft', '#aMoveRight', '#aMoveBottomLeft', '#aMoveBottom', '#aMoveBottomRight').invoke('observe', 'click', moveMapClick);
};
function moveMapClick(e) {
    var vid = utils.getElementFireEvent(e).id;
    var x, y = 100;
    x = (vid == 'aMoveTopLeft' || vid == 'aMoveLeft' || vid == 'aMoveBottomLeft') ? 0 - 100 : ((vid == 'aMoveTop' || vid == 'aMoveBottom') ? 0 : 100);
    y = (vid == 'aMoveLeft' || vid == 'aMoveRight') ? 0 : ((vid == 'aMoveTop' || vid == 'aMoveTopLeft' || vid == 'aMoveTopRight') ? 0 - 100 : 100);
    try { map.slider.slideBy(0 - x, 0 - y, 15, 20, 20); } catch (ex) { }
};
function showShadow(isShow) {
    var divShadow = $('divShadow');
    var divMain = $('divMain') || document.body;
    if (isShow) {
        //        divShadow.setStyle({
        //            width: (document.width || document.body.clientWidth) -10+ 'px',
        //            height: (document.height || document.body.clientHeight)-38 + 'px'
        //        });
        // divShadow.style.width = (document.body.offsetWidth < divMain.offsetWidth ? divMain.offsetWidth - 10 : document.body.offsetWidth - 10) + "px";
        //divShadow.style.height = (divMain.offsetHeight - 38) + "px";
        divShadow.show();
    }
    else {
        divShadow.hide();
    }
};
//xu ly vi tri cua auto complete khi resize
function autoCompleteOnResize(obj) {
    var idAnchor = obj.id.split('_')[1];
    var pos = $(idAnchor).cumulativeOffset();
    obj.setStyle({
        top: pos[1] + 25 + 'px',
        left: pos[0] - 2 + 'px'
    })
}; // xoa box search, tim
function clearBoxSearch(e) {
    var divMaps = $('divMaps');
    if (!divMaps.hasClassName('hide')) {
        var txt = $('txtSearchMaps');
        txt.value = "";
        txt.focus();
    }
    else {
        var txt1 = $('txtSearchA');
        var txt2 = $('txtSearchB');
        [txt1, txt2].each(function(obj) { obj.value = ""; });
        txt2.style.backgroundImage = '';
        txt1.focus();
    }

};
/*-----------------	DROPDOWNLIST	-----------------------------------------------------------------------------*/
function loadDDL(container, html) {
    var _ele = $(container).childElements();
    var spnddl = _ele[0];
    var toggle = _ele[1];
    toggle.innerHTML = html;
    spnddl.observe('click', function(el) {
        if (toggle.style.display == 'none') {
            toggle.show();
            var _arr = toggle.childElements();
            for (var i = 0; i < _arr.length; i++) {
                _arr[i].observe('click', function(e) {
                    e = utils.getElementFireEvent(e);
                    spnddl.innerHTML = '<span>' + e.innerHTML.toString() + '</span>';
                    toggle.hide();
                });
            }
        }
        else {
            toggle.hide();
        }
    });
};
function docClick(e) {
    try {
        if ($("ulBox_txtSearchYP")) $("ulBox_txtSearchYP").hide();
        var ele = null;
        if (e)
            ele = utils.getElementFireEvent(e).up().next();
        if ($('divMain')) $('divMain').select('.toggle').each(function(el) { if (el != ele) el.hide(); });
        else if ($('divMapBody')) $('divMapBody').select('.toggle').each(function(el) { if (el != ele) el.hide(); });
        ele = utils.getElementFireEvent(e);
        var divTmp = $('divLinkDirect');
        if (divTmp && divTmp.visible() && !ele.up('.divLinkDirect') && ele.id != 'divLinkDirect')
            divTmp.hide();

        if (ele.firstChild != null && ele.parentNode.parentNode.id == 'divSortSpec') {//loc theo ten,danh gia..
            var typeSort = findCharSort($("spnSortSpec").firstChild.innerHTML);
            if (typeSort != param.S) {
                param.S = typeSort;
                param.P = 1;
                try { oJax.transport.abort(); } catch (ex) { }
                showBoxLoading(true);
                utils.call("Comp.aspx", param, "POST", "showListCompany", "showListCompany");
                return;
            }
        }
        if (ele.firstChild != null && ele.parentNode.parentNode.id == 'divNumRow') {//loc theo so item
            var numRecord = $("spnNumRow").firstChild.innerHTML;
            if (numRecord != param.R) {
                param.P = 1;
                param.R = numRecord;
                showBoxLoading(true);
                try { oJax.transport.abort(); } catch (ex) { }
                utils.call("Comp.aspx", param, "POST", "showListCompany", "showListCompany");
                return;
            }
        }
        if (ele.firstChild != null && ele.parentNode.parentNode.id == 'divSortType') {
            var SortType = findSortType($("spnSortComment").firstChild.innerHTML);
            if (SortType != param.S) { param.S = SortType; param.oS = "Desc"; }
            else
                param.oS = (param.oS == "Desc") ? "Asc" : "Desc";
            try { oJax.transport.abort(); } catch (ex) { };
            param.vID = 0;
            utils.call("Comp.aspx", param, "POST", "showComment", "showComment");
            return;
        }
        var divTmp = $('divRecentBox');
        if (divTmp && divTmp.visible()) {
            divTmp.hide();
        }
    } catch (ex) { }
};

function createMapIcon(stype) {
    var drag = (arguments.length == 1) ? false : true;
    switch (stype) {
        case 0:
            var ypoint = (map.type == 3) ? ypoint = map.fixPoint.point.y / 2 : map.fixPoint.point.y;
            var point = new mapPoint(parseInt(map.cenPoint.x) * map.currentZoom / 100 - map.iMetaWidth, parseInt(ypoint) * map.currentZoom / 100 - map.iMetaHeigh);
            if (map.maker == null) { //setMapICon
                map.maker = new mapMaker(map.layerMaker.id, point, mapIcon(urlIcons + "common/icons/points/iconpoint.png", 41, 34, map.layerMaker.id + "M"), drag);

                map.maker.map = map;
                if (drag == false) map.makerI = new mapMaker(map.layerMaker.id, point, mapImgIcon(urlIcons + "common/icons/points/iconpoint.gif", 27, 28, map.layerMaker.id + "M"), false);
            } else {
                $(map.maker.id).setStyle({ left: point.x, top: point.y });
                if ($(map.makerI)) $(map.makerI.id).setStyle({ left: point.x, top: point.y });
            }
            map.maker.onclick = function(e) {//khac fuc loi khi click tren diem A, B hoac ngoi sao, icon cong ty dang active k bi xoa di
                resetIconState();
                createInfoBox(e);
            };

            break;
        case 1: //diem A

            var ypointA = (map.type == 3) ? ypoint = map.fixPoint.ABPoint[0].y / 2 : map.fixPoint.ABPoint[0].y;
            var point = new mapPoint(parseInt(map.ABPoint[0].x) * map.currentZoom / 100 - map.iMetaWidth, parseInt(ypointA) * map.currentZoom / 100 - map.iMetaHeigh);
            if (map.makerA == null) {
                map.makerA = mapMaker(map.layerMaker.id, point, setMapICon(urlIcons + 'common/icons/points/iconMap.png', 48, 30, 'iconPointA'), false, [9, -14]);

                if (drag == false) map.makerAI = mapMaker(map.layerMaker.id, point, mapImgIcon(urlIcons + 'common/icons/points/icon_A.gif', 27, 34, map.layerMaker.id + 'A'), false);
            }
            else {
                $(map.makerA.id).setStyle({ left: point.x, top: point.y });
                if ($(map.makerAI)) $(map.makerAI.id).setStyle({ left: point.x, top: point.y });
            }
            map.makerA.onclick = function(e) {
                resetIconState();
                createInfoBox(e);
            };
            break;
        case 2: // diem B
            var ypointB = (map.type == 3) ? ypoint = map.fixPoint.ABPoint[1].y / 2 : map.fixPoint.ABPoint[1].y;
            var point = new mapPoint(parseInt(map.ABPoint[1].x) * map.currentZoom / 100 - map.iMetaWidth, parseInt(ypointB) * map.currentZoom / 100 - map.iMetaHeigh);
            if (map.makerB == null) {
                //map.makerB = createExtIcon(map.layerMaker.id, point.x, point.y, 'iconPointB', map.layerMaker.id + 'B', 'B');
                map.makerB = mapMaker(map.layerMaker.id, point, setMapICon(urlIcons + 'common/icons/points/iconMap.png', 48, 30, 'iconPointB'), false, [9, -14]);
                if (drag == false) map.makerBI = mapMaker(map.layerMaker.id, point, mapImgIcon(urlIcons + 'common/icons/points/icon_B.gif', 27, 34, map.layerMaker.id + 'B'), false);
            }
            else {

                $(map.makerB.id).style.left = point.x + "px";
                $(map.makerB.id).style.top = point.y + "px";
                if ($(map.makerBI)) $(map.makerBI.id).setStyle({ left: point.x, top: point.y });
            }
            map.makerB.onclick = function(e) {
                resetIconState();
                createInfoBox(e);
            };
            break;
    }
};
// tim kiem xung quanh khu vuc, if trang dang tim la trang result thi dung ajax, neu khac thi chuyen ve trang result
function searchNearBy() {
    var txtNear = $("txtSearchNearBy");
    var rsURL = "";
    if (txtNear.value != "") {
        rsURL = "searchResult.aspx?st=" + strState;
        var sps = strState.substr(strState.length / 2);
        var pagename = window.location.pathname.toLowerCase();
        var aspx = pagename.indexOf(".aspx");
        //        rsURL += "&s=" + utils.encode(escape(txtNear.value), sps) + "&nb=" + utils.encode(escape($("txtSearchYP").value), sps);
        //        setTimeout(function() {
        //            window.location.href = rsURL;
        //        }, 0);

        if (pagename.indexOf("vnmap.aspx") != -1 || aspx == -1) { // la trang result => goi ajax
            //findCompany();
            showShadow4Search(true);
            var txt = $("txtSearchNearBy");
            var xy = ((inSearch == 0) ? map.cenPoint : ((map.layerPopup.pos == 0) ? map.ABPoint[0] : map.ABPoint[1]));
            strParamCom = "K=" + utils.encode(escape(txt.value), sps) + "&A=" + $("txtSearchYP").value + "&st=" + strState + "&R=" + 2 + "&stpe=" + 1 + "&P=1";
            var sort = $("txtSearchYP").value != "" ? "K" : "T";
            strParamCom += "&fE=1&C=&F=&S=" + sort + "&fD=0";
            if (pagename.indexOf("vnmap.aspx") != -1 || pagename.endsWith("/vn/") || pagename.endsWith("/en/") || pagename.endsWith("/"))//trang vnmap co search key quang cao
                strParamCom += "&pAds=1";
            try {
                paramCom = (strParamCom).toQueryParams(); //aramCom = (strParamCom + 1).toQueryParams();
            } catch (ex) { }
            utils.call("Comp.aspx", paramCom, "POST", "showListCompanyAdv", "showListCompanyAdv");
            //utils.call("Comp.aspx", paramCom, "POST", "showListCompany", "showListCompany");
        }
        else {
            rsURL += "&s=" + utils.encode(escape(txtNear.value), sps) + "&nb=" + utils.encode(escape($("txtSearchYP").value), sps);
            setTimeout(function() {
                window.location.href = rsURL;
            }, 0);
        }
    }
    else { // hien thi popup thong bao loi
        loadErrorInfo(txtNear);
    }
};
//show div error info
function loadErrorInfo(oTextbox) {

    var pos = oTextbox.cumulativeOffset();
    var divErrorInfo = $('divErrorInfo');
    //    var margin = [15, 360];
    //    if (utils.IE_Firefox() == 7) margin = [15, 300];
    divErrorInfo.setStyle({
        top: pos[1] + 33 + 'px',
        left: pos[0] - 7 + 'px'
    });
    divErrorInfo.show();
    divErrorInfo.txtid = oTextbox.id;
    divErrorInfo.down('#aCloseInfo').observe('click', hideErrorInfo);
};
//hide div error info
function hideErrorInfo() {
    var divErrorInfo = $('divErrorInfo');
    if (divErrorInfo.visible())
        divErrorInfo.hide();
};
function gotoFullMap() {
    var link = createFullLink("vnMap.aspx");
    window.open(link);
};
function createFullLink(page) {
    var strUrlVN = createLink(page) + "&w=" + isWard;
    try {
        if (map.Search == -1 || map.Search == 0) {
            if (oAdd)
                strUrlVN += "&s=0" + "&ex=1" + add2Text(oAdd, "A");
            else
                strUrlVN += "&s=0";
        } else if (map.Search == 1) {
            strUrlVN += "&s=1&ex=1" + add2Text(oAddA, "A") + add2Text(oAddB, "B");
        } else {
            var strUrlP = (window.location.toString()).split("?")[1];
            strUrlVN += (strUrlP != null ? "&" + strUrlP : "");
        }
        if (paramCom != null) {
            strUrlVN += "&" + (strParamCom.replace('&st=' + strState, '') + paramCom.P);
        }
    } catch (ex) { }
    return page + "?" + strUrlVN;

};
function add2Text(objAdd, pos) {
    var str = "";
    if (objAdd != null) {
        str += objAdd.no + ';' + objAdd.stName + ';' + objAdd.wName + ';' + objAdd.dName + ';' + objAdd.wID + ';' + objAdd.dID + ";";
        var xy = "0;0";
        if (inSearch == 0) {
            pos = "A";
            xy = map.maker.mx + ";" + map.maker.my;
        }
        else
            xy = (pos == "A") ? map.ABPoint[0].x + ";" + map.ABPoint[0].y : map.ABPoint[1].x + ";" + map.ABPoint[1].y;
        str += xy;
    }
    return ("&" + pos + "=" + utils.encode(escape(str), strState.substr(strState.length / 2)));
};
function createLink() {
    var mheight = (map.type == 3) ? map.iMetaHeigh * 2 : map.iMetaHeigh;
    var s = "l=" + isLang + "&st=" + strState;
    var df = (map.defaultZoom == undefined) ? DEFAULT_ZOOM : map.defaultZoom;
    s += "&n=" + map.currentZoom + ";" + df + ";" + map.iMetaWidth + ";" + mheight + ";";
    var srcImg = map.interLayer.childNodes[0].id.split('_');
    var srcImg3D = (map.type == 3) ? srcImg[2] * 2 : srcImg[2];
    s += srcImg[1] + ";" + srcImg3D + ";" + map.iWide + ";" + map.iHigh + ";" + map.type;
    // tinh vi tri trung tam
    var xleft = (parseInt(utils.rejectUnit(map.apiLayer.style.left)));
    var ytop = (parseInt(utils.rejectUnit(map.apiLayer.style.top)));
    //var dm = $("divMap").getDimensions();
    var dm = ($("divMap")) ? $("divMap").getDimensions() : $("divSmallMap").getDimensions();
    s += ";" + ((0 - xleft) + dm.width / 2 + map.iMetaWidth) + ";" + ((0 - ytop) + dm.height / 2 + mheight);
    s += ";" + map.cenPoint.x + ";" + map.cenPoint.y + ";" + map.Search + ";" + isWard;
    if ($("divToolTip") != null) {
        try {
            var toolTip = $("divToolTip").down('.aTTButtonClose').down('a');
        } catch (ex) { var toolTip = $("divToolTip").down('.attClose').down('a'); };
        if (toolTip != null && toolTip.name != undefined) {
            s += ('&sd=' + ($("divToolTip").style.display != 'none' ? toolTip.name : "-1"));
        }
    }
    if (document.URL.indexOf('cID=') != -1) {
        s += '&cID=' + document.URL.toQueryParams().cID;
    }
    return s;
};
function OffDirectoryBar() {

    if ($("divShadowP")) {
        $("divShadowP").style.display = "none";
        // chuyen on thanh off
        for (j = 0; j < $("divListCate").childNodes.length; j++) {
            if ($("divListCate").childNodes[j].className.indexOf('On') != -1) {
                $("divListCate").childNodes[j].className = $("divListCate").childNodes[j].className.replace('On', 'Off');
                return;
            }
        }
    }
};
function clickBoxSearch(e) {

    OffDirectoryBar();
    var location = window.location.pathname.toLowerCase();
    var axact = 0; var pp = ""; var pos = -1;
    var st = -1; // gia tri mac dinh, 0: tim dia diem, 1: duong di, -1: co loi

    var url = (location.indexOf('bando') != -1 || location.indexOf('vnmap') != -1 || location.indexOf('.aspx') == -1) ? "search.aspx" : "vnmap.aspx";
    var sA = $("txtSearchA");
    var sB = $("txtSearchB");
    var txtSearchMaps = null;
    var strA = utils.trim(sA.value);
    var strB = utils.trim(sB.value);
    var isSearchMaps = null; //true : tim diem, false: tim duong

    if (url == 'vnmap.aspx') {
        //cac trang khac         
        if (strA == "" && strB == "") { loadErrorInfo(sA); return; }
        if (strA == "" || strB == "") {
            isSearchMaps = true;
            if (strA == "") txtSearchMaps = sB;
            else txtSearchMaps = sA;
        }
        else isSearchMaps = false;
    }
    else {
        //trang vnmap
        //if ($("divMaps").visible()) {
        if ($("divMaps").className != "hide") {
            isSearchMaps = true;
            txtSearchMaps = $('txtSearchMaps');
        }
        else {
            isSearchMaps = false;
            if (strA == "" || strB == "") { // thong bao loi
                if (strA == "") loadErrorInfo(sA);
                else loadErrorInfo(sB);
                return;
            }
        }
    }

    if (!isSearchMaps) {// tim duong di 
        st = 1;
        strA = utils.encode(escape(strA), strState.substr(strState.length / 2));
        strB = utils.encode(escape(strB), strState.substr(strState.length / 2));

        // kiem tra gia tri pxy
        if (sA.pxy != -1 && sA.pxy != undefined) { axact++; pp = sA.pxy; pos = 0; }
        if (sB.pxy != -1 && sB.pxy != undefined) {
            if (axact == 1) { axact++; pp += ";" + sB.pxy; pos = 1; }
            else { axact = (axact == 0) ? 3 : axact + 2; pp = sB.pxy; }
        }
        if (pp == "") pp = "-1"; else pp = utils.encode(escape(pp), strState.substr(strState.length / 2));
        inSearch = 1;
        if (map) map.Search = 1;
    }

    else { // tim dia diem
        inSearch = 0;
        if (map) map.Search = 0;
        smsEnable = false;
        if (txtSearchMaps.value == "") { loadErrorInfo(txtSearchMaps); }
        else {
            var pagename = window.location.pathname.toLowerCase();
            if (chkAdv == true && (pagename.indexOf("vnmap.aspx") != -1 || pagename.endsWith("/vn/") || pagename.endsWith("/en/") || pagename.endsWith("/"))) {//quang cao tran vnMap
                var sps = strState.substr(strState.length / 2);
                var txt = $("txtSearchMaps");
                strParamCom = "K=" + utils.encode(escape(txt.value), sps) + "&A=" + "" + "&st=" + strState + "&R=" + 10 + "&stpe=" + 1 + "&P=1";
                var sort = $("txtSearchMaps").value != "" ? "K" : "T";
                strParamCom += "&fE=1&C=&F=&S=" + sort + "&fD=0&pAds=1";
                try {
                    paramCom = (strParamCom).toQueryParams();
                } catch (ex) { }
                utils.call("Comp.aspx", paramCom, "POST", "showListCompanyAdv", "showListCompanyAdv");
                return;
            }
            strParamCom = "";
            st = 0;
            strA = utils.encode(escape(txtSearchMaps.value), strState.substr(strState.length / 2));
            strB = "";
        }
        if (txtSearchMaps.pxy != -1 & (txtSearchMaps.pxy != undefined && txtSearchMaps.pxy.indexOf('undefined') != -1)) { axact = 1; pp = utils.encode(escape(txtSearchMaps.pxy), strState.substr(strState.length / 2)); }

    }
    if (st == -1) return;
    if (location.indexOf('bando') != -1 || location.indexOf('vnmap') != -1 || location.indexOf('.aspx') == -1) {

        var url = "search.aspx?st=" + strState + "&stpe=" + st;
        var param = (st == 0) ? ((axact == 1) ? { "A": strA, "w": isWard, "ex": axact, "fp": 0, pp: pp} : { "A": strA, "w": isWard, "ex": axact, "fp": 0 }) : { "A": strA, "B": strB, "w": isWard, "fp": pos, "ex": axact, "pp": pp };
        var strfunc = (st == 0) ? "searchResult" : "directResult";
        var divIcon = $('divIcon');
        if (divIcon && $('divMapBody')) {
            var wh = $('divMap').getDimensions();
            divIcon.setStyle({
                'left': (wh.width - 32) / 2 + 'px',
                'top': (wh.height + 93) / 2 + 'px',
                'display': 'block'
            });
        }
        else {
            copyPosition(true, null, divIcon, 0, 0);
            divIcon.show();
        }
        utils.call("search.aspx?st=" + strState + "&stpe=" + st, param, 'POST', strfunc, strfunc);

    }
    else {
        strB = (strB == "") ? "" : "&B=" + strB;
        isWard == undefined ? isWard = '-1' : isWard; //xem lai
        setTimeout(function() { window.location.href = url + "?st=" + strState + "&w=" + isWard + "&s=" + st + "&A=" + strA + strB; }, 0);
    }
};
// gan gia tri vao doi tuong obj, gom 2 truong hop: chuoi cach nhau dau _(sn, tenduong, ten phuong, ten quan, ma phuong, ma quan), or tung gia tri rieng biet (no, sName, dname, did, wname, wid, pos)
function assign2Add(oad) {

    if (oad == null) oad = new Address();
    if (arguments.length == 4) { // truong hop phai cat chuoi , agrment[2] la pos A or  B, agrment[3]: la chuoi phan cach : _ or , or ;...

        var rplace = arguments[1].toLowerCase().replace("q.", "").replace('p.', '').replace("q. ", "").replace('p. ', '').replace('wrd', '').replace('dist', '');
        var ad = utils.toProperCase(rplace).split(arguments[3]);
        if (ad.length > 3) {
            oad.no = (ad[0] == "0" || ad[0] == "undefined") ? "" : ad[0];
            oad.stName = utils.toProperCase(utils.trim(ad[1]));
            oad.dName = (ad[3] == "0") ? "" : utils.toProperCase(utils.trim(ad[3]));
            oad.wName = (isWard == 1) ? "" : (ad[2] == "0") ? "" : utils.toProperCase(utils.trim(ad[2]));
            oad.wID = ad[4];
            oad.dID = ad[5];
            oad.pos = arguments[2];
        } else {
            if (isWard == -1) { // co day du phuong quan
                if (ad.length == 3) { // truong hop ko co so nha
                    oad.no = '';
                    oad.stName = utils.toProperCase(utils.trim(ad[0]));
                    oad.dName = (ad[2] == "0") ? "" : utils.toProperCase(utils.trim(ad[2]));
                    oad.wName = (isWard == 1) ? "" : ((ad[1] == "0") ? "" : utils.toProperCase(utils.trim(ad[1])));
                    oad.wID = ad[4];
                    oad.dID = ad[5];
                    oad.pos = arguments[2];
                }
            }
            else if (isWard == 1) { // chi co quan 
                if (ad.length == 3) { // co day du so nha, duong, quan 
                    oad.no = (ad[0] == "0" || ad[0] == "undefined") ? "" : ad[0];
                    oad.stName = utils.toProperCase(utils.trim(ad[1]));
                    oad.dName = (ad[2] == "0") ? "" : utils.toProperCase(utils.trim(ad[2]));
                    oad.wName = "";
                    oad.wID = 0;
                    oad.dID = 0;
                    oad.pos = arguments[2];
                }
                else { // ko co so nha
                    oad.no = '';
                    oad.stName = utils.toProperCase(utils.trim(ad[0]));
                    oad.dName = (ad[1] == "0") ? "" : utils.toProperCase(utils.trim(ad[1]));
                    oad.wName = "";
                    oad.wID = 0;
                    oad.dID = 0;
                    oad.pos = arguments[2];
                }

            }
            else if (isWard == 0) { // co phuong, khong quan
                if (ad.length == 3) { // co day du so nha, duong, quan 
                    oad.no = (ad[0] == "0" || ad[0] == "undefined") ? "" : ad[0];
                    oad.stName = utils.toProperCase(utils.trim(ad[1]));
                    oad.dName = '';
                    oad.wName = (ad[2] == "0") ? "" : utils.toProperCase(utils.trim(ad[2]));
                    oad.wID = 0;
                    oad.dID = 0;
                    oad.pos = arguments[2];
                }
                else { // ko co so nha
                    oad.no = '';
                    oad.stName = utils.toProperCase(utils.trim(ad[0]));
                    oad.dName = '';
                    oad.wName = (ad[1] == "0") ? "" : utils.toProperCase(utils.trim(ad[1]));
                    oad.wID = 0;
                    oad.dID = 0;
                    oad.pos = arguments[2];
                }
            } else {

            }
        }
    }
    else { // gan truc tiep 
        oad.no = (arguments[1] == "0") ? "" : arguments[1];
        oad.stName = arguments[2];
        oad.dName = arguments[3];
        oad.wName = (isWard == 1 || isWard == 2) ? "" : arguments[5];
        oad.wID = arguments[6];
        oad.dID = arguments[4];
        if (isWard == "2") { oad.dName = ""; oad.wName = ""; }
        oad.wName = utils.toProperCase((oad.wName != "" & oad.wName != "0") ? oad.wName : "");
        oad.dName = utils.toProperCase((oad.dName != "" & oad.dName != "0") ? oad.dName : "");
        oad.pos = arguments[7];
    }
    oad = insertText(oad);
    return oad;
};
function loadEventOtherCity() {
    if ($('aOthers') != null) {
        $('aOthers').onclick = function() {
            var arrPos = $('divListCity').cumulativeOffset();
            $('divOtherCity').style.left = arrPos[0] + 'px';
            $('divOtherCity').style.top = (arrPos[1] + 35) + 'px';
            $('divOtherCity').toggle();
        }
    }
};
// ham resize shadow va gan lai left cho form SignIn/SignOut
function mainResize() {
    try {
        var ow = 0;
        var divMain = document.body.down('.page');
        if (divMain) ow = divMain.offsetWidth;
        var strUrlResize = window.location.href;
        var box = $('box');
        if (box && box.visible() && box.hasClassName('box_others')) { box.clonePosition($("aChageCity/Province"), { setWidth: false, setHeight: false, offsetLeft: -5, offsetTop: 30 }); return; } /*04/05/2010*/
        if (box && box.visible() && box.hasClassName('filterarea')) { box.clonePosition($("afilterDistMore"), { setWidth: false, setHeight: false, offsetLeft: -5, offsetTop: 30 }); return; }
        if ($('box').hasClassName('box_units')) {
            if (document.URL.toLowerCase().indexOf('directory.aspx') != -1) {//trang directory
                var box = $('box');
                if (box && box.visible()) {
                    var cateName = box.down('h4').innerHTML;
                    $('ulSortCate').select('h4').each(function(s) {
                        var val = s.down('a').down('span').innerHTML;
                        if (val == cateName) {
                            var objOther = s.next(1).down('a');
                            box.clonePosition(objOther, { setWidth: false, setHeight: false, offsetLeft: -10, offsetTop: 20 });
                            return;
                        }
                    });
                }
            } else {// 8 chuyen muc
                if (box && box.visible()) { box.clonePosition($("divOther"), { setWidth: false, setHeight: false, offsetLeft: -5, offsetTop: 30 }); return; }
            }
        } else {
            if ($('box')) $('box').style.left = (document.body.offsetWidth / 2) - ($('box').offsetWidth / 2) + "px";
            var box = $('box');
            if (box && box.visible()) {
                var sizeW = utils.windowSize();
                var boxL = (sizeW[0] - box.getDimensions().width) / 2;
                var boxT = (sizeW[1] - box.getDimensions().height + 10) / 2;
                boxL = (boxL > 0 ? boxL : 0);
                boxT = (boxT > 0 ? boxT : 10);
                box.style.left = boxL + 'px';
                box.style.top = boxT + 'px';
            }
        }
    } catch (ex) { }
};
//Dao chieu duong di
function textReverse() {
    var txtA = $('txtSearchA');
    var txtB = $('txtSearchB');
    var textA = txtA.value;
    var textB = txtB.value;
    var text;
    text = textA;
    var ishowA = txtA.next().visible(); /*edit 11/03/2010*/
    (txtB.next().visible()) ? txtA.next().show() : txtA.next().hide();
    ishowA ? txtB.next().show() : txtB.next().hide();


    var Bxy = txtB.pxy;
    txtA.value = textB;
    txtB.pxy = txtA.pxy;
    txtA.pxy = Bxy;
    txtB.value = text;
};
/*
tao ra 1 icon voi toa do x,y, width, height, src, tra ve doi tuong 
id: la id cua layer gan maker vao 
*/
function createCustomIcon(id, x, y, wh, ht, cusIcon, iconID) {
    return mapMaker(id, new mapPoint(x, y), mapIcon(cusIcon, wh, ht, iconID), false);
};
/*TOOLTIP*/
function tooltipClick(e) {
    try {
        var ele = (e.tagName == 'A') ? e : Event.element(e);
    } catch (ex) { ele = Event.element(e) };
    if (ele.className == 'sToolTipBack') ele = ele.up();
    if (ele.className == 'txt') {
        (navigator.appName.indexOf('Opera') != -1) ? ele.focus() : ele.select();
        ele.observe('keydown', enterSearchNearPoint);
    }
    else {
        var txt = $('divToolTip').down('.txt');
        if (txt && txt.visible()) {
            txt.blur();
            txt.observe('keydown', enterSearchNearPoint);
        }
    } if (ele.tagName == "SPAN" && ele.down('a') != null && ele.down('a').className == "aToolTipButton") {//truong hop tim xung quanh ie6 
        ele = ele.down('a');
    } else if (ele.className.indexOf('star') != -1) {
        var ele = utils.getElementFireEvent(e);
        ele = ele.up('UL');
        var info = (ele.id).split("_");
        var url = "Profiles/comment.aspx?st=" + strState + "&cID=" + info[1];
        if (utils.IE7_Firefox() == 6)
            setTimeout(function() { window.location.href = url; }, 0);
        else window.location.href = url;
        return;
    }
    else if (ele.tagName != 'A') { Event.stop(e); return; }
    var className = ele.className;
    if (className == '') ele = ele.up();
    switch (ele.className) {
        case 'attClose':
            ele = ele.up('.dToolTip');
            closeToolTip(ele);
            break;
        case 'attDetail':
            if (ele.id != "") {
                var id = ele.id.split('_');
                var pas = strState.substr(strState.length / 2);
                var url = "details.aspx?st=" + strState + "&cID=" + utils.encode(id[1], pas) + "&ll=" + utils.encode(id[3] + ";" + id[4], pas);
                if (utils.IE7_Firefox() == 6)
                    setTimeout(function() { window.location.href = url; }, 0);
                else window.location.href = url;
            }
            break;
        case 'attSnapshot':
            try { oSnapShot.captureMap(); } catch (ex) { };
            break;
        case 'aTTCompOnStreet': // tim cong ty tren duong nay
            var xy = null;
            showShadow4Search(true);
            if (ele.id == "") {// khi click len icon diem tim diem,A or B
                var uadd = (inSearch == 0) ? oAdd : (map.layerPopup.pos == 0) ? oAddA : oAddB;
                xy = ((inSearch == 0) ? map.cenPoint : ((map.layerPopup.pos == 0) ? map.ABPoint[0] : map.ABPoint[1]));
                strParamCom = "sn=" + utils.encode(escape(uadd.stName), strState.substr(strState.length / 2)) /*Quang 29/08*/ + "&st=" + strState + "&num=" + 6 + "&stpe=" + 17 + "&XY=" + xy.x + "_" + xy.y + "&dID=" + ((uadd.dID == undefined || uadd.dID == '') ? 0 : uadd.dID) + "&P=";
            }
            else {//khi click len icon cong ty
                xy = ele.id.split("_");
                strParamCom = "sn=" + utils.encode(xy[9], strState.substr(strState.length / 2))/*Quang 29/08*/ + "&st=" + strState + "&num=" + 6 + "&stpe=" + 17 + "&XY=" + xy[6] + "_" + xy[7] + "&dID=" + xy[8] + "&P=";
            }
            paramCom = (strParamCom + 1).toQueryParams();
            utils.call("Comp.aspx", paramCom, "POST", "showCompanyResult", "showCompanyResult");
            break;
        case 'aToolTipBack':
            ele = ele.up('.liToolTipForm');
            ele.hide();
            ele.previous().show();
            break;
        case 'aToolTipButton': // tim xung quanh
            var txt = (ele.up().previous().className == "txt") ? ele.up().previous() : ele.previous();
            if (txt.value != '') {
                var xy = null;
                showShadow4Search(true);
                if (ele.up(".liToolTipForm").previous().down(".aTTSearchNearBy").id == "") {
                    xy = ((inSearch == 0) ? map.cenPoint : ((map.layerPopup.pos == 0) ? map.ABPoint[0] : map.ABPoint[1]));
                }
                else {//khi click len icon cong ty
                    xy = ele.up(".liToolTipForm").previous().down(".aTTSearchNearBy").id.split("_");
                    xy = { "x": xy[6], "y": xy[7] };
                }
                strParamCom = "K=" + txt.value + "&XY=" + xy.x + "_" + xy.y + "&st=" + strState + "&num=" + 6 + "&stpe=" + 16 + "&P=";
                paramCom = (strParamCom + 1).toQueryParams();
                utils.call("Comp.aspx", paramCom, "POST", "showCompanyResult", "showCompanyResult");
            }
            break;

        case 'aTTSearchNearBy':
            ele = ele.up('.liToolTipLinks');
            ele.hide();
            ele.next().show();
            break;
        case 'aTTFromHere':
            fromHereToHere(ele);
            if ($("txtSearchA") != null) $("txtSearchA").pxy = '-1';
            break;
        case 'aTTToHere':
            fromHereToHere(ele);
            if ($("txtSearchB") != null) $("txtSearchB").pxy = '-1';
            break;
    }
};
//event key enter when search company nearpoint
function enterSearchNearPoint(e) {
    e = e || window.event;
    if ((e.keyCode == "13" || e.which == "13" || e.charCode == "13")) {
        var txtNearPoint = $('divToolTip').down('.aToolTipButton');
        if (txtNearPoint != null && $('divToolTip').down('input').value != "") {
            if (document.URL.toLowerCase().indexOf('vnmap.aspx') != -1)
                tooltipFullClick(txtNearPoint);
        }
        else
            tooltipFullClick(txtNearPoint);
        if (e.preventDefault) e.preventDefault();
    }
};
//hide tooltip
function closeToolTip(ele) {
    ele.hide();
    var id = ele.id.split('_')[1];
    // $('divToolTipShadow_' + id).hide();
    if ($('divToolTipShadow_' + id)) $('divToolTipShadow_' + id).hide();
    if ($('divToolTipShadow')) $('divToolTipShadow').hide();

    resetIconState();
};
function resetIconState() {
    var activeIcon = map.layerMaker.down('.iconSelected'); //icon dang duoc chon
    //dua icon dang duoc chon ve binh thuong
    if (activeIcon) {
        activeIcon.removeClassName('iconSelected');
        activeIcon.style.zIndex = '';
        var blueIcon = (activeIcon.id.indexOf('DdtacMap') == -1) ? (urlIcons + 'common/icons/points/iconBig.png') : (urlIcons + 'common/icons/points/iconMapLblue.png');
        if (utils.IE7_Firefox() != 6)
            activeIcon.style.backgroundImage = 'url(' + blueIcon + ')';
        else
            activeIcon.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + blueIcon + "',sizingMethod=crop)";
    }
}; function activeIconState(icon) {
    if (icon) {
        var redIcon = (icon.id.indexOf('DdtacMap') == -1) ? (urlIcons + 'common/icons/points/iconBigHover.png') : (urlIcons + 'common/icons/points/iconMapRedPoint.png');
        icon.style.zIndex = 1;
        icon.addClassName('iconSelected');
        if (utils.IE7_Firefox() != 6)
            icon.style.backgroundImage = 'url(' + redIcon + ')';
        else
            icon.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + redIcon + "',sizingMethod=crop)";
    }
};
/*END TOOLTIP*/
function fromHereToHere(e) {

    var divDirection = $('divDirection');

    var txtSearch = null;
    if (e.className.indexOf('From') != -1)
        txtSearch = divDirection.down('#txtSearchA');
    else
        txtSearch = divDirection.down('#txtSearchB');
    var name = e.name.split(";");
    if (name.length > 1) txtSearch.pxy = name[1] + "_" + name[2];
    txtSearch.value = convert2Address(name[0]); //convert2Address(name[0]).replace(',', '');
    txtSearch.Add = name[0];
    txtSearch.style.backgroundImage = 'none';
    if (divDirection.style.display != 'block')/*edit 03/03/2010*/
        onChangeTab($('aTabDirection'));
    txtSearch.focus();
    hideErrorInfo();
};
//load dia chi theo tieng Anh/Viet
function combineAdd(oAdd) {
    var _str = '';
    if (oAdd.no != "0")
        _str += oAdd.no + ' ';

    _str += oAdd.stName;
    if (isWard == 1) { oAdd.wName = ''; }

    if (isLang == 0) {
        if (oAdd.wName != '')
            _str += ', P.' + (isNaN(oAdd.wName) ? ' ' : '') + oAdd.wName;
        _str += ', Q.' + (isNaN(oAdd.dName) ? ' ' : '') + oAdd.dName;
    }
    else {
        _str += isNaN(oAdd.wName) ? (", " + oAdd.wName + ' Wrd') : (', Wrd ' + oAdd.wName);
        _str += isNaN(oAdd.dName) ? (", " + oAdd.dName + ' Dist') : (', Dist ' + oAdd.dName);
    }
    return _str;
};
// clse cac box thong bao  va div chua no'
function closeNote(obj) {
    try {
        [obj.parentNode.parentNode, $("divShadow")].each(function(item) { item.style.display = "none"; });
    } catch (ex) { }
};
function replaceJSON(strhtml) {
    return strhtml;
};
function substr(value, len) {
    if (value == "" || len > value.length) return value;
    return value.substring(0, len - 3) + "...";
};
function convert2Address(strAdr) {
    if (strAdr == null || strAdr == "") return "";
    if (typeof (strAdr) == "object") {
        strAdr = strAdr.no + "," + strAdr.stName + "," + strAdr.wName + "," + strAdr.dName;
    }
    var infoAdd = (strAdr.indexOf(",") != -1) ? strAdr.split(",") : strAdr.split("_");
    infoAdd.select(function(itm, index) { infoAdd[index] = utils.trim(itm); });
    var strReturn = (infoAdd[0] != "0" && infoAdd[0] != 'undefined' && infoAdd[0] != '') ? utils.toProperCase(utils.trim(infoAdd[0])) : ""; /*edit 14/12/2009*/
    if (infoAdd.length == 1) return strReturn;
    strReturn += (((strReturn != "") ? ", " : "") + utils.toProperCase(utils.trim(infoAdd[1])));
    if (isWard != 2) {
        var lang = lang4TabPopUp()[isLang];
        var wname = '';
        var dname = '';
        if (infoAdd.length == 3) {//fortmat:no,street,dname or wname(tuy theo thanh pho ma la dname hay wname tuong uong)
            if (isWard == 1)//tham so thu 3 la quan
                dname = (infoAdd[2] != "" && infoAdd[2] != "0" && infoAdd[2] != undefined) ? utils.trim(infoAdd[2].replace("Q.0", "").replace("Q.", "").replace("Dist", "")) : "";
            else
                wname = (infoAdd[2] != "" && infoAdd[2] != "0" && infoAdd[2] != undefined) ? utils.trim(infoAdd[2].replace("P.0", "").replace("P.", "").replace("Wrd", "")) : ""; //edit 16/11/2009
        } else {//syntax no,streetname,wname,disname :format chuan
            wname = (isWard == 1) ? "" : ((infoAdd[2] != "" && infoAdd[2] != "0" && infoAdd[2] != undefined) ? utils.trim(infoAdd[2].replace("P.0", "").replace("P.", "").replace("Wrd", "")) : "");
            dname = (infoAdd[3] != "" && infoAdd[3] != "0" && infoAdd[3] != undefined) ? utils.trim(infoAdd[3].replace("Q.0", "").replace("Q.", "").replace("Dist", "")) : "";
        }
        if (wname != "") {
            wname = (isLang == 1) ? ConvertFromVNToEng(utils.trim(wname.toLowerCase().replace('x.', '').replace('tt.', ''))) : wname;
            wname = (isLang == 0) ? ((wname.toLowerCase().indexOf('x. ') != -1 || wname.toLowerCase().indexOf('tt. ') != -1) ? wname : (wname.toLowerCase().indexOf('x.') != -1 || wname.toLowerCase().indexOf('tt.') != -1) ? wname.replace('.', '. ') : lang[1] + " " + wname) : (utils.RegNum(wname) == true ? lang[1] + " " + utils.toProperCase(wname.replace('X.', '').replace('x.', '')) : utils.toProperCase(wname.replace('X.', '').replace('x.', '')) + " " + lang[1]);
        }
        if (dname != "") {
            dname = (isLang == 1) ? ConvertFromVNToEng(utils.trim(dname.toLowerCase().replace('h.', ''))) : dname;
            dname = (isLang == 0) ? ((dname.toLowerCase().indexOf('. ') != -1) ? dname : (dname.toLowerCase().indexOf('.') != -1) ? dname.replace('.', '. ') : lang[2] + " " + dname) : (utils.RegNum(dname) == true ? lang[2] + " " + utils.toProperCase(dname.replace('H.', '').replace('h.', '')) : utils.toProperCase(dname.replace('H.', '').replace('h.', '')) + " " + lang[2]);
        }
        switch (parseInt(isWard)) {
            case -1: strReturn += ((wname != "") ? ", " + utils.toProperCase(wname) : "") + ((dname != "") ? ", " + utils.toProperCase(dname) : ""); break;
            case 1: strReturn += (dname != "") ? ", " + utils.toProperCase(dname) : ""; break;
            case 0: strReturn += (wname != "") ? ", " + utils.toProperCase(wname) : ""; break;
        }
    }
    strReturn = (isLang == 0) ? strReturn : ConvertFromVNToEng(strReturn);
    return (utils.trim(strReturn));
};
function getHotSpot() {
    var url = window.location.href.toLowerCase();
    var isHotSpot = false;
    var indexpage = ['index', 'amthuc', 'giaitri', 'khachsan', 'muasam', 'lamdep', 'diadiem.com.vn/'];
    var divHotSpotContent = $("divHotSpotContent");
    for (var i = 0; i < indexpage.length; i++) {
        if (url.indexOf(indexpage[i]) != -1 & divHotSpotContent != null) {
            isHotSpot = true;
            break;
        }
    }
    if (isHotSpot) {
        $('divHotSpotContent').observe('click', clickHotSpot);
        loadHotSpot(strHotSpot);
    }
};
//xu ly kq tu server tra ve
function loadHotSpot(str) {
    if (str == "-1") {
        var divContent = $('divHotSpotContent');
        divContent.innerHTML = ""; oHotSpot = null; clearTimeout(timer);
        if ($('aHSPrevious')) {
            $('aHSPrevious').hide();
            $('aHSNext').hide();
        }
        return;
    }
    try {
        oHotSpot = str.evalJSON(true);
    } catch (exc) { oHotSpot = str; }
    if (oHotSpot.dsHotSpot.length < 1) {
        $('divHotSpotContent').innerHTML = "";
        oHotSpot = null;
        clearTimeout(timer);
        if ($('aHSPrevious')) {
            $('aHSPrevious').hide();
            $('aHSNext').hide();
        }

        return;
    }
    // khong su dung // showContentHotSpot(iHotpot);

};
// hien thi noi dung HotSpot
function showContentHotSpot(index) {
    //debugger
    var divContent = $('divHotSpotContent');
    iHotpot = (index < 0) ? (oHotSpot.dsHotSpot.length - 1) : (index == oHotSpot.dsHotSpot.length ? 0 : index);
    var oHSpot = oHotSpot.dsHotSpot[iHotpot];
    oHSpot.td = replaceJSON(oHSpot.td);
    oHSpot.nd = replaceJSON(oHSpot.nd);
    var strImg = (oHSpot.Pic == '') ? "images/graphics/noPic200x160.jpg" : httpImages + "Images_" + strState + "/" + oHSpot.Pic;
    var url = "viewList.aspx?st=" + strState + "&lID=" + utils.encode(oHSpot.lID, strState.substr(strState.length / 2));
    var strHTML = '<div class="divHotSpotIMG"><a href="' + url + '"><img  id="' + oHSpot.lID + '" alt="' + oHSpot.td + '" src="' + strImg + '"/></a></div>' +
	        ' <div class="divHotSpotDetail">' +
		        '<div class="divHotSpotText">' +
			        '<h1>' +
				        '<a href="' + url + '" id="' + oHSpot.lID + '"> ' + oHSpot.td + '</a>' +
			        '</h1>' +
			        '<p>' + ((oHSpot.nd.length > 160) ? (substr(oHSpot.nd, 160) + '<a href="' + url + '" id="' + oHSpot.lID + '">' + lang4Category()[isLang][4] + '</a>') : oHSpot.nd) + '</p>' +

		        '</div>' +
    '</div>';
    divContent.update(strHTML);

    if (oHotSpot.dsHotSpot.length == 1)
        clearTimeout(timer);
    else { }

    timer = setTimeout("showContentHotSpot(" + (Math.floor(Math.random() * oHotSpot.dsHotSpot.length)) + ")", 2500 * 10);
};
function clickHotSpot(e) {
};
function loadPartnerLinks() {
    var divPartnerLinks = $('divPartnerLinks');
    if (divPartnerLinks) {
        var oPartner = getPartnerLinks();
        var links = '';
        for (var i = 0, len = oPartner.length; i < len; i++) {
            var oTmp = oPartner[i];
            links += '<ul><li class="li_subtitle">' + oTmp.group + '</li>';
            for (var j = 0, lenJ = oTmp.list.length; j < lenJ; j++)
                links += '<li><a rel="nofollow" target="_blank" href=' + oTmp.list[j].link + '>' + oTmp.list[j].name + '</a></li>';
            links += '</ul>';
        }
        divPartnerLinks.innerHTML = links;
    }
};
function clickKeyWord(e) {

    var e = Event.element(e, 'a');
    if (e.id != 'divTopKeyWord')
        if (e.id.length > 1) setTimeout(function() { window.location.href = "Result.aspx?&s=" + e.id + "&nb=&st=" + strState; }, 0);
};
function createBookMark(title, url) {
    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);
    }
};
//hien thi trang Print map
function showPrintPage() {

    var link = createFullLink("print.aspx");
    window.open(link);
};
function hotSpotRollover(e) {
    var ele = Event.element(e);
    var divContPopular = ele.up('.one_cate');
    var imgObj = divContPopular.down('img');
    if (e.type == 'mouseover') {

        if (ele.readAttribute('imgLink') != null) {
            imgObj.src = ele.readAttribute('imgLink');
            imgObj.up('a').href = ele.href;
            divContPopular.select('a').each(function(element) { element.style.fontWeight = ''; });
            ele.style.fontWeight = '700';
        }
    }
};
//event key enter when search street
function enterSearchStreet(e) {

    e = e || window.event;
    if ((e.keyCode == "13" || e.which == "13" || e.charCode == "13")) {
        var ele = utils.getElementFireEvent(e);
        //debugger
        var arr = ['ulBox_txtSearchMaps', 'ulBox_txtSearchA', 'ulBox_txtSearchB', 'txtSearchMaps', 'txtSearchB'];
        for (var i = 0; i < arr.length; i++) {
            if (arr[i].indexOf(ele.id) != -1) {
                if (arr[i].indexOf('ulBox') != -1) {
                    if ($(arr[i]).style.display == "none") {
                        chkAdv = true;
                        clickBoxSearch();
                    }
                }
                else {
                    chkAdv = true;
                    clickBoxSearch();
                }

                if (e.preventDefault) e.preventDefault();
                break;
            }
        }
    }
};
//event key enter when search company nearby
function enterSearchNearBy(e) {
    e = e || window.event;
    if ((e.keyCode == "13" || e.which == "13" || e.charCode == "13")) {
        if ($('ulBox_txtSearchYP').style.display == "none")
            searchNearBy();
        if (e.preventDefault) e.preventDefault();
    }
};
function searchComp(strResult) {
    try {
        objFindComp = strResult.evalJSON(true);
    } catch (execc) { objFindComp = strResult; };
    try {
        showShadow4Search(true);
    } catch (ex) { }
    if (parseInt(objFindComp.stpe) == 16) {
        strParamCom = "K=" + objFindComp.k + "&XY=" + objFindComp.xy + "&st=" + objFindComp.st + "&num=" + objFindComp.num + "&stpe=" + objFindComp.stpe + "&P=";
    } else if (parseInt(objFindComp.stpe) == 17) {
        strParamCom = "sn=" + objFindComp.sn + "&st=" + objFindComp.st + "&num=" + objFindComp.num + "&stpe=" + objFindComp.stpe + "&XY=" + objFindComp.xy + "&dID=" + objFindComp.dID + "&P=";

    }

    paramCom = (strParamCom + objFindComp.p).toQueryParams();
    utils.call("Comp.aspx", paramCom, "POST", "showCompanyResult", "showCompanyResult");
};
function showSendEmailPopup(html) {
    var box = $('box');
    box.style.width = ""; /*21/04/2010*/
    var box_inner = box.down('#box_inner');
    box.className = 'box box_email hide';
    box_inner.update(html);
    changeLangSendMail();
    showShadow(true);
    var url = document.URL.toLowerCase();
    if (url.indexOf('result.aspx') != -1 || url.indexOf('details.aspx')) {/*21/04/2010*/
        pos4Popup(box, true);
    } else {
        pos4Popup(box);
    }
    box.select('#btnEMSend', '.close_box a').invoke('observe', 'click', SendEmailPopupClick);
    if (this.url) {
        $('btnEMSend').name = this.url;
        this.url = null;
    }
    loadTextboxEvent(box);
    var boxads = $('box').select('[class="box_ads"]');
    if (boxads.length != 0) box.removeChild(boxads[0]);
};
/*
- function: send mail va close popup
- update: 11/03/2010 
*/
function SendEmailPopupClick(e) {
    var ele = Event.element(e);
    var box = $('box');
    if (ele.up('div').className == 'close_box') {
        box.addClassName('hide');
        if (box.style.display == "block") box.style.display = "";
        showShadow(false);
        return;
    }
    var _arrTmp = box.select('#txtFrom', "#txtTo", "#txtSubject", "#txtComment", "#liEmailInfo");
    var from = _arrTmp[0].value;
    var to = _arrTmp[1].value;
    if (!utils.checkMail(from) || !utils.checkMail(to)) {
        _arrTmp[4].update(lang4Contact()[isLang][0]);
        _arrTmp[4].style.visibility = "visible";
        return;
    }
    _arrTmp[4].update("Sending... Please wait...");
    _arrTmp[4].style.visibility = "visible";

    var subject = _arrTmp[2].value.stripScripts().stripTags();
    var comment = _arrTmp[3].value.stripScripts().stripTags();

    var url = document.URL.toLowerCase();
    var link = '';
    if (url.indexOf('details') != -1) {
        link = document.URL.substring(0, document.URL.lastIndexOf('/')) + '/' + createFullLink('details.aspx');
        link += "&fTab=" + flagTab;
    }
    else if (url.indexOf('result') != -1)
        link = $('btnEMSend').name;
    else
        link = createLinkPage('vnmap.aspx');
    link = utils.encode(link, strState.substr(strState.length / 2));
    comment = utils.encode(comment, strState.substr(strState.length / 2));
    subject = utils.encode(subject, strState.substr(strState.length / 2));
    var paramSendMail = ('from=' + from + '&to=' + to + '&subject=' + subject + '&comment=' + comment + '&st=' + strState + '&info=' + link).toQueryParams();
    utils.call("sendEmail.aspx", paramSendMail, "POST", "sendEmailResult", "sendEmailResult");
};
/*
- function: tra ve ket qua send mail
- update: 11/03/2010 
*/
function sendEmailResult(iResult) {
    [$('txtFrom'), $('txtTo'), $('txtSubject'), $('txtComment')].each(function(ele) { ele.value = ""; });
    var messageResult = lang4Contact()[isLang];
    var strResult = (iResult == "1") ? messageResult[2] : (iResult == "0") ? messageResult[3] : messageResult[0];
    $('liEmailInfo').update(strResult);
};
function DDFunctionClick(e) {
    var ele = Event.element(e);
    if (ele.tagName != 'A') return;

    if (ele.id == 'aDDHomePage') {
        setHomepage(e);
    }
};

function setHomepage(e) {
    if (Prototype.Browser.IE) {
        document.body.style.behavior = 'url(#default#homepage)';
        document.body.setHomePage('http://diadiem.com.vn/');
    }
};
function Star2HTML(numStar) {
    numStar = parseFloat(numStar);
    return " <li style='width:" + (20 * numStar) + "%;' class='current-rating li" + Math.floor(numStar) + "star'></li>" +
             "   <li><a class='one-star' title='1 star out of 5' href='javascript:;'></a></li>" +
             "   <li><a class='two-stars' title='2 stars out of 5' href='javascript:;'></a></li>" +
             "   <li><a class='three-stars' title='3 stars out of 5' href='javascript:;'></a></li>" +
             "   <li><a class='four-stars' title='4 stars out of 5' href='javascript:;'></a></li>" +
             "   <li><a class='five-stars' title='5 stars out of 5' href='javascript:;'></a></li>";
};
function linktoMobile(e) {
    var url = "mobiles/index.aspx";
    setTimeout(function() {
        window.location.href = url;
    }, 0);

};
function splitAddress(txtAddress) {//syntax-txtAddress :no,streetname,wardname,distname
    if (typeof (txtAddress) == "object") {
        txtAddress = txtAddress.no + "," + txtAddress.stName + "," + txtAddress.wName + "," + txtAddress.dName;
    }
    var nostreet_ = "";
    var warddist_ = "";
    if (txtAddress == "") return { nostreet: nostreet_, warddist: warddist_ };
    var infoAdd = (txtAddress.indexOf(",") != -1) ? txtAddress.split(",") : txtAddress.split("_");
    nostreet_ = (infoAdd[0] != "0" && infoAdd[0] != 'undefined' && infoAdd[0] != '') ? utils.toProperCase(utils.trim(infoAdd[0])) : ""; //edit 14/12/2009

    if (infoAdd.length > 1)

        nostreet_ += (((nostreet_ != "") ? ", " : "") + utils.trim(infoAdd[1]));
    if (isWard != 2) {
        var lang = lang4TabPopUp()[isLang];
        var wname = '';
        var dname = '';
        if (infoAdd.length == 3) {//fortmat:no,street,dname or wname(tuy theo thanh pho ma la dname hay wname tuong uong)
            if (isWard == 1)//tham so thu 3 la quan
                dname = (infoAdd[2] != "" && infoAdd[2] != "0" && infoAdd[2] != undefined) ? utils.trim(infoAdd[2].replace("Q.0", "").replace("Q.", "").replace("Dist", "")) : "";
            else
                wname = (infoAdd[2] != "" && infoAdd[2] != "0" && infoAdd[2] != undefined) ? utils.trim(infoAdd[2].replace("P.0", "").replace("P.", "").replace("Wrd", "")) : "";
        } else {//syntax no,streetname,wname,disname :format chuan
            wname = (isWard == 1) ? "" : ((infoAdd[2] != "" && infoAdd[2] != "0" && infoAdd[2] != undefined) ? utils.trim(infoAdd[2].replace("P.0", "").replace("P.", "").replace("Wrd", "")) : "");
            dname = (infoAdd[3] != "" && infoAdd[3] != "0" && infoAdd[3] != undefined) ? utils.trim(infoAdd[3].replace("Q.0", "").replace("Q.", "").replace("Dist", "")) : "";
        }
        if (wname != "") {
            wname = (isLang == 1) ? utils.trim(wname.toLowerCase().replace('x.', '').replace('tt.', '')) : wname;
            wname = (isLang == 0) ? ((wname.toLowerCase().indexOf('x. ') != -1 || wname.toLowerCase().indexOf('tt. ') != -1) ? wname : (wname.toLowerCase().indexOf('x.') != -1 || wname.toLowerCase().indexOf('tt.') != -1) ? wname.replace('.', '. ') : lang[1] + " " + wname) : (utils.RegNum(wname) == true ? lang[1] + " " + utils.toProperCase(wname.replace('X.', '').replace('x.', '')) : utils.toProperCase(wname.replace('X.', '').replace('x.', '')) + " " + lang[1]);
        }

        if (dname != "") {
            dname = (isLang == 1) ? utils.trim(dname.toLowerCase().replace('h.', '')) : dname;
            dname = (isLang == 0) ? ((dname.toLowerCase().indexOf('. ') != -1) ? dname : (dname.toLowerCase().indexOf('.') != -1) ? dname.replace('.', '. ') : lang[2] + " " + dname) : (utils.RegNum(dname) == true ? lang[2] + " " + utils.toProperCase(dname.replace('H.', '').replace('h.', '')) : utils.toProperCase(dname.replace('H.', '').replace('h.', '')) + " " + lang[2]);
        }
        switch (parseInt(isWard)) {
            case -1: warddist_ += ((wname != "") ? utils.toProperCase(wname) : "") + ((dname != "") ? ", " + utils.toProperCase(dname) : ""); break;
            case 1: warddist_ += (dname != "") ? utils.toProperCase(dname) : ""; break;
            case 0: warddist_ += (wname != "") ? utils.toProperCase(wname) : ""; break;
        }
        if (isLang == 1) {
            nostreet_ = ConvertFromVNToEng(nostreet_);
            warddist_ = ConvertFromVNToEng(warddist_);
        }
    }
    return { nostreet: nostreet_, warddist: warddist_ };
};
function Comp4Lang(i, flag) {
    var oComp_ = (flag == 3) ? dsCty[i] : (flag == 2) ? oCom.dsDtac[i] : (flag == 1) ? oCom.dsDvi[i] : oCom.dsCompany[i];
    var MCty = oComp_.MCty;
    var cname = isLang == 0 ? replaceJSON(oComp_.TCty) : replaceJSON(oComp_.TCtyKD);
    var phone = (oComp_.P == "0" ? "" : replaceJSON(oComp_.P));
    var oAdd = splitAddress((isLang == 0) ? oComp_.Add : oComp_.AddKD);
    var nameGD = "";
    var maQuan = "0";

    if (oComp_.TGD != undefined) {
        nameGD = (isLang == 0 ? replaceJSON(oComp_.TGD) : replaceJSON(oComp_.TGDKD));
    }
    var Logo;
    // httpImages + "common/icons/subcategory/" + oComp_.NnDv.Split("^^")[1].Split("_")[0]+ '.jpg'
    if (flag == 2) {//truong hop doi tac ,lay hinh theo Macty
        if (oComp_.L != "") Logo = ((oComp_.L.indexOf(httpImages) != -1) ? oComp_.L : httpImages + "Images_" + strState + "/imgcongty/DiemVang/" + MCty + ".jpg");
        else {
            if (oComp_.NnDv) Logo = httpImages + "common/icons/subcategory/" + oComp_.NnDv.split("^^")[1].split("_")[0] + '.jpg';
            else Logo = "images/graphics/noPic50x50.jpg";
        }
    } else {

        if (oComp_.L != "")
            Logo = ((oComp_.L.indexOf(httpImages) != -1) ? oComp_.L : httpImages + "Images_" + strState + "/" + oComp_.L);
        else {
            if (oComp_.NnDv) Logo = httpImages + "common/icons/subcategory/" + oComp_.NnDv.split("^^")[1].split("_")[0] + '.jpg';
            else Logo = "images/graphics/noPic50x50.jpg";
        }
        //  var Logo = (oComp_.L != "") ? ((oComp_.L.indexOf(httpImages) != -1) ? oComp_.L : httpImages + "Images_" + strState + "/" + oComp_.L) : "images/graphics/noPic50x50.jpg";
    }

    var star = oComp_.Sta;
    var strUnit = "";
    var unitFirst = 0;
    var maNganh = null;
    if (oComp_.NnDv == undefined) {
        oComp_.NnDv = '';
        unitFirst = oComp_.MDV;
    }
    if (oComp_.NnDv != '') {
        var arrCateUnit = oComp_.NnDv.split(';');
        for (var j = 0; j < arrCateUnit.length; j++) {
            var cateID = arrCateUnit[j].split('^^')[0].split('_')[0];
            if (maNganh == null) maNganh = cateID;
            var arrUnit = arrCateUnit[j].split('^^')[1].split('#');
            if (arrUnit.length > 0) {
                for (var k = 0; k < arrUnit.length; k++) {
                    var _Unit = arrUnit[k].split('_');
                    if (k == 0 && unitFirst == 0) { unitFirst = _Unit[0]; }
                    var tempid = oComp_.MCty + '_' + cateID + '_' + _Unit[0] + '_' + oComp_.X + '_' + oComp_.Y + "_" + oComp_.XY;
                    var uName = (isLang == 0) ? _Unit[1] : _Unit[2];
                    var strPass = strState.substring(strState.length / 2);
                    var href = "Result.aspx?stpe=2&uID=" + utils.encode(_Unit[0], strPass) + "&cID=" + utils.encode(cateID, strPass) + "&uN=" + encodeURIComponent(uName) + "&l=" + isLang;
                    strUnit += '<a id="aUnit_' + tempid + '" class="detail_type" title="' + uName + '" href="' + href + '" target="_blank">' + uName + '</a>,';
                }
            }
        }
        strUnit = strUnit.substr(0, (strUnit.length - 1));
    }

    var strid = oComp_.MCty + "_" + unitFirst + '_' + oComp_.X + '_' + oComp_.Y + "_" + oComp_.XY;
    if (isWard == "2") { wname = ""; dname = ""; }

    var logoComp = (oComp_.LComp.indexOf(httpImages) != -1) ? oComp_.LComp : httpImages + "Images_" + strState + "/" + oComp_.LComp;
    var slogan = (oComp_.Slogan.indexOf(httpImages) != -1) ? oComp_.Slogan : httpImages + "Images_" + strState + "/" + oComp_.Slogan;

    var email = oComp_.Email;
    var link = oComp_.Link;
    var logoDisplay = (oComp_.LDisplay.indexOf(httpImages) != -1) ? oComp_.LDisplay : httpImages + "Images_" + strState + "/" + oComp_.LDisplay;
    var objReturn = { "cID": MCty, "cName": cname, "nostreet": oAdd.nostreet, "dw": oAdd.warddist, "phone": phone, "Sta": star, "strid": strid, "Logo": Logo, "uName": strUnit, "Votes": oComp_.V, "Dist": oComp_.Dsc, "Adv": oComp_.Adv, "MDV": unitFirst, "Dsc": oComp_.Dsc, "tenGD": nameGD, "MaQuan": oComp_.MQ, "maNganh": maNganh, "LComp": logoComp, "Slogan": slogan, "email": email, "link": link, 'LDisplay': logoDisplay };
    //  var objReturn = { "cID": MCty, "cName": cname, "nostreet": oAdd.nostreet, "dw": oAdd.warddist, "phone": phone, "Sta": star, "strid": strid, "Logo": Logo, "uName": strUnit, "Votes": oComp_.V, "Dist": oComp_.Dsc, "Adv": oComp_.Adv, "MDV": unitFirst, "Dsc": oComp_.Dsc, "tenGD": nameGD, "MaQuan": oComp_.MQ, "maNganh": maNganh };
    if (typeof (oComp_.adType) != "undefined") {
        objReturn.adType = oComp_.adType;
        objReturn.adLink = oComp_.adLink;
        objReturn.adText = oComp_.adText;
    }
    return objReturn;
};
/*
isCenter: xac dinh ele_copy co nam giua man hinh hay ko?
ele_source: element mun lay vi tri
ele_copy: element muon gan vi tri
top: khong cach top so voi ele_source
left: khong cach left so voi ele_source
*/
function copyPosition(isCenter, ele_source, ele_copy, top, left) {
    if (isCenter) {
        var wh_copy = ele_copy.getDimensions();
        var w_moniter = utils.windowSize();
        var scrollOff = document.viewport.getScrollOffsets()[1];
        if (isNaN(scrollOff))
            scrollOff = 0;
        var newT = Math.ceil(((w_moniter[1] - wh_copy.height) / 2 + scrollOff + top));
        var newL = Math.ceil(((w_moniter[0] - wh_copy.width) / 2 + left));
        if (newT < 0) newT = 0;
        if (newL < 0) newL = 0;
        ele_copy.style.top = newT + 'px';
        ele_copy.style.left = newL + 'px';
        //       var divShadow = $('divShadow')
        //        var divMain = $('divMain') || document.body;
        //        divShadow.style.width = (document.body.offsetWidth < divMain.offsetWidth ? divMain.offsetWidth - 10 : document.body.offsetWidth - 10) + "px";
        //        divShadow.style.height = (divMain.offsetHeight - 38) + "px";
        //divShadow.show();
    }
    else {
        var arrPos = ele_source.cumulativeOffset();
        ele_copy.style.top = Math.ceil((arrPos[1] + top)) + 'px';
        ele_copy.style.left = Math.ceil((arrPos[0] + left)) + 'px';
        if (!ele_copy.name || ele_copy.name == "")
            ele_copy.name = ele_source.id;
    }
    //ele_copy.show();
    //  - xem lai   ele_copy.show();
};
//chuyen ngon ngu cho trang vnMap
function ChangeLangVNMap() {

    try {
        if (arguments[1] != null) {
            isLang = parseInt(arguments[1]);
        } else {
            isLang = isLang == 0 ? 1 : 0;
        }
        try {
            var langBD = langBanDo()[isLang];
            $('txtSearchMaps').next().innerHTML = langBD[0];
            $('txtSearchA').next().innerHTML = langBD[1];
            $('txtSearchB').next().innerHTML = langBD[1];
            $('txtSearchNearBy').next().innerHTML = langBD[2];
            $('txtSearchYP').next().innerHTML = langBD[3];
        } catch (ex) { };

        var langMap = langVNMap()[isLang];
        $('aDDLanguage').innerHTML = langMap[28];
        if (isLang == 0 && $('aDDLanguage').hasClassName('icon_vi')) {
            $('aDDLanguage').className = 'icon_en';
        }
        else if (isLang == 1 && $('aDDLanguage').hasClassName('icon_en')) {
            $('aDDLanguage').className = 'icon_vi';
        }

        var navLink = [$('navIndex'), $('navMap'), $('navDirectory'), $('navCommute'), $('navEvent')];
        //var navLink = [$('navIndex'), $('navMap'), $('navDirectory'), $('navCommute'), $('navEvent')];
        navLink.each(function(itm) {
            var src = itm.select('img')[0].src;
            if (isLang == 0 && itm.className.indexOf('_en') != -1) {
                itm.className = itm.className.replace('_en', '');

                if (src.indexOf('_en.') != -1) {
                    itm.select('img')[0].src = src.replace('_en', "");
                }
            }
            else if (isLang == 1 && itm.className.indexOf('_en') == -1) {
                var subclass = itm.className.indexOf('active') != -1 ? (' ' + itm.className.split(' ')[1]) : '';
                itm.className = itm.className.split(' ')[0] + "_en" + subclass;
                if (src.indexOf('_en.') == -1) {
                    itm.select('img')[0].src = src.replace('.png', "_en.png");
                }

            }
        });
        // $('navCommute').style.width = (isLang == 0) ? '130px' : '138px';

        $('aTabMaps').innerHTML = langMap[16];
        $('aTabDirection').innerHTML = langMap[17];
        $('btnSearch').down('SPAN').innerHTML = langMap[18];
        $("aTabDirectory").innerHTML = langBD[24];
        //$('btnClear').down('SPAN').innerHTML = langMap[19];

        var divMapTools = $('divMapTools');
        divMapTools.down(".func_snapshot").innerHTML = langBD[4];
        divMapTools.down(".func_sms").innerHTML = langMap[20];
        divMapTools.down(".func_email").innerHTML = langMap[22];
        divMapTools.down(".func_print").innerHTML = langMap[21];
        divMapTools.down(".func_link").innerHTML = langMap[23];
        divMapTools.down(".func_other").innerHTML = langBD[25];

        if ($('aMapType_0')) $('aMapType_0').down("p").innerHTML = langMap[24];
        if ($('aMapType_1')) $('aMapType_1').down("p").innerHTML = langMap[25];
        if ($('aMapType_2')) $('aMapType_2').down("p").innerHTML = langMap[26];
        // $('spnFind').innerHTML = langBD[5];
        if ($('spnNear')) $('spnNear').innerHTML = langBD[6];
        /* var divLogin = $('divLogin');

        if ($('aSignOut')) {
        divLogin.down('SPAN').innerHTML = langBD[9];
        var strTmp = divLogin.down('P').select('a');
        strTmp[0].innerHTML = langBD[10];
        strTmp[1].innerHTML = langBD[11];
        } else {
        divLogin.className = (isLang == 0) ? 'header_signin' : 'header_signin_en';
        }*/
        //$('aDDContact').innerHTML = langMap[29];
        // $("aDDAdds").innerHTML = langMap[31];
        // if ($("aDDRecruit")) $("aDDRecruit").innerHTML = langMap[32];
        if ($('aDDHomePage')) $('aDDHomePage').innerHTML = langMap[30];
        // $('divTopBar').down(".aLogo").down("img").src = "images/graphics/" + (isLang == 0 ? "logo" : "logoE") + ".png";
        if ($('spnDistance')) {
            var _arrTmp = $('spnDistance').innerHTML.split(' - ');
            var _lang = lang4TabDirection()[isLang];
            _arrTmp[0] = _arrTmp[0].split(' ');
            var _str = _lang[4] + ' ';
            if (_arrTmp[0].length > 3) {
                _str += _arrTmp[0][1] + ' ' + _lang[5] + ' ' + _arrTmp[0][3] + (isLang == 0 ? (' ' + _lang[6]) : '');
            }
            else {
                _str += _arrTmp[0][1] + ' ' + _lang[6];
            }
            _str += ' - ' + _arrTmp[1];
            $('spnDistance').innerHTML = _str;
        }
        var box = $('box');
        if (box.hasClassName('box_sms') && box.visible()) changeLangMessSMS();
        if ($('divToolTip') && $('divToolTip').style.display != "none" && arguments[1] == null) {
            if ($('divToolTip').down('.dToolTip_R').select("a")[3].id.length > 4) {
                var IDComp = $('divToolTip').down('.dToolTip_R').select("a")[3].id.replace("aDetailComp", "IconDComMap").replace("aDetailDT", "IconDdtacMap");
                if (!$('boxCompanyResult').hasClassName('hide')) {
                    if ((objCompTemp != "-1" || objCompTemp != null) && arguments[1] == null) showListCompany(objCompTemp);
                }
                createInfoBoxExt($(IDComp));
                resetIconState();
                var strid = IDComp.split("_");
                //dua icon cua cong ty duoc click thanh hover    
                var id2 = '_' + strid[1] + '_' + strid[2] + '_' + strid[3] + '_' + strid[4] + '_' + strid[5] + '_' + strid[6];
                var icon = $('IconDdtacMap' + id2) || $('IconDComMap' + id2); //icon cua cong ty duoc click 
                activeIconState(icon);
            } else {
                var mlang = lang4TabPopUp()[isLang];
                var arrTmp = $('divToolTip').down('ul').select("li");
                var strWard = "", strDist = "";
                var arrDW = arrTmp[2].innerHTML.split(',');
                arrTmp[0].innerHTML = '<h5>' + mlang[0] + '</h5>';
                arrTmp[3].select("span")[0].innerHTML = mlang[16];
                arrTmp[3].select("a")[0].innerHTML = mlang[11];
                arrTmp[3].select("a")[1].innerHTML = mlang[12];
                arrTmp[3].select("a")[2].innerHTML = mlang[13];
                arrTmp[3].select("a")[3].innerHTML = mlang[14];

                arrTmp[4].select("span")[0].innerHTML = mlang[3];
                arrTmp[4].select("a")[0].innerHTML = mlang[4];
                arrTmp[4].select("span")[2].innerHTML = mlang[5];
                var strAddress = $('divToolTip').down('.aTTFromHere').name;
                if (strAddress != undefined && strAddress != '') {
                    var add_ = splitAddress(strAddress.split(';')[0]);
                    arrTmp[1].innerHTML = add_.nostreet;
                    arrTmp[2].innerHTML = add_.warddist;
                }
            }
        }
        else {
            if (!$('boxCompanyResult').hasClassName('hide')) {
                if ((objCompTemp != "-1" || objCompTemp != null) && arguments[1] == null) {
                    showListCompany(objCompTemp);
                    if ($('divToolTip')) $('divToolTip').hide();
                    if ($('divToolTipShadow')) $('divToolTipShadow').hide();
                    resetIconState();
                }
            }
        }
        if ($('divListDistWard') && $('divListDistWard').down('ul') && $('divListDistWard').style.display != "none") {
            showListResultFull(objSearch, strType, 1);
        }
        changeLangSMS();
        changeLangSendMail();
        changeLangLink();

        var langError = errorBox()[isLang];
        $("spnErrorInfo").innerHTML = langError[0];
        changeLangDirectoryBar();
        if (box_) $('divListCate').update(box_.loadBoxCateIcons(box_.index));
        changeLangTextBox('txtSearchMaps');
        changeLangTextBox('txtSearchA');
        changeLangTextBox('txtSearchB');
        ChangLangRecentBox();
        var lang = langListCity()[isLang];
        var aChageCity = $('aChageCity/Province');
        var nearbyArea = $('spnListArea');
        var divListPopular = $('divListPopular');
        if (aChageCity) aChageCity.down('SPAN', 2).update(lang[1]);
        if (nearbyArea) nearbyArea.update(lang[2]);
        if (divListPopular) divListPopular.next().down(lang[3]);
        if ($('spnDistance')) {//diem A,diem B 07/05/2010
            var boxGuidStreet = $('result_direction');
            var streetA = boxGuidStreet.down('.mbox_point_A');
            var streetB = boxGuidStreet.down('.mbox_point_B');
            streetA.title = $('txtSearchA').value;
            streetA.innerHTML = substr($('txtSearchA').value, 40);
            streetB.title = $('txtSearchB').value;
            streetB.innerHTML = substr($('txtSearchB').value, 40);
        }
    } catch (ex) {
        var s = ex;
    }
    changeLangBoxCategory();
};
//doi ngon ngu cho Form Lien ket
function changeLangLink() {
    var box = $('box');
    if (box && box.hasClassName('box_links') && box.visible()) {
        var langL = langLink()[isLang];
        box.down('.box_caption').innerHTML = langL[0];
        var arrChild = box.down('LI').childNodes;
        arrChild[0].innerHTML = langL[1];
        arrChild[1].innerHTML = langL[2];
    }
};
/*
-function:change language for SendMail-PopUp
-update:11/03/2010
*/
function changeLangSendMail() {
    try {
        var langSM = langSendEmail()[isLang]; /*edit 11/03/2010*/
        $('spnSend').innerHTML = langSM[0];
        $('lblEMFrom').innerHTML = '<font>*</font>' + langSM[1];
        $('lblEMTo').innerHTML = '<font>*</font>' + langSM[2];
        $('spnEMCM').innerHTML = langSM[5];
        $('lblEMSubject').innerHTML = langSM[3];
        $('lblEMComment').innerHTML = langSM[4];
        $('spnEMSend').innerHTML = langSM[6];
    } catch (ex) { }
};

function changeLangMessSMS() {
    var langS = langSMS()[isLang];
    $('aIntroSMS').innerHTML = langS[13];
    var arrSpn = $('divSMSNew').select('span');
    arrSpn[0].update(langS[14]);
    arrSpn[1].update(langS[15]);
    arrSpn[2].update(langS[16]);
    arrSpn[3].update(langS[17]);
    $('aCloseSMSNew').innerHTML = langS[12];
};
function boxFindCompanyNearBy(oAdd_) {

    var cateID = (arguments.length == 1) ? oAdd_.cateID : arguments[1];
    showShadow4Search(true);

    strParamCom = "catID=" + cateID + "&XY=" + oAdd_.x + "_" + oAdd_.y + "&st=" + strState + "&posCate=" + oAdd_.posCate + "&ins=" + inSearch;
    strParamCom += "&num=6&stpe=30&dID=" + ((oAdd_.dID == undefined || oAdd_.dID == '') ? 0 : oAdd_.dID) + "&P=";
    paramCom = (strParamCom + 1).toQueryParams();

    var url = document.URL.toLowerCase();
    var fncResult = (url.indexOf('vnmap.aspx') != -1 || url.indexOf('.aspx') == -1) ? "showListCompany" : "showCompanyResult";
    utils.call("Comp.aspx", paramCom, "POST", fncResult, fncResult);
};
function changeLangDirectoryBar() {
    var langB = dllCAtegoryBar()[isLang];
    var divsdP = $("divShadowP");
    var divListCate = $('divListCate');
    if (divsdP) {  // neu co ton tai boc nay
        divsdP.select('label')[0].innerHTML = langB[3]; //label gan
        var divsdP2 = $("divSelSearch_ddl");

        if (divsdP2 && divsdP2.childNodes.length > 0) {//06/05/2010
            for (j = 0; j <= 2; j++) {
                if (divsdP2.select('#divSelSearch_SV')[0].innerHTML == divsdP2.select('#divSelSearch_' + j)[0].innerHTML) {
                    divsdP2.select('#divSelSearch_SV')[0].innerHTML = langB[j];
                }
                divsdP2.select('#divSelSearch_' + j)[0].innerHTML = langB[j];
            }
        }
    }
    if (divListCate)
        divListCate.select('A').each(function(ele) {//change title of image
            var itmCate = objAllCate.find(function(s) {
                return (ele.id == 'aCate_' + s.id);
            });
            if (!Object.isUndefined(itmCate)) ele.title = (isLang == 0) ? itmCate.nameVN : itmCate.nameEN;
        });

};
var idBox = null;
/*recent box - Dia Diem Cua Toi*/
function showRecentBox(e) {

    try {
        var ele = Event.element(e);

        var divRecentBox = $('divRecentBox');
        divRecentBox.down('#ulRecentPoint').innerHTML = '';
        divRecentBox.name = ele.id;

        var pos = ele.cumulativeOffset();
        var left = 682;
        var _left = 996;
        if (utils.IE_Firefox() == -1) {
            left = 692;
            _left = 980;
        }
        if (document.URL.toLowerCase().indexOf('vnmap.aspx') != -1) {
            divRecentBox.style.left = parseInt(pos[0] - 241) + 'px';
            divRecentBox.style.top = pos[1] + 28 + 'px';
        }
        else {
            divRecentBox.style.left = (parseInt(pos[0]) - 240) + 'px';
            divRecentBox.style.top = pos[1] + 23 + 'px';
        }
        idBox = ele.id.charAt(ele.id.length - 1);
        divRecentBox.show();

        var logName = nickUser; // var logName = chkLogin();
        if (logName == "") {
            showListKeySearch('ListKey');

            $('divNotSign').style.display = 'block';
            $('ulRecent').style.display = 'none';
        }
        else {
            var _nick = logName;
            showListKeySearch('ListKey_' + _nick);

            var _avatar = nickAvatar; //$('divLogin').down('img').src;
            if (_avatar.indexOf('?') != -1)
                _avatar = _avatar.substring(0, _avatar.indexOf('?'));
            $('divNotSign').down('.divNotSign').down('img').src = _avatar;
            $('spanRecent').innerHTML = _nick;
            $('spanLoginInfo').style.display = 'none';
        }

        Event.stop(e);
    } catch (exx) { }
};
//click tren khung Dia Diem Cua Toi
function clickRecentBox(e) {

    var ele = Event.element(e);
    if (ele.tagName != 'A') {
        Event.stop(e);
        return;
    }
    var divRecentBox = ele.up('#divRecentBox');

    if (ele.className == 'aPoint') {
        //click item key search
        var url = document.URL.toLowerCase();
        if (url.indexOf('vnmap.aspx') == -1) {
            var lnkDirect = '';
            if (url.indexOf('profiles') != -1) lnkDirect = '../';
            var info = encodeURIComponent(ele.id);
            var strencode = utils.encode(info, strState.substring(strState.length / 2));
            var strendecode = utils.decode(strencode, strState.substring(strState.length / 2));
            window.location.href = lnkDirect + 'vnMap.aspx?st=' + strState + '&infoRC=' + strencode;
        } else
            oClickRecentKeySearch(ele.id);
    }
    else if (ele.id == 'aCloseRB') {
        // button close
        divRecentBox.hide();
    }
    else if (ele.id == 'aDeleteBox') {
        //link Delete
        divRecentBox.down('#ulRecentPoint').innerHTML = '';
        var _url = document.URL.toString();
        var logName = chkLogin();
        if (logName == "") DeleteCookie('ListKey', _url);
        else {
            var _nick = nickUser; //var _nick = $('divLogin').down('.spnNicks').innerHTML;
            DeleteCookie('ListKey_' + _nick, _url);
        }
    }
    else if (ele.id == 'aLogin') {
        //link login
        divRecentBox.hide();
        getFormSInUp('aSignIn');
    }

    Event.stop(e);
};

//them tu khoa tim kiem vao Dia Diem Cua Toi
function addRecentKeySearch() {
    var url = document.location.pathname.toLowerCase();

    var ulRecentPoint = $('ulRecentPoint');
    var _nick;
    var str = "";
    var cookieName = "";
    var logName = chkLogin();

    if (logName == "") {
        cookieName = 'ListKey';
    }
    else {
        _nick = logName;
        cookieName = 'ListKey_' + _nick;
    }

    var pxyTmp = '';
    if (inSearch == 1) {//tim duong
        var strA = utils.trim(oAddA.no + ', ' + oAddA.stName + ', P.' + utils.toProperCase(oAddA.wName) + ', Q.' + utils.toProperCase(oAddA.dName));
        if (strA.charAt(0) == ',') strA = utils.trim(strA.replace(',', ''));
        var strB = utils.trim(oAddB.no + ', ' + oAddB.stName + ', P.' + utils.toProperCase(oAddB.wName) + ', Q.' + utils.toProperCase(oAddB.dName));
        if (strB.charAt(0) == ',') strB = utils.trim(strB.replace(',', ''));
        var strAe = utils.trim(oAddA.textEn);
        var strBe = utils.trim(oAddB.textEn);
        var pxyA = map.ABPoint[0].x + "_" + map.ABPoint[0].y; // txtSearchA.pxy;
        var pxyB = map.ABPoint[1].x + "_" + map.ABPoint[1].y; // txtSearchB.pxy;
        str = strA + ';' + strB;
        if (pxyA && pxyB) {
            pxyTmp = pxyA.replace('_', ':') + ';' + pxyB.replace('_', ':');
            str += ';' + pxyTmp;
        }
        str += '*' + strAe + ';' + strBe;
    }
    else {// tim dia diem

        var txtValue = utils.trim(oAdd.no + ', ' + oAdd.stName + ', P.' + utils.toProperCase(oAdd.wName) + ', Q.' + utils.toProperCase(oAdd.dName));
        if (txtValue.charAt(0) == ',') txtValue = utils.trim(txtValue.replace(',', ''));
        var txtValueE = utils.trim(oAdd.textEn);
        var pxy = map.maker.mx + "_" + map.maker.my;
        str = txtValue;
        if (pxy) {
            pxyTmp = pxy.replace('_', ':');
            str += ';' + pxyTmp;
        }
        str += '*' + txtValueE;
    }

    if (str == "") { return; }

    str = strState + ';' + isWard + ';' + str;

    var strListKey = GetCookie(cookieName);
    if (strListKey != null) {
        if (pxyTmp != '' && strListKey.indexOf(pxyTmp + '*') != -1) return;
        strListKey = str + "_" + strListKey;
        var strKey = strListKey.split("_");
        if (strKey.length > 15) {
            strListKey = strListKey.substring(0, strListKey.lastIndexOf(strKey[15]) + 1);
        }
    }
    else
        strListKey = str + "_";
    SetCookie(cookieName, strListKey, 60);
};
//hien thi danh sach cac item trong Dia Diem Cua Toi
function showListKeySearch(name) {

    var strGetCook = GetCookie(name);
    try {
        var strHTML = '';
        var strText = '';
        strGetCook = strGetCook.split("_");

        for (var i = 0; i < strGetCook.length - 1; i++) {
            var strGetCookV = strGetCook[i].split('*')[0];
            var strGetCookE = strGetCook[i].split('*')[1];
            var arrText = strGetCookV.split(";");
            var arrTextE = strGetCookE.split(";");
            var strHover = '';
            if (arrText.length > 0 & arrText[0] == strState) {
                if (arrText.length > 4) {
                    strText = (isLang == 0) ? (arrText[2].length > 17 ? arrText[2].substring(0, 17) + "..." : arrText[2]) + " - " + (arrText[3].length > 17 ? arrText[3].substring(0, 17) + "..." : arrText[3]) : (arrTextE[0].length > 17 ? arrTextE[0].substring(0, 17) + "..." : arrTextE[0]) + " - " + (arrTextE[1].length > 17 ? arrTextE[1].substring(0, 17) + "..." : arrTextE[1]); //TN 16.11
                    if (strText.indexOf('...') != -1)
                        strHover = 'title="' + arrText[2] + ' - ' + arrText[3] + '"';
                } else {
                    strText = (isLang == 0) ? (arrText[2].length > 37 ? arrText[2].substring(0, 37) + "..." : arrText[2]) : (arrTextE[0].length > 37 ? arrTextE[0].substring(0, 37) + "..." : arrTextE[0]); //TN 16.11
                    if (strText.indexOf('...') != -1)
                        strHover = 'title="' + arrText[2] + '"';
                }

                strHTML += '<li class="liPoint"><a id="' + strGetCook[i] + '" class="aPoint" href="javascript:void(0);" ' + strHover + '>' + strText + '</a></li>';
            }
        }

        $('ulRecentPoint').innerHTML = strHTML;
    } catch (ex) { }
};
//click tren 1 item trong Dia Diem Cua Toi
function oClickRecentKeySearch(id) {

    $("divRecentBox").hide();
    var arrV = id.split('*')[0];
    var arr = arrV.split(';');
    if (strState != arr[0]) {
        //load lai thanh pho
        strState = arr[0];
        isWard = arr[1];
        var ddlCities = $("ddlCities");
        if (ddlCities) ddlCities.value = arr[0];
        map.removeDirectionMaker();
        map.removeMapMaker();
        removeShadow();
        var xy = (arr.length > 4 ? arr[4] : arr[3]).split(':');
        map.initialize(0, xy[0], xy[1], "");
        try { OffDirectoryBar(); removeSearchResult(); } catch (exec) { }
    }

    if (arr.length > 4) { //tim duong di
        var txtSearchA = $('txtSearchA');
        var txtSearchB = $('txtSearchB');
        txtSearchA.value = utils.toProperCase(arr[2]);
        txtSearchA.style.backgroundImage = 'none';
        txtSearchB.value = utils.toProperCase(arr[3]);
        txtSearchB.style.backgroundImage = 'none';

        txtSearchA.pxy = arr[4].replace(':', '_');
        txtSearchB.pxy = arr[5].replace(':', '_');
        onChangeTab($('aTabDirection'));

    }
    else { //tim dia diem
        var txtSearchMaps = $('txtSearchMaps');
        if (txtSearchMaps == null) txtSearchMaps = $("txtSearchA");
        if (txtSearchMaps) {
            txtSearchMaps.value = utils.toProperCase(arr[2]);
            txtSearchMaps.style.backgroundImage = 'none';

            txtSearchMaps.pxy = arr[3].replace(':', '_');
            onChangeTab($('aTabMaps'));

        }
    }
    clickBoxSearch();
};
//kiem tra login chua
function chkLogin() {
    if (typeof (logName) == "undefined") {
        logName = "";
    }
    return logName;
};

function insertText(oad) {
    oad.text = '';
    oad.textEn = '';
    oad.stName = utils.toProperCase(utils.trim(oad.stName));
    oad.wName = utils.trim(oad.wName);
    oad.dName = utils.trim(oad.dName);
    if (oad.no != "") {
        oad.text = (oad.no) + ", ";
        oad.textEn = (oad.no) + ", ";
    }
    oad.text += oad.stName;
    oad.textEn += oad.stName;

    if (isWard != 1) {
        if (oad.wName != "" && oad.wName != "0") {
            oad.text += ", P. " + oad.wName;
            oad.textEn += isNaN(oad.wName) ? (", " + oad.wName + " Wrd") : (", Wrd " + oad.wName);
        }
    }
    if (isWard != 0) {
        if (oad.dName != "" && oad.dName != "0") {
            oad.text += ", Q. " + oad.dName;
            oad.textEn += isNaN(oad.dName) ? (", " + oad.dName + ' Dist') : (", Dist " + oad.dName);
        }
    }
    if (oad.textEn != '') oad.textEn = ConvertFromVNToEng(oad.textEn);

    return oad;
};
function changeLangTextBox(idTextbox) {

    var object = $(idTextbox);
    if (object == null || $(idTextbox).value == undefined || $(idTextbox).value == '') return;
    $(idTextbox).value = convert2Address((idTextbox == 'txtSearchMaps') ? oAdd : (($(idTextbox).Add != undefined) ? $(idTextbox).Add : $(idTextbox).value));
};

function ChangLangRecentBox() {
    var langRB = langRecentBox()[isLang];
    $('spanIntroRecent').innerHTML = langRB[0];
    $('spanRecent').innerHTML = langRB[1];
    if ($('spanLoginInfo')) {
        var spanLoginInfo = $('spanLoginInfo').childElements();
        spanLoginInfo[0].innerHTML = langRB[2];
        spanLoginInfo[1].innerHTML = langRB[3];
        spanLoginInfo[2].innerHTML = langRB[4];
    }
    $('spanPoint').innerHTML = langRB[5];
    $('aDeleteBox').innerHTML = langRB[6];
    $('aCloseRB').innerHTML = langRB[7];
};
function bsTabClick(e) {
    var ele = Event.element(e);
    if (ele.tagName != 'A') return;

    var boxSearchNew = $('boxSearchNew');
    if (ele.id == 'aBSTabDirection') {
        if (boxSearchNew.className == 'boxSearch_5' || boxSearchNew.className == 'boxSearch_3') return;
        if (boxSearchNew.className == 'boxSearch_4') boxSearchNew.className = 'boxSearch_5';
        else boxSearchNew.className = 'boxSearch_3';
        boxSearchNew.down('#aBSTabSearch').className = '';
    }
    else {
        if (boxSearchNew.className == 'boxSearch_4' || boxSearchNew.className == 'boxSearch_2') return;
        if (boxSearchNew.className == 'boxSearch_5') boxSearchNew.className = 'boxSearch_4';
        else boxSearchNew.className = 'boxSearch_2';
        boxSearchNew.down('#aBSTabDirection').className = '';
    }
    ele.className = 'aBSActiveTab';
    hideErrorInfo();
};
//----------------------------------------------------------------------------------------------------------------------------- load tag cloud
function loadTagCloud() {
    if (getFlashPlayerVersion().pv[0] < 7) return;

    var tagContent = $('tagContent');
    if (tagContent) {
        var so = new SWFObject("tagCloud/tagcloud.swf", "tagcloud", "300", "300", "7", "#ffffff"); //Quang 08/04
        so.addParam("wmode", "transparent");
        so.addVariable("tcolor", "0xffffff");
        so.addVariable("tcolor2", "0xffffff");
        so.addVariable("hicolor", "0x00ff00");
        so.addVariable("distr", "true");
        so.addVariable("mode", "tags");
        so.addVariable("tagcloud", encodeURIComponent(tagCloud));
        so.write("tagContent");
        tagContent.style.margin = '-20px 0 0';
        tagContent.style.padding = 0;
        $('divTopKeyWord').stopObserving();
    }
};

//kiem tra flash version
function getFlashPlayerVersion() {
    var UNDEF = "undefined", win = window, nav = navigator, OBJECT = "object", SHOCKWAVE_FLASH = "Shockwave Flash", FLASH_MIME_TYPE = "application/x-shockwave-flash", SHOCKWAVE_FLASH_AX = "ShockwaveFlash.ShockwaveFlash";
    var playerVersion = [0, 0, 0], d = null;
    if (typeof nav.plugins != UNDEF && typeof nav.plugins[SHOCKWAVE_FLASH] == OBJECT) {
        d = nav.plugins[SHOCKWAVE_FLASH].description;
        if (d && !(typeof nav.mimeTypes != UNDEF && nav.mimeTypes[FLASH_MIME_TYPE] && !nav.mimeTypes[FLASH_MIME_TYPE].enabledPlugin)) {
            d = d.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
            playerVersion[0] = parseInt(d.replace(/^(.*)\..*$/, "$1"), 10);
            playerVersion[1] = parseInt(d.replace(/^.*\.(.*)\s.*$/, "$1"), 10);
            playerVersion[2] = /[a-zA-Z]/.test(d) ? parseInt(d.replace(/^.*[a-zA-Z]+(.*)$/, "$1"), 10) : 0;
        }
    }
    else if (typeof win.ActiveXObject != UNDEF) {
        try {
            var a = new ActiveXObject(SHOCKWAVE_FLASH_AX);
            if (a) { // a will return null when ActiveX is disabled
                d = a.GetVariable("$version");
                if (d) {
                    d = d.split(" ")[1].split(",");
                    playerVersion = [parseInt(d[0], 10), parseInt(d[1], 10), parseInt(d[2], 10)];
                }
            }
        }
        catch (e) { }
    }
    return { pv: playerVersion };
};
// xem lai xem co xoa bo ham nay ko 
/*ham dung chung*/
function loadBoxFrame(divHolder) {
    var html = '';
    html += '<div class="box_tl"></div><div class="box_tc"></div><div class="box_tr"></div><div class="box_cl">' +
	'<div class="box_cr"><div id="box_inner_' + divHolder + '" class="box_inner"></div></div></div>' +
	'<div class="box_bl"></div><div class="box_bc"></div><div class="box_br"></div>' +
	'<div class="close_box"><a href="javascript:void(0);">Close this</a></div>';
    var divHolder = $(divHolder);
    divHolder.update(html);
};
/*Feedback*/
/*
Add by Quang 
01/02/2010
load form feedback
*/
function loadBoxFeedback(e) {

    var lang = langFeedBack()[isLang];
    var html = '';
    html += '<h4 class="box_caption">' + lang[0] + '</h4>';
    html += '<div class="groupbox clear">';
    html += '<div class="feedback_option" id="divFBOption">';
    html += '</div>';
    html += '<div class="feedback_form">';
    html += '<div class="textbox">';
    html += '<div class="txt_tl"></div>';
    html += '<div class="txt_tc"></div>';
    html += '<div class="txt_tr"></div>';
    html += '<div class="txt_cl">';
    html += '<div class="txt_cr">';
    html += '<div class="txt_inner">';
    html += '<input type="text" id="txtFBTitle" maxlength="200"/>';
    html += '<label class="inline_label">' + lang[5] + '</label>';
    html += '</div></div></div>';
    html += '<div class="txt_bl"></div>';
    html += '<div class="txt_bc"></div>';
    html += '<div class="txt_br"></div>';
    html += '</div></div>';
    html += '<div class="feedback_form">';
    html += '<div class="textbox">';
    html += '<div class="txt_tl"></div>';
    html += '<div class="txt_tc"></div>';
    html += '<div class="txt_tr"></div>';
    html += '<div class="txt_cl">';
    html += '<div class="txt_cr">';
    html += '<div class="txt_inner">';
    html += '<div class="textarea_inner">';
    html += '<textarea rows="3" cols="10"id="txtFBContent" maxlength="1000" ></textarea>';
    html += '<label class="inline_label">' + lang[11] + '</label>';
    html += '</div></div></div></div>';
    html += '<div class="txt_bl"></div>';
    html += '<div class="txt_bc"></div>';
    html += '<div class="txt_br"></div>';
    html += '</div></div>';
    html += '<div class="feedback_form">';
    html += '<label class="lbl_feedback_note">' + lang[6] + '</label></div>';
    html += '<div class="feedback_form" id="divFBProduct" >';
    html += '</div></div>';
    html += '</div></div>';
    html += '<div class="box_footer">';
    html += '<ul class="box_desc" style="display:none">';
    html += '<li>' + lang[7] + '</li></ul>';
    html += '<div class="button"><a href="javascript:void(0);" rel="nofollow"><span class="no_select" UNSELECTABLE="on">' + lang[8] + '</span></a></div></div>';
    var box = $('box');
    box.down('.box_inner').innerHTML = html;
    box.className = 'box box_feedback';
    copyPosition(true, null, box, 0, 0);
    loadFeedBackInfo();
    if (box.style.display == "none") box.style.display = "block";
    loadTextboxEvent(box);
    box.down('.close_box').observe('click', close_box);
    box.down('.button').observe('click', saveFeedBack);
    showShadow(true);
    // remove box quang cao  //box_ads
    var boxads = $('box').select('[class="box_ads"]');
    if (boxads.length != 0) box.removeChild(boxads[0]);
};

/*
Add by Quang 
01/02/2010
Change option feedback
*/
function changeOption() {
    var arr = $(document.body).select('.feedback_option a');
    arr.invoke('observe', 'click', function(e) {
        var ele = Event.element(e).up('span');
        if (ele.hasClassName('spn_active')) return;
        $(document.body).select('.feedback_option span').invoke('removeClassName', 'spn_active');
        ele.addClassName('spn_active');
    });
};

/*
Add by Quang 
01/02/2010
Event for feedback checkbox
*/
function loadCheckBox() {
    var arrCheckbox = $(document.body).select('.checkbox span');
    if (arrCheckbox.length > 0) {
        arrCheckbox.invoke('observe', 'click', function(e) {
            var ele = Event.element(e).up('.checkbox');
            if (ele.hasClassName('checked')) return;
            $(document.body).select('.checkbox').invoke('removeClassName', 'checked');
            ele.addClassName('checked');
            ele.down('input').checked = true;
        });
    }
    var arrLabel = $(document.body).select('.checkbox label');
    if (arrLabel.length > 0) {
        arrLabel.invoke('observe', 'click', function(e) {
            var ele = Event.element(e).up('.checkbox');
            if (ele.hasClassName('checked')) return;
            $(document.body).select('.checkbox').invoke('removeClassName', 'checked');
            ele.addClassName('checked');
            ele.down('input').checked = true;
        });
    }

};
/*end Feedback*/
/*
Add by Quang 
01/02/2010
Close box
*/
function close_box(e) {
    var id = $("box");
    var arr = $(id).select('.close_box');
    if (arr.length > 0) {
        if (arr[0] == utils.getElementFireEvent(e).parentNode) {
            hideclosebox(id)
        }
        arr[0].onclick = function(e) {
            hideclosebox(id)
        };
    }
    var ddlSortList = $('ddlSortList');
    if (ddlSortList) ddlSortList.style.visibility = 'visible';
};
// function an box co od la box
function hideclosebox(id) {
    id.addClassName('hide');
    if (id.style.display == "block") {
        if (id.style.removeAttribute)
            id.style.removeAttribute('display');
        else id.style.removeProperty("display");
    }
    var shadow = $("divShadow");
    if (shadow.style.display == "block") {
        if (shadow.style.removeAttribute)
            shadow.style.removeAttribute('display');
        else shadow.style.removeProperty("display");
    }
    if (shadow.className.indexOf(' hide') == -1) shadow.addClassName('hide');
};
/*
Add by Quang 
01/02/2010
Load events for textbox
*/
function loadTextboxEvent(container) {
    //textbox
    var arr = container.select('.textbox');
    arr.invoke('observe', 'click', textboxFocus);
    var arrTextbox = container.select('input', 'textarea');
    if (arrTextbox.length > 0) {
        arrTextbox.invoke('observe', 'focus', textboxFocus);
        arrTextbox.invoke('observe', 'blur', textboxBlur);
        if (!arrTextbox[0].visible()) arrTextbox[0].focus();
    }
};

/*
Add by Quang 
01/02/2010
Event click for textbox
*/
function textboxClick(e) {

    var ele = Event.element(e);
    if (ele.tagName != 'INPUT' && ele.tagName != 'TEXTAREA') {
        var arr = ele.up('.textbox').select('input', 'textarea');
        if (arr.length > 0) arr[0].focus();
    }
};

/*
Add by Quang 
01/02/2010
Event focus for textbox
*/
function textboxFocus(e) {

    var ele = Event.element(e);
    if (!ele.hasClassName('textbox')) ele = ele.up('.textbox');
    if (!ele) return;
    var el = ele.up().down('.focus');
    if (el) {
        el.removeClassName('focus');
        var label = el.down('label');
        if (label) label.show();
    };

    ele.addClassName('focus');
    var arr = ele.select('input', 'textarea');
    if (arr.length > 0) arr[0].focus();
    var label = ele.down('label');
    if (label) label.hide();
};

/*
Add by Quang 
01/02/2010
Event blur for textbox
*/
function textboxBlur(e) {
    var ele = Event.element(e);
    var tagName = ele.tagName;
    var isBackground = true;
    if ((tagName == 'INPUT' || tagName == 'TEXTAREA') && ele.value != '')
        isBackground = false;
    if (!ele.hasClassName('textbox')) ele = ele.up('.textbox');
    if (!ele) return;
    var el = ele.up().down('.focus');
    if (el) {
        el.removeClassName('focus');
        var label = ele.down('label');
        if (label && isBackground) label.show();
    }
};

/*
Add by Quang 
01/02/2010
Event for radio
*/
function radioChange(e) {
    var ele = Event.element(e);
    if (ele.tagName != 'LABEL' && ele.tagName != 'SPAN') return;
    var old = ele.up(2).down('.checked');
    if (old) old.removeClassName('checked');

    ele.up('.radio').addClassName('checked');
};

/*
function:load ds Product va ds Option phan loai FeedBack
create:09/02/2010 by hien_nguyen
*/
function loadFeedBackInfo() {
    if (jsonProduct == null && jsonFBOption == null)
        utils.call('Comp.aspx?st=' + strState + '&stpe=32', 'POST', 'showFBInfo', 'showFBInfo');
    else
        showFBInfo();
};
/*
-function:hien thi ds Products && ds Option phan loai feedBack
-create:09/02/2010 by hien_nguyen
*/
function showFBInfo(str) {
    if (arguments.length > 0) {
        if (str == ';;;') return;
        var infoReturn = str.split(';;;');
        jsonProduct = eval(infoReturn[0]);
        jsonFBOption = eval(infoReturn[1]);
    }
    //show ds Option FeedBack
    if (jsonFBOption != null && typeof (jsonFBOption) == 'object' && jsonFBOption.length > 0) {
        var html = '';
        for (var j = 0; j < jsonFBOption.length; j++) {
            var optionName = isLang == 0 ? jsonFBOption[j].NameVN : jsonFBOption[j].NameEng;
            var classOption = (jsonFBOption[j].tID == 1) ? "a_idea" : (jsonFBOption[j].tID == 2) ? "a_question" : (jsonFBOption[j].tID == 3) ? "a_problem" : "a_compliment";
            html += '<span ' + (j != 0 ? '' : 'class="spn_active"') + '>';
            html += '<a href="javascript:void(0);" rel="nofollow" class="' + classOption + '" id="FBOption_' + jsonFBOption[j].tID + '">' + optionName + '</a></span>';
        }
        $('divFBOption').update(html);
    }
    //show ds Product
    if (jsonProduct != null && typeof (jsonProduct) == 'object' && jsonProduct.length > 0) {
        var html = '';
        for (var i = 0; i < jsonProduct.length; i++) {
            html += '<div class="checkbox ' + (i != 0 ? "" : "checked") + '">' +
                   '<input type="checkbox" name="chk_product" id="FBProduct_' + jsonProduct[i].proID + '">' +
                   '<label for="chk_product" class="checkbox_label"><span></span>' + jsonProduct[i].proName + '</label></div>';
        }
        $('divFBProduct').update(html);
    }
    loadCheckBox();
    changeOption();
};
/*    
-function:save noi dung feedback cua user
-create:09/02/2010 by hien_nguyen
*/
function saveFeedBack(e) {
    var box = $('box');
    var title = utils.trim($('txtFBTitle').value.stripTags().stripScripts());
    var content = utils.trim($('txtFBContent').value.stripTags().stripScripts());
    var ulMessage = box.down('.box_desc');
    if (title == '' || content == '') {
        ulMessage.show();
        return;
    }
    else
        ulMessage.hide();
    try {
        var optionID = parseInt(box.down('.spn_active').down('A').id.split('_')[1]);
        var productID = parseInt(box.down('.checked').down('INPUT').id.split('_')[1]);
    } catch (ex) { var optionID = 1; var productID = 1; };
    var FBparam = { 'proID': productID, 'tID': optionID, 'td': title, 'cont': content };
    utils.call('Comp.aspx?st=' + strState + '&stpe=33', FBparam, 'POST', 'showFBResultSaving', 'showFBResultSaving');
    // show box thanks
    var langFB = langFeedBack()[isLang];
    box.down('.box_inner').update('<h4 class="box_caption">' + langFB[9] + '</h4><div class="groupbox clear"><p class="success">' + langFB[10] + '.</p></div>');
};
/*
-function:load event cho tab BSTabs
-create:11/03/2010
*/
function loadSearchTabEvent() {
    var txtSearchNearBy = $('txtSearchNearBy');
    var txtSearchYP = $('txtSearchYP');
    var txtSearchA = $('txtSearchA');
    var txtSearchB = $('txtSearchB');
    try {
        var autoText = new AutoComplete();

        var divBSTabs = $('divBSTabs');
        if (divBSTabs)
            divBSTabs.observe('click', searchTabClick);
        /*try {
        [txtSearchNearBy, txtSearchYP, txtSearchA, txtSearchB].each(function(item) { if (!Object.isUndefined(item)) item.value = ''; });
        } catch (ex) { }*/
        if (txtSearchNearBy) {
            var _snearby = txtSearchNearBy.cumulativeOffset();
            autoText.addTextBox(txtSearchYP, "Suggestion.aspx", 1, ',', [-1, _snearby[0] + 255, _snearby[1] + 25, 218, -1], { ext: 1 });
            $('btnSearchYP').up().observe('click', searchNearBy);
            if ($('ulBSContent')) $('ulBSContent').down('.btnReverse').down('A').observe('click', textReverse);

        }
        if (txtSearchA) {
            var _attTmp = txtSearchA.cumulativeOffset();
            autoText.addTextBox(txtSearchA, "Suggestion.aspx", 1, ',', [-1, _attTmp[0] + 15, _attTmp[1] + 25, 218, -1], { ext: 0 });
            autoText.addTextBox(txtSearchB, "Suggestion.aspx", 1, ',', [-1, _attTmp[0] - 5, _attTmp[1] + 55, 218, -1], { ext: 0 });
        }
    } catch (e) { }
};
/*
-function:event click for searchTab
-create:11/03/2010
*/
function searchTabClick(e) {
    var ele = Event.element(e);
    if (ele.tagName != 'A' || ele.hasClassName('active')) return;
    var divBSTabs = $('divBSTabs');
    var eleActive = divBSTabs.down('.active');
    if (eleActive) eleActive.removeClassName('active');
    ele.addClassName('active');

    var tabDirection = $('ulBSContent').down('.tab_direction_cont');
    if (ele.name.indexOf('gbox') != -1) {  // click vao tab direction
        tabDirection.removeClassName('hide');
        tabDirection.previous().addClassName('hide');
        tabDirection.next().removeClassName('hide');
    }
    else { // 2 tb con lai
        if (ele.name.indexOf('ybox') != -1) {
            tabDirection.next().addClassName('hide');
            tabDirection.previous().removeClassName('hide');
        } else {
            tabDirection.previous().addClassName('hide');
            tabDirection.next().removeClassName('hide');

        }
        tabDirection.addClassName('hide');
    }
    $("divsearchbox").className = ele.name;
    hideErrorInfo();

};
/*
-function :load ds tp viewmore or changecity
-para:type(0:trang index,1trang amthuc,lamdep,...,the same page)
-create:15/03/2010
*/
function clickOtherCity() {
    var type = document.URL.toLowerCase().indexOf('index.aspx') != -1 ? 1 : 2;

    if (strCity == '-1')
        utils.call("Cate.aspx?", { "st": strState, "f": 3, "stpe": type }, "POST", "showListOtherCity", "showListOtherCity");
    else {
        showListOtherCity(strCity);
    }
};
/*
-function :show ds ThanhPho
-para:strJSON:chuoi ds tp tra ve
-create:15/03/2010
*/
function showListOtherCity(strJSON) {

    var html = "";
    strCity = strJSON;
    if (strJSON == "-1") { return; }
    var oListCity;
    try { arrUnit = strJSON.evalJSON(true); } catch (ex) { arrUnit = strJSON; }
    var k = 0;
    var sps = strState.substr(strState.length / 2);
    if (arrUnit.length > 0) {
        var column = document.URL.toLowerCase().indexOf('index.aspx') != -1 ? 2 : 3;
        var items = arrUnit.length; var row = items / column; var mod = items % column;
        var flag = (mod != 0) ? 1 : 0;
        var index = 0;
        html += '<h4 class="box_caption">' + (langListCity()[isLang][0]) + '</h4><div class="groupbox clear"><ul class="list_items">';
        for (var j = 1; j <= column; j++) {
            html += '<li style="' + ((j != 1) ? "pading-left:2px;" : "") + '">';
            for (var k = 1; k <= (row + flag); k++) {
                if (index < items) {
                    var oCity = arrUnit[index];
                    var srplit = window.location.pathname.split("/");
                    var pname = srplit[srplit.length - 1];
                    if (pname.indexOf('?') != -1) pname = pname.substring(0, pname.indexOf('?'));
                    var href = pname + "?st=" + oCity.st;
                    html += "<div class='one_item'><span class='bullet'></span>";
                    html += "<a id='lnk_" + oCity.ID + "' href='" + href + "'>" + ((isLang == 0) ? oCity.nameVN : oCity.nameEN) + "</a></div>";
                    index += 1;
                }
            }
            if (mod > 1) {
                flag = 1;
                mod -= 1;
            }
            else flag = 0;
            html += "</li>";
        }
        html += '</ul></div>';
        var aViewMore = $("aChageCity/Province") || $("aOrtherCity");
        if (aViewMore == null) return;
        var arrPos = aViewMore.cumulativeOffset();
        var box = $('box');
        box.down('#box_inner').update(html);
        box.className = "box box_others hide";
        box.removeClassName('hide');
        box.show();
        box.setStyle({
            top: arrPos[1] + 30 + 'px',
            left: (arrPos[0] - 5) + 'px'
        });
        box.down('.close_box').observe('click', close_box);
        var ddlSortList = $('ddlSortList');
        if (ddlSortList) ddlSortList.style.visibility = 'hidden';
        var boxads = $('box').select('[class="box_ads"]'); //remove box qc 
        if (boxads.length != 0) box.removeChild(boxads[0]);
    }
};
//ham convert viet sang Eng va replace ky tu dac biet trong url
function replaceRegToEng(strValue) {
    strValue = ConvertFromVNToEng(strValue.toLowerCase());
    strValue = strValue.replace(/[!@*()!?\'\"]+/g, "");
    strValue = strValue.replace(/[&_;:.+]+/g, "-");
    return strValue.replace(/[-+\s]+/g, "-");
};
function pos4Popup(ele) {
    if (arguments.length > 1) {//truong hop send sms,send mail o trang result,searchresult
        var box = $('box');
        if (box) {
            margintop = document.body.scrollTop || document.documentElement.scrollTop;
            marginleft = document.body.scrollLeft || document.documentElement.scrollLeft;
            var windowSize = utils.windowSize();
            var url = document.URL.toLowerCase();
            if (url.indexOf("details.aspx") != -1) {
                var el = $('divTabComment');
                window.onscroll = scrollDetail;
                var pos = el.cumulativeOffset();
                var size = box.getDimensions();
                box.style.top = (margintop + (windowSize[1] - size.height) / 2) + "px";
                box.style.left = (marginleft + (windowSize[0] - size.width) / 2) + "px";

            } else if (url.indexOf('result') != -1 || url.indexOf('writereview') != -1) {
                var el = $("divResultList").up('.body_results_r');
                var pos = el.cumulativeOffset();
                var size = box.getDimensions();
                box.style.top = (margintop + (windowSize[1] - size.width) / 2) + "px";
                box.style.left = (pos[0] + (el.getWidth() - size.height) / 2) + "px";
            }
            else {
                var el = $('uTabComments') || $('divListTopList');
                window.onscroll = scrollDetail;
                var pos = el.cumulativeOffset();
                var size = box.getDimensions();
                box.style.top = (margintop + (windowSize[1] - size.height) / 2) + "px";
                box.style.left = (marginleft + (windowSize[0] - size.width) / 2) + "px";
            }
        }
    } else {
        var size = ele.getDimensions();
        ele.style.left = (document.body.offsetWidth - size.width) / 2 + 'px';
        ele.style.top = (document.body.offsetHeight - size.height) / 2 + 'px';
    }
    if (ele.hasClassName('hide')) ele.removeClassName('hide');
    else ele.show();
    var boxads = $('box').select('[class="box_ads"]'); //remove box quang cao 
    if (boxads.length != 0) box.removeChild(boxads[0]);
};


function changeLangBoxCategory() {
    var ulBoxCategory = $('ulBoxCategory');
    if (ulBoxCategory != null) {
        var strHTML = "";
        var langBC = langBoxCate()[isLang];
        var arrPage = ["AmThuc.aspx", "KhachSan.aspx", "MuaSam.aspx", "GiaiTri.aspx", "DuLich.aspx", "LamDep.aspx", "TaiChinh.aspx", "YTe.aspx"];
        var url = document.URL.toLowerCase();
        var isProfile = url.indexOf('profiles') != -1 ? true : false;
        if (langBC.length > 0) {
            for (var i = 0; i < langBC.length; i++) {
                var linkPage = arrPage[i] + "?st=" + strState + "&l=" + isLang;
                if (isProfile) linkPage = "../" + linkPage;
                var cateName = langBC[i];
                strHTML += "<li style='z-index:" + (i + 1) + "'>";
                if (url.indexOf(arrPage[i].toLowerCase()) != -1)
                    strHTML += "<span>" + langBC[i] + "<em class='ico icon_" + (i + 1) + "'><img src='theme/images/icon/category/icon_cate.png' alt='' /></em></span>";
                else
                    strHTML += "<a href='" + linkPage + "'><span>" + langBC[i] + "<em class='ico icon_" + (i + 1) + "'><img src='theme/images/icon/category/icon_cate.png' alt='' /></em></span></a>";
                strHTML += "</li>";
            }
        }
        ulBoxCategory.update(strHTML);
    }
};
function changeLanguage() {

    isLang = (isLang == 1) ? 0 : 1;
    var link = new String(window.location);
    var defaulpage = 'vnmap.aspx';
    if (link.toLowerCase().indexOf('vnmap.aspx') != -1 || (link.toLowerCase().indexOf('.aspx') == -1)) {//trang default
        var strLang = (isLang == 0) ? 'vn/' : 'en/';
        var subpath = '';
        if (link.toLowerCase().indexOf('.aspx') == -1 && (link.lastIndexOf('/') != link.length - 1)) link = link + '/';

        subpath = link.substring(0, link.lastIndexOf('/')).replace('/vn', '').replace('/en', '');
        if (link.toLowerCase().indexOf('vnmap.aspx') != -1 || defaulpage == 'vnmap.aspx') {//vnmap
            defaulpage = 'vnmap.aspx';
            link = subpath + '/' + strLang + defaulpage;
            var param = Object.toQueryString(getMapInfo());
            link = createLinkPage(defaulpage);
        } else {
            link = subpath + '/' + strLang + defaulpage + "?st=" + strState + "&l=" + isLang;
        }

    } else //cac trang khac tam thoi doi chi thay doi url
    {
        if (link.indexOf('vn/') != -1) {
            if (link.indexOf("&l=") == -1 && link.indexOf("?l=") == -1)
                link += ((link.indexOf('?') == -1) ? '?l=1' : '&l=1');
            link = link.replace('vn/', 'en/').replace('?l=0', '?l=1').replace('&l=0', '&l=1');
        } else if (link.indexOf('en/') != -1) {
            if (link.indexOf("&l=") == -1 && link.indexOf("?l=") == -1)
                link += ((link.indexOf('?') == -1) ? '?l=0' : '&l=0');
            link = link.replace('en/', 'vn/').replace('?l=1', '?l=0').replace('&l=1', '&l=0');
        }
        else {
            var strLang = (isLang == 0) ? 'vn' : 'en';
            var subpath = link.substring(0, link.lastIndexOf('/'));
            var subquery = link.substring(link.lastIndexOf('/') + 1, link.length);
            if (subquery.indexOf("?l=") != -1) {
                subquery = subquery.replace(subquery.substr(subquery.indexOf("?l="), 4), '?l=' + isLang);
            }
            else if (subquery.indexOf("&l=") != -1) {
                subquery = subquery.replace(subquery.substr(subquery.indexOf("&l="), 4), '&l=' + isLang);
            } else {
                subquery += ((subquery.indexOf('?') == -1) ? '?l=' + isLang : '&l=' + isLang);
            }
            link = subpath + '/' + strLang + '/' + subquery;
        }
    }
    window.location.href = link;
};
function toParamsOfQuery(str) {
    var strEx = '{';
    var temp = str.substring(1).split("&");
    for (var i = 0; i < temp.length; i++) {
        var val = temp[i].split("=");
        strEx += '"' + val[0] + '":"' + unescape(val[1]) + '",';
    }
    if (strEx.charAt(strEx.length - 1) == ",") strEx = strEx.substring(0, strEx.length - 1);
    strEx += '}';
    return strEx.evalJSON(true);
};

//onclick button Xem Them o tab Nhieu Nhat, Moi Nhat cua cac trang chuyen muc
function onClickMore_Cate(ele) {
    var param = {};
    var window_href = window.location.toString().split('/');
    var url = window_href[window_href.length - 1].toLowerCase().split('.aspx')[0];
    switch (url) {
        case "amthuc": param.id = 1; break;
        case "giaitri": param.id = 4; break;
        case "khachsan": param.id = 2; break;
        case "muasam": param.id = 3; break;
        case "lamdep": param.id = 6; break;
        case "yte": param.id = 9; break;
        case "taichinh": param.id = 7; break;
        case "dulich": param.id = 5; break;
    }
    param.stpe = 230;
    param.st = strState;

    ele.observe('click', function(o) {
        var obj = utils.getElementFireEvent(o);
        if (obj.className != 'arrow') obj = obj.up('.view_more').down('.arrow');
        count += 4;
        param.start = count;
        var div = ele.previous('.module_body_reviews').childElements();
        var obj1;
        div.each(function(o) {
            if (o.className != 'hide')
                obj1 = o.id;
        });
        if (obj.name == 'more') {
            //hien thi 4 comment tiep theo cua Moi Nhat
            if (obj1 == 'divCommentNews') {
                param.gt = 'latest';
                utils.call('Comp.aspx', param, 'POST', 'loadMoreCommentNews', 'loadMoreCommentNews');
            }
            //hien thi 4 comment tiep theo Xem Nhieu Nhat
            else if (obj1 == 'divCommentBest') {
                param.gt = 'most';
                utils.call('Comp.aspx', param, 'POST', 'loadMoreCommentBest', 'loadMoreCommentBest');
            }
        }
        else {
            count = 1;
            param.start = count;
            //hien thi 4 comment dau tien cua Moi Nhat
            if (obj1 == 'divCommentNews') {
                param.gt = 'latest';
                utils.call('Comp.aspx', param, 'POST', 'loadCommentsNews', 'loadCommentsNews');
            }
            //hien thi 4 comment dau tien Xem Nhieu Nhat
            else if (obj1 == 'divCommentBest') {
                param.gt = 'most';
                utils.call('Comp.aspx', param, 'POST', 'loadCommentsBest', 'loadCommentsBest');
            }
        }
    });
};
/* 
* ham callback khi click Moi Nhat --> Xem Them*/
function loadMoreCommentNews(html) {
    while (html.indexOf("***") != -1)
        html = html.replace("***", "'");
    $('divCommentNews').insert(html);
    var ele = $('uTabComments').next('.view_more').down('.arrow');
    if (html == '') {
        ele.name = '';
        ele.innerHTML = langDirectory()[isLang][2];
    }
};
/* 
* ham callback khi click Xem Nhieu Nhat --> Xem Them*/
function loadMoreCommentBest(html) {
    while (html.indexOf("***") != -1)
        html = html.replace("***", "'");
    $('divCommentBest').insert(html);
    var ele = $('uTabComments').next('.view_more').down('.arrow');
    if (html == '') {
        ele.name = '';
        ele.innerHTML = langDirectory()[isLang][2];
    }
};
/* 
* ham callback khi click Xem Nhieu Nhat --> Rut Gon*/
function loadCommentsBest(html) {
    while (html.indexOf("***") != -1)
        html = html.replace("***", "'");
    strTabCommentBest = html;
    $('divCommentBest').update(html);
    var ele = $('uTabComments').next('.view_more').down('.arrow');
    ele.name = 'more';
    ele.innerHTML = langDirectory()[isLang][0];

};
/* 
* ham callback khi click Moi Nhat --> Rut Gon*/
function loadCommentsNews(html) {
    while (html.indexOf("***") != -1)
        html = html.replace("***", "'");
    strTabCommentNew = html;
    $('divCommentNews').update(html);
    var ele = $('uTabComments').next('.view_more').down('.arrow');
    ele.name = 'more';
    ele.innerHTML = langDirectory()[isLang][0];
};
/* TN 20/07
*  Load popup Doc tin tuc*/
function showDetailReading(_html) {
    var news_cont = $('news_cont');
    var arr = _html.split('@a@');
    var content = arr[0];
    if (news_cont) {
        news_cont.update(unescape(content));
        //if (arr[2] == '0')
        $('feedDetails').down('.poweredby').update('Powered by: ' + arr[1]);
        //else 
        if (arr[2] == '1') {
            $('feedDetails').down('.previous_news').style.display = 'block';
            $('feedDetails').down('.next_news').style.display = 'block';
        }
        //scrollThisFeed($('feedScrollbar'), $('news_cont'));
        try {
            var box_feed_inner = $('box_feed_inner');
            var prev = box_feed_inner.down('.previous_news');
            var next = box_feed_inner.down('.next_news');
            next.observe('click', clickFeedSlide);
            prev.observe('click', clickFeedSlide);
        } catch (ex) { }
    }
    else return;
};

/*
Them chuc nang scroll cho eleScroller
Tham so:
- eleScrollbar: element dung lam scrollbar
- eleScroller: element se di chuyen khi nam keo eleScrollbar
*/
function scrollThisFeed(eleScrollbar, eleScroller) {
    eleScrollbar.show();
    var size = { width: 602, height: 480 };
    var container = eleScroller.up();
    if (container) size = container.getDimensions();
    var scroller = new Scrolling.Scroller(eleScroller, size.width, size.height);
    new Scrolling.Scrollbar(eleScrollbar, scroller, new Scrolling.ScrollTween());
    if (eleScrollbar.visible()) eleScroller.style.paddingRight = '40px';
    else eleScroller.style.paddingRight = '1px';
};

/* show hide popup*/
var MyUtils = {
    _show: function(element) {
        return element.removeClassName('hide');
    },
    _hide: function(element) {
        return element.addClassName('hide');
    }
};
Element.addMethods(MyUtils);

function showDPopup(isShow, classname) {
    if (isShow) {
        $('divShadow').show();
        var feedDetails = $('feedDetails');
        feedDetails.down('.box').className = 'box ' + classname;
        var box_inner = feedDetails.down('.box_inner');
        var html = '';
        switch (classname) {
            case 'box_feed_reading':
                html = '<a class="previous_news" href="javascript:void(0);" style="display:none">Previous</a>' +
                        '<div class="feedDetails_cont">' +
                            '<div id="news_cont" class="news_cont"></div>' +
                //'<div id="feedScrollbar" class="select_scrollbar"><div class="Scrollbar-Up"></div><div class="Scrollbar-Down"></div><div class="Scrollbar-Track"><div class="Scrollbar-Handle"></div></div></div>' +
                            '<div id="feedShadow" class="shadow transparent hide"></div>' +
                            '<img id="progressing" class="progressing hide" src="theme/images/progressing.gif" />' +
                        '</div>' +
                        '<a class="next_news" href="javascript:void(0);" style="display:none">Next</a>' +
                        '<span class="poweredby">Powered by:</span>';
                break;
            case 'box_feed_checkin':
                html = '<div class="feed_checkin_cont clear">' +
  		                    '<div class="map feed_map" id="divFeedMap"></div>' +
                            '<div class="feed_list">' +
        	                    '<div class="feed_tab feed_tab_1">' +
            	                    '<a class="feed_tab_checkin" href="javascript:void(0);">Check in</a>' +
                                    '<a class="feed_tab_comment" href="javascript:void(0);">CÃƒÂ¡Ã‚ÂºÃ‚Â£m nhÃƒÂ¡Ã‚ÂºÃ‚Â­n</a></div>' +
                                '<div class="feed_list_cont clear">' +
           	                        '<ul class="clear" id="feed_list_cont"></ul>' +
           	                        '<div id="feedScrollbar" class="select_scrollbar hide"><div class="Scrollbar-Up"></div><div class="Scrollbar-Down"></div><div class="Scrollbar-Track"><div class="Scrollbar-Handle"></div></div></div></div></div>' +
           	                    '</div></div>' +
           	                 '<div class="shadow transparent hide"></div>' +
           	                 '<img src="theme/images/progressing.gif" class="progressing hide"></div>';
                break;
            case 'box_feed_listening':
                html = '<div class="feed_player">' +
    	                    '<div class="fp_header">' +
        	                    '<div class="fp_header_tl"></div>' +
                                '<div class="fp_header_tc">' +
            	                    '<marquee scrolldelay="100"><h6 id="fp_header"></h6></marquee>' +
                                    '<ul class="fp_func">' +
                	                    '<li><a class="fp_add_to_playlist" href="javascript:void(0);">Button Add To Playlist</a></li>' +
                                        '<li><a class="fp_send_as_gift" href="javascript:void(0);">Button Send As Gift</a></li></ul></div>' +
                                '<div class="fp_header_tr"></div></div>' +
                            '<div class="fp_body">' +
                                '<div id="player"></div>' +
                                '<div class="fp_bg"><img id="fp_bg_img" src="theme/images/bg_feed_player.jpg" alt="background of player" /></div>' +
                            '</div>' +
                            '<div class="fp_footer" id="fp_footer"></div>' +
                        '</div>' +
                        '<span class="poweredby">Powered by:</span>';
                break;
        }
        box_inner.update(html);
        feedDetails._show();
        $('feedDetails').down('.close_box').observe('click', function() {
            vID = ''; eM = '';
            index = -1;
            arrFeed = null;
            $('feed_profile').update('');
            $('box_feed_inner').update('');
            $('feedDetails')._hide();
            $('divShadow').hide();
        });
        copyPosition(true, null, feedDetails.down('.box'), 0, 0);
    }
    else {
        $('divShadow')._hide();
        $('feedDetails').hide();
    }
};

/* 
*  load info cua user*/
function loadInfoUser(html) {
    if (html.indexOf('-v-') != -1) {
        var arr = html.split('-v-');
        var html = '';
        html += '<a href="' + arr[2].toString() + '" class="profile_avata">' +
        	'<img alt="' + arr[1].toString() + '" src="' + (arr[3] != "" ? httpImages + "Profiles/" + arr[3] : "theme/images/noAvatar.jpg") + '"></a>' +
        '<a href="' + arr[2].toString() + '" class="profile_nick">' + arr[1].toString() + '</a><br>' +
        '<span class="profile_activity">' + arr[0].toString() + '</span>';
        $('feed_profile').update(html);
    }
};
/* 
*  hien thi Power By: ten cong ty*/
function displayPoweredBy(fID) {
    var original = '';
    switch (fID) {
        case 2: original = 'TinTheThao';
            break;
        case 4: original = 'TimNhanh';
            break;
        case 5: original = 'TheGioiSanhDieu';
            break;
        case 6: original = 'NCT';
            break;
        case 7: original = 'Yume';
            break;
    }
    return original;
};

/* 
*  click Next,Back cua moi feed*/
function clickFeedSlide(e) {
    try { $('feedScrollbar').down('.Scrollbar-Handle').style.top = '0'; } catch (ex) { }
    $('news_cont').style.top = '0';
    var ele = utils.getElementFireEvent(e);
    var param = { stpe: 100, 'fID': fID, 'vID': vID, 'eM': eM };
    if (arrFeed == null) {
        $('feedShadow').removeClassName('hide');
        $('progressing').removeClassName('hide');
        if (ele.className == 'next_news') utils.call('Comp.aspx', param, 'POST', 'loadFeedNext', 'loadFeedNext');
        else if (ele.className == 'previous_news') utils.call('Comp.aspx', param, 'POST', 'loadFeedBack', 'loadFeedBack');
    }
    else {
        $('feedShadow').removeClassName('hide');
        $('progressing').removeClassName('hide');
        if (ele.className == 'next_news') {
            indexFeed++;
            if (indexFeed == arrFeed.length - 1) indexFeed = 0;
        }
        else if (ele.className == 'previous_news') {
            indexFeed--;
            if (indexFeed == -1) indexFeed = arrFeed.length - 2;
        }
        showContentFeed(arrFeed[indexFeed]);
    }
};
/* 
*  callback khi click Next cua moi feed*/
function loadFeedNext(res) {
    if (res != '') {
        var arrres = res.split('@b@');
        arrFeed = arrres;
        indexFeed++;
        if (indexFeed == arrFeed.length - 1) indexFeed = 0;
        showContentFeed(arrFeed[indexFeed]);
    }
};
/* 
*  callback khi click Back cua moi feed*/
function loadFeedBack(res) {
    if (res != '') {
        var arrres = res.split('@b@');
        arrFeed = arrres;
        indexFeed--;
        if (indexFeed == -1) indexFeed = arrFeed.length - 2;
        showContentFeed(arrFeed[indexFeed]);
    }
};
/* 
*  hien thi noi dung cua popup khi click Next/Back*/
function showContentFeed(html) {
    $('feedShadow').addClassName('hide');
    $('progressing').addClassName('hide');
    var size = $('news_cont').up().getDimensions();
    if (html != '') {
        var content = html.split('@a@');
        $('news_cont').update(unescape(content[2]));
        $('feedDetails').down('.poweredby').update('Powered by: ' + displayPoweredBy(parseInt(content[3])));
    }
    else if (html == '') {
        $('news_cont').update('Nothing!!!');
        $('feedDetails').down('.poweredby').update('');
    }
    var s = $('news_cont').getDimensions();
    //    if (s.height > size.height)
    //        scrollThisFeed($('feedScrollbar'), $('news_cont'));
    //    else $('feedScrollbar').hide();
};

/*Load popup Checkin*/
function showDetailCheckin(arr) {
    var html = '';
    var len = arr.length;
    if (len > 10) len = 10;
    for (var i = 0; i < len; i++) {
        var feedID = arr[i].FunctionID + '-v-' + arr[i].IDView + '-v-' + arr[i].Lat + '-v-' + arr[i].Lon + '-v-' + arr[i].LinkImage;
        var title = unescape(arr[i].Title.toString());
        if (title.length > 21) title = title.truncate(21, '...');
        if (i == 0) html += '<li>';
        else html += '<li><div class="hLine" ></div>';
        html += '<a class="fcomp_photo" href="javascript:void(0);" id="feed-v-' + feedID + '"><img src="' + arr[i].LinkImage + '" alt="' + unescape(arr[i].Title) + '" /></a>' +
                                    '<a class="fcomp_name" href="javascript:void(0);" title="' + unescape(arr[i].Title) + '"  id="feed-v-' + feedID + '">' + title + '</a><br />' +
                                    '<i>' + arr[i].DateFeed + '</i>' +
                                '</li>';
    }
    $('feed_list_cont').update(html);
    if (arr.length > 5)
        $('feedScrollbar').show();
    else $('feedScrollbar').hide();

    try { if (arr.length > 5) scrollThisFeed($('feedScrollbar'), $('feed_list_cont')); } catch (ex) { }
    $('box_feed_inner').down('.feed_tab').select('a').each(function(obj) { obj.observe('click', changeTabCheckin); });
};

/* 
*  thay doi cac subtab cua feed Checkin*/
function changeTabCheckin(e) {
    var ele = utils.getElementFireEvent(e);
    $('feed_list_cont').update('');
    if (ele.className == 'feed_tab_checkin') {
        ele.up('.feed_tab').className = 'feed_tab';
        $('feed_list_cont').update(loadFeedListCheckin(strFeedCheckin));
    }
    else if (ele.className == 'feed_tab_comment') {
        ele.up('.feed_tab').className = 'feed_tab feed_tab_2';
        if (strFeedExper == '') {
            var param = { "stpe": 120, "fID": fID, "eM": eM, "st": strState };
            utils.call('Comp.aspx', param, 'POST', 'loadPopupExper', 'loadPopupExper');
        }
        else $('feed_list_cont').update(loadFeedListExper(strFeedExper));
    }
};
/* 
*  callback khi click feed Checkin*/
function loadPopupCheckin(res) {

    /* showDPopup(1, 'box_feed_checkin');
    loadInfoUser(user);
    strFeedCheckin = res;
    
    showDetailCheckin(res);
    $('feed_list_cont').observe('click', clickFeedList);
    */

    // tam thoi chua sua kip phan nay
};
/* 
*  callback khi click subtab Cam Nhan*/
function loadPopupExper(res) {
    strFeedExper = res;
    if (res == '') strFeedExper = '[]';
    $('feed_list_cont').update(loadFeedListExper(strFeedExper));
};
/* 
*  hien thi list feed khi click subtab Checkin*/
function loadFeedListCheckin(arr) {
    var html = '';
    if (arr.length < 6 || arr == '') $('feedScrollbar').hide();
    else $('feedScrollbar').show();
    if (arr != '[]') {
        var len = arr.length;
        if (len > 10) len = 10;
        for (var i = 0; i < len; i++) {
            var feedID = '17-v-' + arr[i].IDView + '-v-' + arr[i].Lat + '-v-' + arr[i].Lon + '-v-' + arr[i].LinkImage;
            var title = unescape(arr[i].Title.toString());
            if (title.length > 21) title = title.truncate(21, '...');
            if (i == 0) html += '<li>';
            else html += '<li><div class="hLine" ></div>';
            html += '<a class="fcomp_photo" href="javascript:void(0);" id="feed-v-' + feedID + '"><img src="' + arr[i].LinkImage + '" alt="' + unescape(arr[i].Title) + '" /></a>' +
                '<a class="fcomp_name" href="javascript:void(0);" title="' + unescape(arr[i].Title) + '" id="feed-v-' + feedID + '">' + title + '</a><br />' +
                '<i>' + arr[i].DateFeed + '</i>' +
            '</li>';
        }
    }
    return html;
};
/* 
*  hien thi list feed khi click subtab Cam Nhan*/
function loadFeedListExper(arr) {
    var html = '';
    if (arr.length < 6 || arr == '') $('feedScrollbar').hide();
    else $('feedScrollbar').show();
    if (arr != '[]') {
        var len = arr.length;
        if (len > 10) len = 10;
        for (var i = 0; i < len; i++) {
            var compinfo = arr[i].CompInfo.split('***');
            var feedID = '16-v-' + compinfo[1] + '-v-' + compinfo[2] + '-v-' + compinfo[3];
            var title = compinfo[0].toString();
            var imgurl = 'http://images.diadiem.com/Images_' + strState + '/' + arr[i].Pic;
            if (title.length > 21) title = title.truncate(21, '...');
            if (i == 0) html += '<li>';
            else html += '<li><div class="hLine" ></div>';
            html += '<a class="fcomp_photo" href="javascript:void(0);" id="feed-v-' + feedID + '"><img src="' + imgurl + '" alt="' + compinfo[0] + '" /></a>' +
                '<a class="fcomp_name" href="javascript:void(0);" title="' + compinfo[0] + '" id="feed-v-' + feedID + '">' + title + '</a><br />' +
                '<i>' + arr[i].Datetime + '</i>' +
            '</li>';
        }
    }
    return html;
};
/* 
*  click item cua subtab Checkin,Cam Nhan*/
function clickFeedList(obj) {
    var ele = Event.element(obj);
    if (ele.tagName == 'IMG') ele = ele.up();
    if (ele.tagName != 'A' || ele.id == '') return;

    var info = ele.id.split('-v-');
    switch (parseInt(info[1])) {
        case 16:
            //Write Review: hien thi trang detail cua cong ty
            var pas = strState.substr(strState.length / 2);
            var url = 'Details.aspx?st=' + strState + '&l=' + isLang + '&cID=' + utils.encode(info[2], pas) + '&ll=' + utils.encode(info[1] + ";" + info[2], pas);
            window.open(url);
            break;
        case 17:
            //Checkin: hien thi ban do voi lat lon
            var pas = strState.substr(strState.length / 2);

            break;
    }
};
/* Load popup Nghe nhac*/
function showDetailListening(song_name, fID, arrimg) {
    if (arrimg.length > 2)
        slideShow();
    else
        $('fp_bg_img').src = 'player/' + (fID == '6' ? 'NCT.jpg' : 'yume.jpg');
    $('fp_header').update(song_name);
    $('feedDetails').down('.poweredby').update('Powered by: ' + displayPoweredBy(parseInt(fID)));
};

//TN 20/07 Hien thi hinh nen cua player
function slideShow() {
    if ($('fp_bg_img')) {
        $('fp_bg_img').src = arrimg[indeximg];
        indeximg++;
        if (indeximg == arrimg.length) indeximg = 1;
        timeout = setTimeout(slideShow, 3000);
    }
};


//callback khi onclick tab 2Play
function loadPlay(html) {
    while (html.indexOf("***") != -1)
        html = html.replace("***", "'");
    strTabPlay = html;
    clearTimeout(timeout);

    // for (var i = k; i < record; i++)
    for (var i = record - 1; i >= 0; i--)
        loadItems(i, strTabPlay);
};

//callback khi onclick tab 2Read
function loadRead(html) {
    while (html.indexOf("***") != -1)
        html = html.replace("***", "'");
    strTabRead = html;
    clearTimeout(timeout);

    for (var i = record - 1; i >= 0; i--)
        loadItems(i, strTabRead);
};

//callback khi onclick tab 2Go
function loadGo(html) {

    while (html.indexOf("***") != -1)
        html = html.replace("***", "'");
    strTabGo = html;
    clearTimeout(timeout);

    for (var i = record - 1; i >= 0; i--)
        loadItems(i, strTabGo);
};
//hien thi hinh max size cua checkin
function loadCheckinPhoto(obj) {
    var path = obj.src;
    if (path == '') return;

    var img = new Image();
    img.onload = function(obj) {
        var feedDetails = $('feedDetails');
        feedDetails.down('#box_feed_inner').update(img);
        feedDetails._show();
        $('divShadow').show();

        img.style.verticalAlign = 'top';

        var box = feedDetails.down('.box');
        box.style.width = (img.width + 29) + 'px';
        copyPosition(true, null, box, 0, 0);

        feedDetails.down('.close_box').observe('click', function() {
            vID = ''; eM = '';
            index = -1;
            arrFeed = null;
            $('feedDetails')._hide();
            $('divShadow').hide();
            $('feed_profile').update('');
            $('box_feed_inner').update('');
            $('feedDetails').down('.box').style.width = '';
        });
    };
    img.src = path.replace('w100', 'max');
    img.alt = obj.alt;
};
//event key enter when search company nearpoint advert
function enterSearchNearPointAdv(e) {
    e = e || window.event;
    if ((e.keyCode == "13" || e.which == "13" || e.charCode == "13")) {
        var txtNearPoint = $('divToolTip').down('.tooltip_search').down('a');
        if (txtNearPoint != null && $('divToolTip').down('input').value != "") {
            if (document.URL.toLowerCase().indexOf('vnmap.aspx') != -1)
                tooltipAdvFullClick(txtNearPoint);
        }
        else
            tooltipAdvFullClick(txtNearPoint);
        if (e.preventDefault) e.preventDefault();
    }
};
String.prototype.endsWith = function(suffix) {
    return this.match(suffix + "$") == suffix;
};
