/* Initialise a TOG Deal Finder creating a new Deal Finder object */
var initDealFinder = function(){
/* Define your offer Object could be earlies or lates or whatever*/
DealFinder.ajaxObj = "eog";
/* Define your objects properties can be whatever you like? although we cannot change the DealFinder property name here and expect it to do anything */
DealFinder.ajaxObjPropNum1 = "price";// used in the object for price/numerical sorting
DealFinder.ajaxObjPropDate1 = "depDate";// used in object to sort by date
DealFinder.ajaxObjPropBool1 = "isADRTog";// used in the object to define data source
DealFinder.ajaxObjPropStr1 = "ogId";
DealFinder.ajaxObjPropStr2 = "depGatewayName";
DealFinder.ajaxObjPropStr3 = "locDesc";
DealFinder.ajaxObjPropStr4 = "locCode";// used in the object to ascertain valid offer
DealFinder.ajaxObjPropStr5 = "arLocationName";
DealFinder.ajaxObjPropStr6 = "holidayDuration";
DealFinder.ajaxObjPropStr7 = "duration";
DealFinder.ajaxObjPropStr8 = "accomName";
DealFinder.ajaxObjPropStr9 = "boardBasis";
DealFinder.ajaxObjPropStr10 = "href";
DealFinder.ajaxObjPropStr11 = "basedOn";

/* Map your selected #{} values to your objects properties keep in quotes so it is not evaluated here (Unfortunately I had to do some serious processing on the Location name and Duration due to inconsistancies in the offers - hopefully this will not be an issue in future */
DealFinder.valueMapping = '{href : to[DealFinder.ajaxObjPropStr10], DurationWeeks : (to[DealFinder.ajaxObjPropStr7] === "1 nights") ? to[DealFinder.ajaxObjPropStr7].replace("1 nights","Day Trip") : to[DealFinder.ajaxObjPropStr7], Airport : to[DealFinder.ajaxObjPropStr2].replace("International","Int\'l"), LocationName : to[DealFinder.ajaxObjPropStr3], depDate : to[DealFinder.ajaxObjPropDate1], Id : to[DealFinder.ajaxObjPropStr1], PeopleSharing : to[DealFinder.ajaxObjPropStr11], Price : to[DealFinder.ajaxObjPropNum1]}';
	
/* Define your results HTML here use #{} to enter your new values */
DealFinder.outputOfferHTML = '<div class="dealFinder"><a href="#{href}" rel="noindex,nofollow" title="Link to book a holiday for #{DurationWeeks} from #{Airport} to #{LocationName} on #{depDate}" id="og#{Id}"><span class="ogLocation">#{LocationName}</span><span class="ogAirport">#{Airport}</span><span class="ogDate">#{depDate}</span><span class="ogDurationWeeks">#{DurationWeeks}</span><span class="ogPeopleSharing">based on #{PeopleSharing} sharing</span><span class="ogPrice"><span class="arrow-link"><strong>&pound;#{Price}</strong><span class="arrowPlaceholder">&nbsp;</span></span></span></a></div>';

/* Define the primary Select element from the Forms innerHTML below */
DealFinder.selectElement = "TOG_departure";

/* 1.Define the class of the elements you will be using for the primary Select's Options' text content and Values. 2.Define your forms HTML */
DealFinder.buildDealFinderForm(".dealFinderTogOffers",'<div id="dealFinder"><form id="TOG_search" action="" method="post"><div class="departure"><label for="TOG_departure">Fly from</label><select id="TOG_departure" name="TOG_departure" title="Select your departure airport"></select></div><div class="orderOptionsAndButton"><label for="TOG_searchoptions">Order results by</label><select id="TOG_searchoptions" name="TOG_searchoptions" title="Select order preference"><option value="price (lowest first)" selected="selected">Price - lowest first</option><option value="price (highest first)">Price - highest first</option><option value="departure date">Departure date</option><option value="stay (shortest first)">Stay - shortest first</option><option value="stay (longest first)">Stay - longest first</option></select><input name="TOG_searchButton" id="TOG_searchButton" type="image" title="Find lowest price holiday offers" value="Go" alt="Go" src="/images/buttons/form/go_secondary.gif" class="formButton" /></div></form><div id="counter"><img src="/images/icons/ajax_loader_deal_finder.gif" width="220" height="19" alt="" /></div><ul id="togSortAndFilter"></ul><div class="destinationTopTenPriceDetails"> <a title="Click to find out more" class="hasPopup" onkeypress="stickyShow(this, \'PriceDetailsSticky\');return false;" onclick="stickyShow(this, \'PriceDetailsSticky\');return false;" href="#PriceDetails">Price details</a></div></div>');

/* Select element ID match in Form */
DealFinder.selectSortElement = "TOG_searchoptions"

/* Define the results container from HTML of form above */
DealFinder.outputOfferHTMLULContainer = "togSortAndFilter";

/* Define the results container from HTML of form above */
DealFinder.counterContainer = "counter";

/* Set an animated Gif for searching feedback to replace the counter message whilst searching - To match the one in the Form */
DealFinder.counterContainerHTML = '<img src="/images/icons/ajax_loader_deal_finder.gif" width="220" height="19" alt="" />'

/* Map your selected #{} values to your object properties and variables for the Counter message and Error message keep in quotes so it is not evaluated here */
DealFinder.valueMapping2 = '{offerTotal : DealFinder.totalToDisplay.length, selectedSelectOption : $(DealFinder.selectElement).options[$(DealFinder.selectElement).selectedIndex].text, selectSortElement : $(DealFinder.selectSortElement).value}';

/* Define the counter text for the form above */
DealFinder.counterHTML = '<p>Showing <em>#{offerTotal}</em> offers from <em>#{selectedSelectOption}</em> ordered by #{selectSortElement}</p> <strong>Price from</strong>';

/* Define the Error text for the form above - In theory this should never need to be displayed */
DealFinder.errorHTML = "<div class='newWarningBlock'><div class='newWarningBlockInner'><img class='newWarningBlockIcon' title='Alert!' alt='Alert!' src='/images/icons/warning.gif'/><div class='newWarningBlockContent'>Sorry we have not been able to find any suitable results for <em>#{selectedSelectOption}</em>. Please try another Airport.</div></div></div>";

/* Define the option values used in your form for sorting the options HTML content can be whatever you like. NOTE the value is used in the display of the counter */
/* Numerically sorts the value of the DealFinder.ajaxObjPrice property */
DealFinder.optionValueForPriceLowSorting = "price (lowest first)"; 
DealFinder.optionValueForPriceHighSorting = "price (highest first)";
/* sorts by date offers by the value of the DealFinder.ajaxObjDurationDays property */
DealFinder.optionValueForDepartureSorting = "departure date";
/* Numerically sorts offers to the value of the DealFinder.ajaxObjDate property */
DealFinder.optionValueForDurationShortSorting = "stay (shortest first)";
DealFinder.optionValueForDurationLongSorting = "stay (longest first)";

/* Define the location of the Ajax requested files */
DealFinder.ajaxFileURL = "/togoffers/earlies/";

/* Now you have your Form built you might want to submit it to have results showing on page load */	
DealFinder.submitDealFinder();

/* Apply an onClick event to the forms submit button to override the submit, and Define the elements id from your form above */
DealFinder.captureDFEvents("TOG_searchButton");

}
addLoadEvent(initDealFinder);