var hospitalType = null;
function selOrgan(obj) {
	$("#organId").val(obj);

	$("#hospitalName").val();
	$("#TPAName").val();
	$("#contexts").html("");
	$("#contextInfo").html("");



	$("#sh5").html("");
	$("#sh6").html("");

	hospitalType = obj;
	if (hospitalType == "01") {
		oid = "";
		$("#sh5").html("医院名称:");
		$("#sh6")
				.html(
						"<input type='text' id=\"hsName\" name='hsName' class='input i_s_240' onclick=\"showDiv('open0')\"/>");
	}
	if (hospitalType == "02") {
		oid = "";
		$("#sh5").html("TPA名称  : ");
		$("#sh6")
				.html(
						"<input type='text' id=\"hsName\" name='hsName' class='input i_s_240' onclick=\"showDiv('open1')\"/>");
	}
}
var hospitalName = null;
function query() {
	$("#contexts").html("");
	hospitalName = $("#hospitalName").val();
	if (hospitalName == "") {
		alert("医院名不能为空");
		return;
	}
	$.ajax({
		type : "POST",
		url : "/claimserver/batchOperation/queryHospital.do",
		data : {
			"hospitalName" : hospitalName,
			"hospitalType" : hospitalType
		},
		error : function() {
			alert("查询数据失败，请稍后重试！");
		},
		success : function(data) {
			if (data == "") {
				alert("无返回数据");
			}
			for ( var i = 0; i < data.length; i++) {
				$("#contexts").append(
						"<tr nid=\"" + data[i].objid
								+ "\"  onclick=\"choosEd(this)\" id="

								+ "><td>" + data[i].partnerName + "</td><td>"
								+ data[i].partnerAddr + "</td><td>"
								+ data[i].partnerType + "</td><td>"
								+ data[i].contactPerson + "</td><td>"
								+ data[i].contactPhone + "</td><td>"
								+ data[i].bankAccountName + "</td><td>"
								+ data[i].bankName + "</td><td>"
								+ data[i].bankAccountNo + "</td></tr>");
			}

		}

	});
}

var TPAName = null;
function queryTPA() {
	$("#contextInfo").html("");
	TPAName = $("#TPAName").val();
	if (TPAName == "") {
		alert("TPA名不能空");
		return;
	}
	$.ajax({
		type : "POST",
		url : "/claimserver/batchOperation/queryHospital.do",
		data : {
			"TPAName" : TPAName,
			"hospitalType" : hospitalType

		},
		error : function() {
			alert("查询数据失败，请稍后重试！");
		},

		success : function(data) {
			if (data == "") {
				alert("无返回数据");
			}
			for ( var i = 0; i < data.length; i++) {
				$("#contextInfo").append(
						"<tr nid=\"" + data[i].objid
								+ "\"  onclick=\"choosEd(this)\"><td>"
								+ data[i].partnerName + "</td><td>"
								+ data[i].partnerAddr + "</td><td>"
								+ data[i].partnerType + "</td><td>"
								+ data[i].contactPerson + "</td><td>"
								+ data[i].contactPhone + "</td><td>"
								+ data[i].payMode + "</td></tr>");
			}
		}
	});
}

// var id = null;
// var hospitalType = null;
// function select(object) {
// hospitalType = object;
// if (hospitalType == "01" ) {
// $("#sh5").html("医院名称:");
// $("#sh6")
// .html(
// "<input type='text' id=\"hsName\" class='input i_s_240'
// onclick=\"showDiv('open0')\"/>");
// }
// if (hospitalType == "02") {
// $("#sh5").html("TPA名称 : ");
// $("#sh6")
// .html(
// "<input type='text' id=\"hsName\" class='input
// i_s_240'onclick=\"showDiv('open1')\"/>");
// }
// }

var oid = "";
var hsName = "";
function choosEd(obj) {
	var tds = obj.childNodes;
	oid = $(obj).attr("nid");
	hsName = tds[0].innerHTML;

	$(obj).css("background-color", "#e5e5e5").siblings().css(
			"background-color", "#FFFFFF");
	index = $(obj).index();
}

function deleteData(obj) {

	if (confirm("确定删除？")) {

		obj.parentNode.parentNode.remove();
	}

}

function confirms() {
	$("#hsName").val(hsName);
	closeDiv('open0');
	closeDiv('open1');

}

function loginInfo() {
	var checkboxs = document.getElementsByClassName("check_yes");// span
	var checkBillNos=document.getElementsByName("checkBillNos");
	if(checkBillNos.length<1){
		alert("批次生成失败");
		return;
	}
	if (checkboxs == null || checkboxs.length == 0) {
		alert("请勾选账单");
		return;
	}
	$("#infoPut")
			.attr('action','/claimserver/batchOperation/queryByBillsInfoTable.do');
	$("#infoPut").submit();
}
function queryCheckBillDetailData() {

	/*
	 * var checkBillNo=$("#checkBillNo").val(); if(checkBillNo=="" ||
	 * checkBillNo==null){ isNull=true; }
	 */
	var fDate = "";
	var lDate = "";
	var flg = false;
	fDate = $("#firstDate").val();
	lDate = $("#lastDate").val();

	if (fDate != "" && lDate != "") {
		flg = true;
	}
	if (fDate == "" && lDate == "") {
		flg = true;
	}

	if (flg == false) {
		alert("请输入完整日期区间!");
		return;
	}
	if (fDate > lDate) {
		alert("开始日期大于结束日期");
		return;
	}
	var fds1=fDate.split("-");
	var fds2=lDate.split("-");
	var year=fds2[0]-fds1[0];
	var month=fds2[1]-fds1[1];
	var day=fds2[2]-fds1[2];
	if(year>1){
		alert("时间必须在一年之内");
		return;
	}else if(year==1){
		if(month>0){
			alert("时间必须在一年之内");
			return;
		}else if(month==0){
			if(day>0){
				alert("时间必须在一年之内");
				return;
			}
		}
		
	}
	$("#formQuery")
			.attr('action','/claimserver/checkBatchDetails/queryCheckBatchDetails.do');
	$("#formQuery").submit();

}
function choice(n) {
	var s=$("span[name=checkBox]");
	var infos=document.getElementsByName("checkBillNos");
	var checkboxs=document.getElementsByClassName("check_yes");
	if ($("#ckAll").is(".check_yes")) {
		for(var i in s){
			if(s[i].className=="check_yes"){
				s[i].className="check_no";
				for(var i=0;i<checkboxs.length;i++){
					infos[i].value="";
					

					}
			}
		}
		$(n).className="check_no";
	} else {
		for(var i in s){
			if(s[i].className=="check_no"){
				s[i].className="check_yes";
				for(var i=0;i<checkboxs.length;i++){
					infos[i].value=checkboxs[i].id;
					}
			}
		}
		$(n).className="check_yes";
	}
}

var checkBoxsLength = 0;
function choice1(obj, n, status) {
	var infos=document.getElementsByName("checkBillNos");
	if ($(obj).is(".check_no")){
		$(obj).className="check_yes";
		if(obj.className =='check_no'){
			infos[status].value=n;
		 }
		var s = $("span[name=checkBox]");
		var isAllChecked = true;
		for(var i in s){
			if(s[i].className=="check_no"){
				if (s[i].id != n){
					isAllChecked = false;
					break;
				}
			}
		}
		if (isAllChecked) {
			$("#ckAll").removeClass("check_no").addClass("check_yes");
		}
	} else {
		$(obj).className="check_no";
		$("#ckAll").removeClass("check_yes").addClass("check_no");
		infos[status].value="";
	}

}

function execlExport() {
	var checkboxs = document.getElementsByClassName("check_yes");// span
	var checkBillNos=document.getElementsByName("checkBillNos");
	if(checkBillNos.length<1){
		alert("导出失败");
		return;}
	if (checkboxs==null||checkboxs.length==0) {
		alert("请勾选账单号");
		return;
	}
	$("#infoPut").attr('action','/claimserver/batchOperation/execlExport.do');
	$("#infoPut").submit();
}