﻿var ParentID=40;
var GrandParentID=40;

window.onload = function()
{
    DeleteTextValue();
    InitScreen();
    setTimeout("InitCatalog()",500);
    LoginMap();
}

//======去掉文本框中的文字
function DeleteTextValue()
{
    var text = document.getElementById("txt");
    
    text.onclick=function()
        {
            
            if(text.value == '关键字')
            {
                text.value='';
            }
        }
}

//==== 界面调整
function InitScreen()
{
    
    var strBV=GetBrowserVersion();//获取浏览器版本
    
    document.getElementById("container").style.width = parseInt(screen.width);

    if(strBV=="IE6")
    {
        //document.getElementById("main_left").style.height=parseInt(screen.height)-317;
        document.getElementById("main_left").style.height=parseInt(screen.height)-305;
    }
    else if(strBV=="IE7")
    {
        document.getElementById("main_left").style.height=parseInt(screen.height)-300;
        
    }
    else if(strBV=="IE8")
    {
         
         document.getElementById("menu").style.position = "relative";
         document.getElementById("menu").style.top = (-16)+"px";
         document.getElementById("menu_buttom").style.position = "relative";
         document.getElementById("menu_buttom").style.top = (-16)+"px";
         document.getElementById("main_left").style.position = "relative";
         document.getElementById("main_left").style.top = (-16) + "px";
         document.getElementById("main_left_content").style.position = "relative";
         document.getElementById("main_left_content").style.left = "6px"
         document.getElementById("main_left").style.height=parseInt(screen.height)-299;
    }
    else
    {
        document.getElementById("menu").style.position = "relative";
         document.getElementById("menu").style.top = (-16)+"px";
         document.getElementById("menu_buttom").style.position = "relative";
         document.getElementById("menu_buttom").style.top = (-16)+"px";
         document.getElementById("main_left").style.position = "relative";
         document.getElementById("main_left").style.top = (-16) + "px";
         document.getElementById("main_left_content").style.position = "relative";
         document.getElementById("main_left_content").style.left = "6px"
         document.getElementById("main_left").style.height=parseInt(screen.height)-298;
    }
    document.getElementById("main_left_content").style.height=parseInt(document.getElementById("main_left").style.height)-62;
    document.getElementById("main_left_two").style.height=parseInt(document.getElementById("main_left_content").style.height)+30;
    if(strBV=="IE6")
    {
        document.getElementById("myTree").style.height=parseInt(document.getElementById("main_left_content").style.height)-23;
        document.getElementById("main_right").style.width = parseInt(screen.width)-222;
        document.getElementById("main_right").style.height=parseInt(document.getElementById("main_left").style.height)-5;
        document.getElementById("main_right_content").style.height= parseInt(document.getElementById("main_right").style.height) - 1;
        document.getElementById("main_right_content").style.width=parseInt(document.getElementById("main_right").style.width)-8;
        document.getElementById("bottom").style.top =parseInt(document.getElementById("menu").style.height + document.getElementById("menu_buttom").style.height + document.getElementById("main_left").style.height)+130;
        document.getElementById("divReturn").style.bottom=document.getElementById("bottom").style.bottom + document.getElementById("bottom").style.height + 4;

    }
    else if(strBV=="IE7")
    {
        document.getElementById("toolbarTop").style.top = 17 + "px";
        document.getElementById("toolbar").style.top = 29 +"px";
        document.getElementById("myTree").style.height=parseInt(document.getElementById("main_left_content").style.height) - 76;
        document.getElementById("main_right").style.top = 130 +"px";
        document.getElementById("main_right").style.width = parseInt(screen.width)-222;
        document.getElementById("main_right").style.height=parseInt(document.getElementById("main_left").style.height) - 30;
        document.getElementById("main_right_content").style.height= parseInt(document.getElementById("main_right").style.height) - 2;
        document.getElementById("main_right_content").style.width=parseInt(document.getElementById("main_right").style.width) - 8;
        document.getElementById("bottom").style.top =parseInt(document.getElementById("menu").style.height + document.getElementById("menu_buttom").style.height + document.getElementById("main_left").style.height)+101;
        document.getElementById("divReturn").style.bottom=document.getElementById("bottom").style.bottom + document.getElementById("bottom").style.height + 3;

    } 
    else if(strBV=="IE8")
    {
        document.getElementById("divReturn").style.bottom = 28+"px";
        document.getElementById("divReturn").style.left = "2px";
        document.getElementById("toolbarTop").style.top = 17 + "px";
        document.getElementById("toolbar").style.top = 29 +"px";
        document.getElementById("myTree").style.height=parseInt(document.getElementById("main_left_content").style.height) - 62;
        document.getElementById("main_right").style.top = 130 +"px";
        document.getElementById("main_right").style.width = parseInt(screen.width)-222;
        document.getElementById("main_right").style.height=parseInt(document.getElementById("main_left").style.height) - 30;
        document.getElementById("main_right_content").style.height= parseInt(document.getElementById("main_right").style.height) - 2;
        document.getElementById("main_right_content").style.width=parseInt(document.getElementById("main_right").style.width) - 8;
        document.getElementById("bottom").style.top =parseInt(document.getElementById("menu").style.height + document.getElementById("menu_buttom").style.height + document.getElementById("main_left").style.height)+101;

    }
    else
    {
        if(document.getElementById("toolbarTop")!=null)
		document.getElementById("toolbarTop").style.top = 17 + "px";
        if(document.getElementById("toolbar")!=null)
		document.getElementById("toolbar").style.top = 29 +"px";
        document.getElementById("myTree").style.height=parseInt(document.getElementById("main_left_content").style.height) - 62;
        document.getElementById("main_right").style.top = 130 +"px";
        document.getElementById("main_right").style.width = parseInt(screen.width)-222;
        document.getElementById("main_right").style.height=parseInt(document.getElementById("main_left").style.height) - 30;
        document.getElementById("main_right_content").style.height= parseInt(document.getElementById("main_right").style.height) - 2;
        document.getElementById("main_right_content").style.width=parseInt(document.getElementById("main_right").style.width) - 8;
        document.getElementById("bottom").style.top =parseInt(document.getElementById("menu").style.height + document.getElementById("menu_buttom").style.height + document.getElementById("main_left").style.height)+101;
    
    }       
    document.getElementById("bottom").style.width=parseInt(screen.width) - 2;
    document.getElementById("bottom_txt").style.width=parseInt(screen.width) - 2;
    document.getElementById("result_content").style.width=parseInt(document.getElementById("main_right").style.width)-12;
    if(document.getElementById("result_head")!=null)
	    document.getElementById("result_head").style.width=parseInt(document.getElementById("main_right").style.width)-10;
    if(screen.width>1024)
    {
        //document.getElementById("result_content").style.width=document.getElementById("main_right").style.width;//795;
        document.getElementById("topright").style.width=screen.width-1024;
        //for(var i=1;i<=6;i++)
            document.getElementById("lispace").style.width=screen.width-488-192-230;
        if(strBV == "IE6")
        {
             document.getElementById("toolbarBottom").style.top = 479 + "px";
        }   
        else if(strBV == "IE7")
             document.getElementById("toolbarBottom").style.top = 455 + "px";
        else if(strBV=="IE8"){
             document.getElementById("toolbarBottom").style.top = 465 + "px";
        }
       
    }
    else
    {
        document.getElementById("result_content").style.width=parseInt(document.getElementById("main_right").style.width)-42;
        document.getElementById("lispace").style.width=112;
        var arrImgButtons=document.getElementsByTagName("img");
        for(var i=0;i<arrImgButtons.length;i++)
        {
            if(arrImgButtons[i].id.substring(0,4)=="imgM")
            {
                arrImgButtons[i].style.height=31;
                arrImgButtons[i].style.width=29;
            }
        }
        if(strBV=="IE6")
            document.getElementById("toolbarBottom").style.top=407;
        else if(strBV == "IE7")
             document.getElementById("toolbarBottom").style.top = 385 + "px";
        else if(strBV=="IE8"){
             document.getElementById("toolbarBottom").style.top = 394 + "px";
        }
        else
        {
            document.getElementById("toolbarBottom").style.top = 394 + "px";
        }
            
    }
}


function LoginMap()
{
	var taken = new LogToken();
    taken.setUserName("admin");
    taken.setPassword("123456");
    taken.login(InitMap); 
}

function InitMap(str)
{
    //var oStyle = new Style(747,448,1,"#4b86c0",1);
    var oMainContent=document.getElementById("main_right_content");
    var oStyle = new Style(parseInt(document.getElementById("main_right_content").style.width),parseInt(document.getElementById("main_right_content").style.height),1,"#4b86c0",1);
    oMap = new MapControl();
    oMap.Style = oStyle;
    oMap.MapDiv = document.getElementById("mapDiv");
    //----------------指定结果DIV
    oMap.ResultListDiv=document.getElementById("result_content");
    
    if(parseInt(screen.width)<=1024)
        oMap.ZoomLevel=1;
    else
        oMap.ZoomLevel =2;
    oMap.MapName = "CW_ZWMAP_10000";
    oMap.InitMap(getControl);
}

function getControl()
{
    oMap.GetSuperMapControl().AttachEvent("onchangeview",ChangeIndex);
}

function ChangeIndex()
{
    var arrID = document.getElementsByTagName("div");
    for(var i=0;i<arrID.length; i++)
    {
        var objMarker = arrID.item(i);
        if(objMarker.id != "" && objMarker.id.indexOf("myInfoBox")>-1)
        {
            
           objMarker.style.zIndex = "2000";
        }
    }
  
}
//=============结果的隐藏和现实==========

function _xs(){ 

    sText = "<img id='imgJieGuo' alt='' id='imgResultTitle' border='0' src='images/jieguo.gif' usemap='#hotarea' onclick1='_yc()'/>";
    sText += "<map name='hotarea'><area shape='rect' coords='88,2,102,20' href='javascript:{_yc();}' title='最小化'><area shape='rect' coords='110,2,125,20' href='javascript:{_zdh();}' title='最大化'></map>";

    var result = document.getElementById("result");
    var result_content = document.getElementById("result_content");
    
    result_content.style.height = 152;
    result.style.bottom = 154 ;
    result.style.height=23;
    result_content.style.display = "block"; 
    document.getElementById("result_head").innerHTML="";  
    document.getElementById("result_head").innerHTML=sText;
    if(screen.width>1024)
        document.getElementById("imgJieGuo").style.right=-2;
    else
        document.getElementById("imgJieGuo").style.right=28;
}
function _yc(){
        /*if(document.getElementById("imgResultTitle").src="images/zhankai.gif")
        {
            _zdh();
            return;
        }*/
        sText = "<img alt='' id='imgResultTitle' src0='images/kg.gif' src='images/zhankai.gif' onclick='_xs()'/>"
        var result = document.getElementById("result");
        var result_content = document.getElementById("result_content");
        result.style.bottom = 0;
        result_content.style.display = "none";
        document.getElementById("result_head").innerHTML="";
        document.getElementById("result_head").innerHTML=sText;
        //document.getElementById("imgResultTitle").src="images/zhankai.gif";
}

function _zdh(){
    sText = "<img alt='' src0='images/kg.gif' src='images/guanb.gif' onclick='_xs()'/>"
    var result = document.getElementById("result");
    result.style.height=document.getElementById("main_right").style.height;
    result.style.bottom=1;
    var result_content = document.getElementById("result_content");
    //result.style.bottom = 0;
    //document.getElementById("result_content").style.display = "none";
    document.getElementById("result_content").style.height=parseInt(document.getElementById("main_right").style.height)-24;
    document.getElementById("result_head").innerHTML="";
    document.getElementById("result_head").innerHTML=sText;
}

//==========地名查询========================
function AddressQuery()
{   
    var oQueryParams = new Object();
	var strkeyword=document.getElementById("txt").value;
    oQueryParams.QueryExp ="525@AddressName like '%"+ strkeyword +"%'";      
    oQueryParams.QueryType = "MapList";//显示方式
    //oQueryParams.PageSize = 15;//每页记录数
    //oQueryParams.CurrentPageIndex = 1;//当前页码
    //oMap.QueryParams = oQueryParams;
    oMap.Query(oQueryParams);
}

//===============目录的树形结构============

function getTree(name)
{
    switch(name)
    {
        case "BMFW":
          document.getElementById("ml").src="images/left_bmfw.gif";
          break;
        case "ZWGK":
          document.getElementById("ml").src="images/left_zwgk.gif";
          break;
        case "ZNCX":
          document.getElementById("ml").src="images/left_zncx.gif";
          break;
        default:
          document.getElementById("ml").src="images/left_fscw.gif";
          break;
            
    }
    document.getElementById("myTree").innerHTML="";
    tree=new dhtmlXTreeObject("myTree","100%","100%",0);
	tree.setImagePath("images/img/CheckTree/img/");
    //tree.enableCheckBoxes(true);
    tree.enableHighlighting(1);
	//tree.enableThreeStateCheckboxes(true);
	tree.setXMLAutoLoading("Ajax/AjaxWebModule.aspx");
    tree.loadXML("Ajax/AjaxWebModule.aspx?Action=" + name );
    tree.setOnClickHandler(oClickNode);
    /*var httpRequest=null;
    httpRequest=CreateHttpRequest();
    httpRequest.onreadystatechange=function()
        {
            if(httpRequest.readyState==4&&httpRequest.status==200)
            {
                buildCatalog(httpRequest.responseXML);
            }
        }
    httpRequest.open("GET","Ajax/AjaxWebModule.aspx?Action=" + name,true);
    httpRequest.send(null);*/
}

function CreateHttpRequest()
{
    var oH=null;
    if(window.ActiveXObject)
        oH=new ActiveXObject("MicroSoft.XMLHTTP");
    else if(window.XMLHttpRequest)
        oH=new XMLHttpRequest();
    return oH;
}
function switchContent(strID)
{
    var divContent=document.getElementById("div_"+strID);
    if(divContent==null||typeof(divContent)=="undefined")
        return;
    if(divContent.style.display=="none")
    {
        divContent.style.display="block";
        document.getElementById("img_"+strID).src="images/spd.gif";
    }
    else
    {
        divContent.style.display="none";
        document.getElementById("img_"+strID).src="images/epd.gif";
    }
}

function GetContentLength(strVal)
{
    var l=0;
    var blInBracket=false;
    for(var i=0;i<strVal.length;i++)
    {
        var c=strVal.substr(i,1);
        if(c=="<")             //遇到左尖括号就把标记记为true
        {
            blInBracket=true;
        }
        else if(c==">")             //如果遇到右尖括号就把标记改为false
        {
            blInBracket=false;
        }
        else if(blInBracket==false)//&&strVal.substr(i,1)!="<")    //不在尖括号里就记为1个长度
        {
            l++;
        }
        /*else if(strVal.substring(i,1)!=">"&&blInBracket)//如果是在尖括号中就跳过
        {
            continue;
        }*/
    }//alert(l);
    return l;
}
function oClickNode()
{

    var sMdlAction = tree.getUserData(tree.getSelectedItemId(),"mdlAction");
    var sMdlHref = tree.getUserData(tree.getSelectedItemId(),"mdlHref");
    if((sMdlAction!=null||sMdlAction!="") && (sMdlHref == null||sMdlHref==""))
    {
        //_xs();
        eval(sMdlAction);
    }
    else if((sMdlAction!=null||sMdlAction!="") && (sMdlHref !=null||sMdlHref!=""))
    {
        //_xs();
        window.open(sMdlHref); eval(sMdlAction);
    }
    else if((sMdlAction==null||sMdlAction=="") && (sMdlHref !=null || sMdlHref !=""))
    {
        
        window.open(sMdlAction);
    }
    else
    {
        
    }
}                              
//===========切换Tab
function switchTab(n){
    var p;
    var catalogID;
    switch(n){
        case 1:
            p = "BMFW";
            catalogID = 40;
            document.getElementById("ml").src="images/left_bmfw.gif";
            break;
        case 2:
            p = "ZWGK";
            catalogID = 38;
            document.getElementById("ml").src="images/left_zwgk.gif";
            break;
        case 3:
            p = "ZSYZ";
            catalogID=39;
            document.getElementById("ml").src="images/left_zsyz.gif";
            break;
        case 4:
            p = "FSCW";
            catalogID=41;
            document.getElementById("ml").src="images/left_fscw.gif";
            break;
	case 5:
	    p= "ZXBZ";
		var w=window.open("help.htm");
		break;
        default:
            p = "BMFW";
            catalogID = 40;
            document.getElementById("ml").src="images/left_bmfw.gif";
    }
    var image = "cd" + n + "_1.gif";
    for(var i = 1; i <= 4; i++ )
    {
        if(i == n)
        {
            document.getElementById("li" + i).style.backgroundImage = 'url(images/'+image+')';
            InitCatalog(catalogID);
            switchMap(p);
        }
        else
        {
            var image2 = "cd"+i+".gif";
            document.getElementById("li" + i).style.backgroundImage = 'url(images/'+image2+')';
        }
    }
    
}

function zbcxTab(n)
{
    var myTree = document.getElementById("myTree");
    if(n == "zbcx")
    {   
        myTree.innerHTML = "";
        myTree.innerHTML = document.getElementById("zbcx").innerHTML ;
         document.getElementById("divReturn").style.display="inline";
        
     }
     else
     {
       myTree.innerHTML = "";
       myTree.innerHTML = document.getElementById("zncx").innerHTML ;
         document.getElementById("divReturn").style.display="inline";
     }   
}
function focusTab(n)
{
    var p;
    switch(n){
        case 1:p = "BMFW";break;
        case 2:p = "ZWGK";break;
        case 3:p = "ZSYZ";break;
        default:p = "FSCW";  
    }
    var image = "cd" + n + "_1.gif";
    for(var i = 1; i <= 4; i++ ){
        if(i == n){
            document.getElementById("li" + i).style.backgroundImage = 'url(images/'+image+')';
        }
        else{
            var image2 = "cd"+i+".gif";
            document.getElementById("li" + i).style.backgroundImage = 'url(images/'+image2+')';
        }
    }
    
}
function losefocusTab(n)
{
}
function switchMap(name)
{
    //alert(oMap.GetSuperMapControl().mapName);
    if(name=="FSCW")
        oMap.SwitchMap("CW_IMAGEMAP_LongTanHuGongYuan");
    else if(oMap.MapName!="CW_ZWMAP_10000")
        oMap.SwitchMap("CW_ZWMAP_10000");
}

function buildCatalog(oDoc)
{
   // alert(oDoc.xml);
    document.getElementById("myTree").innerHTML="";
    var oTContainer=document.createElement("table");
    var oTCBody=document.createElement("tbody");
    oTContainer.appendChild(oTCBody);
    var oTCRow=oTCBody.insertRow(0); 
    var oTCCell=oTCBody.rows[0].insertCell(0);
    oTContainer.style.width="100%";
    oTCCell.style.textAlign="center";
    
    var oTable=document.createElement("table");
    oTable.setAttribute("id","tblCatalog");
    
    oTable.style.align="center";
    oTable.className = "tableCss";
    //oTable.cellpadding="0";
    //oTable.style.width="80%";
    //oTable.style.color="black";
    //oTable.style.fontSize="14px";
    //oTable.style.margin = "auto";
    oTable.cellpadding=2;
    oTable.cellspacing=2;
    var oTBody=document.createElement("tbody");
    oTable.appendChild(oTBody);
    var arrItems=oDoc.selectNodes("/items/item");
    
    for(var i=0;i<arrItems.length;i++)
    {
        var oItem=arrItems.item(i);
      //var oRow=document.createElement("tr");
      //var oCell=document.createElement("td");
        var oRow = oTBody.insertRow(i);
	    var	oCell =oTBody.rows[i].insertCell(0);
	    
        var oHref=document.createElement("a");
        var oImg =document.createElement("img");
        var strImg = false;
        
        var strAction=oItem.selectSingleNode("userdata[@name='mdlAction']").text;  
          
            strAction = "oMap.ClearHighLight();" + strAction;
            
        if(parseInt(oItem.getAttribute("ChildrenNum"))>0){
            strImg = true;
            strAction+="InitCatalog(" + oItem.getAttribute("id") + ");";
        }
        strAction="oMap.PanTo();"+strAction;
        strAction +="LegendShowAndHidden('"+oItem.getAttribute("text")+"');";/*商业发展版块的图例显示与隐藏*/
   
        oHref.href="javascript:{" + strAction + "}";
        oHref.innerText=oItem.getAttribute("text");
        oImg.setAttribute("src" , "images/gif-0162.gif");
        oImg.style.position="absolute";
        oImg.style.left = 35;
        oImg.style.paddingTop = 3;
        if(strImg==true)
            oCell.appendChild(oImg); 
        oCell.appendChild(oHref);
        oCell.style.backgroundImage="url(images/newpic/m_bg2.gif)";
        oCell.style.backgroundRepeat="repeat";
        oCell.style.height="23px";
        
        oCell.onmouseover=function()
            {
                this.style.backgroundImage="url(images/newpic/m_bg.gif)";
                this.style.cursor="hand";
            }
        oCell.onmouseout=function()
            {
                this.style.backgroundImage="url(images/newpic/m_bg2.gif)";
                this.style.cursor="";
            }
        //oRow.appendChild(oCell);
        //oTBody.appendChild(oRow);
   
    }
    
    oTCCell.appendChild(oTable);
    //oTCRow.appendChild(oTCCell);
    //oTCBody.appendChild(oTCRow);
    
    document.getElementById("myTree").appendChild(oTContainer);
}

var arrID = new Array();
var ReturnButton = false;
function InitCatalog(id)
{
    if(ReturnButton==false)
        arrID.push(id);
    var httpRequest=null;
    httpRequest=CreateHttpRequest();
    httpRequest.onreadystatechange=function()
        {
            if(httpRequest.readyState==4&&httpRequest.status==200)
            {
              
                buildCatalog(httpRequest.responseXML);
                
            }
        }
    if(id==null||typeof(id)=="undefined")
        id=40;
    httpRequest.open("GET","Ajax/AjaxWebModule.aspx?Action="+id,true);
    httpRequest.send(null);
    if(!(id>=38&&id<=41))
        document.getElementById("divReturn").style.display="inline";
    else
        document.getElementById("divReturn").style.display="none";
    GrandParentID=ParentID;
    ParentID=id;
    ReturnButton=false;
}

function ReturnOnPage()
{   
    ReturnButton=true;
    arrID.pop();
    InitCatalog(arrID[arrID.length-1]);    
}

/*图例隐藏和显示*/
function LegendShowAndHidden(name)
{
    var LegendDiv = document.getElementById("LegendDiv");
    if(name == "商业发展版块分析")
    {
        
        LegendDiv.style.display = "block";
    }
    else
    {
        LegendDiv.style.display = "none";
    }
}

//王字型磁场简介窗口的打开
function WZXCCHIntroductionOpen()
{
    var toTop = parseInt(screen.height/2)-(300/2)-100;
	var toLeft = parseInt(screen.height/2)-(400/2)-80;
    window.open('PropertyPages/WZXCCHIntroduction.htm','_blank','width=400,height=500,left='+toLeft+',top='+toTop+',status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes') ;
}


