document.write('<iframe id=CalFrame name=CalFrame frameborder=0 src=/calendar/calendar.htm style=display:none;position:absolute;z-index:100></iframe>');
document.onclick=hideCalendar;

function showCalendar(sImg,bOpenBound,sFldy,sFldm,sFldd,sCallback)
{
	var fy,fm,fd,fld1,fld2;
	var cf=document.getElementById("CalFrame");
	var wcf=window.frames.CalFrame;
	var oImg=document.getElementById(sImg);
	if(!oImg){alert("控制对象不存在！");return;}
	//if(!sFld1){alert("输入控件未指定！");return;}
	//fld1=document.getElementById(sFld1);
	fy=document.getElementById(sFldy);
	fm=document.getElementById(sFldm);
	fd=document.getElementById(sFldd);	
	//fld1=document.getElementById(sFld1);	
	//if(!fld1){alert("输入控件不存在！");return;}
	//if(fld1.tagName!="INPUT"||fld1.type!="text"){alert("输入控件类型错误！");return;}
	//if(sFld2)
	//{
		//fld2=document.getElementById(sFld2);
		//if(!fld2){alert("参考控件不存在！");return;}
		//if(fld2.tagName!="INPUT"||fld2.type!="text"){alert("参考控件类型错误！");return;}
	//}
	if(!wcf.bCalLoaded){alert("日历未成功装载！请刷新页面！");return;}
	if(cf.style.display=="block"){cf.style.display="none";return;}
	var eT=0,eL=0,p=oImg;
	var sT=document.body.scrollTop,sL=document.body.scrollLeft;
	var eH=oImg.height,eW=oImg.width;
	while(p&&p.tagName!="BODY"){eT+=p.offsetTop;eL+=p.offsetLeft;p=p.offsetParent;}
	cf.style.top=(document.body.clientHeight-(eT-sT)-eH>=cf.height)?eT+eH:eT-cf.height;
	cf.style.left=(document.body.clientWidth-(eL-sL)>=cf.width)?eL:eL+eW-cf.width;
	cf.style.display="block";	
	wcf.openbound=bOpenBound;
	wcf.fld1=fld1;
	wcf.fy=fy;
	wcf.fm=fm;
	wcf.fd=fd;
	wcf.callback=sCallback;
	wcf.fld2=fld2;
	wcf.initCalendar();
}



function hideCalendar()
{
	var cf=document.getElementById("CalFrame");
	cf.style.display="none";
}

function setCheckInDate(d)
{    
   
   
   
   if (d.length==9)
   {
   if (d.substr(5,2)==10||d.substr(5,2)==11||d.substr(5,2)==12)
   {
   document.getElementById("f_nen1").value=d.substr(0,4); 
   document.getElementById("f_tuki1").value=d.substr(5,2);
   document.getElementById("f_hi1").value=d.substr(8,1);
	}
   else
   {
   document.getElementById("f_nen1").value=d.substr(0,4);  
   document.getElementById("f_tuki1").value=d.substr(5,1); 
   document.getElementById("f_hi1").value=d.substr(7,2); 
   }
   }
   else if (d.length==10)
   { 
   
  document.getElementById("f_nen1").value=d.substr(0,4);  
  document.getElementById("f_tuki1").value=d.substr(5,2); 
  document.getElementById("f_hi1").value=d.substr(8,2); 
   }
   else if (d.length==8)
   {
   document.getElementById("f_nen1").value=d.substr(0,4);  
   document.getElementById("f_tuki1").value=d.substr(5,1); 
   document.getElementById("f_hi1").value=d.substr(7,1); 
   }
   
   
      
   if (document.getElementById("f_nen2").value.length==4)
	
	{
		showCalendar('imageCalendar2',false,'f_nen2','f_tuki2','f_hi2');
	}
	
}
  
//function setCheckInDate(d)
//{
//	document.getElementById("hdate1").value=d;
//	if(document.getElementById("hdate2").value.length==0)
	//{
	//	showCalendar('dimg2',false,'hdate2','hdate1');
	//}
//} 

function yearIndex(yearIdx){
    if (yearIdx == 2007) { ry = 0;}
    else if (yearIdx == 2008) { ry = 1;}
    else if (yearIdx == 2009) { ry = 2;}
   return(ry);
}
function addDate(year, month, date, n){
    var leisure_number = n * 1000 * 60 * 60 * 24;
	var targetDate = new Date(year, month, date);
	var DateInMS = targetDate.getTime();
	DateInMS += leisure_number;
	targetDate.setTime(DateInMS);
	var theYear = targetDate.getFullYear();
	var theMonth = targetDate.getMonth();
	var theDate = targetDate.getDate();
    rdt  = new Date(theYear, theMonth, theDate);
    return(rdt);
}


	function change_hotel_EndDate() {
    leisure_nd = new Date(
		document.QueryCondition.f_nen1.options[document.QueryCondition.f_nen1.options.selectedIndex].value, 
		document.QueryCondition.f_tuki1.options[document.QueryCondition.f_tuki1.options.selectedIndex].value, 
		document.QueryCondition.f_hi1.options[document.QueryCondition.f_hi1.options.selectedIndex].value
	);
	mm = leisure_nd.getMonth();

    y = leisure_nd.getFullYear()-1;
    m = leisure_nd.getMonth()-1;
    d = leisure_nd.getDate();

	if(d == 31 && (mm == 2 || mm == 4 || mm == 6 || mm == 9 || mm == 11)){
		if(mm==2){
			d = 28;
		}else{
			d = 30;
		}
	}else if(eval(document.QueryCondition.f_tuki1.options[document.QueryCondition.f_tuki1.options.selectedIndex].value) == 1){
		if(eval(document.QueryCondition.f_hi1.options[document.QueryCondition.f_hi1.options.selectedIndex].value)==29){
			m = 0;
			d = 29;
		}else if(eval(document.QueryCondition.f_hi1.options[document.QueryCondition.f_hi1.options.selectedIndex].value)==30){
			m = 0;
			d = 30;
		}else if(eval(document.QueryCondition.f_hi1.options[document.QueryCondition.f_hi1.options.selectedIndex].value)==31){
			m = 0;
			d = 31;
		}
	}else if(( d == 29 || d == 30 )&& mm == 2){
		d = 28;
	}else if((eval(document.QueryCondition.f_tuki1.options[document.QueryCondition.f_tuki1.options.selectedIndex].value) == 5) && 
		eval(document.QueryCondition.f_hi1.options[document.QueryCondition.f_hi1.options.selectedIndex].value)==31){
		m = 4;
		d = 31;
	}else if((eval(document.QueryCondition.f_tuki1.options[document.QueryCondition.f_tuki1.options.selectedIndex].value) == 8) && 
		eval(document.QueryCondition.f_hi1.options[document.QueryCondition.f_hi1.options.selectedIndex].value)==31){
		m = 7;
		d = 31;
	}else if((eval(document.QueryCondition.f_tuki1.options[document.QueryCondition.f_tuki1.options.selectedIndex].value) == 10) && 
		eval(document.QueryCondition.f_hi1.options[document.QueryCondition.f_hi1.options.selectedIndex].value)==31){
		m = 9;
		d = 31;
	}else if((eval(document.QueryCondition.f_tuki1.options[document.QueryCondition.f_tuki1.options.selectedIndex].value) == 3) && 
		eval(document.QueryCondition.f_hi1.options[document.QueryCondition.f_hi1.options.selectedIndex].value)==31){
		m = 2;
		d = 31;
	}
    myDate = addDate(y, m ,d, 1);
	currYear    = myDate.getFullYear();
	currMonth   = myDate.getMonth();
	currDate    = myDate.getDate();
	document.QueryCondition.f_nen2.selectedIndex = yearIndex(currYear);
	document.QueryCondition.f_tuki2.selectedIndex = currMonth;
	document.QueryCondition.f_hi2.selectedIndex = currDate-1;
}
