function chkBrows(sInp) {
	var sUA = navigator.userAgent.toLowerCase();
	var bFound = sUA.indexOf(sInp) + 1;
	return bFound;
}
/* css positioning functions for popups */

function FindDocW() {
	return document.body.scrollWidth > document.body.offsetWidth ? document.body.scrollWidth : document.body.offsetWidth;
}
function FindDocH() {
	return document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight;
}
function FindWinW() {
	return self.innerWidth ? self.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body ? document.body.clientWidth : 0;
}
function FindWinH() {
	return self.innerHeight ? self.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body ? document.body.clientHeight : 0;
}
function FindWinScrX() {
	return self.pageXOffset ? self.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body ? document.body.scrollLeft : 0;
}
function FindWinScrY() {
	return self.pageYOffset ? self.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body ? document.body.scrollTop : 0;
}
function FindPosX(oEl,iAdd) {
	var x = String(iAdd) == 'undefined' ? 0 : iAdd;
	if (oEl.offsetWidth) x += oEl.offsetWidth;
	if (oEl.offsetParent) {
		while (oEl.offsetParent) {
			x += oEl.offsetLeft
			oEl = oEl.offsetParent;
		}
	} else if (oEl.x) x += oEl.x;
	return x;
}
function FindPosY(oEl,iAdd) {
	var y = String(iAdd) == 'undefined' ? 0 : iAdd;
	if (oEl.offsetHeight) y += oEl.offsetHeight;
	if (oEl.offsetParent) {
		while (oEl.offsetParent) {
			y += oEl.offsetTop
			oEl = oEl.offsetParent;
		}
	} else if (oEl.y) y += oEl.y;
	return y;
}

function ShowDiv(soPos,soDiv,bShow,iXAdd,iYAdd,bXAddAbs,bYAddAbs) {
   
	var xsDiv = null;
	var ysDiv = null;
	
	if (String(bShow) == 'undefined') bShow = true; 
	if (String(bXAddAbs) == 'undefined') bXAddAbs = false;
	if (String(bYAddAbs) == 'undefined') bYAddAbs = false;
	var oPos = typeof soPos == 'object' ? soPos : document.getElementById(soPos);
	var oDiv = typeof soDiv == 'object' ? soDiv : document.getElementById(soDiv);
	 
	 	if (oDiv.className=='ptP' || oDiv.className=='plT') {
		if (this.chkBrows('msie') && this.chkBrows('windows')) {
			 iYAdd=-47;
		} 
		if (this.chkBrows('msie') && this.chkBrows('mac')) {
			 iYAdd=-346;
			 iXAdd=iXAdd-20;
		}	
	}	
	 
	   
	var iBottom = FindWinScrY() + FindWinH();
	var xsDiv = bXAddAbs ? iXAdd : FindPosX(oPos,iXAdd);
	var ysDiv = bYAddAbs ? iYAdd : FindPosY(oPos,iYAdd);

	oDiv.style.left = xsDiv + 'px';
	oDiv.style.top = ysDiv + 'px'; 
	
	oDiv.style.display = bShow ? "block" : "none";
	var iPopH = oDiv.offsetHeight ? oDiv.offsetHeight : 0;
	
	if (this.chkBrows('msie') && this.chkBrows('mac_')) {    
		ysDiv=ysDiv-5;
		oDiv.style.left = xsDiv + 'px';	
		oDiv.style.top = ysDiv + 'px';	
   }
	if (ysDiv + iPopH > iBottom) {
		ysDiv += (iBottom - ysDiv - iPopH);
		oDiv.style.top = ysDiv + 'px';
	}
	if (document.getElementById('prctip')) {
		if (oDiv.className=='ptP') {
			document.getElementById('prctip').innerHTML = "<div class='title'>"+sbstitl+"</div><div id='prcPop'>"+prcPopVal+"</div>";	
			document.getElementById('prctlt1').innerHTML = "<span class='title'>"+sbstitl+"</span><span class='tltPop'>"+prcPopVal+"</span>";	
			document.getElementById('prctlt2').innerHTML = "<span class='title'>"+sbstitl+"</span><span class='tltPop'>"+prcPopVal+"</span>";	
		}
		
	}
}

//set a global variable to store all timeouts for all tooltips
iTimeout = false;

function ShowTooltip(sPos,sDiv) {
	var sCode = "ShowDiv('" + sPos + "','" + sDiv + "',true,625,0,1,0);";
	//store the timeout so you can cancel it later
	iTimeout = window.setTimeout(sCode,250);
}
function HideTooltip(sPos,sDiv) {
	//clear any lingering timeouts and reset iTimeout;
	if (iTimeout) {
		window.clearTimeout(iTimeout);
		iTimeout = false;
	}
	ShowDiv(sPos,sDiv,false);
}

/* objects for Detailed Farefinder Calendar */

function oMonth_obj(iM,iY,iSta,iEnd) {
	this.iM = iM;
	this.iY = iY;
	this.aDAll = GetArrD(iM,iY);
	this.aDUse = GetArrDBln(iM,iY,iSta,iEnd);
	this.aDofW = GetArrDofW(iM,iY);
	this.iDMax = this.aDAll[this.aDAll.length - 1];
	this.iDUseMin = this.aDAll[this.aDUse.firstIndexOf(true)];
	this.iDUseMax = this.aDAll[this.aDUse.lastIndexOf(true)];

}

function oCal_obj(sName,sDiv,sSelM,sSelD,sStaMY,sStaD,sCurMY,sCurD) {
	this.sName = sName;

	this.oDiv = document.getElementById(sDiv);

	this.oSelM = document.getElementById(sSelM);
	this.oSelD = document.getElementById(sSelD);

	this.dSta = SetDt(FmtDtArr(sStaMY,sStaD));
	this.iStaD = this.dSta.getDate();
	this.iStaY = this.dSta.getFullYear();
	this.iStaM = this.dSta.getMonth();

	this.dEnd = AddDays(this.dSta, this.iDaysOut);
	this.iEndD = this.dEnd.getDate();
	this.iEndY = this.dEnd.getFullYear();
	this.iEndM = this.dEnd.getMonth();

	var aM = GetArrM(this.iStaM,this.iStaY,this.iEndM,this.iEndY);
	this.aM = [];
	var iY = this.iStaY;
	for (var i = 0; i < aM.length; i++) {
		var iStaD = aM[i] == this.iStaM ? this.iStaD : 0;
		var iEndD = aM[i] == this.iEndM ? this.iEndD : 0;
		this.aM[i] = new oMonth_obj(aM[i], iY, iStaD, iEndD);
		if (aM[i] == 11) iY++;//move to the next year after December;

	}

	this.dCur = SetDt(FmtDtArr(sCurMY,sCurD));

	this.iCurD = this.dCur.getDate();
	//this.iCurM = this.dCur.getMonth();
	
	
	this.iCurM = Number((sCurMY.substr(5,2)));
	if (this.iCurM >0) {
		this.iCurM =this.iCurM-1
	}

	
	this.iCurY = this.dCur.getFullYear();
	this.oCurM = GetObjFromArrByVal(this.aM, this.iCurM, "iM");
	this.iMDis = this.iCurM;
	this.iYDis = this.iCurY;
	this.oMDis = this.oCurM;
}
function oCal_obj_SetM(sCurM, sCurY) {
	this.iCurM = TransMFrom(sCurM);
	this.iCurY = Number(sCurY);
	this.oCurM = GetObjFromArrByVal(this.aM, this.iCurM, "iM");
}
function oCal_obj_Init() {
	
	this.PopM();
	this.PopD();
	document.write(this.DrawCal());
	this.MoveCalD();
}
function oCal_obj_PopM(iM) {
	
	var aOpt = this.oSelM.options;
	aOpt.length = 0;
	for (var i = 0; i < this.aM.length; i++) {
		var oM = this.aM[i];
		var bSel = oM.iM == this.iCurM;
		//Saito modified 20070227
		//		aOpt[i] = new Option(this.aMthAbbr[oM.iM] + " " + oM.iY, oM.iY + "-" + TransMTo(oM.iM));
		aOpt[i] = new Option(oM.iY + "年" + this.aMthAbbr[oM.iM], oM.iY + "-" + TransMTo(oM.iM));
		aOpt[i].defaultSelected = bSel;
		aOpt[i].selected = bSel;
//	alert(oM.iY + "年" + " " + this.aMthAbbr[oM.iM]);
//	alert(oM.iY + "-" + TransMTo(oM.iM));
	}
}
function oCal_obj_PopD() {

	var aOpt = this.oSelD.options;
	aOpt.length = 0;
	for (var i = 0; i < this.oCurM.aDAll.length; i++) {
		var sVal = this.oCurM.aDAll[i];
		var sVal2 = FmtTwoDigits(sVal);
		var bSel = sVal == this.iCurD;
		if (this.oCurM.aDUse[i]) {
			// aOpt[aOpt.length] = new Option(sVal2,sVal2);
			aOpt[aOpt.length] = new Option(sVal2 + "日",sVal2);
			aOpt[aOpt.length - 1].defaultSelected = bSel;
			aOpt[aOpt.length - 1].selected = bSel;
		}
	}
}
function oCal_obj_DisM(iM,iY,bLink) {

	if (String(bLink) == 'undefined') bLink = true;
	this.iMDis = iM;
	this.iYDis = iY;
	this.oMDis = GetObjFromArrByVal(this.aM,this.iMDis,"iM");
	this.MoveCalM(false);
	if (!this.bIsPopup && bLink && this.oCalFw && !CompMs(this.iMDis,this.iYDis,this.oCalFw.iMDis,this.oCalFw.iYDis)) this.oCalFw.DisM(iM,iY);
	if (!this.bIsPopup && bLink && this.oCalBk && CompMs(this.iMDis,this.iYDis,this.oCalBk.iMDis,this.oCalBk.iYDis)) this.oCalBk.DisM(iM,iY);
}
function oCal_obj_ChgM(sVal,bFromFwOrBack) {

	if (String(bFromFwOrBack) == 'undefined') bFromFwOrBack = false;
	//passed a value by calendar interface but no value by select onchange event
	var bFromSel = (String(sVal) == 'undefined');
	if (bFromSel) sVal = this.oSelM[this.oSelM.selectedIndex].value;
	var aVals = sVal.split("-");
	this.SetM(aVals[1], aVals[0]);
	this.DisM(TransMFrom(aVals[1]), Number(aVals[0]),false);
	if (this.bPrevDate) {
		this.iCurD = this.bPrevDate;
		this.bPrevDate = false;
	}
	if (this.iCurD > this.oCurM.iDUseMax) {
		this.bPrevDate = this.iCurD;
		this.iCurD = this.oCurM.iDUseMax;
	}
	if (this.iCurD < this.oCurM.iDUseMin) {
		this.bPrevDate = this.iCurD;
		this.iCurD = this.oCurM.iDUseMin;
	}
	this.PopD();
	if (!bFromSel) this.MoveSelM();
	this.MoveCalM(true);
	//sync linked calendar
	if (!bFromFwOrBack) {
		if (this.oCalFw) {
			//if Trip Template, maintain Trip Template span between depart and return cals until return cal is moved.
			if (this.iTTDays > 0) {
				var dTT = new Date(this.iCurY,this.iCurM,this.iCurD);
				dTT = AddDays(dTT,this.iTTDays);
				this.oCalFw.ChgD(dTT.getDate(),dTT.getMonth(),dTT.getFullYear(),true);
			} else if (!CompDs(this.iCurD,this.iCurM,this.iCurY,this.oCalFw.iCurD,this.oCalFw.iCurM,this.oCalFw.iCurY)) {
				this.oCalFw.ChgD(this.iCurD,this.iCurM,this.iCurY,true);
			}
		}
		if (this.oCalBk) {
			if (this.oCalBk) this.oCalBk.iTTDays = 0;//once back calendar is moved, kill trip template linking
			if (CompDs(this.iCurD,this.iCurM,this.iCurY,this.oCalBk.iCurD,this.oCalBk.iCurM,this.oCalBk.iCurY)) {
				this.oCalBk.ChgD(this.iCurD,this.iCurM,this.iCurY,true);
			}
		}
	}
	if (this.bIsPopup) this.ShowCal(false);
}
function oCal_obj_ChgD(iD,iM,iY,bFromFwOrBack) {

	if (String(bFromFwOrBack) == 'undefined') bFromFwOrBack = false;
	//passed value by calendar interface but no values by dropdowns
	if (String(iM) == 'undefined') iM = this.iCurM;
	if (String(iY) == 'undefined') iY = this.iCurY;
	if (String(iD) == 'undefined') iD = Number(this.oSelD[this.oSelD.selectedIndex].value);
	this.SetM(TransMTo(iM),String(iY));
	this.iCurD = iD;
	this.bPrevDate = false;
	this.ChgM(iY + "-" + TransMTo(iM),bFromFwOrBack);
	this.MoveCalD();
	this.MoveSelD();
	if (this.bIsPopup) this.ShowCal(false);
}
function oCal_obj_MoveSelM() {
	var sVal = this.iCurY + "-" + TransMTo(this.iCurM);
	var oS = this.oSelM;
	oS.selectedIndex = GetSelIndByVal(oS, sVal);
}
function oCal_obj_MoveSelD() {
	var oS = this.oSelD;
	oS.selectedIndex = GetSelIndByVal(oS, FmtTwoDigits(this.iCurD));
}
function oCal_obj_MoveCalM(bMoveDay) {
	this.oDiv.innerHTML = this.DrawCal();
	if (bMoveDay || this.iCurM == this.iMDis) this.MoveCalD();
}
function oCal_obj_MoveCalD() {
	for (var i = 1; i <= this.oCurM.iDMax; i++) {
		var oTD = document.getElementById(this.sName + "day_" + i);
		oTD.className = i == this.iCurD ? "act" : "on";
	}
}
function oCal_obj_DrawCal() {
	var iDateThis = 1;
	var iDofWThis = 0;
	var i = 0;
	var iD = 42;
	var bWhitespace = false;

	var sWr = "";

	sWr += '\n<table border="0" cellspacing="0" cellpadding="0" class="date" align="center">';
	sWr += '\n\t\t<td align="left">';
	if (CompMs(this.iStaM,this.iStaY,this.iMDis,this.iYDis)) {
		var iMBk = this.iMDis == 0 ? 11 : this.iMDis - 1;
		var iYBk = this.iMDis == 0 ? this.iYDis - 1 : this.iYDis;
		sWr += '<a href="javascript:' + this.sName + '.DisM(' + iMBk + ',' + iYBk + ');"><img src="/core/images/box_29/arrow_cal_l.gif" alt="return to previous month" width="8" height="10" border="0" /></a>';
	} else {
		sWr += '<img src="/core/images/d.gif" alt="" width="8" height="10" border="0" />';
	}
	sWr += '</td>';
	sWr += '\n\t\t<td align="center">';
	//変更しました（斉藤　070227）
	//sWr += this.aMthFull[this.iMDis] + ", " + this.iYDis ;
	sWr += this.iYDis+"年" + this.aMthFull[this.iMDis];
	//alert(this.aMthFull[this.iMDis] + ", " + this.iYDis+"年");
	sWr += '</td>';
	sWr += '\n\t\t<td align="right">';
	if (CompMs(this.iMDis,this.iYDis,this.iEndM,this.iEndY)) {
		var iMFw = this.iMDis == 11 ? 0 : this.iMDis + 1;
		var iYFw = this.iMDis == 11 ? this.iYDis + 1 : this.iYDis;
		sWr += '<a href="javascript:' + this.sName + '.DisM(' + iMFw + ',' + iYFw + ');"><img src="/core/images/box_29/arrow_cal_r.gif" alt="advance to next month" width="8" height="10" border="0" /></a>';
	} else {
		sWr += '<img src="/core/images/d.gif" alt="" width="8" height="10" border="0" />';
	}
	sWr += '</td>';
	sWr += '\n\t</tr>';
	sWr += '\n</table>';

	sWr += '\n<div class="c"><table cellpadding="0" cellspacing="0" border="0" align="center">';

	sWr += '\n\t<tr class="hdr">';

	for (var x = 0; x < this.aDayAbbr.length; x++) {
		sWr += '\n\t\t<td><div>' + this.aDayAbbr[x] + '</div></td>';
	}



	sWr += '\n\t</tr>';

	sWr += '\n\t<tr>';

	while (iD > 0 || i < this.oMDis.aDAll.length) {
		if (iDofWThis == this.oMDis.aDofW[i]) {
			sWr += '\n\t\t<td id="' + this.sName + 'day_' + this.oMDis.aDAll[i] + '"';
			sWr += !this.oMDis.aDUse[i] ? '><div>' : ' class="on"><a href="javascript:' + this.sName + '.ChgD(' + this.oMDis.aDAll[i] + ',' + this.iMDis + ',' + this.iYDis + ');">';
			sWr += this.oMDis.aDAll[i];
			sWr += !this.oMDis.aDUse[i] ? '</div>' : '</a>';
			iDateThis++
			i++;
		} else {
			if (bWhitespace) {
				sWr += '\n\t\t<td class="bl">&nbsp;';
			} else {
				sWr += '\n\t\t<td class="no">&nbsp;';
			}
		}
		sWr += '</td>';
		if (iDofWThis == 6) {
			if (i >= this.oMDis.aDAll.length) bWhitespace = true;
			sWr += '\n\t</tr>';
			sWr += '\n\t<tr>';
			iDofWThis = 0;
		} else {
			iDofWThis++;
		}
		iD--;
	}

	sWr += '\n\t</tr>';
	if (this.bIsPopup) sWr += '<tr class="hdr"><td colspan="7" style="width:100%;"><a href="javascript:' + this.sName + '.ShowCal(false);">close</a></td></tr>';
	sWr += '\n</table></div>';
	return sWr;
}
function oCal_obj_ShowCal(bShow) {
	sdForm=document.getElementById('sideform');	
	if (String(bShow) == 'undefined'){	
		var iEnble, numEls = sdForm.elements.length; 
   		for(iEnble=0; iEnble<numEls; iEnble++) { 		
      		sdForm.elements[iEnble].disabled = true;
				}				
		bShow = true;
	 }
	 if (bShow == false) {
		 var iEnble, numEls = sdForm.elements.length; 
   		for(iEnble=0; iEnble<numEls; iEnble++) { 
      		sdForm.elements[iEnble].disabled = false; 
   		} 
		 if (chkBrows('msie') && chkBrows('windows')) {
			if (chkBrows('opera')){
			}
			else {
			if (!chkBrows('msie 5.0')) {	
				var IfrRef = document.getElementById('dIframe');	
				IfrRef.style.display = "none";	
					if (document.getElementById('rIframe')) {
						var IfrRef = document.getElementById('rIframe');	
						IfrRef.style.display = "none";
					}		
				}
			}
		}	
	 }
	 
	ShowDiv("launch_" + this.sName, this.oDiv, bShow);

	if (bShow == true) {
		if (chkBrows('msie') && chkBrows('windows')) { 
			if (chkBrows('opera')) {
			}
			else {
				
					if (this.sName == 'oCalPopD'){		
						var DivRef = document.getElementById('departpop');
						if (document.getElementById('dIframe')) {
							var IfrRef = document.getElementById('dIframe');
						}	
					}
		
				else {
					var DivRef = document.getElementById('returnpop');
					if (document.getElementById('rIframe')) {
						var IfrRef = document.getElementById('rIframe');
					}
				}
				if (IfrRef) { 
					IfrRef.style.width = '147px';
    				IfrRef.style.height = '180px';
    				IfrRef.style.top = DivRef.style.top;
    				IfrRef.style.left = DivRef.style.left;
    				IfrRef.style.zIndex = '98';
    				IfrRef.style.display = "block";	
					}
				}
		
	 }	
	}
	if (this.oCalFw) this.oCalFw.oDiv.style.display = "none";
	if (this.oCalBk) this.oCalBk.oDiv.style.display = "none";
}

oCal_obj.prototype.Init = oCal_obj_Init;
oCal_obj.prototype.DrawCal = oCal_obj_DrawCal;
oCal_obj.prototype.PopM = oCal_obj_PopM;
oCal_obj.prototype.PopD = oCal_obj_PopD;
oCal_obj.prototype.SetM = oCal_obj_SetM;
oCal_obj.prototype.DisM = oCal_obj_DisM;
oCal_obj.prototype.ChgM = oCal_obj_ChgM;
oCal_obj.prototype.ChgD = oCal_obj_ChgD;
oCal_obj.prototype.MoveSelM = oCal_obj_MoveSelM;
oCal_obj.prototype.MoveSelD = oCal_obj_MoveSelD;
oCal_obj.prototype.MoveCalD = oCal_obj_MoveCalD;
oCal_obj.prototype.MoveCalM = oCal_obj_MoveCalM;
oCal_obj.prototype.ShowCal = oCal_obj_ShowCal;
oCal_obj.prototype.iDaysOut = 331;
oCal_obj.prototype.bPrevDate = false;
oCal_obj.prototype.oCalFw = false;
oCal_obj.prototype.oCalBk = false;
oCal_obj.prototype.iTTDays = 0;/////////////////////////////////change to test trip template functionality
oCal_obj.prototype.bIsPopup = false;


//css positioning functions for popups

function oAwCal_obj(sName,sType,aBln,sMYSta,sMYEnd,sMYDis,sMYSel,sDSel) {
	this.sName = sName;
	this.sType = sType;
	this.aBln = aBln;
	var aTemp;
	//start month
	this.dSta = ConvMYStrToDate(sMYSta);
	//end month
	this.dEnd = ConvMYStrToDate(sMYEnd);
	//display month
	this.dDis = ConvMYStrToDate(sMYDis);
	//optional selected date
	this.dSel = false;
	if (sMYSel != "" && sDSel != "" && String(sMYSel) != 'undefined' && String(sDSel) != 'undefined') {
		this.dSel = ConvMYStrToDate(sMYSel + "-" + sDSel);
	}
	var sDiv = this.sType == "depart" ? "calAwDep" : "calAwRet";
	var sSpan = this.sType == "depart" ? "depdate" : "retdate";
	this.oDiv = document.getElementById(sDiv);
	this.oSpan = document.getElementById(sSpan);
}
function oAwCal_ConvM() {
	return this.iM + 1;
}
function oAwCal_Set(i) {
	this.dSel = new Date(this.dDis.getFullYear(),this.dDis.getMonth(),i);
	this.Draw();
	this.oLinkCal.Draw();
}
function oAwCal_Move(bPrev) {
	if(bPrev){
		if (this.dDis.getMonth() == 0) {
		    var year = this.dDis.getFullYear();
		    year = year - 1;
		    var month = 11;
			this.dDis = new Date(year, month, 1);
		} else {
		    var month = this.dDis.getMonth();
		    month = month -1;
		    var day = this.dDis.getDay();
		    var year = this.dDis.getFullYear();
			this.dDis = new Date(year, month, 1);// we dont care about day in this object
		}
	}else{
		if (this.dDis.getMonth() == 11) {
		    var year = this.dDis.getFullYear();
		    year = year + 1;
            var month = 0;
			this.dDis = new Date(year, month, 1);
		} else {
		    var month = this.dDis.getMonth();
		    month = month + 1;
		    var day = this.dDis.getDay();
		    var year = this.dDis.getFullYear();
			this.dDis = new Date(year, month, 1);// we dont care about day in this object
		}
	}
	NextStep(false);
}
function oAwCal_Draw() {

	//test to see whether to show previous link. we only care about months and year
	var bPrev = ((this.dDis.getFullYear() > this.dSta.getFullYear()) || ((this.dDis.getMonth() > this.dSta.getMonth()) && (this.dDis.getFullYear() >= this.dSta.getFullYear())));
	if (this.sType == "return" && this.oLinkCal.dSel) {
		var dComp1 = GetDateMY(this.dDis);
		var dComp2 = GetDateMY(this.oLinkCal.dSel);
		//we cannot go by the actual date object. as it takes into account time also I think as I am getting invalid behavior
		bPrev = bPrev && ((dComp1.getFullYear() > dComp2.getFullYear()) || ((dComp1.getMonth() > dComp2.getMonth()) && (dComp1.getFullYear() >= dComp2.getFullYear())));
	}
	//test to see whether to show next link. compare only month and year. day and time should not affect display of those links
	var bNext = ((this.dDis.getFullYear() < this.dEnd.getFullYear()) || ((this.dDis.getMonth() < this.dEnd.getMonth()) && (this.dDis.getFullYear() <= this.dEnd.getFullYear())));
	if (this.sType == "depart" && this.oLinkCal.dSel) {
		var dComp1 = GetDateMY(this.dDis);
		var dComp2 = GetDateMY(this.oLinkCal.dSel);
		bNext = bNext && ((dComp1.getFullYear() < dComp2.getFullYear()) || ((dComp1.getMonth() < dComp2.getMonth()) && (dComp1.getFullYear() <= dComp2.getFullYear())));
	}

	sW = '';
	sW += '<table cellspacing="0" cellpadding="0" border="0" class="cMeHdr">';
	sW += '<tr class="top">';

	sW += '<td class="alt"><span class="sm">';
	sW += !bPrev ? '&nbsp;' : '<a href="javascript:' + this.sName + '.Move(true);">Previous</a>';
	sW += '</span></td>';

	sW += '<td class="actr"><div class="date">';
	sW += this.aMthFull[this.dDis.getMonth()] + ", " + this.dDis.getFullYear();
	sW += '</div></td>';

	sW += '<td class="art"><span class="sm">';
	sW += !bNext ? '&nbsp;' : '<a href="javascript:' + this.sName + '.Move(false);">Next</a>';
	sW += '</span></td>';

	sW += '</tr>';
	sW += '</table>';

	sW += '<table cellpadding="0" cellspacing="0" border="0" class="cMe">';

	sW += '<tr class="hdr">';
	for (var i = 0; i < this.aDayAbbr.length; i++) {
		sW += '<td>' + this.aDayAbbr[i] + '</td>';
	}
	sW += '</tr>';

	var aDates = GetArrD(this.dDis.getMonth(),this.dDis.getFullYear());
	var aDofWs = GetArrDofW(this.dDis.getMonth(),this.dDis.getFullYear())

	var iDateThis = 1;
	var iDofWThis = 0;
	var i = 0;
	var iD = 42;
	var iDSel = this.dSel ? this.dSel.getDate() : 0;

	//actual dates
	sW += '\n<tr>';
	while (iD > 0 || i < aDates.length) {
		sW += iDofWThis == 0 ? '\n<td class="one">' : '\n<td>';
		if (iDofWThis == aDofWs[i]) {
			var bActive = aDates[i] == iDSel;

			var bLink;
			if (this.sType == "depart") {
				bLink = this.oLinkCal.dSel ? this.oLinkCal.dSel.valueOf() >= this.dDis.setDate(aDates[i]) : true;
			} else {
				bLink = this.oLinkCal.dSel ? this.oLinkCal.dSel.valueOf() <= this.dDis.setDate(aDates[i]) : true;
			}

			//active / avail / unavail / blnk
			var bAvail = eval(this.aBln[i]);
			var sClass = bActive ? 'active' : bAvail ? 'avail' : 'unavail';
			sW += '<div class="' + sClass+ '">';
			if (bAvail && bLink && !bActive) sW += '<a href="javascript:' + this.sName + '.Set(' + aDates[i] + ');">';
			sW += aDates[i];
			if (bAvail && bLink && !bActive) sW += '</a>';
			sW += '</div>';
			iDateThis++
			i++;
		} else {
			sW += '<div class="blnk">&nbsp;</div>';
		}
		sW += '</td>';
		if (iDofWThis == 6) {
			sW += '\n</tr>\n<tr>';
			iDofWThis = 0;
		} else {
			iDofWThis++;
		}
		iD--;
	}
	sW += '\n</tr>';
	sW += '\n</table>';
	
	this.oDiv.innerHTML = sW;
	//now show selected @ bottom of page
	sW = '';
	sW += !this.dSel
		? '<b>[not yet selected]</b>'
		: this.aDayAbbr[this.dSel.getDay()] + ', ' + this.aMthFull[this.dSel.getMonth()] + ' ' + this.dSel.getDate() + ', ' + this.dSel.getFullYear();
	;
	this.oSpan.innerHTML = sW;
}

//properties


//these are set in ff_dates_jp.js
//oAwCal_obj.prototype.aMthFull = ['January','February','March','April','May','June','July','August','September','October','November','December'];
//oAwCal_obj.prototype.aMthAbbr = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
//oAwCal_obj.prototype.aDayAbbr = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];

//oAwCal_obj.prototype.aMthFull = ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'];
//oAwCal_obj.prototype.aMthAbbr = ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'];
//oAwCal_obj.prototype.aDayAbbr = ['日','月','火','水','木','金','土'];




//methods
oAwCal_obj.prototype.ConvM = oAwCal_ConvM;
oAwCal_obj.prototype.Draw = oAwCal_Draw;
oAwCal_obj.prototype.Move = oAwCal_Move;
oAwCal_obj.prototype.Set = oAwCal_Set;

//submit function
function NextStep(bFinal) {
	//grab form reference
	var oF = document.getElementById(oD.sFormID);
	//stuff selected departure date, if any, into hidden form fields
	if (oD.dSel) {
		oF.seldepMY.value = ConvDateToMYStr(oD.dSel);
		oF.seldepD.value = ConvDateToDStr(oD.dSel);
	}
	//stuff selected return date, if any, into hidden form fields
	if (oR.dSel) {
		oF.selretMY.value = ConvDateToMYStr(oR.dSel);
		oF.selretD.value = ConvDateToDStr(oR.dSel);
	}
	if (!bFinal) {
		//if just switching months, set form action, stuff display months into hidden form fields, and submit
		oF.action = oD.sChgMthURL;
		oF.disdepMY.value = ConvDateToMYStr(oD.dDis);
		oF.disretMY.value = ConvDateToMYStr(oR.dDis);
		oF.waiting.value = 'true';
		oF.submit();
	} else {
		//otherwise, make sure both dates selected and then either submit or display an error alert
		if (oD.dSel && oR.dSel) {
			oF.action = oD.sSubmitURL;
			oF.waiting.value = 'true';
			oF.submit();
		} else {
			alert(oD.sErrMsg);
		}
	}
}

/* date and calendar utility functions */

function GetObjFromArrByVal(aObj,uVal,sProp) {
	var oRet = false;
	for (var i = 0; i < aObj.length; i++) {
		if (aObj[i][sProp] == uVal) {
			oRet = aObj[i];
			break;
		}
	}
	return oRet;
}
function GetArrIndByVal(aArr,uVal) {
	var iRet = -1
	for (var i = 0; i < aArr.length; i++) {
		if (aArr[i] == uVal) {
			iRet = i;
			break;
		}
	}
	return iRet;
}
function GetSelIndByVal(oSel,uVal) {
	var aArr = [];
	for (var i = 0; i < oSel.options.length; i++) { aArr[i] = oSel.options[i].value; }
	return GetArrIndByVal(aArr,uVal);
}
function GetDinM(iM,iY) {
	//takes actual number of month and returns number of days
	var a = [31,28,31,30,31,30,31,31,30,31,30,31];
	if (iY % 4 == 0) a[1] = 29;
	return a[iM];
}
function AddDays(dD,iDays) {
	/*
	1000 = 1 second
	60000 = 1 minute
	3600000 = 1 hour
	86400000 = 1 day
	*/
	var sD = dD.toString();
	var iD = Date.parse(sD);
	iD += (86400000 * iDays);
	return new Date(iD);
}
function GetArrM(iStaM,iStaY,iEndM,iEndY) {
	var a = [];
	var iM = iStaM;
	var iY = iStaY;
	var dEnd = new Date(iEndY,iEndM);
	var dNow = new Date(iY,iM);
	while (dEnd.valueOf() >= dNow.valueOf()) {
		a[a.length] = iM;
		if (iM == 11) {
			iY++;
			iM = 0;
		} else {
			iM++;
		}
		dNow = new Date(iY,iM);
	}
	return a;
}
function GetArrD(iM,iY) {
	var a = [];
	for (var i = 1; i <= GetDinM(iM,iY); i++) {
		a[a.length] = i;
	}
	return a;
}
function GetArrDBln(iM,iY,iSta,iEnd) {
	var a = [];
	for (var i = 1; i <= GetDinM(iM,iY); i++) {
		a[a.length] = iEnd && i > iEnd ? false : iSta && i < iSta ? false : true;
	}
	return a;
}
function GetArrDofW(iM,iY) {
	var a = [];
	for (var i = 1; i <= GetDinM(iM,iY); i++) {
		a[a.length] = new Date(iY,iM,i).getDay();
	}
	return a;
}
function SetDt(aYMD) {
	var oD = new Date();
	oD.setFullYear(aYMD[0]);
	oD.setMonth(aYMD[1]);
	oD.setDate(aYMD[2]);
	return oD;
}
function CompMsFlex(iM1,iY1,sSign,iM2,iY2) {
	var iD1 = new Date(iY1,iM1);
	var iD2 = new Date(iY2,iM2);
	var sEval = "iD1.valueOf() " + sSign + " iD2.valueOf()";
	return eval(sEval);
}
function CompMs(iM1,iY1,iM2,iY2) {
	var iD1 = new Date(iY1,iM1);
	var iD2 = new Date(iY2,iM2);
	return iD2.valueOf() > iD1.valueOf();
}
function CompDs(iD1,iM1,iY1,iD2,iM2,iY2) {
	var iD1 = new Date(iY1,iM1,iD1).valueOf();
	var iD2 = new Date(iY2,iM2,iD2).valueOf();
	return iD2 > iD1
}
function FmtDtArr(sYM,sD) {
	return [Number(sYM.substr(0,4)), TransMFrom(sYM.substr(5,2)),Number(sD)];
}
function FmtTwoDigits(inp) {
	var sRet = String(inp);
	return sRet.length == 1 ? "0" + sRet : sRet;
}
function TransMTo(inp) {
	inp = Number(inp);
	inp++;
	return FmtTwoDigits(inp);
}
function TransMFrom(inp) {
	inp = Number(inp);
	inp--;
	return inp;
}
function GetDateMY(d,iM) {
	if (String(iM) == 'undefined') iM = 0;
	var dR = new Date(d.getFullYear(),d.getMonth());
	if (iM < 0) dR.DecrMth();
	if (iM > 0) dR.IncrMth();
	return dR;
}
function ConvMYStrToDate(s) {
	var aR = s.split("-");
	for (var i = 0; i < aR.length; i++) {
		i == 1 ?
			aR[i] = TransMFrom(aR[i]) /*convert 1-based month strung to 0-based number*/
			: aR[i] = Number(aR[i]) /*convert year and date strings to numbers*/
		;
	}
	var dR = new Date(aR[0],aR[1]);
	if (aR.length > 2) dR.setDate(aR[2]);
	return dR;
}
function ConvDateToMYStr(d) {
	return String(d.getFullYear() + "-" + (TransMTo(d.getMonth())));
}
function ConvDateToDStr(d) {
	return String(FmtTwoDigits(d.getDate()));
}

//JS API

function array_indexof(inp) {
	var iRet = -1;
	for (var i = 0; i < this.length; i++) {
		if (this[i] == inp) {
			iRet = i;
			break;
		}
	}
	return iRet;
}
function array_lastindexof(inp) {
	var iRet = -1;
	for (var i = 0; i < this.length; i++) {
		if (this[i] == inp) {
			iRet = i;
		}
	}
	return iRet;
}
function array_firstindexof(inp) {
	var iRet = -1;
	for (var i = 0; i < this.length; i++) {
		if (this[i] == inp) {
			iRet = i;
			break
		}
	}
	return iRet;
}
function array_indexofdate(inp) {
	var iRet = -1;
	for (var i = 0; i < this.length; i++) {
		if (this[i].valueOf() == inp.valueOf()) {
			iRet = i;
			break;
		}
	}
	return iRet;
}
function array_indexofdateprop(inp,sProp) {
	var iRet = -1;
	for (var i = 0; i < this.length; i++) {
		var o = this[i];
		if (o[sProp].valueOf() == inp.valueOf()) {
			iRet = i;
			break;
		}
	}
	return iRet;
}
Array.prototype.indexOf = array_indexof;
Array.prototype.lastIndexOf = array_lastindexof;
Array.prototype.firstIndexOf = array_firstindexof;
Array.prototype.indexOfDate = array_indexofdate;
Array.prototype.indexOfDateProp = array_indexofdateprop;

function Date_DecrMth() {
	if (this.getMonth() == 0) {
		this.setMonth(11);
		this.setFullYear(this.getFullYear() - 1);
	} else {
		this.setMonth(this.getMonth() - 1);
	}
}
function Date_IncrMth() {
	if (this.getMonth() == 11) {
		this.setMonth(0);
		this.setFullYear(this.getFullYear() + 1);
	} else {
		this.setMonth(this.getMonth() + 1);
	}
}

Date.prototype.DecrMth = Date_DecrMth;
Date.prototype.IncrMth = Date_IncrMth;
