var _TUITRACK={};var dlh_deals;var dlh_hotdeals=Class.create({initialize:function(a){this.instanceName=a;this.container=false;this.update_url="/hotdeals_update.cfm";this.data="";this.modal="";this.boards_filter="";this.departs_filter="";this.months_filter="";this.nights_filter="7";this.initial_load=true;this.current_offer_id=0},getData:function(){var a=this;new Ajax.Request(this.update_url,{method:"get",parameters:{hotdeals_departs:a.departs_filter,hotdeals_boardbasis:a.boards_filter,hotdeals_nights:a.nights_filter,hotdeals_month:a.months_filter},onSuccess:function(c){var b=c.responseText.evalJSON();a.data=b}})},getDataAndUpdate:function(){var a=this;try{$("dlh_hotdeals_wait").style.display="block"}catch(b){}new Ajax.Request(this.update_url,{method:"get",parameters:{hotdeals_departs:a.departs_filter,hotdeals_boardbasis:a.boards_filter,hotdeals_nights:a.nights_filter,hotdeals_month:a.months_filter},onSuccess:function(g){var d=g.responseText.evalJSON();var c=a.data.optionsData;a.data=d;a.data.optionsData=c;a.update();try{$("dlh_hotdeals_wait").style.display="none"}catch(f){}}})},update:function(){var f=document.getElementById(this.id_Target);var a=2;var q=Math.floor(200/(6-a));while(f.hasChildNodes()){f.removeChild(f.firstChild)}var l=document.createElement("table");l.id=this.id_Target+"_table";l.cellSpacing="0px";l.cellPadding="0px";$(this.id_Target).appendChild(l);var d=l.insertRow(l.rows.length);var h=d.insertCell(0);h.style.width="140px";h.style.height="20px";var e=1;for(var r=a;r<6;r++){starCell=d.insertCell(e);e=e+1;starCell.style.width=q+"px";starCell.style.height="20px";starCell.style.textAlign="center";starCell.style.color="#ff6600";starCell.style.fontWeight="bold";starCell.innerHTML=r;starImg=document.createElement("img");starImg.src="http://www.directline-holidays.co.uk/images/matrix-star.gif";starImg.style.width="10px";starImg.style.height="9px";starCell.appendChild(starImg)}var n="";var o=a;var u=0;var t;if(this.data.data.DATA.length>0){for(var r=0;r<this.data.data.DATA.length;r++){if(u<9){var s;var v=this.data.data.DATA[r];for(var p=0;p<this.data.data.DATA[r].length;p++){window[this.data.data.COLUMNS[p]]=v[p]}if(TD_STAR_RATING>a-1){if(RESORT_DISPLAY_NAME!=n){u++;if(u<9){t=l.insertRow(l.rows.length);t.id=RESORT_DISPLAY_NAME+"_holder";o=a;n=RESORT_DISPLAY_NAME;if(u%2){s="#accdff"}else{s="#f5fef8"}var g=t.insertCell(0);g.id=RESORT_DISPLAY_NAME+"_holder";g.style.width="140px";g.style.height="20px";g.style.background=s;g.style.paddingLeft="3px";g.innerHTML=RESORT_DISPLAY_NAME;var e=1;for(var m=a;m<6;m++){var c=t.insertCell(e);e=e+1;c.style.background=s;c.style.width=q+"px";c.style.height="20px";c.style.textAlign="center";price_cell_link=document.createElement("a");price_cell_link.id=RESORT_DISPLAY_NAME+"_"+m+"_price";price_cell_link.style.textAlign="center";price_cell_link.style.textDecoration="underline";price_cell_link.style.color="#003399";c.appendChild(price_cell_link)}}}if(u<9){var w=$(RESORT_DISPLAY_NAME+"_"+TD_STAR_RATING+"_price");w.innerHTML="&pound;"+TD_PRICE_SYSTEM;w.style.cursor="pointer";w.alt=ID;w.observe("click",this.clickedOfferPrice.bind(this))}}}}}if(this.initial_load){var b=document.createElement("div");b.className="hd_title";b.appendChild(document.createTextNode("Filter Hot Deals"));$(this.id_Target+"_search").appendChild(b);this.addSearchField("departs","Departure Airport");this.addSearchField("boards","Board Basis");this.addSearchField("nights","Duration");this.addSearchField("months","Month");var b=document.createElement("div");b.className="hd_blurb";b.appendChild(document.createTextNode("The grid shows some of"));b.appendChild(document.createElement("br"));b.appendChild(document.createTextNode("our hottest deals. Just"));b.appendChild(document.createElement("br"));b.appendChild(document.createTextNode("click on a price or filter"));b.appendChild(document.createElement("br"));b.appendChild(document.createTextNode("the deals with the above"));$(this.id_Target+"_search").appendChild(b);this.initial_load=false}},addSearchField:function(f,a){var b=document.createElement("select");b.id=f+"_select";var e=document.createElement("option");e.value="";e.innerHTML=a;b.appendChild(e);for(var c=0;c<this.data.optionData[f].DATA.length;c++){var d=this.data.optionData[f].DATA[c];e=document.createElement("option");e.value=d[0];e.innerHTML=d[1];if(d[0]==this[f+"_filter"]){e.selected="selected"}b.appendChild(e)}$(this.id_Target+"_search").appendChild(b);$(b.id).observe("change",this.searchFieldChanges.bind(this));$(this.id_Target+"_search").appendChild(document.createElement("br"))},searchFieldChanges:function(b){try{var a=b.target.id.split("_")[0];var d=b.target.options[b.target.selectedIndex].value;try{if(pageTracker!==undefined){pageTracker._trackEvent("TUI Offers","Filter",a+" "+b.target.options[b.target.selectedIndex].text)}}catch(c){}this[a+"_filter"]=d;this.getDataAndUpdate()}catch(c){}},clickedOfferPrice:function(b){this.current_offer_id=b.target.alt;var a=b.target.id.split("_");_TUITRACK.country=a[0];_TUITRACK.stars=a[1];this.popupModal(b.clientX,b.clientY)},setupModal:function(){this.modal=document.createElement("div");this.modal.style.width="170px";this.modal.id=this.id_Target+"_modal_popup";this.modal.style.position="absolute";this.modal.style.background="#fff";this.modal.style.border="1px solid #000";this.modal.style.display="none";this.modal.style.zIndex="100";this.modal.style.padding="10px";this.modal.style.textAlign="left";this.modal_content=document.createElement("div");this.modal_content.id=this.id_Target+"_modal_content";this.modal_content.style.zIndex="101";this.modal.appendChild(this.modal_content);var g=document.createElement("div");g.style.width="15px";g.style.height="15px";g.style.lineHeight="15px";g.style.fontWeight="bold";g.style.textAlign="center";g.style.border="1px solid #000";g.style.background="#fff";g.style.position="absolute";g.id="dh_modal_close";g.style.top="2px";g.style.right="2px";g.style.cursor="pointer";g.style.zIndex="102";g.appendChild(document.createTextNode("X"));this.modal.appendChild(g);var d=document.createElement("div");d.style.fontWeight="bold";d.style.paddingBottom="5px";d.innerHTML="Rooms required";this.modal.appendChild(d);this.room_select=document.createElement("select");this.room_select.id="dh_roomselect";for(var e=0;e<6;e++){var b=document.createElement("option");b.value=e+1;b.innerHTML=(e+1)+((e>0)?" rooms":" room");this.room_select.appendChild(b)}this.modal.appendChild(this.room_select);var f=document.createElement("div");f.id=this.id_Target+"_occupants_div";this.modal.appendChild(f);var a=document.createElement("div");a.id=this.id_Target+"_children_ages_div";this.modal.appendChild(a);document.body.appendChild(this.modal);$(this.room_select.id).observe("change",this.changedNumberOfRooms.bind(this));$(g.id).observe("click",this.closeModal.bind(this));this.renderOccupants(1,2,0);this.renderChildrenAgeFields();var c=document.createElement("input");c.type="button";c.value="Search";c.style.position="absolute";c.style.bottom="11px";c.style.right="10px";c.style.width="62px";c.id="hd_searchbutton";this.modal.appendChild(c);$(c.id).observe("click",this.submitSearch.bind(this))},submitSearch:function(a){var m=new Object();var n=this.current_offer_id;var b=this.room_select.options[this.room_select.selectedIndex].value;var d=0;var o=0;for(var h=0;h<b;h++){var g=$("room_"+(h+1)+"_adults");var j=$("room_"+(h+1)+"_children");d+=parseInt(g.options[g.selectedIndex].value);o+=parseInt(j.options[j.selectedIndex].value);m["frm_AdultsRoom"+(h+1)]=parseInt(g.options[g.selectedIndex].value);m["frm_ChildrenRoom"+(h+1)]=parseInt(j.options[j.selectedIndex].value)}for(var h=0;h<o;h++){var c=$("child_age_"+(h+1));m["frm_Child"+(h+1)]=parseInt(c.options[c.selectedIndex].value)}m.offer_id=n;m.frm_RoomsRequired=parseInt(b);try{m.board_basis=$("boards_select").value}catch(l){}try{if(pageTracker!==undefined&&_TUITRACK!==undefined){pageTracker._trackEvent("TUI Offers","Search",_TUITRACK.country+" "+_TUITRACK.stars+" star")}}catch(l){}var p=document.createElement("form");p.method="post";p.action="/searchRedirect.cfm";for(var k in m){var f=document.createElement("input");f.type="hidden";f.name=k;f.value=m[k];p.appendChild(f)}document.body.appendChild(p);p.submit()},changedNumberOfRooms:function(a){var b=a.target.options[a.target.selectedIndex].value;this.renderOccupants(b,2,0);this.renderChildrenAgeFields()},changedNumberOfChildren:function(b){var a=b.target.id.split("_")[1];var c=b.target.options[b.target.selectedIndex].value;this.renderChildrenAgeFields()},renderChildrenAgeFields:function(){var a=document.getElementById(this.id_Target+"_children_ages_div");while(a.hasChildNodes()){a.removeChild(a.firstChild)}var g=this.room_select.options[this.room_select.selectedIndex].value;var l=0;for(var d=0;d<g;d++){var e=$("room_"+(d+1)+"_children");l+=parseInt(e.options[e.selectedIndex].value)}if(l>0){var f=document.createElement("div");f.style.fontWeight="bold";f.style.paddingBottom="4px";f.style.paddingTop="3px";f.style.fontSize="10px";f.innerHTML="Please specify the ages of children at time of travel.";a.appendChild(f);for(var d=0;d<l;d++){var n=document.createElement("div");var m=document.createElement("span");m.style.fontWeight="bold";m.innerHTML="Child "+(d+1)+"&nbsp;&nbsp;&nbsp;";var h=document.createElement("select");h.id="child_age_"+(d+1);for(var c=0;c<17;c++){var b=document.createElement("option");b.value=c;b.innerHTML=c;h.appendChild(b)}n.appendChild(m);n.appendChild(h);a.appendChild(n)}}else{var k=document.createElement("div");k.style.height="28px";a.appendChild(k)}},renderOccupants:function(k,b,n){var a=document.getElementById(this.id_Target+"_occupants_div");while(a.hasChildNodes()){a.removeChild(a.firstChild)}var h=document.createElement("div");var f=document.createElement("div");var c=document.createElement("div");h.appendChild(document.createTextNode("Adults"));f.appendChild(document.createTextNode("Under 18s"));c.className="hd_occ_titles";h.style.width="94px";f.style.width="72px";c.appendChild(h);c.appendChild(f);a.appendChild(c);for(var g=0;g<k;g++){var q=document.createElement("div");var p=document.createElement("span");p.style.fontWeight="bold";p.innerHTML="Room "+(g+1)+"&nbsp;&nbsp;&nbsp;";var l=document.createElement("select");l.id="room_"+(g+1)+"_adults";l.style.marginLeft="0px";var e=document.createElement("select");e.id="room_"+(g+1)+"_children";e.style.marginLeft="14px";for(var d=0;d<10;d++){var o=document.createElement("option");o.value=(d);o.innerHTML=(d);if(d==b){o.selected="selected"}var m=document.createElement("option");m.value=(d);m.innerHTML=(d);if(d==n){m.selected="selected"}l.appendChild(o);e.appendChild(m)}q.appendChild(p);q.appendChild(l);q.appendChild(e);a.appendChild(q);$(e.id).observe("change",this.changedNumberOfChildren.bind(this))}},popupModal:function(a,b){this.closeModal();this.setupModal();this.modal.style.display="block";this.modal.style.left=a+"px";this.modal.style.top=b+"px"},closeModal:function(){try{this.modal.style.display="none";document.body.removeChild(this.modal);this.modal=""}catch(a){}}});