function OneLine_Comment_Add(theForm,callBackFunc){
	//発言追加
	
	//input value check
	if( !(theForm.BBS_Body.value.length > 0) ){
		alert('発言が空白です。');
		return false;
	}

	//make query
	var postdata =encodeURIComponent("BBS_Body")	+"="	+encodeURIComponent(theForm.BBS_Body.value);
		postdata+="&"+encodeURIComponent("onelineaddform")	+"="	+encodeURIComponent('dummy');
	
	//post
	//var jsonData=json_postWithQueryString_Async('json_one_line_comment_add.html',postdata);
	json_postWithQueryString_Async('json_one_line_comment_add.html',postdata,callBackFunc);
}

function OneLine_Comment_Add_After(theRequest){
	if( (theRequest.readyState==4) && (theRequest.status==200) ){
		eval("var jsonData="+theRequest.responseText);
		
		//initialize error message
		var errorMessage='';
		
		//error check
		errorMessage+=jsonData.Message_01 ? jsonData.Message_01 : '';
		errorMessage+=jsonData.Message_02 ? jsonData.Message_02 : '';
		errorMessage+=jsonData.Message_03 ? jsonData.Message_03 : '';
		
		//view
		var OneLineAddMessage=document.getElementById('OneLineAddMessage');
		if(errorMessage.length>0){
			OneLineAddMessage.style.display="block";
			OneLineAddMessage.innerHTML=errorMessage;
		} else if(jsonData.Success){
			//update mypage bottom
			OneLineAddMessage.style.display="block";
			var OneLineAddMessage=document.getElementById('OneLineAddMessage');
			OneLineAddMessage.innerHTML=jsonData.Success;
			
			//clear form text
			var bbsBodyText=document.getElementById('bbsBodyText');
			bbsBodyText.value="";
			
		} else {
			OneLineAddMessage.innerHTML='Error';
		}
		
		innerHTML_get('communityInfo','inner_mypage_bottom.html');
		
		setTimeout(oneLineAddMessageClose,2500);
	}
}

function OneLine_Comment_Add_AfterFromMapBottom(theRequest){
	if( (theRequest.readyState==4) && (theRequest.status==200) ){
		eval("var jsonData="+theRequest.responseText);
		
		//initialize error message
		var errorMessage='';
		
		//error check
		errorMessage+=jsonData.Message_01 ? jsonData.Message_01 : '';
		errorMessage+=jsonData.Message_02 ? jsonData.Message_02 : '';
		errorMessage+=jsonData.Message_03 ? jsonData.Message_03 : '';
		
		//view
		var OneLineAddMessage=document.getElementById('AddMessageFromMapBottom');
		if(errorMessage.length>0){
			OneLineAddMessage.style.display="block";
			OneLineAddMessage.innerHTML=errorMessage;
		} else if(jsonData.Success){
			//update mypage bottom
			OneLineAddMessage.style.display="block";
			var OneLineAddMessage=document.getElementById('AddMessageFromMapBottom');
			/* FireBug */ if(window.console){console.debug("from map button");}
			OneLineAddMessage.innerHTML=jsonData.Success;
			
			//clear form text
			var bbsBodyTextFromMapBottom=document.getElementById('bbsBodyTextFromMapBottom');
			bbsBodyTextFromMapBottom.value="";
			
		} else {
			OneLineAddMessage.innerHTML='Error';
		}
		
		//MyOneLine_ReadMore(0);
		
		setTimeout(AddMessageFromMapBottomClose,2500);
	}
}

function oneLineAddMessageClose(){
	parts_close('OneLineAddMessage');
}
function AddMessageFromMapBottomClose(){
	parts_close('AddMessageFromMapBottom');
}

function json_postWithQueryString_Async(file,queryString,theReturnFunc){
	//jsonデータを取得し呼び出し元に返す（メソッドポスト）。
	var request= GXmlHttp.create();
	request.onreadystatechange=function(){
		theReturnFunc(request);
	}
	request.open("POST",file,true);
	request.setRequestHeader("content-type","application/x-www-form-urlencoded");
	request.setRequestHeader("If-Modified-Since","Thu,01 Jun 1970 00:00:00 GMT");	//cache management
	request.send(queryString);	
	
}

function innerHTML_get_Async(node,file,queryName,queryValue,theReturnFunc){
	//innerHTMLのファイルを取得する。
	var query="";
	if(queryName && queryValue){
		query+="?"+ encodeURIComponent(queryName) + "=" + encodeURIComponent(queryValue);
	}
	
	var request=GXmlHttp.create();
	request.onreadystatechange=function(){
		theReturnFunc(node,request);
	}
	request.open("GET",file+query,true);
	request.setRequestHeader("If-Modified-Since","Thu,01 Jun 1970 00:00:00 GMT");	//cache management
	request.send(null);
}

function innerHTML_get_Async_After_Update(theNode,theRequest){
	if( (theRequest.readyState==4) && (theRequest.status==200) ){
		var targetNode=document.getElementById(theNode);
		targetNode.innerHTML=theRequest.responseText;
	}
}

function OneLine_list(numOfComment){
	//発言表示
	
	//make query
	if(globalLatestMessageID > 0){
		var postdata =encodeURIComponent("Actniche_BBS_LatestMessageID")	+"="	+encodeURIComponent(globalLatestMessageID);
	}
	if(numOfComment && isNaN(numOfComment)==false){
		postdata+='&'+encodeURIComponent("Actniche_BBS_ROWS")	+"="	+encodeURIComponent(numOfComment);
	}
	json_postWithQueryString_Async('json_one_line_comment_list.html',postdata,OneLine_list_After);
	
	//make query for kusu2base
	
	//lat lng boundary
	var theLatLngBounds=map.getBounds();
	var northEastLatlng=theLatLngBounds.getNorthEast();
	var southWestLatlng=theLatLngBounds.getSouthWest();
	
	var topLat		=northEastLatlng.lat();
	var rightLng	=northEastLatlng.lng();
	var bottomLat	=southWestLatlng.lat();
	var leftLng		=southWestLatlng.lng();
	
	var postQuery  =	encodeURIComponent("ActnicheCommunity_TopLatitude")		+"="	+encodeURIComponent(topLat);
		postQuery +='&'+encodeURIComponent("ActnicheCommunity_RightLongitude")	+"="	+encodeURIComponent(rightLng);
		postQuery +='&'+encodeURIComponent("ActnicheCommunity_BottomLatitude")	+"="	+encodeURIComponent(bottomLat);
		postQuery +='&'+encodeURIComponent("ActnicheCommunity_LeftLongitude")	+"="	+encodeURIComponent(leftLng);
	
	json_postWithQueryString_Async('json_kusubase_list.html',postQuery,kusubase_list_After);
}

function OneLine_list_After(theRequest){
	if( (theRequest.readyState==4) && (theRequest.status==200) ){
		eval("var jsonData="+theRequest.responseText);
		
		//initialize error message
		var errorMessage='';
		
		//error check
		errorMessage+=jsonData.ErrorMessage_01 ? jsonData.ErrorMessage_01 : '';
		
		//view
		if(errorMessage.length>0){
			alert(errorMessage);
		} else if(jsonData.ROWCOUNT > 0) {
			// when data exist
			globalMessageList		=jsonData.MessageBody;
			//globalLatestMessageID	=jsonData.LatestMessageID;
			OneLine_Comment_View();
		} else {
			// when no data
			/* FireBug */ if(window.console){console.debug("No data");}
			globalTimerID_GetOneLine=setTimeout(OneLine_list,5000);
			globalMessageLeftBox.innerHTML="新規発言はありません";
		}
	}
}

function OneLine_Comment_View(){
	var commentData=globalMessageList.pop();
	globalMessageLeftBox.innerHTML="残り " + (globalMessageList.length) + " 発言";
	if(commentData){
		/* FireBug */ if(window.console){console.debug("MessageID: "+commentData.MESSAGE_ID);}
		globalLatestMessageID=commentData.MESSAGE_ID;
		var thelatlng=new GLatLng(commentData.CenterLatitude,commentData.CenterLongitude);
		
		var imageHTML='';
		for(var i=0, n=commentData.Photos.length; i<n; i++){
			imageHTML+='<span style="cursor:pointer" onclick="Area_enlargeImage('+ commentData.Photos[i].PhotoID +')"><img src="'+ commentData.Photos[i].Photo_URL+'" width="48px" height="48px" border="0"></span>';
		}
		var html='<div style="width:275px">';
					html+='<div style="float:left; width:51px">';
					html+='<table style="width:50px">';
					html+=	'<tr>';
					html+=		'<td style="width:50px; height:50px">';
					if(imageHTML.length >0){
						html+=		'<div style="padding-left:0.2em; padding-right:0.2em; float:left;">'+imageHTML+'</div>';
					} else {
						html+=		'<div style="padding-left:0.2em; padding-right:0.2em; float:left;"><span style="cursor:pointer" onclick="Area_enlargeImage()"><img src="img/nophoto.gif" width="48px" height="48px" border="0"></span></div>';
					}
					html+=		'</td>';
					html+=	'</tr>';
					html+='</table>';
					html+='</div>';
					html+='<div style="margin-left:3.5em">';
					html+=	'<div><a href="mypage.html?Login_UID='+commentData.USERID+'" style="font-weight:bold; text-decoration:none">'+commentData.USERNAME+'</a></div>';
					html+=	'<div style="font-size:0.9em; margin-top:0.2em; word-break:break-all;"><table><tr><td style="width:100%; height:100%">'+commentData.BODY+'</td></tr></table></div>';
					html+=	'<div style="text-align:right; font-size:0.7em; margin-top:0.5em;">'+commentData.DATE+'&nbsp;'+commentData.TIME+'</div>';
					html+='</div>';
			html+='<div>';
		var theMarker= new GMarker(thelatlng,globalhomebaseIcon);
		
		//make polygon data
		var areaData = new Array();
		for(var m=0, p=commentData.AreaLatLng.length; m<p; m++){
			var latitude	=commentData.AreaLatLng[m].Latitude;
			var longitude	=commentData.AreaLatLng[m].Longitude;
			var cornerlatlng=new GLatLng(latitude,longitude);
			areaData.push(cornerlatlng);
		}
		//first index of array
		areaData.push(areaData[0]);
		
		var	strokeColor		='#ff66ff';
		var strokeWeight	=2;
		var strokeOpacity	=1;
		var fillColor		="#000000";
		var fillOpacity		=0.2;
		var thePolygon=new GPolygon(areaData,strokeColor,strokeWeight,strokeOpacity,fillColor,fillOpacity);
		
		
		map.addOverlay(theMarker);
		map.addOverlay(thePolygon);	
		var opt={"onOpenFn":function(){
						WaitWhileFiveSecond(theMarker,thePolygon);
					},
				"onCloseFn":function(){
						map.removeOverlay(theMarker);
						map.removeOverlay(thePolygon);
					}};
		map.openInfoWindowHtml(thelatlng,html,opt);
		
	} else {
		//load
		globalMessageList=new Array();
		globalTimerID_GetOneLineMore=setTimeout(OneLine_list,1000);
	}
}

function WaitWhileFiveSecond(theMarker,thePolygon){
	globalTimerID_CommentView=setTimeout(function(){
		OneLine_Comment_View();
	},5000);
}

function TimerOfOneLine_Clear(){
	if(globalTimerID_GetOneLine)		clearTimeout(globalTimerID_GetOneLine);
	if(globalTimerID_CommentView)		clearTimeout(globalTimerID_CommentView);
	if(globalTimerID_GetOneLineMore)	clearTimeout(globalTimerID_GetOneLineMore);
}
function MyOneLine_ReadMore(thePage){
	var postdata =encodeURIComponent("Actniche_BBS_Page")		+"="	+encodeURIComponent(thePage);
	
	//file get
	json_postWithQueryString_Async('inner_my_oneline_read_more.html',postdata,MyOneLine_ReadMore_After)
}

function MyOneLine_ReadMore_After(theRequest){
	if( (theRequest.readyState==4) && (theRequest.status==200) ){
		document.getElementById('MyOneLineComment').innerHTML=theRequest.responseText;
	}
}

function profile_message_modify_form_show(){
	//プロフィール編集フォーム
	//file get
	innerHTML_get('communityInfo','inner_profile_message_modify_form.html');
}

function profile_message_modify_submit(theForm){
	//プロフィール編集 サブミット
	//input value check
	//userName
	if(theForm.Login_NAME.value.length >0){
		var userName=theForm.Login_NAME.value;
	} else {
		alert('ニックネームが未入力です。');
		return false;
	}
	
	//make query
	var postdata =encodeURIComponent("Login_NAME")				+"="	+encodeURIComponent(userName);
		postdata+="&"+encodeURIComponent("Login_PASS1")			+"="	+encodeURIComponent(theForm.Login_PASS1.value);
		postdata+="&"+encodeURIComponent("Login_PASS2")			+"="	+encodeURIComponent(theForm.Login_PASS2.value);
		postdata+="&"+encodeURIComponent("profilemodify_form")	+"="	+encodeURIComponent(theForm.profilemodify_form.value);
		
	//check
	var jsonData=json_postWithQueryString('json_profile_message_modify_check.html',postdata);
	
	//error check
	var errorMessage='';
	errorMessage+=jsonData.Message_01 ? jsonData.Message_01 + '<br>' :'';
	errorMessage+=jsonData.Message_02 ? jsonData.Message_02 + '<br>' :'';
	errorMessage+=jsonData.Message_03 ? jsonData.Message_03 + '<br>' :'';
	errorMessage+=jsonData.Message_04 ? jsonData.Message_04 + '<br>' :'';
	errorMessage+=jsonData.Message_05 ? jsonData.Message_05 + '<br>' :'';
	errorMessage+=jsonData.Message_06 ? jsonData.Message_06 + '<br>' :'';
	
	if(errorMessage.length >0){
		var profileModifyMessage=document.getElementById('profileModifyMessage');
		profileModifyMessage.style.display='block';
		profileModifyMessage.innerHTML=errorMessage;
		setTimeout(profile_modify_submit_Close,2500);
	} else {
		//result display
		innerHTML_Update_Post('communityInfo','inner_profile_message_modify_form.html',postdata);
	}
}
function nomap_OneLine_ReadMore(thePage){
	var postdata =encodeURIComponent("Actniche_BBS_Page")		+"="	+encodeURIComponent(thePage);
	
	//file get
	json_postWithQueryString_Async('inner_nomap_oneline_read_more.html',postdata,nomap_OneLine_ReadMore_After);

}

function nomap_OneLine_ReadMore_After(theRequest){
	if( (theRequest.readyState==4) && (theRequest.status==200) ){
		document.getElementById('OneLineListDisplay').innerHTML=theRequest.responseText;
	}
}
function Reload_HomeBase_View(theAreaID){
	var pathName=window.location.pathname;
	var regexp=/map_online/;
	if(regexp.test(pathName)){
		button_control_oneline('Stop'); TimerOfOneLine_Clear(); areaMarker_click(theAreaID,null,true,null,true);
	} else {
		window.location.href="map_oneline.html?ActnicheCommunity_AreaID="+encodeURIComponent(theAreaID)
	}
}
function NoLogin_Comment_Add(){
	var AddMessageFromMapBottom=document.getElementById('AddMessageFromMapBottom');
	var html ="<table style='width:90%'>";
		html 	+="<tr>";
		html 		+="<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
		html 		+="<td style='text-align:center'>ログインしておりません。</td>";
		html 		+="<td style='text-align:right'><span style='cursor:pointer; color:blue; font-size:0.8em' onclick='AddMessageFromMapBottomClose() ;return false'>閉じる</a></td>";
		html 	+="</tr>";
		html+="</table>";
		html+=	"<br><a href='login_form.html' onclick='window.open(\"login_form.html\",\"\",\"width=320,height=180\"); return false'>ログインする。</a>";
		html+=	"<br>マップチャットを利用するには<a href='regist_form.html'>ユーザー登録</a>が必要です。";
	AddMessageFromMapBottom.innerHTML=html;
	AddMessageFromMapBottom.style.display="block";
}

function kusubase_list_After(theRequest){
	if( (theRequest.readyState==4) && (theRequest.status==200) ){
		eval("var jsonData="+theRequest.responseText);
		
		//initialize error message
		var errorMessage='';
		
		//remove marker from map
		for(var i=0; i<globalLogonUserMarkerArr.length; i++){
			map.removeOverlay(globalLogonUserMarkerArr[i]);
			/* FireBug */ if(window.console){console.debug("remove");}
		}
		globalLogonUserMarkerArr=[];
		
		//icon common setting
		var myIconSise	=new GSize(9,13);
		var myShadowSize=new GSize(15,15);
		var myIconAnchor=new GPoint(5,10);
		
		//homebase icon
			//man, woman,gender no public
		var imageFile="img/homebase_marker_nopublic.gif";
		
		var homeBaseIcon=new GIcon(G_DEFAULT_ICON,imageFile);
		homeBaseIcon.iconSize=myIconSise;
		homeBaseIcon.shadowSize=myShadowSize;
		homeBaseIcon.iconAnchor=myIconAnchor;
		
		if(jsonData.kusubaseList && jsonData.kusubaseList.length >0){
			//add marker to map
			for(var i=0; i<jsonData.kusubaseList.length; i++){
				var baseObj=jsonData.kusubaseList[i];
				var mylatlng=new GLatLng(baseObj.centerLatitude,baseObj.centerLongitude);
				//marker
				var localHomeBaseMarker=new GMarker(mylatlng,homeBaseIcon,false);
				globalLogonUserMarkerArr.push(localHomeBaseMarker);
				map.addOverlay(localHomeBaseMarker);
				
				//event
				LogOnUserKusuBase_AddListener(localHomeBaseMarker,baseObj.areaID)
			}
		}
	}

}

function LogOnUserKusuBase_AddListener(theMarker,areaID){
	//event
	var onclickFunction=function(){
		button_control_oneline('Stop'); TimerOfOneLine_Clear();
		areaMarker_click(areaID,null,true,null,true,'false');
	}
	
	GEvent.addListener(theMarker, "click", onclickFunction);
}
