// Require prototype.js
// Require function.js

var Condition = Class.create();

Condition.prototype = {

	initialize  : function() {
		this.dict = {};
    },

	setDict : function(value) {
		this.dict = value;
		//alert(hashToJSON(this.dict));
	},

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

	// - - - - - - - - - - - - - - - - - - - - -
	//検索条件種別

	setType : function(value) {
		this.dict['type'] = trim(value);
	},
	getType : function() {
		return this.dict['type'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//検索条件

	setValue : function(value) {
		this.dict['value'] = trim(value);
	},
	getValue : function() {
		return this.dict['value'];
	},

	setValue2 : function(value) {
		this.dict['value2'] = trim(value);
	},
	getValue2 : function() {
		return this.dict['value2'];
	},

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

	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'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//性別指定

	setGender : function(value) {
		this.dict['gender'] = trim(value);
	},
	getGender : function() {
		return this.dict['gender'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//自動車の有無

	setCar : function(value) {
		this.dict['car'] = trim(value);
	},
	getCar : function() {
		return this.dict['car'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//免許の有無

	setLicense : function(value) {
		this.dict['license'] = trim(value);
	},
	getLicense : function() {
		return this.dict['license'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//子供の有無

	setChildlen : function(value) {
		this.dict['childlen'] = trim(value);
	},
	getChildlen : function() {
		return this.dict['childlen'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//ペットの有無

	setPet : function(value) {
		this.dict['pet'] = trim(value);
	},
	getPet : function() {
		return this.dict['pet'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//登録種別

	setObject_type : function(value) {
		this.dict['object_type'] = trim(value);
	},
	getObject_type : function() {
		return this.dict['object_type'];
	},

	// - - - - - - - - - - - - - - - - - - - - -
	//登録者コード

	setObject_id : function(value) {
		this.dict['object_id'] = trim(value);
	},
	getObject_id : function() {
		return this.dict['object_id'];
	},

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

	validate : function() {

		var errmsg = "";

		switch( this.dict['type'] ) {
		case "0":
			//距離による検索
			if ( ! this.dict['value'] ) {
				errmsg += "・検索半径を入力してください。\n";
			}
			else if ( ! checkNum(this.dict['value']) ) {
				errmsg += "・検索半径は半角数字で入力してください。\n";
			}
/*
			else if ( ! this.dict['latitude'] ) {
				errmsg += "・緯度を入力してください。\n";
			}
			else if ( ! this.dict['longitude'] ) {
				errmsg += "・経度を入力してください。\n";
			}
*/
			break;

		case "1":	//市町村コードによる検索
			break;

		case "2":	//都道府県コードによる検索
			break;

		case "3":	//住所による検索
			if ( ! this.dict['value'] ) {
				errmsg += "・検索町域を入力してください。\n";
			}
			else if ( ! checkZenkaku(this.dict['value']) ) {
				errmsg += "・検索町域を全角文字で入力してください。\n";
			}
			break;

		case "4":	//最も近い施設
			break;

		// - - - - - - - - - - - - - - - - - - -
		//検索オプション

		case "100":	//なし
			break;

		case "101":	//性別(0:男性/1:女性)
			if ( ! this.dict['value'] ) {
				errmsg += "・性別を入力してください。\n";
			}
			break;

		case "102":	//誕生日(前後日数)
			if ( ! this.dict['value'] ) {
				errmsg += "・誕生日有効日数を入力してください。\n";
			}
			else if ( ! checkNum(this.dict['value']) ) {
				errmsg += "・誕生日有効日数は半角数字で入力してください。\n";
			}
			break;

		case "103":	//入会日数
			if ( ! this.dict['value'] ) {
				errmsg += "・入会日有効日数を入力してください。\n";
			}
			else if ( ! checkNum(this.dict['value']) ) {
				errmsg += "・入会日有効日数は半角数字で入力してください。\n";
			}
			break;

		case "104":	//年齢
			if ( ! this.dict['value'] ) {
				errmsg += "・年齢を入力してください。\n";
			}
			else if ( ! checkNum(this.dict['value']) ) {
				errmsg += "・年齢は半角数字で入力してください。\n";
			}
			if ( ! this.dict['value2'] ) {
				errmsg += "・年齢を入力してください。\n";
			}
			else if ( ! checkNum(this.dict['value2']) ) {
				errmsg += "・年齢は半角数字で入力してください。\n";
			}
			break;

		default:
			errmsg += "・検索条件の値が異常です。\n";
			break;
		}

		return errmsg;
	},

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

	toJSON : function() {
		return hashToJSON(this.dict);
    }


};

