/**
 * 検索クラス
 *
 * @param
 * @return
 */
 function searchAbstract() {

	this.grp = "all";
	this.param = null;
	//this.apidomain = "http://mapion.nextra.homes.co.jp/";
	this.apidomain = "http://oem-maps.nextra.homes.co.jp/";
	this.apiname = null;
	this.callback = "callback";
	this.charset = "UTF-8";
	this.timeOutMS = 10000;
	this.noCacheIE = true;
	this.geofb = null;
	this.geoc1 = null;
	this.position = null;
	this.page = null;
	this.offset = null;
	this.hits = null;
	
	this.requestcount = 0;
	
 	this.json = null;
	this.data = null;
	
	this.onloadFunction = null;
 	
}
 
searchAbstract.prototype.setPosition = function() {
 	// 座標が必要な場合は、オーバーライドして使う。
}

searchAbstract.prototype.request = function(param) {
 	this.json.scriptId = 'Jscript2Id' + JSON.scriptCounter++;	
	
	if (typeof(this.onloadFunction) == "function") {
		this.json.removeEventListener( "onload"  , this.onloadFunction );
	}
	
 	var apiurl = this.apidomain + this.apiname;
 	var apiparam = "?";
 	if (param == null) param = new Object();
 	this.setPosition();
  	if (homesGlobal.gyo != null && homesGlobal.gyo != "") {
 		param.gyo = homesGlobal.gyo;
 	}
 	if (this.geofb != null) {
 		param.geofb = this.geofb;
 	}
 	if (this.geoc1 != null) {
 		param.geoc1 = this.geoc1;
 	}
 	if (this.flgadjust != null) {
 		param.flgadjust = this.flgadjust;
 	}
 	if (this.hits != null) {
 		if (param.hits == null) {
	 		param.hits = this.hits;
 			param.page = this.page;
 		}
 	}
 	for (var p in param) {
 		if (p == "mid") {
 			var midarray = param[p].split(",");
 			if (midarray.length == 1) {
		 		apiparam += "mid=H" + midarray[0] + "&";
 			} else {
 				for (var i = 0; i < midarray.length; i++) {
 					apiparam += "mid[]=H" + midarray[i] + "&";
 				}
 			}
 		} else {
 			if (param[p].length != 0) {
		 		apiparam += p + "=" + param[p] + "&";
 			}
 		}
 	}
 	apiparam = apiparam.substr(0, apiparam.length - 1);
 	
 	var thisobject = this;
 	this.onloadFunction = function(e) {
 		thisobject.data = e.target.responseData[0];
		thisobject.responseData = e.target.responseData;
		thisobject.requestid = e.requestid;
		thisobject.dispatchEvent(new EventObject("onload",thisobject));
 	}
 	this.json.addEventListener( "onload"  , this.onloadFunction );
 	
 	var fullUrl = apiurl + apiparam;
 	
 	this.json.fullUrl = fullUrl;
 	this.json.callbackParamName = this.callback;
 	this.json.charset = this.charset;
 	this.json.noCacheIE = this.noCacheIE;
 	this.json.get();
 	
}
 
searchAbstract.prototype.callbackFunction = function(e) {
 	this.data = e.target.responseData[0];
	this.dispatchEvent(new EventObject("onload",this));
}

searchAbstract.prototype.getData = function() {
 	return this.data;
}

searchAbstract.prototype.setJsonEvent = function() {
 	if (this.json == null) return;
 	
 	if(typeof(EventDispatcher)=="undefined"){return;}
	EventDispatcher.implement(this);

 	var thisobject = this;
 	this.json.addEventListener( "onerror"  , function(e) {
		thisobject.dispatchEvent(new EventObject("onerror",thisobject));
 	} );

}

/**
 * Bukken/Search検索
 *
 * @param
 * @return
 */
function searchBukkenSearch(map) {
 	this.map = map;
	this.apiname = "Bukken/Search.jsonp";
	this.hits = "40";
	this.page = "1";
  	this.json = new JSON();
  	this.json.timeOutMS = this.timeOutMS;
  	this.gyo = "";
  	this.flgadjust = "1";
  	
  	if (homesGlobal.gyo != null && homesGlobal.gyo != "") {
  		this.gyo = homesGlobal.gyo;
  	}

 	this.setJsonEvent();
 	
}

searchBukkenSearch.prototype = new searchAbstract;
 
searchBukkenSearch.prototype.setPosition = function() {
 	var bounds = this.map.getBoundsLatLng();
 	var latlng = this.map.getCenterLatLng();
 	this.geoc1 = latlng.y + "," + latlng.x;
 	this.geofb = bounds.minY + "," + bounds.minX + ";" + bounds.maxY + "," + bounds.maxX;
}

/**
 * Bukken/MapBalloon検索
 *
 * @param
 * @return
 */
function searchBukkenMapBalloon(map) {
 	this.map = map;
	//this.apiname = "Bukken/MapBalloon.jsonp"
	this.apiname = "Bukken/Search.jsonp"
  	this.json = new JSON();
  	this.json.timeOutMS = this.timeOutMS;
  	if (homesGlobal.position != null) {
	  	this.geoc1 = homesGlobal.position.y + "," + homesGlobal.position.x;
  	}
  	if (homesGlobal.gyo != null && homesGlobal.gyo != "") {
  		this.gyo = homesGlobal.gyo;
  	}

 	this.setJsonEvent();
 	
}

searchBukkenMapBalloon.prototype = new searchAbstract;
 
searchBukkenMapBalloon.prototype.setPosition = function() {
 	var latlng = this.map.getCenterLatLng();
 	this.geoc1 = latlng.y + "," + latlng.x;
}

/**
 * Bukken/Maps2検索
 *
 * @param
 * @return
 */
function searchBukkenMaps2(map) {
 	this.map = map;
	this.apiname = "Bukken/Maps2.jsonp"
  	this.json = new JSON();
  	this.json.timeOutMS = this.timeOutMS;

  	if (homesGlobal.gyo != null && homesGlobal.gyo != "") {
  		this.gyo = homesGlobal.gyo;
  	}

 	this.setJsonEvent();
 	
}

searchBukkenMaps2.prototype = new searchAbstract;
 
searchBukkenMaps2.prototype.setPosition = function() {
 	var bounds = this.map.getBoundsLatLng();
 	var latlng = this.map.getCenterLatLng();
 	this.geoc1 = latlng.y + "," + latlng.x;
 	this.geofb = bounds.minY + "," + bounds.minX + ";" + bounds.maxY + "," + bounds.maxX;
}

/**
 * RegInfo/MarketPriceAreaRent検索
 *
 * @param
 * @return
 */
function searchRegInfoMarketPriceAreaRent(map) {
 	this.map = map;
	this.apiname = "RegInfo/MarketPriceAreaRent.jsonp";
	
  	if (homesGlobal.gyo != null && homesGlobal.gyo != "") {
  		this.gyo = homesGlobal.gyo;
  	}

  	this.json = new JSON();
  	this.json.timeOutMS = this.timeOutMS;

 	this.setJsonEvent();
 	
}

searchRegInfoMarketPriceAreaRent.prototype = new searchAbstract;

searchRegInfoMarketPriceAreaRent.prototype.request = function(param) {
 	
	this.json.scriptId = 'Jscript2Id' + JSON.scriptCounter++;	
	if (typeof(this.onloadFunction) == "function") {
		this.json.removeEventListener( "onload"  , this.onloadFunction );
	}

 	var apiurl = this.apidomain + this.apiname;
 	var apiparam = "?";
 	if (param == null) param = new Object();
  	if (homesGlobal.gyo != null && homesGlobal.gyo != "") {
 		param.gyo = homesGlobal.gyo;
 	}
 	for (var p in param) {
 		apiparam += p + "=" + param[p] + "&";
 	}
 	apiparam = apiparam.substr(0, apiparam.length - 1);
 	
 	var thisobject = this;
 	this.onloadFunction = function(e) {
 		thisobject.data = e.target.responseData[0];
		thisobject.responseData = e.target.responseData;
		thisobject.requestid = e.requestid;
		thisobject.dispatchEvent(new EventObject("onload",thisobject));
 	}
 	this.json.addEventListener( "onload"  , this.onloadFunction );
 	
 	var fullUrl = apiurl + apiparam;
 	
 	this.json.fullUrl = fullUrl;
 	this.json.callbackParamName = this.callback;
 	this.json.charset = this.charset;
 	this.json.noCacheIE = this.noCacheIE;
 	this.json.get();
 	
}
 
/**
 * Realtor/Maps2検索
 *
 * @param
 * @return
 */
function searchRealtorMaps2(map) {
 	this.map = map;
	this.apiname = "Realtor/Maps2.jsonp"
  	this.json = new JSON();
  	this.json.timeOutMS = this.timeOutMS;

  	if (homesGlobal.gyo != null && homesGlobal.gyo != "") {
  		this.gyo = homesGlobal.gyo;
  	}

 	this.setJsonEvent();
 	
}

searchRealtorMaps2.prototype = new searchAbstract;
 
searchRealtorMaps2.prototype.setPosition = function() {
 	var bounds = this.map.getBoundsLatLng();
 	var latlng = this.map.getCenterLatLng();
 	this.geoc1 = latlng.y + "," + latlng.x;
 	this.geofb = bounds.minY + "," + bounds.minX + ";" + bounds.maxY + "," + bounds.maxX;
}

/**
 * Realtor/Detail検索
 *
 * @param
 * @return
 */
function searchRealtorDetail(map) {
 	this.map = map;
	this.apiname = "Realtor/Detail.jsonp"
  	this.json = new JSON();
  	this.json.timeOutMS = this.timeOutMS;

  	if (homesGlobal.gyo != null && homesGlobal.gyo != "") {
  		this.gyo = homesGlobal.gyo;
  	}

 	this.setJsonEvent();
 	
}

searchRealtorDetail.prototype = new searchAbstract;
 
/**
 * そこどこ検索
 *
 * @param
 * @return
 */
function searchSokodoko(map) {
 	this.map = map;
	this.apiname = "map/uc/Where";
	this.grp = "all";
  	this.json = new JSON();
  	this.json.timeOutMS = this.timeOutMS;

 	this.setJsonEvent();
 	
}

searchSokodoko.prototype = new searchAbstract;
 
searchSokodoko.prototype.request = function(param) {

	this.json.scriptId = 'Jscript2Id' + JSON.scriptCounter++;
	
	if (typeof(this.onloadFunction) == "function") {
		this.json.removeEventListener( "onload"  , this.onloadFunction );
	}

 	var apiurl = homesGlobal.domain + this.apiname;
 	var apiparam = "?";
 	if (param == null) param = new Object();
 	param.ie = "utf-8";
 	param.oe = "utf-8";
 	param.dtm = "wgs";
 	param.json = "1"
 	param.vo = "mbml";
 	this.setPosition();
  	if (homesGlobal.grp != null && homesGlobal.grp != "") {
 		param.grp = homesGlobal.grp;
 	} else {
 		param.grp = this.grp;
 	}
 	if (this.position != null) {
 		param.nl = this.position.y;
 		param.el = this.position.x;
 	}
 	for (var p in param) {
 		apiparam += p + "=" + param[p] + "&";
 	}
 	apiparam = apiparam.substr(0, apiparam.length - 1);
 	
 	var thisobject = this;
 	this.onloadFunction = function(e) {
 		thisobject.data = e.target.responseData[0];
		thisobject.responseData = e.target.responseData;
		thisobject.requestid = e.requestid;
		thisobject.dispatchEvent(new EventObject("onload",thisobject));
 	}
 	this.json.addEventListener( "onload"  , this.onloadFunction );
 	
 	var fullUrl = apiurl + apiparam;
 	
 	this.json.fullUrl = fullUrl;
 	this.json.callbackParamName = this.callback;
 	this.json.charset = this.charset;
 	this.json.noCacheIE = this.noCacheIE;
 	this.json.get();
 	
}
 
searchSokodoko.prototype.setPosition = function() {
 	this.position = this.map.getCenterLatLng();
}


/**
 * ランドマーク検索
 *
 * @param
 * @return
 */
function searchLandmark(map) {
 	this.map = map;
	this.apiname = "map/uc/PoiWithin";
	this.pm = "20";
	this.scl = null;
 	this.minnl = null;
 	this.minel = null;
 	this.maxnl = null;
 	this.maxel = null;
 	this.genre1_code = "";
	this.grp = "homes";
  	this.json = new JSON();
   	this.json.timeOutMS = this.timeOutMS;
 	this.setJsonEvent();
}

searchLandmark.prototype = new searchAbstract;

searchLandmark.prototype.request = function(param) {

	this.json.scriptId = 'Jscript2Id' + JSON.scriptCounter++;

	if (typeof(this.onloadFunction) == "function") {
		this.json.removeEventListener( "onload"  , this.onloadFunction );
	}

 	var apiurl = homesGlobal.domain + this.apiname;
 	var apiparam = "?";
 	if (param == null) param = new Object();
 	param,grp = this.grp;
 	param.sgrp = "lm01";
 	param.crf = "0";
 	param.ie = "utf-8";
 	param.oe = "utf-8";
 	param.dtm = "wgs";
 	param.json = "1"
 	param.vo = "mbml";
 	this.setPosition();
  	if (homesGlobal.grp != null && homesGlobal.grp != "") {
 		param.grp = homesGlobal.grp;
 	} else {
 		param.grp = this.grp;
 	}
 	if (this.position != null) {
 		param.nl = this.position.y;
 		param.el = this.position.x;
 	}
 	if (this.scl != null) {
 		param.scl = this.scl;
 	}
 	if (this.minnl != null && this.minel != null && this.maxnl != null && this.maxel != null) {
 		param.minnl = this.minnl;
 		param.minel = this.minel;
 		param.maxnl = this.maxnl;
 		param.maxel = this.maxel;
 	}
 	for (var p in param) {
 		apiparam += p + "=" + param[p] + "&";
 	}
 	apiparam = apiparam.substr(0, apiparam.length - 1);
 	
 	var thisobject = this;
 	this.onloadFunction = function(e) {
 		thisobject.data = e.target.responseData[0];
		thisobject.responseData = e.target.responseData;
		thisobject.requestid = e.requestid;
		thisobject.dispatchEvent(new EventObject("onload",thisobject));
 	}
 	this.json.addEventListener( "onload"  , this.onloadFunction );
 	
 	var fullUrl = apiurl + apiparam;
 	
 	this.json.fullUrl = fullUrl;
 	this.json.callbackParamName = this.callback;
 	this.json.charset = this.charset;
 	this.json.noCacheIE = this.noCacheIE;
 	this.json.get();
 	
}
 
searchLandmark.prototype.setPosition = function() {
 	var bounds = this.map.getBoundsLatLng();
 	this.minnl = bounds.minY;
 	this.minel = bounds.minX;
 	this.maxnl = bounds.maxY;
 	this.maxel = bounds.maxX;
 	this.position = this.map.getCenterLatLng();
 	this.scl = homesutil.ZidToScl(this.map.getZoomLevel());
}

 
