// Require prototype.js
// Require function.js
// Require wsse.js
// Require Condition.js
// Require Blogsearch.js

var Landmark = Class.create();

Landmark.prototype = {

	initialize  : function() {
		this.dict = {};
		this.conditionList = [];
		this.blogsearchList = [];
		this.landmarkRssList = [];
    },

	setDict : function(value) {
		this.dict = value;

		//検索条件を分解
		if ( this.dict['conditionList'] ) {

			var list = this.dict['conditionList'].condition;
			if ( list ) {
				for(var idx=0;idx < list.length;idx++) {
					var condition = new Condition();
					condition.setDict( list[idx] );
					this.conditionList.push(condition);
				}
			}
		}

		//ブログ検索を分解
		if ( this.dict['blogsearchList'] ) {

			var list = this.dict['blogsearchList'].blogsearch;
			if ( list ) {
				for(var idx=0;idx < list.length;idx++) {
					var blog = new Blogsearch();
					blog.setDict( list[idx] );
					this.blogsearchList.push(blog);
				}
			}
		}

	},

	// - - - - - - - - - - - - - - - - - - - - -
	//登録日時

	setCreate_tstmp : function(value) {
		this.dict['create_tstmp'] = trim(value);
	},
	getCreate_tstmp : function() {
		return this.dict['create_tstmp'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//更新日時

	setUpdate_tstmp : function(value) {
		this.dict['update_tstmp'] = trim(value);
	},
	getUpdate_tstmp : function() {
		return this.dict['update_tstmp'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//ランドマークＩＤ

	setId : function(value) {
		this.dict['id'] = trim(value);
	},
	getId : function() {
		return this.dict['id'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//有効区分

	setEnable : function(value) {
		this.dict['enable'] = trim(value);
	},
	getEnable : function() {
		return this.dict['enable'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//区分

	setLandmark_class : function(value) {
		this.dict['landmark_class'] = trim(value);
	},
	getLandmark_class : function() {
		return this.dict['landmark_class'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//リンク区分

	setLink_class : function(value) {
		this.dict['link_class'] = trim(value);
	},
	getLink_class : function() {
		return this.dict['link_class'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//リンク先スポットID

	setLink_id : function(value) {
		this.dict['link_id'] = trim(value);
	},
	getLink_id : function() {
		return this.dict['link_id'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//メールアドレス

	setMail : function(value) {
		this.dict['mail'] = trim(value);
	},
	getMail : function() {
		return this.dict['mail'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//パスワード

	setPassword : function(value) {
		this.dict['password'] = trim(value);
	},
	getPassword : function() {
		return this.dict['password'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//名称

	setName : function(value) {
		this.dict['name'] = trim(value);
	},
	getName : function() {
		return this.dict['name'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//名称かな

	setKana : function(value) {
		this.dict['kana'] = trim(value);
	},
	getKana : function() {
		return this.dict['kana'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//略称

	setNickname : function(value) {
		this.dict['nickname'] = trim(value);
	},
	getNickname : function() {
		return this.dict['nickname'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//Name

	setEname : function(value) {
		this.dict['ename'] = trim(value);
	},
	getEname : function() {
		return this.dict['ename'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//郵便番号

	setZip : function(value) {
		this.dict['zip'] = replaceAll(trim(value), "-", "");
	},
	getZip : function() {
		return this.dict['zip'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//住所１

	setAdd1 : function(value) {
		this.dict['add1'] = trim(value);
	},
	getAdd1 : function() {
		return this.dict['add1'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//住所２

	setAdd2 : function(value) {
		this.dict['add2'] = trim(value);
	},
	getAdd2 : function() {
		return this.dict['add2'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//住所３

	setAdd3 : function(value) {
		this.dict['add3'] = trim(value);
	},
	getAdd3 : function() {
		return this.dict['add3'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//電話番号

	setTel : function(value) {
		if ( value ) {
			value = replaceAll( replaceAll( trim(value), "(", ""), ")", "");
		}
		this.dict['tel'] = trim(value);
	},
	getTel : function() {
		return this.dict['tel'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//FAX番号

	setFax : function(value) {
		if ( value ) {
			value = replaceAll( replaceAll( trim(value), "(", ""), ")", "");
		}
		this.dict['fax'] = trim(value);
	},
	getFax : function() {
		return this.dict['fax'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//URL

	setUrl : function(value) {
		this.dict['url'] = trim(value);
	},
	getUrl : function() {
		return this.dict['url'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//ブログRSS

	setBlogrss : function(value) {
		this.dict['blogrss'] = trim(value);
	},
	getBlogrss : function() {
		return this.dict['blogrss'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//営業時間

	setBizhours : function(value) {
		this.dict['bizhours'] = trim(value);
	},
	getBizhours : function() {
		return this.dict['bizhours'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//定休日

	setHoliday : function(value) {
		this.dict['holiday'] = trim(value);
	},
	getHoliday : function() {
		return this.dict['holiday'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//緯度

	setLatitude : function(value) {
		this.dict['latitude'] = trim(value);
	},
	getLatitude : function() {
		return this.dict['latitude'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//経度

	setLongitude : function(value) {
		this.dict['longitude'] = trim(value);
	},
	getLongitude : function() {
		return this.dict['longitude'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//全国地方公共団体コード

	setArea_code : function(value) {
		value = trim(value);
		if (value) {
			this.dict['area_code1'] = value;
			if (value.length > 1) {
				this.dict['area_code2'] = value.substring(0,2);
			}
		}
	},
	getArea_code : function() {
		return this.dict['area_code1'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//全国地方公共団体コード１

	setArea_code1 : function(value) {
		this.dict['area_code1'] = trim(value);
	},
	getArea_code1 : function() {
		return this.dict['area_code1'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//全国地方公共団体コード２

	setArea_code2 : function(value) {
		this.dict['area_code2'] = trim(value);
	},
	getArea_code2 : function() {
		return this.dict['area_code2'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//カテゴリ１

	setCategory1 : function(value) {
		this.dict['category1'] = trim(value);
	},
	getCategory1 : function() {
		return this.dict['category1'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//カテゴリ２

	setCategory2 : function(value) {
		this.dict['category2'] = trim(value);
	},
	getCategory2 : function() {
		return this.dict['category2'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//カテゴリ３

	setCategory3 : function(value) {
		this.dict['category3'] = trim(value);
	},
	getCategory3 : function() {
		return this.dict['category3'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//カテゴリ文字列

	getCategoryStr : function() {
		var ret = this.dict['category1'];
		if (this.dict['category2']) {
			if (ret) ret += " / ";
			ret += this.dict['category2'];
		}
		if (this.dict['category3']) {
			if (ret) ret += " / ";
			ret += this.dict['category3'];
		}
		return ret;
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//設立
	setBirthday : function(y, m, s) {
		if ((y) && (m) && (s)) {
			this.dict['birthday'] = y + "-" + m + "-" + s;
		} else {
			this.dict['birthday'] = "";
		}
	},
	getBirthday : function() {
		return this.dict['birthday'];
	},

	getBirthday_y : function() {
		if ( this.dict['birthday'] ) {
			return this.dict['birthday'].split("-")[0];
		}
		return '';
	},

	getBirthday_m : function() {
		if ( this.dict['birthday'] ) {
			return this.dict['birthday'].split("-")[1];
		}
		return '';
	},

	getBirthday_d : function() {
		if ( this.dict['birthday'] ) {
			return this.dict['birthday'].split("-")[2];
		}
		return '';
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//説明

	setSummary : function(value) {
		this.dict['summary'] = trim(value);
	},
	getSummary : function() {
		return this.dict['summary'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//閲覧回数

	getViewcount : function() {
		return this.dict['viewcount'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//ご近所Pickup区分

	setEnablepickup : function(value) {
		this.dict['enablepickup'] = trim(value);
	},
	getEnablepickup : function() {
		return this.dict['enablepickup'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//ご近所Pickupメッセージ

	setPickupmsg : function(value) {
		this.dict['pickupmsg'] = trim(value);
	},
	getPickupmsg : function() {
		return this.dict['pickupmsg'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//ご近所Pickup写真ファイル名

	setPickupphoto : function(value) {
		this.dict['pickupphoto'] = trim(value);
	},
	getPickupphoto : function() {
		return this.dict['pickupphoto'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//ご近所Pickup表示頻度

	setPickuprate : function(value) {
		this.dict['pickuprate'] = trim(value);
	},
	getPickuprate : function() {
		return this.dict['pickuprate'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//ご近所Pickup表示回数

	setPickupcount : function(value) {
		this.dict['pickupcount'] = trim(value);
	},
	getPickupcount : function() {
		return this.dict['pickupcount'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//有料記事区分

	setEnablecommercial : function(value) {
		this.dict['enablecommercial'] = trim(value);
	},
	getEnablecommercial : function() {
		return this.dict['enablecommercial'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//取得半径

	setScope : function(value) {
		this.dict['scope'] = trim(value);
	},
	getScope : function() {
		return this.dict['scope'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//記事の有無

	setHastopic : function(value) {
		this.dict['hastopic'] = trim(value);
	},
	getHastopic : function() {
		return this.dict['hastopic'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//記事数

	setNumtopic : function(value) {
		this.dict['numtopic'] = trim(value);
	},
	getNumtopic : function() {
		return this.dict['numtopic'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//クーポンの有無

	setHascoupon : function(value) {
		this.dict['hascoupon'] = trim(value);
	},
	getHascoupon : function() {
		return this.dict['hascoupon'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//求人の有無

	setHasjob : function(value) {
		this.dict['hasjob'] = trim(value);
	},
	getHasjob : function() {
		return this.dict['hasjob'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//	新規記事あり(int)

	setHasnewtopic : function(value) {
		this.dict['hasnewtopic'] = trim(value);
	},
	getHasnewtopic : function() {
		return this.dict['hasnewtopic'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//	ブログ有り(int)

	setHasblog : function(value) {
		this.dict['hasblog'] = trim(value);
	},
	getHasblog : function() {
		return this.dict['hasblog'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//	口コミ有り(int)

	setHasbbs : function(value) {
		this.dict['hasbbs'] = trim(value);
	},
	getHasbbs : function() {
		return this.dict['hasbbs'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//ロゴ写真ファイル名

	setLogo_photo : function(value) {
		this.dict['logo_photo'] = trim(value);
	},
	getLogo_photo : function() {
		return this.dict['logo_photo'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//写真1ファイル名

	setPhoto1 : function(value) {
		this.dict['photo1'] = trim(value);
	},
	getPhoto1 : function() {
		return this.dict['photo1'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//写真2ファイル名

	setPhoto2 : function(value) {
		this.dict['photo2'] = trim(value);
	},
	getPhoto2 : function() {
		return this.dict['photo2'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//写真3ファイル名

	setPhoto3 : function(value) {
		this.dict['photo3'] = trim(value);
	},
	getPhoto3 : function() {
		return this.dict['photo3'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//写真4ファイル名

	setPhoto4 : function(value) {
		this.dict['photo4'] = trim(value);
	},
	getPhoto4 : function() {
		return this.dict['photo4'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//駐車場

	setParking : function(value) {
		this.dict['parking'] = trim(value);
	},
	getParking : function() {
		return this.dict['parking'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//オーナー

	setOwnerid : function(value) {
		this.dict['ownerid'] = trim(value);
	},
	getOwnerid : function() {
		return this.dict['ownerid'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//メモ

	setMemo : function(value) {
		this.dict['memo'] = trim(value);
	},
	getMemo : function() {
		return this.dict['memo'];
	},

	// - - - - - - - - - - - - - - - - - - - - - - -
	//業種詳細

	getBiztype : function() {
		return this.dict['biztype'];
	},
	setBiztype : function(value) {
		this.dict['biztype'] = trim(value);
	},

	// - - - - - - - - - - - - - - - - - - - - - - -
	//配達サービス(INT)

	getDelivery : function() {
		return this.dict['delivery'];
	},
	setDelivery : function(value) {
		this.dict['delivery'] = trim(value);
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - -
	//責任者名

	getSupervisor : function() {
		return this.dict['supervisor'];
	},
	setSupervisor : function(value) {
		this.dict['supervisor'] = trim(value);
	},

	// - - - - - - - - - - - - - - - - - - - - - - -
	//責任者名カナ

	getSupervisorkana : function() {
		return this.dict['supervisorkana'];
	},
	setSupervisorkana : function(value) {
		this.dict['supervisorkana'] = trim(value);
	},

	// - - - - - - - - - - - - - - - - - - - - - - -
	//担当者名
	
	getPic : function() {
		return this.dict['pic'];
	},
	setPic : function(value) {
		this.dict['pic'] = trim(value);
	},

	// - - - - - - - - - - - - - - - - - - - - - - -
	//担当者名カナ
	
	getPickana : function() {
		return this.dict['pickana'];
	},
	setPickana : function(value) {
		this.dict['pickana'] = trim(value);
	},

	// - - - - - - - - - - - - - - - - - - - - - - -
	//R500M担当者名
	
	getR500mpic : function() {
		return this.dict['r500mpic'];
	},
	setR500mpic : function(value) {
		this.dict['r500mpic'] = trim(value);
	},

	// - - - - - - - - - - - - - - - - - - - - - - -
	//R500M担当者メール
	
	getR500mmail : function() {
		return this.dict['r500mmail'];
	},
	setR500mmail : function(value) {
		this.dict['r500mmail'] = trim(value);
	},

	// - - - - - - - - - - - - - - - - - - - - - - -
	//スポット情報表示

	getDisplayable : function() {
		return this.dict['displayable'];
	},
	setDisplayable : function(value) {
		this.dict['displayable'] = trim(value);
	},

	// - - - - - - - - - - - - - - - - - - - - - - -
	//地名

	getAddname : function() {
		return this.dict['addname'];
	},
	setAddname : function(value) {
		this.dict['addname'] = trim(value);
	},

	// - - - - - - - - - - - - - - - - - - - - - - -
	//最寄り駅ID

	getStation_id : function() {
		return this.dict['station_id'];
	},
	setStation_id : function(value) {
		this.dict['station_id'] = trim(value);
	},

	// - - - - - - - - - - - - - - - - - - - - - - -
	//最寄り駅名

	getStation_name : function() {
		return this.dict['station_name'];
	},
	setStation_name : function(value) {
		this.dict['station_name'] = trim(value);
	},

	// - - - - - - - - - - - - - - - - - - - - - - -
	//同一名称ランドマーク有無

	getHassamename : function() {
		return this.dict['hassamename'];
	},
	setHassamename : function(value) {
		this.dict['hassamename'] = trim(value);
	},

	// - - - - - - - - - - - - - - - - - - - - - - -
	//同一略称ランドマーク有無	

	getHassamenickname : function() {
		return this.dict['hassamenickname'];
	},
	setHassamenickname : function(value) {
		this.dict['hassamenickname'] = trim(value);
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//検索条件リスト

	getConditionList : function() {
		return this.conditionList;
	},

	clearConditionList : function() {
		this.conditionList = [];
	},

	addCondition : function(type, value) {

		var condition = new Condition();

		//検索条件種別
		condition.setType( type );

		//検索条件
		condition.setValue( value );

		//緯度
		condition.setLatitude( this.dict['latitude'] );

		//経度
		condition.setLongitude( this.dict['longitude'] );

		//登録種別
		condition.setObject_type( this.dict['landmark_class'] );

		//登録者コード
		condition.setObject_id( this.dict['id'] );

		this.conditionList.push(condition);
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//ブログ検索リスト

	getBlogsearchList : function() {
		return this.blogsearchList;
	},

	clearBlogsearchList : function() {
		this.blogsearchList = [];
	},

	deleteBlogsearchList : function(type) {
		var blogArray = [];
		if ( this.blogsearchList.length > 0 ) {
			for(var idx=0;idx < this.blogsearchList.length;idx++) {
				var blog = this.blogsearchList[idx];
				if (blog.getType() != type) {
					blogArray.push( blog );
				}
			}
		}
		this.blogsearchList = blogArray;
	},

	getBlogsearchListType : function(type) {
		var blogArray = [];
		if ( this.blogsearchList.length > 0 ) {
			for(var idx=0;idx < this.blogsearchList.length;idx++) {
				var blog = this.blogsearchList[idx];
				if (blog.getType() == type) {
					blogArray.push( blog );
				}
			}
		}
		return blogArray;
	},

	addBlogsearch : function(type, enable, num, id, blog_num, blog_type, blog_word_and, blog_word_or, blog_word_not) {

		var blogsearch = new Blogsearch();

		//検索条件種別
		blogsearch.setType( type );

		//有効区分
		blogsearch.setEnable( enable );

		//番号
		blogsearch.setNum( num );

		//ランドマークＩＤ
		blogsearch.setId( id );

		//ブログ取得数
		blogsearch.setBlog_num( blog_num );

		//ブログ検索種別
		blogsearch.setBlog_type( blog_type );

		//ブログANDキーワード
		blogsearch.setBlog_word_and( blog_word_and );

		//ブログORキーワード
		blogsearch.setBlog_word_or( blog_word_or );

		//ブログNOTキーワード
		blogsearch.setBlog_word_not( blog_word_not );

		this.blogsearchList.push(blogsearch);
	},

	selectBlogsearchList : function(type) {

		if ( this.blogsearchList.length > 0 ) {
			for(var idx=0;idx < this.blogsearchList.length;idx++) {
				var blog = this.blogsearchList[idx];
				if (blog.getType() == type) {
					blog.setEnable( '1' );
				} else {
					blog.setEnable( '0' );
				}
			}
		}

		this.dict['blogsearchselect'] = type;
	},

	// - - - - - - - - - - - - - - - - - - - - - - -
	//ブログ検索選択

	getBlogsearchselect : function() {
		return this.dict['blogsearchselect'];
	},
	setBlogsearchselect : function(value) {
		this.dict['blogsearchselect'] = trim(value);
	},
	
	getLandmarkRss : function() {
		result = [];
		d = this.dict['landmarkRssList'];
		if (d['landmarkRss'] == null) {
			return result;
		}
		lr = d['landmarkRss'];
		for (var i = 0; i < lr.length; i++) {
			v = lr[i];
			result.push({'rss_url' : v['rss_url'],
				     'topic_category1' : v['topic_category1'],
				     'topic_category2' : v['topic_category2']});
		}
		return result;
	},
	setLandmarkRss : function (v) {
		this.landmarkRssList = v;
	},
	

	// - - - - - - - - - - - - - - - - - - - - -
	//バリデーションチェック

	validate : function() {

		var errmsg = "";

		//名称(全角)
		if ( ! this.dict['name'] ) {
			errmsg += "・名称を入力してください。\n";
		}
		else if ( ! checkZenkaku(this.dict['name']) ) {
			errmsg += "・名称を全角文字で入力してください。\n";
		}

		//名称かな(全角かな)
		if (( this.dict['kana'] ) && (! checkZenkaku(this.dict['kana']))) {
			errmsg += "・名称かな(全角かな)は全角文字で入力してください。\n";
		}

		//カテゴリ
/*
		if ( ! this.dict['category1'] ) {
			errmsg += "・カテゴリを設定してください。\n";
		}
*/

		//英字名(半角英数字)
/*
		if (( this.dict['ename'] ) && (! checkHankaku(this.dict['ename']))) {
			errmsg += "・英字名は半角英数字で入力してください。\n";
		}
*/

		//郵便番号(半角数字)
		if (( this.dict['zip'] ) && (! checkTel(this.dict['zip']))) {
			errmsg += "・郵便番号は半角数字で入力してください。\n";
		}

		//住所　都道府県市区(全角)
		if (( this.dict['add1'] ) && ( ! checkZenkaku(this.dict['add1']) )) {
			errmsg += "・住所　都道府県市区を全角文字で入力してください。\n";
		}

		//町村番地(全角)
		if (( this.dict['add2'] ) && ( ! checkZenkaku(this.dict['add2']) )) {
			errmsg += "・住所　町村番地を全角文字で入力してください。\n";
		}

		//電話番号(半角数字)
		if (( this.dict['tel'] ) && (! checkTel(this.dict['tel']))) {
			errmsg += "・電話番号は半角数字で入力してください。\n";
		}

		//FAX番号(半角数字)
		if (( this.dict['fax'] ) && (! checkTel(this.dict['fax']))) {
			errmsg += "・FAX番号は半角数字で入力してください。\n";
		}

		//メールアドレス(半角英数字)
		if (( this.dict['mail'] ) && (! checkEmail(this.dict['mail']))) {
			errmsg += "・正しい形式のメールアドレスを入力してください。\n";
		}
/*
		//URL(半角英数字)
		if (( this.dict['url'] ) && (! checkHankaku(this.dict['url']))) {
			errmsg += "・URLは半角英数字で入力してください。\n";
		}
*/

		//R500M担当者メール
		if (( this.dict['r500mmail'] ) && (! checkEmail(this.dict['r500mmail']))) {
			errmsg += "・正しい形式のR500M担当者メールアドレスを入力してください。\n";
		}

		//検索条件別
		errmsg += this.validateWithCondition();
/*
		//住所または緯度・経度
		if ( ((this.dict['add1']) && (this.dict['add2'])) ||
			 ((this.dict['latitude']) && (this.dict['longitude'])) ) {
		} else if (! this.isAddressCondition()) {
			errmsg += "・検索条件が住所による検索ではない場合、住所または緯度・経度を入力してください。\n";
		}
		//郵便番号または全国地方公共団体コード
		if ((! this.dict['zip']) && (! this.dict['area_code1'])) {
			errmsg += "・郵便番号または全国地方公共団体コードを入力してください。\n";
		}
*/

		//住所存在確認
/*
		if (( this.dict['add1'] ) && ( this.dict['add2'] )) {

			var ret = getPosFromAdd( this.dict['add1'] + this.dict['add2'] );
			if (( ret[0] ) && ( ret[1] )) {
				//折角なので代入
				if (! this.dict['latitude']) {
					this.dict['latitude'] = ret[0];
				}
				if (! this.dict['longitude']) {
					this.dict['longitude'] = ret[1];
				}

			} else {
				errmsg += "・ご入力頂きました住所は確認できません。町域番地等をご確認ください。\n";
			}

		}
*/

		//検索条件
		if ( this.conditionList.length > 0 ) {
			var idx = 0;
			for(idx=0;idx < this.conditionList.length;idx++) {
				errmsg += this.conditionList[idx].validate();
			}
		}

		//ブログ検索
		if ( this.blogsearchList.length > 0 ) {
			var idx = 0;
			for(idx=0;idx < this.blogsearchList.length;idx++) {
				errmsg += this.blogsearchList[idx].validate();
			}
		}
		// スポットRSS
		if (this.landmarkRssList.length > 0 ) {
		    for(var i = 0; i < this.landmarkRssList.length; i++) {
		    	var v = this.landmarkRssList[i];
			if (v == null) { continue; }
			var url = v[0];
			if (trim(url) == "") {
			    errmsg + "・スポットRSSのURLに空欄があります\n";
			}
			else if (!url.match('^https?://')) {
			    errmsg + "・スポットRSSのURLが http:// または https:// から始まらないものがあります\n";
			}
		    	
		    }
		}

		return errmsg;
	},


	validateWithCondition : function() {

		var errmsg = "";
	
		if ((this.conditionList) && (this.conditionList.length > 0)) {
			//alert(this.conditionList.length);

			for(var idx=0;idx < this.conditionList.length;idx++) {
				var condition = this.conditionList[idx];
				switch( condition.getType() ) {
				case "0":
					//距離による検索(住所または緯度・経度)
					if ( ((this.dict['add1']) && (this.dict['add2'])) ||
						 ((this.dict['latitude']) && (this.dict['longitude'])) ) {
					} else {
						errmsg += "・検索条件が距離による検索の場合、住所または緯度・経度を入力してください。\n";
					}
					break;

				case "1":	//市町村コードによる検索(郵便番号または住所)
					if ( (this.dict['area_code1']) || ((this.dict['add1']) && (this.dict['add2'])) || (this.dict['zip']) ) {
					} else {
						errmsg += "・検索条件が市町村コードよる検索の場合、市町村コードまたは住所または郵便番号を入力してください。\n";
					}
					break;

				case "2":	//都道府県コードによる検索(郵便番号または住所)
					if ( (this.dict['area_code1']) || ((this.dict['add1']) && (this.dict['add2'])) || (this.dict['zip']) ) {
					} else {
						errmsg += "・検索条件が都道府県コードよる検索の場合、市町村コードまたは住所または郵便番号を入力してください。\n";
					}
					break;

				case "3":	//住所による検索
					break;

				case "4":	//最も近い施設(住所または緯度・経度)
					if ( ((this.dict['add1']) && (this.dict['add2'])) ||
						 ((this.dict['latitude']) && (this.dict['longitude'])) ) {
					} else {
						errmsg += "・検索条件が最も近い施設で検索の場合、住所または緯度・経度を入力してください。\n";
					}
					break;
				}
			}
		}

		return errmsg;
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//JSON

	toJSON : function() {

		//検索条件
		if ( this.conditionList.length > 0 ) {
			var conArray = [];
			for(var idx=0;idx < this.conditionList.length;idx++) {
				conArray.push( this.conditionList[idx].getDict() );
			}

			this.dict['conditionList'] = {};
			this.dict['conditionList']['condition'] = conArray;
		} else {
			this.dict['conditionList'] = null;
		}


		//ブログ検索
		if ( this.blogsearchList.length > 0 ) {
			var blogArray = [];
			for(var idx=0;idx < this.blogsearchList.length;idx++) {
				blogArray.push( this.blogsearchList[idx].getDict() );
			}

			this.dict['blogsearchList'] = {};
			this.dict['blogsearchList']['blogsearch'] = blogArray;
		} else {
			this.dict['blogsearchList'] = null;
		}

		//スポットRSS
		if (this.landmarkRssList.length > 0) {
			data = new Array();
			for (var i = 0; i < this.landmarkRssList.length; i++) {
				var v = 
				{'rss_url' : this.landmarkRssList[i][0],
				 'topic_category1' : this.landmarkRssList[i][1],
				 'topic_category2' : this.landmarkRssList[i][2]
				 };

				data.push( v );
			}
			this.dict['landmarkRssList'] = {'landmarkRss' : data };
		} else {
			this.dict['landmarkRssList'] = null;
		}


		return hashToJSON(this.dict);
    }
	

};


var LandmarkList = Class.create();

LandmarkList.prototype = {

	initialize  : function() {
		this.dict = {};
		this.subdict = {};
		this.array = [];
    },

	// - - - - - - - - - - - - - - - - - - - - -
	//スポット追加

	addLandmark : function(landmark) {

		var catTag1 = landmark.getCategory1();
		if (!catTag1) {
			catTag1 = "_";
		}

		var catTag2 = landmark.getCategory2();
		if (!catTag2) {
			catTag2 = "_";
		}

		var catDict1 = this.dict[catTag1];
		var catArray2 = null;

		if ( catDict1 ) {
			catArray2 = catDict1[catTag2];
		} else {
			catDict1 = new Object();
			this.dict[catTag1] = catDict1;
		}

		if (!catArray2) {
			catArray2 = new Array();
			catDict1[catTag2] = catArray2;
		}

		catArray2.push(landmark);
		this.array.push(landmark);

		var catTag3 = landmark.getCategory3();
		if ( catTag3 ) {
			var tag = catTag1 + "+" + catTag2;
			var catDict3 = this.subdict[tag];
			var catArray3 = null;

			if ( catDict3 ) {
				catArray3 = catDict3[catTag3];
			} else {
				catDict3 = new Object();
				this.subdict[tag] = catDict3;
			}

			if (!catArray3) {
				catArray3 = new Array();
				catDict3[catTag3] = catArray3;
			}

			catArray3.push(landmark);
		}

		//alert("add:"+landmark.getName());

	},

	// - - - - - - - - - - - - - - - - - - - - -
	//スポット数

	getNumOfLandmark : function() {
		return this.array.length;
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//スポット取得

	getLandmarkAll : function() {
		return this.array;
	},

	getLandmark : function(catTag1, catTag2) {

		if (!catTag1) {
			catTag1 = "_";
		}

		if (!catTag2) {
			catTag2 = "_";
		}

		var catDict1 = this.dict[catTag1];
		if (catDict1) {
			var catArray2 = catDict1[catTag2];
			if (catArray2) {
				return catArray2;
			}
		}

		return null;
	},

	getLandmarkByLink : function(type) {
		var ret = [];
		for(var idx = 0;idx < this.array.length;idx++) {
			var lm = this.array[idx];
			if (lm.getLink_class() == type) {
				ret.push(lm);
			}
		}
		return ret;
	},

	getLandmarkById : function(id) {
		for(var idx = 0;idx < this.array.length;idx++) {
			var lm = this.array[idx];
			if (lm.getId() == id) {
				return lm;
			}
		}
		return null;
	},

	hasCategory3 : function(catTag1, catTag2) {

		var list = this.getLandmark(catTag1, catTag2);
		if (list) {
			var hascat3 = 0;
			for(var idx = 0; idx < list.length; idx++) {
				var landmark = list[idx];
				if ((landmark) && (landmark.getCategory3())) {
					hascat3++;
				}
			}
			return ((hascat3 >= 10) && (list.length == hascat3));
		}

		return false;
	},

	getLandmark3 : function(catTag1, catTag2, catTag3) {
		var tag = catTag1 + "+" + catTag2;
		var catDict3 = this.subdict[tag];
		if (catDict3) {
			var catArray3 = catDict3[catTag3];
			if (catArray3) {
				return catArray3;
			}
		}
		return null;
	},


	// - - - - - - - - - - - - - - - - - - - - -
	//カテゴリ取得

	getCategories1 : function() {
		return( getDictKeys( this.dict ) );
	},

	getCategories2 : function(catTag1) {

		if (!catTag1) {
			catTag1 = "_";
		}

		return( getDictKeys( this.dict[catTag1] ) );
	},

	getCategories3 : function(catTag1, catTag2) {
		var tag = catTag1 + "+" + catTag2;
		return( getDictKeys( this.subdict[tag] ) );
	}

}


function readLandmark_wsse(id, wsse) {

	var reqparam = "json";
	var url = "/landmark/info/" + id;
	var landmark = null;
	var trycount = 2;

	while(trycount-- > 0) {

		new Ajax.Request(
			url,
			{
				"method": "get", 
				"parameters": reqparam + "&nolink&request_dummy=" + Math.random(),
				"asynchronous": false,
				"requestHeaders": ['X-WSSE', wsse,
								   'RequestPath', location.pathname],
				onSuccess: function(request) {
					//alert(request.requestHeaders);
					//alert(request.responseText);

					var val;
					var idx;
					var json; 
					eval("json=" + replaceAll(request.responseText,"\n","\\n")); 

					var list = json.landmarkResponse.landmarkList.landmark;
					if ( list ) {
						landmark = new Landmark();
						landmark.setDict( list[0] );
					}

				},
				onComplete: function(request) {},
				onFailure: function(request) {}, 
				onException: function (xmlhttp, e) {} 
			}
		); 

		if ((landmark) || (trycount == 0))	break;
	}

	return landmark;
}

function readLandmark(id, user, passwd) {
	return readLandmark_wsse(id, wsseHeader(user, passwd));
}

function readLandmarkWithLink(id, user, passwd, callback) {

	var numoflandmark = 0;
	var landmarklist = null;
	var asynchronous = (callback != null);

	new Ajax.Request(
		"/landmark/info/" + id,
		{
			"method": "get", 
			"parameters": "&json&request_dummy=" + Math.random(),
			"asynchronous": asynchronous,
			"requestHeaders": ['X-WSSE', wsseHeader(user, passwd),
							   'RequestPath', location.pathname],
			onSuccess: function(request) {
				//alert(request.responseText);

				var json; 
				eval("json="+replaceAll(request.responseText,"\n","\\n")); 

				if (json.landmarkResponse.numoflandmark) {
					numoflandmark = parseInt(json.landmarkResponse.numoflandmark);
				}
				//alert(numoflandmark);

				var list = json.landmarkResponse.landmarkList.landmark;
				if ( list ) {
					landmarklist = new LandmarkList();

					for(var idx = 0; idx < list.length ; idx++){
						var landmark = new Landmark();
						landmark.setDict( list[idx] );
						landmarklist.addLandmark( landmark );
					}
				}

			},
			onComplete: function(request) {
				if (callback) {
					callback(numoflandmark, landmarklist);
				}
			},
			onFailure: function(request) {}, 
			onException: function (xmlhttp, e) {} 
		}
	); 

	return landmarklist;
}

function createDefaultBlogsearch(id, user, passwd) {

	var reqparam = "json";
	var url = "/landmark/defaultblogsearch/" + id;
	var landmark = null;
	var trycount = 2;

	while(trycount-- > 0) {

		new Ajax.Request(
			url,
			{
				"method": "get", 
				"parameters": reqparam + "&nolink&request_dummy=" + Math.random(),
				"asynchronous": false,
				"requestHeaders": ['X-WSSE', wsseHeader(user, passwd),
								   'RequestPath', location.pathname],
				onSuccess: function(request) {
					//alert(request.requestHeaders);
					alert(request.responseText);

					var val;
					var idx;
					var json; 
					eval("json=" + replaceAll(request.responseText,"\n","\\n")); 

					var list = json.landmarkResponse.landmarkList.landmark;
					if ( list ) {
						landmark = new Landmark();
						landmark.setDict( list[0] );
					}

				},
				onComplete: function(request) {},
				onFailure: function(request) {}, 
				onException: function (xmlhttp, e) {/*alert(e.name + ': '+ e.message);*/} 
			}
		); 

		if ((landmark) || (trycount == 0))	break;
	}

	return landmark.getBlogsearchList();
}


function searchLandmark(reqparam, callback, user, passwd) { 
	return searchLandmarkRequest("/landmark/info/", user, passwd, reqparam, callback);
}

function searchLandmarkHL(reqparam, callback) { 
	return searchLandmarkRequest("/landmark/headline/", '', '', reqparam, callback);
}

function searchLandmarkRequest(url, user, passwd, reqparam, callback) { 

	//alert(url);
	//alert(reqparam);
	//alert(wsseHeader(user, passwd));

	var numoflandmark = 0;
	var landmarklist = null;
	var asynchronous = (callback != null);

	new Ajax.Request(
		url, 
		{
			"method": "get", 
			"parameters": reqparam + "&json&request_dummy=" + Math.random(), 
			"asynchronous": asynchronous,
			"requestHeaders": ['X-WSSE', wsseHeader(user, passwd)],
			onSuccess: function(request) {
				//alert(request.responseText);
				var json; 
				eval("json="+replaceAll(request.responseText,"\n","\\n")); 

				if (json.landmarkResponse.numoflandmark) {
					numoflandmark = parseInt(json.landmarkResponse.numoflandmark);
				}
				//alert(landmarkTotal);

				var list = json.landmarkResponse.landmarkList.landmark;
				if ( list ) {
					landmarklist = new LandmarkList();

					for(var idx = 0; idx < list.length ; idx++){
						var landmark = new Landmark();
						landmark.setDict( list[idx] );
						landmarklist.addLandmark( landmark );
					}
				}
			},
			onComplete: function(request) {
				if (callback) {
					callback(numoflandmark, landmarklist);
				}
			},
			onFailure: function(request) {}, 
			onException: function (xmlhttp, e) {} 
		}
	);

	return landmarklist;
}


function loadPickup(param, callback) { 

	var landmark = null;
	var asynchronous = (callback != null);

//	alert(param);

	new Ajax.Request(
		"/landmark/pickup", 
		{
			"method": "get", 
			"parameters": param + "&json&request_dummy=" + Math.random(), 
			"asynchronous": asynchronous,
			onSuccess: function(request) {

				//alert(request.responseText);

				var val;
				var json; 
				eval("json="+replaceAll(request.responseText,"\n","\\n")); 

				var list = json.landmarkResponse.landmarkList.landmark;

				if (list) {
					landmark = new Landmark();
					landmark.setDict( list[0] );
				}
			},
			onComplete: function(request) {
				if (callback) {
					callback(landmark);
				}
			},
			onFailure: function(request) {}, 
			onException: function (xmlhttp, e) {} 
		}
	); 

}

/*
function loadPickup(userid, callback) { 

	var landmark = null;
	var asynchronous = (callback != null);

	new Ajax.Request(
		"/landmark/pickup", 
		{
			"method": "get", 
			"parameters": "user=" + userid + "&json&request_dummy=" + Math.random(), 
			"asynchronous": asynchronous,
			onSuccess: function(request) {

				//alert(request.responseText);

				var val;
				var json; 
				eval("json="+request.responseText); 

				var list = json.landmarkResponse.landmarkList.landmark;

				if (list) {
					landmark = new Landmark();
					landmark.setDict( list[0] );
				}
			},
			onComplete: function(request) {
				if (callback) {
					callback(landmark);
				}
			},
			onFailure: function(request) {}, 
			onException: function (xmlhttp, e) {} 
		}
	); 

}
*/


