$(function () {
	var O_HotelID = $("#O_HotelID");
	var O_HotelRoomID = $("#O_HotelRoomID");
	var O_OrderID = $("#O_OrderID");
	var O_OrderNo = $("#O_OrderNo");
	var O_OrderIndate = $("#O_OrderIndate");
	var O_OrderOutdate = $("#O_OrderOutdate");
	var O_HotelRoomNo = $("#O_HotelRoomNo");
	var O_Content = $("#O_Content");
	var O_Submit = $("#O_Submit");//提交按钮
	
	//点击提交按钮
	O_Submit.click(function(){
		var basePath = $($("body")[0]).attr("base");
		var v_orderId = O_OrderID.val();
		var v_hotelId = O_HotelID.val();
		var v_hotelRoomId = O_HotelRoomID.val();
		var v_orderNo = O_OrderNo.val().replace(/ /g, '').replace(/'/g, '');
		var v_indate = O_OrderIndate.val();
		var v_outdate = O_OrderOutdate.val();
		var d1 = new Date(v_indate.replace(/-/g, "/"));
		var d2 = new Date(v_outdate.replace(/-/g, "/"));
		var v_roomno = O_HotelRoomNo.val().replace(/ /g, '').replace(/'/g, '');
		var v_content = O_Content.val().replace(/ /g, '').replace(/'/g, '');
		var v_score = $(":input[name='O_Score']:checked").val();
		//遍历得到每个checkbox的value值
		var arrChk = $(":input[name='O_HotelImpression']:checked");
		var v_imp = "";
		for(var i = 0; i < arrChk.length; i++) {
			v_imp += arrChk[i].value;
			if(i < arrChk.length - 1) {
				v_imp += ",";
			}
		}
		if(v_indate.length == 0) {
			alert("请选择入住日期！");
			O_OrderIndate.focus();
		} else if(v_indate != "" && !/^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/.test(v_indate)) {
			alert("入住日期格式有误！");
			O_OrderIndate.focus();
		} else if(v_outdate.length == 0) {
			alert("请选择离店日期！");
			O_OrderOutdate.focus();
		} else if(v_outdate != "" && !/^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/.test(v_outdate)) {
			alert("离店日期格式有误！");
			O_OrderOutdate.focus();
		} else if(Date.parse(d1) - Date.parse(d2) >= 0) {
			alert("入住日期" + v_indate + "晚于离店日期" + v_outdate);
			O_OrderOutdate.focus();
		} else if(v_roomno.length == 0) {
			alert("请填写房间号！");
			O_HotelRoomNo.focus();
		} else if(!(v_content.length > 9 && v_content.length < 400)) {
			alert("点评内容请保持[10-400]！");
			O_Content.focus();
		} else {
			O_Submit.attr("disabled", true);
			$.post(basePath + "?m=member.addCommentHandle",{ hotelId:v_hotelId, roomId:v_hotelRoomId, roomNo:v_roomno, orderCode:v_orderNo, score:v_score, indate:v_indate, outdate:v_outdate, remark:v_content, imp:v_imp },function(data) {//alert(data);
				alert(data[1]);
				if(data[0] == "success") {
					window.location.href = basePath + "member/photoadd-" + v_orderId + ".html";
				}
				O_Submit.attr("disabled", false);
			}, "json");
		}
	});
});