﻿window.onresize=function(){
    var h=fnGetWindowHeight(),w=fnGetWindowWidth()-22;
    _oMap.MapHeight(h-156);
    _oMap.MapWidth(w);
    $('EdushiObj').style.top=h-180+'px'
    $('EdushiObj').style.left='11px';
    var vz=0;
    if(getZoom()>1)vz=1;
   _oEye.Zoom(vz); 
   //alert($('Cpointer').style.paddingLeft);
   $('Cpointer').style.marginTop=(_oMap.MapHeight()/2)-7+'px';
   $('Cpointer').style.marginLeft=(_oMap.MapWidth()/2)-7+'px';
	$('4w').style.top=h-55+'px';
   $('4w').style.left=w-60+'px';
    
}
window.onload =function(){
    window.onresize();
    fnCreateCityList();    
    fnDashboardStyleChange();
    fnLoadJs(2,"Marker",function(){marker.Load()}); 
    if($('DragWindowTop'))$('DragWindowTop').onmousedown=function(e){MyDrag(e,$('DragWindow'));}
    //MouserMoveEvent
    _oMap.onMapMouseMove = function(){
        //$('cxy').innerHTML="当前地图中心点：x="+_omPro.CenterX+"||y="+_omPro.CenterY;
    }
    //MouseDownEvent
    _oMap.onMapMouseDown = function(e){
        if(typeof marker!="undefined" && marker.status && e.which==1)marker.operate();
        if(typeof marker!="undefined" && marker.status && e.button==1)marker.operate();
    }
    //MouseUpEvent
    _oMap.onMapMouseUp = function(e){
        
    }
    _oMap.onMapZoomChange = function(){
        fnDashboardStyleChange();
        var vz=0;
        if(getZoom()>1)vz=1;
       _oEye.Zoom(vz);       
    }
    _oMap.onPaneEnd = function (x1,y1,x2,y2,flg){             
    }
    _oMap.onSpotLabelClick=function (spot){
    }   
}
function ShowAnchor(){

    go2xy(Request('tx'),Request('ty'));
    var i='a';
	var popHtmlMode ='<div class="Note2" onmousemove="$(\'{$pid}\').style.zIndex=1000;" onmouseout="$(\'{$pid}\').style.zIndex=100;"><div class="NTop"><h1 onclick="$(\'{$id}\').style.display=\'block\';">{$title}</h1></div><div id="{$id}" style="display:none;" class="NContent"><div class="NoteC">{$markerContent}</div><div class="NInput"><div onclick="" class="LeftPic"></div><div onclick="copycode(add,\'复制成功，请贴到你的QQ/MSN上发给你的好友！\')" class="RightPic"></div><input id="add" type="text" value="{$add}" size="14" style="display:none;"><div style="clear:both"></div></div></div></div>';
		var t = popHtmlMode.replace("{$title}",Request('title'));
		t = t.replace("{$markerContent}",Request('tcon'));
		t = t.replace('{$id}',"M"+i);
		t = t.replace('{$id}',"M"+i);
		t = t.replace('{$pid}','putPopLable_'+i);
		t = t.replace('{$pid}','putPopLable_'+i);
		t = t.replace('{$pid}','putPopLable_'+i);
		t = t.replace('{$add}','http://2d.edushi.com/'+_sDefaultCityCode+'&tx='+Request('tx')+'&ty='+Request('ty')+'&title='+Request('title')+'&tcon='+Request('tcon'));
		var nd = $C('div');
        nd.id='putPopLable_'+i;
        nd.innerHTML=t; 
        putPopT(Request('tx'),Request('ty'),100,20,95,0,nd);        
}
function ChanageCity()
{
	location.href = 'http://2d.edushi.com/'+$('CityList').value;
}
function fnMarker(){
    StopScale();
    if(!(typeof marker!="undefined" && marker.status)){
        fnLoadJs(2,"Marker",function(){marker.status=true;marker.Load()}); 
        _omPro.PointerTip='<div class="Note"><div class="NTu"></div><div class="NTop"></div><div class="NContent">左键写便笺</div><div style="clear:both"></div></div>';
        _omPro.PointerTipDiffX=-5;
        _omPro.PointerTipDiffY=30;
        _oMap.ShowPointerTip(true);        
    }else{
        marker.status=false;
        _omPro.PointerTip='';
        _oMap.ShowPointerTip(false);
    } 
}
function fnCreateCityList(){    
    for(i=0;i<CityName.length-1;i++){      
		if (CityName[i].indexOf("├")< 0){
			var group = document.createElement('OPTGROUP');
			group.label = CityName[i];		
			$('CityList').appendChild(group);
		}else{
		    $('CityList').options[i] = new Option(CityName[i],CityCode[i]);         
	    }
	 }
	 for(i=0;i<$('CityList').options.length;i++){
	    if(_sDefaultCityCode==$('CityList').options[i].value){
		        $('CityName').innerHTML=$('CityList').options[i].innerHTML.replace("├","");
		        $('CityList').options[i].selected = true;
		    }
	 }
}
function fnDashboardStyleChange(){
    var Dashboard_Z = getZoom();
    for (i=0;i<4;i++){
        if(i==Dashboard_Z){
            $('zoombar_'+i).className = 'Action';
        }else{
            $('zoombar_'+i).className = 'Uaction';
        }
    } 
}
function MyDrag(e,o){
	var mX,mY,oX,oY,oW,oH;
	if(!e)e=window.event;
	if(!e.pageX)e.pageX = e.clientX;
	if(!e.pageY)e.pageY = e.clientY;
	mX = parseInt(e.pageX,10);
	mY = parseInt(e.pageY,10);
	oX = parseInt(o.style.left,10);
	oY = parseInt(o.style.top,10);
	wX = fnGetWindowWidth();
	wY = fnGetWindowHeight();
	oW = parseInt(o.offsetWidth,10);
	oH = parseInt(o.offsetHeight,10);	
    if(document.addEventListener){
		document.addEventListener('mousemove', mousemove, true);
        document.addEventListener('mouseup', mouseup, true); 
    } 
    else{
		if(o.setCapture)o.setCapture();						      
		if(document.attachEvent){ 
			document.attachEvent('onmousemove', mousemove); 
			document.attachEvent('onmouseup', mouseup); 
		}
    }
	function mousemove(e){
		if(!e)e=window.event;
		if(!e.pageX)e.pageX = e.clientX;
		if(!e.pageY)e.pageY = e.clientY;
		var oLeft=oX + (parseInt(e.pageX,10) -mX),oTop=oY + (parseInt(e.pageY,10) -mY);
		//var oH=390;
		if(oLeft>0&&oLeft<(wX-oW))o.style.left=oX + (parseInt(e.pageX,10) -mX);
		//if($('Lmiddle').style.display=="none")oH=40;
		if(oTop-110>0&&oTop<(wY-oH))o.style.top=oY + (parseInt(e.pageY,10)-mY);
	}
	function mouseup(e){
        if(document.removeEventListener){ 
            document.removeEventListener('mousemove', mousemove, true); 
            document.removeEventListener('mouseup', mouseup, true); 
        } else{
			if(o.releaseCapture)o.releaseCapture();
			if(document.detachEvent){ 
				document.detachEvent('onmousemove', mousemove); 
				document.detachEvent('onmouseup', mouseup); 
			}
        }
        stop(e);
	}
    function stop(e){ 
        if(e.stopPropagation) return e.stopPropagation(); 
        else return e.cancelBubble=true;             
    } 
    function abort(e){ 
        if(e.preventDefault) return e.preventDefault(); 
        else return e.returnValue=false; 
   } 
}
function WindowClose(){
    removePopAll();
    $('DragWindow').style.display="none";
}
function WindowMin(){
    with($('Lmiddle').style){
	    display = display == '' ? 'none' : '';
    }
    with($('DragWindow').style){
	    height = height == '28px' ? '280px' : '28px';
    }
    if($('Lmiddle').style.display == ''){    	
	    $('img_min').src=$('img_min').src.replace("2d22.gif","2d23.gif");
    }
    else{
        $('img_min').src=$('img_min').src.replace("2d23.gif","2d22.gif");
    }
} 
function changeImg_Move(obj){
    var img = obj.src;    
    obj.src = img.replace('2d23.gif','2d22.gif').replace('4map13.gif','4map13A.gif').replace('4map05.gif','4map05A.gif');
}
function changeImg_Out(obj){
    var img = obj.src;    
    obj.src = img.replace('2d22.gif','2d23.gif').replace('4map13A.gif','4map13.gif').replace('4map05A.gif','4map05.gif');
}
function ShowMobilePanel(titlename){   
    if($('DragWindowTitle')!='')$('DragWindowTitle').innerHTML  = titlename;
    if($('DragWindow').style.display!='block'){ 
        $('DragWindow').style.top       = 130;
        $('DragWindow').style.left      = document.body.clientWidth - 280;
    }
    $('DragWindow').style.right = 30+'px';
    $('DragWindow').style.top   = 130+'px';
    $('DragWindow').style.display   = 'block';
    this.ClearTitle = function(){
        $('DragWindowTitle').innerHTML ='';
    }
    this.InsertContent = function(){
        return $('Drag_Content').innerHTML;
    }
    return $('Drag_Content');
}
function fnChangeTitle(titlename){
    if($('DragWindowTitle')!='')$('DragWindowTitle').innerHTML  = titlename;
}
function CloseMobilePanel(){
    removePopAll();
    $('DragWindow').style.display   = 'none';    
}
function fnEyeMap(){
    if($('Scontent').style.display=='none'){
        var h=fnGetWindowHeight();
        $('EdushiObj').style.top=h-180+'px'
        $('Scontent').style.display='block';
    }else{
        $('Scontent').style.display='none';
        var h=fnGetWindowHeight();
        $('EdushiObj').style.top=h-50+'px'
    }
}
function Lsearch(){}
Lsearch.prototype.page = 1;
Lsearch.prototype.key  = '';
Lsearch.prototype.pageSize = 4;
Lsearch.prototype.pageCount=1;
Lsearch.prototype.Init=function(){
    this.page = 1
    if(typeof sData!="undefined"){
        sData=null;
        delete sData;
    }
}
Lsearch.prototype.fnLoadSearchData=function(){
    if($('LocalSearch').value==""){alert('关键字不能为空！');return false;}
    this.Init();
    var kw=$('LocalSearch').value;
    this.key=kw;
    ShowMobilePanel('搜索结果').innerHTML='<div style="text-align:center; padding-top:80px"><div class="loadingImg"></div> <br>正在搜索 <font color="ff0000" style="word-break:break-all;"><b>'+ kw+'</b></font> 请稍候...</div>';
    var url = 'Function/'+_sLanguage+'/Search.aspx?action=SearchData&&citycode='+_sDefaultCityCode+'&kw='+escape(kw);
    VENetwork.DownloadScript(url,function(){LS.fnShowSearchData();});
}
Lsearch.prototype.fnShowSearchData=function(){
    if(typeof sData=="undefined"||sData==null){
         ShowMobilePanel('搜索结果').innerHTML='无搜索结果！';
         return false;
    }    

    var intBegin  = (this.page-1)*(this.pageSize);
    var intEnd    = this.page*(this.pageSize);
    if(intEnd>(sData.ID.length-1)){
        intEnd=sData.ID.length-1;
    }
    if((sData.ID.length-1)%(this.pageSize)==0){
        this.pageCount=((sData.ID.length-1)/this.pageSize);
    }else{
        this.pageCount=int(sData.ID.length-1,this.pageSize)+1;
    }
    var r='<h2>搜索<font> {$key} </font>得到{$count}个结果：</h2><ul>{$list}</ul><h3>{$page}</h3>';
    var t='';
    var sign=['①','②','③','④','⑤'];
    var l=0;
    removePopAll();
    for(i=intBegin;i<=intEnd;i++){
        t +='<li><font>'+sign[l]+'</font><span onclick="go2xy('+sData.LogicalX[i]+','+sData.LogicalY[i]+');LS.ShowPopInfo('+i+');">'+sData.Name[i]+'</span><br />地址：'+sData.Address[i]+'</li>';
        l++;
        this.ShowPop(i,l);
    }
    var strPage=pageShow(this.page,this.pageCount,5,'pageStr','fnShowpage');
    r=r.replace('{$key}',this.key).replace('{$count}',sData.ID.length).replace('{$list}',t).replace('{$page}',strPage);
    ShowMobilePanel('搜索结果').innerHTML=r;
    r=null;
    t=null;
}
Lsearch.prototype.ShowPop=function(a,b){
    var w=parseInt(sData.Name[a].length*14.1);
//    if (navigator.appVersion.match(/\bMSIE\b/)){
//        w=
//    }    
    var p='<div class="MapPOPO" onclick="LS.ShowPopInfo('+a+');" onmouseover="LS.ShowTitle('+a+');" onmouseout="LS.HiddinTitle('+a+');">'+b+'</div>'
        +'<div id="LsPInfo'+a+'" onclick="LS.ShowPopInfo('+a+');" onmouseover="LS.ShowTitle('+a+');" onmouseout="LS.HiddinTitle('+a+');" class="PopoBg" style="position:absolute; left:0px;display:none;"><div class="MapPOPO" >'+b+'</div><div  class="Name" style="width:'+w+'px;">'+sData.Name[a]+'</div></div>';
    var nd = $C('div');
    nd.id='LsP'+a;
    nd.innerHTML=p;
    putPop(parseInt(sData.LogicalX[a]),parseInt(sData.LogicalY[a]),w+26,50,-10,24,nd);
    nd=null;    
}
Lsearch.prototype.ShowTitle=function(a,b){
    if($('LsPInfo'+a).style.display=="none")$('LsPInfo'+a).style.display="block";
}
Lsearch.prototype.HiddinTitle=function(a,b){
    if($('LsPInfo'+a).style.display=="block")$('LsPInfo'+a).style.display="none";
}
Lsearch.prototype.ShowPopInfo=function(a){
    removePop('Info');
    var p='<div class="InfoPopo"><div class="Over"><div class="Title"><div>'+sData.Name[a]+'</div><span><div onclick="removePop(\'Info\');" class="Popclose"></div></span></div><ul><li>分类：'+sData.BigTypeName[a]+'>'+sData.SmallTypeName[a]+'</li><li>区划：'+sData.AdminName[a]+'</li><li>地址：'+sData.Address[a]+'</li><li>电话：'+sData.Telephone[a]+'</li></ul></div><div class="Bottom"></div><div style="clear:both"></div></div>'
    var nd = $C('div');
    nd.id='Info';
    nd.innerHTML=p;
    putPop(parseInt(sData.LogicalX[a]),parseInt(sData.LogicalY[a]),253,50,61,180,nd);
    nd=null;
}

function fnShowpage(a){
    if(a){
        LS.page=a;
    }
    LS.fnShowSearchData();
}
var LS =new Lsearch();