date_init=new Date()
dateCurrentIn=new Date(date_init.getYear(),date_init.getMonth(),parseInt(date_init.getDate())+15)
dateCurrentOut=new Date(parseInt(dateCurrentIn.getYear()),parseInt(dateCurrentIn.getMonth()),parseInt(dateCurrentIn.getDate())+3)
var arrMonth=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
var arrDays=new Array(31,0,31,30,31,30,31,31,30,31,30,31);
var arrDs=new Array("S","M","T","W","TH","F","S");
dc=new Date()
intYearCurrent=dc.getFullYear()
function nextMonth(intCal){

		intMonth=parseInt(document.getElementById('cbMonth_in').value);
		intYear=parseInt(document.getElementById('cbYear_in').value);

	intMonthNext=(intMonth==11)?0:intMonth+1;
	intYearNext=(intMonthNext==0)?intYear+1:intYear;
	makeCalendar(intMonthNext,intYearNext,intCal);
}
function prevMonth(intCal){

		intMonth=parseInt(document.getElementById('cbMonth_in').value);
		intYear=parseInt(document.getElementById('cbYear_in').value);

	intMonthPrev=(intMonth==0)?11:intMonth-1;
	intYearPrev=(intMonthPrev==11)?intYear-1:intYear;
	
	makeCalendar(intMonthPrev,intYearPrev,intCal);
}
function makeCalendar(intMonth,intYear,intCal){
	intMonth=parseInt(intMonth);
	intYear=parseInt(intYear);
	arrDays[1]=(intYear%4==0)?29:28;
	
	strCalendar='<table width="185" cellspacing="0" cellpadding="3" border="0"" id="ctable">';
	strCalendar+='<tr><td align="center" width="100%">';
	strCalendar+='<a href="javascript:prevMonth('+intCal+')">Prev</a> <select id="cbMonth_in" onChange="Change('+intCal+');">';
	for(var i=0;i<12;i++){
		if(i==intMonth){
			strCalendar+='<option value="'+i+'" selected>'+arrMonth[i]+'</option>';
		}else{
			strCalendar+='<option value="'+i+'">'+arrMonth[i]+'</option>';
		}
	}
	strCalendar+='</select>';
	strCalendar+='<select id="cbYear_in" onChange="Change('+intCal+');">';
	for(var i=2007;i<=intYear+2;i++){
		if(i==intYear){
			strCalendar+='<option value="'+i+'" selected>'+i+'</option>';
		}else{
			strCalendar+='<option value="'+i+'">'+i+'</option>';
		}
	}
	
	strCalendar+='</select> <a href="javascript:nextMonth('+intCal+')">Next</a>';
	strCalendar+='</td></tr>';
	
	
	//#Create Day of Calendar
	strCalendar+='<tr><td>';
	
	strCalendar+='<table width="185" border="0" cellspacing="1" id="sub_ctable">';
	strCalendar+='<tr align="center">'
	strCalendar+='<td width="15%" class="cheader">'+arrDs[0]+'</td>';
	strCalendar+='<td width="14%" class="cheader">'+arrDs[1]+'</td>';
	strCalendar+='<td width="14%" class="cheader">'+arrDs[2]+'</td>';
	strCalendar+='<td width="14%" class="cheader">'+arrDs[3]+'</td>';
	strCalendar+='<td width="14%" class="cheader">'+arrDs[4]+'</td>';
	strCalendar+='<td width="14%" class="cheader">'+arrDs[5]+'</td>';
	strCalendar+='<td width="15%" class="cheader">'+arrDs[6]+'</td>';
	strCalendar+='</tr>';
	
	intLastMonth=intMonth-1;
	intLastYear=intYear;
	if(intLastMonth==-1){intLastMonth=11;intLastYear=intLastYear-1;}
	intLastDay=arrDays[intLastMonth];
	dt=new Date(intYear,intMonth,1);
	intStartDay=dt.getDay();

	intCols=0;
	strCalendar+='<tr>';
	if(intMonth==0){
			intMonthPrev=12;
			intYearPrev=intYear-1;
		}else{
			intMonthPrev=intMonth;
			intYearPrev=intYear;
	}
	
	dt=new Date();
	nowDate=dt.getDate();
	nowMonth=dt.getMonth();
	nowYear=dt.getFullYear();
	
	date_now=genDate(nowYear,nowMonth+1,nowDate)
	
	for(var i=0;i<intStartDay;i++,intCols++){
		
		intDay=(intLastDay-intStartDay+i+1);
		//alert(datediff('2007/11/19',genDate(intYearPrev,intMonthPrev,intDay)));
		if(datediff(date_now,genDate(intYearPrev,intMonthPrev,intDay))==true){
			if(intCal==1){
				strCalendar+='<td align="right"><a href="javascript:changeDay(\''+genDate(intYearPrev,intMonthPrev,intDay)+'\',1)">'+intDay+'</a></td>';
			}else{
				strCalendar+='<td align="right"><a href="javascript:changeDay(\''+genDate(intYearPrev,intMonthPrev,intDay)+'\',2)">'+intDay+'</a></td>';
			}
		}else{
		strCalendar+='<td align="right">'+intDay+'</td>';
		}
		

	}
	
	for(var i=1;i<=arrDays[intMonth];i++,intCols++){
		if(datediff(date_now,genDate(intYear,intMonth+1,i))==true){
			if(intCal==1){
				strCalendar+='<td align="right"><a href="javascript:changeDay(\''+genDate(intYear,intMonth+1,i)+'\',1)">'+i+'</a></td>';
			}else{
				strCalendar+='<td align="right"><a href="javascript:changeDay(\''+genDate(intYear,intMonth+1,i)+'\',2)">'+i+'</a></td>';
			}
		}else{
		strCalendar+='<td align="right">'+i+'</td>';
		}
		if(intCols==6){
			strCalendar+='</tr><tr>';
			intCols=-1;
		}
	}
	
	for(var i=1;intCols<7;i++,intCols++){
		intNextMonth=(intMonth==11)?1:intMonth+2;
		intNextYear=(intMonth==11)?intYear+1:intYear;
		if(datediff(date_now,genDate(intNextYear,intNextMonth,i))==true){
			if(intCal==1){
				strCalendar+='<td align="right"><a href="javascript:changeDay(\''+intNextYear+'/'+(intNextMonth)+'/'+i+'\',1)">'+i+'</a></td>';
			}else{
				strCalendar+='<td align="right"><a href="javascript:changeDay(\''+intNextYear+'/'+(intNextMonth)+'/'+i+'\',2)">'+i+'</a></td>';
			}
		}else{
			strCalendar+='<td align="right">'+i+'</td>';
		}
	}
	
	strCalendar+='</tr>';
	strCalendar+='</table>';
	
	strCalendar+='</tr></td>';
	//#-----------------------
	strCalendar+='</table>';

	document.getElementById('a').innerHTML=strCalendar;
}

function fnGenDCalendar(check_in_date,check_out_date){
	if(check_in_date !=null){
		//yyyy/mm/dd
		arrDateIn=check_in_date.split("/");
		arrDateOut=check_out_date.split("/");
		date_in=arrDateIn[2];
		month_in=arrDateIn[1];
		year_in=arrDateIn[0];
		
		date_out=arrDateOut[2];
		month_out=arrDateOut[1];
		year_out=arrDateOut[0];
	}else{
		dateCurrent=new Date()
		date_in=dateCurrent.getDate()
		month_in=dateCurrent.getMonth()
		year_in=dateCurrent.getFullYear()
		
		dateCurrentOut=new Date(year_in,month_in,date_in+2)
		
		date_out=dateCurrentOut.getDate()
		month_out=dateCurrentOut.getMonth()
		year_out=dateCurrentOut.getFullYear()
	}
	document.getElementById('check_in_date').innerHTML=fnSetDCalendar(28,10,2007,1,1);
	document.getElementById('check_out_date').innerHTML=fnSetDCalendar(30,10,2007,2,1);
}

function fnSetDCalendar(intDate,intMonth,intYear,intType,intArrange){
	if(intType==1){
		strDateName='chk_in_date';
		strMonthName='chk_in_month';
		strYearName	='chk_in_year';
	}else{
		strDateName='chk_out_date';
		strMonthName='chk_out_month';
		strYearName	='chk_out_year';
	}
	
	
	strDate='<select name='+strDateName+' onChange="fn_cbChange()">';
	arrDays[1]=(intYear%4==0)?29:28;
	for(var i=1;i<=arrDays[intMonth];i++){
		if(i==intDate){
			strDate+='<option value='+i+' selected>'+i+'</option>';
		}else{
			strDate+='<option value='+i+'>'+i+'</option>';
		}
		
	}
	strDate+='</select>';
	
	strMonth='<select name='+strMonthName+' onChange="fn_cbChange()">';
	for(var i=0;i<arrMonth.length;i++){
		if(i==intMonth){
			strMonth+='<option value='+i+' selected>'+arrMonth[i]+'</option>';
		}else{
			strMonth+='<option value='+i+'>'+arrMonth[i]+'</option>';
		}
		
	}
	strMonth+='</select>';
	
	strYear='<select name='+strYearName+' onChange="fn_cbChange()">';
	for(var i=0;i<=2;i++){
		if((intYear+i)==intYear){
			strYear+='<option value='+(intYear+i)+' selected>'+(intYear+i)+'</option>'
		}else{
			strYear+='<option value='+(intYear+i)+'>'+(intYear+i)+'</option>'
		}
		
	}
	strYear+='</select>';
	return strMonth+strDate+strYear;
	//return strMonth
}
