﻿// JScript 文件

function mclick(obj,index)
    {
        //if(position!="")
        //{
            //document.getElementById(position).src="imgs/" + position + "_1.jpg";
        //}
        position=obj.id;
        //document.getElementById(position).src="imgs/" + position + "_2.jpg";
        if(tfbh != "")
            document.getElementById("tficon").style.visibility='';
        obj.style.backgroundColor='#ffffff';
        obj.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=80);";
        
        ClearDistance();
        switch(index)
        {
            case 1:
                mapZoomInTf();
                break;
            case 2:
                mapZoomOutTf();
                break;
            case 3:
                mapzoom++;
                mapCheckZomm();
                map.setCenter(map.getCenter(),mapzoom);
                mapToolControl(1);
                break;
            case 4:
                mapzoom--;
                mapCheckZomm();
                map.setCenter(map.getCenter(),mapzoom);
                mapToolControl(2);
                break;
            case 5:
                mapFull();
                break;
            case 6:
                maptool=0;
                break;
            case 7:
                mapToolControl(3);
                break;
            case 8:
                mapToolControl(4);
                break;
            case 11:
                document.getElementById("tficon").style.visibility='hidden';
                if(yuanquan.polygon7)
                {
                    map.removeOverlay(yuanquan.polygon7);
                    yuanquan.polygon7 = null;
                }
                if(yuanquan.polygon10)
                {
                    map.removeOverlay(yuanquan.polygon10);
                    yuanquan.polygon10 = null;
                }
                maptool=11;
                break;
            case 13:
                map.setMapType(G_PHYSICAL_MAP);
                defaultMapType=0;
                mapCheckZomm();
                //map.setMapType(0); //HYBRID  //G_SATELLITE_MAP  //G_NORMAL_MAP
                //G_NORMAL_MAP 地圖
                //G_SATELLITE_MAP 衛星
                //G_HYBRID_MAP 混合
                //G_PHYSICAL_MAP 地形
                break;
            case 14:
                map.setMapType(G_SATELLITE_MAP);
                defaultMapType=1;
                mapCheckZomm();
                break;
            case 15:
                map.setMapType(G_NORMAL_MAP);
                defaultMapType=2;
                mapCheckZomm();
                break;
        }
    }
    
    
//放大操作
function mapZoomInTf()
    {
        if (tflastpoint)
        {
            mapzoom++;
            mapCheckZomm();
            map.setCenter(tflastpoint, mapzoom);
        }
    }
//缩小操作
function mapZoomOutTf()
    {
        if (tflastpoint)
        {
            mapzoom--;
            mapCheckZomm();
            map.setCenter(tflastpoint, mapzoom);
        }
    }
    
//全图操作
function mapFull()
    {
        maptool=0;
        mapzoom=defaultmapzoom;
        mapcenterx=defmapcenterx;
        mapcentery=defmapcentery;
        if (tflastpoint)
        {
            map.setCenter(tflastpoint, mapzoom);
        }
        else
        {
            map.setCenter(new GLatLng(defmapcentery,defmapcenterx), mapzoom);
        }
        mapbounds=map.getBounds();
        mapCheckZomm();
    }

//检测视野
function mapCheckZomm()
    {
        if (mapzoom<=defmapminzoom)
        {
            mapzoom=defmapminzoom;
        }
        if (mapzoom>=defmapmaxzoom)
        {
            mapzoom=defmapmaxzoom;
        }
        //alert(defaultMapType);
        if (defaultMapType == 1)
        {
            mapDrawCity();
        }
        else
        {
            mapDelCity();
        }
    }
    
function ClearDistance()
	{
        if (distanceline)
        {
            if (distanceline.polyline)
            {
                map.removeOverlay(distanceline.polyline);
                distanceline.polyline=null;
            }
            if (distanceline.points.length>0)
            {
                map.removeOverlay(distanceline.points[0].marker);
                distanceline.points[0].marker=null;
            }
            if (distanceline.points.length>1)
            {
                map.removeOverlay(distanceline.points[1].marker);
                distanceline.points[1].marker=null;
            }
            distanceline=new classtfline();
        }
    }
    
//线信息对象
function classtfline()
    {
		this.polyline=null;
		this.tm="";
		this.color="";
		this.icon="";
		this.points=[];
    }
    
//设置操作功能号
function mapToolControl(tool)
    {
        maptool=tool;
        map.closeInfoWindow();
    }
    
//点信息对象
function classtfpoint()
    {
		this.marker=null;
		this.point=null;
		this.rqsj="";
		this.zxfl="";
		this.zxqy="";
		this.zxfs="";
		this.ydsd="";
		this.ydfx="";
		this.radius7="";
		this.radius10="";
		this.depict="";
		this.polygon7=null;
		this.polygon10=null;
    }
    
//城市信息
function classcity()
    {
		this.marker=null;
		this.point=null;
		this.code="";
		this.name="";
		this.zoom="";
		this.ok="";
	}
    
//地图测距
function mapDistance(marker,point)
		{
			if (distanceline)
			{
				if (distanceline.points.length==2)//清除历史测距
				{
					ClearDistance();
				}
				if (distanceline.points.length<2)
				{
					var icon = new GIcon();
					icon.image = url + "images/distance.png";  //cross.gif
					icon.iconSize = new GSize(12, 20);
					icon.iconAnchor = new GPoint(6, 20);
					icon.infoWindowAnchor = new GPoint(5, 1);
					var markerinfo = new GMarker(point,icon);
					map.addOverlay(markerinfo);
					var temppoint=new classtfpoint();
					temppoint.marker=markerinfo;
					temppoint.point=point;
					distanceline.points.push(temppoint);
					if (distanceline.points.length==2)				
					{
						mapDrawPolyline(distanceline,'#FFFFFF',1,0.5);
						var distance=ForDight(distanceline.points[0].point.distanceFrom(distanceline.points[1].point)/1000,2);
						alert('两点间直线距离为：' + distance.toString() + '公里！');
					}
				}
			}
		}
		
		
		
//画折线处理
function mapDrawPolyline(line,color,weight,opacity)
		{
			if (line.points.length>0)
			{				
				if (line.polyline)
				{
					map.removeOverlay(line.polyline);
				}
				line.polyline=null;
				var tfpointline=[];
				for(var i=0;i<line.points.length;i++)
				{
					tfpointline.push(line.points[i].point);
				}
				line.polyline=new GPolyline(tfpointline,color,weight,opacity);
				map.addOverlay(line.polyline);
			}
		}
		
function mover(obj)
    {
        if (obj.id==position)
        {
            return false;
        }
        //obj.src="imgs/" + obj.id + "_2.jpg";
        obj.style.backgroundColor='#99ffff';
        obj.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=100);";
    }

function mout(obj)
    {
        if (obj.id==position)
        {
            return false;
        }
        obj.style.backgroundColor='#ffffff';
        obj.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=80);";
        //obj.src="imgs/" + obj.id + "_1.jpg";
    }
    
var isopen=false;
var isopen2=true;
function closeandopen()
{
	if(isopen)
	{
		closeoropen.src="images/1.jpg";
		tfLeftTable.style.display="inline";
		isopen=false;
	}
	else
	{
		closeoropen.src="images/2.jpg";
		tfLeftTable.style.display="none";
		isopen=true;
	}
}
function closeandopen2()
{
	if(isopen2)
	{
		cao2.src="images/1.jpg";
		divljlb.style.display="inline";
		isopen2=false;
	}
	else
	{
		cao2.src="images/2.jpg";
		divljlb.style.display="none";
		isopen2=true;
	}
}

//////////////////////////////////////////////////////////////数据/////////////////////////
function SelectInit()
    {
        var obj = $("NF");
        var i = new Date().getYear();
        for(i;i>=1949;i--)
        {
            obj.options[obj.length] = new Option(i+"年",i);
        }
   
        //$XML("../xml/aaa.xml",SelectAYearCallback);
        $XML("../xml/gettyphoon.aspx?year="+obj.value,SelectAYearCallback);
        //$XML("http://www.meteo-gis.cn/db/xml/tfbhxmllist/"+obj.value+".xml",SelectAYearCallback);
    }
    
function SelectAYearCallback(dom)
    {
       
        var childNodes = dom.selectNodes("NewDataSet/Table");
        if(childNodes)
        {
            var len = childNodes.length
            var res = '<table border="0" onselectstart="return false;" onmousedown="kuosan();" cellpadding="0" cellspacing="0" width="210px" id="Table9" style="cursor:hand;">';
            var child = null;
            var node = null;
            
            var _tfbh,_tfm,_tfme;
            for( var i=0;i< len;i++ )
            {
                child = childNodes.item(i);
                
                _tfbh = child.selectSingleNode("Serial").text;        //.Trim()selectSingleNode("Serial").text.Trim();  //Serial
                _tfm  = child.selectSingleNode("Number").text;  //.Trim();Number
                node = child.selectSingleNode("Ename");
                if (node != null)
                    {_tfme = node.text;}  //.Trim();Ename
                else
                    {_tfme = '-';}
                _tfm  = _tfm  || "&nbsp;";
                _tfme = _tfme || "&nbsp;";
                res += '<tr id="'+_tfbh+'">'
                    + '<td align="center" width="28%" height="20">'+_tfbh+'</td>'
                    + '<td align="center" width="28%" >'+_tfm+'</td>'
                    + '<td align="center" width="44%" >'+_tfme+'</td>'
                    + '</tr>';
            }
        }
        res += '</table>';
        $("table").innerHTML =res;
        dianjitb1 = $("Table9");
    }
    
function SelectAYear(val)
    {
        $XML("../xml/gettyphoon.aspx?year="+val,SelectAYearCallback);
        //$XML("db/xml/tfbhxmllist/"+val+".xml",SelectAYearCallback);
    }
    
function TFXMLload()
    {
        if(tfbh != "")
        {
            
            $XML("../xml/getserial.aspx?num="+tfbh,TFXMLloadCallback);
            //$XML("db/xml/tflsljxmllist/"+tfbh+".xml",TFXMLloadCallback);
        }
    }
    
function $XML(path,callback)//相对路径，返回时调用的方法，加上一个返回的XML文档数据
    {
        GDownloadUrl(path, function(data, responseCode) {
            if(responseCode == 200)
                callback(GXml.parse(data));
            else
                alert("加载XML文件时出现错误！");
        });
    }
    
function $YBXML(path,tm,callback)//相对路径，台风编号，时间，返回方法
    {
        GDownloadUrl(path, function(data, responseCode) {
            if(responseCode == 200)
                callback(GXml.parse(data),tm);
        });
    }
    
function kuosan(e)
{
    var tr,ee;
    ee=e==null?event.srcElement:e.target;
    if(ee.tagName!="TD")
        return;
    tr=ee.parentNode;
    if(dianjitb1.selRow!=null)
    {
        var tmptr = dianjitb1.selRow;
        tmptr.style.backgroundColor = "";
    }
    tr.style.backgroundColor = "#3f6fd1";  //2954ad
    dianjitb1.selRow=tr;
    tfbh = tr.id;
    tfm = tr.childNodes[1].innerHTML;
    $("tsInf").style.display = "";
    window.setTimeout("TFXMLload();",3);
}

//存储台风详细路径的信息到数组中去
function TFXMLloadCallback(dom)
    {
        var childNodes = dom.selectNodes("NewDataSet/Table");
        if(childNodes)
        {
            var len = childNodes.length;
            if(len != 0)
            {
                var child = null;
                var node = null;
                var _TFBH,_RQSJ,_WD,_JD,_ZXQY,_ZXFS,_YDSD,_YDFX,_RADIUS7,_RADIUS10,_DEPICT,_FLDJ,_IMG,_POINT;
                tfarr = new Array();
                for(var i=0;i<len;i++)
                {
                    child     = childNodes[i];
                    
                    _TFBH     = child.selectSingleNode("Serial").text;
                    _RQSJ     = getDatetime(child.selectSingleNode("Tdatetime").text,true);
                    _WD       = child.selectSingleNode("lon").text;
                    _JD       = child.selectSingleNode("lat").text;
                    _ZXQY     = child.selectSingleNode("p").text;
                    _ZXFS     = child.selectSingleNode("v").text;
                    
                    node = child.selectSingleNode("sp");  //_YDSD     = child.selectSingleNode("sp").text;
                    if (node != null)
                        {_YDSD = node.text;} 
                    else
                        {_YDSD = '-';}
                    
                    node = child.selectSingleNode("dir");   //_YDFX     = child.selectSingleNode("dir").text;
                    if (node != null)
                        {_YDFX = node.text;} 
                    else
                        {_YDFX = '-';}
                    
                    node = child.selectSingleNode("r6");   //_RADIUS7  = child.selectSingleNode("r6").text;
                    if (node != null)
                        {_RADIUS7 = node.text;} 
                    else
                        {_RADIUS7 = '-';}
                    
                    node = child.selectSingleNode("r8");   //_RADIUS10 = child.selectSingleNode("r8").text;
                    if (node != null)
                        {_RADIUS10 = node.text;} 
                    else
                        {_RADIUS10 = '-';}
                    
                    _DEPICT   = child.selectSingleNode("Tdatetime").text;
                    _FLDJ     = getLevelf(child.selectSingleNode("v").text); 
                    _IMG      = "images/lan2.png";  //child.selectSingleNode("IMG").text; 
                    _TFME     = child.selectSingleNode("Ename").text;
                    _TFM      = getDatetime(child.selectSingleNode("Tdatetime").text,false);
                    _POINT    = new GLatLng(_JD,_WD);      
                                
                    //tfarr[i] = new Array(_TFBH,_RQSJ,_WD,_JD,_ZXQY,_ZXFS,_YDSD,_YDFX,_RADIUS7,_RADIUS10,_DEPICT,_FLDJ,_IMG,_POINT,_TFME,_TFM);
                    tfarr[i] = new Array(_TFBH,_RQSJ,_WD,_JD,_ZXQY,_ZXFS,_YDSD,_YDFX,_RADIUS7,_RADIUS10,_DEPICT,_FLDJ,_IMG,_POINT,_TFME,_TFM);
                    //tfarr[i] = new Array(_TFBH,_RQSJ,_WD,_JD,_ZXQY,_ZXFS,_POINT,_TFME);//_YDSD,_YDFX,_RADIUS7,_RADIUS10,_DEPICT,_FLDJ,_IMG,//,_TFM
                }
                
                tfljlbChange();
                window.setTimeout("TFLSDDraw();",3);
            }
            else
            {
                alert("没返回此台风数据！");
                $("tsInf").style.display = "none";
            }
        }
        else
        {
            $("tsInf").style.display = "none";
        }
    }
    
function getDatetime(atime,flag)
    {
        var year = atime.substring(0,4);
        var month = atime.substring(5,7);
        var day = atime.substring(8,10);
        var hour = atime.substring(11,13);
        if (flag)
            {return month+'-'+day+' '+hour+'时';}   //year+'-'+
        else
            {return year+'-'+month+'-'+day+' '+hour+':00:00';}
    }
    
function getLevelf(ff)
    {
        if (ff<0.3) 
            {return "0";}
        else if (ff<1.6) 
            {return "1";}
        else if (ff<3.4) 
            {return "2";}
        else if (ff<5.5) 
            {return "3";}
        else if (ff<8) 
            {return "4";}
        else if (ff<10.8) 
            {return "5";}
        else if (ff<13.9) 
            {return "6";}
        else if (ff<17.2) 
            {return "7";}
        else if (ff<20.8)  
            {return "8";}
        else if (ff<24.5) 
            {return "9";}
        else if (ff<28.5) 
            {return "10";}
        else if (ff<32.7) 
            {return "11";}
        else if (ff<37) 
            {return "12";}
        else if (ff<41.5) 
            {return "13";}
        else if (ff<46.2) 
            {return "14";}
        else if (ff<51) 
            {return "15";}
        else if (ff<56.1) 
            {return "16";}
        else 
            {return "17";}
    }
    
///////////////////////////////////画图处理
function tfljlbChange()
    {
        var res = '<table id="tflslftable" border="0" onmousedown="selectTable2Row();" cellpadding="0" cellspacing="0" width="210px" style="cursor:hand;">';
        var i = tfarr.length-1;
        for(i;i>-1;i--)
        {
            res += '<tr theid="'+i+'">'
                + '<td align="center" width="36%" height="19">'+tfarr[i][1]+'</td>'
                + '<td align="center" width="19%" >'+tfarr[i][2]+'</td>'
                + '<td align="center" width="17%" >'+tfarr[i][3]+'</td>'
                + '<td align="center" width="17%" >'+tfarr[i][4]+'</td>'
                + '<td align="center" width="11%" >'+tfarr[i][5]+'</td>'
                + '</tr>';
        }
        res += '</table>';
        $("divljlb").style.display = "";
		$("tfljlb").style.height="200px";
		cao2.src="images/1.jpg";
		isopen2 = false;
        $("tfljlb").innerHTML =res;
        dianjitb2 = $("tflslftable");
    }
    
    var tflspoints = null;
    var tmpline = null;
    
/////////////////具体台风的地图绘制
function TFLSDDraw()
    {
        if(tfarr)
        {

            tflspoints = [];
            
            if(tmpline != null)
            {
                map.removeOverlay(tmpline);
                tmpline = null;
            }
            
            if(tfdraw.length > 0)
            {
                for(var j=0;j<tfdraw.length;j++)
                {
                    map.removeOverlay(tfdraw[j]);
                }
                tfdraw = new Array();
            }
            
            if(tfyblspoints.length != 0)
            {
                for(var i=0;i<tfyblspoints.length;i++)
                {
                    for(var j=1;j<tfyblspoints[i].length;j++)
                    {
                        map.removeOverlay(tfyblspoints[i][j]);
                    }
                }
            }
            
            tfyblspoints = new Array();
            if(yblines.length != 0)
            {
                for(var ii=0;ii<yblines.length;ii++)
                    map.removeOverlay(yblines[ii]);
                yblines = new Array();
            }
            
            for(var i=0;i < tfarr.length;i++)
            {
                
                var icon = new GIcon();
                icon.image = url + tfarr[i][12];
                icon.iconSize = new GSize(8, 8);
                icon.iconAnchor = new GPoint(3, 3);
                icon.infoWindowAnchor = new GPoint(5, 1);
                var markerinfo = new GMarker(tfarr[i][13],icon);
                tflspoints.push(tfarr[i][13]);
                markerinfo.theid = i;
                markerinfo.thepoint = tfarr[i][13];
                tfdraw.push(markerinfo);
                
                GEvent.addListener(markerinfo, "mouseover", function() {
                    TFInfoShow(this.theid,this.thepoint);
                });  
                
                GEvent.addListener(markerinfo, "click", function() {
                    maptool=0;
                    $("tsInf").style.display = "";
                    selectSiteChangeTable2(this.theid);
                    window.setTimeout(SelectTFASite,3,this.theid); //(this.theid)
                });
                
                GEvent.addListener(markerinfo, "mouseout", function() {
                    TFInfoHidden();
                });
                
                map.addOverlay(markerinfo);
                if(i == tfarr.length-1)
                {
                    tflastpoint = tfarr[i][13];
                }
            }
            tmpline = new GPolyline(tflspoints,'#FB7304',3,0.5);
            map.addOverlay(tmpline);
        }
        
        $("tsInf").style.display = "none";
        var t = tfarr[i-1];
        addInfo(t[0]+"号 "+t[14],t[15],t[3],t[2],t[5],t[6],t[7],t[8],t[9],t[4],t[11]);
        
        //alert(t);
        
        mapLastPoint();
        
        //selectSiteChangeTable2(i-1);
        
        TFYBLJXMLload(tfarr[i-1]);
        
        mapDrawCir(i-1);
        
        mapFull();
    }
    
//画最后历史节点
function mapLastPoint()
    {
        if(tflastpoint != null)
        {
            var bounds=map.getBounds();
            var gm=new GMercatorProjection(mapzoom+1);
            var bp=gm.fromLatLngToPixel(new GLatLng(bounds.getNorthEast().y,bounds.getSouthWest().x),mapzoom);
            var p=gm.fromLatLngToPixel(tflastpoint,mapzoom);
            var tficon=document.getElementById("tficon");
//            tficon.style.left=(p.x-bp.x-18).toString() + "px";
//            tficon.style.top=(p.y-bp.y-23).toString() + "px";
            if (p.y>bp.y)
            {
                tficon.style.visibility="";
            }
            movetftb();
        }
    }
    
    
function addInfo(title,t,JD,WD,win,m,md,r7,r10,p,fldj)
    {
        
        if($("info").style.display != "")
            $("info").style.display = "";
        //if($("tl").style.display != "")
        //    $("tl").style.display = "";
            
        
        info.innerHTML = "<div style='background-color:#ffffff;font-family:verdana,small arial,宋体;filter: Alpha(Opacity=50);width:200px;'><div style='position:relative;'><p align=center style='margin:8;'><font color='#2e353d'><b>"+title+"</b></font></p>"
                       +"<p style='margin:8;'>时间: "+t+"</p>"
   				       +"<p style='margin:8;'>东经: "+sround(WD)+" (度)&nbsp;&nbsp;"+"北纬: "+sround(JD)+" (度)</p>"
   				       +"<p style='margin:8;'>中心气压: "+p+" (百帕)</p>"
				       +"<p style='margin:8;'>最大风速: "+win+" (米/秒)&nbsp;&nbsp;"+"风力: "+fldj+" 级</p>"
				       +"<p style='margin:8;'>移动速度: "+m+" (公里/小时)</p>"
				       +"<p style='margin:8;'>移动方向: "+md+"</p>"
				       +"<p style='margin:8;'>7级风圈半径: "+r7+" (公里)</p>"
				       +"<p style='margin:8;'>10级风圈半径: "+r10+" (公里)</p></div></div>"
    }
    
function sround(val)
    {
	    tempval=val*10;
	    var tempstr;
	    if(tempval % 10 == 0)
	    {
		    tempstr=val.toString();//+".0";
	    }
	    else
	    {
		    tempstr=val.toString();
	    }
	    return tempstr;
    }
    
    
function movetftb()
	{
	    if(tflspoints != null && tflspoints.length >0)
	    {
	        var len = tflspoints.length;
	        tf_px = new Array();
	        tf_py = new Array();

            clearTimeout(movingtfid);
            
	        for(var i=0;i<len;i++)
	        {
	            var bounds=map.getBounds();
                var gm=new GMercatorProjection(mapzoom+1);
                var bp=gm.fromLatLngToPixel(new GLatLng(bounds.getNorthEast().y,bounds.getSouthWest().x),mapzoom);
                var p=gm.fromLatLngToPixel(tflspoints[i],mapzoom);
                tf_px.push(p.x-bp.x-22);
                tf_py.push(p.y-bp.y+4);
	        }
    	    
	        move_Tf_Yt(-1);
	    }
	}
	
function move_Tf_Yt(curr_p)
	{	
		var tme=30;
		var x_c,y_c,k,bz,point;
		bz = 0;
		point = curr_p;
		if (point == tf_px.length-1 )
			point =-1;
		if ( point == -1 )
		{
			x_c = tf_px[point+1];
			y_c = tf_py[point+1];
			point = point + 1;
			bz = 1;
		}
		else
		{
			x_c = tfyt.style.left;
			y_c = tfyt.style.top;
			x_c = x_c.substr(0,x_c.length-2)*1;
			y_c = y_c.substr(0,y_c.length-2)*1;
		}
		while (tf_px[point+1]<0 || tf_py[point+1]<0 || tf_px[point+1]>movewidth || tf_py[point+1]>moveheight)
		{
			x_c = tf_px[point+1];
			y_c = tf_py[point+1];				
			point = point + 1;
			bz = 2;
		}
		if (x_c<0 || y_c<0 || x_c>movewidth || y_c>moveheight)
		{tmp=1;}
		if ( bz==0 )
		{
			if (x_c != tf_px[point+1])
			{
				k = (tf_py[point+1] - tf_py[point])/(tf_px[point+1] - tf_px[point]);
				if ( x_c > tf_px[point+1] )
				{
					x_c = x_c - 1;
					y_c = tf_py[point] - (tf_px[point]-x_c)*k;
				}
				if ( x_c < tf_px[point+1] )
				{
					x_c = x_c + 1;
					y_c = tf_py[point] +(x_c-tf_px[point]) * k;
				}		
			}
			else
			{
				if ( y_c > tf_py[point+1] )
					y_c = y_c * 1 - 1;
				else
					if ( y_c < tf_py[point+1] )
						y_c = y_c + 1;
				else
					if ( y_c = tf_py[point+1] )
						point = point + 1;							
			}			
		}	
        
		tfyt.style.left = x_c;
		tfyt.style.top = y_c;
		
		
		
		movingtfid = setTimeout("move_Tf_Yt(" + point + ")",tme);
		//movingtfid = window.setInterval("move_Tf_Yt(" + point + ")",tme);
	}
	
	
//重新设定地图大小
    function resizeMap() 
    {
        //var windowWidth = document.documentElement.clientWidth-2;
        //document.getElementById("map").style.width=windowWidth.toString() + "px";
        //mapstateload();
        movewidth = $("map").offsetWidth-10;
        moveheight = $("map").offsetHeight-7;
    }
    
function addDatetime(atime,flag)
    {
        var year = atime.substring(0,4);
        var month = atime.substring(5,7);
        var day = atime.substring(8,10);
        var hour = atime.substring(11,13);
        var minute = atime.substring(14,16);
        
        var temp ;
        temp = new Date(year,month,day,hour,minute);
        var f = flag;
        if (f==24) {temp.setDate(temp.getDate()+1);}
        else if (f==48) {temp.setDate(temp.getDate()+2);}
        else if (f==72) {temp.setDate(temp.getDate()+3);}
        
        var year2 = temp.getYear();
        var month2 = temp.getMonth();
        var day2 = temp.getDate();
        var hour2 = temp.getHours();
        var minute2 = temp.getMinutes();
        
        var dtime = year2.toString() + "-" + fillstring(month2.toString()) + "-" + fillstring(day2.toString()) + " " + fillstring(hour2.toString()) + ":" + fillstring(minute2.toString()) + ":00";
        
        return(dtime);
    }
    
function fillstring(str)
  {
   if(str.length==1)
   {
    str = "0" + str; 
   }
   return(str);
  }

    
function caseWhere(str)
    {
        if (str=="韩国") {return "images/lv2.png";}
        else if (str=="日本") {return "images/zi2.png";}
        else if (str=="国家气象中心") {return "images/cheng2.png";}
    }
    
function caseWhereYS(str)
    {
        if (str=="韩国") {return "1fba24";}
        else if (str=="日本") {return "98386e";}
        else if (str=="国家气象中心") {return "cb9f45";}
    }
    
function TFYBLJXMLload(t)
    {
        var para2 = "";
        //var index1 = t[15].indexOf("月"),index2 = t[15].indexOf("日"),index3 = t[15].indexOf("时");
        
        theybid = t[13];
        //para2 = t[0].substr(0,4) + "-" + "00".substring(0,2-t[1].substring(0,index1).length) + t[1].substring(0,index1) + "-" + "00".substring(0,2-t[1].substring(index1+1,index2).length) +t[1].substring(index1+1,index2) + " " + "00".substring(0,2-t[1].substring(index2+1,index3).length) + t[1].substring(index2+1,index3)+":00:00";
        para2 = t[10];
        
        //alert(t);

        $YBXML("../xml/getyb.aspx?num="+t[0],para2,TFYBLJXMLloadCallback);
        //xmlhttpreq.sendReq("GetTFData",TFYBLJXMLloadCallback,"3",t[0],para2);
    }
    
//处理预报路径返回的数据,生成节点
function TFYBLJXMLloadCallback(xmldom,tm)
    {
        var tmptime;
        try
        {
            tmptime = xmldom.selectSingleNode("NewDataSet/Table[fdatetime = '"+tm+"']/fdatetime").text;  
            
        }
        catch(e){}
        
        if(tmptime)
        {
            var childNodes = xmldom.selectNodes("NewDataSet/Table[fdatetime = '"+tmptime+"']");
            var len = childNodes.length;

            var child = null;
            var k1,k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12,k13,k14;
            
            ybarr = null;
            ybarr = new Array();
            for(var i=0;i<len;i++)
            {
                child     = childNodes[i];
                k1  = addDatetime(child.selectSingleNode("fdatetime").text,child.selectSingleNode("tohour").text);
                k2  = child.selectSingleNode("lon").text;
                k3  = child.selectSingleNode("lat").text;
                k4  = child.selectSingleNode("v").text;
                k5  = "-";//k5  = child.selectSingleNode("ydsd").text;
                k6  = "-";//k6  = child.selectSingleNode("ydfx").text;
                k7  = "-";//child.selectSingleNode("radius7").text;
                k8  = "-";//child.selectSingleNode("radius10").text;
                k9  = child.selectSingleNode("p").text;
                k10 = child.selectSingleNode("fwhere").text;
                k11 = getLevelf(child.selectSingleNode("v").text);//grade
                k12 = caseWhere(child.selectSingleNode("fwhere").text); //"images/huang2.png";//child.selectSingleNode("img").text;
                k13 = caseWhereYS(child.selectSingleNode("fwhere").text);//child.selectSingleNode("ys").text;
                k14 = new GLatLng(k3,k2);
                
                ybarr[i]  = new Array(k1,k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12,k13,k14);
                //alert(k1+','+k2+','+k3+','+k4+','+k5+','+k6+','+k7+','+k8+','+k9+','+k10+','+k11+','+k12+','+k13+','+k14);
            }
            
            theys = null;
            theys = new Array();                        

            if(tfyblspoints.length != 0)
            {
                for(var i=0;i<tfyblspoints.length;i++)
                {
                    for(var j=0;j<tfyblspoints[i].length;j++)
                    {
                         map.removeOverlay(tfyblspoints[i][j]);
                    }
                }
            }
            
            tfyblspoints = new Array();
            if(yblines.length != 0)
            {
                for(var ii=0;ii<yblines.length;ii++)
                    map.removeOverlay(yblines[ii]);
                yblines = new Array();
            }
            
            var x = 0;//点的组合
            var thetmparr = new Array();
            for(var i=0;i < ybarr.length;i++)
            {
                var icon = new GIcon();
                icon.image = url + ybarr[i][11];
                icon.iconSize = new GSize(8, 8);
                icon.iconAnchor = new GPoint(4, 4);
                icon.infoWindowAnchor = new GPoint(5, 1);
                var markerinfo = new GMarker(ybarr[i][13],icon);

                markerinfo.theid = i;
                markerinfo.thepoint = ybarr[i][13];
                
                if(i == 0 && i == ybarr.length-1)
                {
                    thetmparr.push(theybid);
                    thetmparr.push(markerinfo);
                    tfyblspoints.push(thetmparr);
                    theys.push(ybarr[i][12]);
                    thetmparr = new Array();
                }
                else if( i == 0)
                {
                    thetmparr.push(theybid);
                    thetmparr.push(markerinfo);
                    theys.push(ybarr[i][12]);  ///
                }
                else if(ybarr[i][9] != ybarr[i-1][9])
                {
                    tfyblspoints.push(thetmparr);
                    thetmparr = new Array();
                    thetmparr.push(theybid);
                    thetmparr.push(markerinfo);
                    theys.push(ybarr[i][12]);  ///
                }
                else if(ybarr[i][9] == ybarr[i-1][9])
                {
                    thetmparr.push(markerinfo);
                }
                
                if (i == ybarr.length-1)
                {
                    thetmparr.push(markerinfo);
                    tfyblspoints.push(thetmparr);
                    theys.push(ybarr[i][12]);
                    thetmparr = new Array();
                }
                
                GEvent.addListener(markerinfo, "mouseover", function() {
                    TFInfoShow(this.theid,this.thepoint,2);
                });

                GEvent.addListener(markerinfo, "mouseout", function() {
                    TFInfoHidden();
                });

                map.addOverlay(markerinfo);
                
                
            }
            
            

            for(var j=0;j<tfyblspoints.length;j++)
            {
                var thetmppoints = new Array();
                thetmppoints.push(tfyblspoints[j][0]);
                for(var y=1;y<tfyblspoints[j].length;y++)
                    {thetmppoints.push(tfyblspoints[j][y].getPoint());}
                if (y!=1)
		{tmpline1 = new GPolyline(thetmppoints,"#"+theys[j],2.0,0.9);
                //alert(j + " " + theys[j]);
                map.addOverlay(tmpline1);
                yblines.push(tmpline1);}
            }
        }
    }
    
//路径节点画圆处理
function mapDrawCir(x)
    {
        var tmp = tfarr[x];
        
        if(yuanquan.polygon7)
        {
            map.removeOverlay(yuanquan.polygon7);
            yuanquan.polygon7 = null;
        }
        if(yuanquan.polygon10)
        {
            map.removeOverlay(yuanquan.polygon10);
            yuanquan.polygon10 = null;
        }

        if (tmp[8] != "0" && tmp[8] != "" && tmp[8] != "9999")
        {
            //var polygon=drawCircle(new GLatLng(tmp[2],tmp[3]), tmp[8]*1000, "#FFFF00", 3, 1,0.5);
            var polygon=drawCircle2(new GLatLng(tmp[3],tmp[2]), tmp[8],180,"#ffe92d",1,1,"#ffe92d",0.3);
            map.addOverlay(polygon);
            yuanquan.polygon7=polygon;
        }
        //alert(tmp[9]);
        if (tmp[9] != "0" && tmp[9] != "" && tmp[9] != "9999")
        {
            //alert("10");
            var polygon=drawCircle2(new GLatLng(tmp[3],tmp[2]), tmp[9], 180,"#ff902d",1,1,"#ff902d",0.3);
            map.addOverlay(polygon);
            yuanquan.polygon10=polygon;
        }
        
        mapDistanceToLastPoint(new GLatLng(tmp[3],tmp[2]));
    }
    
function drawCircle(center, radius, color, complexity,thickness,opacity) 
{ 
	center.y=center.y*1;
	center.x=center.x*1;
	var points = []; 
	var radians = Math.PI / 180; 
	var longitudeOffset = radius / (Math.cos(center.y * radians) * 111325); 
	var latitudeOffset = radius / 111325;
	//alert(latitudeOffset); 
	for (var i = 0; i < 360; i += complexity) 
	{ 
		var point = new GLatLng(center.y + (latitudeOffset * Math.sin(i * radians)),center.x + (longitudeOffset * Math.cos(i * radians))); 
		points.push(point);    
	} 
	points.push(points[0]);         // close the circle 
	var polyline = new GPolyline(points, color, thickness);
	var polygon = new GPolygon([polyline], true, color, opacity, true); 
	return polygon;
}

var bounds = new GLatLngBounds();
function drawCircle2(center, radius, nodes, liColor, liWidth, liOpa, fillColor, fillOpa)
{
// Esa 2006
	//calculating km/degree
	var latConv = center.distanceFrom(new GLatLng(center.lat()*1+0.1, center.lng()*1))/100;
	var lngConv = center.distanceFrom(new GLatLng(center.lat()*1, center.lng()*1+0.1))/100;

	//Loop 
	var points = [];
	var step = parseInt(360/nodes)||10;

	for(var i=0; i<=360; i+=step)
	{
	    var pint = new GLatLng(center.lat()*1 + (radius/latConv * Math.cos(i * Math.PI/180)), center.lng()*1 + (radius/lngConv * Math.sin(i * Math.PI/180)));
	    points.push(pint);
	    bounds.extend(pint); //this is for fit function
	}
	fillColor = fillColor||liColor||"#0055ff";
	liWidth = liWidth||2;

	var poly = new GPolygon(points,liColor,liWidth,liOpa,fillColor,fillOpa);
	//map.addOverlay(poly);
	return poly;
}
        

//显示台风具体显示,当鼠标移到哪个点时
function TFInfoShow(theid,thepoint,type)
    {
        var bounds=map.getBounds();
        var gm=new GMercatorProjection(mapzoom+1);
        var bp=gm.fromLatLngToPixel(new GLatLng(bounds.getNorthEast().y,bounds.getSouthWest().x),mapzoom);
        var p=gm.fromLatLngToPixel(thepoint,mapzoom);
        var pointinfo1=$("pointinfo");

        var map_width = $("map").offsetWidth,map_height = $("map").offsetHeight;
        
        if((p.x-bp.x+8 + 200)<=map_width)
            pointinfo1.style.left=(p.x-bp.x+8).toString() + "px";
        else
            pointinfo1.style.left=(p.x-bp.x-200).toString() +"px";
        if((p.y-bp.y+220) <= map_height)
            pointinfo1.style.top=(p.y-bp.y).toString() + "px";
        else
            pointinfo1.style.top = (p.y-bp.y-220).toString() + "px";
        var tmp;
        if(type == null)
        {
            tmp = tfarr[theid];
            $("tm").innerHTML = "台风名称";
            $("TFM").innerHTML = tmp[14];
            $("RQSJ").innerHTML = tmp[15];
            $("JD").innerHTML = tmp[2]+"(度)";
            $("WD").innerHTML = tmp[3]+"(度)";
            $("ZXFS").innerHTML = tmp[5]+"(米/秒)";
            $("ZXQY").innerHTML = tmp[4]+"(百帕)";
            $("YDSD").innerHTML = tmp[6]+"(公里/小时)";
            $("YDFX").innerHTML = tmp[7];
            $("RADIUS7").innerHTML = tmp[8]+"(公里)";
            $("RADIUS10").innerHTML = tmp[9]+"(公里)";
            $("FLDJ").innerHTML = tmp[11]+"级";
        }
        else
        {
            tmp = ybarr[theid];
            $("tm").innerHTML = "预报台";
            $("TFM").innerHTML = tmp[9];
            $("RQSJ").innerHTML = tmp[0];
            $("JD").innerHTML = tmp[1]+"(度)";
            $("WD").innerHTML = tmp[2]+"(度)";
            $("ZXFS").innerHTML = tmp[3]+"(米/秒)";
            $("ZXQY").innerHTML = tmp[8]+"(百帕)";
            $("YDSD").innerHTML = tmp[4];  //+"(公里/小时)"
            $("YDFX").innerHTML = tmp[5];
            $("RADIUS7").innerHTML = tmp[6];  //+"(公里)"
            $("RADIUS10").innerHTML = tmp[7]; //+"(公里)"
            $("FLDJ").innerHTML = tmp[10]+"级";
        }
        
        if (p.y>bp.y)
        {
            pointinfo1.style.display="";
        }
    }
        
function TFInfoHidden()
    {
        $("pointinfo").style.display = "none";
    }
    
function selectSiteChangeTable2(id)
{
    theselecttb2 = $("tflslftable");
    var tr = theselecttb2.childNodes[0].childNodes[theselecttb2.childNodes[0].childNodes.length-id-1];
    
    if(theselecttb2.selRow!=null)
    {
        var tmptr = theselecttb2.selRow;
        tmptr.style.backgroundColor = "";
    }
    tr.style.backgroundColor = "#3f6fd1";
    theselecttb2.selRow=tr;
}

function selectTable2Row(e)
{
    var tr,ee;
    ee=e==null?event.srcElement:e.target;
    if(ee.tagName!="TD")
        return;
    tr=ee.parentNode;
    if(dianjitb2.selRow!=null)
    {
        var tmptr = dianjitb2.selRow;
        tmptr.style.backgroundColor = "";
    }
    tr.style.backgroundColor = "#3f6fd1";
    dianjitb2.selRow=tr;
    theid = tr.theid;
    $("tsInf").style.display = "";
    window.setTimeout(SelectTFASite,3,theid);//(theid)
}

//选择了一个台风的节点,传来一个节点的位置opint = new GLatLng(y,x);
function SelectTFASite(id)
    {
        var t = tfarr[id];
        tflastpoint = t[13];
        addInfo(t[0]+"号 "+t[14],t[15],t[3],t[2],t[5],t[6],t[7],t[8],t[9],t[4],t[11]);
        mapLastPoint();
        mapDrawCir(id);
        $("tsInf").style.display = "none";
        TFYBLJXMLload(t);
    }
    
    
//路径节点画圆处理
function mapDrawCirbak2(clspoint)
		{
			//alert(clspoint);
			//alert(clspoint[8]);
			//alert(clspoint[9]);
			
			var pt = new GLatLng(clspoint[2],clspoint[3]);
			
			if (clspoint[8].toString()!="")
			{
				var polygon=drawCircle(pt, clspoint[8].toString()*1000, "#FFFF00", 1, 4,0.2);	
				map.addOverlay(polygon);			
				//clspoint.polygon7=polygon;
			}
			if (clspoint[9].toString()!="")
			{
				var polygon=drawCircle(pt, clspoint[9].toString()*1000, "#FF0000", 1, 4,0.2);				
				map.addOverlay(polygon);
				//clspoint.polygon10=polygon;
			}
		}
		
var mapcity;//城市对象		
function getcityxml()
		{
			var cityxml = new Ajax.ContentLoader("js/mapcity.xml", cityxmlload, null, null, null, null );
		}
function cityxmlload()
		{
			mapcity=[];
			var citydata=this.req.responseXML.documentElement;
			if (citydata)
			{
				var childNodes = Ajax.Dom.getChildNodes( citydata );
				var iChildNode;
				for( var i=0;i< childNodes.length;i++ )
				{
					iChildNode=childNodes[i];
					var citypoint=new classcity();
					citypoint.code=iChildNode.getAttribute( "AREA_CODE" ).toString();
					citypoint.name=iChildNode.getAttribute( "AREA_NAME" ).toString();
					citypoint.point=new GLatLng(iChildNode.getAttribute( "P_Y" )*1,iChildNode.getAttribute( "P_X" )*1);
					citypoint.zoom=iChildNode.getAttribute( "ZOOM" ).toString();
					citypoint.ok=iChildNode.getAttribute( "OK" ).toString();
					mapcity.push(citypoint);
				}
				//调用画城市处理
				//mapDrawCity();
			}
		}
		
//绘制城市
function mapDrawCity()
		{
			if (mapcity)
			{
				for(var i=0;i<mapcity.length;i++)
				{
					if (mapcity[i].zoom*1<=mapzoom)
					{
						if (!(mapcity[i].marker))
						{
							var icon=new K_IconOverlay("images/city.gif",null,1,null);
							var markerinfo=new K_HtmlMarker(icon,mapcity[i].point,'<FONT style="font-size:11px;WIDTH:100%; COLOR:#C4D4EE;">' + mapcity[i].name + '</font>');
							map.addOverlay(markerinfo);
							mapcity[i].marker=markerinfo;
						}
					}
					else
					{
						if (mapcity[i].marker)
						{
							map.removeOverlay(mapcity[i].marker);
							mapcity[i].marker=null;
						}
					}
				}
			}
		}
		
		
//删除城市
function mapDelCity()
    {
        if(mapcity)
            {
                for(var j=0;j<mapcity.length;j++)
                {
                    if (mapcity[j].marker)
						{
							map.removeOverlay(mapcity[j].marker);
							mapcity[j].marker=null;
						}
                }
                //mapcity = [];
            }
    }
    
    
function mapDistanceToLastPoint(TPoint)
    {
        if(mapcity)
            {
                var res = '<div style="position:relative;"><table border="0" width="100%" cellpadding="0" cellspacing="0" id="Table10"><tr><td colspan=4><p align=center style="margin:8;"><font color="#2e353d"><b>与各城市距离(单位:公里)</b></font></p></td></tr><tr>';
                var count = 0;
                for(var j=0;j<mapcity.length;j++)
                {
				    if (mapcity[j].ok=="1")
				    {
				        var distance=ForDight(TPoint.distanceFrom(mapcity[j].point)/1000,1);
                        //alert('两点间直线距离为：' + distance.toString() + '公里！');
                        res += '<td align="right" width="25%" height="23">'+mapcity[j].name+':&nbsp;</td>'
                            + '<td align="left" width="25%" >&nbsp;'+distance.toString()+'</td>';
                        count += 1;
                        if (count==2)
                        {
                            res += '</tr><tr>';
                            count = 0;
                        }
				    }
                }
                res += '</tr></table></div>';
                $("mapDistanceDiv").innerHTML =res;
                $("mapDistanceDiv").style.display = "";
            }
    }
