/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | JavaScript                                                           |
// +----------------------------------------------------------------------+
// | Copyright (c) 2006 EXT. All rights reserved.                         |
// +----------------------------------------------------------------------+
// | スクリプトの著作権は株式会社エクスト及び作成者に帰属します。         |
// | 無断配布・コピー・改造等は一切禁止します。　　　　                   |
// | 文字コード：UTF-8                                                    |
// | 改行コード：LF                                                       |
// +----------------------------------------------------------------------+
// | Authors: EXT Developments Team  T.Tabata <develop@ext.ne.jp>         |
// +----------------------------------------------------------------------+
//
// $Id: master.js,v 1.2 2007/03/15 08:44:01 tabata Exp $
//
// 共通JSライブラリ

/**
 * ジャンル取得関数
 * 
 * @param string	$_tmpBaseUrl		ベースURL
 * @param integer	$_tmpCategoryCode	カテゴリコード
 * @param string	$_tmpGenreID		ジャンル設定リストボックスID属性名
 * @return void
 */
function getGenreList($_tmpBaseUrl, $_tmpCategoryCode, $_tmpGenreID)
{
	if ($_tmpGenreID) {
		$GenreID = $_tmpGenreID;
	} else {
		$GenreID = 'genre';
	}

	$_optionsLength = document.getElementById($GenreID).options.length;

	for ($_tmpI=1; $_tmpI<$_optionsLength; $_tmpI++)
	{
		document.getElementById($GenreID).options[1] = null;
	}

	if ($_tmpCategoryCode > 0) {
		var oJsr = new JSONscriptRequest($_tmpBaseUrl + 'JavaScript/GenreList/' + $_tmpCategoryCode + '/');
		oJsr.buildScriptTag();
		oJsr.addScriptTag();
	}
}

/**
 * ジャンルリストコールバック関数
 * 
 * @param string	$_tmpJSON	JSON形式ジャンルリスト
 * @return void
 */
function GenreListCallBack($_tmpJSON)
{
	$_i = 0;
	
	while ($_tmpValue = $_tmpJSON[$_i]) {
		document.getElementById($GenreID).options[$_i + 1] = new Option(decodeURIComponent($_tmpValue['name']), $_tmpValue['code']);
		$_i++;
	}
}

/**
 * 駅名取得関数
 * 
 * @param string	$_tmpBaseUrl			ベースURL
 * @param integer	$_tmpArrayNumber		駅名リストボックス設定配列番号
 * @param integer	$_tmpStationLineCode	路線コード
 * @return void
 */
function getStationList($_tmpBaseUrl, $_tmpArrayNumber, $_tmpStationLineCode)
{
	$GlobalsArrayNumber = $_tmpArrayNumber;
	$_optionsLength = document.getElementById('station[' + $GlobalsArrayNumber + ']').options.length;

	for ($_tmpI=1; $_tmpI<$_optionsLength; $_tmpI++)
	{
		document.getElementById('station[' + $GlobalsArrayNumber + ']').options[1] = null;
	}

	if ($_tmpStationLineCode > 0) {
		var oJsr = new JSONscriptRequest($_tmpBaseUrl + 'JavaScript/StationList/' + $_tmpStationLineCode + '/');
		oJsr.buildScriptTag();
		oJsr.addScriptTag();
	}
}

/**
 * 駅名リストコールバック関数
 * 
 * @param string	$_tmpJSON	JSON形式駅名リスト
 * @return void
 */
function StationListCallBack($_tmpJSON)
{
	$_i = 0;

	while ($_tmpValue = $_tmpJSON[$_i]) {
		document.getElementById('station[' + $GlobalsArrayNumber + ']').options[$_i + 1] = new Option(decodeURIComponent($_tmpValue['name']), $_tmpValue['code']);
		$_i++;
	}
}

/**
 * 携帯にメール送信
 * 
 * @param $_tmpBaseUrl
 * @param $_tmpMailDomain
 * @param $_tmpMailAddress
 * @return void
 */
function MobileMail($_tmpBaseUrl, $_tmpMailDomain, $_tmpMailAddress)
{
	if (!$_tmpMailAddress) {
		alert('@より前のアドレスを入力してください。');
		return false;
	} else if (!$_tmpMailAddress.match(/^[_A-Za-z0-9-]+[\._A-Za-z0-9-]*$/)) {
		alert('書式が間違っています。');
		return false;
	}
	
	if (!$_tmpMailDomain) {
		alert('ドメインを選択してください。');
	}

	if (confirm('送信します。よろしいですか？\nドメイン拒否設定をしている方は\n「arukusize.com」のドメインを許可してください。')) {
		var oJsr = new JSONscriptRequest($_tmpBaseUrl + 'JavaScript/MobileSendMail/' + $_tmpMailDomain + '/' + encodeURI($_tmpMailAddress) + '/');
		oJsr.buildScriptTag();
		oJsr.addScriptTag();
		
		return true;
	} else {
		return false;
	}
}

/**
 * 携帯にスポット詳細ページの URL をメール送信
 * 
 * @param $_tmpBaseUrl
 * @param $_tmpMailDomain
 * @param $_tmpMailAddress
 * @return void
 */
function MobileMailSpot($_tmpBaseUrl, $_tmpMailDomain, $_tmpMailAddress, $_tmpSpotCode)
{
	if (!$_tmpMailAddress) {
		alert('@より前のアドレスを入力してください。');
		return false;
	} else if (!$_tmpMailAddress.match(/^[_A-Za-z0-9-]+[\._A-Za-z0-9-]*$/)) {
		alert('書式が間違っています。');
		return false;
	}
	
	if (!$_tmpMailDomain) {
		alert('ドメインを選択してください。');
	}
	if (!$_tmpSpotCode) {
		alert('スポット詳細ページから操作してください。');
	}
	
	if (confirm('送信します。よろしいですか？\nドメイン拒否設定をしている方は\n「arukusize.com」のドメインを許可してください。')) {
		var oJsr = new JSONscriptRequest($_tmpBaseUrl + 'JavaScript/MobileSendMail/' + $_tmpMailDomain + '/' + encodeURI($_tmpMailAddress) + '/' + $_tmpSpotCode + '/');
		oJsr.buildScriptTag();
		oJsr.addScriptTag();
		
		return true;
	} else {
		return false;
	}
}

/**
 * 携帯にメール送信コールバック関数
 * 
 * @param $_tmpJSON
 * @return void
 */
function MobileSendMailCallBack($_tmpJSON)
{
	switch ($_tmpJSON[0]) {
		case 'true':
			alert('送信しました。');
			break;
		
		case 'mailError':
			alert('エラーが発生しました。再度送信してください。');
			break;
		
		case 'timeOver':
			alert('連続送信は出来ません。');
			break;
	}
}

/**
 * QuestionnaireCheck
 * 
 * @param $_tmpCheckID
 * @param $_tmpMethod
 * @return void
 */
function QuestionnaireCheck($_tmpCheckID, $_tmpMethod)
{
	$Flag = false;

	for ($i = 0; $i < document.questionForm.elements.length; $i++) {
		if (document.questionForm.elements[$i].checked) {
			$Flag = true;
		}
	}
	
	if ($Flag) {
		document.questionForm.submit();
	} else {
		alert('回答を選んでください。');
	}
}
