$(function() {
		
	var O_Province = $("#O_Province");
	var O_City = $("#O_City");
	var O_Area = $("#O_Area");

	var O_Landmark = $("#O_Landmark");
	var O_ServiceAdd  = $("#O_ServiceAdd");
	
	
	$('#add_ktvType').click(function(){
		var ktv_type = $('#ktvType').attr('value');
		
		$.post("?m=admin/ktv.addKtvType", { name:ktv_type }, function(data) {
			if(data > 0)
			{
				alert('添加成功');	
			}
			var option = "<option checked='checked' value="+ data +">" + ktv_type + "</option>";
			
			$('#O_Ktvtype').append(option)
			
			
		
		});
	})
	
	O_ServiceAdd.click(function(){
		
		
		
		var O_Service = $('#service_content').val();
		var txt = "<div style='width:auto; padding-left:5px; padding-right:5px; float:left;'><input type='checkbox' name='O_Service' value='"+ O_Service +"' id='O_Service_0'>"+ O_Service +"</div>";				
		alert($('#service_content_info').append(txt));
	})
	
	
	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) {
																						
				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);
				var O_ShopArea = $("#O_ShopArea");																														
				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_Subtitle = $("#O_Subtitle");
		var O_Landmark = $("#O_Landmark");
		var O_Address = $("#O_Address");
		
		var e_Detail = e_detail.getContent();
		var e_Facility = e_facility.getContent();
		var e_Traffic = e_traffic.getContent();


		var O_Detail = CKEDITOR.instances.O_Detail;
		
		var O_opentime = $("#O_Opentime"); 
		var O_closetime = $("#O_Closetime"); 
		
		var O_ktvtype = $("#O_Ktvtype"); 
		var O_Facility = CKEDITOR.instances.O_Facility;
		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_ktvtype = O_ktvtype.val();

		var O_Opentime = O_opentime.val();
		var v_Closetime = O_closetime.val();
		
		var v_shopArea = O_ShopArea.val();
		var v_landmark = O_Landmark.val();
		
		var v_Subtitle = O_Subtitle.val();
		
		var v_address = O_Address.val().replace(/ /g, '').replace(/'/g, '').replace(/"/g, '');
		var v_listTitle = $('input:radio[name="O_ListTitle"]:checked').val(); 
		//服务
		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("请填写KTV名称！");
			O_Name.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/ktv.addHandle", { name:v_name, enName:v_enname, shortName:v_shortname, phone:v_phone, ktvtype:v_ktvtype, areaId:v_area, shopareaId:v_shopArea, landmarkId:v_landmark, address:v_address, service:v_service, detail:e_Detail,  facility:e_Facility, traffic:e_Traffic, baiduMapX:v_baiduMapX, baiduMapY:v_baiduMapY, title:v_title, keywords:v_keywords, description:v_description, listTitle:v_listTitle, status:v_status , opentime:O_Opentime,closetime:v_Closetime,subtitle:v_Subtitle , listTitle:v_listTitle}, function(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");
		}
	});
}); 