$(document).ready(function() {
var ctx = $("#ctx").val();//获取服务器地址
	
	/***************************    热点管理列表页    ***************************/

	//开启,暂停
	$("#btn-enable,#btn-disable,#btn-delete").click(function(){
		if($(this).attr("id") == "btn-enable"){
			url = ctx+"/operator/main/ap/apmac/enable";
		}else if($(this).attr("id") == "btn-disable"){
			url = ctx+"/operator/main/ap/apmac/disable";
		}else if($(this).attr("id") == "btn-delete"){
			url = ctx+"/operator/main/ap/apmac/delete";
		}
		singleOper($(this),url);
	});
			
	//批量开启,批量暂停
	$("#all-btn-enable,#all-btn-disable,#all-btn-delete").click(function(){
		if($(this).attr("id") == "all-btn-enable"){
			url = ctx+"/operator/main/ap/apmac/enable";
		}else if($(this).attr("id") == "all-btn-disable"){
			url = ctx+"/operator/main/ap/apmac/disable";
		}else if($(this).attr("id") == "all-btn-delete"){
			url = ctx+"/operator/main/ap/apmac/delete";
		}
		batchOpear($(this),url);
	});
	
	$("#btn_formSubmit").click(function(){
		refreshData();
	});
	
	/***************************    新建，编辑热点页面    ***************************/
	
	if($("#apmacListForm").html()){
		$("#apmacListForm").autovalidate();
	}
	
	$("#btn-apmac-save").click(function(){
		if (!$("#apmacListForm").validate()) {
			return false;
		}
		if($("#cn").val() == ""){
			$("#main_cnul").addClass("mainChange").attr("title","请选择省份");
			$("#cnul_selectdiv").find('span.spanVaildate').html("请选择省份");
			return false;
		}
		if($("#cnCity").val() == ""){
			$("#main_cnCityul").addClass("mainChange").attr("title","请选择省份对应的城市");
			$("#cnCityul_selectdiv").find('span.spanVaildate').html("请选择省份对应的城市");
			return false;
		}
		if($("#place").val() == ""){
			$("#main_placeul").addClass("mainChange").attr("title","请选择场景");
			$("#placeul_selectdiv").find('span.spanVaildate').html("请选择场景");
			return false;
		}
		$("#apmacListForm").submit();
		return false;
	});
	
	$("#btn-apmac-cancel").click(function(){
		window.location.href = ctx+"/operator/main/ap/apmac/list";
	});
	
	if($("#cnUl_selectdiv").html()){
		$("#cnul_box").mouseleave(function(){
	 		if($("#cn").val() == ""){
				$("#main_cnul").addClass("mainChange").attr("title","请选择省份");
				$("#cnUl_selectdiv").find('span.spanVaildate_ul').html("请选择省份");
			}else{
				$("#main_cnul").removeClass("mainChange").attr("title","");
				$("#cnUl_selectdiv").find('span.spanVaildate_ul').html("");
			}
	 	});
	}
	
	if($("#cnCityUl_selectdiv").html()){
	 	$("#cnCityul_box").mouseleave(function(){
	 		if($("#cnCity").val() == ""){
				$("#main_cnCityul").addClass("mainChange").attr("title","请选择省份对应的城市");
				$("#cnCityUl_selectdiv").find('span.spanVaildate_ul').html("请选择省份对应的城市");
			}else{
				$("#main_cnCityul").removeClass("mainChange").attr("title","");
				$("#cnCityUl_selectdiv").find('span.spanVaildate_ul').html("");
			}
	 	});
	}
	
	if($("#placeul_selectdiv").html()){
	 	$("#placeul_box").mouseleave(function(){
	 		if($("#place").val() == ""){
				$("#main_placeul").addClass("mainChange").attr("title","请选择场景");
				$("#placeul_selectdiv").find('span.spanVaildate_ul').html("请选择场景");
			}else{
				$("#main_placeul").removeClass("mainChange").attr("title","");
				$("#placeul_selectdiv").find('span.spanVaildate_ul').html("");
			}
	 	});
	}
});

function exportExcel_list(){
	var searchValue = $("#searchValue").val();
	if(searchValue == "请输入关键字"){
		searchValue = "";
	}
	var param = "?cn="+$("#cn").val()+"&cnCity="+$("#cnCity").val()+"&place="+$("#place").val()+"&placeId="+$("#placeId").val()+"&searchValue="+searchValue;
	$("#exportExcel").attr("href",$("#ctx").val()+"/operator/main/ap/apmac/exportApListExcel"+param);
	return false;
}

function exportExcel_relationship(){
	var searchValue = $("#searchValue").val();
	if(searchValue == "请输入关键字"){
		searchValue = "";
	}
	var param = "?searchValue="+searchValue;
	$("#exportExcel").attr("href",$("#ctx").val()+"/operator/main/ap/apmac/exportRelationshipExcel"+param);
	return false;
}