
var Calendar = function(){};
/**产品编号*/
//Calendar.prototype.id = $("#product_id").val();
Calendar.prototype.id = 0;
/**客户类型*/
Calendar.prototype.customerType = 0;
/**回调参数*/
Calendar.prototype.params = [];
/**清除节点工作*/
Calendar.prototype.removeNode = function(){
	$("#calendar_title_id").remove();
	$("#calendar_div_id").remove();	
};
/**获得今天的日期*/
Calendar.prototype.getTodayDate = function(){
	var date = new Date();
	var currentYear = date.getFullYear();
	var currentMonth = date.getMonth() + 1;
	var currentDay = date.getDate();
	if(currentMonth < 10){
		currentMonth = "0" + currentMonth;
	}
	if(currentDay < 10){
		currentDay = "0" + currentDay;
	}
	return currentYear + "-" + currentMonth + "-" + currentDay;
};


/**初始化页面时候的日历函数*/
Calendar.prototype.processor = function(){
	var data = Calendar.prototype.params;
	var result = "";
	if(data.length == 0){
//		result = "<div class='calendar_font'>此产品暂无拼团出行计划，请考虑是否包团出行。</div>";
//		result = Calendar.prototype.notice();
		$(".calendar").remove();
		$("#product_order").remove();
		$("#project_id").remove();
	}else{
			
		var year = data[0].year;
		var month = data[0].month;
		
		var previousMonth = month - 1;
		var previousYear = year;
		
		var nextMonth = month + 1;
		var nextYear = year;
	
		if(previousMonth < 1){
			previousMonth = 12 + previousMonth;
			previousYear = previousYear - 1;
		}	
		
		if(nextMonth > 12){
			nextMonth = nextMonth - 12;
			nextYear = nextYear + 1;
		}
		result += "<div class='calendar_title' id='calendar_title_id'>";
		result += "		<span>";
		result += "			<h5>点击日期,马上预订!</h5>";
//		result += "			<span style='color:#CCC;font-size:12px;'>(点击日历的价格预订)</span>";
		result += "		</span>";
		result += "";
		result += "</div>";
		result += "<div class='calendar_div' id='calendar_div_id'>";
		result += "		<div class='calendar_date'>";
		result +=  "		<div style='margin-top:31px;height:287px;width:80px;float:left;border-top:1px solid #CCC;'>";
		result +=  "			<a onmouseout=this.className='calender_btn' onmouseover=this.className='previous_next_mouseover' class='calender_btn' href='javascript:void(0);' onclick='btn_click("+previousYear+","+previousMonth+");'>▲</a>";
		result += "				<div style='height:245px;text-align:center;color:#666666;font-size:12px;width:79px;float:left;border-left:1px solid #CCC;'>";
		result += "					<div style='margin-top:105px;font-family:Simsun,sans-serif;font-size:12px'>"+year+"年<br/>"+month+"月</div>";
		result += "				</div>";
		result += "				<a onmouseout=this.className='calender_btn' onmouseover=this.className='previous_next_mouseover' class='calender_btn' style='border-bottom:1px solid #CCC;' href='javascript:void(0);' onclick='btn_click("+nextYear+","+nextMonth+");'>▼</a>";
		result += "			</div>";
		result += "		</div>";
		result += "		<div id='calendar_left'>";
		result += "			<table id='border' border='0' cellspacing='0' style='height:319px;'>";
		result += "				<tr>";
		result += "					<td class='label weekday'>星期一</td>";
		result += "					<td class='label weekday'>星期二</td>";
		result += "					<td class='label weekday'>星期三</td>";
		result += "					<td class='label weekday'>星期四</td>" ;
		result += "					<td class='label weekday'>星期五</td>";
		result += "					<td class='label weekday Saturday'>星期六</td>";
		result += "					<td class='label weekday Sunday'>星期日</td>";
		result += "				</tr>";
		result += 				Calendar.prototype.bulidContent(data);
		result += "			</table>";
		result += "		</div>";
		result += "</div>";
		
		
	}
//	alert(result);
	$(".calendar").append(result);
};

/**点击按钮时候的日历函数*/
Calendar.prototype.build = function(year,month){
	var data = Calendar.prototype.params;
	var result = "";
	var previousMonth = month - 1;
	var previousYear = year;
	
	var nextMonth = month + 1;
	var nextYear = year;

	if(previousMonth < 1){
		previousMonth = 12 + previousMonth;
		previousYear = previousYear - 1;
	}	
	if(nextMonth > 12){
		nextMonth = nextMonth - 12;
		nextYear = nextYear + 1;
	}
	result += "<div class='calendar_title' id='calendar_title_id'>";
	result += "		<span>";
//	result += "			<h5 style='display:inline'>出发日起价</h5>";
	result += "			<h5>点击日期,马上预订!</h5>";
//	result += "			<span style='color:#CCC;font-size:12px;'>(点击日历的价格预订)</span>";
	result += "		</span>";
	result += "";
	result += "</div>";
	result += "<div class='calendar_div' id='calendar_div_id'>";
	result += "		<div class='calendar_date'>";
	result +=  "		<div style='margin-top:31px;height:287px;width:80px;float:left;border-top:1px solid #CCC;'>";
	result +=  "			<a onmouseout=this.className='calender_btn' onmouseover=this.className='previous_next_mouseover' class='calender_btn' href='javascript:void(0);' onclick='btn_click("+previousYear+","+previousMonth+");'>▲</a>";
	result += "				<div style='height:245px;text-align:center;color:#666666;font-size:12px;width:79px;float:left;border-left:1px solid #CCC;'>";
	result += "					<div style='margin-top:105px;font-family:Simsun,sans-serif;font-size:12px'>"+year+"年<br/>"+month+"月</div>";
	result += "				</div>";
	result += "				<a onmouseout=this.className='calender_btn' onmouseover=this.className='previous_next_mouseover' class='calender_btn' style='border-bottom:1px solid #CCC;' href='javascript:void(0);' onclick='btn_click("+nextYear+","+nextMonth+");'>▼</a>";
	result += "			</div>";
	result += "		</div>";
	result += "		<div id='calendar_left'>";
	result += "			<table id='border' border='0' cellspacing='0' style='height:319px;'>";
	result += "				<tr>";
	result += "					<td class='label weekday'>星期一</td>";
	result += "					<td class='label weekday'>星期二</td>";
	result += "					<td class='label weekday'>星期三</td>";
	result += "					<td class='label weekday'>星期四</td>" ;
	result += "					<td class='label weekday'>星期五</td>";
	result += "					<td class='label weekday Saturday'>星期六</td>";
	result += "					<td class='label weekday Sunday'>星期日</td>";
	result += "				</tr>";
	result += 				Calendar.prototype.bulidContent(data);
	result += "			</table>";
	result += "		</div>";
	result += "</div>";
	
//	alert(result);
	$(".calendar").append(result);
	
};

/**生成符合条件的内容*/
Calendar.prototype.bulidContent = function(){
	var data = Calendar.prototype.params;
	var result = "";
	$.each(data,function(i){
		var calendarIndex = data[i].calendar_index;
		var calendarMonth = data[0].month;
		var calendarYear = data[0].year;
		if(calendarIndex < 10){
			calendarIndex = "0" + calendarIndex;
		}
		if(calendarMonth < 10){
			calendarMonth = "0" + calendarMonth;
		}
		var now = calendarYear + "-" + calendarMonth + "-" + calendarIndex;
		
		if(i % 7 == 0){
			result += "<tr>";
		}
		
		if(data[i].calendar_index == 0){
			result += "<td>";
			result += "	 <div class='none_project'>&nbsp;</div>";
			result += "	 <div>&nbsp;</div>";
			result += "	 <div>&nbsp;</div>";
			result += "</td>";
		} else {
			
			if (data[i].BE_Product_Reserve_ID == 0) {
				result += "<td>";
				result += "		<div class='count_enough' style='margin-right:8px;width:72px;'>&nbsp;</div>";
				result += "		<div style='width:80px;'>";
				result += "			<div style='width:22px;float:left;margin:0;border:0;text-align:center;font-size:16px;font-weight:bold;' class='none_project'>" + data[i].calendar_index + "</div>";
				result += "			<div style='width:58px;float:left;margin:0;border:0;text-align:right;font-size:11px;' class='product_price'>&nbsp;</div>";
				result += "		</div>";
				result += "		<div style='color:#F00;font-weight:bold;font-size:12px;'>&nbsp;</div>";
				result += "</td>";
			} else {
				var expectPrice = Calendar.prototype.splitPrice(data[i].expectPrice);
				var ListPrice = Calendar.prototype.splitPrice(data[i].priceList);
				var schedule = data[i].schedule;
				var scheduleShow = "";
				var togetherShow = "title = '同行价'";
				var straightShow = "title = '直客价'";
				var notice = data[i].purchaseNotice;
				if(!notice){
					notice = "";
				}
				if(Calendar.prototype.customerType != 'T'){
					expectPrice = "&nbsp;";
					togetherShow = "";
					straightShow = "";
				}
				if(schedule){
					scheduleShow = schedule;
					if(scheduleShow == '报名截止'){
						//scheduleShow = "<font color='red'>报名截止</font>";
					}
				}
				if(data[i].m_attributesetinstance_id == 0 && data[i].BE_Product_Reserve_ID != 0){
					scheduleShow = '报名中';
				}
				
				if(Calendar.prototype.today < now && (scheduleShow == '报名中' || scheduleShow == '特价中')){
//					result += "<td class='mouse_over_css' onmouseover=this.className='mouseover_j' onmouseout=this.className='mouseout_j' onclick='regist_click("+Calendar.prototype.id+","+data[i].BE_Product_Reserve_ID+ ","+data[i].qtyleft +","+data[i].m_attributesetinstance_id+",event)'>";
//					result += "<td class='mouse_over_css' onmouseover=this.className='mouseover_j' onclick='regist_click("+Calendar.prototype.id+","+data[i].BE_Product_Reserve_ID+ ","+data[i].qtyleft +","+data[i].m_attributesetinstance_id+",event)'>";
					result += "<td class='mouse_over_css' onmouseover=this.className='mouseover_j' onclick='orderLink("+data[i].BE_Product_Reserve_ID+")'>";
					result += "		<div style='width:80px;' class='count_enough'>" + scheduleShow + "</div>";
					result += "		<div style='width:80px;'>";
					result += "			<div style='width:22px;float:left;margin:0;border:0;text-align:center;font-size:16px;font-weight:bold;'>" + data[i].calendar_index + "</div>";
					result += "			<div style='width:58px;float:left;margin:0;border:0;text-align:right;font-size:12px;' class='product_price' "+togetherShow+">"+expectPrice+"</div>";
					result += "		</div>";
					result += "		<div style='color:#F00;font-size:12px;'"+straightShow+">"+ListPrice+"</div>";
					result += "		<input type='hidden' id='"+data[i].BE_Product_Reserve_ID+"notice' value ='"+notice+"'/>";
					result += "		<input type='hidden' id='"+data[i].BE_Product_Reserve_ID+"schedule' value ='"+schedule+"'/>";					
					result += "</td>";
				}else
					if(Calendar.prototype.today < now && (scheduleShow != '报名中' && scheduleShow != '特价中')){
						result += "<td>";
						result += "		<div style='width:80px;' class='grey_color'>" + scheduleShow + "</div>";
						result += "		<div style='width:80px;'>";
						result += "			<div style='width:22px;float:left;margin:0;border:0;text-align:center;font-size:16px;font-weight:bold;' class='grey_color'>" + data[i].calendar_index + "</div>";
						result += "			<div style='width:58px;float:left;margin:0;border:0;text-align:right;font-size:12px;' class='grey_color' "+togetherShow+">"+expectPrice+"</div>";
						result += "		</div>";
						result += "		<div style='font-size:12px;' class='grey_color' "+straightShow+">"+ListPrice+"</div>";
						result += "		<input type='hidden' id='"+data[i].BE_Product_Reserve_ID+"notice' value ='"+notice+"'/>";
						result += "		<input type='hidden' id='"+data[i].BE_Product_Reserve_ID+"schedule' value ='"+schedule+"'/>";					
						result += "</td>";
					
				}else{
					result += "<td>";
					result += "		<div class='count_enough' style='width:80px;'>&nbsp;</div>";
					result += "		<div style='width:80px;'>";
					result += "			<div style='width:22px;float:left;margin:0;border:0;text-align:center;font-size:16px;font-weight:bold;' class='none_project'>" + data[i].calendar_index + "</div>";
					result += "			<div style='width:58px;float:left;margin:0;border:0;text-align:right;font-size:12px;' class='product_price'>&nbsp;</div>";
					result += "		</div>";
					result += "		<div style='color:#F00;font-weight:bold;font-size:12px;'>&nbsp;</div>";
					result += "</td>";
				}
			}
		}
	});
	return result;
};

/**生成符合条件的单项产品内容*/
Calendar.prototype.bulidSingleContent = function(){
	var data = Calendar.prototype.params;
	var result = "";
	$.each(data,function(i){
		
		var calendarIndex = data[i].index;
		var calendarMonth = data[0].month;
		var calendarYear = data[0].year;
		if(calendarIndex < 10){
			calendarIndex = "0" + calendarIndex;
		}
		if(calendarMonth < 10){
			calendarMonth = "0" + calendarMonth;
		}
		var now = calendarYear + "-" + calendarMonth + "-" + calendarIndex;
		if(i % 7 == 0){
			result += "<tr>";
		}
		
		if(data[i].index == 0){
			result += "<td>";
			result += "	 <div class='none_project'>&nbsp;</div>";
			result += "	 <div>&nbsp;</div>";
			result += "	 <div>&nbsp;</div>";
			result += "</td>";
		} else {
			
			if (data[i].productPriceListId == 0 || data[i].priceType == 'C' || data[i].priceType == 'D') {
				result += "<td>";
				result += "		<div class='count_enough' style='margin-right:8px;width:72px;'>&nbsp;</div>";
				result += "		<div style='width:80px;'>";
				result += "			<div style='width:20px;float:left;margin:0;border:0;text-align:center;font-size:16px;font-weight:bold;' class='none_project'>" + data[i].index + "</div>";
				result += "			<div style='width:60px;float:left;margin:0;border:0;text-align:right;font-size:11px;' class='product_price'>&nbsp;</div>";
				result += "		</div>";
				result += "		<div style='color:#F00;font-weight:bold;font-size:12px;'>&nbsp;</div>";
				result += "</td>";
			} else {
				var expectPrice = Calendar.prototype.splitPrice(data[i].standardPrice);
				var ListPrice = Calendar.prototype.splitPrice(data[i].listPrice);
				var schedule = "预订中";
				var scheduleShow = "预订中";
				var togetherShow = "title = '同行价'";
				var straightShow = "title = '直客价'";
				if(data[i].priceType == 'B'){
					expectPrice = "需询价";
					ListPrice = "需询价";
				}
				if(Calendar.prototype.customerType != 'T'){
					expectPrice = "&nbsp;";
					togetherShow = "";
					straightShow = "";
				}

				
				if(Calendar.prototype.today < now){
//					result += "<td class='mouse_over_css' onmouseover=this.className='mouseover_j' onmouseout=this.className='mouseout_j' onclick='regist_click("+Calendar.prototype.id+","+data[i].BE_Product_Reserve_ID+ ","+data[i].qtyleft +","+data[i].m_attributesetinstance_id+",event)'>";
					result += "<td class='mouse_over_css' onmouseover=this.className='mouseover_j' onclick='regist_click();'>";
					result += "		<div style='width:80px;' class='count_enough'>" + scheduleShow + "</div>";
					result += "		<div style='width:80px;'>";
					result += "			<div style='width:20px;float:left;margin:0;border:0;text-align:center;font-size:16px;font-weight:bold;'>" + data[i].index + "</div>";
					result += "			<div style='width:60px;float:left;margin:0;border:0;text-align:right;font-size:12px;' class='product_price' "+togetherShow+">"+expectPrice+"</div>";
					result += "		</div>";
					result += "		<div style='color:#F00;font-size:12px;'"+straightShow+">"+ListPrice+"</div>";
					result += "		<input type='hidden' id='"+data[i].productPriceListId+"notice' value =''/>";
					result += "		<input type='hidden' id='"+data[i].productPriceListId+"schedule' value ='"+schedule+"'/>";					
					result += "</td>";
				}else{
					result += "<td>";
					result += "		<div class='count_enough' style='width:80px;'>&nbsp;</div>";
					result += "		<div style='width:80px;'>";
					result += "			<div style='width:20px;float:left;margin:0;border:0;text-align:center;font-size:16px;font-weight:bold;' class='none_project'>" + data[i].index + "</div>";
					result += "			<div style='width:60px;float:left;margin:0;border:0;text-align:right;font-size:12px;' class='product_price'>&nbsp;</div>";
					result += "		</div>";
					result += "		<div style='color:#F00;font-weight:bold;font-size:12px;'>&nbsp;</div>";
					result += "</td>";
				}
			}
		}
	});
	
	return result;
};


/**初始化页面时候的单项产品日历函数*/
Calendar.prototype.Singleprocessor = function(){
	var data = Calendar.prototype.params;
	var result = "";
	if(data.length == 0){
//		result = "<div class='calendar_font'>此产品暂无拼团出行计划，请考虑是否包团出行。</div>";
//		result = Calendar.prototype.notice();
		$(".calendar").remove();
		$("#product_order").remove();
	}else if(data[0].priceType != 'null'){
//		result = "<div class='calendar_font'>很抱歉,此产品目前无法接受预订,请选择其它产品,谢谢!</div>";
		$(".calendar").remove();
		$("#product_order").remove();
	}else{
			
		var year = data[0].year;
		var month = data[0].month;
		
		var previousMonth = month - 1;
		var previousYear = year;
		
		var nextMonth = month + 1;
		var nextYear = year;
	
		if(previousMonth < 1){
			previousMonth = 12 + previousMonth;
			previousYear = previousYear - 1;
		}	
		
		if(nextMonth > 12){
			nextMonth = nextMonth - 12;
			nextYear = nextYear + 1;
		}
		result += "<div class='calendar_title' id='calendar_title_id'>";
		result += "		<span>";
		result += "			<h5>点击日期,马上预订!</h5>";
//		result += "			<span style='color:#CCC;font-size:12px;'>(点击日历的价格预订)</span>";
		result += "		</span>";
		result += "";
		result += "</div>";
		result += "<div class='calendar_div' id='calendar_div_id'>";
		result += "		<div class='calendar_date'>";
		result +=  "		<div style='margin-top:31px;height:287px;width:80px;float:left;border-top:1px solid #CCC;'>";
		result +=  "			<a onmouseout=this.className='calender_btn' onmouseover=this.className='previous_next_mouseover' class='calender_btn' href='javascript:void(0);' onclick='btn_click("+previousYear+","+previousMonth+");'>▲</a>";
		result += "				<div style='height:245px;text-align:center;color:#666666;font-size:12px;width:79px;float:left;border-left:1px solid #CCC;'>";
		result += "					<div style='margin-top:105px;font-family:Simsun,sans-serif;font-size:12px'>"+year+"年<br/>"+month+"月</div>";
		result += "				</div>";
		result += "				<a onmouseout=this.className='calender_btn' onmouseover=this.className='previous_next_mouseover' class='calender_btn' style='border-bottom:1px solid #CCC;' href='javascript:void(0);' onclick='btn_click("+nextYear+","+nextMonth+");'>▼</a>";
		result += "			</div>";
		result += "		</div>";
		result += "		<div id='calendar_left'>";
		result += "			<table id='border' border='0' cellspacing='0' style='height:319px;'>";
		result += "				<tr>";
		result += "					<td class='label weekday'>星期一</td>";
		result += "					<td class='label weekday'>星期二</td>";
		result += "					<td class='label weekday'>星期三</td>";
		result += "					<td class='label weekday'>星期四</td>" ;
		result += "					<td class='label weekday'>星期五</td>";
		result += "					<td class='label weekday Saturday'>星期六</td>";
		result += "					<td class='label weekday Sunday'>星期日</td>";
		result += "				</tr>";
		result += 				Calendar.prototype.bulidSingleContent(data);
		result += "			</table>";
		result += "		</div>";
		result += "</div>";
		
		
	}
//	alert(result);
	$(".calendar").append(result);
};

/**点击按钮时候的单项产品日历函数*/
Calendar.prototype.Singlebuild = function(year,month){
	var data = Calendar.prototype.params;
	var result = "";
	var previousMonth = month - 1;
	var previousYear = year;
	
	var nextMonth = month + 1;
	var nextYear = year;

	if(previousMonth < 1){
		previousMonth = 12 + previousMonth;
		previousYear = previousYear - 1;
	}	
	if(nextMonth > 12){
		nextMonth = nextMonth - 12;
		nextYear = nextYear + 1;
	}
	result += "<div class='calendar_title' id='calendar_title_id'>";
	result += "		<span>";
//	result += "			<h5 style='display:inline'>出发日起价</h5>";
	result += "			<h5>点击日期,马上预订!</h5>";
//	result += "			<span style='color:#CCC;font-size:12px;'>(点击日历的价格预订)</span>";
	result += "		</span>";
	result += "";
	result += "</div>";
	result += "<div class='calendar_div' id='calendar_div_id'>";
	result += "		<div class='calendar_date'>";
	result +=  "		<div style='margin-top:31px;height:287px;width:80px;float:left;border-top:1px solid #CCC;'>";
	result +=  "			<a onmouseout=this.className='calender_btn' onmouseover=this.className='previous_next_mouseover' class='calender_btn' href='javascript:void(0);' onclick='btn_click("+previousYear+","+previousMonth+");'>▲</a>";
	result += "				<div style='height:245px;text-align:center;color:#666666;font-size:12px;width:79px;float:left;border-left:1px solid #CCC;'>";
	result += "					<div style='margin-top:105px;font-family:Simsun,sans-serif;font-size:12px'>"+year+"年<br/>"+month+"月</div>";
	result += "				</div>";
	result += "				<a onmouseout=this.className='calender_btn' onmouseover=this.className='previous_next_mouseover' class='calender_btn' style='border-bottom:1px solid #CCC;' href='javascript:void(0);' onclick='btn_click("+nextYear+","+nextMonth+");'>▼</a>";
	result += "			</div>";
	result += "		</div>";
	result += "		<div id='calendar_left'>";
	result += "			<table id='border' border='0' cellspacing='0' style='height:319px;'>";
	result += "				<tr>";
	result += "					<td class='label weekday'>星期一</td>";
	result += "					<td class='label weekday'>星期二</td>";
	result += "					<td class='label weekday'>星期三</td>";
	result += "					<td class='label weekday'>星期四</td>" ;
	result += "					<td class='label weekday'>星期五</td>";
	result += "					<td class='label weekday Saturday'>星期六</td>";
	result += "					<td class='label weekday Sunday'>星期日</td>";
	result += "				</tr>";
	result += 				Calendar.prototype.bulidSingleContent();
	result += "			</table>";
	result += "		</div>";
	result += "</div>";
	
	$(".calendar").append(result);
	
};



/**拆分日期金额*/
Calendar.prototype.splitPrice = function(price){
	var result = "￥" + price;
//	if(price == 0){
//		result = "￥" + price;
//	}
//	if(price > 1000){
//		result = "￥" + parseInt(price/1000) + "," + (price - parseInt(price/1000)*1000);
//	}
//	if (price < 1000 && price > 0) {
//		result = "￥" + price + "";
//	}
	return result;
};

/**初始化页面时候要获取的行程日历的数据*/
Calendar.prototype.initialParams = function(){
	$.ajax({
		type:"POST",
		dataType:"json",
		url:encodeURI("/productDetailCalendarServlet?m_product_id="+Calendar.prototype.id),
//		url:encodeURI("/productDetailCalendarServlet?m_product_id="+Calendar.prototype.id),
		success:function(data){	
		Calendar.prototype.params = data;
		Calendar.prototype.processor();
	}
		
	});
	
};

/**点击按钮时候要获取的行程日历的数据*/
Calendar.prototype.succedentParams = function(year,month){
	$.ajax({
		type:"POST",
		dataType:"json",
//		url:encodeURI("/ProductReserveInfoServlet?m_product_id="+Calendar.prototype.id+"&month="+month+"&year="+year),
		url:encodeURI("/ProductReserveInfoServlet?m_product_id="+Calendar.prototype.id+"&month="+month+"&year="+year),
		success:function(data){	
			Calendar.prototype.params = data;
			Calendar.prototype.build(year,month);
		}
	});
	
}


/**初始化页面时候要获取的单项产品价格的数据*/
Calendar.prototype.initialSingleParams = function(){
	$.ajax({
		type:"POST",
		dataType:"json",
//		url:encodeURI("/productPriceCalendarServlet?type=init&productId="+Calendar.prototype.id),
		url:encodeURI("/productPriceCalendarServlet?type=init&productId="+Calendar.prototype.id),
		success:function(data){	
		Calendar.prototype.params = data;
		Calendar.prototype.Singleprocessor();
	}
		
	});
	
};

/**点击按钮时候要获取的单项产品价格的数据*/
Calendar.prototype.succedentSingleParams = function(year,month){
	$.ajax({
		type:"POST",
		dataType:"json",
//		url:encodeURI("/productPriceCalendarServlet?type=click&productId="+Calendar.prototype.id+"&month="+month+"&year="+year),
		url:encodeURI("/productPriceCalendarServlet?type=click&productId="+Calendar.prototype.id+"&month="+month+"&year="+year),
		success:function(data){	
			Calendar.prototype.params = data;
			Calendar.prototype.Singlebuild(year,month);
		}
	});
	
}



/**日历初始化函数*/
Calendar.prototype.init = function(){
	Calendar.prototype.removeNode();
	Calendar.prototype.id = $("#product_id").val();
	Calendar.prototype.customerType = $("#customerType").val();
	Calendar.prototype.today = Calendar.prototype.getTodayDate();
}

/**初始化页面时加载的行程日历*/
Calendar.prototype.initPage = function(){
	Calendar.prototype.init();
	Calendar.prototype.initialParams();
};

/**点击按钮的时候加载的行程日历*/
Calendar.prototype.ajaxPage = function(year,month){
	Calendar.prototype.init();
	Calendar.prototype.succedentParams(year,month);
};


/**初始化页面时加载的行程日历*/
Calendar.prototype.initSinglePage = function(){
	Calendar.prototype.init();
	Calendar.prototype.initialSingleParams();
};

/**点击按钮的时候加载的行程日历*/
Calendar.prototype.ajaxSinglePage = function(year,month){
	Calendar.prototype.init();
	Calendar.prototype.succedentSingleParams(year,month);
};



Calendar.prototype.notice = function(){
	
	var result = "";
//	result += '<form method="post" action="">';
	result += '    	<div class="engross"><input type="hidden" name="" id="productId" value="'+Calendar.prototype.id+'"/></div>';
	result += '    	<div class="notice_body">';
	result += '        	<div class="notice">提示：此产品暂无拼团出行计划，如若预订请填写下面信息。</div>';
	result += '            <div class="query_box">';
	result += '                <div class="notice_line" style="margin-top:20px;font-size:16px;">';
	result += '				   <div class="notice_title">快&nbsp;速&nbsp;预&nbsp;订</div>';
	result += '            </div>';
	result += '            <div class="notice_line">';
	result += '                 <div class="notice_label">人&nbsp;&nbsp;&nbsp;数：</div>';
	result += '                 <div class="notice_input"><input type="text" name="registerNumber" id="registerNumber"/></div>';
	result += '            </div>';
	result += '            <div class="notice_line">';
	result += '                 <div class="notice_label">出发日期：</div>';
	result += '                 <div class="notice_input"><input type="text" name="leaveDate" id="notice_leave" onfocus="notice_focus();"/></div>';
	result += '            </div>';
	result += '            <div class="notice_line">';
	result += '                 <div class="notice_label">姓&nbsp;&nbsp;&nbsp;名：</div>';
	result += '                 <div class="notice_input"><input type="text" name="userName"/></div>';
	result += '            </div>';
	result += '            <div class="notice_line">';
	result += '                 <div class="notice_label">手&nbsp;&nbsp;&nbsp;机：</div>';
	result += '                 <div class="notice_input"><input type="text" name="mobile"/></div>';
	result += '            </div>';
	result += '            <div class="notice_btn" style="clear:both;">';
	result += '            		<div id="inquire_submit" onclick="inquireSubmit();"><img src="/img/main/sure_botton.jpg" style="border:0;"/></div>';
	result += '            </div>';
	result += '       </div>';
	result += '    </div>';
//	result += '</form>';
	return result;
};



$(document).ready(function(){
	var cal = new Calendar();//2010-05-23
	
	if(productType == '1'){
		
		if(year_time != '' && month_time != ''){
			year_time = parseInt(year_time);
			if(month_time[0] == '0'){
				month_time = month_time[1];
			}
			var year_int = parseInt(year_time);
			var month_int = parseInt(month_time);
			cal.ajaxPage(year_int, month_int);
		}else{
			cal.initPage();		

		}
		
		
	}else{
		cal.initSinglePage();
	}
	

	
	
	

});

var CalendarButton = function(){};

CalendarButton.prototype.execute = function(year,month){
	var calendar = new Calendar();
		

	if(productType == '1'){
		calendar.ajaxPage(year,month);
			
	}else{
		calendar.ajaxSinglePage(year, month);
	}

};

function btn_click(year,month){
	var button = new CalendarButton();
	button.execute(year,month);
}



function ensureSubmit(){
	
	$(".engross").remove();
	$(".notice_body").remove();
	var calendar = new Calendar();
	var result = calendar.notice();
	$(".calendar").append(result);
	
}





$(document).ready(function(){
	
	$(".operate_head").click(function(){
		$("#regist_bg").css("display","none");
		$("#calendar_tab").css("display","none");
	});

	$(".btn_regist").click(function(event){
		$("#calendar_tab").css("display","none");
		window.location.href="../register.html";
	});
	
});	




function login_click(product_id,product_reserve_id){
	
	var obj = document.getElementById("username_j");
	if(obj){
		user_check(product_id,product_reserve_id);
	}else{
		user_submit(product_id,product_reserve_id);
	}
}

function user_submit(product_id,product_reserve_id){
	
	var regist_count = $("#regist_count_j").val();
	if(regist_count == ""){
		$(".errorMessage").html("请填写报名人数！");
		return false;
	}
	if(isNaN(regist_count)){
		$(".errorMessage").html("报名人数只能为数字！");
		return false;
	}
	
	$("#ProductId_j").val(product_id);
	$("#ProductReserveId_j").val(product_reserve_id);
	$("#calendar_tab").css("display","none");
	$("#login_j").submit();
}




function user_check(product_id,product_reserve_id){
	var username = $("#username_j").val();
	var password = $("#password_j").val();
//	$(".regist_message").html("");
	var regist_count = $("#regist_count_j").val();
	if(regist_count == ""){
		$(".errorMessage").html("请填写报名人数！");
		return false;
	}
	if(isNaN(regist_count)){
		$(".errorMessage").html("报名人数只能为数字！");
		return false;
	}
	if(username == ""){
		$(".errorMessage").html("请输入用户名！");
		return false;
	}
	if(password == ""){
		$(".errorMessage").html("请输入密码！");
		return false;
	}
	
	var mode = "Login";
		
	$.get("../UserLoginValidateServlet",
			{"EMail":encodeURI(username),"Password":encodeURI(password),"Mode":"Login"},
			function(data, textStatus){
				if(data.length > 7){

					$("#ProductId_j").val(product_id);
					$("#ProductReserveId_j").val(product_reserve_id);
					$("#calendar_tab").css("display","none");
					$("#login_j").submit();
					
				}
				if(data.length == 7){
					$(".errorMessage").html("用户名或密码错误，请重新输入！");						
					return false;
				}
				if(data == ""){
					$(".errorMessage").html("网络连接失败！");
					return false;
				}
				
			});

	
}
/*--------------------------------------------------------------*/






var check_user_input = function(){};

/**报名人数*/
check_user_input.prototype.peoplenum = 0;
/**Email地址*/
check_user_input.prototype.email = "";
/**密码*/
check_user_input.prototype.password = "";
/**手机号码*/
check_user_input.prototype.mobile = "";
/**姓名*/
check_user_input.prototype.username = "";
/**产品编号*/
check_user_input.prototype.productId = 0;
/**发团团号*/
check_user_input.prototype.reserveId = 0;
/**登录结果*/
check_user_input.prototype.result = "";

/*初始化参数*/
check_user_input.prototype.init = function(productId,reserveId){
	/*报名人数*/
	check_user_input.prototype.peoplenum = $("#regist_count_j").val();
	/*Email地址*/
	check_user_input.prototype.email = $("#username_j").val();
	/*密码*/
	check_user_input.prototype.password = $("#password_j").val();
	/*手机号码*/
	check_user_input.prototype.mobile = $("#mobile_j").val();
	/*姓名*/
	check_user_input.prototype.username = $("#name_j").val();
	/*产品编号*/
	check_user_input.prototype.productId = productId;
	/*发团编号*/
	check_user_input.prototype.reserveId = reserveId;
};


/*验证人数*/
check_user_input.prototype.check_peoplenum = function(){
	var num = check_user_input.prototype.peoplenum;
	if(isNaN(num)){
		$("#regist_number_error").html("预订人数仅限填写数字！");
		return false;
	}
	$("#regist_number_error").html("");
	return true;
};

/*验证邮箱*/
check_user_input.prototype.check_email = function(){
	var email = check_user_input.prototype.email;
	var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/; /*电子邮箱的正则表达式*/
	var bool = reg.test(email);
	if(bool == false && email != ""){
		$("#username_j_error").html("邮箱格式错误，请重新填写！");
		return false;
	}
	$("#username_j_error").html("");
	return true;
};

/*验证手机*/
check_user_input.prototype.check_mobile = function(){
	var phone = check_user_input.prototype.mobile;
	var mobile_reg = /^1[3|4|5|8][0-9]\d{4,8}$/;
	var bool = mobile_reg.test(phone);
	if(bool == false && phone != ""){
		$("#mobile_j_error").html("手机格式错误，请重新填写！");
		return false;
	}
	$("#mobile_j_error").html("");
	return true;	
};

/*验证姓名*/
check_user_input.prototype.check_username = function(){
	var name = check_user_input.prototype.username;
	var reg = /^[\u4E00-\u9FA5]+$/; /*中文的正则表达式*/
	var bool = reg.test(name);
	if(name != "" && bool == false){
		$("#name_j_error").html("姓名只能填写汉字！");
		return false;
	}
	$("#name_j_error").html("");
	return true;
};

/*验证用户输入的邮箱和密码是否正确*/
check_user_input.prototype.check_login = function(email,password,type){
	
	check_user_input.prototype.result = "";
	
	$.ajax({
		type:"POST",
		dataType:"text",
		url:encodeURI("/UserLoginValidateServlet?EMail="+email+"&Password="+password+"&Mode=Login"),
		success:function(data){
		
		check_user_input.prototype.result = data;
//		alert("check_user_input.prototype.check_login:" + check_user_input.prototype.result);
		
		check_user_input.prototype.check_callback(type);
		
	}
	});
	
}

/**填写会员信息的验证*/
check_user_input.prototype.check_member = function(email,password,type){
	check_user_input.prototype.result = "";
	$.ajax({
		type:"POST",
		dataType:"text",
		url:encodeURI("/UserLoginValidateServlet?EMail="+email+"&Password="+password+"&Mode=Login"),
		success:function(data){
		check_user_input.prototype.result = data;
		alert("check_user_input.prototype.check_login:" + check_user_input.prototype.result);
		
		check_user_input.prototype.check_callback(type);
		
		
	}
	});
}

/**处理回调的信息*/
check_user_input.prototype.check_callback = function(type){
	var result = check_user_input.prototype.result;
	var status = false;
	
	/*验证手机格式*/
	var not_mobile = check_user_input.prototype.check_mobile();
	/*验证姓名格式*/
	var not_name = check_user_input.prototype.check_username();
	
	if(result.length > 7){
		status = true;
	}else{
		$("#username_j_error").html("用户名或密码错误，请重新输入！");
		status = false;
	}
	
	
	if(type == "member"){
		if(status){
			$("#ProductId_j").val(check_user_input.prototype.productId);
			$("#ProductReserveId_j").val(check_user_input.prototype.reserveId)
			$("#calendar_tab").css("display","none");
			$("#login_j").submit();
		}else{
			return false;
		}
	}

	if(type == "all"){
		if (!status) {
			return false;
		} else {
			/*如果手机及姓名格式正确并且用户名和密码输入正确*/
			if(not_name == true && not_mobile == true){
				$("#ProductId_j").val(check_user_input.prototype.productId);
				$("#ProductReserveId_j").val(check_user_input.prototype.reserveId)
				$("#calendar_tab").css("display","none");
				$("#login_j").submit();
			}
			return false;
		}
		
		
	}
	
	
	
	
}






/**
 * 	验证规则如下：
 * 	1.预订人数必填
 * 	2.会员信息：验证用户名和密码的必填和合法性
 * 	3.非会员信息：验证手机和姓名的必填和合法性
 * 	4.如果填写了会员信息或者填写了非会员信息则2、3两条都需验证
 * */
check_user_input.prototype.onSubmit = function(){
	
	var num = check_user_input.prototype.peoplenum;
	
	var email = check_user_input.prototype.email;
	
	var password = check_user_input.prototype.password;
	
	var mobile = check_user_input.prototype.mobile;
	
	var name = check_user_input.prototype.username;
	
	var isMember = (email != "" && password != "");
//	var isNotMember = (mobile != "" && name != "");
	var isNotMember = (mobile != "");
	
	$("#regist_number_error").html("");
	$("#username_j_error").html("");
	$("#mobile_j_error").html("");
	$("#name_j_error").html("");
	
	
	if(num == ""){
		$("#regist_number_error").html("请填写预订人数！");
		return false;
	} else {
		check_user_input.prototype.check_peoplenum();
	}
	
	/*会员信息与非会员信息都填写完整*/
	if(isMember == true && isNotMember == true){
		check_user_input.prototype.check_login(email,password,"all");
		return false;
	}else 
		/*会员信息填写完整*/
		if(isMember == true) {
			var is_email = check_user_input.prototype.check_email();
			if(is_email == true){
				check_user_input.prototype.check_login(email,password,"member");
			}
			return false;
	}else 
		/*非会员信息填写完整*/
		if(isNotMember == true){
			var not_mobile = check_user_input.prototype.check_mobile();
			var not_name = check_user_input.prototype.check_username();
			if(not_name == true && not_mobile == true){
				$("#ProductId_j").val(check_user_input.prototype.productId);
				$("#ProductReserveId_j").val(check_user_input.prototype.reserveId)
				$("#calendar_tab").css("display","none");
				$("#login_j").submit();
			}
			return false;
	}	/*以上信息填写不完整*/	
		else {
			alert("请将信息填写完整！");
			return false;
	}
	
};


function checkname_passsword(email,password){
	var result = "";
	alert("before:" + result);
	$.ajax({
		type:"POST",
		dataType:"text",
		url:encodeURI("/UserLoginValidateServlet?EMail="+email+"&Password="+password+"&Mode=Login"),
		success:function(data){
		
		result = data;
	}
	});
	
	alert(result);
}






/*---------------------------------------------------------------------------*/
function regist_click(product_id,product_reserve_id,qtyleft,attribute,event){
	var schedule = $("#"+product_reserve_id+"schedule").val();
	if(schedule != '报名中' && schedule != '特价中'){
		alert("很抱歉,此日期目前无法接受预订,请另外选择其它报名中的日期,谢谢!");
	}else{
		

		var qtyleftShow = "";
		var notice = $("#"+product_reserve_id+"notice").val();
		
		$("#calendar_tab").css("display","block");
		var height = 6650 + "px";
		var width = document.documentElement.clientWidth + "px";
		$("#regist_bg").css({"display":"block","width":width,"height":height});		
		$("#ensureSubmit").bind("click",function(){
//			login_click(product_id,product_reserve_id);
			
			var check = new check_user_input();
			check.init(product_id,product_reserve_id);
//			check.productId = product_id;
//			alert(check.productId);
//			check.reserveId = product_reserve_id;
			check.onSubmit();

			
		});
		
	}
}
/*---------------------------------------------------------------*/

function orderLink(product_reserve_id){
//	window.location.href = '/BookTravelGroupFillOrder?reserveId='+product_reserve_id;
	
	var form = document.createElement('form');
	document.body.appendChild(form);
	form.setAttribute('method', 'post');
	var url = '/BookTravelGroupFillOrder.htm';
	form.action = url;

	var input = document.createElement('input');
	input.setAttribute('type', 'hidden');
	input.setAttribute('name', 'reserveId');
	input.setAttribute('value', product_reserve_id);
	form.appendChild(input);

	form.submit();
	return false;
}




function test(product_reserve_id){

	var form = document.createElement('form');
	document.body.appendChild(form);
	form.setAttribute('method', 'post');
	var url = '/BookTravelGroupFillOrder.htm';
	form.action = url;

	var input = document.createElement('input');
	input.setAttribute('type', 'hidden');
	input.setAttribute('name', 'reserveId');
	input.setAttribute('value', product_reserve_id);
	form.appendChild(input);

	form.submit();
	return false;

}



