/*えう*/
var cash = [] ;
function ajedit_html(ajedit_id){
	ajedit_value = document.getElementById(ajedit_id).innerHTML ;
	cash[ajedit_id] = ajedit_value ;
	id = document.getElementById('id').value ;
	var text = '' ;
	text += '<div class="edit_now">' ;
	text += '<input name="' + ajedit_id + '_edit_now" id="' + ajedit_id + '_edit_now" type="text" style="width:100px;" value="' + ajedit_value + '" />' ;
	text += "<input type=\"button\" style=\"width:24px;\" value=\"OK\" onclick=\"ajedit_html_ok('" + id + "','" + ajedit_id + "','" + ajedit_id + "_edit_now');false;\" />" ;
	text += '<input type="button" style="width:24px;" value="NO" onclick="ajedit_html_no(' + "'" + ajedit_id + "'" + ');false;" />' ;
	text += '</div>' ;
	document.getElementById(ajedit_id).innerHTML = text ;
	return 1 ;
}

function ajedit_html_textarea(ajedit_id){
	ajedit_value = document.getElementById(ajedit_id).innerHTML ;
	cash[ajedit_id] = ajedit_value ;
	ajedit_value = ajedit_value.replace(/\<BR\>/ig, "\n") ;
	ajedit_value = ajedit_value.replace(/\<br\s\/\>/ig, "\n") ;
	id = document.getElementById('id').value ;
	var text = '' ;
	text += '<div class="edit_now">' ;
	text += '<textarea name="' + ajedit_id + '_edit_now" id="' + ajedit_id + '_edit_now" cols="32" rows="4" style="width:250px;">' + ajedit_value + '</textarea><br />' ;
	text += "<input type=\"button\" style=\"width:24px;\" value=\"OK\" onclick=\"ajedit_html_ok('" + id + "','" + ajedit_id + "','" + ajedit_id + "_edit_now');false;\" />" ;
	text += '<input type="button" style="width:24px;" value="NO" onclick="ajedit_html_no(' + "'" + ajedit_id + "'" + ');false;" />' ;
	text += '</div>' ;
	document.getElementById(ajedit_id).innerHTML = text ;
	return 1 ;
}

function ajedit_html_date(ajedit_id){
	ajedit_value = document.getElementById(ajedit_id).innerHTML ;
	cash[ajedit_id] = ajedit_value ;
	id = document.getElementById('id').value ;
	var text = '' ;
	text += '<div class="edit_now">' ;
	text += '<select name="_edit_now">' ;
	text += '<option value=""></option>' ;
	text += '</select>' ;
	text += "<input type=\"button\" style=\"width:24px;\" value=\"OK\" onclick=\"ajedit_html_ok('" + id + "','" + ajedit_id + "','" + ajedit_id + "_edit_now');false;\" />" ;
	text += '<input type="button" style="width:24px;" value="NO" onclick="ajedit_html_no(' + "'" + ajedit_id + "'" + ');false;" />' ;
	text += '</div>' ;
	document.getElementById(ajedit_id).innerHTML = text ;
	return 1 ;
}

function ajedit_html_time(ajedit_id){
	ajedit_value = document.getElementById(ajedit_id).innerHTML ;
	cash[ajedit_id] = ajedit_value ;
	id = document.getElementById('id').value ;
	uri = '/hanabidb/ajedit_time.php?id=' + id ;
	fgetjs(uri,'time') ;
	return 1 ;
}

function ajedit_html_ok(out_id,ajedit_id,ajedit_name){
	data = document.getElementById(ajedit_name).value ;
	if(data.length <= 0) {
		document.getElementById(out_id).innerHTML = '' ;
		return 0 ;
	}
	url_data = encodeURIComponent(data) ;
	url = '/hanabidb/ajedit.php' ;
	post_data = 'id=' + document.getElementById('id').value ;
	post_data += '&name=' + ajedit_id ;
	post_data += '&value=' + url_data ;
	text = requestFile( out_id , 'POST' , url , true , post_data) ;
	return 1 ;
}

function ajedit_time_html_ok(){
	sh_data = document.getElementById('stime_h').value ;
	sm_data = document.getElementById('stime_m').value ;
	eh_data = document.getElementById('etime_h').value ;
	em_data = document.getElementById('etime_m').value ;
	data = sh_data + ':' + sm_data + '-' + eh_data + ':' + em_data ;
	url_data = encodeURIComponent(data) ;
	url = '/hanabidb/ajedit_time_input.php' ;
	post_data = 'id=' + document.getElementById('id').value ;
	post_data += '&name=' + 'time' ;
	post_data += '&value=' + url_data ;
	text = requestFile( 'time' , 'POST' , url , true , post_data) ;
	return 1 ;
}

function ajedit_html_no(ajedit_id){
	document.getElementById(ajedit_id).innerHTML = cash[ajedit_id] ;
	return 1 ;
}

function likes(in_id,out_id) {
	data = document.getElementById(in_id).value ;
	if(data.length <= 0) {
		document.getElementById(out_id).innerHTML = '' ;
		return 0 ;
	}
	url_data = encodeURIComponent(data) ;
	url = '/kaku/likes_search.php?q=' + url_data ;
	post_data = "" ;
	text = requestFile( out_id , 'GET' , url , true , post_data) ;
	return 1 ;
}

//XMLHttpRequestオブジェクト生成
function createHttpRequest(){

	//Win ie用
	if(window.ActiveXObject){
			try {
					//MSXML2以降用
					return new ActiveXObject("Msxml2.XMLHTTP") //[1]'
			} catch (e) {
					try {
							//旧MSXML用
							return new ActiveXObject("Microsoft.XMLHTTP") //[1]'
					} catch (e2) {
							return null
					}
			 }
	} else if(window.XMLHttpRequest){
			//Win ie以外のXMLHttpRequestオブジェクト実装ブラウザ用
			return new XMLHttpRequest() //[1]'
	} else {
			return null
	}
}

//ファイルにアクセスし受信内容を確認します
function requestFile( data , method , fileName , async, post_data)
{
	//XMLHttpRequestオブジェクト生成
	var httpoj = createHttpRequest() //[1]
	
	//open メソッド
	httpoj.open( method , fileName , async ) ; //[2]
	if(method == 'POST') {
		httpoj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") ;
		httpoj.send(post_data) ;
	}
	//受信時に起動するイベント
	httpoj.onreadystatechange = function()	//[4]
	{ 
		//readyState値は4で受信完了
		if (httpoj.readyState==4)	//[5]
		{ 
			//コールバック
			on_loaded(httpoj, data)
		}
	}
	
	//send メソッド
	httpoj.send( data ) //[3]
		
}

//コールバック関数 ( 受信時に実行されます )
function on_loaded(oj, id)
{
			//レスポンスを取得
		res	= oj.responseText //[6]
			//ダイアログで表示
		if(res == "1") {
//			document.getElementById(id).innerHTML = "reload now..." ;
//			data = document.getElementById('id').value ;
//			var fileName = "/hanabidb/mk_html.php?id=" + data ;
//			var httpoj = createHttpRequest(); //[1]
//			httpoj.open( 'GET' , fileName , true );
//			location.href = "/hanabidb/mk_html.php?id=" + data ;
			location.reload(true) ;
		}

}

function ajedit_cal(id) {
	location.href = "/hanabidb/ajedit_cal.php?id=" + id ;
	return 1 ;
}
function ajedit_map(id) {
	location.href = "/hanabidb/ajedit_map.php?id=" + id ;
	return 1 ;
}
