var _TUITRACK={};var dls_deals;var dls_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="";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{$("dls_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(F){var D=F.responseText.evalJSON();var C=A.data.optionsData;A.data=D;A.data.optionsData=C;A.update();try{$("dls_hotdeals_wait").style.display="none"}catch(E){}}})},update:function(){var F=document.getElementById(this.id_Target);var A=2;var N=Math.floor(200/(6-A));while(F.hasChildNodes()){F.removeChild(F.firstChild)}var I=document.createElement("table");I.id=this.id_Target+"_table";I.cellSpacing="0px";I.cellPadding="0px";$(this.id_Target).appendChild(I);var D=I.insertRow(I.rows.length);var H=D.insertCell(0);H.style.width="140px";H.style.height="20px";var E=1;for(var O=A;O<6;O++){starCell=D.insertCell(E);E=E+1;starCell.style.width=N+"px";starCell.className="hd_matrix_star";starCell.innerHTML=O;starImg=document.createElement("img");starImg.src="http://www.directline-holidays.co.uk/images/spacer.gif";starImg.className="sprite_matrix_star";starCell.appendChild(starImg)}var K="";var L=A;var R=0;var Q;if(this.data.data.DATA.length>0){for(var O=0;O<this.data.data.DATA.length;O++){if(R<9){var P;var S=this.data.data.DATA[O];for(var M=0;M<this.data.data.DATA[O].length;M++){window[this.data.data.COLUMNS[M]]=S[M]}if(TD_STAR_RATING>A-1){if(RESORT_DISPLAY_NAME!=K){R++;if(R<9){Q=I.insertRow(I.rows.length);Q.id=RESORT_DISPLAY_NAME+"_holder";L=A;K=RESORT_DISPLAY_NAME;if(R%2){P="#ffffff"}else{P="#f2f2f2"}var G=Q.insertCell(0);G.id=RESORT_DISPLAY_NAME+"_holder";G.style.width="140px";G.style.height="20px";G.style.background=P;G.style.paddingLeft="3px";G.style.color="#666666";G.innerHTML=RESORT_DISPLAY_NAME;var E=1;for(var J=A;J<6;J++){var C=Q.insertCell(E);E=E+1;C.style.background=P;C.style.width=N+"px";C.style.height="20px";C.style.textAlign="center";price_cell_link=document.createElement("a");price_cell_link.id=RESORT_DISPLAY_NAME+"_"+J+"_price";price_cell_link.style.textDecoration="underline";C.appendChild(price_cell_link)}}}if(R<9){var T=$(RESORT_DISPLAY_NAME+"_"+TD_STAR_RATING+"_price");T.innerHTML="&pound;"+TD_PRICE_SYSTEM;T.style.cursor="pointer";T.alt=ID;T.observe("click",this.clickedOfferPrice.bind(this))}}}}}if(this.initial_load){var B=document.createElement("div");B.className="hd_title";B.appendChild(document.createTextNode("HOT Deals filter"));$(this.id_Target+"_search").appendChild(B);var B=document.createElement("div");B.className="hd_blurb";B.appendChild(document.createTextNode("Click a price or filter"));B.appendChild(document.createElement("br"));B.appendChild(document.createTextNode("to find the best deal."));$(this.id_Target+"_search").appendChild(B);this.addSearchField("departs","Departure Airport");this.addSearchField("boards","Board Basis");this.addSearchField("nights","Duration");this.addSearchField("months","Month");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 K=new Object();var L=this.current_offer_id;var B=this.room_select.options[this.room_select.selectedIndex].value;var D=0;var M=0;for(var G=0;G<B;G++){var F=$("room_"+(G+1)+"_adults");var H=$("room_"+(G+1)+"_children");D+=parseInt(F.options[F.selectedIndex].value);M+=parseInt(H.options[H.selectedIndex].value);K["frm_AdultsRoom"+(G+1)]=parseInt(F.options[F.selectedIndex].value);K["frm_ChildrenRoom"+(G+1)]=parseInt(H.options[H.selectedIndex].value)}for(var G=0;G<M;G++){var C=$("child_age_"+(G+1));K["frm_Child"+(G+1)]=parseInt(C.options[C.selectedIndex].value)}K.offer_id=L;K.frm_RoomsRequired=parseInt(B);try{K.board_basis=$("boards_select").value}catch(J){}try{if(pageTracker!==undefined&&_TUITRACK!==undefined){pageTracker._trackEvent("TUI Offers","Search",_TUITRACK.country+" "+_TUITRACK.stars+" star")}}catch(J){}var N=document.createElement("form");N.method="post";N.action="/searchRedirect.cfm";for(var I in K){var E=document.createElement("input");E.type="hidden";E.name=I;E.value=K[I];N.appendChild(E)}document.body.appendChild(N);N.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 J=0;for(var D=0;D<G;D++){var E=$("room_"+(D+1)+"_children");J+=parseInt(E.options[E.selectedIndex].value)}if(J>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<J;D++){var L=document.createElement("div");var K=document.createElement("span");K.style.fontWeight="bold";K.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)}L.appendChild(K);L.appendChild(H);A.appendChild(L)}}else{var I=document.createElement("div");I.style.height="28px";A.appendChild(I)}},renderOccupants:function(I,B,L){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<I;G++){var O=document.createElement("div");var N=document.createElement("span");N.style.fontWeight="bold";N.innerHTML="Room "+(G+1)+"&nbsp;&nbsp;&nbsp;";var J=document.createElement("select");J.id="room_"+(G+1)+"_adults";J.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 M=document.createElement("option");M.value=(D);M.innerHTML=(D);if(D==B){M.selected="selected"}var K=document.createElement("option");K.value=(D);K.innerHTML=(D);if(D==L){K.selected="selected"}J.appendChild(M);E.appendChild(K)}O.appendChild(N);O.appendChild(J);O.appendChild(E);A.appendChild(O);$(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){}}});
