/*------------------------------------------------------------------------------
 JSON関連定義
------------------------------------------------------------------------------*/
var uri_base =				"http://www.sumunavi.net/common/json/";

/* マスタ関連 */
var uri_get_addr =			uri_base + "get_addresses.json";
var uri_get_kline =			uri_base + "get_line.json";
var uri_get_ksta =			uri_base + "get_station.json";

/* 物件情報関連 */
var uri_get_clist =			uri_base + "get_clist.json";
var uri_get_blist =			uri_base + "get_blist.json";
var uri_get_clist_map =		uri_base + "get_clist_map.json";
var uri_get_blist_map =		uri_base + "get_blist_map.json";






/*------------------------------------------------------------------------------
 全ページ共通処理
------------------------------------------------------------------------------*/
$(function() {
	if (!$.support.opacity && !$.support.style && typeof document.documentElement.style.maxHeight == "undefined") {
		var err_ie6 = "＊＊　重要なお知らせ　＊＊\n\n";
		err_ie6 += "お客様がお使いのブラウザソフトウェアは\n「Internet Explorer 6」であると思われます。\n";
		err_ie6 += "当サイトを正しく表示できない場合がございますので、\n最新ブラウザをご利用いただけますようお願い致します。";
		alert(err_ie6);
	}
	$.ajaxSetup({ cache: false });
	$("a[rel*='lightbox']").lightBox();
});


/*------------------------------------------------------------------------------
 マスタ関連
------------------------------------------------------------------------------*/
/* 住所取得 (新旧マージ 1010ver.) */
function sel_jcode(targetid, cbtype, pcode, acode) {
	var params = new Object();
	params = {
		"p" : pcode,
		"a" : acode,
		"type" : cbtype,
		"bm" : 1
	};
	var out_html = "";

	$("#" + targetid).empty().append("<p class=\"center\"><img src=\"images/wait_anim.gif\" /></p>");
	$.getJSON(uri_get_addr, params, function(datum) {
		for (key in datum) out_html += "<label><input type=\"checkbox\" name=\"jcode\" value=\"" + key + "\" />&nbsp;" + datum[key] + "</label>";
		$("#sel_jcode").empty().append(out_html);
	});
}


/*------------------------------------------------------------------------------
 検索系共通・汎用
------------------------------------------------------------------------------*/
/* 待ち表示 */
function wait_datum_read() {
	var out_html = "<div id=\"waitimg\"></div>";
	$("#cblist_result_box").empty().append(out_html);
	$("#waitimg").activity({
		segments: 12,
		width: 20,
		space: 24,
		length: 50,
		color: '#666',
		speed: 1
	});
}

/* 賃料・価格下限表示 */
function put_cost_lower(targetselect, cbtype) {
	var out_html = "<option value=\"0\">指定しない</option>";

	if (cbtype == "c" || cbtype == "C") {
		for (var i = 5; i <= 55; i += 5) out_html += "<option value=\"" + i + "\">￥" + i + ",000</option>";
	} else if (cbtype == "b" || cbtype == "B") {
		for (var i = 5; i <= 20; i += 5) out_html += "<option value=\"" + i + "\">￥" + numberformat(i * 100) + "万</option>";
	}

	$("select[name='" + targetselect + "']").empty().append(out_html);
}

/* 賃料・価格上限表示 */
function put_cost_upper(targetselect, cbtype) {
	var out_html = "<option value=\"999\">指定しない</option>";

	if (cbtype == "c" || cbtype == "C") {
		for (var i = 5; i <= 80; i += 5) out_html += "<option value=\"" + i + "\">￥" + i + ",000</option>";
		out_html += "<option value=\"100\">￥100,000</option>";
		out_html += "<option value=\"150\">￥150,000</option>";
	} else if (cbtype == "b" || cbtype == "B") {
		for (var i = 10; i <= 30; i += 5) out_html += "<option value=\"" + i + "\">￥" + numberformat(i * 100) + "万</option>";
	}

	$("select[name='" + targetselect + "']").empty().append(out_html);
}

/* 売買面積下限表示 */
function put_area_lower(targetselect, btype) {
	var out_html = "<option value=\"0\">指定しない</option>";

	if (btype == "" || btype == "undefined") {
		for (var i = 1; i <= 15; i++) out_html += "<option value=\"" + i + "\">" + (i * 10) + "</option>";
	} else if (btype == "h" || btype == "m") {
		for (var i = 1; i <= 5; i++) out_html += "<option value=\"" + i + "\">" + (i * 10) + "</option>";
	} else if (btype == "t" || btype == "s") {
		for (var i = 5; i <= 15; i++) out_html += "<option value=\"" + i + "\">" + (i * 10) + "</option>";
	}

	$("select[name='" + targetselect + "']").empty().append(out_html);
}

/* 面積上限表示 */
function put_area_upper(targetselect, btype) {
	var out_html = "<option value=\"0\">指定しない</option>";

	if (btype == "" || btype == "undefined") {
		for (var i = 3; i <= 20; i++) out_html += "<option value=\"" + i + "\">" + (i * 10) + "</option>";
	} else if (btype == "h" || btype == "m") {
		for (var i = 3; i <= 8; i++) out_html += "<option value=\"" + i + "\">" + (i * 10) + "</option>";
	} else if (btype == "t" || btype == "s") {
		for (var i = 10; i <= 20; i++) out_html += "<option value=\"" + i + "\">" + (i * 10) + "</option>";
	}

	$("select[name='" + targetselect + "']").empty().append(out_html);
}

/* 表示開始位置パラメタ取得 */
function get_cfrom_params() {
	var now_cfrom = $("#ajax_param_from").val() + "";
	now_cfrom = (now_cfrom == "" || now_cfrom == "undefined" || now_cfrom == "0") ? 10 : parseInt(now_cfrom);

	return now_cfrom;
}

/* 表示件数パラメタ取得 */
function get_ccount_params() {
	var now_ccount = $("#ajax_param_count").val() + "";
	now_ccount = (now_ccount == "" || now_ccount == "undefined" || now_ccount == "0") ? 10 : parseInt(now_ccount);

	return now_ccount;
}


/*------------------------------------------------------------------------------
 共通・汎用
------------------------------------------------------------------------------*/
/* Javascript版 numberformat */
function numberformat(num) {
	return num.toString().replace(/([\d]+?)(?=(?:\d{3})+$)/g, function(t){ return t + ','; });
}

/* getパラメタをパース */
function params_parse(params) {
	if (params == "") {
		return null;
	} else {
		var buffer = params.substr(1);
		var pairs = buffer.split("&");
		var result = new Object();

		for (var i in pairs) {
			var pair = pairs[i].split("=");
			result[pair[0]] = unescape(pair[1].replace("+", " "));
		}

		return result;
	}
}

/* 明細表示 */
function np(code, type) {
	var out_html = "";
	out_html += "<input type=\"hidden\" name=\"BCode\" value=\"" + code + "\" />";
	out_html += "<input type=\"hidden\" name=\"Type\" value=\"" + type + "\" />";
	$("#window_open")
		.attr("action", "meisai.html")
		.empty().append(out_html)
		.submit();
}

/* 問い合わせ表示 */
function qmailopenall(type) {
	var out_html = "";
	out_html += "<input type=\"hidden\" name=\"t\" value=\"" + type + "\" />";
	$("#window_open")
		.attr("action", "cbmails.html")
		.empty().append(out_html)
		.submit();
}

/* 問い合わせ送信 */
function qfsubmit(keyparam) {
	$("#question_form input[name='key']").val(keyparam);
	$("#question_form").submit();
}

/* お気に入り削除 */
function del_favorite(bcode) {
	$("#fav_form input[name='favorite']").val(bcode);
	$("#fav_form").submit();
}

