	/*var tId='';
function newHandler(){
	var add=getEleVal(markerAddress);
	var name=getEleVal(markerName);
	aj_reastaurantNameCheck(add,name);// check address and name if already existed
}
function check_address(){
	var add=document.restauForm.markerAddress.value;
	var name=document.restauForm.markerName.value;
	
	if(checkField()){
		aj_reastaurantNameCheck(add,name);//address, name check if already exists
		aj_reastaurantNameCheck(add,name);//address, name check if already exists
	} // 檢查欄位
}
function checkLatLng(){
	if( document.restauForm.lat.value=='' || document.restauForm.lng.value=='' )
		return false;
	return true;
}
function checkField(){
	var form=document.restauForm;
	if(!isValid(form.markerAddress.value)){
		alert('住址欄位尚未填寫噢');
		return false;
	}
	if(!isValid(form.markerName.value)){
		alert('店家名稱尚未填寫噢');
		return false;
	}
	return true;
}
function isValid(check){
	if( check=='' || typeof(check)=='undefined' || check==null )
		return false;
	return true;
}
function aj_reastaurantNameCheck(markerAddress,markerName) {
	var xmlHttp=new createHttpRequest();
	var lng=document.restauForm.lng.value;
	var lat=document.restauForm.lat.value;
	var url = "address_check.php?address="+markerAddress+"&name="+markerName+"&lng="+lng+"&lat="+lat;
	
	document.getElementById('ln').value=url;
	 xmlHttp.open("GET", url, true);
	 xmlHttp.onreadystatechange = function reply_reastaurantNameCheck(){
		if (xmlHttp.readyState == 4 && xmlHttp.status==200  ) {
			var response = xmlHttp.responseText;
			var checkResult=eval('(' +response+ ')');
			if(checkResult!=null && checkResult!=''){	//已經有人新增	
				createInvDiv(checkResult);  //放入不可見的div
				showAlreadyExist();	//show 是否要以此新增
			}
			else{　//無人新增過	
				showCreateWay();  //show 新增方式
			}
		}
	  }	//end of reply  function函數不可加()
	  xmlHttp.send(null);
}

function inputAlreadyInfo(){
		if(isValid(document.getElementById('inv0').value))
			document.restauForm.rId.value=document.getElementById('inv0').value; //name
		if(isValid(document.getElementById('inv1').value))
			document.restauForm.markerName.value=document.getElementById('inv1').value; //name
		if(isValid(document.getElementById('inv2').value))
			document.restauForm.markerAddress.value=document.getElementById('inv2').value; //add
		if(isValid(document.getElementById('inv3').value))
			document.restauForm.markerPhone.value=document.getElementById('inv3').value; //rPhone
		if(isValid(document.getElementById('inv4').value))
			document.restauForm.markerWeb.value=document.getElementById('inv4').value; //rWeb
}
*/

function drag(){
	
//	var map = new GMap2(document.getElementById("map_canvas"));
//var center = new GLatLng(39.917, 116.397);
//map.setCenter(center, 14);

//var marker = new GMarker(center, {draggable: true});

GEvent.addListener(marker, "dragstart", function() {
  map.closeInfoWindow();
  //map.clearOverlays();
  });

GEvent.addListener(marker, "dragend", function() {
  var p=marker.getLatLng();
  dragByLngLat(p.y,p.x)
 //alert(p.x);
  });

//map.addOverlay(marker);
}

function toPosition(address){
	if($('#addFie').val()!='')
		doPosition(address);
}//end of function
function doPosition(address){
		var re_add=address;	
		geocoder.getLatLng(re_add,function(point) 
				{  	
					if (point) { 
						positionByLngLat(address,point.y,point.x);//定位 y=lat ,x =l
						show_repAdd('#000000',"");
						document.getElementById('la').value=point.y;
						document.getElementById('ln').value=point.x;
						drag();
					} 	
					else{
						putLatLng('','');	
						show_repAdd('#FF0000',"抱歉，無法定位噢! 可試試拖曳座標定位>.^");
						var point=new GLatLng(22.626083, 120.265768);
		map.setCenter(point, 14);
		map.addControl(new GSmallMapControl());
	    map.addControl(new GMapTypeControl());
		marker=new GMarker(point,{draggable: true});
		drag();
		map.addOverlay(marker);
						
					}
				} //end of function (  point)
		);
		map.clearOverlays();
	}
	
function show_repAdd(col,textHtml){
	document.getElementById('replyAddCheck').style.color=col;
	document.getElementById('replyAddCheck').innerHTML=textHtml;
}

function revise_address(address){
			if(address.indexOf('樓')!=-1){
				address=address.substring(0,address.lastIndexOf('號')+1);	//去掉樓
			}
			if(address.indexOf('F')!=-1){
				address=address.substring(0,address.lastIndexOf('F')+1);	//去掉F
			}
			if(address.indexOf('f')!=-1){
				address=address.substring(0,address.lastIndexOf('f')+1);	//去掉f
			}
			if(address.indexOf('-')!=-1){
				var index=address.indexOf('-');//50-1號  0的index
				address=address.substring(0,index)+'號';
			}
			else if(address.indexOf('之')!=-1){
				var index=address.indexOf('之');//50-1號  0的index
				address=address.substring(0,index)+'號';
			}
			return address;
	}
function needDbCheck(address){
		var addTailIndex=address.length-1;
		//var nameEvent=document.addRestaurant.markerName.event.type;
		if( (address.indexOf('號')!=-1) ||
			( address.charAt(addTailIndex)=="街" || address.charAt(addTailIndex)=="路"
			  ||address.charAt(addTailIndex)=="段"||address.charAt(addTailIndex)=="號"
			  ||address.charAt(addTailIndex)=="巷"||address.charAt(addTailIndex)=="市"||address.charAt(addTailIndex)=="縣"  ))
		  {
			return true;
		  }
		return false;  
	}
function positionByLngLat(address,lat,lng){
		var point=new GLatLng(lat,lng);
		
		putLatLng(lat,lng);
		map.setCenter(point,14);
	marker=new GMarker(point,{draggable: true});
	/*	 var icon=new GIcon();   
    icon.image="http://140.117.71.186/map/Icons/iconb.png";   
    //icon.iconSize = new GSize(10,10);   
    icon.iconAnchor = new GPoint(10,35);   
    icon.infoWindowAnchor = new GPoint(20, 20);  
	marker=new GMarker(point,{icon:icon});*/
		map.addOverlay(marker);
		var re_add=revise_address(address);
		if(re_add.indexOf(address)==-1){
			var here="<h3 style='color:#C0c0c0'>地圖上大約的位置 :</h3><br>"+re_add;
		}
		else{
			var here="<h3 style='color:#000000'>您所輸入的地址 : </h3><br>"+address;
		}
		GEvent.addListener(marker, "click", function(){
			marker.openInfoWindowHtml(here);
		});
			marker.openInfoWindowHtml(here);
}

function dragByLngLat(lat,lng){
	map.clearOverlays();
	show_repAdd('#000000',"");
		var point=new GLatLng(lat,lng);
		
		putLatLng(lat,lng);
		map.setCenter(point,14);
	//marker=new GMarker(point,{draggable: true});
	/*	 var icon=new GIcon();   
    icon.image="http://140.117.71.186/map/Icons/iconb.png";   
    //icon.iconSize = new GSize(10,10);   
    icon.iconAnchor = new GPoint(10,35);   
    icon.infoWindowAnchor = new GPoint(20, 20);  
	marker=new GMarker(point,{icon:icon});*/
		map.addOverlay(marker);
		
		
			var here="<h2>地圖上大約的位置^.<</h2>";
		
		
		GEvent.addListener(marker, "click", function(){
			marker.openInfoWindowHtml(here);
		});
			marker.openInfoWindowHtml(here);
		//alert(document.restauForm.lng.value);
}
function putLatLng(lat,lng){
	document.restauForm.lat.value=lat;
	document.restauForm.lng.value=lng;
}
/*
function getCreateWay(){
	var cWay=document.restauForm.createWay.value;
	if(cWay=='create'){
		return "add_activity_action.php";
	}	
	else if(cWay=='update'){
		return "update_restau.php";
	}
}
function exCreateWay(way){
	document.restauForm.createWay.value=way;
}
function showNewRestau(){
	var newMes="請填寫餐廳資訊";
	var newRbut="確定";
	var newLbut="重填";
	var rButton=document.createElement('input');
	var lButton=document.createElement('input');
	var cBox=document.createElement('span');
		cBox=document.createTextNode(newMes);
	rButton.onclick=function (){ 
		check_address();
	}
	rButton.type="button";
	lButton.type="reset";
	lButton.value=newLbut;
	rButton.value=newRbut;
	putBackImage(lButton);
	putBackImage(rButton);
	setMessageCell(lButton,cBox,rButton);
}*/
// 已存在　問否要以此家餐廳新增文章
function showAlreadyExist(){
	var alMes="已經有人新增過囉 是否以這家餐廳新增文章";
	var alRbut="是";
	var alLbut="否";
	var rButton=document.createElement('input');
	var lButton=document.createElement('input');
	var mesBox=document.createElement('span');
		mesBox.appendChild(document.createTextNode(alMes));
	rButton.type="button";
	lButton.type="button";
	rButton.onclick=function (){ newExistHandler(); }//要以此家餐廳新增文章 所以放入資料 
	lButton.onclick=function (){ showNewRestau() ;   }  //不要以此家餐廳 新增 所以重新回到填寫餐廳資訊
	putBackImage(lButton);
	putBackImage(rButton);
	rButton.value=alRbut;
	lButton.value=alLbut;
	setMessageCell(lButton,mesBox,rButton);
}
function newExistHandler(){
	inputAlreadyInfo();//放入資料
	showRevise();//show 是否修改
}
function putBackImage(ele){
	ele.style.background="url(article/img/butBack.png)";
}
//建立不可見的資料 from aj_restauNameCheck
function createInvDiv(info){
	var invDiv=document.getElementById('invDiv');
	while (invDiv.hasChildNodes()) { 
		invDiv.removeChild(invDiv.childNodes[0]);
	}		
	//invDiv.removeallchild();
	for(var i=0 ;i<info.length;i++){
		var span=document.createElement('span');
			span.value=info[i];
			span.appendChild(document.createTextNode(info[i]));
			span.id='inv'+i;
			invDiv.appendChild(span);
	}
}
function nightAddress(add){
	document.restauForm.markerAddress.value=add;
	toPosition(add);
}
/*
function showCreateWay(){
	var alMes="請選擇新增文章的方式";
	var alRbut="一般新增";
	var alLbut="部落格匯入";
	var submitBut=document.createElement('input');
	var rButton=document.createElement('input');
	var lButton=document.createElement('input');
	var mesBox=document.createElement('span');
		mesBox.appendChild(document.createTextNode(alMes));	
	rButton.type="button";
	lButton.type="button";
	rButton.onclick=function (){
		doPosition(document.restauForm.markerAddress.value);
		setTimeout(checkBeforeSubmit,2000);
		
		document.restauForm.insertWay.value='normal';
	}
	lButton.onclick=function (){
		doPosition(document.restauForm.markerAddress.value);
		setTimeout(checkBeforeSubmit,2000);		
		document.restauForm.insertWay.value='rss';
	}
	rButton.value=alRbut;
	lButton.value=alLbut;
	setMessageCell(lButton,mesBox,rButton);
}
*/
/*
function checkBeforeSubmit(){
		/*clearTimeout(tId);
		if(checkLatLng()==false){
			alert("抱歉，無法定位噢! 可試試只輸入街道名稱");
			//putLatLng('','');
			showNewRestau();
		}
		else{
			var actUrl=getCreateWay();
			document.restauForm.action=actUrl;
			document.restauForm.submit();
		}	
		var actUrl=getCreateWay();
			document.restauForm.action=actUrl;
			document.restauForm.submit();
}
function showRevise(){
	var alMes="您可以修改餐廳資訊";
	var alRbut="修改完畢";
	var alLbut="不修改";
	var rButton=document.createElement('input');
	var lButton=document.createElement('input');
	var mesBox=document.createElement('span');
		mesBox.appendChild(document.createTextNode(alMes));
	rButton.type="button";
	lButton.type="button";
	rButton.onclick= function (){
		exCreateWay('update');  //update
		showCreateWay();
	} //修改完畢 ,show 新增方式
	lButton.onclick= function (){
		exCreateWay('update');  //update
		showCreateWay();
	} //修改完畢 ,show 新增方式
	rButton.value=alRbut;
	lButton.value=alLbut;
	setMessageCell(lButton,mesBox,rButton);
}
function removeMessage(){
	var rBut=document.getElementById('leftButton');
	while (rBut.hasChildNodes()) { 
		rBut.removeChild(rBut.childNodes[0]);
	}		
	var messageDiv=document.getElementById('message');
	while(messageDiv.hasChildNodes()) { 
		messageDiv.removeChild(messageDiv.childNodes[0]);
	}
	var lBut=document.getElementById('rightButton');
	while (lBut.hasChildNodes()) { 
		lBut.removeChild(lBut.childNodes[0]);
	}		
}
function setMessageCell(left,center,right){
	removeMessage();
	document.getElementById('message').appendChild( center);
	document.getElementById('leftButton').appendChild(left);
	document.getElementById('rightButton').appendChild(right);
}
function createHttpRequest(){
		if(window.ActiveXObject){
			return new ActiveXObject("Microsoft.XMLHTTP");
		}
		else if(window.XMLHttpRequest){
			return new XMLHttpRequest();
		}	
}
function getEleVal(id){
	return document.getElementById(id).value;
}
function aj_nightMarket(){
			var xml_nightMarket=new createHttpRequest();
			var url="article/srh_night.php";
			xml_nightMarket.open("POST" , url, true);
			xml_nightMarket.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
			xml_nightMarket.send(null); 
			xml_nightMarket.onreadystatechange =
			function reply_nightMarket(){
				if (xml_nightMarket.readyState == 4 && xml_nightMarket.status==200  ) {
						var response = xml_nightMarket.responseText;
						var result= eval('(' +response+ ')');
						showNightMarket(result);
					}
			}//end of replay
}
function showNightMarket(result){
		var nNum=0;
		var option="";
		var optgroupHead="";
		var optgroupTail="<\/optgroup>";
		var totalGroupOption="";
		for(var i=0;i<result.length;i++){  //<4
			option="";
			optgroupHead="<optgroup label='"+result[i]['nRegion']+"'>";
			nNum=result[i]['nName'].length;
			for(var j=0; j < nNum ; j++){
				var opt=result[i]['nName'][j];
				option+= "<option label='"+opt+"'"+" value='"+result[i]['nAddress'][j]+"' >"+opt
						+"<\/option>";
			}
			totalGroupOption+=optgroupHead+option+optgroupTail;
		}
		var totalSelect="<SELECT name='nightMarket' onchange='nightAddress(document.restauForm.nightMarket.options[selectedIndex].value);'>	 "		
		+"<option selected='selected' value='請選擇夜市'>請選擇夜市</option>"+totalGroupOption+"<\/select>";
		document.getElementById('showOption').innerHTML=totalSelect;
		document.getElementById('showOption').innerHTML+="您可依照店家變更地址";
		clickField('nameFie');
		clickField('addFie');
	}
	function optionHandler(isNight){
		if(isNight=="night"){
			document.restauForm.notNight.checked=false;
			document.getElementById('showOption').style.visibility="visible";
			aj_nightMarket();
		}
		else{
			document.restauForm.night.checked=false;
			document.getElementById('showOption').style.visibility="hidden";
		}
	}*/
	function clickField(id){
		if(document.getElementById(id).onfocus=='')
			return ;
		document.getElementById(id).onfocus='';
		document.getElementById(id).style.color='#000';
		document.getElementById(id).value='';
	}