// データ取得URL
var _sAplUrl_1		= "/bk_topics/ajx_com/aj_gettopics.php" ;
var _sAplUrl_2		= "/bk_topics/ajx_com/aj_gettopics_view.php" ;
var _sPaBkno		= "bk_no="			;			// 
var _sPaSeqno		= "seq_no="			;			// 
var _sPaDd			= "DD="				;			// 

// タグID
var sID_BkTitle		= "bk_title"		;			// 物件名
var sID_TpStr		= "topics_str"		;			// トピックス本文
var sID_PupY		= "publish_up_y"	;			// 公開開始日付(年)
var sID_PupM		= "publish_up_m"	;			// 公開開始日付(月)
var sID_PupD		= "publish_up_d"	;			// 公開開始日付(日)

var _sX_Pup			= "publish_up"		;			// 公開開始日付
var _sX_TpStr		= "topics_str"		;			// トピックス本文
var _sX_BkName		= "bk_name"			;			// 物件名

var _sX_Message		= "message"			;			// メッセージ
var _sX_ErrorNo		= "errorno"			;			// エラー番号

var iFlag = 0 ;
/*--------------------------------------------------------------------------*
 *
 * 共 通																	*
 *
 *--------------------------------------------------------------------------*/
/****************************************************************************
 *
 * newXMLHttpRequest ---- XMLHttpRequest オブジェクトの生成
 *
 ****************************************************************************/
function newXMLHttpRequest() {

	if( typeof ActiveXObject != "undefined" ) {
		return new ActiveXObject( "Microsoft.XMLHTTP" ) ;	// MSXML2まで
	} else if( typeof XMLHttpRequest != "undefined" ) {
		return new XMLHttpRequest() ;
	} else {
		return null ;
	}

//	if( window.XMLHttpRequest ) {
//		return new XMLHttpRequest() ;
//	}
//	if ( window.ActiveXObject ) {
//		try {
//			return new ActiveXObject( "Msxml2.XMLHTTP" ) ;
//		} catch( e ) {
//			try{
//				return new ActiveXObject( "Microsoft.XMLHTTP" ) ;
//			} catch( e2 ) {
//				return null ;
//			}
//		}
//	}


//	//Win ie用
//	if( typeof window.ActiveXObject != "undefined" ) {
//		try {
//			//MSXML2以降用
//			return new ActiveXObject( "Msxml2.XMLHTTP" ) ;	//[1]'
//		} catch ( e ) {
//			try {
//				//旧MSXML用
//				return new ActiveXObject( "Microsoft.XMLHTTP" ) ;	//[1]'
//			} catch ( e2 ) {
//				return new ActiveXObject( "Microsoft.XMLHTTP" ) ;	//[1]'
////				return null ;
//			}
//		 }
//	} else if( typeof window.XMLHttpRequest != "undefined" ) {
//		//Win ie以外のXMLHttpRequestオブジェクト実装ブラウザ用
//		return new XMLHttpRequest() ;		//[1]'
//	} else {
//		return new ActiveXObject( "Microsoft.XMLHTTP" ) ;
////		return null ;
//	}

}

/****************************************************************************
 *
 * ajax でデータを取得する
 *
 ****************************************************************************/
function com_getResult_bkname( sBkNo, sSeqNo, sBoxId ) {
	// リクエストオブジェクト生成
	var oHttp = newXMLHttpRequest() ;
//alert( "check" ) ;
	if( !oHttp ) {
//alert( "oHttp false" ) ;
		return false ;
	}

	// 実行URL作成
	oDate = new Date() ;	// キャッシュ対策用の日時
	var sUrl = _sAplUrl_1 ;
	var sPar = _sPaBkno + encodeURI( sBkNo )
						+ "&" + _sPaSeqno + encodeURI( sSeqNo )
						+ "&" + _sPaDd    + encodeURI( oDate.toLocaleString() ) ;
//alert( sUrl + "\n" + sPar ) ;

	// POST メソッド、URL 指定、非同期(=true)
	oHttp.open( "POST", sUrl, true ) ;

	// サーバーからの応答時の処理を定義
	oHttp.onreadystatechange = function() {
//alert( "call response" );
		com_getTopicsResult_bkname( oHttp, sBoxId ) ;
	} ;

	// リクエスト送信
	oHttp.setRequestHeader( "content-type"
							, "application/x-www-form-urlencoded;charset=Shift-jis" ) ;
	oHttp.send( sPar ) ;


	return true ;
}

// ---------------------------------------------------------------- //
//  レスポンス関数 ajax 通信完了後に呼び出されるハンドラ
// ---------------------------------------------------------------- //
//  0 = uninitialized
//  1 = loading
//  2 = loaded
//  3 = interactive
//  4 = complete
// ---------------------------------------------------------------- //
function com_getTopicsResult_bkname( oHttp, sBoxId ) {

//alert( "check[" + oHttp.readyState + "][" + oHttp.status + "]" ) ;
	if( oHttp.readyState == 4 ) {

		if( oHttp.status == 200 ) {

			var bExecStat = false ;

			var resXML = oHttp.responseText ;

			aLines = resXML.split( "\n" ) ;
//alert( "lines[" + aLines.length + "]" ) ;

			for( iLcnt = 0; iLcnt < aLines.length; iLcnt++ ) {

				sBkName		= "" ;	// 物件名
				sMsgStr		= "" ;	// メッセージ
				sErrNo		= "" ;	// エラーコード

				if( aLines[iLcnt].match(/^\<\?xml.+$/i) ) {
					continue ;
				}
				if( aLines[iLcnt].match(/^\<[\/]?topics\>$/i) ) {
					continue ;
				}

				if( aLines[iLcnt].match(/^\<\match\>$/i) ) {

					for( iMcnt = 1; iMcnt < aLines.length; iMcnt++ ) {

						iAcnt = iLcnt + iMcnt ;
//alert( "LINE[" + iAcnt + "] [" + aLines[iAcnt] + "]" ) ;
						if( aLines[iAcnt].match(/^\<\/match\>$/i) ) {
							iLcnt = iAcnt ;
							break ;
						}

						// 公開開始日付
						if( aLines[iAcnt].match(/^\<publish_up\>(.+)\<\/publish_up\>$/i) ) {
							aLinesWk = aLines[iAcnt].match(/^\<publish_up\>(.+)\<\/publish_up\>$/i) ;
							if( aLinesWk[1].match(/\[empty\]/i) ) {
								sPupDate = "[empty]" ;
								sPupY    = "" ;			// 公開開始日付(年)
								sPupM    = "" ;			// 公開開始日付(月)
								sPupD    = "" ;			// 公開開始日付(日)
							} else {
								sPupDate = aLines[iAcnt] ;
								aPup     = sPupDate.split( "-" ) ;
								sPupY    = aPup[0] ;	// 公開開始日付(年)
								sPupM    = aPup[1] ;	// 公開開始日付(月)
								sPupD    = aPup[2] ;	// 公開開始日付(日)
							}
							continue ;
						}

						// 物件名
						if( aLines[iAcnt].match(/^\<bk_name\>(.+)\<\/bk_name\>$/i) ) {
							aLinesWk = aLines[iAcnt].match(/^\<bk_name\>(.+)\<\/bk_name\>$/i) ;
							if( aLinesWk[1].match(/\[empty\]/i) ) {
								sBkName = "[empty]" ;
							} else {
								sBkName = aLinesWk[1] ;
							}
							continue ;
						}

						// 本文
						if( aLines[iAcnt].match(/^\<topics_str\>(.+)\<\/topics_str\>$/i) ) {
							aLinesWk = aLines[iAcnt].match(/^\<topics_str\>(.+)\<\/topics_str\>$/i) ;
							if( aLinesWk[1].match(/\[empty\]/i) ) {
								sTextStr = "[empty]" ;
							} else {
								sTextStr = aLinesWk[1] ;
								// 改行コードへの置き換え
								sTextStr = sTextStr.replace(/\[:::\]/g,"\n") ;
								// セミコロンへの置き換え
								sTextStr = sTextStr.replace(/\[:6:\]/g,"&") ;
								// セミコロンへの置き換え
								sTextStr = sTextStr.replace(/\[:_:\]/g,";") ;
								// Aタグにtargetを埋め込む
								sTextStr = sTextStr.replace(/(<[aA]) /g,"$1 target=_blank ") ;
							}
							continue ;
						}

						// メッセージ
						if( aLines[iAcnt].match(/^\<message\>(.+)\<\/message\>$/i) ) {
							aLinesWk = aLines[iAcnt].match(/^\<message\>(.+)\<\/message\>$/i) ;
							sMsgStr  = aLinesWk[1] ;
							continue ;
						}

						// エラーコード
						if( aLines[iAcnt].match(/^\<errorno\>(.+)\<\/errorno\>$/i) ) {
							aLinesWk = aLines[iAcnt].match(/^\<errorno\>(.+)\<\/errorno\>$/i) ;
							sErrNo   = aLinesWk[1] ;
							continue ;
						}

					}
//alert( "BK_NAME[" + sBkName + "]" ) ;
//alert( "TOPICS[" + sTextStr + "]" ) ;
//alert( "MSG[" + sMsgStr + "]" ) ;
//alert( "ERRNO[" + sErrNo + "]" ) ;

					// エラーの場合
					if( sMsgStr != "" && sErrNo != "" ) {
						alert( sMsgStr + "[" + sErrNo + "]" ) ;
						continue ;
					}

					/* データ設定 */
					// 物件名
					if( sBoxId == "" ) {
						sBoxId = sID_BkTitle ;
					}
					oIdBkName	= document.getElementById( sBoxId ) ;

					/* 文字列置き換え */
					// 物件名
//					replaceText( oIdBkName, sBkName ) ;
					if( typeof oIdBkName == "object" ) {
						oIdBkName.innerText = sBkName ;
					}

				}

			}

		} else {
			$( "result" ).innerHTML = "<b>通信に失敗しました</b>" ;
		}

	}else{
		$( "result" ).innerHTML = "<b>通信中…</b>" ;
	}

}

/****************************************************************************
 *
 * ajax でデータを取得する
 *
 ****************************************************************************/
function com_getResult_prev( sBkNo, sSeqNo, sBoxId ) {
	// リクエストオブジェクト生成
	var oHttp = newXMLHttpRequest() ;
//alert( "check" ) ;
	if( !oHttp ) {
//alert( "oHttp false" ) ;
		return false ;
	}

	// 実行URL作成
	oDate = new Date() ;	// キャッシュ対策用の日時
	var sUrl = _sAplUrl_1 ;
	var sPar = _sPaBkno + encodeURI( sBkNo )
						+ "&" + _sPaSeqno + encodeURI( sSeqNo )
						+ "&" + _sPaDd    + encodeURI( oDate.toLocaleString() ) ;
//alert( sUrl + "\n" + sPar ) ;

	// POST メソッド、URL 指定、非同期(=true)
	oHttp.open( "POST", sUrl, true ) ;

	// サーバーからの応答時の処理を定義
	oHttp.onreadystatechange = function() {
//alert( "call response" );
		handle_getTopicsResult_prev( oHttp, sBoxId ) ;
	} ;

	// リクエスト送信
	oHttp.setRequestHeader( "content-type"
							, "application/x-www-form-urlencoded;charset=Shift-jis" ) ;
	oHttp.send( sPar ) ;


	return true ;
}

// ---------------------------------------------------------------- //
//  レスポンス関数 ajax 通信完了後に呼び出されるハンドラ
// ---------------------------------------------------------------- //
//  0 = uninitialized
//  1 = loading
//  2 = loaded
//  3 = interactive
//  4 = complete
// ---------------------------------------------------------------- //
function handle_getTopicsResult_prev( oHttp, sBoxId ) {

//alert( "check[" + oHttp.readyState + "][" + oHttp.status + "]" ) ;
	if( oHttp.readyState == 4 ) {

		if( oHttp.status == 200 ) {

			var bExecStat = false ;

			var resXML = oHttp.responseText ;

			aLines = resXML.split( "\n" ) ;
//alert( "lines[" + aLines.length + "]" ) ;

			for( iLcnt = 0; iLcnt < aLines.length; iLcnt++ ) {

				sTextStr	= "" ;	// 本文
				sMsgStr		= "" ;	// メッセージ
				sErrNo		= "" ;	// エラーコード

				if( aLines[iLcnt].match(/^\<\?xml.+$/i) ) {
					continue ;
				}
				if( aLines[iLcnt].match(/^\<[\/]?topics\>$/i) ) {
					continue ;
				}

				if( aLines[iLcnt].match(/^\<\match\>$/i) ) {

					for( iMcnt = 1; iMcnt < aLines.length; iMcnt++ ) {

						iAcnt = iLcnt + iMcnt ;
//alert( "LINE[" + iAcnt + "] [" + aLines[iAcnt] + "]" ) ;
						if( aLines[iAcnt].match(/^\<\/match\>$/i) ) {
							iLcnt = iAcnt ;
							break ;
						}

						// 公開開始日付
						if( aLines[iAcnt].match(/^\<publish_up\>(.+)\<\/publish_up\>$/i) ) {
							aLinesWk = aLines[iAcnt].match(/^\<publish_up\>(.+)\<\/publish_up\>$/i) ;
							if( aLinesWk[1].match(/\[empty\]/i) ) {
								sPupDate = "[empty]" ;
								sPupY    = "" ;			// 公開開始日付(年)
								sPupM    = "" ;			// 公開開始日付(月)
								sPupD    = "" ;			// 公開開始日付(日)
							} else {
								sPupDate = aLines[iAcnt] ;
								aPup     = sPupDate.split( "-" ) ;
								sPupY    = aPup[0] ;	// 公開開始日付(年)
								sPupM    = aPup[1] ;	// 公開開始日付(月)
								sPupD    = aPup[2] ;	// 公開開始日付(日)
							}
							continue ;
						}

						// 物件名
						if( aLines[iAcnt].match(/^\<bk_name\>(.+)\<\/bk_name\>$/i) ) {
							aLinesWk = aLines[iAcnt].match(/^\<bk_name\>(.+)\<\/bk_name\>$/i) ;
							if( aLinesWk[1].match(/\[empty\]/i) ) {
								sBkName = "[empty]" ;
							} else {
								sBkName = aLinesWk[1] ;
							}
							continue ;
						}

						// 本文
						if( aLines[iAcnt].match(/^\<topics_str\>(.+)\<\/topics_str\>$/i) ) {
							aLinesWk = aLines[iAcnt].match(/^\<topics_str\>(.+)\<\/topics_str\>$/i) ;
							if( aLinesWk[1].match(/\[empty\]/i) ) {
								sTextStr = "[empty]" ;
							} else {
								sTextStr = aLinesWk[1] ;
								// 改行コードへの置き換え
								sTextStr = sTextStr.replace(/\[:::\]/g,"\n") ;
								// セミコロンへの置き換え
								sTextStr = sTextStr.replace(/\[:6:\]/g,"&") ;
								// セミコロンへの置き換え
								sTextStr = sTextStr.replace(/\[:_:\]/g,";") ;
								// Aタグにtargetを埋め込む
								sTextStr = sTextStr.replace(/(<[aA]) /g,"$1 target=_blank ") ;
							}
							continue ;
						}

						// メッセージ
						if( aLines[iAcnt].match(/^\<message\>(.+)\<\/message\>$/i) ) {
							aLinesWk = aLines[iAcnt].match(/^\<message\>(.+)\<\/message\>$/i) ;
							sMsgStr  = aLinesWk[1] ;
							continue ;
						}

						// エラーコード
						if( aLines[iAcnt].match(/^\<errorno\>(.+)\<\/errorno\>$/i) ) {
							aLinesWk = aLines[iAcnt].match(/^\<errorno\>(.+)\<\/errorno\>$/i) ;
							sErrNo   = aLinesWk[1] ;
							continue ;
						}

					}
//alert( "BK_NAME[" + sBkName + "]" ) ;
//alert( "TOPICS[" + sTextStr + "]" ) ;
//alert( "MSG[" + sMsgStr + "]" ) ;
//alert( "ERRNO[" + sErrNo + "]" ) ;

					// エラーの場合
					if( sMsgStr != "" && sErrNo != "" ) {
						alert( sMsgStr + "[" + sErrNo + "]" ) ;
						continue ;
					}

					/* データ設定 */
					// トピックス本文
					if( sBoxId == "" ) {
						sBoxId = sID_TpStr ;
					}
					oIdTpStr	= document.getElementById( sBoxId ) ;

					/* 文字列置き換え */
					// トピックス本文
					if( typeof oIdTpStr == "object" ) {
						var sContents = "" ;
						if( sTextStr != "[empty]" ) {
							sContents = sTextStr ;
						}

						oIdTpStr.innerHTML = sContents ;
					}

				}

			}

		} else {
			$( "result" ).innerHTML = "<b>通信に失敗しました</b>" ;
		}

	}else{
		$( "result" ).innerHTML = "<b>通信中…</b>" ;
	}

}

/****************************************************************************
 *
 * ajax でデータを取得する
 *
 ****************************************************************************/
function com_getResult_view( sBkNo, sBoxId ) {
	// リクエストオブジェクト生成
	var oHttp = newXMLHttpRequest() ;
//alert( "check" ) ;
	if( !oHttp ) {
//alert( "oHttp false" ) ;
		return false ;
	}

	// 実行URL作成
	oDate = new Date() ;	// キャッシュ対策用の日時
	var sUrl = _sAplUrl_2 ;
	var sPar = _sPaBkno + encodeURI( sBkNo )
						+ "&" + _sPaDd    + encodeURI( oDate.toLocaleString() ) ;
//alert( sUrl + "\n" + sPar ) ;

	// POST メソッド、URL 指定、非同期(=true)
	oHttp.open( "POST", sUrl, true ) ;

	// サーバーからの応答時の処理を定義
	oHttp.onreadystatechange = function() {
//alert( "call response" );
		handle_getTopicsResult_view( oHttp, sBoxId ) ;
	} ;

	// リクエスト送信
	oHttp.setRequestHeader( "content-type"
							, "application/x-www-form-urlencoded;charset=Shift-jis" ) ;
	oHttp.send( sPar ) ;


	return true ;
}

// ---------------------------------------------------------------- //
//  レスポンス関数 ajax 通信完了後に呼び出されるハンドラ
// ---------------------------------------------------------------- //
//  0 = uninitialized
//  1 = loading
//  2 = loaded
//  3 = interactive
//  4 = complete
// ---------------------------------------------------------------- //
function handle_getTopicsResult_view( oHttp, sBoxId ) {

//alert( "check[" + oHttp.readyState + "][" + oHttp.status + "]" ) ;
	if( oHttp.readyState == 4 ) {

		if( oHttp.status == 200 ) {

			var bExecStat = false ;

			var resXML = oHttp.responseText ;

			aLines = resXML.split( "\n" ) ;
//alert( "lines[" + aLines.length + "]" ) ;

			for( iLcnt = 0; iLcnt < aLines.length; iLcnt++ ) {

				sBkName		= "" ;	// 物件名
				sPupDate	= "" ;	// 公開開始日付
				sPupY		= "" ;	// 公開開始日付(年)
				sPupM		= "" ;	// 公開開始日付(月)
				sPupD		= "" ;	// 公開開始日付(日)
				sTextStr	= "" ;	// 本文
				sMsgStr		= "" ;	// メッセージ
				sErrNo		= "" ;	// エラーコード

				if( aLines[iLcnt].match(/^\<\?xml.+$/i) ) {
					continue ;
				}
				if( aLines[iLcnt].match(/^\<[\/]?topics\>$/i) ) {
					continue ;
				}

				if( aLines[iLcnt].match(/^\<\match\>$/i) ) {

					for( iMcnt = 1; iMcnt < aLines.length; iMcnt++ ) {

						iAcnt = iLcnt + iMcnt ;
//alert( "LINE[" + iAcnt + "] [" + aLines[iAcnt] + "]" ) ;
						if( aLines[iAcnt].match(/^\<\/match\>$/i) ) {
							iLcnt = iAcnt ;
							break ;
						}

						// 公開開始日付
						if( aLines[iAcnt].match(/^\<publish_up\>(.+)\<\/publish_up\>$/i) ) {
							aLinesWk = aLines[iAcnt].match(/^\<publish_up\>(.+)\<\/publish_up\>$/i) ;
							if( aLinesWk[1].match(/\[empty\]/i) ) {
								sPupDate = "[empty]" ;
								sPupY    = "" ;			// 公開開始日付(年)
								sPupM    = "" ;			// 公開開始日付(月)
								sPupD    = "" ;			// 公開開始日付(日)
							} else {
								sPupDate = aLines[iAcnt] ;
								aPup     = sPupDate.split( "-" ) ;
								sPupY    = aPup[0] ;	// 公開開始日付(年)
								sPupM    = aPup[1] ;	// 公開開始日付(月)
								sPupD    = aPup[2] ;	// 公開開始日付(日)
							}
							continue ;
						}

						// 物件名
						if( aLines[iAcnt].match(/^\<bk_name\>(.+)\<\/bk_name\>$/i) ) {
							aLinesWk = aLines[iAcnt].match(/^\<bk_name\>(.+)\<\/bk_name\>$/i) ;
							if( aLinesWk[1].match(/\[empty\]/i) ) {
								sBkName = "[empty]" ;
							} else {
								sBkName = aLinesWk[1] ;
							}
							continue ;
						}

						// 本文
						if( aLines[iAcnt].match(/^\<topics_str\>(.+)\<\/topics_str\>$/i) ) {
							aLinesWk = aLines[iAcnt].match(/^\<topics_str\>(.+)\<\/topics_str\>$/i) ;
							if( aLinesWk[1].match(/\[empty\]/i) ) {
								sTextStr = "[empty]" ;
							} else {
								sTextStr = aLinesWk[1] ;
								// 改行コードへの置き換え
								sTextStr = sTextStr.replace(/\[:::\]/g,"\n") ;
								// セミコロンへの置き換え
								sTextStr = sTextStr.replace(/\[:6:\]/g,"&") ;
								// セミコロンへの置き換え
								sTextStr = sTextStr.replace(/\[:_:\]/g,";") ;
								// Aタグにtargetを埋め込む
								sTextStr = sTextStr.replace(/(<[aA]) /g,"$1 target=_blank ") ;
							}
							continue ;
						}

						// メッセージ
						if( aLines[iAcnt].match(/^\<message\>(.+)\<\/message\>$/i) ) {
							aLinesWk = aLines[iAcnt].match(/^\<message\>(.+)\<\/message\>$/i) ;
							sMsgStr  = aLinesWk[1] ;
							continue ;
						}

						// エラーコード
						if( aLines[iAcnt].match(/^\<errorno\>(.+)\<\/errorno\>$/i) ) {
							aLinesWk = aLines[iAcnt].match(/^\<errorno\>(.+)\<\/errorno\>$/i) ;
							sErrNo   = aLinesWk[1] ;
							continue ;
						}

					}
//alert( "BK_NAME[" + sBkName + "]" ) ;
//alert( "TOPICS[" + sTextStr + "]" ) ;
//alert( "MSG[" + sMsgStr + "]" ) ;
//alert( "ERRNO[" + sErrNo + "]" ) ;

					// エラーの場合
					if( sMsgStr != "" && sErrNo != "" ) {
						alert( sMsgStr + "[" + sErrNo + "]" ) ;
						continue ;
					}

					/* データ設定 */
					// トピックス本文
					if( sBoxId == "" ) {
						sBoxId = sID_TpStr ;
					}
					oIdTpStr	= document.getElementById( sBoxId ) ;

					/* 文字列置き換え */
					// トピックス本文
					if( typeof oIdTpStr == "object" ) {
						var sContents = "" ;
						if( sTextStr != "[empty]" ) {
							sContents = sTextStr ;
						}

						oIdTpStr.innerHTML = sContents ;
					}

				}

			}

		} else {
			$( "result" ).innerHTML = "<b>通信に失敗しました</b>" ;
		}

	}else{
		$( "result" ).innerHTML = "<b>通信中…</b>" ;
	}

}
/******************************************************************************/

