/* Updated by JB 27/10/2008 */

var togLocationEarlies = "/togoffers/earlies/" 
var togLocation = "/togoffers/"

if (window.location.href.match(/^file/)) {
    togLocationEarlies = "http://www.falconholidays.ie/togoffers/earlies/"
	togLocation = "http://www.falconholidays.ie/togoffers/"
}

var timestamp = new Date();

/* Price comparison flexible earlies and lates TOG */
/*F0.5 allows for tog offers to be added to a document in an editable content region*/
function tuiTog(){
	$$(".togOffer").each(function(to){
	to.hide();
		if(to.empty()) return;// Any elements in ere?
		if(to.firstChild){
		var todChNos = to.childNodes;
			$A(todChNos).each(function(todChNo){
				if(todChNo.nodeType == 3){
				var text = todChNo.nodeValue;
					if(text.blank()){//if only containing white space
					return;
					}
					else{
					to.replace('<div class="' + text.strip() + '">&nbsp;</div>');// all togOfferElements will be made divs ie will no accept divs placed inside inline elements
				   	}
				}
			});
		}
	});
	getOffersFromDoc();
}	

/* F1 Gets the ftEarlies and ftLates offers from the document */
/* Global variables and Arrays associated with F1 */
var earliesRegEx=/earlies/;
var latesRegEx=/lates/;
var ftEarlies = new Array();
var ftEarliesClassNosFinal = new Array();
var ftLates = new Array();
var ftLatesClassNosFinal = new Array();
var ftEarliesClassNosFinalUniqCompact = new Array();
var ftLatesClassNosFinalUniqCompact = new Array();
/* Global variables and Arrays associated with F1 */
function getOffersFromDoc(){
var ftEarliesClassesSplit = new Array();
var ftEarliesClassNos = new Array();
var ftEarliesClassNosCount = 0;
var ftEarliesCount = 0;	
var ftEarliesClassNosFinalCount = 0;	
var ftLatesClassesSplit = new Array();
var ftLatesClassNos = new Array();
var ftLatesClassNosCount = 0;
var ftLatesCount = 0;	
var ftLatesClassNosFinalCount = 0;

var docBody = document.body;
var allElements = $(docBody).descendants();
$A(allElements).each(function(ae) {/* For every element in the document get those with an earlies or a lates class */
	if(ae.className.match(earliesRegEx)){
	ftEarlies[ftEarliesCount] = ae// add all earlies class elements to ftEarlies Array
	ftEarliesCount ++;
	}
	if(ae.className.match(latesRegEx)){
	ftLates[ftLatesCount] = ae// add all lates class elements to ftLates Array
	ftLatesCount ++;
	}
});
$A(ftEarlies).each(function(e) {/* For all elements with class name of earlies get their numbers */
	if(e.className.match(earliesRegEx)){
	ftEarliesClassesSplit = e.className.split(" ");
		$A(ftEarliesClassesSplit).each(function(ecs) {
			if (ecs.match(earliesRegEx)){	
			ecs = ecs.split("earlies");		
			ftEarliesClassNos[ftEarliesClassNosCount] = ecs;
			ftEarliesClassNosCount ++;
			}
		});
	}
});	
$A(ftEarliesClassNos).each(function(ecn) {/* For all class numbers if multiples split down to singles */	
	if(ecn.toString().length > 5){/* if ftEarlies numbers are multiples break them down */
	ecn = ecn.toString();	
		if(ecn.indexOf(",") != -1){
		var ftEarliesNosSplit = ecn.split(",");
			$A(ftEarliesNosSplit).each(function(ens) {				
			ftEarliesClassNosFinal[ftEarliesClassNosFinalCount] = ens;			
			ftEarliesClassNosFinalCount ++;
			});
		}
	}
	else
	{
	ecn = ecn.toString();
	ftEarliesClassNosFinal[ftEarliesClassNosFinalCount] = ecn.substr(1,5);
	ftEarliesClassNosFinalCount ++;
	}	
});	
ftEarliesClassNosFinalUniqCompact = $A(ftEarliesClassNosFinal).uniq().without("");	
$A(ftLates).each(function(l) {/* For all elements with class name of lates get their numbers */
	if(l.className.match(latesRegEx)){
	ftLatesClassesSplit = l.className.split(" ");
		$A(ftLatesClassesSplit).each(function(lcs) {
			if (lcs.match(latesRegEx)){	
			lcs = lcs.split("lates");		
			ftLatesClassNos[ftLatesClassNosCount] = lcs;
			ftLatesClassNosCount ++;
			}
		});
	}
});	
$A(ftLatesClassNos).each(function(lcn) {/* For all class numbers if multiples split down to singles */
	if(lcn.toString().length > 5){/* if ftLates numbers are multiples break them down */
	lcn = lcn.toString();	
		if(lcn.indexOf(",") != -1){
		var ftLatesNosSplit = lcn.split(",");
			$A(ftLatesNosSplit).each(function(lns) {				
			ftLatesClassNosFinal[ftLatesClassNosFinalCount] = lns;			
			ftLatesClassNosFinalCount ++;
			});
		}
	}
	else
	{
	lcn = lcn.toString();
	ftLatesClassNosFinal[ftLatesClassNosFinalCount] = lcn.substr(1,5);
	ftLatesClassNosFinalCount ++;
	}	
});
ftLatesClassNosFinalUniqCompact = $A(ftLatesClassNosFinal).uniq().without("");
	if(ftEarliesClassNosFinalUniqCompact.length > 0){
		for(var n=0; n<ftEarliesClassNosFinalUniqCompact.length; n++){
		var url1 = togLocationEarlies+ftEarliesClassNosFinalUniqCompact[n]+".html?time="+escape(timestamp);
		new Ajax.Request( url1, { method: 'get', onComplete: showResponseFlexiTog });
		}
	}
	if(ftLatesClassNosFinalUniqCompact.length > 0){
		for(var n=0; n<ftLatesClassNosFinalUniqCompact.length; n++){
		var url2 = togLocation+ftLatesClassNosFinalUniqCompact[n]+".html?time="+escape(timestamp);
		new Ajax.Request( url2, { method: 'get', onComplete: showResponseFlexiTog });	
		}
	}
}		

/* F2 Assign TOG or EOG Ajax response to a variable and call an Array building function */
function showResponseFlexiTog(originalRequest){	
var jsonRaw = originalRequest.responseText;
writeEandLArray(jsonRaw);
}
		
/* F3 put all offers into an Array */
/* Global variables and Arrays associated with F3 */
var ftEarliesAndLatesArray = new Array();
ftEarliesAndLatesArrayCount = 0;
var goneToWriteEandLMultiDimArrays = false;
/* Global variables and Arrays associated with F3 */
function writeEandLArray(jsonRaw){	
	if (jsonRaw.match(/^\{\"eog\"/) || jsonRaw.match(/^\{\"og\"/)) {
	jsonContent = eval("(" + jsonRaw + ")"); 
	ftEarliesAndLatesArray[ftEarliesAndLatesArrayCount] = jsonContent;
	ftEarliesAndLatesArrayCount++;
		if(ftEarliesAndLatesArray.length == ((ftLatesClassNosFinalUniqCompact.length) + (ftEarliesClassNosFinalUniqCompact.length))){
		writeEandLMultiDimArrays(ftEarliesAndLatesArray);
		goneToWriteEandLMultiDimArrays = true;
		}
	setTimeout("timerForBadTogs(ftEarliesAndLatesArray)",(ftEarlies.length + ftLates.length) * 400);
	}	
}

function timerForBadTogs(ftEarliesAndLatesArray){
	if(goneToWriteEandLMultiDimArrays == false){
	writeEandLMultiDimArrays(ftEarliesAndLatesArray);
	}
}

/* F4 */
function writeEandLMultiDimArrays(ftEarliesAndLatesArray){
	for(o=0; o<ftEarlies.length; o++){// For each element
	var myftEarliesElement = ftEarlies[o];
	ftEarlies[o] = new Array();// Extend element array to MDArray
	ftEarlies[o][0] = myftEarliesElement;
		for(p=0; p<ftEarliesAndLatesArray.length; p++){// For each object
			if(ftEarliesAndLatesArray[p].eog){// if object is an eog
				if(!ftEarlies[o][0].className) continue;
				if(ftEarlies[o][0].className.match("earlies" + ftEarliesAndLatesArray[p].eog.ogId)){// if object matches class
					if(ftEarlies[o][1]){
						if(parseInt(ftEarlies[o][1].eog.price) > parseInt(ftEarliesAndLatesArray[p].eog.price)){
						ftEarlies[o][1] = ftEarliesAndLatesArray[p];
						}
					}else{
					ftEarlies[o][1] = ftEarliesAndLatesArray[p];// make 2nd index the object
					}			
				}
			}
		}	
	}
	for(o=0; o<ftLates.length; o++){// For each element
	var myLatesElement = ftLates[o];
	ftLates[o] = new Array();// Extend element array to MDArray
	ftLates[o][0] = myLatesElement;
		for(p=0; p<ftEarliesAndLatesArray.length; p++){// For each object
			if(ftEarliesAndLatesArray[p].og){// if object is an og
				if(!ftLates[o][0].className) continue;
				if(ftLates[o][0].className.match("lates" + ftEarliesAndLatesArray[p].og.ogId)){// if object matches class
					if(ftLates[o][1]){
						if(parseInt(ftLates[o][1].og.price) > parseInt(ftEarliesAndLatesArray[p].og.price)){
						ftLates[o][1] = ftEarliesAndLatesArray[p];
						}
					}else{
					ftLates[o][1] = ftEarliesAndLatesArray[p];// make 2nd index the object
					}			
				}

			}
		}	

	}
	compareftEarliesAndLatesArrays(ftEarlies, ftLates);
}

/* F5 Make an array of all elements ftEarlies and lates and write out any earlies (these will be overwritten by any cheaper lates offers later*/
function compareftEarliesAndLatesArrays(ftEarlies, ftLates){

var allElementsOfferElementsArray = new Array();
var allElements = document.body.descendants();
	for(var i=0; i<allElements.length; i++){
		if(allElements[i].className.match(earliesRegEx) || allElements[i].className.match(latesRegEx)){
		allElementsOfferElementsArray[i] = allElements[i];
		}
	}
allElementsOfferElementsArrayComp = $A(allElementsOfferElementsArray).compact();//remove null and undefined entries	
	for(o=0; o<allElementsOfferElementsArrayComp.length; o++){	
	var myOfferElement = allElementsOfferElementsArrayComp[o];
	allElementsOfferElementsArrayComp[o] = new Array();// Extend element array to MDArray
	allElementsOfferElementsArrayComp[o][0] = myOfferElement;	
		for(r=0; r<ftEarlies.length; r++){
			if(allElementsOfferElementsArrayComp[o][0] != ftEarlies[r][0]) continue;
			if(allElementsOfferElementsArrayComp[o][0] == ftEarlies[r][0]){
			allElementsOfferElementsArrayComp[o][1] = ftEarlies[r][1];
			writeOutTheOffer(allElementsOfferElementsArrayComp[o][0], allElementsOfferElementsArrayComp[o][1]);/* write out the earlies offers */
			}
		}
	}
	selectLatesOrEarlies(allElementsOfferElementsArrayComp);
}

/* F6 send either the lates offer or the earlies offer to writeOutTheOffer */
function selectLatesOrEarlies(allElementsOfferElementsArrayComp){
	$A(allElementsOfferElementsArrayComp).each(function(el2) {//for each e & l element
		$A(ftLates).each(function(l2){//for each l elemen	
			if(el2[0] == l2[0]){//if the elements are the same element	
				if(el2[1] == null){//if the elements multi dim Array buddy is undefined
					el2[1] = l2[1];//the elements multi dim Array buddy is equal to the lates multi dim Array buddy
					return writeOutTheOffer(el2[0], el2[1]);//write out the lates offer
				}
				if(!l2[1]){
					return writeOutTheOffer(el2[0], el2[1]);	
				}
				if(el2[1].eog){
					if(parseInt(el2[1].eog.price) > parseInt(l2[1].og.price)){//If the og is cheaper than the eog
					return writeOutTheOffer(l2[0], l2[1]);//write out the og over the eog
					}
				}
				else{
					return writeOutTheOffer(el2[0], el2[1]);
				}
			}
		});	
	});
}

/* F7 Insert the offer details into their elements */
function writeOutTheOffer(elementRef, offerRef){
if(!offerRef) return false;
if(!elementRef) return false;
	if(offerRef.eog){//is it an og or is it an eog?	
	var ogId = offerRef.eog.ogId;
	var ogAirport = offerRef.eog.depGatewayName.replace("International","Int'l");
	    if(offerRef.eog.locDesc != ""){
		var ogLocation = offerRef.eog.locDesc;//work around to fix the change in arLocationName 
		}
		else{
		var ogLocation = offerRef.eog.arLocationName;
		}		
	var ogDurationDays = offerRef.eog.holidayDuration;
	var ogDurationWeeks = offerRef.eog.duration;
	var ogAccomcode = offerRef.eog.accomCode; // Use this format for linking to accommodation 
	var ogAccomName = offerRef.eog.accomName;
	var ogBoard = offerRef.eog.boardBasis;
	var ogDate = offerRef.eog.depDate;
	var ogCurrency = offerRef.eog.curSymbol;
	var ogPrice = offerRef.eog.price;
	var ogHref = offerRef.eog.href; // offer url
	var ogPeopleSharing = offerRef.eog.basedOn;
	var og = "eog"
	}
	else{	
	var ogId = offerRef.og.ogId;
	var ogAirport = offerRef.og.depGatewayName.replace("International","Int'l");
	var ogLocation = offerRef.og.arLocationName;
	var ogDurationDays = offerRef.og.holidayDuration;
	var ogDurationWeeks = offerRef.og.duration;
	var ogAccomcode = offerRef.og.accomCode; // Use this format for linking to accommodation 
	var ogAccomName = offerRef.og.accomName;
	var ogBoard = offerRef.og.boardBasis;
	var ogDate = offerRef.og.depDate;
	var ogCurrency = offerRef.og.curSymbol;
	var ogPrice = offerRef.og.price;
	var ogHref = offerRef.og.href; // offer url
	var ogPeopleSharing = offerRef.og.basedOn;
	var og = "og";	
	}
	
	
	
	if(elementRef.hasClassName("style1")){
		elementRef.innerHTML = '<div " class="promotionsActivityDetails"><div class="promotionsActivityDetailsDate">' + ogDate + '</div><div class="promotionsActivityDetailsDeparts">' + ogAirport + '</div><div class="promotionsActivityDetailsArrives">' + renameTOG(ogLocation, ogHref) + '</div><div class="promotionsActivityDetailsOffer"><div class="promotionsActivityDetailsBasis">' + ogDurationWeeks + ', based on ' + ogPeopleSharing + ' adults sharing</div><div class="promotionsActivityDetailsPrice"><a href="' + ogHref + '" class="arrow-link">from <strong>' + ogCurrency + ogPrice + '</strong><span class="arrowPlaceholder">&nbsp;</span></a></div><div class="clearer"></div></div></div>'
	}
	if(elementRef.hasClassName("style2")){
		elementRef.innerHTML = '<div class="dealFinder"><a href="' + ogHref + '" rel="noindex,nofollow" title="Link to book a holiday for ' + ogDurationWeeks + ' from ' + ogAirport + ' to ' + ogLocation + ' on ' + ogDate + '" id="og' + ogId + '"><span class="ogLocation">' + ogLocation + '</span><span class="ogAirport">' + ogAirport + '</span><span class="ogDate">' + ogDate + '</span><span class="ogDurationWeeks">' + ogDurationWeeks + '</span><span class="ogPeopleSharing">based on ' + ogPeopleSharing + ' sharing</span><span class="ogPrice"><span class="arrow-link"><strong>' + ogCurrency + ogPrice + '</strong><span class="arrowPlaceholder">&nbsp;</span></span></span></a></div>';
		alternateOfferStyle2();
	}
	if(elementRef.hasClassName("style3")){
		elementRef.innerHTML = '<div class="promotionsOffer"><div class="promotionsOfferResort"> <a href="' + TOGpromolink(ogLocation, ogHref) + '">' + renameTOG(ogLocation, ogHref) + '</a> </div><p>from</p><p class="promotionsOfferPrice">' + ogCurrency + ogPrice + '</p><p>per person</p>' +ogAirport + '<br/>' + ogDate + '<br/>' + ogDurationWeeks + ', based on<br/>' + ogBoard + ' people sharing</p><a href="' + ogHref + '"> <img alt="View details" src="/images/buttons/form/view_details_small.gif" width="150" height="50" alt="" /> </a> </div>';
	}
	if(elementRef.hasClassName("style4")){
	elementRef.innerHTML = '<div class="style4"><div><a href="http://www.falconholidays.ie/' + TOGpromolink(ogLocation, ogHref) + '"><span class="topTenOgLocation">' + renameTOG(ogLocation, ogHref) + '</span></a><span class="arrow-link"><span class="style4From"> from</span> <a href="http://www.falconholidays.ie/' + TOGpromolink(ogLocation, ogHref) + '">' + ogCurrency + ogPrice + '</a></span></div></div>';
	}
	if(elementRef.hasClassName("style4.1")){
	elementRef.innerHTML = '<div class="style4"><span class="topTenOgLocation">' + renameTOG(ogLocation, ogHref) + '</span><span class="arrow-link"><span class="style4From"> from</span> ' + ogCurrency + ogPrice + '</span></div>';
	}
	if(elementRef.hasClassName("style5")){		
			elementRef.innerHTML = '<div class="style5me clickBox"><span class="ogDate">' + ogDate + '</span><span class="ogAirport">' + ogAirport + '</span><span class="ogLocation">' + renameTOG(ogLocation, ogHref) + '</span><span class="ogDurationWeeks">' + ogDurationWeeks + '</span><span class="ogPeopleSharing">' + ogPeopleSharing + ' adults</span><span class="ogPrice"><a href="' + ogHref + '" class="arrow-link">from <strong>' + ogCurrency + ogPrice + '</strong><span class="arrowPlaceholder">&nbsp;</span></a></span></div>';
			alternateOfferStyle();/* Alternate table row background colour */
			clickableDivs()
	}
	if(elementRef.hasClassName("leadinPriceTog")){
		if(elementRef.firstChild){
			re = /\w{1,}/
			if(!re.test(elementRef.childNodes[0].nodeValue)){/* remove &nbsp; if present (/destinations) */
				elementRef.childNodes[0].nodeValue = "";
			}
			if(elementRef.childElements() != ""){
				elementRef.childElements().each(function(erce){
					if(erce.hasClassName("ogPrice")){
						if(ogCurrency == "&euro;"){	
						erce.innerHTML = '<span class="left">ROI from <strong>' + ogCurrency + ogPrice + '</strong></span>';	
						}
						else{
						erce.innerHTML = '<span class="right">NI from <strong>' + ogCurrency + ogPrice + '</strong></span>';	
						}
					}
				});
			}
			else{
				if(ogCurrency == "&euro;"){
				elementRef.innerHTML = elementRef.firstChild.nodeValue + '<span class="ogPrice" id="og' + ogId + '"><span class="left">ROI from ' + '<strong>' + ogCurrency + ogPrice + '</strong></span></span>';
				}
				else{
				elementRef.innerHTML = elementRef.firstChild.nodeValue + '<span class="ogPrice" id="og' + ogId + '"><span class="right">NI from ' + '<strong>' + ogCurrency + ogPrice + '</strong></span></span>';	
				}
			}
		}
	}
	if(elementRef.hasClassName("style7")){
		elementRef.innerHTML = '&nbsp;from ' + ogCurrency + ogPrice;	
	}
	if(elementRef.hasClassName("style8")){
		elementRef.innerHTML = '<div><a href="' + ogHref + '"><span class="style8Location">' + renameTOG(ogLocation, ogHref) + '</span><span class="style8Price"> from ' + ogCurrency + ogPrice + '</span></a></div>'		
	}
	if(elementRef.hasClassName("style9")){
	elementRef.innerHTML = '<div><p class="destinationDetails">' + ogDate + '<br/><strong>' + ogAirport + '</strong><br/>' + ogDurationWeeks + '<br/>based on ' + ogPeopleSharing + ' sharing<br/><a href="' + ogHref + '" class="arrow-link">From <span>' + ogCurrency + ogPrice + '</span> per person&nbsp;<span class="arrowPlaceholder">&nbsp;</span></a></p></div>'
	thirdStyle9Style(); /*add a class which sets margin to 0px for every 3rd offer in this style */
	}
	/*DestinationDayPrice*/
	if(elementRef.hasClassName("destinationDayPrice")){
	elementRef.innerHTML = '<a href="/last-minute-deals/" class="destination">'+ renameTOG(ogLocation, ogHref) +'</a><a href="/last-minute-deals/"><span class="togDate">'+ dayDateMonth(ogDate) +'</span><span class="togPrice">' + ogCurrency + ogPrice +'</span></a>'
	}
	
	function dayDateMonth(ogDate){
		var day = ogDate.substring(0,3);
		var date = ogDate.substring(3,6);
		var month = ogDate.substring(7,11);
		var dayDateMonth = day+" "+date+" "+month;
		return dayDateMonth;
		}
	
}

/* alternate the style of the table style offers by adding a class */
function alternateOfferStyle(){
var odd = false;
	$$(".style5").each(function(s5){
		if (odd == true) {
        s5.addClassName("style5odd");
        odd = false;
        } 
		else{
        odd = true;
        }						
	});
}

function alternateOfferStyle2(){
var odd = false;
	$$(".style2").each(function(s2){
		if (odd == true) {
        s2.addClassName("dealFinderOdd");
        odd = false;
        } 
		else{
        odd = true;
        }						
	});
}

/* Every 3rd tog style9 will have a class added to it which will remove the right margin therefore allowing it to fit a 3 column main content box tab container
function thirdStyle9Style(){
	var thirdStyle9StyleCount = 0;
	$$(".destinationDetails").each(function(s9){
		if (thirdStyle9StyleCount == 2) {
        s9.addClassName("thirdStyle9");
        thirdStyle9StyleCount = 0;
        } 
		else{
        thirdStyle9StyleCount++;
        }						
	});
} */

/* Sun array only. Works as above */
TOGdests = new Array();
TOGdests[0] = new Array("More destinations","","destinations/");
TOGdests[1] = new Array("Algarve","","holidays/algarve-holidays/");
TOGdests[2] = new Array("Faro","Algarve","holidays/algarve-holidays/");
TOGdests[3] = new Array("Bulgaria","","holidays/bulgaria-bourgas-holidays/");
TOGdests[4] = new Array("Almeria","Costa de Almeria","holidays/costa-de-almeria-holidays/");
TOGdests[5] = new Array("Costa de Almeria","Costa de Almeria","holidays/costa-de-almeria-holidays/");
TOGdests[6] = new Array("Costa Daurada","Costa Dorada","holidays/costa-dorada-holidays/");
TOGdests[7] = new Array("Costa Dorada","","holidays/costa-dorada-holidays/");
TOGdests[8] = new Array("Costa del Sol","","holidays/costa-del-sol-holidays/");
TOGdests[9] = new Array("Costa Del Sol","Costa del Sol","holidays/costa-del-sol-holidays/");
TOGdests[10] = new Array("Costa de la Luz","","holidays/costa-de-la-luz-holidays/");
TOGdests[11] = new Array("Crete","","holidays/crete-holidays/");
TOGdests[12] = new Array("Cyprus","","destinations/cyprus-holidays/");
TOGdests[13] = new Array("Egypt","","destinations/egypt-holidays/");
TOGdests[14] = new Array("Fuerteventura","","holidays/fuerteventura-holidays/");
TOGdests[15] = new Array("Gran Canaria","","holidays/gran-canaria-holidays/");
TOGdests[16] = new Array("Ibiza","","holidays/ibiza-holidays/");
TOGdests[17] = new Array("Italy","","destinations/italy-holidays/");
TOGdests[18] = new Array("Jamaica","","holidays/jamaica-holidays/");
TOGdests[19] = new Array("Lanzarote","","holidays/lanzarote-holidays/");
TOGdests[20] = new Array("Lapland","","holidays/lapland-holidays/");
TOGdests[21] = new Array("Majorca","","holidays/majorca-holidays/");
TOGdests[22] = new Array("Mahon","Menorca","holidays/menorca-holidays/");
TOGdests[23] = new Array("Menorca","","holidays/menorca-holidays/");
TOGdests[24] = new Array("Neapolitan Riviera","N. Riviera","holidays/neapolitan-riviera-holidays/");
TOGdests[25] = new Array("Palma","Majorca","holidays/majorca-holidays/");
TOGdests[26] = new Array("Red Sea","Egypt","destinations/egypt-holidays/");
TOGdests[27] = new Array("Tenerife","","holidays/tenerife-holidays/");
TOGdests[28] = new Array("Tunisia","","holidays/tunisia-holidays/");
TOGdests[29] = new Array("Turkey","","destinations/turkey-holidays/");
TOGdests[30] = new Array("Zante","","holidays/zante-holidays/");
/* tog renaming */
function renameTOG(TOGdestinationToWrite, offerHref) {
// If the second or third variable is the same as the first, you should omit it!
	for (TOGloopcounter in TOGdests) {		
	var TOGtempvar = TOGdests[TOGloopcounter][0];
		if (TOGdestinationToWrite.indexOf(TOGtempvar) >= 0) {
			if (TOGdests[TOGloopcounter][1] != "") {
			TOGdestinationToWrite = TOGdests[TOGloopcounter][1];
			}
			else { 
			TOGdestinationToWrite = TOGdests[TOGloopcounter][0] 
			}
		break;
		}
		else{
			if(TOGloopcounter == TOGdests.length-1){// if ogLocation is not in TOGdests
			TOGdestinationToWrite = TOGdestinationToWrite;
			}
		}
	}
return TOGdestinationToWrite;
} //renameTOG ends

function TOGpromolink(TOGdestinationToWrite, offerHref) {
var TOGpromopage;
	for (TOGloopcounter in TOGdests) {
	var TOGtempvar = TOGdests[TOGloopcounter][0];
		if (TOGdestinationToWrite.indexOf(TOGtempvar) >= 0) {
			if (TOGdests[TOGloopcounter][2] != "") {
			TOGpromopage = TOGdests[TOGloopcounter][2];
			}
			else { 
			TOGpromopage = TOGdests[TOGloopcounter][0] 
			}
		break;
		}
		else{
			if(TOGloopcounter == TOGdests.length-1){// if ogLocation is not in TOGdests
			TOGpromopage = "destinations/";
			}
		}
	}
TOGpromopage = TOGpromopage.toLowerCase();
return TOGpromopage;
}
/* End of tog renaming */

/* makes all of div clickable, linking to the first href found within the row. You simply need to add the class 'clickBox' */
function clickableDivs(){
if (!document.getElementsByTagName) return false; //added to test the browsers DOM compatibility
if (!document.getElementsByTagName('div')) return false; //added to test for any divs
var divs = document.getElementsByTagName('div');
	for(var i=0,j=divs.length;i<j;i++){
		if (divs[i].className.match('clickBox')){ // .match to deal with multiple class names
		if (!divs[i].getElementsByTagName('a')[0]) continue; // to ensure no errors if href is not present
  		divs[i].style.cursor = "pointer"; // change the cursor to a pointer if onclick is applied
   			divs[i].onclick = function (){
   			window.location = this.getElementsByTagName('a')[0].href; //regular link
   			}
  		}
 	}
}

addLoadEvent(clickableDivs);