function checkform(){
	var theform=document.selform;
	var inputday;
	var inputday2;
		
	inputday= new Date(theform.year.value,theform.mon.value - 1,theform.day.value);
	inputday2= new Date(theform.year2.value,theform.mon2.value - 1,theform.day2.value);
	
		
	if(inputday.getTime() >= inputday2.getTime()) 
	{
		alert("退房日期 <= 入住日期");
		return false;
	}
	if(inputday.getTime() < now.getTime()) 
	{
		alert("入住日期 <= 今天");
		return false;
	}
	if((theform.hotel_id.value=="")|| (theform.hotel_id.value==0))
	{
		alert("選擇飯店");
		return false;
	}
		
	theform.inputday.value=theform.year.value+"/"+theform.mon.value+"/"+theform.day.value;
	theform.inputday2.value=theform.year2.value+"/"+theform.mon2.value+"/"+theform.day2.value;
	return true;
}
function SetToday(){
 	var theform=document.selform;
	theform.year.length=2;
	theform.year2.length=2;
	theform.year.options[0].text = now_year;
	theform.year.options[0].value = now_year;
	theform.year.options[1].text = next_year;
	theform.year.options[1].value = next_year;
	theform.year2.options[0].text = now_year;
	theform.year2.options[0].value = now_year;
	theform.year2.options[1].text = next_year;
	theform.year2.options[1].value = next_year;
		
	theform.mon.length=12;
	theform.mon2.length=12;
		
	for(i=0;i<12;i++){
		theform.mon.options[i].text = i+1;
		theform.mon.options[i].value = i+1;
		theform.mon2.options[i].text = i+1;
		theform.mon2.options[i].value = i+1;
	}
			
	theform.day.length=31;
	theform.day2.length=31;
			
	for(i=0;i<31;i++){
		theform.day.options[i].text = i+1;
		theform.day.options[i].value = i+1;
		theform.day2.options[i].text = i+1;
		theform.day2.options[i].value = i+1;
	}			
	theform.roomcount.length=10;
		
	for(i=0;i<theform.roomcount.length;i++){
		theform.roomcount.options[i].text = i+1;
		theform.roomcount.options[i].value = i+1;
	}
			
	theform.year.value=now_year;
	theform.mon.value=now_month;
	theform.day.value=now_date;
	theform.year2.value=tommorrow_year;
	theform.mon2.value=tommorrow_month;
	theform.day2.value=tommorrow_date;
}
function showcalendar(type,year,month){
	if(year==0){ 
		year=now_year;
		month=now_month;
	}	
	var monstartday = new Date(year,month-1,1);
	var monendday = new Date(year,month,0);
	var thisid,monthstr,datetypestr,startday;
	
	if(type==1){
		thisid="c1";
		datetypestr="入住日期";
	}	
	else 
	{
		thisid="c2";
		datetypestr="退房日期";
	}
	year=monstartday.getFullYear();
	month=monstartday.getMonth()+1;
	startday=monstartday.getDay();
	monthstr="<table class=table1 width=212 bgcolor=ffffff border=1 style='border-collapse:collapse'  bordercolor='#7599D0' cellspacing=0 cellpadding=0 style='font-size:9pt;font-family:'arial'>";
	monthstr+="<tr><td align=center height=20 valign=middle>";
	monthstr+="<span style='width:192px;padding-left:16px;vertical-align:middle'>"+datetypestr+"</span>";
	monthstr+="<span class=calendarspan3><img src='http://www.ezhotel.com.tw/images/month_close.gif' style='cursor:hand' width=16 height=16 align=absmiddle onclick='closcalendar("+type+")' alt=' 關 閉 '></span></td></tr>";
	monthstr+="<tr><td align=center valign=middle height=20><span class=calendarspan3><img src='http://www.ezhotel.com.tw/images/month_back.gif'  align=absmiddle style='cursor:hand' onclick='javascript:showcalendar("+type+","+year+","+(month-1)+");' alt='上個月'></span>";
	monthstr+="<span  style='text-align:center;width:150px' >"+year+" / "+(month)+"</span>";
	monthstr+="<span class=calendarspan3><img src='http://www.ezhotel.com.tw/images/month_to.gif' style='cursor:hand'  align=absmiddle onclick='javascript:showcalendar("+type+","+year+","+(month+1)+");' alt='下個月'></span></td></tr>";
	monthstr+="<tr><td width=100% align=left>";
				monthstr+="<span class=calendarspan2><font color=#777777>日</font></span>";
				monthstr+="<span class=calendarspan1><font color=#777777>一</font></span>";
					monthstr+="<span class=calendarspan1><font color=#777777>二</font></span>";
					monthstr+="<span class=calendarspan1><font color=#777777>三</font></span>";
					monthstr+="<span class=calendarspan1><font color=#777777>四</font></span>";
					monthstr+="<span class=calendarspan1><font color=#777777>五</font></span>";
					monthstr+="<span class=calendarspan2><font color=#777777>六</font></span>";
				for(i=0;i<monstartday.getDay();i++)
	{
		monthstr+="<span class=calendarspan1> </span>";
	}
	for(i=0;i<monendday.getDate();i++)
	{
		if((year==today.getFullYear())&&(month==today.getMonth()+1)&&((i+1)==today.getDate())) monthstr+="<span class=calendarspan4 ><b>"+(i+1)+"</b></span>";
		else if((year>today.getFullYear())||(year==today.getFullYear() && month>today.getMonth()+1)||(year==today.getFullYear() && month==today.getMonth()+1 && (i+1) > today.getDate()))
		{
			monthstr+="<span class=calendarspan1><a href='javascript:setorderdate("+type+","+year+","+month+","+(i+1)+");' class='datemenu'>"+(i+1)+"</a></span>";	
		}
		else
		{
			monthstr+="<span class=calendarspan1><font color=bbbbbb>"+(i+1)+"</font></span>";
		}
		if((startday+1)%7==0) monthstr+="<br>";
		startday++;
	}
	monthstr+="</td></tr></table>";
	
	c1.style.display='none';
	c2.style.display='none';
	document.getElementById("d1").style.display='none';
	document.getElementById("d2").style.display='none';
	eval("document.getElementById('d"+type+"').style.display=''");
	eval(thisid+".style.display=''");
	eval(thisid+".innerHTML=''");
	eval(thisid+".innerHTML=\""+monthstr+"\"");
}
function setorderdate(type,year,month,date)
{
	var theform=document.selform;
	if(type==1)
	{
		theform.year.value=year;
		theform.mon.value=month;
		theform.day.value=date;
		showcalendar(2,year,month);
	}
	else
	{
		theform.year2.value=year;
		theform.mon2.value=month;
		theform.day2.value=date;
		c2.style.display='none';
		document.getElementById("d2").style.display='none';
	}
}
function closcalendar(type)
{
	if(type==1) thisid="c1";
	else  thisid="c2";
	eval(thisid+".style.display='none'");
	eval("document.getElementById('d"+type+"').style.display='none'");
}
