// Displayed Savings Pop-Up v.2
if (expDS === undefined) {
	var expDS = {
		dsHeaderCopy:'When you need a flight and a hotel,',
		dsCopy:'<div class="ds-middle-top-copy-header">book both at the same time and you can save up to $450* per trip.</div><div class="ds-middle-top-copy">See for yourself now!</div>',
		dsCTALinkLabel:'Try it and see!',
		dsCTALinkRfrr:-856790,
		dsCTALink:'/daily/packages/default.asp',
		dsCTACopy:'Build your "Flight + Hotel" trip now',
		dsCTACopyPromo:'How much will YOU save?',
		dsCTAClassName:'ds-cta-copy',
		dsCTAPromoClassName:'ds-cta-copy-promo',
		dsHasCTALink:true,
		dsDDLIntroCopy:'Check out the deals other customers have found:',
		dsDDLLabelCopy:'See samples from:',
		tripLinkCopy:'See current trip details',
		tripLinkDisplay:true,
		tripLinkRfrr:-856789,
		dsLegalCopy1:'*Savings based on all vacation package bookings with Flight + Hotel on Expedia.com in 2009, as compared to price of the same components booked separately. Savings will vary based on origin/destination, length of trip, stay dates and selected travel supplier(s). Savings not available on all packages.',
		dsLegalCopy2:'** Sample savings based on Flight+Hotel packages found by Expedia customers. Subject to availability.',
		dsXMLFile:'/daily/prod/displayedsavings/data/shoppedv2.xml?r='+Math.random(),
		hoursOldLimit:730,
		isDynamic:true,
		xmlHttpRequest:null,
		isDataLoaded:false,
		arrSavingsDDL:[],
		arrSavingsDDLLoaded:false,
		arrSavingsKnownOrigin:[],	
		arrSavingsUnKnownOrigin:[],
		soapRequestURL:'/daily/pricecheck/pricecheck.asmx',
		soapRequest:null,	
		userOriginDma:null,		
		userOriginTla:[],
		matchedTla:null,
		userOriginTlaLoaded:false,
		coords:{popupX:0, popupY:0, arrowX:0, arrowY:0, clickX:0, clickY:0},        
		triggerElement:null,
		popupDiv:null,
		popupDivPaddingVert:50,
		popupDivPaddingHoriz:5,
		shadowPadding:45,
		cornerHeight:14,		
        popupIFrame:null,
		arrowDiv:null,
        isIE:(/\w*MSIE\w*/).test(navigator.appVersion),
		previousDivHeight:0,
		isInited:false,
		prevEventObj:null,
		init:function()
		{
			//this.preloadDSImages();
            this.checkFTLA();
            this.createDiv();
            this.createIF();				
			this.createArrow();
			this.isInited = true;
		},		
        showDS:function(el,event)
        {
			var currentEventObj = (event.target)?event.target:event.srcElement;
			//alert(currentEventObj.tagName);
			if (currentEventObj != this.previousEventObj)
			{
				this.previousEventObj = currentEventObj;
			}
			else
			{
				if (this.popupDiv.style.display == 'block')
				{
					this.hideDS();
					return;
				}
			}

			(typeof el == 'string')?el = document.getElementById(el):el = el;

			this.coords.clickX = event.clientX;
			this.coords.clickY = event.clientY + this.getScrollHeight();

			if (!this.isInited)
			{
				this.init();
			}
            this.triggerElement = el;            
            this.show();
        },	
        hideDS:function()
        {   
            if (this.popupDiv != null)this.popupDiv.style.display = 'none';
            if (this.popupIFrame != null && this.isIE ) this.popupIFrame.style.display = 'none';
			this.hideArrow();
        },
        show:function()
        {       
			this.setCoords();      			
			this.showArrow();
            var _top = this.coords.popupY + 'px';
            var _left = this.coords.popupX + 'px';						
            
            this.popupDiv.style.top = _top;
            this.popupDiv.style.left = _left;		
			this.popupDiv.style.visibility ='hidden';
            this.popupDiv.style.display = 'block';	
            
            if (this.isIE)
            {
                this.popupIFrame.style.width = this.popupDiv.offsetWidth+'px';
                this.popupIFrame.style.height = this.popupDiv.offsetHeight+'px';
                this.popupIFrame.style.top = _top;            
                this.popupIFrame.style.left = _left;
                this.popupIFrame.style.display = 'block';
            }

            this.check();
		
			this.popupDiv.style.visibility ='visible';
			
			if (this.isDynamic && !this.isDataLoaded)
			{
				this.getDmaFromCookie();
				this.loadXML(); //asynchronous call
				this.isDataLoaded=true;
			}			
        },	
		preloadDSImages:function()
		{
			if (document.images)
			{
			  var preload_image_object = new Image();
			  var image_url = new Array();
			  image_url[0] = 'http://media.expedia.com/media/content/expus/graphics/common/corners/DISPLAYEDSAVINGSv1_LT_yellow.png';
			  image_url[1] = 'http://media.expedia.com/media/content/expus/graphics/common/corners/DISPLAYEDSAVINGSv1_LB_yellow.png';
			  image_url[2] = 'http://media.expedia.com/media/content/expus/graphics/common/corners/DISPLAYEDSAVINGSv1_TL_yellow.png';
			  image_url[3] = 'http://media.expedia.com/media/content/expus/graphics/common/corners/DISPLAYEDSAVINGSv1_TC_yellow.png';
			  image_url[4] = 'http://media.expedia.com/media/content/expus/graphics/common/corners/DISPLAYEDSAVINGSv1_TR_yellow.png';
			  image_url[5] = 'http://media.expedia.com/media/content/expus/graphics/common/corners/displayedsavings_close_yellow.png';
			  image_url[6] = 'http://media.expedia.com/media/content/expus/graphics/common/corners/DISPLAYEDSAVINGSv1_MML_yellow.png';
			  image_url[7] = 'http://media.expedia.com/media/content/expus/graphics/common/corners/DISPLAYEDSAVINGSv1_MMC_yellow.png';
			  image_url[8] = 'http://media.expedia.com/media/content/expus/graphics/common/corners/DISPLAYEDSAVINGSv1_MMR_yellow.png';
			  image_url[9] = 'http://media.expedia.com/media/content/expus/graphics/common/corners/ds-scrollpane-header-bg_yellow.gif';
			  image_url[10] = 'http://media.expedia.com/media/content/expus/graphics/common/corners/ds-scrollpane-bg_yellow.gif';
			  image_url[11] = 'http://media.expedia.com/media/content/expus/graphics/common/corners/ds-scrollpane-row-separator_yellow.gif';
			  image_url[12] = 'http://media.expedia.com/media/content/expus/graphics/common/corners/ds-scrollpane-footer-bg_yellow.gif';
			  image_url[13] = 'http://media.expedia.com/media/content/expus/graphics/icons/box-arrow-blue13x13.gif';
			  image_url[14] = 'http://media.expedia.com/media/content/expus/graphics/common/corners/DISPLAYEDSAVINGSv1_BL_yellow.png';
			  image_url[15] = 'http://media.expedia.com/media/content/expus/graphics/common/corners/DISPLAYEDSAVINGSv1_BC_yellow.png';
			  image_url[16] = 'http://media.expedia.com/media/content/expus/graphics/common/corners/DISPLAYEDSAVINGSv1_BR_yellow.png';
			  image_url[17] = 'http://media.expedia.com/media/content/expus/graphics/common/corners/DISPLAYEDSAVINGSv1_RT_yellow.png';
			  image_url[18] = 'http://media.expedia.com/media/content/expus/graphics/common/corners/DISPLAYEDSAVINGSv1_RM_yellow.png';
			  image_url[19] = 'http://media.expedia.com/media/content/expus/graphics/common/corners/DISPLAYEDSAVINGSv1_RB_yellow.png';
			  image_url[20] = 'http://media.expedia.com/media/content/expus/graphics/common/arrows/displayedsavings_arrow_l_yellow.png';
			  image_url[21] = 'http://media.expedia.com/media/content/expus/graphics/common/arrows/displayedsavings_arrow_r_yellow.png';

			   var i = 0;
			   for(i=0; i<=21; i++) 
			   {
				 preload_image_object.src = image_url[i];
			   }
			}
		},
        createDiv:function()
        {            
            if(this.popupDiv == null)
            {
                this.popupDiv = document.createElement('div');
                this.popupDiv.id = 'ds-div';
            	this.popupDiv.innerHTML = this.createContent();				
                this.popupDiv.style.zIndex = '9990';
                this.popupDiv.style.display = 'none';
                this.popupDiv.style.position= 'absolute';                
                document.body.appendChild(this.popupDiv);
            }
        },
        createIF:function()
        {
            if(this.isIE && this.popupIFrame == null)
            {
                this.popupIFrame = document.createElement('iframe');
                this.popupIFrame.id='ds-if';
                this.popupIFrame.src='';
                this.popupIFrame.style.zIndex='9989';
                this.popupIFrame.style.display='none';
                this.popupIFrame.style.position='absolute';
                this.popupIFrame.style.top = 0;
                this.popupIFrame.style.left = 0;
                this.popupIFrame.frameBorder=0;
                this.popupIFrame.style.filter='progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
                document.body.appendChild(this.popupIFrame);			
            }
        },
		createArrow:function()
		{			
            if(this.arrowDiv == null)
            {
                this.arrowDiv = document.createElement('div');
                this.arrowDiv.id = 'ds-arw';
				this.arrowDiv.className = 'ds-arwL';
				this.arrowDiv.innerHTML = '&nbsp;';
                this.arrowDiv.style.position= 'absolute'; 								
                this.arrowDiv.style.zIndex = '10000';
                this.arrowDiv.style.display = 'none';              
                document.body.appendChild(this.arrowDiv);
            }						
		},        
		createContent:function()
        { 
			if (this.dsHasCTALink)
			{
				this.dsCTAClassName='ds-cta-copy-link';
				this.dsCTAPromoClassName='ds-cta-copy-promo-link';
			}		
            return [
					'<div id="ds-wrapper">',
						'<div id="ds-left">',
							'<div id="ds-left-top">&nbsp;</div>',
							'<div id="ds-left-middle">&nbsp;</div>',
							'<div id="ds-left-bottom">&nbsp;</div>',
						'</div>',
						'<div id="ds-middle">',
							'<div id="ds-middle-top">',
								'<div id="ds-middle-top-left">&nbsp;</div>',
								'<div id="ds-middle-top-center">&nbsp;</div>',
								'<div id="ds-middle-top-right">&nbsp;</div>',
							'</div>',
							'<div id="ds-middle-top-copy">',
								'<div id="ds-middle-top-copy-header">',
									'<div id="ds-middle-top-copy-header-content">',
										this.dsHeaderCopy,
									'</div>',
									'<div id="ds-middle-top-copy-header-close" onclick="expDS.hideDS();">&nbsp;</div>',
								'</div>',
								'<div class="dsclearer"></div>',
								'<div id="ds-middle-top-copy-content">',
									this.dsCopy,
								'</div>',
							'</div>',
							'<div id="ds-middle-middle">',
								'<div id="ds-middle-middle-left">&nbsp;</div>',
								'<div id="ds-middle-middle-center">&nbsp;</div>',
								'<div id="ds-middle-middle-right">&nbsp;</div>',
							'</div>',
							'<div class="dsclearer"></div>',
							'<div id="ds-middle-bottom-savings-module">',
								'<div id="ds-ddl-origin-wrapper">',
									'<div id="ds-ddl-intro-copy">',
										this.dsDDLIntroCopy,
									'</div>',
									'<div id="ds-ddl-label-copy">',
										this.dsDDLLabelCopy,
									'</div>',
									'<div id="ds-ddl-object">',
										'<select id="ds-ddl-origin" onchange="expDS.setOrigin(this.value);">',
											'<option>Please select your home airport</option>',
										'</select>',
									'</div>',
								'</div>',
								'<div id="ds-scroll-pane-header">',
								'</div>',
								'<div id="ds-scroll-pane-wrapper">',
									'<div id="ds-scroll-pane">',
									'</div>',
								'</div>',
								'<div id="ds-scroll-pane-footer">',
								'</div>',
								'<div id="ds-cta">',
									'<div class="' + this.dsCTAPromoClassName + '">',
										this.dsCTACopyPromo,
									'</div>',
									'<div class="' + this.dsCTAClassName + '">',
										(this.dsHasCTALink)?this.dsCTALinkLabel+'<a href="'+this.dsCTALink+'?rfrr='+this.dsCTALinkRfrr+'">'+this.dsCTACopy+'</a>':this.dsCTACopy,
									'</div>',
									'<div id="ds-scroll-pane-legal-1">',
										this.dsLegalCopy1,
									'</div>',
									'<div id="ds-scroll-pane-legal-2">',
										this.dsLegalCopy2,
									'</div>',				
								'</div>',
							'</div>',
							'<div id="ds-middle-bottom">',
								'<div id="ds-middle-bottom-left">&nbsp;</div>',
								'<div id="ds-middle-bottom-center">&nbsp;</div>',
								'<div id="ds-middle-bottom-right">&nbsp;</div>',
							'</div>',             
						'</div>',
						'<div id="ds-right">',
							'<div id="ds-right-top">&nbsp;</div>',
							'<div id="ds-right-middle">&nbsp;</div>',
							'<div id="ds-right-bottom">&nbsp;</div>',
						'</div>',
					'</div>'
                	].join('');
        },	
		loadXML:function()
		{
			try
			{
				this.xmlHttpRequest = new XMLHttpRequest();
			}
			catch (e)
			{
				try
				{
					this.xmlHttpRequest = new ActiveXObject('Msxml2.XMLHTTP');
				}
				catch (e)
				{
					this.xmlHttpRequest = new ActiveXObject('Microsoft.XMLHTTP');
				}
			}
			
			if (this.xmlHttpRequest == null)
			{
				return;
			}		
			else
			{
				this.xmlHttpRequest.onreadystatechange = this.loadXML_callback;
				this.xmlHttpRequest.open("GET", this.dsXMLFile, true);
				this.xmlHttpRequest.send(null);
			}		
		},
		loadXML_callback:function()
		{
			if (expDS.xmlHttpRequest.readyState == 4)
			{
				if (expDS.xmlHttpRequest.status == 200)
				{
					try
					{
						var xmlDocKnownOrigin = expDS.removeWhiteSpace(expDS.xmlHttpRequest.responseXML.documentElement).childNodes[0];
						var xmlDocUnKnownOrigin = expDS.removeWhiteSpace(expDS.xmlHttpRequest.responseXML.documentElement).childNodes[1];
						//Store the xml data in an Array to use later
						var i, j, oneRow, oneSavings;
						for (i = 0; i < xmlDocKnownOrigin.childNodes.length; i++)
						{
							if (xmlDocKnownOrigin.childNodes[i].nodeType == 1)
							{
								oneRow = xmlDocKnownOrigin.childNodes[i];
								oneSavings = expDS.arrSavingsKnownOrigin[expDS.arrSavingsKnownOrigin.length] = new Object();
								for (j = 0; j < oneRow.childNodes.length; j++)
								{
									if (oneRow.childNodes[j].nodeType == 1)
									{
										oneSavings[oneRow.childNodes[j].tagName] = (oneRow.childNodes[j].firstChild) ? oneRow.childNodes[j].firstChild.nodeValue : '';
									}
								}
							}
						}
						for (i = 0; i < xmlDocUnKnownOrigin.childNodes.length; i++)
						{
							if (xmlDocUnKnownOrigin.childNodes[i].nodeType == 1)
							{
								oneRow = xmlDocUnKnownOrigin.childNodes[i];
								oneSavings = expDS.arrSavingsUnKnownOrigin[expDS.arrSavingsUnKnownOrigin.length] = new Object();
								for (j = 0; j < oneRow.childNodes.length; j++)
								{
									if (oneRow.childNodes[j].nodeType == 1)
									{
										oneSavings[oneRow.childNodes[j].tagName] = (oneRow.childNodes[j].firstChild) ? oneRow.childNodes[j].firstChild.nodeValue : '';
									}
								}
							}
						}
						//Check create date here
						var hoursOld = expDS.checkDateStampHoursOld(expDS.arrSavingsKnownOrigin[0].createDate);
						if (parseInt(hoursOld) <= parseInt(expDS.hoursOldLimit))
						{
							expDS.arrSavingsDDL = expDS.arrSavingsKnownOrigin.slice();
							expDS.loadDDLOrigin();
							
							if (FTLA.length == 3)
							{
								expDS.userOriginTla.push(FTLA);
							}
							setTimeout('expDS.checkTla()', 500);

							document.getElementById('ds-left-middle').className = 'ds-left-middle-data';
							document.getElementById('ds-right-middle').className = 'ds-right-middle-data';
							document.getElementById('ds-middle-middle').style.display = 'block';
							document.getElementById('ds-middle-bottom-savings-module').style.display = 'block';
							expDS.show();
						}											
					}
					catch(e)
					{
						//alert('error: ' + e);
					}
				}
			}
		},
		loadDDLOrigin:function()
		{
			this.arrSavingsDDL.sort(this.sortByOrigin);
			var previousOrigin = '';
			for (i = 0; i < this.arrSavingsDDL.length; i++)
			{
				var currentOriginValue = this.arrSavingsDDL[i].Origin;
				var currentOrigin = this.arrSavingsDDL[i].o_CITY_CONTENT + ' (' + currentOriginValue + ')';
				if (previousOrigin != currentOrigin)
				{
					previousOrigin = currentOrigin;
					var ddl = document.getElementById('ds-ddl-origin');
					var elOpt = document.createElement('option');
					elOpt.text = currentOrigin;
					elOpt.value = currentOriginValue;
					if (!this.isIE)
					{
						ddl.add(elOpt, null);
					}
					else
					{
						ddl.add(elOpt);
					}
				}
			}
			this.arrSavingsDDLLoaded=true;
			this.setOrigin();
			this.getUserOriginTla();		
		},
		getUserOriginTla:function()
		{
			//TODO: Get Dma from cookie
			try
			{
				this.soapRequest = new XMLHttpRequest();
			}
			catch (e)
			{
				try
				{
					this.soapRequest = new ActiveXObject('Msxml2.XMLHTTP');
				}
				catch (e)
				{
					this.soapRequest = new ActiveXObject('Microsoft.XMLHTTP');
				}
			}
			
			if (this.soapRequest == null)
			{
				return;
			}		
			else
			{
				this.soapRequest.onreadystatechange = this.getUserOriginTla_callBack;
				this.soapRequest.open("POST", this.soapRequestURL, true);
				this.soapRequest.setRequestHeader('Content-Type','text/xml');

				this.soapRequest.send(this.createSoapRequestXml());
			}						
		},
		getUserOriginTla_callBack:function(r)
		{
			//(r != null)?expDS.userOriginTla=r.Tla.Id:expDS.userOriginTla=null;
			if (expDS.xmlHttpRequest.readyState == 4)
			{
				if (expDS.xmlHttpRequest.status == 200)
				{
					try
					{
						var xmlTlas = expDS.removeWhiteSpace(expDS.soapRequest.responseXML.documentElement);
						var tlas = xmlTlas.getElementsByTagName('Tla');
						for (i = 0; i < tlas.length; i++)
						{
							if (tlas[i].childNodes[1].firstChild.data == '1')
							{
								var position = (FTLA.length==3)?1:0;
								expDS.userOriginTla.splice(position,0,tlas[i].childNodes[0].firstChild.data);
							}
							else
							{
								expDS.userOriginTla.push(tlas[i].childNodes[0].firstChild.data);
							}
						}
					} 
					catch (e)
					{
						//alert('error: ' + e);
					}
				}
			}		
			expDS.userOriginTlaLoaded=true;
		},
		createSoapRequestXml:function()
        { 
            return [
					'<?xml version="1.0" encoding="utf-8"?>',
						'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">',
							'<soap:Body>',
								'<getDma xmlns="http://www.expedia.com/">',
									'<Dma>',
										this.userOriginDma,
									'</Dma>',
								'</getDma>',
							'</soap:Body>',
						'</soap:Envelope>'
                	].join('');
        },
		checkFTLA:function()
		{
			if(typeof FTLA == 'undefined')
			{
				FTLA = '';
			}
		},
		checkTla:function()
		{
			if (this.arrSavingsDDLLoaded && this.userOriginTlaLoaded)
			{
				var originExists=false;
				var ddl = document.getElementById('ds-ddl-origin');
				var i, j;
				for(i=0;i<this.userOriginTla.length;i++)
				{
					if (originExists == false)
					{
						for(j=0;j<ddl.length;j++)
						{
							if (this.userOriginTla[i] == ddl[j].value)
							{ 
								originExists = true;
								expDS.matchedTla = this.userOriginTla[i];
								break;
							}
						}
					}
					else
					{
						break;
					}
				}
				
				if (originExists)
				{
					this.setOrigin(this.matchedTla);					
				}
				else
				{
					this.setOrigin();
				}
			}
			else
			{
				var duration = (this.isIE)?1000:500;
				setTimeout('expDS.checkTla();',duration);
			}
		},						
		setOrigin:function(origin)
		{
			if (origin != undefined && origin.length == 3)
			{
				this.setDDLOrigin(origin);
				this.clearScrollPane();
				this.loadScrollPane(1,origin);
			}
			else
			{
				this.clearScrollPane();
				this.loadScrollPane(0,origin);
			}
		},
		setDDLOrigin:function(origin)
		{
			document.getElementById('ds-ddl-origin').value = origin;
		},		
		clearScrollPane:function()
		{
			document.getElementById('ds-scroll-pane').innerHTML = '';
		},
		loadScrollPane:function(type,origin)
		{
			var arrScrollPane = (type == 1)?this.arrSavingsKnownOrigin:this.arrSavingsUnKnownOrigin;
			var scrollPane = document.getElementById('ds-scroll-pane');
			var scrollPaneTable = '<table class="ds-scroll-pane-table">';
			for (i=0; i < arrScrollPane.length; i++)
			{
				if (type == 1)
				{
					if (arrScrollPane[i].Origin == origin)
					{
						scrollPaneTable += this.buildDestinationRow(false,arrScrollPane[i]);
					}
				}
				else
				{
					scrollPaneTable += this.buildDestinationRow(true,arrScrollPane[i]);						
				}	
			}
			scrollPaneTable += '</table>';
			scrollPane.innerHTML = scrollPaneTable;
		},
		buildDestinationRow:function(originIsKnown,destination)
		{
			var destinationName = (originIsKnown)?destination.o_CITY_CONTENT + ' (' + destination.Origin + ')' + ' - ' + destination.d_CITY_CONTENT + ' (' + destination.Destination + ')':destination.d_CITY_CONTENT + ' (' + destination.Destination + ')'; 
			var totalSavings = this.formatPrice(destination.TotalSavingsPrice);
			var tripDates = destination.FlightDepartureDate + ' - ' + destination.FlightReturnDate;
			var tripNights = this.getTripNights(destination.FlightDepartureDate,destination.FlightReturnDate);
			var travelerInfo = 'Travelers: ' + destination.NumberTravelers + ((destination.NumberRooms==1)?' ('+destination.NumberRooms+' Room)':' ('+destination.NumberRooms+' Rooms)');
			var airlineName = ((destination.airlineName != undefined)&&(destination.airlineName.length))?destination.airlineName:'Airline info not available';
			var separatePrice = '<div class="ds-scrollpane-content-float-left">Booked Separately</div>' + this.formatPrice(destination.bookedSeperately);
			var starRating = (destination.HotelStarRating)?this.getStarRatingImage(destination.HotelStarRating):'';
			var truncateLength = (starRating!='')?23:35;
			var hotelName = (destination.HotelName.length<truncateLength)?destination.HotelName:destination.HotelName.substring(0,truncateLength)+'...';
			var togetherPrice = '<div class="ds-scrollpane-content-float-left">Booked Together</div>' + this.formatPrice(destination.TotalTogetherPrice);
			var tripLink = (this.tripLinkDisplay)?this.getTripLink(destination.FlightDepartureDate, destination.FlightReturnDate, destination.Origin, destination.RegionID, destination.Destination, destination.HotelID, destination.NumberTravelers, destination.NumberRooms):'&nbsp;';
			var asOfDate = this.createAsOfDate(destination.TealeafTimeStamp);
			
			var dealRow = '<tr class="ds-scroll-pane-row"><td class="ds-origin-destination">' + destinationName + '</td><td class="ds-total-savings"><div class="ds-scrollpane-content-float-left">TRIP SAVINGS</div> <span class="ds-total-savings-price">' + totalSavings + '</span></td></tr>';
			dealRow += '<tr class="ds-scroll-pane-row"><td class="ds-travel-dates">' + tripDates + tripNights + '</td><td class="ds-traveler-info ds-white-bg">' + travelerInfo + '</td></tr>';
			dealRow += '<tr class="ds-scroll-pane-row"><td class="ds-scrollpane-text">' + airlineName + '</td><td class="ds-booked-separately ds-white-bg">' + separatePrice + '</td></tr>';
			dealRow += '<tr class="ds-scroll-pane-row"><td class="ds-scrollpane-text">' + hotelName + '&nbsp;' +starRating + '</td><td class="ds-booked-together ds-white-bg">' + togetherPrice + '</td></tr>';
			dealRow += '<tr class="ds-scroll-pane-row"><td class="ds-scrollpane-text">' + tripLink + '</td><td class="ds-as-of-date ds-white-bg">' + asOfDate + '</td></tr>'; 
			dealRow += '<tr class="ds-scroll-pane-row-separator"><td colspan="2">&nbsp;</td></tr>';
			return  dealRow;
		},
		showArrow:function()
		{
			this.hideArrow();
            var _top = this.coords.arrowY + 'px';
            var _left = this.coords.arrowX + 'px';
            this.arrowDiv.style.top = _top;
            this.arrowDiv.style.left = _left;			
			this.arrowDiv.style.display = 'block';
		},
		hideArrow:function()
		{			
			if (this.arrowDiv != null)this.arrowDiv.style.display = 'none';
		},	
		setCoords:function()
		{
			var el = this.triggerElement;
			var elOffsetTop = 0;
			var elOffsetLeft = 0;
            while (el != null)
            {
                elOffsetTop += el.offsetTop;
                elOffsetLeft += el.offsetLeft;
                el = el.offsetParent; 
            }
			var elWidth = this.triggerElement.offsetWidth;
			var elHeight = this.triggerElement.offsetHeight;
			var popupWidth = this.popupDiv.offsetWidth;			
			var popupHeight = this.popupDiv.offsetHeight;			
			var arrowWidth = this.arrowDiv.offsetWidth;
			var arrowHeight = this.arrowDiv.offsetHeight;
			var arrowDirection = null;
			var screenWidth = this.getScreenWidth();
			var screenHeight = this.getScreenHeight();
			
			//Position the arrow vertically			
			this.coords.arrowY = this.coords.clickY - arrowHeight/2; 
			
			//Position the arrow horizontally
			if((elOffsetLeft + elWidth + arrowWidth + popupWidth + this.popupDivPaddingHoriz) < screenWidth)
			{
				this.arrowDiv.className = 'ds-arwL';
				arrowDirection = 'left';
				this.coords.arrowX = elOffsetLeft + elWidth + this.popupDivPaddingHoriz;
			}
			else
			{
				this.arrowDiv.className = 'ds-arwR';
				arrowDirection = 'right';
				this.coords.arrowX = elOffsetLeft - arrowWidth - this.popupDivPaddingHoriz;
			}

			//Position the popup vertically
			var exceedsTop = (this.getScrollHeight() >= (this.coords.clickY - this.popupDivPaddingVert));
			var exceedsBottom = ((this.getScreenHeight() + this.getScrollHeight()) <= (this.coords.clickY + (popupHeight - this.shadowPadding)));
			var maxTopY = this.coords.clickY - arrowHeight;
			var maxBottomY = (this.coords.clickY - popupHeight) + (arrowHeight + this.shadowPadding);
			if (this.getScreenHeight() < popupHeight)
			{
				this.coords.popupY = (this.getScrollHeight() > maxTopY)?maxTopY:this.getScrollHeight();
			}
			else if (exceedsTop)
			{
				this.coords.popupY = (maxTopY < this.getScrollHeight()) ? maxTopY : this.getScrollHeight();
			}
			else if (exceedsBottom)
			{
				this.coords.popupY = (maxBottomY > ((this.getScreenHeight() + this.getScrollHeight()) - popupHeight)) ? maxBottomY : (this.getScreenHeight() + this.getScrollHeight()) - popupHeight;
			}
			else
			{
				this.coords.popupY = this.coords.clickY - this.popupDivPaddingVert;
			}

			// Position popup horizontal			
			if (arrowDirection == 'left')
			{
				this.coords.popupX = elOffsetLeft + elWidth + arrowWidth + this.popupDivPaddingHoriz;
			}
			else
			{
				this.coords.popupX = elOffsetLeft - arrowWidth - popupWidth + this.shadowPadding;
			}
			
			if (this.getScrollLeft() > this.coords.popupX)
			{
				this.setClickCoords();
			}
			
			this.previousDivHeight = this.popupDiv.offsetHeight;        			
		},
		setClickCoords:function()
		{	
			this.arrowDiv.className = 'ds-arwL';		
			//Position the arrow			
			this.coords.arrowX = ((this.isIE)?(this.coords.clickX + this.getScrollLeft()):this.coords.clickX) + this.popupDivPaddingHoriz;
			this.coords.arrowY = (this.coords.clickY - this.arrowDiv.offsetHeight/2);
			
			//Position the popup			
			this.coords.popupX = ((this.isIE)?(this.coords.clickX + this.getScrollLeft()):this.coords.clickX) + this.popupDivPaddingHoriz + this.arrowDiv.offsetWidth;				
			this.coords.popupY = (this.coords.clickY - this.popupDivPaddingVert);
		},											
		getScrollHeight:function()
        {
            if(document.documentElement.scrollTop)
            {
                return document.documentElement.scrollTop;
            }            
            if(document.body.scrollTop)
            {
                return document.body.scrollTop;
            }            
            if(window.pageYOffset)
            {
                return window.pageYOffset;
            }            
            return 0;
        },	  	      
        getScreenHeight:function()
        {			
            if(window.innerHeight)
            {				
                return window.innerHeight;
            }			
			
            if(document.documentElement.clientHeight)
            {				
                return document.documentElement.clientHeight;
            }
			
            if(document.body.clientHeight)
            {
				
                return document.body.clientHeight;
            }
            
            return 0;
        },
        getScrollLeft:function()
        {
            if(document.documentElement.scrollLeft)
            {
                return document.documentElement.scrollLeft;
            }            
            if(document.body.scrollLeft)
            {
                return document.body.scrollLeft;
            }            
            if(window.pageXOffset)
            {			
                return window.pageXOffset;				
            }            
            return 0;
        },		
        getScrollWidth:function()
        {
            if(document.documentElement.scrollWidth)
            {
                return document.documentElement.scrollWidth;
            }            
            if(document.body.scrollWidth)
            {
                return document.body.scrollWidth;
            }            
            if(window.pageXOffset)
            {				
                return window.pageXOffset;				
            }            
            return 0;
        },		  	      
        getScreenWidth:function()
        {
            if(window.innerWidth)
            {
				var windowInnerWidth = window.innerWidth;
				var scrollWidth = this.getScrollWidth();
                return (scrollWidth < windowInnerWidth)?scrollWidth:windowInnerWidth;
            }
            
            if(document.documentElement.clientWidth)
            {
                return document.documentElement.clientWidth;
            }
            
            if(document.body.clientWidth)
            {
                return document.body.clientWidth;
            }
            
            return 0;
        },
		getDmaFromCookie:function()
		{
			var c_name = 'ipsnf3';
			if (document.cookie.length>0)
			{
				var c_start = document.cookie.indexOf(c_name + '=');
				if (c_start != -1)
				{ 
					c_start = c_start + c_name.length+1; 
					c_end = document.cookie.indexOf(';',c_start);
					if (c_end == -1)
					{
						c_end = document.cookie.length;
					}	
					var c_value = unescape(document.cookie.substring(c_start,c_end));
					this.userOriginDma = c_value.split('|')[3];
				} 
				else
				{
					this.userOriginDma = 0;
				}
			}		
		},		
		sortByOrigin:function(a,b)
		{
			var x = a.o_CITY_CONTENT.toLowerCase();
    		var y = b.o_CITY_CONTENT.toLowerCase();
    		return ((x < y) ? -1 : ((x > y) ? 1 : 0));
		},
		formatPrice:function(num)
		{
			num = eval(num);
			num *= 100;
			num = Math.round(num)/100;
		
			if (num - Math.floor(num) == 0)
			{
				num = num; //+ ".00";
			}
			else
			{
				string = num.toString();
				parts = string.split(".");
				cents = parts[1];
				if (cents.length == 1)
				{
					num = num + "0";
				}
			}
		
			num = "$" + num;
			return num;
		},
		getTripNights:function(startDate,endDate)
		{
		    var ONE_NIGHT = 1000 * 60 * 60 * 24;
			var startdate = new Date(startDate);
			var enddate = new Date(endDate);
		    var startdate_ms = startdate.getTime();
		    var enddate_ms = enddate.getTime();
		    var difference_ms = Math.abs(startdate_ms - enddate_ms);
			var difference_days = Math.round(difference_ms/ONE_NIGHT);
			var tripnights = (difference_days == 1)?' ('+difference_days+' night)':' ('+difference_days+' nights)';

		    return tripnights;
		},		
		checkDateStampHoursOld:function(dt)
		{
			var createMonth = (dt.split('.')[0].split('T')[0].split('-')[1]);
			var createDay = dt.split('.')[0].split('T')[0].split('-')[2];
			var createYear = dt.split('.')[0].split('T')[0].split('-')[0];
			var createTime = dt.split('.')[0].split('T')[1];
			var createDateString = createMonth + '/' + createDay + '/' + createYear +  ' ' + createTime + ' GMT';
			var createDateLocal = new Date(createDateString);		
			var viewDate = new Date();		
			var dateDiffHours = Math.floor(Math.abs(viewDate.getTime() - createDateLocal.getTime()) / (1000 * 60 * 60));
			
			return dateDiffHours;
		},
		createAsOfDate:function(dt)
		{
			var createMonth = (dt.split('.')[0].split('T')[0].split('-')[1]);
			var createDay = dt.split('.')[0].split('T')[0].split('-')[2];
			var createYear = dt.split('.')[0].split('T')[0].split('-')[0];
			var createTime = dt.split('.')[0].split('T')[1];
			var createDateString = createMonth + '/' + createDay + '/' + createYear +  ' ' + createTime + ' GMT';
			var createDateLocal = new Date(createDateString);
			
			var viewDate = new Date();

			var dateDiffHours = Math.ceil(Math.abs(viewDate.getTime() - createDateLocal.getTime()) / (1000 * 60 * 60));
			var createAsOfDateMessage = (dateDiffHours <= 1)? 'Priced less than ' + dateDiffHours + ' hour ago':'Priced less than ' + dateDiffHours + ' hours ago';
			return createAsOfDateMessage;				
		},
		getTripLink:function(fromdate, todate, fromairport, destinationid, toairport, hotelid, numberadults, numberrooms)
		{
			if(fromdate != undefined && todate != undefined && fromairport != undefined && destinationid != undefined  && toairport != undefined && hotelid != undefined && numberadults != undefined && numberrooms)
			{
				var numadults = '';
				var assignedadults = 0;
				for (var i=1;i<=numberrooms;i++)
				{
					if((numberadults % numberrooms) == 0)
					{
						numadults += '&NumAdult' + i + '=' + Math.round(numberadults/numberrooms);
					}
					else
					{
						if (i == numberrooms)
						{
							numadults += '&NumAdult' + i + '=' + (numberadults - assignedadults);
						}
						else
						{
							numadults += '&NumAdult' + i + '=' + Math.round(numberadults/numberrooms);
							assignedadults += Math.round(numberadults/numberrooms);
						}
					}
				}
				return '<a href="/pubspec/scripts/eap.asp?GOTO=PACKAGEWIZ&FromDate=' + fromdate + '&ToDate=' + todate + '&FrAirport=' + fromairport + '&DestId=' + destinationid + ':' + toairport + '&HotelIDs=' + hotelid + numadults + '&NumRoom=' + numberrooms  + '&rfrr=' + this.tripLinkRfrr + '" class="ds-trip-link">' + this.tripLinkCopy + '</a>';
			}
			else
			{
				return '&nbsp;';
			}
		},
		getStarRatingImage:function(rating)
		{
			var alt = rating.substring(0,1) + '.' + rating.substring(1,2) + ' stars';
			return '<img src="http://media.expedia.com/hotels/ratings/stars/hotstar'+rating+'.gif" alt="'+alt+'" />';
		},		 	           
		removeWhiteSpace:function(root)
		{
			var i = 0;
			while (i != root.childNodes.length)
			{
				if (root.childNodes[i].nodeType == 3)
				{
					root.removeChild(root.childNodes[i])
				}
				else
				{
					var j = 0;
					while (j != root.childNodes[i].childNodes.length)
					{
						if (root.childNodes[i].childNodes[j].nodeType == 3)
						{
							root.childNodes[i].removeChild(root.childNodes[i].childNodes[j])
						}
						else
						{
							j++;
						}
					}
					i++;
				}
			}
			return root;			
		},		
		check:function()
        {
            var newOFHeight = this.popupDiv.offsetHeight;
            if (this.previousDivHeight != newOFHeight)
            {
                this.show();
            }
             
        }    
    };    
}

function dsCheck(e)
{
	var target = (e && e.target) || (event && event.srcElement);
	var isEventObj = expDS.previousEventObj == target;
	var isDS = checkParent(target, 'ds-div');
	if (!isDS && !isEventObj)
	{
		expDS.hideDS();
	}
}

function checkParent(target, ds)
{
	var isDS = false;
	while(target.parentNode)
	{
		target = target.parentNode;
		if(target.id == ds)
		{
			isDS = true;
		}
	}
	return isDS;
}



function doDS_SA(rfrr)
{
    g_s_gsDelay=10;
    s_linkTrackVars='prop16,eVar28';
    s_linkType='o';
    s_linkName='RFRR Action Link';
    s_prop16=rfrr;
    s_eVar28=rfrr;
    s_lnk=s_co(this);
    s_gs(s_account);
    g_s_gsDelay=500;
}

if (document.addEventListener)
{
	document.addEventListener('click', dsCheck, false);
}
else if (document.attachEvent)
{
	document.attachEvent('onclick', dsCheck);
}