$(".ibox-content table a,.ibox-title a,#tableEventsToolbar a").click(function(event) {
	var url = $(this).attr("href");
	if ($(this).attr("target") == "dialog") {
		event.preventDefault();
		var dialogWidth = $(this).attr("width");
		var dialogHeight = $(this).attr("height");
		var title = $(this).html();
		parent.layer.open({
			type : 2,
			title : title,
			closeBtn : 1,
			shadeClose : false,
			scrollbar : false,
			area : [ dialogWidth, dialogHeight ],
			content : url,
			skin : 'popup',
			btn : [ "确定", "取消" ],
			yes : function(indexIframe, layero) {
				// var iframeWin =
				// parent.window[layero.find('iframe')[0]['name']];
				// //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
				var body = parent.layer.getChildFrame('body', indexIframe);
				body.find('form').submit();
			}
		});
	}else if ($(this).attr("target") == "dialogDetail") {
        event.preventDefault();
        var dialogWidth = $(this).attr("width");
        var dialogHeight = $(this).attr("height");
        var title = $(this).html();
        parent.layer.open({
            type : 2,
            title : title,
            closeBtn : 1,
            shadeClose : false,
            scrollbar : false,
            area : [ dialogWidth, dialogHeight ],
            content : url,
            skin : 'popup',
            btn : [ "确定"]
        });
    }else if($(this).attr("target")=="ajaxTodo"){
		event.preventDefault();
		var msg = $(this).attr("title");
		var title = $(this).html();
		parent.layer.confirm(msg, {
			title:title,
			skin : 'popup',
			btn: ['确定','取消'] //按钮
		}, function(){
			parent.layer.closeAll();
			var loadIndex = parent.layer.load(0, {shade: [0.3,'#808080']});
			$.ajax({
				type : 'POST',
				url : url,
				dataType : "json",
				//async :false,
				success : function(json) {
					parent.layer.close(loadIndex);
					dialogAjaxDone(json);
				},error: function(xhr, ajaxOptions, thrownError){
					parent.layer.close(loadIndex);
					ajaxError(xhr, ajaxOptions, thrownError);
				}
				});
		}, function(){
			parent.layer.closeAll();
		});
	}
});

function ajaxSuccess(json){
	parent.layer.closeAll();
	toastr.clear();
	toastr.success(json.message);
}

function validateCallback(form) {
	var $form = $(form);
	if (!$form.valid()) {
		return false;
	}
	var loadIndex = parent.layer.load(0, {shade: [0.3,'#808080']});
	$.ajax({
		type:form.method||'POST',
		url:$form.attr("action"),
		data:$form.serializeArray(),
		dataType:"json",
		async :false,
		success : function(json) {
			parent.layer.close(loadIndex);
			dialogAjaxDone(json);
		},error: function(xhr, ajaxOptions, thrownError){
			parent.layer.close(loadIndex);
			ajaxError(xhr, ajaxOptions, thrownError);
		}
		});
	return false;
}





function validateCallbackDow(form) {
	var $form = $(form);
	if (!$form.valid()) {
		return false;
	}
	debugger;
	var loadIndex = parent.layer.load(0, {shade: [0.3,'#808080']});
	$.ajax({
		type:form.method||'POST',
		url:$form.attr("action"),
		data:$form.serializeArray(),
		dataType:"json",
		success : function(json) {
			if(json.data!=null&&json.data.length>0){
				download(json);
			}else {
				dialogAjaxDone(json);
				parent.layer.close(loadIndex);
			}
		},error: function(xhr, ajaxOptions, thrownError){
			parent.layer.close(loadIndex);
			ajaxError(xhr, ajaxOptions, thrownError);
		}
	});
	return false;
}






function validateCallbackDow2(form) {
	var $form = $(form);
	if (!$form.valid()) {
			return false;
		}

	var forms = new FormData(document.getElementById('batchSecurity'));
debugger;
	var loadIndex = parent.layer.load(0, {shade: [0.3,'#808080']});
	$.ajax({
		type:'POST',
		url:$form.attr("action"),
		data:forms,
		processData:false,              // 这个参数必须要 在你发送文件上传的时候就需要设置
		contentType:false,
		dataType:"json",
		success : function(json) {
			if(json.data!=null&&json.data.length>0){
				download(json);
			}else {
				dialogAjaxDone(json);
				parent.layer.close(loadIndex);
			}
		},error: function(xhr, ajaxOptions, thrownError){
			parent.layer.close(loadIndex);
			ajaxError(xhr, ajaxOptions, thrownError);
		}
	});
	return false;
}






function dialogAjaxDone(json) {
	if (json.statusCode == "200") {
		if ("closeCurrent" == json.callbackType) {
            parent.reloadPage(json.navTabId);
			parent.ajaxDone(json);
			closeCurrent();
		}else if ("refreshCurrent" == json.callbackType) {
            refresh();
            parent.ajaxDone(json);
        }else{
            ajaxDone(json);
        }
	}else
		ajaxDone(json);
}

function ajaxError(xhr, ajaxOptions, thrownError) {
	toastr.options = {
		"closeButton" : true,
		"debug" : false,
		"progressBar" : false,
		"positionClass" : "toast-top-center",
		"onclick" : null,
		"showEasing" : "swing",
		"showMethod" : "fadeIn"
	}
	toastr.clear();
	toastr.error("Http status: " + xhr.status + " " + xhr.statusText + "\najaxOptions: "
			+ ajaxOptions + "\nthrownError:" + thrownError + "\n" + xhr.responseText);
}

function download(json) {
	// window.open(ctx+"/"+url);

	var  arr=json.data;
	debugger;
	for(j = 0,len=arr.length; j < len; j++) {
	var form = $("<form>");//定义一个form表单
	form.attr("style", "display:none");
	form.attr("target", "");
	form.attr("method", "post");
	form.attr("action", ctx+"/"+arr[j]);
	$("body").append(form);//将表单放置在web中
	form.submit();//表单提交
	form.remove();//表单提交
	parent.layer.confirm('<div style="text-align:center"><p>报告导出成功</p></div>', {
		title: "温馨提示",
		skin: "confirm-class",
		btn: ['我知道了']
		//按钮
	}, function (index) { // 按钮1的回调
		dialogAjaxDone(json);
	});

	}

}

function ajaxDone(json) {
	if (json.statusCode == "300") {
		toastr.options = {
			"closeButton" : true,
			"debug" : false,
			"progressBar" : false,
			"positionClass" : "toast-top-center",
			"onclick" : null,
			"showEasing" : "swing",
			"showMethod" : "fadeIn"
		}
		toastr.clear();
		toastr.error(json.message);
	} else if (json.statusCode == "200") {
		toastr.options = {
			"closeButton" : false,
			"debug" : false,
			"progressBar" : false,
			"positionClass" : "toast-top-center",
			"onclick" : null,
			"showDuration" : "400",
			"hideDuration" : "1000",
			"timeOut" : "7000",
			"extendedTimeOut" : "2000",
			"showEasing" : "swing",
			"hideEasing" : "linear",
			"showMethod" : "fadeIn",
			"hideMethod" : "fadeOut"
		}
		toastr.clear();
		toastr.success(json.message);
	}
}

function closeCurrent(){
	parent.layer.closeAll();
}

function reloadPage(navTabId){
	$("#"+navTabId).trigger("click");
}


function toastrError(message){
	toastr.options = {
			"closeButton" : true,
			"debug" : false,
			"progressBar" : false,
			"positionClass" : "toast-top-center",
			"onclick" : null,
			"showEasing" : "swing",
			"showMethod" : "fadeIn"
		}
		toastr.clear();
		toastr.error(message);
}

function toastrSuccess(message){
	toastr.options = {
			"closeButton" : false,
			"debug" : false,
			"progressBar" : false,
			"positionClass" : "toast-top-center",
			"onclick" : null,
			"showDuration" : "400",
			"hideDuration" : "1000",
			"timeOut" : "7000",
			"extendedTimeOut" : "2000",
			"showEasing" : "swing",
			"hideEasing" : "linear",
			"showMethod" : "fadeIn",
			"hideMethod" : "fadeOut"
		}
		toastr.clear();
		toastr.success(message);
}