//页面DOM加载后执行函数
$j(function(){ 
	$j("#hotel_order_inquiry_submited").hide();
	$j('#hotel_order_inquiry_form').show();
	//初始化酒店订单查询
	init_hotel_order_inquiry_form();
});

function init_hotel_order_inquiry_form()
{
	//Ajax提交酒店订单查询
	if ($j('#hotel_order_inquiry_form').length) {
		$j('#hotel_order_inquiry_form').submit(function(){
			jQuery.ajax({
				url: urlPrefix + "ajax.aspx", // 这里要改为 comments-ajax.php 文件的位置
				data: encodeURI($j('#hotel_order_inquiry_form').serialize()), // 从表单中获取数据
				type: 'POST', // 设置请求类型为 ‘POST’，默认为 ‘GET’
				dataType:'json',
				beforeSend: function() {
					
					if($j("#hostTel").attr("value").trim()=="" || $j("#hotelOrderSN").attr("value").trim()=="")
					{
						alert("请输入订单号和订单联系人电话号码！");
						return false;
					}
					$j('#hotel_order_inquiry_form').hide();
					$j('#hotel_order_inquiry_submited').show();
					$j('#hotel_order_inquiry_loading').show();
					$j('#hotel_order_inquiry_error').hide();
					$j('#hotel_order_inquiry_success').hide();
					
				},
				error: function(request) {
					$j('#hotel_order_inquiry_loading').hide();
					$j('#hotel_order_inquiry_error').show().html("查询失败["+request.responseText+"]，请重试！<input type=button value=\"重新查询\" onclick=\"hotel_order_inquiry_redo()\">");
				},
				success: function(json) {
					$j('#hotel_order_inquiry_loading').hide();
					if(json.flag==1)
					{						
						
						$j("#hotel_order_sn").html(json.o_sn);
						$j("#sn").attr("value",json.o_sn);
						
						
						$j("#hotel_order_state").html(json.o_state);
						
						if(json.o_state!="待处理")
						{
							$j("#btnDeleteHotelOrder").attr("disabled", true); 
							$j("#btnUpdateHotelOrder").attr("disabled", true); 
						}
						else
						{
							$j("#btnDeleteHotelOrder").removeAttr("disabled"); 
							$j("#btnUpdateHotelOrder").removeAttr("disabled"); 
						}
						//预订酒店房间信息
						
						$j("#hotelName").html("<a href=./HotelShow.aspx?h_id="+json.o_hid+" target=_blank>"+json.o_hotelName+"</a>");
						$j("#roomType").html(json.o_roomType);
						$j("#hotel_order_inDate").html(json.o_indate);
						$j("#hotel_order_outDate").html(json.o_outdate);
						$j("#hotel_order_roomNum").html(json.o_roomNum + " 间");
						$j("#hotel_order_menNum").html(json.o_menNum + " 人");
						$j("#hotel_order_totalPrice").html("￥"+json.o_totalPrice);
						$j("#hotel_order_time").html(json.o_bookTime);
						
						
						
						//联系人信息
						$j("#hostName")[0].value = json.o_name;
						
						$j("#sex_0").attr("checked",json.o_sex==0);
						$j("#sex_1").attr("checked",json.o_sex==1);
						
						
						$j("<option value=\""+json.o_idType+"\">"+json.o_idType+"</option>").appendTo("#idType");
						$j("#idType").attr("value",json.o_idType);
						
						$j("#idNum").attr("value",json.o_idNum);
						$j("#tel").attr("value",json.o_tel);
						$j("#fax").attr("value",json.o_fax);
						$j("#email").attr("value",json.o_email);
						
						$j("<option value=\""+json.o_confirmWay+"\">"+json.o_confirmWay+"</option>").appendTo("#confirmWay");
						$j("#confirmWay").attr("value",json.o_confirmWay);
						
						$j("#otherInfo").attr("value",json.o_other);
						
						
						$j('#hotel_order_inquiry_success').show();
						$j('#hotel_order_inquiry_error').hide().html();
						
					}
					else
					{
						$j('#hotel_order_inquiry_success').hide();
						$j('#hotel_order_inquiry_error').show().html(json.errMsg + "<br/><input type=button value=\"重新查询\" onclick=\"hotel_order_inquiry_redo()\">");
					}
					
					
				}
			});
			return false;
		});
	}
}
//更新订单信息
function hotel_order_update()
{	
	jQuery.ajax({
		url: urlPrefix + "ajax.aspx", // 这里要改为 comments-ajax.php 文件的位置
		data: encodeURI($j('#hotel_book_form').serialize()), // 从表单中获取数据
		type: 'POST', // 设置请求类型为 ‘POST’，默认为 ‘GET’
		dataType:'json',
		beforeSend: function() {
			$j('#hotel_order_inquiry_form').hide();
			$j('#hotel_order_inquiry_submited').show();
			$j('#hotel_order_inquiry_loading').show();
			$j('#hotel_order_inquiry_error').hide();
			$j('#hotel_order_inquiry_success').hide();
		},
		error: function(request) {
			$j('#hotel_order_inquiry_loading').hide();
			$j('#hotel_order_inquiry_error').show().html("操作失败["+request.responseText+"]，请重试！<input type=button value=\"重试\" onclick=\"hotel_order_update_redo()\">");
		},
		success: function(json) {
			$j('#hotel_order_inquiry_loading').hide();
			if(json.flag==1)
			{
				alert("操作提示：订单信息更新成功！");
				hotel_order_update_redo();
			}
			else
			{
				alert("操作提示：订单信息失败！！！");
				$j('#hotel_book_success').hide();
				$j('#hotel_book_error').show().html(json.errMsg + "<br/><input type=button value=\"重试\" onclick=\"hotel_order_inquiry_redo()\">");
				hotel_order_update_redo();
			}
		}
	});
	return false;

}
//重新更新
function hotel_order_update_redo()
{
	$j("#hotel_order_inquiry_submited").show();
	$j('#hotel_order_inquiry_form').hide();
	$j('#hotel_order_inquiry_loading').hide();
	$j('#hotel_order_inquiry_success').show();
	$j('#hotel_order_inquiry_error').hide().html();
}
function hotel_order_delete()
{
	var sn = $j("#sn").attr("value");
	alert(sn);
	jQuery.ajax({
		url: urlPrefix + "ajax.aspx", // 这里要改为 comments-ajax.php 文件的位置
		data: "sn="+sn + "&act=hotel_order_delete",
		type: 'POST', // 设置请求类型为 ‘POST’，默认为 ‘GET’
		dataType:'json',
		beforeSend: function() {
			$j('#hotel_order_inquiry_form').hide();
			$j('#hotel_order_inquiry_submited').show();
			$j('#hotel_order_inquiry_loading').show();
			$j('#hotel_order_inquiry_error').hide();
			$j('#hotel_order_inquiry_success').hide();
		},
		error: function(request) {
			$j('#hotel_order_inquiry_loading').hide();
			$j('#hotel_order_inquiry_error').show().html("操作失败["+request.responseText+"]，请重试！<input type=button value=\"重试\" onclick=\"hotel_order_update_redo()\">");
		},
		success: function(json) {
			$j('#hotel_order_inquiry_loading').hide();
			if(json.flag==1)
			{
				alert("操作提示：订单已成功取消！");
				$j("#hotel_order_inquiry_submited").hide();
				$j('#hotel_order_inquiry_form').show();
			}
			else
			{
				alert("操作提示：订单取消失败，请重试！！！");
				$j('#hotel_book_success').hide();
				$j('#hotel_book_error').show().html(json.errMsg);
				hotel_order_update_redo();
			}
		}
	});
	return false;
}
//重新查询
function hotel_order_inquiry_redo()
{
	$j("#hotel_order_inquiry_submited").hide();
	$j('#hotel_order_inquiry_form').show();
}
