/**
 * バスロケーションシステム「周辺のバス停を検索」ボタンクラス
 * @param string rewriteId
 * @param integer page_id
 */
var BusButton = function(rewriteId, page_id){
	this.rewriteId = rewriteId;
	this.contents = "";
	this.method = "POST";	//フォームデータのMETHOD属性値(GET/POST)
	this.async = true;	//非同期通信(TRUE:有効,FALSE:無効)
	this.path = "/search/result.php?mode=bbutton";	//サーバ側実行パス
	this.getButtonById(page_id);
}
/**
 * 関数プロトタイプ宣言
 */
BusButton.prototype = {
	/**
	 * 観光情報IDを条件に「周辺のバス停を検索」ボタンを返す
	 * @param integer page_id
	 * @return void
	 */
	getButtonById: function(page_id) {
		if (page_id) {
			var query = "pid=" + page_id;
			this.doQuery(query);
		}
	},
	/**
	 * クエリ実行
	 * @param query クエリ文字列
	 * @return 作成したhtml
	 */
	doQuery: function(query) {
		var chache = true;	//キャッシュ無効スイッチ(true/false)
		var xmlhttpobj = createXMLHttpRequest();	//XMLHttpRequestオブジェクト
		//Ajaxで検索開始
		xmlhttpobj.open(this.method,this.path,this.async);
		if (this.method == 'POST') {
			xmlhttpobj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		}
		//キャッシュを見に行かないようにする
		if (chache) {
			xmlhttpobj.setRequestHeader("If-Modified-Since", "Thu, 01 Jun 1970 00:00:00 GMT");
		}
		xmlhttpobj.onreadystatechange = function() {
			if (xmlhttpobj.readyState == 4) {
				if (xmlhttpobj.status == 200) {
					this.writeContents(xmlhttpobj);
				} else {
					alert("情報の取得に失敗しました。[" + xmlhttpobj.status + "]");
				}
			}
		}.bind(this);
		xmlhttpobj.send(query);
	},
	/**
	 * 結果を表示する
	 * @param void
	 * @return void
	 */
	writeContents: function(obj) {
		if (obj.responseText != "") {
			if (document.getElementById(this.rewriteId)) {
				document.getElementById(this.rewriteId).innerHTML = obj.responseText;
			}
		}
		return false;
	}
}

