$(function () {
	var basePath = $($("body")[0]).attr("base");
	var O_Area=$("#O_Area");//所在区域
	var O_ShopArea=$("#O_ShopArea");//商业区
	var O_HotelName=$("#O_HotelName");//酒店名称
	var O_Indate=$("#O_Indate");//入住日期
	var O_Outdate=$("#O_Outdate");//离店日期
	var O_PriceMin=$("#O_PriceMin");//价格1
	var O_PriceMax=$("#O_PriceMax");//价格2
	var O_HotelLevel=$("#O_HotelLevel");//酒店星级
	var O_Landmark=$("#O_Landmark");//酒店靠近
	var O_Service=$(".Service");//设施服务
	var O_SearchHotel=$("#O_SearchHotel");//搜索
	//选择所在区域
//	O_Area.change(function(){
//		//加载商业区
//		$.post("/Common/GetShopAreaData.aspx",{ areaId:O_Area.val() },function(data) {
//			O_ShopArea.find('option').remove().end().append('<option value="0">--请选择--</option>');
//			var ary = eval(data);
//			for(var i=0;i<ary.length;i++) {
//				O_ShopArea.append('<option value="' + ary[i][0] + '">' + ary[i][1] + '</option>');
//			}
//			O_ShopArea.val('0');
//		});
//	});
	//入住日期
	O_Indate.click(function(){
		//alert("tm1");
		WdatePicker({minDate:'%y-%M-#{%d}',el:'O_Indate'})
	});
	//离厂日期
	O_Outdate.click(function(){
		WdatePicker({minDate:'%y-%M-#{%d}',el:'O_Outdate'})
	});
	//搜索按钮
	O_SearchHotel.click(function(){
		var v_province="",v_provinceId="0",v_city="",v_cityId="0",v_areaId="0",v_shopAreaId="0",v_levelId="0";
		var v_area=O_Area.find('option:selected').text();
		v_area = v_area == '--请选择--' ? "" : v_area;
		var v_shopArea=O_ShopArea.find('option:selected').text();
		v_shopArea = v_shopArea == '--请选择--' ? "" : v_shopArea;
		var v_indate=O_Indate.val();
		var v_outdate=O_Outdate.val();
		var v_priceMin=O_PriceMin.val();
		var v_priceMax=O_PriceMax.val();
		var v_hotelName=O_HotelName.val();
		var v_landmark=O_Landmark.val();
		var v_level=O_HotelLevel.find('option:selected').text();
		v_level = v_level == '--请选择--' ? "" : v_level;
		//var v_service=O_Service.attr("value");
		var v_service=new Array();
		O_Service.each(function(){
			if(this.checked) { v_service+=$(this).val() + ","; }
		});
		if(v_service.length > 0) { v_service=v_service.substring(0,v_service.length-1); }
	
		//判断入住日期
		if(v_indate.length==0){ alert("请选择入住日期!");O_Indate.focus();WdatePicker({minDate:'%y-%M-#{%d}',el:'O_Indate'});return; }
		//判断离店日期
		if(v_outdate.length==0){ alert("请选择离店日期!");O_Outdate.focus();WdatePicker({minDate:'%y-%M-#{%d}',el:'O_Outdate'});return; }
		//比较日期
		var d1 = new Date(v_indate.replace(/-/g,"/"));
		var d2 = new Date(v_outdate.replace(/-/g,"/"));
		if(Date.parse(d1) - Date.parse(d2)>0) {
			alert("入住日期"+v_indate+"晚于离店日期"+v_outdate);O_Outdate.focus();WdatePicker({minDate:'%y-%M-#{%d}',el:'O_Outdate'});return;
		}
		$.post(basePath + "?m=hotel.setSearchSession", { provinceName:v_province,provinceId:v_provinceId,cityName:v_city,cityId:v_cityId,areaName:v_area,areaId:v_areaId,shopareaName:v_shopArea,shopareaId:v_shopAreaId,levelName:v_level,levelId:v_levelId,hotelName:v_hotelName,priceMin:v_priceMin,priceMax:v_priceMax,indate:v_indate,outdate:v_outdate,landmarkName:v_landmark,service:v_service }, function(data) {//alert(data);
			if(data[0] == "success") {
				window.location.href = basePath + "hotel/list-search.html";
			}
		}, "json");
	});
}); 
