$(function() {
	var O_Province = $("#O_Province");
	var O_City = $("#O_City");
	var O_Area = $("#O_Area");
	var O_ShopArea = $("#O_ShopArea");
	var O_Landmark = $("#O_Landmark");
	
	O_Province.change(function() {
		var provinceId = O_Province.val();
		if(provinceId != "") {
			$.post("?m=admin/city.getListByProvince", { provinceId:provinceId, pageSize:0, json:true }, function(data) {//alert(data);
				O_City.empty();
				O_City.append("<option value=\"\">==城市==</option>");
				O_Area.empty();
				O_Area.append("<option value=\"\">==行政区==</option>");
				$.each(data, function(id, item) {
					O_City.append("<option value=\"" + item.id + "\">" + item.name + "</option>");
				});
			}, "json");
		} else {
			O_City.empty();
			O_City.append("<option value=\"\">==城市==</option>");
			O_Area.empty();
			O_Area.append("<option value=\"\">==行政区==</option>");
		}
	});
	
	O_City.change(function() {
		var cityId = O_City.val();
		if(cityId != "") {
			$.post("?m=admin/area.getListByCity", { cityId:cityId, pageSize:0, json:true }, function(data) {//alert(data);
				O_Area.empty();
				O_Area.append("<option value=\"\">==行政区==</option>");
				$.each(data, function(id, item) {
					O_Area.append("<option value=\"" + item.id + "\">" + item.name + "</option>");
				});
			}, "json");
		} else {
			O_Area.empty();
			O_Area.append("<option value=\"\">==行政区==</option>");
		}
	});
	
	O_Area.change(function() {
		var areaId = O_Area.val();
		if(areaId != "") {
			$.post("?m=admin/shoparea.getListByArea", { areaId:areaId, pageSize:0, json:true }, function(data) {//alert(data);
				O_ShopArea.empty();
				O_ShopArea.append("<option value=\"\">==商业区==</option>");
				$.each(data, function(id, item) {
					O_ShopArea.append("<option value=\"" + item.id + "\">" + item.name + "</option>");
				});
			}, "json");
			$.post("?m=admin/landmark.getListByArea", { areaId:areaId, pageSize:0, json:true }, function(data) {//alert(data);
				O_Landmark.empty();
				O_Landmark.append("<option value=\"\">==标志物==</option>");
				$.each(data, function(id, item) {
					O_Landmark.append("<option value=\"" + item.id + "\">" + item.name + "</option>");
				});
			}, "json");
		} else {
			O_ShopArea.empty();
			O_ShopArea.append("<option value=\"\">==商业区==</option>");
			O_Landmark.empty();
			O_Landmark.append("<option value=\"\">==标志物==</option>");
		}
	});
	
	var O_Add = $("#O_Add");
	O_Add.click(function() {
		var O_Name = $("#O_Name");
		var O_EnName = $("#O_EnName");
		var O_ShortName = $("#O_ShortName");
		var O_Phone = $("#O_Phone");
		var O_Level = $("#O_Level");
		var O_Area = $("#O_Area");
		var O_ShopArea = $("#O_ShopArea");
		var O_Landmark = $("#O_Landmark");
		var O_Address = $("#O_Address");
		var O_Detail = CKEDITOR.instances.O_Detail;
		var O_Catering = CKEDITOR.instances.O_Catering;
		var O_Facility = CKEDITOR.instances.O_Facility;
		var O_Meeting = CKEDITOR.instances.O_Meeting;
		var O_Scenery = CKEDITOR.instances.O_Scenery;
		var O_Traffic = CKEDITOR.instances.O_Traffic;
		
		var O_Title = $("#O_Title");
		var O_Keywords = $("#O_Keywords");
		var O_Description = $("#O_Description");
		var O_ListTitle = $("[name='O_ListTitle']:checked"); 
		var O_Status = $(":input[name='O_Status']:checked");
		
		var v_name = O_Name.val().replace(/ /g, '').replace(/'/g, '').replace(/"/g, '');
		var v_enname = O_EnName.val().replace(/'/g, '').replace(/"/g, '');
		var v_shortname = O_ShortName.val().replace(/ /g, '').replace(/'/g, '').replace(/"/g, '');
		var v_phone = O_Phone.val().replace(/ /g, '').replace(/'/g, '').replace(/"/g, '');
		var v_level = O_Level.val();
		var v_area = O_Area.val();
		var v_shopArea = O_ShopArea.val();
		var v_landmark = O_Landmark.val();
		var v_address = O_Address.val().replace(/ /g, '').replace(/'/g, '').replace(/"/g, '');
		//服务
		var v_service = "";
		$(":input[name='O_Service']:checked").each(function() {
			if(v_service.length > 0) v_service += '|';
    		v_service += $(this).val();
		});
		var v_detail = O_Detail.getData().replace(/'/g, '').replace(/"/g, '');
		var v_catering = O_Catering.getData().replace(/'/g, '').replace(/"/g, '');
		var v_facility = O_Facility.getData().replace(/'/g, '').replace(/"/g, '');
		var v_meeting = O_Meeting.getData().replace(/'/g, '').replace(/"/g, '');
		var v_scenery = O_Scenery.getData().replace(/'/g, '').replace(/"/g, '');
		var v_traffic = O_Traffic.getData().replace(/'/g, '').replace(/"/g, '');
		var v_baiduMapX = $("#O_BaiduX").html().replace(/ /g, '').replace(/'/g, '');
		var v_baiduMapY = $("#O_BaiduY").html().replace(/ /g, '').replace(/'/g, '');
		var v_title = O_Title.val().replace(/'/g, '').replace(/"/g, '');
		var v_keywords = O_Keywords.val().replace(/'/g, '').replace(/"/g, '');
		var v_description = O_Description.val().replace(/'/g, '').replace(/"/g, '');
		var v_listTitle = O_ListTitle.val();
		var v_status = O_Status.val();
		
		if(v_name == '') {
			alert("请填写酒店名称！");
			O_Name.focus();
			return false;
		} else if(v_level == '') {
			alert("请选择酒店星级！");
			O_Level.focus();
			return false;
		} else if(v_area == '') {
			alert("请选择所在区域！");
			O_Area.focus();
			return false;
		} else {
			O_Add.attr("disabled", true);
			if(v_shopArea == '') v_shopArea = '0';
			if(v_landmark == '') v_landmark = '0';
			$.post("?m=admin/hotel.addHandle", { name:v_name, enName:v_enname, shortName:v_shortname, phone:v_phone, levelId:v_level, areaId:v_area, shopareaId:v_shopArea, landmarkId:v_landmark, address:v_address, service:v_service, detail:v_detail, catering:v_catering, facility:v_facility, meeting:v_meeting, scenery:v_scenery, traffic:v_traffic, baiduMapX:v_baiduMapX, baiduMapY:v_baiduMapY, title:v_title, keywords:v_keywords, description:v_description, listTitle:v_listTitle, status:v_status }, function(data) {//alert(data);
				alert(data[1]);
				if(data[0] == "success") {
					window.location.reload();
				} else {
					if(data[2] == "name is null") {
						O_Name.focus();
					} else if(data[2] == "levelId is null") {
						O_Level.focus();
					} else if(data[2] == "areaId is null") {
						O_Area.focus();
					}
				}
				O_Add.attr("disabled", false);
			}, "json");
		}
	});
}); 