﻿//载入滚动信息
/*
function loadMarqueeInfo() {
    var cuXiaoList =
        [
            {
                title: "2010年9月26日至28日第五届中博会在南昌国际会展中心举行",
                url: 'http://expocentralchina.mofcom.gov.cn/pub/zbblh/default.htm'
            },
            {
                title: "南昌之窗是第五届中博会电子地图服务唯一合作伙伴",
                url: 'http://www.nc0791.cn/'
            },
            {
                title: "2010年11月27日一30日2010中国绿色食品博览会在南昌国际展览中心举行",
                url: 'http://hzb.nc.gov.cn/news_view.asp?id=461'
            }
        ];

    var t = '';
    var b = 341;
    var cn = ['abfef5', 'efabfe', 'fff9ad', '7c84ff', 'ff8280'];
    var m = cn.length;
    for (k = 0; k < cuXiaoList.length; k++) {
        var url = cuXiaoList[k].url;
        var title = cuXiaoList[k].title;

        var mk = k % m;
        var c = cn[mk];
        var h = b + mk * 33;
        t += "<li style='background-position-y:-" + h + "px;color:#" + cn[mk] + "'>";
        t += "<A style='COLOR: #" + c + "' href='" + url + "' target='_blank'>" + title + "</A>";
        t += "</li>";
    }
    document.getElementById("gonggao").innerHTML = t;
    new Marquee("gonggao", 2, 1, 640, 25, 20, 0, 0);
}
*/

//载入天气预报
function loadTimeWeather() {
    //debugger;
    var requestUrl = "map/AjaxHandle.ashx?req=timeweather";
    downloadUrl(requestUrl, function(request) {
        var rText = request.responseText;
        document.getElementById("timeWeather").innerHTML = rText;
    });
}

//主题面板
var curThemeName = '';
function loadThemeMapsTypeList()
{
    var requestUrl ="map/AjaxHandle.ashx?req=ThemeMapsBigType";
    downloadUrl(requestUrl, function(request) {
        //debugger;
        var json = xmlHttpRequestJson(request);
        if (json == null || json == 'undefined')
            return false;
        var lists = json.ThemeTypeLists;
        var t = '';
        var curThemeType = '';
        var sw = 0; //统计宽度
        var w = 0;
        var len = lists.length;
        var ztNavhtml = "";
        var ztMenuhtml = "";

        for (var k = len - 1; k > -1; k--) {
            var tid = lists[k].BCT_ID;
            var tname = lists[k].BCT_TypeName.trim();
            if (tname.indexOf('专题') > -1) {
                continue;
            }
            if (k == 0) {
                curThemeType = tid;
                curThemeName = tname;
            }
            //专题处理
            w = Utils.Common.getTextLength(tname, 14) + 30;
            sw += w;
            t += "<li sw=" + sw + " style='width:" + w + "px' onclick='setCurThemeMapsType(" + tid + ",\"" + tname + "\")' id='thememaps_" + tid + "'><a><span>" + tname + "</span></a></li>";
            sw -= 5;
        }
        var ul = document.getElementById('ulThemeList');
        ul.innerHTML = t + ztNavhtml;
		 //阿腾增加ie6检测代码
        var isIE = !!window.ActiveXObject;
        var isIE6 = isIE && !window.XMLHttpRequest;
		if (isIE && isIE6) {
            ul.style.width = sw-12 + 'px';
        }
        else {
            
            ul.style.width = sw + 'px';
        }
        //ul.style.width = sw + 'px';

        var ulmenuW = 0;
        //处理父节点宽度
        var ulmenu = document.getElementById('ulThemeMenu');
        var ulmenulis = ulmenu.getElementsByTagName("li");
        for (var k = 0; k < ulmenulis.length; k++) {
            var text = ulmenulis[k].innerText;
            w = Utils.Common.getTextLength(text, 14) + 30;
            ulmenulis[k].style.width = w + "px";
            ulmenuW += w - 5;
        }

        //ul.style.width = sw + 'px';
        var themeList = document.getElementById('themeList');
        //阿腾增加ie6检测代码
        //var isIE = !!window.ActiveXObject;
        //var isIE6 = isIE && !window.XMLHttpRequest;
        if (isIE && isIE6) {
            themeList.style.width = sw + ulmenuW +37+85+80+ "px";
        }
        else {
            
            themeList.style.width = sw + ulmenuW+85+80 + "px";
        }
        //themeList.style.width = sw + ulmenuW + "px";
        window.setTimeout(function() {
            setCurThemeMapsType(curThemeType, curThemeName);
        }, 1000);
    });
}
function fnShowThemeMenu(key) {

    var m = $('thememenu_' + key + '_li');
    var t = $('thememenu_' + key);
    if (t&&m) {
        var p = getPos(m);
        t.style.left =p.x+4+"px";
        t.style.top = p.y+23+"px";
        t.style.display = t.style.display == 'block' ? 'none' : 'block';
    }

}
function setCurThemeMapsMenu(tid, key) {
    //debugger;
    if (!Number(tid))
        return false;
        
    var m = $('thememenu_' + key + '_li');
    if (m) {
        var themeList_items = document.getElementById('themeList_items');
        themeList_items.innerHTML = fnGetLoading();
        themeList_items.style.width = "100%";
        themeList_items.style.marginLeft = 0;
        
        //设置当前
        setCurThemeMapsMenuClass(m);
        
        var url = GlobalConfig.EDataCenterUrl + 'CommMap5.0/ThemeMaps.aspx?domain=' + GlobalConfig.Domain + '&l=' + GlobalConfig.Language + '&typeid=' + tid + '&req=2';
        ENetwork.DownloadScript(url, function() {
            if (typeof _ThemeMapList == 'undefined') { return false };
            var html = '';
            var len = _ThemeMapList.SubTypeList.length;
            for (i = 0; i < len; i++) {
                var Tid = _ThemeMapList.SubTypeList[i].BCT_ID;
                var Tname = _ThemeMapList.SubTypeList[i].BCT_TypeName;
                html += "<a href='javascript:LoadThemeMapList(" + Tid + ",\"" + Tname + "\")'>" + Tname + "</a>";
            }
            var li = $("thememaps_" + tid);
            var th = "";
            var themeName = li.getElementsByTagName('a')[0].innerHTML;
            if (themeName == "中博会专题") {
                //var tid = 0;
                var name = "省市简况";
                th = "<a href='http://" + GlobalConfig.Domain + "/ssjk.aspx?req=jxsjk' target='_blank'>" + name + "</a>";
            }
            else if (themeName == "绿博会专题") {
                //MoveTo2(-2390, 7522);
                var name = "绿博会简况";
                th = "<a href='http://" + GlobalConfig.Domain + "/lbh.aspx?req=g' target='_blank'>" + name + "</a>";
                //len += 1;
                //map.aspx?l=zh-chs&x=-2390&y=7522
                name = "场馆布局";
                th += "<a href='javascript:MoveTo2(-2390,7522);'>" + name + "</a>";
            }

            themeList_items.innerHTML = "<span style='color:#ffb600;'>" + themeName + ": </span>" + th + html;
            
            var num = fnGetTextLength(themeList_items.innerText);
            var tw = (num.zh + num.en) * 12 + len * 10;
            //计算宽度
            themeList_items.style.width = tw + "px";

            m = $('thememenu_' + key + '_li');
            var p = getPos(m);
            themeList_items.style.marginLeft = p.x + "px";

        });
    }
	
}

function setCurThemeMapsMenuClass(obj) {
    //设置菜但
    var ul = document.getElementById('ulThemeList');
    var items = ul.childNodes;
    for (k = items.length - 1; k > -1; k--) {
        items[k].className = '';    
    }

    ul = document.getElementById('ulThemeMenu');
    items = ul.childNodes;
    for (var k = items.length - 1; k > -1; k--) {
        if (items[k] == obj) {
            items[k].className = 'current';  
        }
        else {
            items[k].className = '';
        }
    }
}

function setCurThemeMapsType(Tid, Tname) {
    //debugger;
    var cid = "thememaps_" + Tid;
    var cobj=document.getElementById(cid);
    if (cobj) {
        if (cobj.className=='current')
            return false;
        curThemeName = Tname;
        //获取子项
        getThemeMapListByTypeId(Tid, cid);
    }
	document.getElementById("thememenu_jp_li").className="";
}

/*
function setZtMenu(name) {
    if (tname.indexOf('专题') > -1) {
        if (ztNavhtml === '') {
            tname = "会展专题";
            w = Utils.Common.getTextLength(tname, 14) + 30;
            sw += w;
            ztNavhtml = "<li name='nav_hzzt' sw=" + sw + " style='width:" + w + "px'><a><span>" + tname + "</span></a></li>";
        }

        //var _navMenuTemp = "<div id='{$id}' style='display:none;' class='TabMenu' onmouseover='{$event}' onmouseout='{$event}'>";</div>";
        
        <li onclick="fnOpenHuDongTab()"><a href="javascript:">开心互动</a></li>
        <li class='Hr'></li>
        <li onclick="fnOpenWeatherTab()"><a href="javascript:">天气预报</a></li>
        
        
        var _navMenuId = "nav_hzzt";
        var _navMenu = document.getElementById(_navMenuId);
        if (!_navMenu) {
            _navMenu = document.createElement("div");
            document.getElementById('Wrapper').appendChild(_navMenu);

            _navMenu.setAttribute("id", _navMenuId);
            _navMenu.style.display = "none";
            _navMenu.setAttribute("class", TabMenu);
            _navMenu.onmouseover = function() { };
            _navMenu.onmouseout = function() { };
            _navMenu.innerHTML = "<div class='InComPlaceNav'><div class='InComPlaceUp'></div><div class='InComPlaceDn'><ul id='" + _navMenuId + "ul'>{$lis}</ul></div></div>";
        }
        var _navMenuul = document.getElementById(_navMenuId + "ul");
        
        continue;
    }
}
*/
//设置当前项
function getCurTheme(cid) {
    //设置菜但
    var ul = document.getElementById('ulThemeList');
    var items = ul.childNodes;
    var curIndex = 0;
    for (k = items.length-1; k>-1; k--) {

        var index = k;
        if (items[k].getAttribute("id") == cid) {
            items[k].className = 'current';
            curIndex = k; //items.length-k;
        }
        else {
            items[k].className = '';
        }
    }

    ul = document.getElementById('ulThemeMenu');
    items = ul.childNodes;
    for (var k = items.length - 1; k > -1; k--) {
        items[k].className = '';
    }
    
    return curIndex;
}

function setThemeListPos(index) {

    var themeList_items = document.getElementById('themeList_items');
    var pNode = themeList_items.parentNode;

    var ltw = _pageWidth - 2 * pNode.offsetLeft;
    var tw = themeList_items.clientWidth;
    var ml = 0;
    if (tw > ltw) {
        themeList_items.style.width = ltw + "px";
    }
    else {
        var ul = document.getElementById('ulThemeList');
        var items = ul.childNodes;

        var k = items.length - 1 - index;
        
        var direct = 'center';
        //设置前两个个和最后两个位置
        if (k < 2) {
            direct = "left";
        }
        else if (k >= items.length - 2) {
            direct = "right";
        }
//        else if (k == 2) {
//            direct = "right";
//            k = items.length - 1;
//        }
        var themeobj = items[k];
        //var pThemeobj = getPos(themeobj);
        var selfWidth = 0;
        var ow = Number(themeobj.getAttribute('sw')) + Number(getPos(ul).x) - pNode.offsetLeft;
        if (direct == "left") {
            ml = ow - Number(themeobj.clientWidth) - 5 + 'px';
        }
        else if (direct == "right") {
            selfWidth =Utils.HTML.getValueOfNoPx(themeList_items.style.width);
            ml = ow - selfWidth + 5 + 'px';
        }
        //中间
        else if (direct == "center") {
        selfWidth = Utils.HTML.getValueOfNoPx(themeList_items.style.width);
            ml = ow - Number(themeobj.clientWidth) / 2 - selfWidth / 2 + 'px';
        }
    }
    themeList_items.style.marginLeft = ml;
}
//显示某个特定主题分类
function getThemeMapListByTypeId(tid, cid) {
    if (tid == '')
        return false;

    var themeList_items=document.getElementById('themeList_items');
    themeList_items.innerHTML = fnGetLoading();
    themeList_items.style.width = "100%";
    themeList_items.style.marginLeft = 0;
    //设置当前项
    var curIndex = getCurTheme(cid);
    var url = GlobalConfig.EDataCenterUrl + 'CommMap5.0/ThemeMaps.aspx?domain=' + GlobalConfig.Domain + '&l=' + GlobalConfig.Language + '&typeid=' + tid + '&req=2';
    ENetwork.DownloadScript(url, function() {
        if (typeof _ThemeMapList == 'undefined') { return false };
        var html = '';
        var len = _ThemeMapList.SubTypeList.length;
        for (i = 0; i < len; i++) {
            var Tid = _ThemeMapList.SubTypeList[i].BCT_ID;
            var Tname = _ThemeMapList.SubTypeList[i].BCT_TypeName;
            html += "<a href='javascript:LoadThemeMapList(" + Tid + ",\"" + Tname + "\")'>" + Tname + "</a>";
        }

        themeList_items.innerHTML = html;
        
        var num = fnGetTextLength(themeList_items.innerText);
        var tw = (num.zh + num.en) * 12 + len * 10;
        //计算宽度
        themeList_items.style.width = tw + "px";
        //设置子菜单位置
        setThemeListPos(curIndex);
		window.setTimeout(function() {
            //阿腾加载返回房产的参数
	//阿腾加改变选择项的样式
	if(document.getElementById("ztfsearchtype").value!="")
	{
	document.getElementById("thememenu_fc_li").className = "current";
    document.getElementById("thememenu_hz_li").className = "";
    document.getElementById("thememenu_jp_li").className = ""; 
    var mymenuul=document.getElementById("ulThemeList");
    for (var i = 0; i < mymenuul.childNodes.length; i++) {
        mymenuul.childNodes[i].className = "";
    }
	document.getElementById("themeList_items").innerHTML = "";
	     var fangchangstr=" <a onclick=\"houseClick('hire')\"  style='cursor:hand'>租房</a>";             
               
                    fangchangstr+="<a onclick=\"houseClick('sale')\" style='cursor:hand'>二手房</a>";
                    fangchangstr+="<a onclick=\"houseClick('list_mini')\"  style='cursor:hand'>楼盘</a>";
                   fangchangstr+="<a onclick=\"houseClick('broker')\" style='cursor:hand'>经纪人</a>";
					document.getElementById("themeList_items").innerHTML =fangchangstr;
					document.getElementById("themeList_items").style.width="150px";
					
					document.getElementById("themeList_items").style.marginLeft=document.getElementById("thememenu_fc_li").offsetLeft+300-25+"px";
					document.getElementById("ztfsearchtype").value="";
					}
        },1000);
    });
	
    
    /*
    //打折促销特殊处理
    if (curThemeName == "打折促销") {
        var requestUrl="map/AjaxHandle.ashx?req=getAllGoodClass_1";
        downloadUrl(requestUrl, function(request)
        {
            var json = xmlHttpRequestJson(request);
            if (json == null)
                return false;
            var goodList = json.GoodClasses;

            var len = goodList.length;
            var html = "";
            for (i = 0; i < len; i++) {
                var Tid = goodList[i].CId;
                var Tname = goodList[i].CName;
                html += '<a href="javascript:dzcxLoadThemeMapListByTypeId(' + Tid + ',\'' + Tname + '\')">' + Tname + '</a>';
            }
            themeList_items.innerHTML = html;
            var num = fnGetTextLength(themeList_items.innerText);
            //计算宽度
            themeList_items.style.width = (num.zh + num.en) * 12 + len * 10 + "px";
            //设置子菜单位置
            setThemeListPos(curIndex);
        });
    }
    else {
        
    }  
    */
	
}
function LoadThemeMapList(Tid, Tname) {
    //中博会专题
    var f = '';
    var b = false;
    //add by hbc
    var mainView = document.getElementById("tdMain");
    var mainViewHouse = document.getElementById("tdHouse");
    mainView.style.display = "block";
    mainViewHouse.style.display = "none";
//add by hbc end
//add by 阿腾 隐藏竞拍和房产楼盘
hiddenztfpop();
    switch (Tname) {
        case '推荐宾馆酒店': f = "2"; break;
        case '旅游景点': f = "0"; break;
        case '商贸广场': f = "1"; break;
        case '交通':
            {
                //fnSearchChange();
                fnSearchChange2('liBusSearch');
            } break;
        case '天气':
            {
                fnOpenWeatherTab();
                b = true;
            } break;
        case '省市简况':
            {
                b = true;
            } break;
    }
    if (b) {
        return;
    }
    if (f != "") {
        //fnShowNav(f);
    }
    fnLoadThemeMapListByTypeId(Tid, Tname);
	
}

//显示某个特定主题分类
function fnLoadThemeMapListByTypeId(Tid, Tname, sKey) {
    if (typeof (fnOpenTab) == "function") {
        fnOpenTab();
		var Digital = new Date();
        Digital = Digital + 40000;
        var url = GlobalConfig.NewSkinPath + 'Fundation/ThemeMap.html?classid=' + Tid+'&k='+Digital;
        if (sKey != '' && sKey != null) {
            url = url + '&key=' + escape(sKey);
        }
        //debugger;
        tab = new TabControl.Tab(document, 'themeMap', Tname, url, true, true, 80);
        fnAddTab(tab);
    }
    else {
        window.location.href = "map.aspx";
    }
}

//打开天气预报选项卡
function fnOpenWeatherTab() {
    var title = '天气预报';
    var url = "http://map.nc0791.cn/weather.aspx";
    var tab = new TabControl.Tab(document, 'weather', title, url, true, true, 80);
    fnAddTab(tab);
}
function fnOpenHuDongTab() {
    var title = '开心互动';
    var url = GlobalConfig.NewSkinPath + "page/HuDong.aspx";
    var tab = new TabControl.Tab(document, 'hudong', title, url, true, true, 80);
    fnAddTab(tab);
}
/*
//打折促销根据子类别地图查询
function dzcxLoadThemeMapListByTypeId(Tid, Tname, sKey) {
    fnOpenTab();
    var url = GlobalConfig.NewSkinPath + 'Fundation/DzcxMap.htm?classid=' + Tid; //+ '&key=' + escape(Tname);
    if (sKey) {
        url = url + '&key=' + escape(sKey);
    }
    tab = new TabControl.Tab(document, 'DzcxMap', Tname, url, true, true, 80);
    fnAddTab(tab);
}
//打开打折促销新闻页
function fnOpenDzcxNewsTab() {
var title = '打折快讯';
var url = GlobalConfig.NewSkinPath + "page/dzcxNews.aspx";
var tab = new TabControl.Tab(document, 'dzcxNews', title, url, true, true, 80);
fnAddTab(tab);
}

//打折促销增加图标
function dzcxAppendIcon(data) {
for (var k = 0; k < data.length; k++) {
var x = data[k].x;
var y = data[k].y;
if (Utils.Validator.isNum(x) && Utils.Validator.isNum(y)) {
var title = data[k].chrgood;
var img = '/Map/Images/dzcxIcon44.png';
var oimg = '/Map/Images/dzcxIcon_over44.png';
var gid = data[k].goodid;
var sFn = 'if(parent.fnShowDzcxPop){parent.fnShowDzcxPop(' + gid + ',' + x + ',' + y + ');}';
var w = 41;
var h = 33;
var ew = 13;
var eh = 27;
var isAppendEye = false;
fnAppendIcon(title, x, y, k + 1, img, oimg, sFn, w, h, ew, eh, isAppendEye);
}
}
}
*/
function fnOpenHomeTab() {
    var title = '首页';
    var url = GlobalConfig.NewSkinPath + "page/home.aspx";
    var tab = new TabControl.Tab(document, 'home', title, url, true, true, 80);
    fnAddTab(tab);
}

//地图设置菜单显示
function fnShowTableSetup() {
    var t = $('divTableSetup');
    if (t) {
        t.style.display = t.style.display == 'block' ? 'none' : 'block';
    }
}
function showDituNews() {
    document.getElementById('dituNews').style.display = 'block';
}
//地图排队标点
function appendUserIcon(index, usernum, username) {
    //debugger;
    var xys = getUserCoord(index * 1 - 1);
    var x = xys.split(',')[0];
    var y = xys.split(',')[1];
    
    var img = '/Map/Images/hdIcon44.png';
    //var oimg = '/Map/Images/hdIcon_over44.png';
    //var sFn = 'if(parent.fnShowHuDongPop){parent.fnShowHuDongPop("' + id + '",' + x + ',' + y + ');}';
    x = parseInt(x);
    y = parseInt(y);
    
    var w = 41;
    var h = 33;
    var ew = 13;
    var eh = 27;
    var isAppendEye = false;
    fnAppendIcon(username, x, y, index, img, img, null, w, h, ew, eh, isAppendEye);
}
function getUserCoord(index) {
    //_UserCoordList[index * 1];
    var len = _UserCoordList.length;
    var bl = 100;
    if (index > len - 1) {
        var xys1 = _UserCoordList[len - 1];
        var xys2 = _UserCoordList[len - 2];
        var x1 = xys1.split(',')[0] * 1;
        var x2 = xys2.split(',')[0] * 1;
        if (x1 < x2) {
            bl = -100;
        }
        _UserCoordList[index] = x1 + bl + "," + xys1.split(',')[1];
    }
    return _UserCoordList[index];
}
function frmImage(f) {
    var width = 900;
    var height = 580;
    var id = "msgbox_";
    //var url = "map/lbh/" + f + "3.html";
    var url = "lbh.aspx?req=m&action=" + f;
    var title = "南昌国际展览中心---" + (f == '0' ? "主" : f.toUpperCase()) + "馆";
    art.dialog.open(
            url,
            {
                drag: false, lock: true, width: width, height: height, title: title, id: id, fixed: true
            }
        );
        }
        function showjptheme(j) {
            var mainView = document.getElementById("tdMain");
            var mainViewHouse = document.getElementById("tdHouse");
            mainView.style.display = "block";
            mainViewHouse.style.display = "none";
            var title = '';
            var url = "";
            var tab = "";
            if (j == 1) {
                title = "当前竟拍";
                url = "/map/map/jingpai.aspx";
                var tab = new TabControl.Tab(document, 'weather', title, url, true, true, 80);
                fnAddTab(tab);
            }
            else if (j == 2) {
            title = "最近成交";
            url = "/map/map/jingpai_suc.aspx";
            var tab = new TabControl.Tab(document, 'weather', title, url, true, true, 80);
            fnAddTab(tab);
        }
        else if (j == 3) {
            if (ztfchecklogin()) {
                title = "我的参与";
                url = "/map/map/jingpai_my.aspx";
                var tab = new TabControl.Tab(document, 'weather', title, url, true, true, 80);
                fnAddTab(tab);
            }
            else {
                alert("请先登录!");
                return;
            }
        }
        else if (j == 4) {
        if (ztfchecklogin()) {
                title = "我的订单";
                url = "/map/map/jingpai_mysuc.aspx";
                var tab = new TabControl.Tab(document, 'weather', title, url, true, true, 80);
                fnAddTab(tab);
            }
        else {
            alert("请先登录!");
            return;
        }
    }
    }
    function ztfchecklogin() { 
    
            var isCookieExist;
            //检查cookie是否存在
            isCookieExist = document.cookie.length;
            if (!isCookieExist) {
                return false;
            }
            else {
                //取出cookie值
                var cookieContent = document.cookie;

                //取出cookie状态
                var checkStatus = "yuwinduser=";

                //查找是否存在字符串visited=
                var startIndex = cookieContent.indexOf(checkStatus);
                if (startIndex != -1) {
                    //把位置锁定到"="的后面
                    startIndex += checkStatus.length;

                    //从'='后开始查找符号","
                    var endIndex = cookieContent.indexOf(",", startIndex);
                    if (endIndex == -1) {
                        endIndex = cookieContent.length;
                    }
                    //取出visited=后的字串
                    var result = unescape(cookieContent.substring(startIndex, endIndex));
                    if (result != "") {
                        return true;
                    }
                    else {
                        return false;
                    }
                }

            }
    }

