<!--
floatX=10;
floatY=0;
layerwidth=800;
layerheight=130;
align="left";
valign="top";
delayspeed=4;

// This script is copyright (c) Henrik Petersen, NetKontoret
// Feel free to use this script on your own pages as long as you do not change it.
// It is illegal to distribute the script as part of a tutorial / script archive.
// Updated version available at: http://www.echoecho.com/toolfloatinglayer.htm
// This comment and the 4 lines above may not be removed from the code.

NS6=false;
IE4=(document.all);
if (!IE4) {NS6=(document.getElementById);}
NS4=(document.layers);

function adjust() {
if ((NS4) || (NS6)) {
layerwidth = window.innerWidth;	// 06/15/02 LDG...sorry Henrik, had to modify.
if (lastX==-1 || delayspeed==0)
{
lastX=window.pageXOffset + floatX;
lastY=window.pageYOffset + floatY;
}
else
{
dx=Math.abs(window.pageXOffset+floatX-lastX);
dy=Math.abs(window.pageYOffset+floatY-lastY);
d=Math.sqrt(dx*dx+dy*dy);
c=Math.round(d/10);
if (window.pageXOffset+floatX>lastX) {lastX=lastX+delayspeed+c;}
if (window.pageXOffset+floatX<lastX) {lastX=lastX-delayspeed-c;}
if (window.pageYOffset+floatY>lastY) {lastY=lastY+delayspeed+c;}
if (window.pageYOffset+floatY<lastY) {lastY=lastY-delayspeed-c;}
}
if (NS4){
document.layers['floatlayer'].pageX = lastX;
document.layers['floatlayer'].pageY = lastY;
}
if (NS6){
document.getElementById('floatlayer').style.left=lastX;
document.getElementById('floatlayer').style.top=lastY;
}
}
else if (IE4){
if (lastX==-1 || delayspeed==0)
{
lastX=document.body.scrollLeft + floatX;
lastY=document.body.scrollTop + floatY;
}
else
{
dx=Math.abs(document.body.scrollLeft+floatX-lastX);
dy=Math.abs(document.body.scrollTop+floatY-lastY);
d=Math.sqrt(dx*dx+dy*dy);
c=Math.round(d/10);
if (document.body.scrollLeft+floatX>lastX) {lastX=lastX+delayspeed+c;}
if (document.body.scrollLeft+floatX<lastX) {lastX=lastX-delayspeed-c;}
if (document.body.scrollTop+floatY>lastY) {lastY=lastY+delayspeed+c;}
if (document.body.scrollTop+floatY<lastY) {lastY=lastY-delayspeed-c;}
}
document.all['floatlayer'].style.posLeft = lastX;
document.all['floatlayer'].style.posTop = lastY;
} 
setTimeout('adjust()',50);
}

function define()
{
if ((NS4) || (NS6)) 
{ 
if (align=="left") {floatX=ifloatX};
if (align=="right") {floatX=window.innerWidth-ifloatX-layerwidth-20};
if (align=="center") {floatX=Math.round((window.innerWidth-20)/2)-Math.round(layerwidth/2)};
if (valign=="top") {floatY=ifloatY};
if (valign=="bottom") {floatY=window.innerHeight-ifloatY-layerheight};
if (valign=="center") {floatY=Math.round((window.innerHeight-20)/2)-Math.round(layerheight/2)};
}
if (IE4) 
{
if (align=="left") {floatX=ifloatX};
if (align=="right") {floatX=document.body.offsetWidth-ifloatX-layerwidth-20}
if (align=="center") {floatX=Math.round((document.body.offsetWidth-20)/2)-Math.round(layerwidth/2)}
if (valign=="top") {floatY=ifloatY};
if (valign=="bottom") {floatY=document.body.offsetHeight-ifloatY-layerheight}
if (valign=="center") {floatY=Math.round((document.body.offsetHeight-20)/2)-Math.round(layerheight/2)}
}
}

//==========================================================
// This script is copyright (c) Henrik Petersen, NetKontoret
//=====================  E N D  O F  =======================
//========  The rest is our code... put in here ============
//========  because this is a common included   ============
//========  js file                             ============
//=====================  E N D  O F  =======================

// 04/22/05 GHS < BEGIN
function showHotDealSearchCalendar( layerName ) {
    /*07/19/06 DODD < START - Fix to work in Firefox as well
	var x = (window.event.clientX - layerwidth - 20);	// 19 is the width of the calendar icon: bt_cal.gif
	var y = (window.event.clientY - (layerheight/2));
	//Proper positioning of the calendar.
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		scrOfY = window.pageYOffset; scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		scrOfY = document.body.scrollTop; scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		scrOfY = document.documentElement.scrollTop; scrOfX = document.documentElement.scrollLeft;
	}
	x += scrOfX;
	y += scrOfY;
    */

    var x, y;
	var lobj = eval( layerName );
	var txtTargetName;
	var calendar, basedOn, basedOn2;
	//alert( layerName );
	if (layerName == "floatlayer") {
		calendar = FIND("CalendarIFRAME1");
		txtTargetName = g_ControlContainerID + "HotDealsSearch1_txtDepartureDate";
		basedOn = FIND(g_ControlContainerID + "HotDealsSearch1_txtDepartureDate");
		basedOn2 = FIND(g_ControlContainerID + "HotDealsSearch1_txtDepartureDate");
	}
	if (layerName == "floatlayer2") {
		calendar = FIND("CalendarIFRAME2");
		txtTargetName = g_ControlContainerID + "HotDealsSearch1_txtDepartureDateHigh";
		basedOn = FIND(g_ControlContainerID + "HotDealsSearch1_txtDepartureDateHigh");
		basedOn2 = FIND(g_ControlContainerID + "HotDealsSearch1_txtDepartureDateHigh");
	} 
	
	var eL=0;var eT=0;
	eP = FIND( txtTargetName );
	eF = eP;
    for(var p=eP; p&&p.tagName!='BODY'; p=p.offsetParent){
      eL+=p.offsetLeft;
      eT+=p.offsetTop;
    }
    var eH=eP.offsetHeight;
    var dH=eF.style.pixelHeight;
    var sT=document.body.scrollTop;
    x=eL;
    if(eT-dH >= sT && eT+eH+dH > document.body.clientHeight+sT)
      y=eT-dH;
    else
      y=eT+eH;
      
	if (lobj.style.display == "none") {
		if ((calendar == "[object]") || (calendar == "[object HTMLIFrameElement]")) {
			var fixedSrc = fixSourceForVAXCalendar(calendar.src, basedOn, basedOn2);
			//alert( calendar.src + "\n=================\n" + fixedSrc);
			calendar.src = fixedSrc;	// This should reload the calendar page to the appropriate date.
		}
		lobj.style.display = "block";
		if (layerName == "floatlayer") {
			floatX = x;
			floatY = y;
		} 
		/* 11/09/05 JSJ > START: Removed this... we only need to do this for the first float layer, otherwise there are display problems
		if (layerName == "floatlayer2") {
			floatX = x;
			floatY = y;
		} 11/09/05 JSJ > END		  
		*/
		lobj.style.left = x;
		lobj.style.top = y;
	} else {
		lobj.style.display = "none";
	}
}

// 10/21/05 JSJ > START: adding a new fixSource that will reformat the input string for the new VAXCalendar
function fixSourceForVAXCalendar(sourceString, basedOn, basedOn2){	
	var defaultDate = ""
	
	// Try to find a default date from the basedOns
	if (basedOn != null) {
		defaultDate = basedOn.value;
		
		// if the first based wasn't a value try the second basedOn
		if (trim(defaultDate) == "" && basedOn2 != null && basedOn2.value != "") {	
			defaultDate = basedOn2.value;
		}
		
		// Add an extra "0" back since isDate removes it
		if (defaultDate != "" && defaultDate.length < 7){
			defaultDate = "0" + defaultDate
		}		
	}
		
	// These are the querystring keys that the VAXCalendar will be expecting
	var LOW_DATES_KEY    = "LowDates=";
	var HIGH_DATES_KEY   = "HighDates=";
	var DOW_MASKS_KEY    = "DOWMasks=";
	var DEFAULT_DATE_KEY = "DefaultDate=";
	var ACTIONAFTERSELECT_KEY = "ClientScriptToExecute="
	var CONTROL2POPULATE_KEY  = "ControlToPopulate="
		
	// These are the old values that may still be in use, that should be replaced with the new values
	var OLD_LOW_DATE_KEY        = "lo=";
	var OLD_HIGH_DATE_KEY       = "hi=";
	var OLD_DOW_MASK_KEY        = "DOW=";
	var OLD_DEFAULT_DATE_KEY    = "inDate=";
	var OLD_ADJUSTACCOMDATE_KEY = "adjustAccomDate=";
	var OLD_ACTIONAFTERSELECT_KEY = "AlsoReplyNewDate="
	var OLD_CONTROL2POPULATE_KEY  = "targetDate="
	
	// Get the page source ie "VAXCalendar.aspx?"
	var source = sourceString.substring(0, sourceString.indexOf("?") + 1);
	
	// Get the querystring variables after the source string
	var querystring = sourceString.substring(sourceString.indexOf("?") + 1);
		
	// Split up the query string and parse for the calendar input variables
	var stringTokens= querystring.split("&");  
	var foundDefaultDate = false;
	for (var x=0; x < stringTokens.length; x++){
		// if the current querystring token has any of these old variable names, replace it with the new variable name
		stringTokens[x] = reformatVariableName(stringTokens[x], OLD_LOW_DATE_KEY, LOW_DATES_KEY);		
		stringTokens[x] = reformatVariableName(stringTokens[x], OLD_HIGH_DATE_KEY, HIGH_DATES_KEY);
		stringTokens[x] = reformatVariableName(stringTokens[x], OLD_DOW_MASK_KEY, DOW_MASKS_KEY);		
		stringTokens[x] = reformatVariableName(stringTokens[x], OLD_ACTIONAFTERSELECT_KEY, ACTIONAFTERSELECT_KEY);
		
		/*** Special Refomating cases ***/
		// Try to match the adjustAccomdate value 
		if (stringTokens[x].toUpperCase().indexOf(OLD_ADJUSTACCOMDATE_KEY.toUpperCase()) == 0) 
		{
			foundDefaultDate = true; 
			
			var reformattedDate = reformatDateFromYYMMDD(stringTokens[x].substring(OLD_ADJUSTACCOMDATE_KEY.length + 1));
			if (reformattedDate != null) 
			{
				stringTokens[x] = DEFAULT_DATE_KEY + reformattedDate;
			}
			else {
				stringTokens[x] = reformatVariableName(stringTokens[x], OLD_ADJUSTACCOMDATE_KEY, DEFAULT_DATE_KEY);
			}
		}	
				
		// Try to match the default date query string variable
		else if( (stringTokens[x].toUpperCase().indexOf(OLD_DEFAULT_DATE_KEY.toUpperCase()) == 0) ||
				 (stringTokens[x].toUpperCase().indexOf(DEFAULT_DATE_KEY.toUpperCase()) == 0) )
		{
			foundDefaultDate = true;
			if (defaultDate != "") {
				stringTokens[x] = DEFAULT_DATE_KEY + defaultDate;			
			}
			else {
				stringTokens[x] = reformatVariableName(stringTokens[x], OLD_DEFAULT_DATE_KEY, DEFAULT_DATE_KEY);		
			}
		}		
		
		// Try to find the control to populate variable
		else if(stringTokens[x].toUpperCase().indexOf(OLD_CONTROL2POPULATE_KEY.toUpperCase()) == 0) {
			stringTokens[x] = stringTokens[x].replace(OLD_CONTROL2POPULATE_KEY, CONTROL2POPULATE_KEY);
			
			// If the control ends with a ".value" then trim that part off, the VAXCalendar will adds that part already
			var searchString = ".value"
			var tokenLength = stringTokens[x].length
			
			// Look at the last 6 characters of the token ad see if they are equal to ".value"
			if (tokenLength > searchString.length && stringTokens[x].substring(tokenLength - searchString.length) == searchString) {
				stringTokens[x] = stringTokens[x].substring(0, tokenLength - searchString.length)
			}// if			
		}// else if		
	} // for
	
	// Add a default date if it was not passed in the querystring
	if (!foundDefaultDate && defaultDate != "") {
		stringTokens[stringTokens.length] = DEFAULT_DATE_KEY + defaultDate;		
	}
	
	// Return the source string plus the rejoined and reformatted querystring
	return  source + (stringTokens.join("&") );
}

// 10/21/05 JSJ > START: Added this function to check if the given oldVariableName is at the beginning of the given
//						 inString.  If so, this function returns the oldVariableName replaced with the newVariableName
//						 otherwise it returns the original string
function reformatVariableName(inString, oldVariableName, newVariableName) {
	// Try to find the old variable at the begining of the string and replace it if found
	if(inString.toUpperCase().indexOf(oldVariableName.toUpperCase()) == 0) {
		return inString.replace(oldVariableName, newVariableName);
	}	
	// Otherwise return the string.
	return inString;
}

function reformatDateFromYYMMDD(inDateStr){
// Pad any date values that are less than 6 characters long since leading zeros are cut off
	if (inDateStr.length < 6) {
		inDateStr = "0" + inDateStr;
	}
	
	// Check to see if this is numeric, MiniSearchControls are passing in the date in YYMMDD format
	// and it should be in DDMMMYY format
	if (!isNaN(inDateStr))  {
		var year = parseInt("20" + inDateStr.substring(0, 2));
		var month = parseInt(inDateStr.substring(2, 4) - 1);
		var day = parseInt(inDateStr.substring(4, 6));
		var date = new Date(year, month, day);
		
		return ConvertDateTo_ddmmmyyyy(date);
	}
	else {
		return null;
	}
}
// 10/21/05 JSJ > END


// 10/21/05 JSJ > START > use the new fixSourceForVAXCalendar() function above instead of the old fix source
function fixSrc( inSrcStr, basedOnField, basedOnField2) {
	return fixSourceForVAXCalendar(inSrcStr, basedOnField, basedOnField2);	
}
// 10/21/05 JSJ > END

/*========== Usage ===================
<script language="JavaScript">
if (NS4) {document.write('<LAYER NAME="floatlayer" LEFT="'+floatX+'" TOP="'+floatY+'">');}
if ((IE4) || (NS6)) {document.write('<div id="floatlayer" style="position:absolute; left:'+floatX+'; top:'+floatY+';">');}
</script>

*** Put your html here.

<script language="JavaScript">
if (NS4) {
document.write('</LAYER>');
}
if ((IE4) || (NS6)) {
document.write('</DIV>');
}
ifloatX=floatX;
ifloatY=floatY;
define();
window.onresize=define;
lastX=-1;
lastY=-1;
adjust();
</script>

//==================================== */
// -->