﻿/*********************************************************
（このファイルはUTF-8で保存すること）
*********************************************************/



/*********************************************************
	検索フォームを要求

count　→　１ページあたり何件表示するかを指定する。
result_template　→　検索結果表示に使用するテンプレートファイル名を指定する。指定しない場合は''を渡す（その場合はsearch.tplが使用される）
form_template　→　検索フォーム表示に使用するテンプレートファイル名を指定する。指定しない場合は''を渡す（その場合はget_search_form.tplが使用される）
hdst1　→　目的地（地域）のコードを' 'で囲って指定する。指定しない場合は''を渡す。
hdst2　→　目的地（国）のコードを' 'で囲って指定する。指定しない場合は''を渡す。

*********************************************************/
function get_form_html(count, result_template, form_template, hdst1, hdst2)
{
	sendData  = "count=" + encodeURI( count );
	sendData += "&result_template=" + encodeURI( result_template );
	sendData += "&form_template=" + encodeURI( form_template );
	sendData += "&hdst[0]=" + encodeURI( hdst1 );
	sendData += "&hdst[1]=" + encodeURI( hdst2 );
	httpObj = createXMLHttpRequest( fetch_form_html );
	if ( httpObj ){
		httpObj.open( "POST", "/ajax/get_search_form.php", true );
		httpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	//この指定が無いとリクエストを受け付けない処理系もあるので
		httpObj.send( sendData );
	}
}

/*********************************************************
	検索フォームを受信＆表示
*********************************************************/
function fetch_form_html()
{
	if ( ( httpObj.readyState == 4 ) && ( httpObj.status == 200 ) ){
		//JSONのデータを解析して表示する
		jsData = httpObj.responseText;
		data = eval("("+jsData+")");
		if ( data.output_html ){
			if ( isOpera() ){	//Opera
				var main_form = eval( 'document.all.main_form' );
				main_form.innerHTML = data.output_html;
			}
			else{
				var main_form = document.getElementById( 'main_form' );
				main_form.innerHTML = data.output_html;
			}
		}
	}
}


/*********************************************************
	地域選択⇒選択された地域の国を要求
*********************************************************/
function select_area()
{
	if ( document.feelabroad_search_form.elements['hdst[0]'].value ){
		sendData  = "area=" + encodeURI( document.feelabroad_search_form.elements['hdst[0]'].value );
		httpObj = createXMLHttpRequest( fetch_countries );
		if ( httpObj ){
			httpObj.open( "POST", "/ajax/get_countries.php", true );
			httpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	//この指定が無いとリクエストを受け付けない処理系もあるので
			httpObj.send( sendData );
		}
	}
	document.feelabroad_search_form.elements['hdst[1]'].length = 0;
	document.feelabroad_search_form.elements['hdst[2]'].length = 0;
}

/*********************************************************
	国を受信＆プルダウンに表示
*********************************************************/
function fetch_countries()
{
	if ( ( httpObj.readyState == 4 ) && ( httpObj.status == 200 ) ){
		//JSONのデータを解析して表示する
		jsData = httpObj.responseText;
		data = eval("("+jsData+")");
		if ( data.countries_array ){
			document.feelabroad_search_form.elements['hdst[1]'].length = 0;
			for ( i = 0; i < data.countries_array.length; i ++ ){
				idx = document.feelabroad_search_form.elements['hdst[1]'].length;
				document.feelabroad_search_form.elements['hdst[1]'].length ++;
				document.feelabroad_search_form.elements['hdst[1]'].options[idx].text = data.countries_array[i].country_name;	//国名
				document.feelabroad_search_form.elements['hdst[1]'].options[idx].value = data.countries_array[i].country_code;	//国コード
			}
		}
		else{
			document.feelabroad_search_form.elements['hdst[1]'].length = 0;
			document.feelabroad_search_form.elements['hdst[2]'].length = 0;
		}
	}
}

/*********************************************************
	国選択⇒選択された国の都市を要求
*********************************************************/
function select_country()
{
	if ( document.feelabroad_search_form.elements['hdst[1]'].value ){
		sendData  =  "area=" + encodeURI( document.feelabroad_search_form.elements['hdst[0]'].value );
		sendData  += "&country=" + encodeURI( document.feelabroad_search_form.elements['hdst[1]'].value );
		httpObj = createXMLHttpRequest( fetch_cities );
		if ( httpObj ){
			httpObj.open( "POST", "/ajax/get_cities.php", true );
			httpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	//この指定が無いとリクエストを受け付けない処理系もあるので
			httpObj.send( sendData );
		}
	}
	document.feelabroad_search_form.elements['hdst[2]'].length = 0;
}

/*********************************************************
	都市を受信＆プルダウンに表示
*********************************************************/
function fetch_cities()
{
	if ( ( httpObj.readyState == 4 ) && ( httpObj.status == 200 ) ){
		//JSONのデータを解析して表示する
		jsData = httpObj.responseText;
		data = eval("("+jsData+")");
		if ( data.cities_array ){
			document.feelabroad_search_form.elements['hdst[2]'].length = 0;
			for ( i = 0; i < data.cities_array.length; i ++ ){
				idx = document.feelabroad_search_form.elements['hdst[2]'].length;
				document.feelabroad_search_form.elements['hdst[2]'].length ++;
				document.feelabroad_search_form.elements['hdst[2]'].options[idx].text = data.cities_array[i].city_name;	//都市名
				document.feelabroad_search_form.elements['hdst[2]'].options[idx].value = data.cities_array[i].city_code;	//都市コード
			}
		}
		else{
			document.feelabroad_search_form.elements['hdst[2]'].length = 0;
		}
	}
}


/*********************************************************
	検索実行

count　→　１ページあたり何件表示するかを指定する。
result_template　→　検索結果表示に使用するテンプレートファイル名を指定する。指定しない場合は''を渡す（その場合はsearch.tplが使用される）

*********************************************************/
function do_search( page_number, count, result_template )
{
	sendData  =  "dap=" + encodeURI( document.feelabroad_search_form.dap.value );
	sendData  += "&hdst[0]=" + encodeURI( document.feelabroad_search_form.elements['hdst[0]'].value );
	sendData  += "&hdst[1]=" + encodeURI( document.feelabroad_search_form.elements['hdst[1]'].value );
	sendData  += "&hdst[2]=" + encodeURI( document.feelabroad_search_form.elements['hdst[2]'].value );
	for ( i = 0; i < document.feelabroad_search_form.elements['scs[]'].length; i ++ ){
		if ( document.feelabroad_search_form.elements['scs[]'][i].checked ){
			sendData  += "&scs[]=" + encodeURI( document.feelabroad_search_form.elements['scs[]'][i].value );
		}
	}
	sendData  += "&ym=" + encodeURI( document.feelabroad_search_form.ym.value );
	sendData  += "&aln=" + encodeURI( document.feelabroad_search_form.aln.value );
	sendData  += "&prl=" + encodeURI( document.feelabroad_search_form.prl.value );
	sendData  += "&pru=" + encodeURI( document.feelabroad_search_form.pru.value );
	for ( i = 0; i < document.feelabroad_search_form.elements['tp'].length; i ++ ){
		if ( document.feelabroad_search_form.elements['tp'][i].checked ){
			sendData  += "&tp=" + encodeURI( document.feelabroad_search_form.elements['tp'][i].value );
		}
	}
	sendData  += "&p=" + encodeURI( page_number );
	sendData  += "&result_template=" + encodeURI( result_template );
	sendData  += "&count=" + encodeURI( count );
	httpObj = createXMLHttpRequest( fetch_search_result );
	if ( httpObj ){
		httpObj.open( "POST", "/ajax/search.php", true );
		httpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	//この指定が無いとリクエストを受け付けない処理系もあるので
		httpObj.send( sendData );
		if ( isOpera() ){	//Opera
			var main_contents = eval( 'document.all.main_contents' );
			main_contents.innerHTML = "<div align='center' style='padding:50px;'><img src='ajax/ajax-loader.gif'></div>";
		}
		else{
			var main_contents = document.getElementById( 'main_contents' );
			main_contents.innerHTML = "<div align='center' style='padding:50px;'><img src='ajax/ajax-loader.gif'></div>";
		}
	}
pageTracker._trackPageview(sendData );
}

/*********************************************************
	検索結果を受信＆表示
*********************************************************/
function fetch_search_result()
{
	if ( ( httpObj.readyState == 4 ) && ( httpObj.status == 200 ) ){
		//JSONのデータを解析して表示する
		jsData = httpObj.responseText;
		data = eval("("+jsData+")");
		if ( data.output_html ){
			if ( isOpera() ){	//Opera
				var main_contents = eval( 'document.all.main_contents' );
				main_contents.innerHTML = data.output_html;
			}
			else{
				var main_contents = document.getElementById( 'main_contents' );
				main_contents.innerHTML = data.output_html;
			}
		}
	}
}



/*********************************************************
	詳細表示
*********************************************************/
function show_detail( cid, year, month , count, result_template, form_template, hdst1, hdst2 )
{
	sendData  =  "cid=" + encodeURI( cid );
	if ( year != "" ){
		sendData  += "&y=" + encodeURI( year );
	}
	if ( month != "" ){
		sendData  += "&m=" + encodeURI( month );
	}
	sendData += "&count=" + encodeURI( count );
	sendData += "&result_template=" + encodeURI( result_template );
	sendData += "&form_template=" + encodeURI( form_template );
	sendData += "&hdst[0]=" + encodeURI( hdst1 );
	sendData += "&hdst[1]=" + encodeURI( hdst2 );
	httpObj = createXMLHttpRequest( fetch_detail );
	if ( httpObj ){
		httpObj.open( "POST", "/ajax/get_detail.php", true );
		httpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	//この指定が無いとリクエストを受け付けない処理系もあるので
		httpObj.send( sendData );
	}
}


/*********************************************************
	詳細表示を受信＆表示
*********************************************************/
function fetch_detail()
{
	if ( ( httpObj.readyState == 4 ) && ( httpObj.status == 200 ) ){
		//JSONのデータを解析して表示する
		jsData = httpObj.responseText;
		data = eval("("+jsData+")");
		if ( data.output_html ){
			if ( isOpera() ){	//Opera
				var course_detail = eval( 'document.all.course_detail' );
				course_detail.innerHTML = data.output_html;
			}
			else{
				var course_detail = document.getElementById( 'course_detail' );
				course_detail.innerHTML = data.output_html;
			}
		}
		if ( data.search_form_html ){
			if ( isOpera() ){	//Opera
				var main_form = eval( 'document.all.main_form' );
				main_form.innerHTML = data.search_form_html;
			}
			else{
				var main_form = document.getElementById( 'main_form' );
			 	main_form.innerHTML = data.search_form_html;
			}
		}
	}
}



/*********************************************************
	IEか？
*********************************************************/
function isIE()
{
	str = navigator.appName.toUpperCase();
	if ( str.indexOf("EXPLORER") >= 0 ){
		return true;
	}
	else{
		return false;
	}
}

/*********************************************************
	Operaか？
*********************************************************/
function isOpera()
{
	if ( navigator.userAgent.indexOf("Opera") != -1 ){	//Opera
		return true;
	}
	else{
		return false;
	}
}

