﻿var GetLocationValue;
var GetFileArea;
String.prototype.QueryString = function(Url) {
	var reg = new RegExp("(^|&)" + Url + "=([^&]*)(&|$)");
	var r = this.substr(this.indexOf("\?") + 1).match(reg);
	if (r != null) return decodeURI(r[2]); return null;
}
var request = location.href;
GetLocationValue = request.QueryString("RuleValue");
GetFileArea = request.QueryString("FileArea");

function init(mode) {
	var so = $("#province");
	so.empty();
	$("#city").empty();
	for (var i in Public_Data_City)
		so.append("<option value=" + i + ">" + i + "</option>");
	if (mode)
		so.change(function() { CitySelect(this.value); });
}
function CitySelect(CtrlValue) {
	var so2 = $("#city");
	so2.empty();
	for (var i in Public_Data_City[CtrlValue]) {
		var objOption = document.createElement("OPTION");
		objOption.text = Public_Data_City[CtrlValue][i];
		objOption.value = Public_Data_City[CtrlValue][i];
		so2[0].options.add(objOption);
	}
}
function SaveValue() {
	var value1 = $("#province").val();
	var value2 = $("#city").val();
	var _value = "";
	if ((value1 != "") && (value2 != "" && value2 != null))
		_value = value1 + "-" + value2;
	else if ((value1 != "") && (value2 == "" || value2 == null))
		_value = value1;
	$("#LocationValue").val(_value);
}
function RuleSotrWork() {
	var RuleSortValue = $("#RuleSort").val();
	if (RuleSortValue == "省级范围") {
		$("#province").show();
		$("#city").hide().val("");
		$("#LocationValue").val("");
		init(false);
	}
	else if (RuleSortValue == "市级范围") {
		$("#province").show();
		$("#city").show();
		$("#LocationValue").val("");
		init(true);
	}
	else {
		$("#province").hide().val("");
		$("#city").hide().val("");
		$("#LocationValue").val($("#RuleSort").val());
	}
}
var CityData;
function Refer() {
	SaveValue();
	var __Url;
	if (request.indexOf("PMRule") > 0)
		__Url = "/PMRule.aspx";
	else
		__Url = "/RealtyRule.aspx";
	location.href = __Url + "?RuleValue=" + encodeURI($("#LocationValue").val()) + "&FileArea=" + encodeURI($("#FileArea").val());
}
function GetRuleCity() {
	CityData = GetLocationValue;
	if (GetFileArea != null)
		$("#FileArea").val(GetFileArea);
	if ((!CityData) || (CityData == "") || (CityData == "所有法律法规")) {
		$("#RuleSort").val("所有法律法规");
		$("#LabelValue").text("查询范围：所有法律法规");
	} else if (CityData == "国家范围") {
		$("#RuleSort").val("国家范围");
		$("#LabelValue").text("查询范围：国家范围");
	} else if (CityData.indexOf("-") > 0) {
		$("#RuleSort").val("市级范围");
		RuleSotrWork();
		init(true);
		WriteValue();
	} else {
		$("#RuleSort").val("省级范围");
		RuleSotrWork();
		init(false);
		WriteValue();
	}
}
function WriteValue() {
	var TempValue = CityData.split("-");
	$("#province").val(TempValue[0]);
	if (TempValue[1] != "") {
		CitySelect(TempValue[0]);
		$("#city").val(TempValue[1]);
	}
	$("#LabelValue").text("查询范围：" + GetLocationValue)
}
$(document).ready(function() { GetRuleCity() });