var highLightIndex = -1;
$(function() {
	var O_Type = $("#O_Type");
	var mainlist = $("#mainlist");
	var O_SimpleSearchBtn = $("#O_SimpleSearchBtn");
	var O_Field = $("#simpleSearch");
	var O_Key = $("#simpleSearchKey");
	var O_KeyOffset = O_Key.offset();
	var O_Auto = $("#auto");
	O_Auto.hide(); // 隐藏自动补全框
	O_Auto.css("border", "1px solid #817F82")
	.css("background-color", "#fff")
	.css("position", "absolute")
	.css("z-index", "1000")
	.css("top", O_KeyOffset.top + O_Key.height() + 5)
	.css("left", O_KeyOffset.left)
	.css("width", O_Key.width() + 3);
	
	var O_Flush = $("#O_Flush");
	O_Flush.hide();
	// 分页按钮
	mainlist.find(".page").click(function() {
		mainlist.find("#loading").show();
		pageClick(this);
	});
	// 点击快捷搜索按钮
	O_SimpleSearchBtn.click(function() {
		simpleSearch();
	});
	O_Key.focus();
	// 搜索失去焦点
	O_Key.blur(function() {
		if(highLightIndex != -1) {
			var nodes = O_Auto.children("div");
			O_Key.val(nodes.eq(highLightIndex).html());
			highLightIndex = -1;
		}
		O_Auto.hide();
		O_SimpleSearchBtn.focus();
	});
	getCount();
});
// 快捷搜索
function simpleSearch() {
	var O_Type = $("#O_Type");
	var mainlist = $("#mainlist");
	var O_Flush = $("#O_Flush");
	var v_field = $("#simpleSearch").val();
	var O_Key = $("#simpleSearchKey");
	var v_key = O_Key.val().replace(/ /g, '').replace(/'/g, '');
	// 设置列表类型
	if(v_key == "") {
		O_Type.val("list");
	} else {
		O_Type.val("simplesearch");
	}
	O_Flush.show();
	$.post("?m=admin/order.visa_simpleSearch", { field:v_field, key:v_key }, function(data) {
		mainlist.html(data);
		mainlist.find(".page").click(function() {
			mainlist.find("#loading").show();
			pageClick(this);
		});
		O_Flush.hide();
	});
}
// 点击状态按钮
function statusClick(v_status) {
	var mainlist = $("#mainlist");
	var O_Flush = $("#O_Flush");
	// 设置列表类型
	$("#O_Type").val("bystatus");
	$("#currentStatus").val(v_status);
	O_Flush.show();
	$.post("?m=admin/order.getListByStatus", { status:v_status }, function(data) {
		mainlist.html(data);
		mainlist.find(".page").click(function() {
			mainlist.find("#loading").show();
			pageClick(this);
		});
		O_Flush.hide();
	});
}
// 点击会员按钮
function byMemberClick(orderId, memberId) {
	var mainlist = $("#mainlist");
	var O_Flush = $("#O_Flush");
	// 设置列表类型
	$("#O_Type").val("bymember");
	$("#currentMemberId").val(memberId);
	O_Flush.show();
	$.post("?m=admin/order.getListByMember", { memberId:memberId }, function(data) {
		mainlist.html(data);
		mainlist.find(".page").click(function() {
			mainlist.find("#loading").show();
			pageClick(this);
		});
		O_Flush.hide();
	});
}
// 加载列表
function loadList(page, linehighId) {
	var mainlist = $("#mainlist");
	var v_type = $("#O_Type").val();
	var O_Flush = $("#O_Flush");
	O_Flush.show();

	if(v_type == "list") {
		$.post("?m=admin/order.getVisaList", { page:page }, function(data) {							
			mainlist.html(data);
			mainlist.find(".page").click(function() {
				mainlist.find("#loading").show();
				pageClick(this);
			});
			if(linehighId) { 
				mainlist.find("#O_Row_" + linehighId).addClass("on"); // 高亮行
			}
			O_Flush.hide();
		});
	} else if(v_type == "simplesearch") {
		var v_field = $("#simpleSearch").val();
		var O_Key = $("#simpleSearchKey");
		var v_key = O_Key.val().replace(/ /g, '').replace(/'/g, '');
		$.post("?m=admin/order.visa_simpleSearch", { field:v_field, key:v_key, page:page } ,function(data) {
			mainlist.html(data);
			mainlist.find(".page").click(function() {
				mainlist.find("#loading").show();
				pageClick(this);
			});
			if(linehighId) { 
				mainlist.find("#O_Row_" + linehighId).addClass("on");//高亮行
			}
			O_Flush.hide();
		});
	} else if(v_type == "bystatus") {
		var v_status = $("#currentStatus").val();
		$.post("?m=admin/order.getListByStatus", { status:v_status, page:page }, function(data) {
			mainlist.html(data);
			mainlist.find(".page").click(function() {
				mainlist.find("#loading").show();
				pageClick(this);
			});
			if(linehighId) { 
				mainlist.find("#O_Row_" + linehighId).addClass("on");//高亮行
			}
			O_Flush.hide();
		});
	} else if(v_type == "bymember") {
		var v_memberId = $("#currentMemberId").val();
		$.post("?m=admin/order.getMemberList",{ id:v_memberId, page:page }, function(data) {
			mainlist.html(data);
			mainlist.find(".page").click(function() {
				mainlist.find("#loading").show();
				pageClick(this);
			});
			if(linehighId) { 
				mainlist.find("#O_Row_" + linehighId).addClass("on");//高亮行
			}
			O_Flush.hide();
		});
	}
}
//分页点击
function pageClick(t) {
	
	loadList(t.id);
}
//首页
function firstPage() {
	var O_FirstPage = document.createElement("span");
	O_FirstPage.id = "1";
	$("#loading").show();
	pageClick(O_FirstPage);
}
//上一页
function prevPage() {
	var prevPage = parseInt($("#O_CurrentPage").val()) - 1;
	var O_PrevPage = $("#" + prevPage.toString());
	O_PrevPage.triggerHandler("click");
}
//下一页
function nextPage() {
	var nextPage = parseInt($("#O_CurrentPage").val()) + 1;
	var O_NextPage = $("#" + nextPage.toString());
	O_NextPage.triggerHandler("click");
}
//尾页
function lastPage() {
	var pageCount = parseInt($("#O_PageCount").val());
	var O_LastPage = document.createElement("span");
	O_LastPage.id = pageCount.toString();
	$("#loading").show();
	pageClick(O_LastPage);
}
//跳转到下拉列
function goPage() {
	var O_Page = $("#O_Page");
	var O_Go = $("#O_Go");
	var O_GoPage  = document.createElement("span");
	O_GoPage.id = O_Page.val();
	$("#loading").show();
	pageClick(O_GoPage);
}
// 订单浏览
function viewClick(t) {
	$("#divView h1 span").html("订单信息浏览");
	var O_Content = $("#contentView");
	O_Content.html('<div style="width:580px;height:200px;_height:300px;font-size:14px;text-align:center;"><span style="margin-top:120px;margin-bottom:15px;">正在加载...</span><img src="theme/admin/images/loading.gif"></div>');
	setView();
	var id = t.id.replace(/o_/g, '');
	highLightRow(id);//高亮行
	$.post("?m=admin/order.info", { id:id }, function(data) {//alert(data);
		O_Content.html(data);
		setView();
	});
	//启动浏览模式
	openView();
}
//添加
function addClick() {
	$("#divUpdate h1 span").html("订单信息添加");
	var O_Content = $("#contentUpdate");
	O_Content.html('<div style="width:580px;height:200px;_height:300px;font-size:14px;text-align:center;"><div style="margin-top:120px;margin-bottom:15px;">正在加载...</div><img src="theme/admin/images/loading.gif"></div>');
		alert(1);
		return;
	setUpdate();
	$.post("?m=admin/order.add", {}, function(data) {//alert(data);
		O_Content.html(data);
		setUpdate();
		setMember();
	
		$("#O_SumbitUpdate").attr("disabled", false).unbind("click").click(function() { add(); });
	});
	//启动浏览模式
	openUpdate();
}
// 订单状态更新
function updateStatusClick(t) {

	$("#divUpdate h1 span").html("订单状态更新");
	var O_Content = $("#contentUpdate");
	O_Content.html('<div style="width:580px;height:200px;_height:300px;font-size:14px;text-align:center;"><div style="margin-top:120px;margin-bottom:15px;">正在加载...</div><img src="theme/admin/images/loading.gif"></div>');
	setUpdate();

	var id = t.id.replace(/o_/g, '');
	highLightRow(id);//高亮行
	$.post("?m=admin/order.visa_updateStatus", { id:id }, function(data) {//alert(data);
		O_Content.html(data);
		setUpdate();
		
		$("#O_SumbitUpdate").attr("disabled", false).unbind("click").click(function() { 
			updateStatus();
		});
	});
	//启动浏览模式
	openUpdate();
}
// 订单信息更新
function updateClick(t) {
	$("#divUpdate h1 span").html("订单信息更新");
	var O_Content = $("#contentUpdate");
	O_Content.html('<div style="width:580px;height:200px;_height:300px;font-size:14px;text-align:center;"><div style="margin-top:120px;margin-bottom:15px;">正在加载...</div><img src="theme/admin/images/loading.gif"></div>');
	setUpdate();
	var id = t.id.replace(/o_/g, '');
	highLightRow(id);//高亮行
	alert(2);
	return;
	$.post("?m=admin/order.update", { id:id }, function(data) {//alert(data);
		O_Content.html(data);
		setUpdate();
		setMember();
		
		$("#O_SumbitUpdate").attr("disabled", false).unbind("click").click(function() { update(); });
	});
	//启动浏览模式
	openUpdate();
}
// 删除
function delClick(t) {
	if(confirm("删除所选酒店订单，确认？")) {
		var id = t.id.replace(/o_/g, '');
		$.post("?m=admin/order.visadelHandle", { id:id }, function(data){
			if(data[0] == "success") {
				//刷新列表
				var page = $("#O_CurrentPage").val();
				loadList(page);
				//刷新统计
				getCount();
			} else {
				alert(data[1]);
			}
		}, "json");
		return true; 
	}
	return false;
}
// 全选删除
function checkDelAll() {
	$(".delAll").attr("checked", $("#o_delall").attr("checked"));
}
// 批量删除
function delSelectClick() {
	if(confirm("删除所选酒店订单，确认？")) {
		// 遍历得到每个checkbox的value值
        var arrChk = $(":input[class='delAll']:checked");  
        var v_ids = "";  
        for(var i = 0; i < arrChk.length; i++) {
            v_ids += arrChk[i].value;
            if(i < arrChk.length - 1) v_ids += ",";
        }
		$.post("?m=admin/order.delSelect", { ids:v_ids }, function(data) {
			// 刷新列表
			var page = $("#O_CurrentPage").val();
			loadList(page);
			// 刷新统计
			getCount();
		});
		return true; 
	}
	return false;
}
//获取统计
function getCount() {
	$.post("?m=admin/order.getVisaCount", {}, function(data) {
													
		var str = "共 <span class=\"f_14b_f00\">" + data.all + "</span> 个, 已点评 <span class=\"f_14b_f00\">" + data.comment + "</span> 个, 已入住 <span class=\"f_14b_f00\">" + data.checkin + "</span> 个, 已处理 <span class=\"f_14b_f00\">" + data.handle + "</span> 个, 处理中 <span class=\"f_14b_f00\">" + data.wait + "</span> 个, 已取消 <span class=\"f_14b_f00\">" + data.cancel + "</span> 个";
		$("#O_Count").html(str);
		$("#O_Flush").hide();
	}, "json");
}
// 高亮行
function highLightRow(id) {
	$(".row").removeClass("on");
	$("#O_Row_" + id).addClass("on");
}
// 获取窗体区域
function getRange() {
	// 得到屏幕的大小
    var top = document.body.scrollTop;
    var left = document.body.scrollLeft;
    var height = document.body.clientHeight;
    var width = document.body.clientWidth;
    if (top == 0 && left == 0 && height == 0 && width == 0) {
        top = document.documentElement.scrollTop;
        left = document.documentElement.scrollLeft;
        height = document.documentElement.clientHeight;
        width = document.documentElement.clientWidth;
    }
    return { top: top, left: left, height: height, width: width };
}
//更新窗体位置
function updatePosition(name) {
	var windowObj = $(window); // 获取window对象
	var browserWidth = windowObj.width(); // 获取当前浏览器长度
	var browserHeight = windowObj.height(); // 获取当前浏览器宽度
	var scrollLeft = windowObj.scrollLeft();
	var scrollTop = windowObj.scrollTop();
	var cwinWidth = $divUpdate.width();
	var cwinHeight = $divUpdate.height();
	var left = scrollLeft + (browserWidth - cwinWidth) / 2;
	var top = scrollTop + (browserHeight - cwinHeight) / 2;
	$("#div" + name).css("top", top).css("left", left);
	$("#div" + name + "F").css("top", top).css("left", left);
}
//处理
function add() {
	var page = $("#O_CurrentPage").val();
	var O_Content = $("#contentUpdate");
	var O_Room = O_Content.find("#O_Room");
	var O_InDate = O_Content.find("#O_InDate");
	var O_OutDate = O_Content.find("#O_OutDate");
	var O_BookType = O_Content.find("input[name='O_BookType']:checked");
	var O_Member = O_Content.find("#O_Member option:selected");
	var O_RoomNum = O_Content.find("#O_RoomNum");
	var O_PersonNum = O_Content.find("#O_PersonNum");
	var O_InTimeMin = O_Content.find("#O_InTimeMin");
	var O_InTimeMax = O_Content.find("#O_InTimeMax");
	var O_Name = O_Content.find("#O_Name");
	var O_Mobile = O_Content.find("#O_Mobile");
	var O_CertType = O_Content.find("#O_CertType");
	var O_Email = O_Content.find("#O_Email");
	var O_Remark = O_Content.find("#O_Remark");
	var O_TotalPrice = O_Content.find("#O_TotalPrice");
	var O_ReturnMoney = O_Content.find("#O_ReturnMoney");
	
	var v_RoomId = O_Room.val();
	var v_indate = O_InDate.val();
	var v_outdate = O_OutDate.val();
	var v_bookType = O_BookType.val();
	var v_memberId = O_Member.val();
	var v_memberAccount = O_Member.text();
	var v_roomNum = O_RoomNum.val();
	var v_personNum = O_PersonNum.val();
	var v_inTimeMin = O_InTimeMin.val();
	var v_inTimeMax = O_InTimeMax.val();
	var v_name = O_Name.val().replace(/ /g, '').replace(/'/g, '');
	var v_mobile = O_Mobile.val().replace(/ /g, '').replace(/'/g, '');
	var v_certType = O_CertType.val();
	var v_email = O_Email.val().replace(/ /g, '').replace(/'/g, '');
	var v_remark = O_Remark.val().replace(/ /g, '').replace(/'/g, '');
	var v_totalPrice = O_TotalPrice.html();
	var v_returnMoney = O_ReturnMoney.html();
	var v_handleContent = $("#O_HandleContent").val();
	var v_status = $("[name='O_Status']:checked").val();

	if(v_RoomId == "") {
		alert("请选择房间类型！");
		O_RoomId.focus();
		return false;
	} else if(v_indate == "") {
		alert("请选择入住日期！");
		O_InDate.focus();
		return false;
	} else if(v_outdate == "") {
		alert("请选择离店日期！");
		O_OutDate.focus();
		return false;
	} else if(v_bookType != "无帐号客户" && v_memberId == "") {
	    alert("请选择会员帐号！");
		O_Member.focus();
		return false;
	} else if(v_name == "") {
		alert("入住人姓名不能为空！");
		O_Name.focus();
		return false;
	} else if(v_mobile == "") {
		alert("手机号码不能为空！");
		O_Mobile.focus();
		return false;
	} else if(v_mobile != "" && !/^(13|15|18)\d{9}$/.test(v_mobile)) {
		alert("请输入正确的手机号码！");
		O_Mobile.focus();
		return false;
	} else if(v_email != "" && !/.+@.+\.[a-zA-Z]{2,4}$/.test(v_email)) {
		alert("Email有误！");
		O_Email.focus();
		return false;
	} else {
		var O_Submit = $("#O_SumbitUpdate");
		O_Submit.attr("disabled", true);
		$.post("?m=admin/order.addHandle", { roomId:v_RoomId, indate:v_indate, outdate:v_outdate, memberAccount:v_memberAccount, roomNum:v_roomNum, personNum:v_personNum, inTimeMin:v_inTimeMin, inTimeMax:v_inTimeMax, name:v_name, phone:v_mobile, certType:v_certType, email:v_email, remark:v_remark, handleContent:v_handleContent, status:v_status }, function(data) {//alert(data);
			if(data[0] == "success") {
				//刷新列表
				var page = $("#O_CurrentPage").val();
				loadList(page);
				//刷新统计
				getCount();
				//隐藏阴影
				closeUpdate();
			} else {
				alert(data[1]);
				if(data[2] == "roomId is null") {
					O_Room.focus();
				} else if(data[2] == "indate is null") {
					O_InDate.focus();
				} else if(data[2] == "outdate is null") {
					O_OutDate.focus();
				} else if(data[2] == "name is null") {
					O_Name.focus();
				} else if(data[2] == "phone is null") {
					O_Mobile.focus();
				}
			}
			O_Submit.attr("disabled", false);
		}, "json");
	}
}
function update() {
	var page = $("#O_CurrentPage").val();
	var O_Content = $("#contentUpdate");
	var O_Id = O_Content.find("#O_OrderId");
	var O_Room = O_Content.find("#O_Room");
	var O_InDate = O_Content.find("#O_InDate");
	var O_OutDate = O_Content.find("#O_OutDate");
	var O_BookType = O_Content.find("input[name='O_BookType']:checked");
	var O_Member = O_Content.find("#O_Member option:selected");
	var O_RoomNum = O_Content.find("#O_RoomNum");
	var O_PersonNum = O_Content.find("#O_PersonNum");
	var O_InTimeMin = O_Content.find("#O_InTimeMin");
	var O_InTimeMax = O_Content.find("#O_InTimeMax");
	var O_Name = O_Content.find("#O_Name");
	var O_Mobile = O_Content.find("#O_Mobile");
	var O_CertType = O_Content.find("#O_CertType");
	var O_Email = O_Content.find("#O_Email");
	var O_Remark = O_Content.find("#O_Remark");
	var O_TotalPrice = O_Content.find("#O_TotalPrice");
	var O_ReturnMoney = O_Content.find("#O_ReturnMoney");
	
	var v_id = O_Id.val();
	var v_RoomId = O_Room.val();
	var v_indate = O_InDate.val();
	var v_outdate = O_OutDate.val();
	var v_bookType = O_BookType.val();
	var v_memberId = O_Member.val();
	var v_memberAccount = O_Member.text();
	var v_roomNum = O_RoomNum.val();
	var v_personNum = O_PersonNum.val();
	var v_inTimeMin = O_InTimeMin.val();
	var v_inTimeMax = O_InTimeMax.val();
	var v_name = O_Name.val().replace(/ /g, '').replace(/'/g, '');
	var v_mobile = O_Mobile.val().replace(/ /g, '').replace(/'/g, '');
	var v_certType = O_CertType.val();
	var v_email = O_Email.val().replace(/ /g, '').replace(/'/g, '');
	var v_remark = O_Remark.val().replace(/ /g, '').replace(/'/g, '');
	var v_totalPrice = O_TotalPrice.html();
	var v_returnMoney = O_ReturnMoney.html();

	if(v_RoomId == "") {
		alert("请选择房间类型！");
		O_RoomId.focus();
		return false;
	} else if(v_indate == "") {
		alert("请选择入住日期！");
		O_InDate.focus();
		return false;
	} else if(v_outdate == "") {
		alert("请选择离店日期！");
		O_OutDate.focus();
		return false;
	} else if(v_bookType != "无帐号客户" && v_memberId == "") {
	    alert("请选择会员帐号！");
		O_Member.focus();
		return false;
	} else if(v_name == "") {
		alert("入住人姓名不能为空！");
		O_Name.focus();
		return false;
	} else if(v_mobile == "") {
		alert("手机号码不能为空！");
		O_Mobile.focus();
		return false;
	} else if(v_mobile != "" && !/^(13|15|18)\d{9}$/.test(v_mobile)) {
		alert("请输入正确的手机号码！");
		O_Mobile.focus();
		return false;
	} else if(v_email != "" && !/.+@.+\.[a-zA-Z]{2,4}$/.test(v_email)) {
		alert("Email有误！");
		O_Email.focus();
		return false;
	} else {
		var O_Submit = $("#O_SumbitUpdate");
		O_Submit.attr("disabled", true);
		$.post("?m=admin/order.updateHandle", { id:v_id, roomId:v_RoomId, indate:v_indate, outdate:v_outdate, memberAccount:v_memberAccount, roomNum:v_roomNum, personNum:v_personNum, inTimeMin:v_inTimeMin, inTimeMax:v_inTimeMax, name:v_name, phone:v_mobile, certType:v_certType, email:v_email, remark:v_remark, price:v_totalPrice ,takeMoney:v_returnMoney }, function(data) {//alert(data);
			if(data[0] == "success") {
				alert(data[1]);
				//刷新列表
				var page = $("#O_CurrentPage").val();
				loadList(page, v_id);
				//刷新统计
				getCount();
				//隐藏阴影
				closeUpdate();
			} else {
				alert(data[1]);
				if(data[2] == "roomId is null") {
					O_Room.focus();
				} else if(data[2] == "indate is null") {
					O_InDate.focus();
				} else if(data[2] == "outdate is null") {
					O_OutDate.focus();
				} else if(data[2] == "name is null") {
					O_Name.focus();
				} else if(data[2] == "phone is null") {
					O_Mobile.focus();
				}
			}
			O_Submit.attr("disabled", false);
		}, "json");
	}
}
function updateStatus() {
	var page = $("#O_CurrentPage").val();
	var O_Submit = $("#O_SumbitUpdate");
	O_Submit.attr("disabled", true);
	var id = $("#O_ID").val();
	var handleContent = $("#O_HandleContent").val();
	var status = $("[name='O_Status']:checked").val();
	$.post("?m=admin/order.visaupdateStatusHandle", { id:id, handleContent:handleContent, status:status }, function(data) {//alert(data);
		if(data[0] == "success") {
			//刷新列表
			var page = $("#O_CurrentPage").val();
			loadList(page, id);
			//刷新统计
			getCount();
			//隐藏阴影
			closeUpdate();
		} else {
			alert(data[1]);
		}
		O_Submit.attr("disabled", false);
	}, "json");
}
//点击预订类型
function changeBookType(obj) {
	changeBookTypeDo(obj.value);
}
//点击预订类型执行
function changeBookTypeDo(type) {
	var O_MemberRow = $("#O_MemberRow");
	var O_MemberRowTitle = $("#O_MemberRowTitle");
	var O_Member = $("#O_Member");
	var O_Name = $("#O_Name");
	var O_Mobile = $("#O_Mobile");
	var O_Email = $("#O_Email");
	var O_Flush = $("#O_Flush");
	if(type == "无帐号客户") {
		O_Member.get(0).options.length = 0;
		O_Name.val("");
		O_Mobile.val("");
		O_Email.val("");
		O_MemberRow.hide();
		loadPrice();//加载酒店价格
	} else if(type == "普通会员") {
		O_Member.get(0).options.length = 0;
		O_Member.append("<option value=\"\">==普通会员==</option>");
		$.post("?m=admin/member.getListByStatus", { pageSize:0, status:"已激活", json:true }, function(data) {//alert(data);
			$.each(data, function(id, item) {
				O_Member.append("<option value=\"" + item.id + "\">" + item.account + "</option>");
			});
		}, "json");
		O_MemberRowTitle.html("普通会员：");
		O_MemberRow.show();
		loadPrice();
	} else if(type == "分销会员") {
		O_Member.get(0).options.length = 0;
		O_Member.append("<option value=\"\">==分销会员==</option>");
		$.post("?m=admin/distribution.getListByStatus", { pageSize:0, status:"已激活", json:true }, function(data) {//alert(data);
			$.each(data, function(id, item) {
				O_Member.append("<option value=\"" + item.id + "\">" + item.account + "</option>");
			});
		}, "json");
		O_MemberRowTitle.html("分销会员：");
		O_MemberRow.show();
		loadPrice();
	}
}
//点击酒店
function changeHotel() {
	var O_Content = $("#contentUpdate");
	var O_Hotel = O_Content.find("#O_Hotel");
	var O_Room = O_Content.find("#O_Room");
	var v_hotelId = O_Hotel.val();
	if(v_hotelId == "") { v_hotelId = "0"; }
	$.post("?m=admin/room.getListByHotel", { hotelId:v_hotelId, status:"已审核", pageSize:0, json:true }, function(data) {
		O_Room.get(0).options.length = 0;
		O_Room.append("<option value=\"\">==房型==</option>");
		$.each(data, function(id, item) {
			O_Room.append("<option value=\"" + item.id + "\">" + item.name + "</option>");
		});
		//加载酒店价格
		loadPrice();
	}, "json");
}
//点击房间类型
function changeRoom() {
	loadPrice();//加载酒店价格
}
//更改预订数
function changeRoomNum() {
	loadPrice();//加载酒店价格
}
//设置会员框
function setMember() {
	var O_Content = $("#contentUpdate");
	var O_Name = O_Content.find("#O_Name");
	var O_Mobile = O_Content.find("#O_Mobile");
	var O_Email = O_Content.find("#O_Email");
	O_Content.find("#O_Member").change(function() {
		var obj = $(this);
		var v_value = obj.val();
		if(v_value == "") {
			O_Name.val("");
			O_Mobile.val("");
			O_Email.val("");
		} else {
			var account = obj.find("option:selected").text();
			$.post("?m=admin/member.getInfoByAccount", { account:account }, function(data) {
				if(data != null) {
					O_Name.val(data.name);
					O_Mobile.val(data.mobile);
					O_Email.val(data.email);
				} else {
					O_Name.val("");
					O_Mobile.val("");
					O_Email.val("");
				}
			}, "json");
		}
		loadPrice();//加载酒店价格
	});
}
//加载酒店价格
function loadPrice() {
	var O_DivUpdate = $("#divUpdate");
	var O_Content = $("#contentUpdate");
	var O_Room = O_Content.find("#O_Room");
	var O_PriceList = O_Content.find("#O_PriceList");
	var O_PriceListContent = O_Content.find("#O_PriceListContent");
	var v_RoomId = O_Room.val();
	if(v_RoomId == "") {
		if(O_PriceList.css("display") != "none") {
			O_DivUpdate.height(O_DivUpdate.height() - O_PriceList.height());//更新层高
		}
		O_PriceList.hide();
	} else {
		var O_InDate = O_Content.find("#O_InDate");
		var O_OutDate = O_Content.find("#O_OutDate");
		var O_BookType = O_Content.find("input[name='O_BookType']:checked");
		var O_RoomNum = O_Content.find("#O_RoomNum");
		var O_Member = O_Content.find("#O_Member option:selected");
		var v_indate = O_InDate.val();
		var v_outdate = O_OutDate.val();
		var v_bookType = O_BookType.val();
		var v_roomNum = O_RoomNum.val();
		var v_memberAccount = O_Member.text();
		$.post("?m=admin/order.getPriceByRoom",{ roomId:v_RoomId, indate:v_indate, outdate:v_outdate, bookType:v_bookType, memberAccount:v_memberAccount, roomNum:v_roomNum },function(data) {//alert(data);
			var str = "";
			$.each(data.pricelist, function(id, item) {
				var date = item.date.split("-");
				str += "<div class=\"itemDay\"><div class=\"day\">" + date[1] + "月" + date[2] + "日</div><div class=\"weekJ\">(" + item.dateofweek + ")</div><div class=\"priceJ\">" + item.price + "元</div><div class=\"return\">(返现" + item.returnMoney + "元)</div></div>";
			});
			if(str.length > 0) {
				str = "<div class=\"dayprice\">" + str + "</div>";
			}
			str += "<div style=\"clear:both;\">总天数：" + data.totalDay + " 总间夜：" + data.totalNight + " 总房价：<span id=\"O_TotalPrice\">" + data.sumPrice + "</span>元 返点现金：<span id=\"O_ReturnMoney\">" + data.sumReturnMoney + "</span>元</div>";
			var height = O_DivUpdate.height() - (O_PriceList.css("display") != "none" ? O_PriceList.height() : 0);
			O_PriceListContent.html(str);
			O_PriceList.show();
			height += O_PriceList.height();
			O_DivUpdate.height(height);//更新层高
		}, "json");
	}
}
//检验离店日期
function checkTm2() {
	var tm1 = document.getElementById("O_InDate");
	var tm1Value = document.getElementById("tm1Value");
	var tm2 = document.getElementById("O_OutDate");
	var tm2Value = document.getElementById("tm2Value");
	if(tm1 != null && tm1Value != null && tm2 != null && tm2Value != null) {
		var v_tm1 = tm1.value;
		var v_tm1Value = tm1Value.value;
		var v_tm2 = tm2.value;
		var v_tm2Value = tm2Value.value;
		if(v_tm1.length > 0 && v_tm2.length == 0) {
			WdatePicker({mindate:'%y-%M-#{%d}',el:'O_OutDate'});
			tm2.focus();
		} else if(v_tm1.length > 0 && v_tm2.length > 0) {
			//比较日期
			var d1 = new Date(v_tm1.replace(/-/g, "/"));
			var d2 = new Date(v_tm2.replace(/-/g, "/"));
			//如果入住日期大于离店日期
			if(Date.parse(d1) - Date.parse(d2) >= 0) {
				if(v_tm1 != v_tm1Value || v_tm2 != v_tm2Value) {
					if(Date.parse(d1) - Date.parse(d2) > 0) {
						alert("入住日期" + v_tm1 + "晚于离店日期" + v_tm2);
						tm1.focus();
						WdatePicker({mindate:'%y-%M-#{%d}', el:'O_InDate'});
					}
					if(Date.parse(d1) - Date.parse(d2) == 0) {
						alert("离店日期至少要比入住日期晚1天");
						tm2.focus();
						WdatePicker({mindate:'%y-%M-#{%d}', el:'O_OutDate'});
					}
					if(v_tm1 != v_tm1Value) { tm1.focus(); }
					if(v_tm2 != v_tm2Value) { tm2.focus(); }
					tm1Value.value = v_tm1;
					tm2Value.value = v_tm2;
				}
			} else {
				if(v_tm1 != v_tm1Value || v_tm2 != v_tm2Value) {
					tm1Value.value = v_tm1;
					tm2Value.value = v_tm2;
				}
			}
		}
	}
	loadPrice();//加载酒店价格
}