/**********************************************
 *   Base functions in YYmap
 *   author:  Dexter.Yy(http://dexteryy.blogspot.com)
 *   version:  2007.3.1 
 **********************************************/
 
 



 

 /**********************************************
 *   when onload
 **********************************************/

 window.onload=function()
 {
	init(); 
	addEvent();
	
 }
 
 window.onunload=function()
 {
 	GUnload();
 }
 
 function init()
 {
	//load google maps
	yymap.loadMap('mapinser',30.562261,110.698242,5); 

	//add a drag handle on border-bottom
	document.onmousemove = function(event)
	{
		yymap.mouse=mouseObj.getPosition(event);
	}
	
	//
	var newheight=document.body.offsetHeight-260;
	if(newheight>400)
	{
		getid("mapinser").style.height=newheight+"px";
		getid("toolbox").style.height=newheight+"px";
		getid("maplist").getElementsByTagName('UL')[0].style.height=200+(newheight-400)+"px";
	}

 
	
 }
 
 function addEvent()
 {
	 var allinput=document.body.getElementsByTagName('INPUT');
	 for(var i=0;i<allinput.length;i++)
	 {
	 	if(allinput[i].getAttribute('type')=="text")
		{
			allinput[i].onfocus=function()
			{
				this.style.background="#ffffcc";
				this.style.color="#000";
			}
			allinput[i].onblur=function()
			{
				this.style.background="#666";
				this.style.color="#fff";
			}
		}
	 }
	 var alltextarea=document.body.getElementsByTagName('TEXTAREA');
	 for(i=0;i<alltextarea.length;i++)
	 {
	 	alltextarea[i].onfocus=function()
		{
			this.style.background="#ffffcc";
			this.style.color="#000";
		}
		alltextarea[i].onblur=function()
		{
			this.style.background="#666";
			this.style.color="#fff";
		}
	 }

	
		
	 //add drag handle
	 addDragHandle("main","mapinfo");


 }
 
 /**************** init function end ******************/
 
 
 
 
 
 
 /**********************************************
 *   init function
 **********************************************/

/*      switch png<IMG> to SPAN/CSS filter when IE6 
 ********************************************************/

function alphaPNG(png)
{
	var aVersion=navigator.appVersion.split("MSIE");
	var version=parseInt(aVersion[1]);
	var pp=png.parentNode;
	
	if( (version>=5.5) && (version<7) && (document.body.filters) )
	{
		var mout=png.onmouseout.toString();
		var mover=png.onmouseover.toString();
		
		alphaHTML="<span style=\"cursor:pointer;filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='"+png.src+"');display:block;width:"+png.style.width+";height:"+png.style.height+";\" onmouseover=\""+mover.substring(mover.indexOf("{")+1,mover.lastIndexOf("}"))+"\" onmouseout=\""+mout.substring(mout.indexOf("{")+1,mout.lastIndexOf("}"))+"\" ></span>";
		png.outerHTML=alphaHTML;
	}
	
} 

 /**************** init function end ******************/











 /**********************************************
 *             YY GOOGLE MAPS API V2
 **********************************************/


var yymap={
	map:null,
	geocoder:null,
	icoimage:null,
	ban:false,
	targetMarker:null,
	targetId:null,
	targetPoint:null,
	targetIco:null,
	markerNum:0,  //ID count
	CountNum:0,
	markerCount:function(n)   //Markers count
	{  
		yymap.CountNum+=n;
		getid('showcount').innerHTML="目前有"+yymap.CountNum+"个标记";
	},  
	mapTypes:[],
	mouse:null,
	idinURL:function()
	{
		if(window.location.search!=null)
		{
			var id=getURLvalue('id');
			return id;
		} 
	},
	dbinURL:function()
	{
		if(window.location.search!=null)
		{
			var db=getURLvalue('db');
			return id;
		} 
	},

	/**************************************************      
	 *     加载地图,添加事件,
	 **************************************************/
	loadMap:function(box,startX,startY,indexZ)
	{
		if (GBrowserIsCompatible()) 
		{
	        yymap.map = new GMap2(document.getElementById(box));
	        yymap.map.setCenter(new GLatLng(startX, startY), indexZ);
			
			//添加控件,
			yymap.map.addControl(new GLargeMapControl());
			//建立地理译码
			yymap.geocoder = new GClientGeocoder();
			
			//修改地图类型,
			yymap.setTypes('hybrid');
			
   			//添加图标,
			// Download the data in db.xml and load it on the map. The format is
			// <yymapDB>
			//   <marker>
			//   	<id>数字</id>
			//   	<lat>经度</lat>
			//   	<lng>纬度</lng>
			//   	<ico>标记的源图相对路径</ico>
			//   	<author>作者</author>
			//   	<date>提交时间</date>
			//   	<email>作者的邮箱</email>
			//   	<blog>作者的主页或BLOG</blog>
			//   	<title>标题</title>
			//   	<content>内容</content>
			//   </marker>
			// </yymapDB>
			var ramnum = parseInt(100000*Math.random());
			var request = GXmlHttp.create();
			request.open("GET", "db.xml?x="+ramnum, true);
			request.onreadystatechange = function() 
			{
				if (request.readyState == 4) 
				{
					var xmldata = GXml.parse(request.responseText);
					var markers = xmldata.documentElement.getElementsByTagName("marker");
					yymap.markerNum = parseInt(markers[markers.length-1].getElementsByTagName("id")[0].firstChild.nodeValue);
					
					for (var i = 0; i < markers.length; i++) 
					{
						try{
							var urid=markers[i].getElementsByTagName("id")[0].firstChild.nodeValue;
							if(!urid)
								throw "地标加载错误";
							var urlat=markers[i].getElementsByTagName("lat")[0].firstChild.nodeValue;
							var urlng=markers[i].getElementsByTagName("lng")[0].firstChild.nodeValue;
							var urico=markers[i].getElementsByTagName("ico")[0].firstChild.nodeValue.toString();
							var urauthor=markers[i].getElementsByTagName("author")[0].firstChild.nodeValue;
							var urdate=markers[i].getElementsByTagName("date")[0].firstChild.nodeValue;
							var uremail=markers[i].getElementsByTagName("email")[0].firstChild.nodeValue;
							var urblog=markers[i].getElementsByTagName("blog")[0].firstChild.nodeValue;
							var urtitle=markers[i].getElementsByTagName("title")[0].firstChild.nodeValue.toString();
							var urcontent=markers[i].getElementsByTagName("content")[0].firstChild.nodeValue.toString();
						} catch(e) {
							continue;
						}
						
						yymap.markerCount(1);
						var point = new GLatLng( parseFloat(urlat), parseFloat(urlng) );
						
						yymap.map.addOverlay( yymap.createMarker(point, urico, urid, urauthor, urdate, uremail, urblog, urtitle, urcontent) );
						
					}

						//如果地址参数里有ID，自动弹出信息框,
						if(getid('mli'+yymap.idinURL()))
						{
							getid('mli'+yymap.idinURL()).getElementsByTagName('A')[0].onclick();
							yymap.movecenter(17);
						}

						//显示更新信息,
						//yymap.showAlert("<h2>功能更新：</h2><dl style=\"height:100px;overflow-y:auto;\"><dt>3/16/2007</dt><dd>信息框里加入“复制网址按钮</dd><dd>现在可以通过固定的独立网址，直接访问你标注的地点</dd><dt>3/14/2007</dt><dd>鼠标滑过时出现注释框，方便浏览</dd><dd>信息框里增加“关闭”按钮</dd><dd>地图高度自适应浏览器窗口，可以通过拖动地图下边框来拉大地图</dd><dt>3/13/2007</dt><dd>加入中国县地级的地名搜索功能</dd></dl>");
					

					getid("ajaxloading").style.display="none";
				}
				else
				{
					yymap.ajaxloading("ajaxloading");
				}
			}
			request.send(null);
			
	        
			//事件,地图移动后,
			GEvent.addListener(yymap.map, "moveend", function() 
			{
				yymap.showCenter("maplocation");
			});
			
			//事件,在地图上无图标的地方点击,
			GEvent.addListener(yymap.map, "click", function(marker, point) 
			{
			    yymap.whenClickMap(marker,point);
			  
			});
			
	    }
		else
		{
			if(document.getElementById("noscript"))
			{
				var alert=document.getElementById("noscript").cloneNode();
				alert.style.display="";
				document.body.insertBefore(alert);
			}
			
		}
	},
	

	/**************************************************      
	 *     修改地图类型,
	 **************************************************/
	setTypes:function(str)
	{
		var mapTypes=yymap.map.getMapTypes();
		switch (str)
		{
			case "map":
				yymap.map.setMapType(mapTypes[0]);
				break;
			case "satellite":
				yymap.map.setMapType(mapTypes[1]);
				break;
			case "hybrid":
				yymap.map.setMapType(mapTypes[2]);
				break;
		}
	},
						
	/**************************************************      
	 *     设置图标的基础属性,
	 **************************************************/
	baseIcon:function()
	{
		var icon = new GIcon();
		icon.shadow = "images/marker1shadow.png";
		icon.iconSize = new GSize(29, 34);
		icon.shadowSize = new GSize(43, 33);
		icon.iconAnchor = new GPoint(9, 34);
		icon.infoWindowAnchor = new GPoint(9, 2);
		icon.infoShadowAnchor = new GPoint(18, 25);
		return icon;
	},
	
	/**************************************************      
	 *     获取地图中心,
	 **************************************************/
	boxcenter:function()
	{
		var center=yymap.map.getCenter();
		return center;
	},

	/**************************************************      
	 *     显示中心坐标,
	 **************************************************/
	showCenter:function(where)
	{
		if(getid(where))
		{
			var getzoom=yymap.map.getZoom();
			getid(where).getElementsByTagName('INPUT')[0].value = yymap.boxcenter().lat().toString();
			getid(where).getElementsByTagName('INPUT')[1].value = yymap.boxcenter().lng().toString();
			getid(where).getElementsByTagName('INPUT')[2].value = getzoom.toString();
		} 
	},
	

	/**************************************************      
	 *     移动地图中心,
	 **************************************************/
	movecenter:function()
	{
		
		if(arguments.length==0)
		{
			var box=getid("maplocation");
			var lat=box.getElementsByTagName('INPUT')[0].value;
			var lng=box.getElementsByTagName('INPUT')[1].value;
			var indexZ=parseInt(box.getElementsByTagName('INPUT')[2].value);
			if(lat!="" && lng!="" && indexZ!="")yymap.map.setCenter(new GLatLng(lat, lng), indexZ);
		}
		else if(arguments.length==1)
		{
			var marker=yymap.targetMarker;
			var point=marker.getPoint();
			var indexZ=parseInt(arguments[0]);
			yymap.map.setCenter(point, indexZ);
		}
		else if(arguments.length==3)
		{
			var lat=arguments[0];
			var lng=arguments[1];
			var indexZ=arguments[2];
			yymap.map.setCenter(new GLatLng(lat, lng), indexZ);
		}
	},
	

	/**************************************************      
	 *     从searchdb.kml里搜索地区,
	 **************************************************/
	searchCity:function()
	{
		var address=arguments[0];
		var ajaxvalue="search="+address;
		
		var ajaxsubmit=function()
		{
			var req=arguments[0].responseText;
			if( req=="" )
			{
				
				if (yymap.geocoder) 
				{
					yymap.geocoder.getLatLng
					(
						address,
						function(point) 
						{
							if (!point) 
							{
							  yymap.showAlert("抱歉～～搜索不到结果！");
							} 
							else 
							{
							  yymap.map.setCenter(point, 13);
							  var addmarker = new GMarker(point);
							  yymap.map.addOverlay(addmarker);
							  addmarker.openInfoWindowHtml(address);
							}
						}
					);
				}
				else
				{
					yymap.showAlert("抱歉～～搜索不到结果！");
				}
				
				
			}
			else
			{
				var data=req.split(",");
			
				var lat=data[1];
				var lng=data[0];
				var indexZ=data[2];
				
				yymap.movecenter(lat, lng, 13);

				var addmarker = new GMarker(new GLatLng(lat, lng));
				yymap.map.addOverlay(addmarker);
				addmarker.openInfoWindowHtml(address);

			}

			getid("ajaxloading").style.display="none";
		}
		var loading=function()
		{
			yymap.ajaxloading("ajaxloading");
		}

		var obj = new Ajax(ajaxsubmit,loading);
		obj.process("php/search.php",ajaxvalue,"POST");
	},
	
	
	/**************************************************      
	 *       创建图标,
	 **************************************************/
	createMarker:function()       
	{
		var icon = new GIcon(yymap.baseIcon());
		
		//手工添加图标,
		if(arguments.length==1)
		{
			var point=arguments[0];
			icon.image = yymap.icoimage; //"images/marker1.png"
			
			var marker = new GMarker(point,icon);
			yymap.targetMarker=marker;
			yymap.targetPoint=point;
			yymap.targetIco=icon.image;
			yymap.markerCount(1);
		}
		
		//从XML加载图标,
		else if(arguments.length==9) //point, urico, urid, urauthor, urdate, uremail, urblog, urtitle, urcontent
		{
			var point= arguments[0];
			icon.image = arguments[1];
			var urtitle=arguments[7];
			var urauthor=arguments[3];
			var urdate=arguments[4];

			var marker = new GMarker(point,icon);                                                                        
			var info=yymap.markerInfo(arguments[2],arguments[3],arguments[4],arguments[5],arguments[6],arguments[7],arguments[8]);
			
			
			GEvent.addListener(marker, "click", function() 
			{
			  yymap.whenClickMarker(marker,info,point,icon.image);
			});

			GEvent.addListener(marker, "mouseover", function() 
			{
			  yymap.whenOverMarker(urtitle,urauthor,urdate);
			});
			GEvent.addListener(marker, "mouseout", function() 
			{
			  getid('mouseoverbox').style.display="none";
			});

			//加载地点列表,
			var newli=document.createElement('LI');
			var list=getid("maplist").getElementsByTagName('UL')[0];
			newli.innerHTML="<a href=\"#\"><span class=\"arrow\"></span>"+arguments[7]+"</a><em style=\"font-weight:600;\">"+arguments[3]+"</em><em>更新于"+arguments[4]+"</em>";
			newli.setAttribute('id','mli'+arguments[2]);
			list.insertBefore(newli,list.getElementsByTagName('LI')[0]);
			newli.getElementsByTagName('A')[0].onclick=function() 
			{
			  yymap.whenClickMarker(marker,info,point,icon.image);
			  return false;
			}
			
		}  
		
		return marker;
	},
	
	/**************************************************      
	 *       获取图标的信息,
	 **************************************************/
	markerInfo:function()
	{
		if(arguments.length==0)
		{
		    var urtext="<div class=\"markerbox\"><h3>新的标记</h3><p>很好!你在地图上创建了一个新标记,但它还没有保存到数据库里.</p><p>如果你确认这个标记的位置没有错,请在表单里填写相关的信息,然后保存</p></div>";
            return urtext; 
		}
		if(arguments.length==7)
		{
			var urid=arguments[0];
			var urauthor=arguments[1];
			var urdate=arguments[2];
			var uremail=arguments[3];
			var urblog=arguments[4];
			var urtitle=arguments[5];
			//var urcontent=replaceHTML(arguments[6]);
			var newinput=document.getElementById("hiddencontent");
			newinput.innerHTML="<input id='hiddenvalue' type='hidden' value='"+arguments[6]+"' />";
			var urcontent=document.getElementById('hiddenvalue').value;

			var urtext="<div id=\"mapboxWin\" mid=\""+urid+"\" class=\"markerbox\"><h3>"+urtitle+"</h3><div class=\"button\"><input type=\"button\" value=\"关闭\" onclick=\"yymap.map.closeInfoWindow();\" /><input type=\"button\" value=\"放大\" onclick=\"yymap.movecenter(17);\" /><input type=\"button\" value=\"编辑\" onclick=\"yymap.showForm('"+encodeURIComponent(urtitle)+"','"+encodeURIComponent(urauthor)+"','"+uremail+"','"+urblog+"','"+encodeURIComponent(urcontent)+"',"+urid+");\" /><a class=\"button\" href=\"#\" onclick=\"this.getElementsByTagName('DIV')[0].style.display='';this.style.background='#ccc';return false;\" ><div class=\"URLbox\" style=\"display:none;\" ><input type=\"text\" size=\"100\" class=\"text\" onfocus=\"this.select();\" onblur=\"this.parentNode.style.display='none';this.parentNode.parentNode.style.background='#000';\" value=\""+window.location.protocol+window.location.hostname+window.location.pathname+"?id="+urid+"\"  /></div><span>复制网址</span></a></div><div class=\"markerHead\"><span class=\"head\">发布者:</span><span><a href=\""+urblog+"\">"+urauthor+"</a></span><span class=\"head\">联系方式:</span><span><a href=\"mailto:"+uremail+"\">"+uremail+"</a></span><span class=\"head\">更新日期:</span><span>"+urdate+"</span></div><div class=\"markerContent\">"+urcontent+"</div></div>";
		    return urtext;
		}
	},
	
	
	/**************************************************      
	 *       全地图点击事件,
	 **************************************************/
	whenClickMap:function(marker,point)
	{
		if (!marker) 
		{
			if(yymap.ban!=true)
			{
				if(yymap.icoimage!=null )
				{
					yymap.map.addOverlay( yymap.createMarker(point) );
					
					var marker=yymap.targetMarker;
					var info=yymap.markerInfo();
					yymap.showInfoWin(marker,info);
					
					yymap.showForm();
				}
				else
				{
					yymap.showAlert("要在地图上创建标记,你首先必须选择一种图标.");
				}
			}    
			else
			{
				yymap.showAlert("你添加了一个新标记,保存或取消后才能进行其他操作.");
			}
				
		}
	},
	

	/**************************************************      
	 *       图标点击事件,
	 **************************************************/
	whenClickMarker:function(marker,info,point,ico)
	{
		if(yymap.ban!=true)
		{
			yymap.showInfoWin(marker,info);
		    yymap.targetMarker=marker;
			yymap.targetPoint=point;
			yymap.targetIco=ico;
		}
		else
		{
			yymap.showAlert("你添加了一个新标记,保存或取消后才能进行其他操作.");
		}
	},

	/**************************************************      
	 *       鼠标滑过图标事件
	 **************************************************/
	whenOverMarker:function()
	{
		if(arguments.length==3)
		{
			getid("mouseoverbox").innerHTML="<h3>"+arguments[0]+"</h3><p><span class=\"author\">"+arguments[1]+"</span>更新于<span class=\"date\">"+arguments[2]+"</span></p>";
			getid("mouseoverbox").style.top=yymap.mouse.t+"px";
			getid("mouseoverbox").style.left=yymap.mouse.l+"px";
			getid("mouseoverbox").style.display="";
		}
		else if(arguments.length==1)
		{
			getid("mouseoverbox").innerHTML="<p>"+arguments[0]+"</p>";
			getid("mouseoverbox").style.top=yymap.mouse.t+"px";
			getid("mouseoverbox").style.left=yymap.mouse.l+"px";
			getid("mouseoverbox").style.display="";		
		}
		
	},
	
	/**************************************************      
	 *       显示表单,
	 **************************************************/
	showForm:function()
	{
		//保存之前禁止所有地图事件,
		yymap.ban=true;
		
		//编辑已存在的标记,
		if(arguments.length==6)
		{
			yymap.targetId=arguments[5];
			
			getid('formpoint').value=yymap.targetPoint;
			getid('formico').value=yymap.targetIco;
			
			getid('formtitle').value=decodeURIComponent(arguments[0]);
			getid('formauthor').value=decodeURIComponent(arguments[1]);			
			getid('formemail').value=arguments[2];
			getid('formblog').value=arguments[3];
			tinyMCE.setContent(decodeURIComponent(arguments[4])); //getid('formcontent').value=arguments[4];
			
			getid("button2").value="删除";
			getid("button3").style.display="";
		}
		//添加新标记,
		else if(arguments.length==0)
		{
			yymap.markerNum++;
			
			getid('formpoint').value=yymap.targetPoint;
			getid('formico').value=yymap.targetIco;
			
			getid('formtitle').value="标题";
			getid('formauthor').value="你的名字";			
			getid('formemail').value="你的Email";
			getid('formblog').value="http://你的Blog或个人网站";
			tinyMCE.setContent("在这里填一段简介"); //getid('formcontent').value="在这里填一段简介";
			getid("button3").style.display="none";
			getid("button2").value="取消";
		}
		var showbox=new transform(getid('markeredit'),"style.right",-20,-260,30);
		showbox.cast();
	},
	

	/**************************************************      
	 *       提交表单信息,显示信息框,
	 **************************************************/
	submitMarker:function()
	{
		if(yymap.targetMarker==null)return false;
		var marker=yymap.targetMarker;
		
		if(yymap.targetId!=null)
		{
			var urid=yymap.targetId; //编辑状态
		}
		else
		{
			var urid=yymap.markerNum; //添加状态
		}
		
		var urpoint=getid('formpoint').value;
		var urico=getid('formico').value;
			
			
		var urauthor=getid('formauthor').value;
		
		var time = new Date( ); 
		var urdate=time.toLocaleDateString().toString()+time.toLocaleTimeString().toString();
		
		var uremail=getid('formemail').value;
		var urblog=getid('formblog').value;
		var urtitle=getid('formtitle').value;
		var urcontent=tinyMCE.getContent(); //getid('formcontent').value;
		
		//验证表单内容,
		if(!isemail(uremail) && uremail!="#")
		{
			yymap.showAlert("email地址错误");
			return false;
		}	
		else
		{
			var info=yymap.markerInfo(urid,urauthor,urdate,uremail,urblog,urtitle,urcontent);
			yymap.showInfoWin(marker,info);
			
			//ajax提交,
			var ajaxvalue="id="+urid+"&point="+urpoint+"&ico="+urico+"&author="+encodeURIComponent(urauthor)+"&date="+urdate+"&email="+uremail+"&blog="+encodeURIComponent(urblog)+"&title="+encodeURIComponent(urtitle)+"&content="+encodeURIComponent(urcontent);
			var ajaxsubmit=function(reg,value)
			{
				//alert(reg.responseText);
				yymap.ajaxsubmitdone("ajaxloading",marker,info,urpoint,urico,urid,urtitle,urauthor,urdate);
			}
			var loading=function()
			{
				yymap.ajaxloading("ajaxloading");
			}
			
			var obj = new Ajax(ajaxsubmit,loading);
			if(yymap.targetId!=null)
			{
				obj.process("php/edit.php",ajaxvalue,"POST");   //编辑状态
			}
			else
			{
				obj.process("php/add.php",ajaxvalue,"POST");    //添加状态
			}
			
			
		
		}
		
	},

	/**************************************************      
	 *       AJAX提交过程中显示loading提示，
	 **************************************************/
	ajaxloading:function(ajaxloading)
	{
		getid(ajaxloading).style.display="";
	},

	/**************************************************      
	 *       AJAX提交完成后修改页面内容，
	 **************************************************/
	ajaxsubmitdone:function(ajaxloading,marker,info,urpoint,urico,urid,urtitle,urauthor,urdate)
	{
			//修改标记的信息框内容,
			GEvent.addListener(marker, "click", function() 
			{
			  yymap.whenClickMarker(marker,info,urpoint,urico);
			});
			
			//修改鼠标滑过提示,
			GEvent.addListener(marker, "mouseover", function() 
			{
			  yymap.whenOverMarker(urtitle,urauthor,urdate);
			});
			GEvent.addListener(marker, "mouseout", function() 
			{
			  getid('mouseoverbox').style.display="none";
			});
			
			//修改地点列表,
			var list=getid("maplist").getElementsByTagName('UL')[0];
			
				if(getid('mli'+urid)) //编辑状态
				{	
					var newli=getid('mli'+urid);
					newli.innerHTML="<a href=\"#\"><span class=\"arrow\"></span>"+urtitle+"</a><em style=\"font-weight:600;\">"+urauthor+"</em><em>更新于"+urdate+"</em>";
					newli.getElementsByTagName('A')[0].onclick=function() 
					{
						yymap.whenClickMarker(marker,info,urpoint,urico);
						return false;
					}
					//清空ID,
					yymap.targetId=null;
				}
				else  //添加状态
				{   
					newli=document.createElement('LI');
					newli.setAttribute('id','mli'+urid);
					newli.innerHTML="<a href=\"#\"><span class=\"arrow\"></span>"+urtitle+"</a><em style=\"font-weight:600;\">"+urauthor+"</em><em>更新于"+urdate+"</em>";
					list.insertBefore(newli,list.getElementsByTagName('LI')[0]);
					newli.getElementsByTagName('A')[0].onclick=function() 
					{
					  yymap.whenClickMarker(marker,info,urpoint,urico);
					  return false;
					}
				}
				
			
			//激活地图事件,
			yymap.ban=false;
			yymap.noIco();

			getid(ajaxloading).style.display="none";
			
			var hiddenbox=new transform(getid('markeredit'),"style.right",-260,-20,30);
		    hiddenbox.cast();	
	},


	/**************************************************      
	 *      显示信息框,
	 **************************************************/
	showInfoWin:function()
	{
		if(arguments.length==2)
		{
			var marker=arguments[0];
			var urtext=arguments[1];
			marker.openInfoWindowHtml(urtext);
		}
	},
	

	/**************************************************      
	 *      删除标记,
	 **************************************************/
	removeMarker:function()
	{
		if(yymap.targetMarker==null)return false;
		if(confirm('你确定要删除吗?'))
		{
		    var marker=yymap.targetMarker;

			if(yymap.targetId==null)    //取消添加,
			{
				yymap.ajaxremovedone("ajaxloading",marker);
			}
			else                        //ajax删除,
			{
				var ajaxvalue="id="+yymap.targetId;
				var ajaxsubmit=function(reg,value)
				{
					yymap.ajaxremovedone("ajaxloading",marker);
				}
				var loading=function()
				{
					yymap.ajaxloading("ajaxloading");
				}
				
				var obj = new Ajax(ajaxsubmit,loading);
				obj.process("php/remove.php",ajaxvalue,"POST");
			}
			
		}
				
	},

	/**************************************************   
	 *      用AJAX删除标记后修改地图内容,
	 **************************************************/
	ajaxremovedone:function(ajaxloading,marker)
	{
		yymap.map.removeOverlay(marker);
		yymap.map.closeInfoWindow();
		var hiddenbox=new transform(getid('markeredit'),"style.right",-260,-20,30);
		hiddenbox.cast();
			
			
		//修改地点列表,
		if(yymap.targetId!=null)
		{
			var list=getid("maplist").getElementsByTagName('UL')[0];
			var urid=yymap.targetId;
			if(getid('mli'+urid))
			{
				var newli=getid('mli'+urid);
				list.removeChild(newli);
			}
			//清空ID,
			yymap.targetId=null;
		}

		getid(ajaxloading).style.display="none";
		
		yymap.markerCount(-1);

		//激活地图事件,
		yymap.ban=false;
		yymap.targetMarker=null;
		yymap.noIco();
	},


	/**************************************************      
	 *      取消编辑,
	 **************************************************/
	noEdit:function()
	{
		var hiddenbox=new transform(getid('markeredit'),"style.right",-260,-20,30);
		hiddenbox.cast();
		
		//清空ID,
		yymap.targetId=null;
		
		//激活地图事件,
		yymap.ban=false;
		
	},

	/**************************************************     
	 *     取消选择图标,
	 **************************************************/
	noIco:function()
	{
		yymap.icoimage=null;
		var ico=getid('icoList').getElementsByTagName('A');
		for(var i=0;i<getid('icoList').getElementsByTagName('A').length;i++)
		{
			ico[i].style.border="none";
		}
		
	},
	
	/***************************      
	 *     提示信息,
	 ***************************/
	showAlert:function(str)
	{
		if(getid('mapalert'))
		{
			getid('mapalert').getElementsByTagName('DIV')[0].getElementsByTagName('SPAN')[0].innerHTML = str;
			var show=new transform(getid('mapalert'),"style.marginTop",0,-165,30);
		    show.cast();
			getid('mapalert').getElementsByTagName('INPUT')[0].focus();
		}
	}
}


 /**********************************************
 *             YY GOOGLE MAPS API V2 END
 **********************************************/










 /**********************************************
 *   event function
 **********************************************/

var curIco=null;
function chooseImg(img,src)
{
	yymap.icoimage="images/"+img+".png";
	src.style.border="2px solid #ccc";
	if(curIco!=null && curIco!=src)
	{
		curIco.style.border="";
		curIco=src;
		src.blur();
	}
	else
	{
		curIco=src;
	}
	
}

function hiddenList(src)
{
	var list=src.parentNode.getElementsByTagName('UL')[0];
	if(list.style.height=="200px")
	{
		var hidden=new transform(list,"style.height",0,200,20);
		hidden.cast();
	}
	else if(list.style.height=="0px")
	{
		var hidden=new transform(list,"style.height",200,0,20);
		hidden.cast();
	}
}



var moveLeft;
function moveTagBar(str,forwar)

{
	var bar=str.parentNode.getElementsByTagName('DIV')[0].getElementsByTagName('DIV')[0];
	var l=parseInt(bar.style.marginLeft);
	var tl=0;
	var barw=str.parentNode.getElementsByTagName('DIV')[0].offsetWidth;

	for(var i=0;i<bar.getElementsByTagName('A').length;i++)
	{
		var w=bar.getElementsByTagName('A')[i].offsetWidth;
		var tl=tl+w+22;
	}

    if(forwar=="right")
	{
		if(Math.abs(parseInt(l))<tl-barw)

		{
			str.style.borderLeft="10px solid #ff6600";
			bar.style.marginLeft=parseInt(bar.style.marginLeft)-14+"px";
			moveLeft=setTimeout(function(){moveTagBar(str,forwar)},60);
		}else{
			str.style.borderLeft="10px solid #333";
		}
	}

	else if(forwar=="left")
	{
		if(parseInt(l)<0)
		{
			str.style.borderRight="10px solid #ff6600";
			bar.style.marginLeft=parseInt(bar.style.marginLeft)+14+"px";
			moveLeft=setTimeout(function(){moveTagBar(str,forwar)},60);
		}else{
			str.style.borderRight="10px solid #333";
		}

	}
}

function stopTagBar(str,forwar)
{
	if(forwar=="right")
	{
		str.style.borderLeft="10px solid #333";
	}
	else if(forwar=="left")
	{
		str.style.borderRight="10px solid #333";
	}
	if(moveLeft)clearTimeout(moveLeft);
}







/**********************************************
 *   Drag the border!
 **********************************************/
function addDragHandle(out,before)
{
	 var draghandle=document.createElement('A');
	 draghandle.setAttribute('id','draghandle');
	 draghandle.setAttribute('href','#');
	 draghandle.onmouseover=function()
	 {
		yymap.whenOverMarker('<strong style=\'color:#ffcc00\'>点击这里可以拉大地图的下边框喔！</strong>');
	 }
	 draghandle.onmouseout=function()
	 {
		getid('mouseoverbox').style.display='none';
	 }
	 draghandle.onclick=drag.startDragVborder;
	 getid(out).insertBefore(draghandle,getid(before));
}

var drag={

	target:function()
	{
		var obj=getid('draghandle');
		return obj;
	},

	dragGo:null,
	dragEnd:null,
    H1:0,
	H2:0,

	dragRange:function()

	{

		var range=0;

		if(drag.dragEnd!=null && drag.dragGo!=null) range=drag.dragEnd-drag.dragGo;

		return range;

	},

	startDragVborder:function()

	{
		var target=drag.target();
		target.style.background="#ff6600";

		drag.dragGo=yymap.mouse.t

		drag.H1=parseInt(getid("mapinser").style.height);
		drag.H2=parseInt(getid("maplist").getElementsByTagName('UL')[0].style.height);
		
		document.body.style.cursor="n-resize";
		document.body.onmousemove=drag.goDragVborder;
		document.body.onmouseup=drag.stopDragVborder;
        target.onclick=function(){return false;}

		return false;
	},

	stopDragVborder:function()

	{
		var target=drag.target();
		target.style.background="#666";

        drag.dragEnd=yymap.mouse.t;

		getid("mapinser").style.height=drag.getChange(drag.H1,400)+"px";
		getid("toolbox").style.height=drag.getChange(drag.H1,400)+"px";
		getid("maplist").getElementsByTagName('UL')[0].style.height=drag.getChange(drag.H2,200)+"px";

		getid("mouseoverbox").style.display="none";
		document.body.style.cursor="";
		document.body.onmousemove=null;
		document.body.onmouseup=null;
		setTimeout(function(){target.onclick=drag.startDragVborder;},100);
	},

	goDragVborder:function()

	{

	    drag.dragEnd=yymap.mouse.t;

		getid("mapinser").style.height=drag.getChange(drag.H1,400)+"px";
		getid("toolbox").style.height=drag.getChange(drag.H1,400)+"px";
		getid("maplist").getElementsByTagName('UL')[0].style.height=drag.getChange(drag.H2,200)+"px";

	},
	
	getChange:function(h,min)
	{
		var r=h+drag.dragRange();
		if(r<min)
		{
			r=min;
			yymap.whenOverMarker('<strong style=\'color:#ffcc00\'>已经达到最小高度，不能再拖了！</strong>');
				//drag.stopDragVborder();
		}
		return r;
	}

}
/**********************************************
 *   Drag the border! (end)
 **********************************************/




 
 /**************** event function end ******************/








 
 
 /**********************************************
 *   base function
 **********************************************/
function getid(id)
{
	return document.getElementById(id);
} 


function  replaceHTML(str)
{   
	//str=str.replace(/\&/g,"");
	str=str.replace(/\'/g,"&#039;");
	str=str.replace(/\"/g,"&quot;");

	return str;   
}   
function  unreplaceHTML(str)
{   
	//str=str.replace(/\&/g,"&amp;");
	str=str.replace(/\&#039;/g,"\\'");
	//str=str.replace(/\&quot;/g,"\"");
	//str=str.replace(/\<br/>/g,"\\n"); 
	str=str.replace(/\&gt;/g,">");
	str=str.replace(/\&lt;/g,"<"); 

	return str;   
}  

/*                   get mouse event 
 ********************************************************/

var mouseObj={
	"getPosition":function(ev){
		ev=ev||window.event;
		//alert(document.documentElement.scrollTop);
		if(ev.pageX || ev.pageY)
	    {
			return {l:ev.pageX,t:ev.pageY};
	    }
	    else
	    {
		    return {l:ev.clientX+document.documentElement.scrollLeft,t:ev.clientY+document.documentElement.scrollTop};
	    }
	},
	"getTarget":function(ev){
		ev=ev||window.event;
		if(typeof ev != undefined)
		{
			evt=ev.target||ev.srcElement;
		    return evt;
		}
		else
		{
			return null;
		}
	}
}


/*             get value from URL
 ******************************************************************/
function getURLvalue(key) 
{
        var href = window.location.search;
        var lhref = href.toLowerCase();

        var pos = lhref.indexOf( key + "=" );
        if (pos==-1) return null;

        var next = lhref.indexOf( "&", pos );
        var value = href.substring( pos + key.length + 1, (next==-1) ? 999 : next );

        return value;
}


/*          form check
 ******************************************************************/
 
function isemail(str)
{
	var result=str.match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/);
	if(result==null) return false;
	return true;
}



 /**************** base function end ******************/

 
 
 
 
 
 
 
 
/**********************************************
 *   class
 **********************************************/
 
 /*          zoom class 
 ********************************************************/

function animeZoom(ico,gWidth,gHeight,nWidth,nHeight)
{
	this.png=ico;
	this.iheight=nHeight;
	this.iWidth=nWidth;
	this.goWidth=gWidth;
	this.goHeight=gHeight;
	this.rico;
}

animeZoom.prototype.zoomEvent=function()
{
	if(this.iWidth<this.goWidth)
	{
		this.goEnlarge();
	}
	else if(this.iWidth>this.goWidth)
	{
		this.goReduce();
	}

}

animeZoom.prototype.goEnlarge=function()
{
	this.png.style.width=this.goWidth+"px";
	this.png.style.height=this.goWidth+"px";
}

animeZoom.prototype.goReduce=function()
{
	var obj=this;
	var h=parseInt(this.png.style.height);
	var w=parseInt(this.png.style.width);
	if(w>this.goWidth)
	{
		this.png.style.width=w-2+"px";
		this.png.style.height=h-2+"px";
		this.rico=setTimeout(function(){obj.goReduce();},30);
	}else{
		//this.png.style.width=this.goWidth+"px";
		//this.png.style.height=this.goheight+"px";
		window.clearTimeout(this.rico);
	}
}


 /*          linear anime class 
 ********************************************************/

function transform()
{
	if(arguments.length==8) //two css property
	{
		this.i=arguments[0];
	    this.cssName1=arguments[1];
	    this.cssName2=arguments[2];
	    this.gValue1=arguments[3];
	    this.gValue2=arguments[4];
	    this.iValue1=arguments[5];
	    this.iValue2=arguments[6];
	    this.speed=arguments[7];
	    this.eico;
	    this.rico;
	}
	else if(arguments.length==5) //one css property
	{
		this.i=arguments[0];
	    this.cssName1=arguments[1];
	    this.gValue1=arguments[2];
	    this.iValue1=arguments[3];
	    this.speed=arguments[4];
	    this.eico;
	    this.rico;
		
	}
	
}

transform.prototype.cast=function()
{
	if(this.iValue1<this.gValue1)
	{
		this.goEnlarge();
	}
	else if(this.iValue1>this.gValue1)
	{
		this.goReduce();
	}

}


transform.prototype.goEnlarge=function()
{
	var obj=this;
	var h=eval('this.i.'+this.cssName1);
	if(this.cssName2!=undefined)var w=eval('this.i.'+this.cssName2);
	
	if(parseInt(h)<this.gValue1)
	{
		
		eval('this.i.'+this.cssName1+'=parseInt(h)+this.speed+"px"');
		if(this.cssName2!=undefined)eval('this.i.'+this.cssName2+'=parseInt(w)+this.speed+"px"');

		this.eico=setTimeout(function(){obj.goEnlarge();},40);
	}else{
		eval('this.i.'+this.cssName1+'=this.gValue1+"px"');
		if(this.cssName2!=undefined)eval('this.i.'+this.cssName2+'=this.gValue2+"px"');
		window.clearTimeout(this.eico);
	}
}
transform.prototype.goReduce=function()
{
	var obj=this;
	var h=eval('this.i.'+this.cssName1);
	if(this.cssName2!=undefined)var w=eval('this.i.'+this.cssName2);
	
	if(parseInt(h)>this.gValue1)
	{
		eval('this.i.'+this.cssName1+'=parseInt(h)-this.speed+"px"');
		if(this.cssName2!=undefined)eval('this.i.'-this.cssName2+'=parseInt(w)+this.speed+"px"');

		this.rico=setTimeout(function(){obj.goReduce();},40);
	}else{
		eval('this.i.'+this.cssName1+'=this.gValue1+"px"');
		if(this.cssName2!=undefined)eval('this.i.'+this.cssName2+'=this.gValue2+"px"');
		window.clearTimeout(this.rico);
	}
}
 /*          linear anime class  end
 ********************************************************/	 
	 
	 

 /*               Ajax 
 ********************************************************/
 
function getRequester()
{
  try
  {
      if(window.XMLHttpRequest) 
      {
          return new XMLHttpRequest();
      } 
      else if(window.ActiveXObject)
      {
         try 
         {
               return new ActiveXObject("Microsoft.XMLHTTP");
         } catch (e) 
         {
               try {
                    return new ActiveXObject("Msxml2.XMLHTTP");
               } catch (e) {return false;}
         }          
      }
  }
  catch (e) 
  {
	  
      alert("You need a browser which supports an XMLHttpRequest Object.\nMozilla build 0.9.5 has this Object and IE5 and above.");
	  return false;
  }
}


function Ajax(cb,loads)
{
  
  var me = this;
  this.requester = getRequester();
  
  if(cb)
  {
	
    this.callback = cb;
  }
  else
    this.callback = function(req)
    {
      return eval(req.responseText);
    }
  if(loads)
    this.Loads = loads;
  else
    this.Loads = function(readyState)
    {
      return readyState;
    }

  this.requester.onreadystatechange = function(){
	  //alert(me.requester.readyState);
    switch(me.requester.readyState)
    {
      case 1:
	     me.Loads(me.requester.readyState);
		 break;
      case 2:
      case 3:
	    
        break;
      case 4:
	    
	    if(me.requester.status == 200)
		{
			 var response = me.callback(me.requester,me.value);
		}
        break;
      default:
        alert("Error");
        break;
    }
  }

  this.state = function()
  {
    return me.requester.readyState;
  }

  this.process = function(url, parameters,method){
	//alert(url);
	if(method=="POST")
	{
		me.requester.open("POST", url, true);
	    me.requester.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	    //me.requester.setRequestHeader("Content-type", "text/html; charset=GB2312");
        me.requester.setRequestHeader("Content-length", parameters.length);
        me.requester.setRequestHeader("Connection", "close");
        me.requester.send(parameters);
	    me.value = parameters;
	}
	else
	{
		url = url+"?"+parameters;
		//alert(url);
		me.requester.open("GET", url, true);
		me.requester.send(null);
	    me.value = parameters;
	}
	
  }
}

	 
 /*              Ajax   end
 ********************************************************/



 
 /**************** class end ***************************/