var arrCompareCount = new Array();
var arrShorListCount = new Array();
var globCompCount = 0;
var globShorLstCount = 0;

var player = '<div id="boxB" class="videoBox" style="display:none">';
player += '<div><table id="header"><tr><td id="field1">&nbsp;</td><td id="field2" onmousedown="dragStart(event, '
		+ "'boxB'"
		+ ')"><a onclick="CloseMe('
		+ "'boxB'"
		+ ')">Close Player</a> Click here to drag the screen</td></tr></table></div>';
player += '<div id="content" class="content">';
player += '</div>';
player += '</div>';

function popFullView(elementId) {
	document.getElementById("" + elementId).style.display = 'block';
}

function hideFullView(elementId) {
	document.getElementById("" + elementId).style.display = 'none';
}
function goBack() {
	var browserName = navigator.appName;
	if (browserName == 'Netscape') {
		history.go(-1);
	} else {
		window.location.reload(history.go(-1));
	}
}
function embedVideoPlayer(elementId) {
	while (!(document.getElementById("boxB") == 'undefined' || document.getElementById("boxB") == '' || document.getElementById("boxB") == null)) {
		document.getElementById("boxB").parentNode.removeChild(document.getElementById("boxB"));
	}
	document.getElementById(elementId).innerHTML += player;
}
function hideText(id, text) {
	var elem;
	elem = document.getElementById(id);
	if (elem.value == text) {
		elem.value = '';
	}
}

function showText(id, text) {
	var elem;
	elem = document.getElementById(id);
	if (elem.value == '') {
		elem.value = '' + text;
	}
}

function viewLink(resultId) {
	document.getElementById('updateRecentlyViewedList').value = resultId;
	// document.forms["holidayForm_main"].submit();
}


function showMessage(type) {
	if (type == 'SHORTLIST') {
		alert("Your Shortlist is currently empty. To add a holiday to your Shortlist, click the 'Add to Shortlist' link. To view any Saved Shortlists, please login.");
	} else if (type == 'COMPARISONLIST') {
		alert("You have not selected any holidays to compare. To select a holiday, click the Compare tick box. You can compare a maximum of 5 holidays at a time.");
	}
}
function openHolidayPopup(resultId, originalRequestURI, formName) {
	document.getElementById('updateRecentlyViewedList').value = resultId;
	if (originalRequestURI.indexOf('?') < 0) {
		originalRequestURI += "?";
	} else {
		originalRequestURI += "&";
	}
	var url = originalRequestURI + "result=" + resultId + "&reloadParent=0&formName="+formName;
	window
			.open(url, 'Holiday',
					'menubar=no,width=630,height=600,toolbar=no,scrollbars=yes,resizable=yes');
}

function openHolidayPopup1(resultId, originalRequestURI) {
	//document.getElementById('updateRecentlyViewedList').value = resultId;
	if (originalRequestURI.indexOf('?') < 0) {
		originalRequestURI += "?";
	} else {
		originalRequestURI += "&";
	}
	var url = originalRequestURI + "result=" + resultId + "&reloadParent=0";
	window
			.open(url, 'Holiday',
					'menubar=no,width=630,height=600,toolbar=no,scrollbars=yes,resizable=yes');
}

function changeTabView(id, resortLatitude, resortLongitude,
		accommodationLatitude, accommodationLongitude, tab) {
	var tabArr = new Array(5);
	tabArr[0] = "DETAILS";
	tabArr[1] = "MEDIA";
	tabArr[2] = "MAPS";
	tabArr[3] = "FACILITIES";
	tabArr[4] = "REVIEWS";
	tabArr[5] = "DEALS";

	for (x = 0; x < 6; x++) {
		var current = document.getElementById(id + "_" + tabArr[x]);
		var currentTab = document.getElementById(id + "_TAB_" + tabArr[x]);
		if (!(current == null || current == 'undefined')
				&& !(currentTab == null || currentTab == 'undefined')) {
			if (tab == tabArr[x]) {
				current.style.display = 'block';
				currentTab.style.display = 'block';
				if (document.all && !window.opera && !window.XMLHttpRequest){
					currentTab.style.position = 'fixed';
				}
			} else {
				current.style.display = 'none';
				currentTab.style.display = 'none';
			}
		}

	}
	if (tab == "MAPS") {
		if (resortLatitude != '' && resortLongitude != '') {
			displayMultiMap(id, resortLatitude, resortLongitude,
					accommodationLatitude, accommodationLongitude);
		}
	}
	if (tab == "MEDIA") {
		embedVideoPlayer(id + "_VIDEO");
	}
}

function setVarAndSubmit(action, idx, sizeOfComparisonList,
		maxComparisionItineraries, currentResultId) {
	var sizeCurrent = "" + sizeOfComparisonList;
	var sizeMax = "" + maxComparisionItineraries;

	if (action == "ADD" && sizeCurrent == sizeMax) {
		alert("You can compare a maximum of 5 holidays at any one time");

		if (("" + document.forms["holidayForm_compare"].checkedResults.length) == "undefined") {
			document.forms["holidayForm_compare"].checkedResults.checked = false;
		} else
			document.forms["holidayForm_compare"].checkedResults[idx].checked = false;

		var top = document.getElementById(currentResultId).offsetTop;
		var left = document.getElementById(currentResultId).offsetLeft;
		window.scrollTo(left, top);
		return false;
	} else {
		document.getElementById("resultToBeUpdatedInComparisonList").value = currentResultId;
		document.getElementById("updateComparisonList").value = action;
		var originalRequestURI = document.getElementById("compareSuccessUrl").value;
		if (originalRequestURI.indexOf('?') < 0) {
			originalRequestURI += "?";
		} else {
			originalRequestURI += "&";
		}
		document.getElementById("compareSuccessUrl").value = originalRequestURI
				+ "scrollTo=" + currentResultId;
		originalRequestURI = document.getElementById("compareErrorUrl").value;
		if (originalRequestURI.indexOf('?') < 0) {
			originalRequestURI += "?";
		} else {
			originalRequestURI += "&";
		}
		document.getElementById("compareErrorUrl").value = document
				.getElementById("compareErrorUrl").value;
		document.forms["holidayForm_compare"].submit();
	}
}

//Gets called called from onclick of the compare check box 

function setCompareProps(sourceScreen, resultIndex, sizeOfComparisonList,
		maxComparisionItineraries, currentResultId) {

	var sizeMax = maxComparisionItineraries;
	var currID = "";
	var actionType = "";
	var altFlightsSpanID = "fromAltFlightsPageSpanID";

	// addded for search amends FF
    var addLink="";
	var addLink2x2="";
	
   
	if (sourceScreen == "ALTERNATEFLIGHTS") {
		currID = "compChkBx_" + resultIndex;
	} else {
		currID = "compChkBx_" + currentResultId;
		addLink = "addlink_"    + currentResultId;
		addLink2x2 = "addlink"   + currentResultId;
	   
		
	}

	var compareChkBoxObj = document.getElementById(currID);

	if (sizeOfComparisonList > globCompCount) {
		globCompCount = sizeOfComparisonList;
	}

	if (compareChkBoxObj.checked == true  ) {
			
				actionType = "ADD";
				if(document.getElementById(addLink)!=null)
		{           
					document.getElementById(addLink).style.display='block';}

      if(document.getElementById(addLink2x2)!=null)
		{ 
		  document.getElementById(addLink2x2).style.display='block';}
				
	} else if (compareChkBoxObj.checked == false) {
			
				actionType = "REMOVE";
				if(document.getElementById(addLink)!=null)
		{document.getElementById(addLink).style.display='none';}
				if(document.getElementById(addLink2x2)!=null)
		{document.getElementById(addLink2x2).style.display='none';}
		
	}
	if (actionType == "ADD" && globCompCount >= sizeMax) {
		alert("You can compare a maximum of 5 holidays at any one time");
		if(document.getElementById(addLink)!=null)
		{document.getElementById(addLink).style.display='none';}
		if(document.getElementById(addLink2x2)!=null)
		{document.getElementById(addLink2x2).style.display='none';}
		document.getElementById(currID).checked=false;
		return false;
	} else {
		var originalRequestURI = document.getElementById("compareSuccessUrl").value;
		if (originalRequestURI.indexOf('?') < 0) {
			originalRequestURI += "?";
		} else {
			originalRequestURI += "&";
		}
		document.getElementById("compareSuccessUrl").value = originalRequestURI
				+ "scrollTo=" + currentResultId;
		originalRequestURI = document.getElementById("compareErrorUrl").value;
		if (originalRequestURI.indexOf('?') < 0) {
			originalRequestURI += "?";
		} else {
			originalRequestURI += "&";
		}
		document.getElementById("compareErrorUrl").value = document
				.getElementById("compareErrorUrl").value;

		if (sourceScreen == "SEARCH") {
			//Request is from the Compare check box on List search & holiday details POP up
			updateCompareList(actionType, currentResultId, document
					.getElementById("compareSuccessUrl").value, document
					.getElementById("compareErrorUrl").value);

		} else if (sourceScreen == "ALTERNATEFLIGHTS") {
			// the following block gets execetued if the request is from onclick of the checkbox on
			// 1. Alternate Flights
			// 2. More Info pop up on / from alternate flights screen. (POP
			// screen sends "sourceScreen" as "SEARCH")

			updateCompareList_AltFlight(actionType, "masterPackage", document
					.getElementById("compareSuccessUrl").value, document
					.getElementById("compareErrorUrl").value);

		}

		if (actionType == "ADD") {
			globCompCount++;
			if (document.getElementById("holDetPopSpanID")

					|| document.getElementById("holInfoPopSpanID")) {
				if (window.opener.document.getElementById(currID)) {
					window.opener.document.getElementById(currID).checked = true;
				}
			}
		} else if (actionType == "REMOVE") {
			globCompCount--;
			if (document.getElementById("holDetPopSpanID")
					|| document.getElementById("holInfoPopSpanID")) {
				if (window.opener.document.getElementById(currID)) {
					window.opener.document.getElementById(currID).checked = false;
				}
			}
		}
	}
}

function submitSelectHoliday(index, formName) {
	document.getElementById('updateRecentlyViewedList').value = index;
	document.forms[formName].selectHolidayIndex.value = index;
	document.forms[formName].click();
	return true;
}


function tcSubmitSelectHoliday(index, formName) {
	document.getElementById('updateRecentlyViewedList').value = index;
	if(document.forms[formName]) document.forms[formName].selectHolidayIndex.value = index;
	
	return true;
}

//function to submit in the parent window from the pop up [popup will be closed].
function closePopupAndSubmit(index, url, formName) {
	document.getElementById('updateRecentlyViewedList').value = index;
	window.opener.document.forms[formName].selectHolidayIndex.value = index;
	window.opener.document.forms[formName].selectHoliday.click();
	window.close();
}

function removeFromCompareList(action, packageID, sizeOfCompList, columnIndex) {
	var originalRequestURI = document.getElementById("compareSuccessUrl").value;
	if (originalRequestURI.indexOf('?') < 0) {
		originalRequestURI += "?";
	} else {
		originalRequestURI += "&";
	}
	document.getElementById("compareSuccessUrl").value = originalRequestURI
			+ "scrollTo=" + packageID;
	originalRequestURI = document.getElementById("compareErrorUrl").value;
	if (originalRequestURI.indexOf('?') < 0) {
		originalRequestURI += "?";
	} else {
		originalRequestURI += "&";
	}
	document.getElementById("compareErrorUrl").value = document
			.getElementById("compareErrorUrl").value;

	// make the ajax call
	updateCompareList(action, packageID, document
			.getElementById("compareSuccessUrl").value, document
			.getElementById("compareErrorUrl").value);

	// no. of rows is hardcoded as. it is a fixed count(ie. rows).
	removeTableColumn(columnIndex, 15);
}

/* 
 The following method removes a column from a table. The column index is the input to this method.
 Column id & Row id should be of the form : col_0, col_1, col_3; row_0,row_1, row_2 etc
 */

function removeTableColumn(colIndex, noOfRows) {

	for ( var i = 0; i < noOfRows+1; i++) {
		var rowObj = document.getElementById("row_" + i);
		var cellObj = document.getElementById("col_" + colIndex);
		if (cellObj.cellIndex >= 0)
			rowObj.deleteCell(cellObj.cellIndex);
	}

}

function updateRoomAllocation(roomKey, resultId, roomId) {

	AjaxSearchResultTools
			.updatePackageRoomAllocation(resultId, roomId, roomKey);
}

function updateAlternateFlightPackageRoomAllocation(roomKey, resultId, roomId) {

	AjaxSearchResultTools.updateAlternateFlightPackageRoomAllocation(resultId,
			roomId, roomKey);
	document.getElementById('updateAJAXButton').style.display = 'block';
	document.getElementById('buttonDiv').style.display = 'none';
}

function clearRB(id) {
	for ( var i = 0; i < 10; i++) {

		if (document.getElementById("room" + i + "_" + id) != null) {
			if (document.getElementById("room" + i + "_" + id).checked == true) {
				document.getElementById("room" + i + "_" + id).checked = false;
			}
		}

	}

}

function clearCheaperRoom(id) {

	for ( var i = 0; i < 10; i++) {
		if (document.getElementById("room_defaultRoom_" + id) != null) {
			if (document.getElementById("room_defaultRoom_" + id).checked == true) {
				document.getElementById("room_defaultRoom_" + id).checked = false;
			}
		}
	}

}

function addToShortlist(sizeOfShortList, resultIndex) {
	var sizeCurrent = "" + sizeOfShortList;
	x = document.getElementById("anchor_" + resultIndex);

	if (sizeCurrent == '10') {
		alert("You can Shortlist a maximum of 10 holidays at any one time.");
		x.href = "#";
		return false;
	} else {
		return true;
	}
}

//Gets called called from onclick of the ADD/REMOVE shortlist link

function addToShortList_Search(resultIndex, selectedID, shorListURL,
		sizeOfShortList) {

	var spanID = "shrtLstSpanID_" + selectedID;
	var anchorID = "anchor_" + selectedID;
	var anchorObj = document.getElementById(anchorID);
	var spanObj = document.getElementById(spanID);
	var action = "";
	var sizeCurrent = "";
	// alert(sizeOfShortList);

	if (sizeOfShortList > globShorLstCount) {
		globShorLstCount = sizeOfShortList;
	}

	//sizeCurrent = globCompCount;
	var packDivID = "packageDiv_" + resultIndex; // this id is set on
	// shortlistItems.jsp

	if (!document.getElementById(packDivID)) // search result page or
	// alternate flights screen
	{
		if (anchorObj.innerHTML.indexOf("Add") != -1) {
			if (globShorLstCount >= 10) {
				alert("You can Shortlist a maximum of 10 holidays at any one time.");
				// anchorObj.href = "#";
				// globShorLstCount--
				return false;
			} else {
				action = "Add";
				ajaxAddToShortList(action, selectedID, shorListURL, resultIndex);
				globShorLstCount++;
				spanObj.innerHTML = "Shortlisted / ";
				anchorObj.innerHTML = "Remove from Shortlist";
				if (document.getElementById("holDetPopSpanID")
						|| document.getElementById("holInfoPopSpanID")) {
					if (window.opener.document.getElementById(spanID)) {
						window.opener.document.getElementById(spanID).innerHTML = "Shortlisted / ";
						window.opener.document.getElementById(anchorID).innerHTML = "Remove from Shortlist";
					}
				}
			}
		} else if (anchorObj.innerHTML.indexOf("Remove") != -1) {
			action = "Remove";
			ajaxAddToShortList(action, selectedID, shorListURL, resultIndex);
			globShorLstCount--;
			spanObj.innerHTML = "";
			anchorObj.innerHTML = "Add to Shortlist";
			if (document.getElementById("holDetPopSpanID")
					|| document.getElementById("holInfoPopSpanID")) {
				if (window.opener.document.getElementById(spanID)) {
					window.opener.document.getElementById(spanID).innerHTML = "";
					window.opener.document.getElementById(anchorID).innerHTML = "Add to Shortlist";
				}
			}
		}

	} else { //my shortlist screen
		action = "Remove";
		document.getElementById(packDivID).style.display = "none";
		ajaxAddToShortList(action, selectedID, shorListURL, resultIndex);
	}
}

/**
 * This function shows and hides the div when required
 **/
function switchLayer(layer) {
	var elem, vis;
	elem = document.getElementById(layer);
	vis = elem.style; // if the style.display value is blank we try to figure
	// it out here

	if (vis.display == '' && elem.offsetWidth != undefined
			&& elem.offsetHeight != undefined) {
		vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? 'block'
				: 'none';

	} else {
		vis.display = (vis.display == '' || vis.display == 'block') ? 'none'
				: 'block';
	}

}

function goToResult(id) {
	//switchLayer('RoomAllocation_SV_'+id);switchLayer('RoomAllocation_FV_'+id);

	if (id != null && id != '') {
		var top = document.getElementById(id).offsetTop;
		var left = document.getElementById(id).offsetLeft;
		window.scrollTo(left, top);
	}
}

function addToShortList_AltFlights(resultIndex, masterPackID, shorListURL,
		sizeOfShortList, selectedPackageID) {

	var anchorObj = document.getElementById("anchor_" + selectedPackageID);
	var spanObj = document.getElementById("shrtLstSpanID_" + selectedPackageID);
	var action = "";
	var altFlightsSpanID = "fromAltFlightsPageSpanID";
	// var altFlightsSpanIDObj = document.getElementById(altFlightsSpanID);
	// var sizeCurrent=""+sizeOfShortList;

	if (sizeOfShortList > globShorLstCount) {
		globShorLstCount = sizeOfShortList;
	}

	if (anchorObj.innerHTML.indexOf("Add") != -1) {
		if (globShorLstCount >= 10) {
			alert("You can Shortlist a maximum of 10 holidays at any one time.");
			// anchorObj.href = "#";
			// globShorLstCount--
			return false;
		} else {
			action = "Add";
			ajaxAddToShortList_AltFlights(action, masterPackID, shorListURL,
					resultIndex);
			globShorLstCount++;
			spanObj.innerHTML = "Shortlisted / ";
			anchorObj.innerHTML = "Remove from Shortlist";

			/*
			 * //if the request is from the more info / holiday detail POP up on
			 * Alt Flights screen if(
			 * !document.getElementById("fromAltFlightsPageSpanID") &&
			 * window.opener.document.getElementById("fromAltFlightsPageSpanID")){ //
			 * currID = "compChkBx_"+resultIndex; //
			 * window.opener.document.getElementById(currID).checked = true;
			 * window.opener.spanObj.innerHTML ="Shortlisted / ";
			 * window.opener.anchorObj.innerHTML = "Remove from Shortlist"; }
			 */
		}
	} else if (anchorObj.innerHTML.indexOf("Remove") != -1) {
		action = "Remove";
		ajaxAddToShortList_AltFlights(action, selectedPackageID, shorListURL,
				resultIndex);
		globShorLstCount--;
		spanObj.innerHTML = "";
		anchorObj.innerHTML = "Add to Shortlist";

		/*
		 * //if the request is from the more info / holiday detail POP up on Alt
		 * Flights screen if(
		 * !document.getElementById("fromAltFlightsPageSpanID") &&
		 * window.opener.document.getElementById("fromAltFlightsPageSpanID")){ //
		 * currID = "compChkBx_"+resultIndex; //
		 * window.opener.document.getElementById(currID).checked = true;
		 * window.opener.spanObj.innerHTML ="";
		 * window.opener.anchorObj.innerHTML = "Add to Shortlist"; }
		 */
	}
}

function checkForEmptyList(srcOfReq, anchorID) {
	if (srcOfReq == 'SHORTLIST') {
		if (document.getElementById("shortLstSpanID")
				&& (document.getElementById("shortLstSpanID").innerHTML == '0')) {
			alert("Your Shortlist is currently empty. To add a holiday to your Shortlist,"
					+ "click the 'Add to Shortlist' link. To view any Saved Shortlists, please login.");
			return false;
		} else {
			document.getElementById(anchorID).href = '/search/holiday/myShortlist.jsp';
		}

	} else if (srcOfReq == 'COMPARE') {
		if (document.getElementById("compCountSpanID")
				&& (document.getElementById("compCountSpanID").innerHTML == '0')) {
			alert("You have not selected any holidays to compare. To select a holiday, click the Compare tick box."
					+ "You can compare a maximum of 5 holidays at a time.");
			return false;
		} else {
			document.getElementById(anchorID).href = '/search/holiday/myComparelist.jsp';
		}
	}
}
function showDealWait(id, flagged) {
	if(document.getElementById(id + '_DEALS')){
		var loadingDisplay = "<div class='main tab4main'><div class='dealsLoading'><img src='/images/siteElements/polling.gif' alt='Loading' /><img src='/images/siteElements/polling2.gif' alt='Hunting for the best deals available' /></div></div>";
		document.getElementById(id + '_DEALS').innerHTML = loadingDisplay;
	} else {
		tcShowDealWait(id, flagged);
	}
}
function find(resultId, month) {
	if(document.getElementById(resultId + '_DEALS')){
	var url = "/search/holiday/fragments/results/packageAvailability.jsp?result="
			+ resultId + "&month=" + month;

	AjaxSearchResultTools.getDeals(resultId, month, url, function(data) {
		dwr.util.setValue(resultId + "_DEALS", data, {
			escapeHtml : false
		});
	});
	} else {
		tcFindDeals(resultId, month);
	}
}


function find(resultId, month, flagged) {
	if(document.getElementById(resultId + '_DEALS')){
		var url = "/search/holiday/fragments/results/packageAvailability.jsp?result="
				+ resultId + "&month=" + month;

		AjaxSearchResultTools.getDeals(resultId, month, url, function(data) {
			dwr.util.setValue(resultId + "_DEALS", data, {
				escapeHtml : false
			});
		});
	} else {
		tcFindDeals(resultId, month, flagged);
	}
}

function loadingDeals(){
	var loadingDisplay = "<div class='main tab4main'><div class='dealsLoading'><img src='/images/siteElements/polling.gif' alt='Loading' /><img src='/images/siteElements/polling2.gif' alt='Hunting for the best deals available' /></div></div>";
	document.getElementById('acccontent').innerHTML = loadingDisplay;
}

function highlightTab(id){
	if(document.getElementById(id)){
		if(document.getElementById('selectedTab')){
			var className = document.getElementById('selectedTab').className;
			var index = className.indexOf('selected');
			className = className.substring(0, index);
			document.getElementById('selectedTab').innerHTML = "<a href='#' onclick='location.reload(true);'>"+document.getElementById('selectedTab').innerHTML+"</a>"
			document.getElementById('selectedTab').className = className;
			
		}
		document.getElementById(id).className = "content tab5selected";
		document.getElementById(id).innerHTML = "<img id='viewAvail' src='/images/siteElements/buttons/view-availability.jpg' />";
	}
}

function destinationDeals(accomCode, date, deepLinksRequired) {
	var url = "/deals/calendar.jsp?accomCode="+accomCode;
	
	if(deepLinksRequired){
		if(deepLinksRequired == 'true'){
			url = url+"&deepLinksRequired="+deepLinksRequired;
		}
	}

	AjaxSearchResultTools.getDestinationDeals(accomCode, date, url, function(data) {
		dwr.util.setValue("acccontent", data, {
			escapeHtml : false
		});
	});
}


function tcShowDealWait(package){
	var loadingDisplay = "<div class='dealsLoading'><img src='/images/siteElements/loading.gif' alt='Loading' /></div>";
	document.getElementById('extraContent_'+package).innerHTML = loadingDisplay;
}

function tcShowDealWait(package, flagged){
	var loadingDisplay = "<div class='dealsLoading'><img src='/images/siteElements/loading.gif' alt='Loading' /></div>";
	document.getElementById(getDivContainerID(flagged, package)).innerHTML = loadingDisplay;
}

function tcChangeTabView(id, package, flagged) {
	if(flagged != 'true') {
		//Normal Result
		  if(document.getElementById('overview_'+package)) document.getElementById('overview_'+package).className = 'overviewOff';
		  if(document.getElementById('alternativeDates_'+package)) document.getElementById('alternativeDates_'+package).className = 'alternativeOff';
		  if(document.getElementById('hotelDetails_'+package)) document.getElementById('hotelDetails_'+package).className = 'hotelDetailsOff';
		  if(document.getElementById('mapView_'+package)) document.getElementById('mapView_'+package).className = 'mapViewOff';
		  if(document.getElementById('customerView_'+package)) document.getElementById('customerView_'+package).className = 'customerReviewsOff';
		  if(document.getElementById('imageVideo_'+package)) document.getElementById('imageVideo_'+package).className = 'imageVideoOff';
		  if(document.getElementById('alternativeFlightsTab_'+package)) document.getElementById('alternativeFlightsTab_'+package).className = 'alternativeFlightsOff';

		  if(document.getElementById(id) && document.getElementById(id).className == 'overviewOff') document.getElementById(id).className = 'overviewOn';
		  if(document.getElementById(id) && document.getElementById(id).className == 'alternativeOff') document.getElementById(id).className = 'alternativeOn';
		  if(document.getElementById(id) && document.getElementById(id).className == 'hotelDetailsOff') document.getElementById(id).className = 'hotelDetailsOn';
		  if(document.getElementById(id) && document.getElementById(id).className == 'mapViewOff') document.getElementById(id).className = 'mapViewOn';
		  if(document.getElementById(id) && document.getElementById(id).className == 'customerReviewsOff') document.getElementById(id).className = 'customerReviewsOn';
		  if(document.getElementById(id) && document.getElementById(id).className == 'imageVideoOff') document.getElementById(id).className = 'imageVideoOn';
		  if(document.getElementById(id) && document.getElementById(id).className == 'alternativeFlightsOff') document.getElementById(id).className = 'alternativeFlightsOn';
		if(document.getElementById(id)) document.getElementById(id).style.height = "27px";
		  /**
		   * Fix for trip advisor reviews overridden by the above change of class names
		   */
			if(document.getElementById(id) && document.getElementById(id).className){
				if(document.getElementById(id).className != 'customerReviewsOn'){
					document.getElementById(package+'_taReviews').style.display='none';
				}else{
					document.getElementById(package+'_taReviews').style.display='block';
				}
			}
	} else {
		// Customer Fav Result
		if(document.getElementById('cf_overview_'+package)) document.getElementById('cf_overview_'+package).style.background = "url(/images/siteElements/overview-yellow.gif) no-repeat top left";
		if(document.getElementById('cf_alternativeDates_'+package)) document.getElementById('cf_alternativeDates_'+package).style.background = "url(/images/siteElements/alternative_dates_off.gif) no-repeat top left";
		if(document.getElementById('cf_hotelDetails_'+package)) document.getElementById('cf_hotelDetails_'+package).style.background = "url(/images/siteElements/favEle_11.gif) no-repeat top left";
		if(document.getElementById('cf_mapView_'+package)) document.getElementById('cf_mapView_'+package).style.background = "url(/images/siteElements/favEle_13.gif) no-repeat top left";
		if(document.getElementById('cf_customerView_'+package)) document.getElementById('cf_customerView_'+package).style.background = "url(/images/siteElements/favEle_15.gif) no-repeat top left";
		if(document.getElementById('cf_imageVideo_'+package)) document.getElementById('cf_imageVideo_'+package).style.background = "url(/images/siteElements/favEle_17.gif) no-repeat top left";
			
		if(document.getElementById(id) && document.getElementById(id).className == 'overview') document.getElementById(id).style.background = "url(/images/siteElements/favEle_07.gif) no-repeat top left";
		if(document.getElementById(id) && document.getElementById(id).className == 'alternativeDates') document.getElementById(id).style.background = "url(/images/siteElements/aldates-yellow.gif) no-repeat top left";
		if(document.getElementById(id) && document.getElementById(id).className == 'hotelDetails') document.getElementById(id).style.background = "url(/images/siteElements/hoteldetails-yellow.gif) no-repeat top left";
		if(document.getElementById(id) && document.getElementById(id).className == 'map') document.getElementById(id).style.background = "url(/images/siteElements/mapview-yellow.gif) no-repeat top left";
		if(document.getElementById(id) && document.getElementById(id).className == 'reviews') document.getElementById(id).style.background = "url(/images/siteElements/customerreviews-yellow.gif) no-repeat top left";
		if(document.getElementById(id) && document.getElementById(id).className == 'photosAndVideos') document.getElementById(id).style.background = "url(/images/siteElements/imagesvids-yellow.gif) no-repeat top left";
		if(document.getElementById(id)) document.getElementById(id).style.height = "27px";
		/**
		   * Fix for trip advisor reviews overridden by the above change of class names
		   */
	if(document.getElementById(id) && document.getElementById(id).className){
		if(document.getElementById(id).className != 'reviews'){
			document.getElementById(package+'_taReviews').style.display='none';
		}else{
			document.getElementById(package+'_taReviews').style.display='block';
		}
	}
}


}

function tcFindDeals(resultId, month) {
	var url = "/search/holiday/fragments/results/packageAvailability.jsp?result=" + resultId + "&month=" + month;

	AjaxSearchResultTools.getDeals(resultId, month, url, function(data) {
		dwr.util.setValue('extraContent_' + resultId, data, {
			escapeHtml : false
		});
	});
}

function tcFindDeals(resultId, month, flagged) {
	var url = "/search/holiday/fragments/results/packageAvailability.jsp?flagged="+ flagged +"&result=" + resultId + "&month=" + month;

	AjaxSearchResultTools.getDeals(resultId, month, url, function(data) {
		dwr.util.setValue(getDivContainerID(flagged, resultId), data, {
			escapeHtml : false
		});
	});
}

function displayOverview(id){
	if(document.getElementById('extraContent_' + id)) document.getElementById('extraContent_' + id).innerHTML ="";
}

function getDivContainerID(flagged, resultId){
	var unID = 'extraContent_' + resultId;
	if(flagged == 'true'){
		unID = 'cf_extraContent_' + resultId;
	}
	return unID;
}

function displayOverview(id, flagged){
	if(document.getElementById(getDivContainerID(flagged, id))) document.getElementById(getDivContainerID(flagged, id)).innerHTML = "";
}

function getTabContent(path, resultId){
	if(path){
		AjaxSearchResultTools.getContent(path, resultId, function(data) {
			dwr.util.setValue('extraContent_' + resultId, data, {
				escapeHtml : false
			});
		});
	}
}

function getTabContent(path, resultId, flagged){
	if(path){
		AjaxSearchResultTools.getContent(path, resultId, function(data) {
			dwr.util.setValue(getDivContainerID(flagged, resultId), data, {
				escapeHtml : false
			});
		});
	}
}


function getReviewTabContent(path, reviewNumber, resultId){
	if(path){
		if(reviewNumber){
			path = path + '?reviewItemNumber=' + reviewNumber;
		} else {
			path = path + '?reviewItemNumber=0';
		}
		AjaxSearchResultTools.getContent(path, resultId, function(data) {
			dwr.util.setValue('extraContent_' + resultId, data, {
				escapeHtml : false
			});
		});
	}
}

function getReviewTabContent(path, reviewNumber, resultId, flagged){
	if(path){
		if(reviewNumber){
			path = path + '?reviewItemNumber=' + reviewNumber;
		} else {
			path = path + '?reviewItemNumber=0';
		}
		AjaxSearchResultTools.getContent(path, resultId, function(data) {
			dwr.util.setValue(getDivContainerID(flagged, resultId), data, {
				escapeHtml : false
			});
		});
	}
}

function getMapTabContent(path, resultId, resortLatitude, resortLongitude, accomLattitude, accomLogitude){
	if(path){
		AjaxSearchResultTools.getContent(path, resultId, function(data) {
			dwr.util.setValue('extraContent_' + resultId, data, {
				escapeHtml : false
			});
					displayMultiMap(resultId, resortLatitude, resortLongitude, accomLattitude, accomLogitude);
		});
		

	}
}

function getMapTabContent(path, resultId, resortLatitude, resortLongitude, accomLattitude, accomLogitude, flagged){
	if(path){
		AjaxSearchResultTools.getContent(path, resultId, function(data) {
			dwr.util.setValue(getDivContainerID(flagged, resultId), data, {
				escapeHtml : false
			});
			displayMultiMap(resultId, resortLatitude, resortLongitude, accomLattitude, accomLogitude);
		});
		

	}
}

function getVideoTabContent(path, resultId, videoSrc){
	if(path){
		AjaxSearchResultTools.getContent(path, resultId, function(data) {
			dwr.util.setValue('extraContent_' + resultId, data, {
				escapeHtml : false
			});
			if(videoSrc){
				embedVideoPlayer(resultId + "_VIDEO");
				PlayVideo(videoSrc);
			}
		});
	}
}

function getVideoTabContent(path, resultId, videoSrc, flagged){
	if(path){
		AjaxSearchResultTools.getContent(path, resultId, function(data) {
			dwr.util.setValue(getDivContainerID(flagged, resultId), data, {
				escapeHtml : false
			});
			if(videoSrc){
				embedVideoPlayer(resultId + "_VIDEO");
				PlayVideo(videoSrc);
			}
		});
	}
}

function addPackageToHolidayShortList(id){
	if(id){
		AjaxSearchResultTools.reqAddToShortList('', id, '', function(data) {
			if(data == 'full'){
				alert('Sorry, you can only add 5 items to your shortlist');
			}
		});
		
		
		AjaxSearchResultTools.getContent('/common/fragments/holidayShortlistItems.jsp', id, function(data) {
	
			dwr.util.setValue('shortlistedPackages', data, {
				escapeHtml : false
			});
			
			updateShortlistCount(id)
		});
		
	}
}


function removePackageToHolidayShortList(id){
	if(id){
		AjaxSearchResultTools.reqRemoveFromShortList('', id, '');
		AjaxSearchResultTools.getContent('/common/fragments/holidayShortlistItems.jsp', id, function(data) {
			dwr.util.setValue('shortlistedPackages', data, {
				escapeHtml : false
			});
			updateShortlistCount(id)
		});
		
	}
}


function updateShortlistCount(id){
		AjaxSearchResultTools.getContent('/common/fragments/holidayShortlistCount.jsp', id, updateShortlistText);
		AjaxSearchResultTools.getContent('/search/holiday/fragments/results/updateShortlistLink.jsp', id, function(data){
			dwr.util.setValue('sl_'+id, data, {
				escapeHtml : false
			});
		
		});
}

function updateShortlistText (data){

	var shortlistCountElements = getElementsByClass('shortCount', null, 'span');
	
	if(shortlistCountElements){
		for(var i = 0; i < shortlistCountElements.length; i++){
			shortlistCountElements[i].innerHTML = data;
		}
	}
}


function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
function getAlternativeFlights(path, id){
	if(path && id){
		AjaxSearchResultTools.getContent(path, id, function(data) {
				document.getElementById('extraContent_' + id).innerHTML = data;
		});
	}

	document.getElementById(id+'_taReviews').style.display='none';
	
	
}

function getAlternativeFlights(path, id, flagged){
	if(path && id){
		AjaxSearchResultTools.getContent(path, id, function(data) {
				document.getElementById(getDivContainerID(flagged, id)).innerHTML = data;
		});
	}

	document.getElementById(id+'_taReviews').style.display='none';
	
	
}

function getAlternativeFlightPacakge(id, previousID){
	if(id){
		AjaxSearchResultTools.getMasterSearchResult('/search/holiday/fragments/results/masterPackage_1x1.jsp', id, function(data) {
				if(data != undefined && data != null){
					var t = document.createElement('div');
					if(data && data != ''){
						t.innerHTML = data;
					} else {
						t.innerHTML = 'Sorry your Session has timed out.'
					}
					document.getElementById('sr_' + previousID).innerHTML = '';
					document.getElementById('sr_' + previousID).appendChild(t);
				}
		});
	}
}



function getAlternativeFlightPacakge(id, previousID, flagged){
	if(id){
		AjaxSearchResultTools.getMasterSearchResult('/search/holiday/fragments/results/masterPackage_1x1.jsp', id, function(data) {
				if(data != undefined && data != null){
					var t = document.createElement('div');
					
					
					if(data && data != ''){
						t.innerHTML = data;
					} else {
						t.innerHTML = 'Sorry your Session has timed out.'
					}
					
					var uID = 'sr_' + previousID;
					if(flagged == 'true'){
						uID = 'cf_sr_' + previousID;
					}
					
					document.getElementById(uID).innerHTML = '';
					document.getElementById(uID).appendChild(t);
				}
		});
	}
}


function getAlternativeBoardBasis(id, previousID){
	if(id){
		AjaxSearchResultTools.getAlternativeBoardBasis('/search/holiday/fragments/results/masterPackage_1x1.jsp', previousID, id, function(data) {
				var t = document.createElement('div');
				if(data && data != ''){
					t.innerHTML = data;
				} else {
					t.innerHTML = 'Sorry your Session has timed out.'
				}
				document.getElementById('sr_' + previousID).innerHTML = '';
				document.getElementById('sr_' + previousID).appendChild(t);
				document.getElementById('sr_' + previousID).id='sr_'+id;
		});
	}
}

function getAlternativeBoardBasis(id, previousID, flagged){
	if(id){
		AjaxSearchResultTools.getAlternativeBoardBasis('/search/holiday/fragments/results/masterPackage_1x1.jsp?flagged='+flagged, previousID, id, function(data) {
				var t = document.createElement('div');
				
				
				if(data && data != ''){
					t.innerHTML = data;
				} else {
					t.innerHTML = 'Sorry your Session has timed out.'
				}
				
				var uID = 'sr_';
				if(flagged == 'true'){
					uID = 'cf_sr_';
				}
				document.getElementById(uID + previousID).innerHTML = '';
				document.getElementById(uID + previousID).appendChild(t);
				document.getElementById(uID + previousID).id=uID+id;
		});
	}
}


function displayShortlistCriteria(){
	AjaxSearchResultTools.getPageContent('/common/fragments/holidayShortlistItems.jsp', function(data) {
		dwr.util.setValue('shortlistedPackages', data, {
			escapeHtml : false
		});
	});
	AjaxSearchResultTools.getPageContent('/common/fragments/holidayShortlistCount.jsp', updateShortlistText);
}
function findTAReviews(id,accommCode,hasReviews){
var reviewIndex = 1;
if(document.getElementById(id + '_taReviews')){
//loadingReviews(id);
	var url = "/reviews/taReviews.jsp?currentResultId="
			+ id + "&accommCode=" + accommCode + "&reviewIndex="+reviewIndex + "&accomReviews="+hasReviews;

	AjaxSearchResultTools.getReviews(url, function(data) {
		dwr.util.setValue(id + "_taReviews", data, {
			escapeHtml : false
		});
	});
	}
}
/** F10200 Fix introduced to avoid content indexing by search engine spiders by fetching content via AJAX **/
function findTAReviewsForBrowsePages(divId,id,accommCode,pageName){
	var reviewIndex = 1;

	if(document.getElementById('extraContent_taReviews_'+divId)){
		
		var url = "/reviews/taReviews.jsp?currentResultId="
				+ id + "&accommCode=" + accommCode + "&reviewPageName="+pageName + "&reviewIndex="+reviewIndex;

		AjaxSearchResultTools.getReviews(url, function(data) {
			dwr.util.setValue('extraContent_taReviews_'+divId, data, {
				escapeHtml : false
			});
		});
		}
	}


function findNextReview(id,accommCode,reviewIndex,count){
if(reviewIndex != count){
reviewIndex++;
}
if(document.getElementById(id + '_taReviews')){
	var url = "/reviews/taReviews.jsp?currentResultId="
			+ id + "&accommCode=" + accommCode + "&reviewIndex=" + reviewIndex;

	AjaxSearchResultTools.getReviews(url, function(data) {
		dwr.util.setValue(id + "_taReviews", data, {
			escapeHtml : false
		});
	});
	}
}


function showReviews(id){
	if(document.getElementById(id+'_reviewDetails').style.display == 'block'){
		document.getElementById(id+'_reviewDetails').style.display='none';
		document.getElementById(id+'_readRevSpan').innerHTML="<b>Read Reviews</b>";
		
	}else{
		document.getElementById(id+'_reviewDetails').style.display='block';
		document.getElementById(id+'_readRevSpan').innerHTML="<b>Hide Reviews</b>";
	}
}

function showContent(id,index){
document.getElementById(id+'_contentSummary_'+index).style.display='none';
document.getElementById(id+'_reviewContent_'+index).style.display='block';
}

function hideContent(id,index){
document.getElementById(id+'_contentSummary_'+index).style.display='block';
document.getElementById(id+'_reviewContent_'+index).style.display='none';
}

function loadingReviews(resultId){
	var loadingDisplay = "<div class='main tab4main'><div class='dealsLoading'><img src='/images/siteElements/polling.gif' alt='Loading' /></div>";
	document.getElementById(resultId + "_taReviews").innerHTML = loadingDisplay;
}

function getReviewAccomContent(path, reviewNumber, resultId,filter){
	if(path){
		if(reviewNumber){
			path = path + '?reviewItemNumber=' + reviewNumber + "&filter=" + filter;
		} else {
			path = path + '?reviewItemNumber=0';
		}
		AjaxSearchResultTools.getPageContent(path, function(data) {
			dwr.util.setValue('extraContent_' + resultId, data, {
				escapeHtml : false
			});
		});
	}
}


function getReviewRatingFilter(path, filter, resultId, reviewNumber){
	if(path){
		if(filter){
			path = path + "?filter=" + filter + "&reviewItemNumber=1" ;
		} else {
			path = path + "?filter=reviews&reviewItemNumber=1";
		}
		AjaxSearchResultTools.getPageContent(path, function(data) {
			dwr.util.setValue('extraContent_' + resultId, data, {
				escapeHtml : false
			});
		});
	}
}


function readMoreReviews(id){
	window.open(id, 'Holiday','menubar=no,width=1030,height=700,left=100,top=200,toolbar=no,scrollbars=yes,resizable=yes');
}


function openHolidayPopupHolidayPlanner(resultId, originalRequestURI, formName) {
	if (originalRequestURI.indexOf('?') < 0) {
		originalRequestURI += "?";
	} else {
		originalRequestURI += "&";
	}
	var url = originalRequestURI + "result=" + resultId + "&reloadParent=0&formName="+formName;
	window
			.open(url, 'Holiday',
					'menubar=no,width=630,height=600,toolbar=no,scrollbars=yes,resizable=yes');
}

function submitRadioSort(elem){
	if(elem){
		var sortDropDowns = document.getElementsByName('sortBy');
		if(sortDropDowns){
			var sortOptions = sortDropDowns[0].options;
			if(sortOptions){
				for(var i = 0; i < sortOptions.length; i++){
					if(sortOptions[i].value == elem.value){
						sortDropDowns[0].selectedIndex = i;
						var formElems = document.getElementsByName('sortResultsForm');
						formElems[0].submit();
						break;
						
					}
				}
			}
		}
	}
}



function showHalfReviews(id) {
		document.getElementById(id+'_reviewDetails').style.display='none';
		
		document.getElementById(id+'_reviewShort').style.display="block";
}

function showFullReviews(id) {
	   document.getElementById(id+'_reviewDetails').style.display='block';
	   
	   document.getElementById(id+'_reviewShort').style.display="none";
}

