//common.js
window.console = { log: function() {} }

// ldeals
function displayhint(ob_airport){
	hint('Help: ','Price is from ' + ob_airport,event,0,false, 0, 'latedeals');
}

//Flash plugin detect
var flash = new Object();	
flash.installed = false;
if (navigator.plugins && navigator.plugins.length) {
	for (x=0; x < navigator.plugins.length; x++) {	
		if (navigator.plugins[x].name.indexOf('Shockwave Flash') != -1) {		
			flash.installed = true;					
			flash.version = eval(navigator.plugins[x].description.split('Shockwave Flash ')[1].split('.')[0]);					
			break;
		}
	}
} else if (window.ActiveXObject) {
	for (x = 2; x <= 20; x++) {
		try {
			oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + x + "');");
			if(oFlash) {		
				flash.installed = true;	
				flash.version = x;
			}
		}
		catch(e) {}
	}
}

flash.insertBOJ = function() {
	if(flash.installed && (flash.version >= 8)) {
 		flashObject = '<embed src="/flash/homepage.swf" menu="false" quality="high" FlashVars="sXmlPath=%2Fflash%2Fxml%2Fhomepage%2Exml" width="380px" height="188px" type="application/x-shockwave-flash" salign="T" bgcolor="#4299F0" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		document.write(flashObject);
		document.getElementById("noFlashContent").style.display = "none";
	} else {
		document.getElementById("noFlashContent").style.display = "block";
		document.getElementById("flashContent").style.display = "block";
	}	
}

flash.insertRotBanner = function() {
	if(flash.installed && (flash.version >= 8)) {
 		flashObject = '<embed src="/flash/Rotating_Banners.swf" wmode="transparent" menu="false" quality="high" FlashVars="sXmlPath=%2Fflash%2Fxml%2Fhomepage%2Exml" width="380px" height="188px" type="application/x-shockwave-flash" salign="T" bgcolor="#4299F0" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		document.write(flashObject);
		document.getElementById("noFlashContent").style.display = "none";
	} else {
		document.getElementById("noFlashContent").style.display = "block";
		document.getElementById("flashContent").style.display = "block";
	}	
}

flash.insertRotBannerIE = function() {
	if(flash.installed && (flash.version >= 8)) {
 		flashObject = '<embed src="/flash/Rotating_BannersIE.swf" wmode="transparent" menu="false" quality="high" FlashVars="sXmlPath=%2Fflash%2Fxml%2Fhomepage%2Exml" width="380px" height="188px" type="application/x-shockwave-flash" salign="T" bgcolor="#4299F0" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		document.write(flashObject);
		document.getElementById("noFlashContent").style.display = "none";
	} else {
		document.getElementById("noFlashContent").style.display = "block";
		document.getElementById("flashContent").style.display = "block";
	}	
}

flash.insertMap = function (country_id, boj, width, height) {
	if (flash.installed && (flash.version >= 8)) {
		var xmlfilename = "countries" + country_id;
		if (boj) {
			xmlfilename = "countries" + boj + country_id;
		}
		document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab##version=8,0,0,0\" width=\"" + width + "\" height=\"" + height + "\" id=\"map\" align=\"middle\">");
		document.write("<param name=\"allowScriptAccess\" value=\"sameDomain\" />");
		if(country_id == 22){
			document.write("<param name=\"movie\" value=\"/flash/map_de.swf\" />");
		}
		else{
			document.write("<param name=\"movie\" value=\"/flash/map.swf\" />");
		}
		document.write("<param name=\"quality\" value=\"high\" />");
		document.write("<param name=\"bgcolor\" value=\"#fcffee\" />");
		document.write("<param name=\"FlashVars\" value=\"sXmlPath=%2Fflash%2Fxml%2F" + xmlfilename + "%2Exml\" />");
		document.write("<embed src=\"/flash/map.swf\" quality=\"high\" FlashVars=\"sXmlPath=%2Fflash%2Fxml%2F" + xmlfilename + "%2Exml\" bgcolor=\"#fcffee\" width=\"" + width + "\" height=\"" + height + "\" name=\"map\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />");
		document.write("</object>");
	}
	else {
			//if flash is undetected and the BOJ page, write in the image map
			if (boj) {
		
		document.write("<img src=\"/images/misc/Web-Non-Flash-Map-BOJ.jpg\" width=\"710\" height=\"300\" border=\"0\" usemap=\"#MapBoj\" /><map name=\"MapBoj\" id=\"MapBoj\"><area shape=\"poly\" coords=\"70,138,83,138,93,140,106,142,111,152,149,155,157,158,155,165,121,166,114,178,106,186,71,144\" href=\"/q_search.cfm?search_mode=low_mid_high&region_id=8&boj=1\" alt=\"Florida\" /><area shape=\"poly\" coords=\"229,247,285,247,284,262,242,266,227,255\" href=\"/q_search.cfm?search_mode=low_mid_high&region_id=59&boj=1\" alt=\"Barbados\" /><area shape=\"poly\" coords=\"317,213,396,215,392,233,340,253,333,256\" href=\"/q_search.cfm?search_mode=low_mid_high&region_group_id=4&boj=1\" alt=\"Canary Islands\" /><area shape=\"poly\" coords=\"383,143,386,147,392,145,395,145,394,150,394,152,393,154,393,159,391,163,388,166,391,169,391,175,388,176,388,179,380,180,329,170,327,152\" href=\"/q_search.cfm?search_mode=low_mid_high&country_id=3&boj=1\" alt=\"Portugal\" /><area shape=\"poly\" coords=\"381,142,380,138,352,139,349,123,377,121,386,130,421,133,450,143,436,169,421,182,398,189,390,179\" href=\"/q_search.cfm?search_mode=low_mid_high&country_id=5&boj=1\" alt=\"Spain\" /><area shape=\"poly\" coords=\"468,154,468,172,502,177,510,177,510,184,436,188,433,177,448,153\" href=\"/q_search.cfm?search_mode=low_mid_high&region_group_id=3&boj=1\" alt=\"Balearic Islands\" /><area shape=\"poly\" coords=\"495,190,523,188,562,197,563,208,496,212,490,198\" href=\"/q_search.cfm?search_mode=low_mid_high&country_id=7&boj=1\" alt=\"Malta &amp; Gozo\" /><area shape=\"poly\" coords=\"479,129,477,124,472,118,475,111,485,106,492,107,497,101,506,101,509,104,516,105,515,110,508,114,508,124,510,128,515,130,519,140,529,147,544,156,539,164,538,172,529,176,526,163,518,170,505,174,485,170,481,148,490,148,495,144,495,137,492,133,492,129\" href=\"/q_search.cfm?search_mode=low_mid_high&country_id=15&boj=1\" alt=\"Italy\" /><area shape=\"poly\" coords=\"512,96,550,95,550,118,537,118,537,132,525,129,515,119\" href=\"/q_search.cfm?search_mode=low_mid_high&country_id=24&boj=1\" alt=\"Croatia\" /><area shape=\"poly\" coords=\"553,136,590,139,593,151,591,162,592,174,593,181,593,193,592,200,584,204,565,192,550,173\" href=\"/q_search.cfm?search_mode=low_mid_high&country_id=14&boj=1\" alt=\"Greece\" /><area shape=\"poly\" coords=\"596,156,600,133,623,125,692,146,697,153,701,157,701,161,701,165,703,170,703,177,703,182,652,188,630,189,609,189,599,191,595,163\" href=\"/q_search.cfm?search_mode=low_mid_high&region_id=40&boj=1\" alt=\"Turkey\" /><area shape=\"poly\" coords=\"592,195,594,206,641,206,649,191\" href=\"/q_search.cfm?search_mode=low_mid_high&country_id=6&boj=1\" alt=\"Cyprus\" /><area shape=\"poly\" coords=\"591,214,624,211,641,231,642,243,634,248,650,280,639,289,584,288,584,219\" href=\"/q_search.cfm?search_mode=low_mid_high&region_id=51&boj=1\" alt=\"Egypt\" /></map>");
			}
			//flash is undetected but not a best of james page, so write in an alternative image map
			else{
				document.write("<img src=\"/images/misc/Web-Non-Flash-Map.jpg\" border=\"0\" usemap=\"#Map\" /><map name=\"Map\" id=\"Map\"><area shape=\"poly\" coords=\"70,138,87,139,108,141,154,155,155,171,125,167,117,172,115,183,106,188,69,145\" href=\"/regions/Florida/\" alt=\"Florida\" /><area shape=\"poly\" coords=\"385,144,391,145,396,145,395,150,391,161,391,166,392,172,391,177,384,183,379,179,328,170,327,155\" href=\"/regions/algarve/\" alt=\"Portugal\" /><area shape=\"poly\" coords=\"381,144,346,137,347,119,421,133,451,142,451,148,437,156,431,163,432,169,429,178,418,183,399,190,390,180\" href=\"/spain-holidays.cfm\" alt=\"Spain\" /><area shape=\"poly\" coords=\"424,130,427,112,384,115,377,98,407,89,423,80,445,66,480,83,476,97,473,112,478,127,472,133,452,132,452,143,426,135\" href=\"/france-holidays.cfm\" alt=\"France\" /><area shape=\"poly\" coords=\"432,190,513,190,511,176,471,170,468,155,454,155,440,163,435,177,430,183\" href=\"/regions/TheBalearicIslands.cfm\" alt=\"Balearic Islands\" /><area shape=\"poly\" coords=\"231,248,283,246,282,259,246,266,229,261,223,251\" href=\"/regions/barbados/\" alt=\"Barbados\" /><area shape=\"poly\" coords=\"493,190,493,206,562,209,566,196,521,187\" href=\"/regions/malta/\" alt=\"Malta &amp; Gozo\" /><area shape=\"poly\" coords=\"376,60,370,56,364,54,335,54,332,40,372,37,377,31,384,31,395,32,398,39,396,51,390,58\" href=\"/regions/ireland/\" alt=\"Ireland\" /><area shape=\"poly\"coords=\"479,127,484,125,487,123,493,128,497,133,499,138,499,141,499,144,495,148,488,149,478,151,480,160,483,166,492,171,510,175,514,181,518,185,523,186,529,185,538,183,544,174,550,166,549,155,534,142,523,127,517,113,514,105,505,103,492,103,484,107,480,112,476,112,475,116,476,121\" href=\"/italy-holidays.cfm\" alt=\"Italy\" /><area shape=\"poly\" coords=\"512,93,550,95,551,117,537,119,532,120,537,128,538,136,525,127,512,103\" href=\"/regions/croatia/\" alt=\"Croatia\" /><area shape=\"poly\" coords=\"584,222,582,227,581,232,582,239,584,240,584,250,584,264,584,275,584,287,588,289,615,289,631,289,640,289,645,284,651,282,651,278,650,272,645,265,643,257,639,249,643,236,643,231,635,223,623,215,608,212,593,214,587,217\" href=\"/regions/egypt/\" alt=\"Egypt\" /><area shape=\"poly\" coords=\"394,214,317,212,316,235,336,257,375,246,392,230,398,222\" href=\"/regions/TheCanaryIslands.cfm\" alt=\"Canary Islands\" /><area shape=\"poly\" coords=\"551,137,595,137,593,153,592,156,593,165,594,168,595,174,595,184,592,200,583,201,575,197,568,192,561,186,554,180,551,166\" href=\"/greece-holidays.cfm\" alt=\"Greece\" /><area shape=\"poly\" coords=\"608,195,595,195,593,206,629,209,642,203,646,191,602,193\" href=\"/regions/cyprus/\" alt=\"Cyprus\" /><area shape=\"poly\" coords=\"596,156,612,151,605,140,603,129,623,128,641,128,658,128,680,136,695,149,702,157,702,172,706,178,703,185,694,188,675,188,664,188,654,187,651,187,644,185,633,187,632,189,625,189,616,189,609,189,606,189,599,180,596,164\" href=\"./regions/turkey/\" alt=\"Turkey\" /></map>");
				
			}
	}
}

flash.insertMiniOrlando = function() {
	if(flash.installed && (flash.version >= 8)) {
 		flashObject = '<embed src="http://www.ivc4.com/jamesvillas/jvnewbutton.swf" quality="high" wmode="transparent" flashvars="flv=http://www.ivc4.com/jamesvillas/orlando230x130.flv&video_duration=12&bufferSecs=6&linkTo=http://www.jamesvillas.co.uk/regions/florida/index.cfm?orlandovideo=yes" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="230" height="130"></embed>';
		document.write(flashObject);
	}	
}

flash.insertMiniGulfCoast = function() {
	if(flash.installed && (flash.version >= 8)) {
 		flashObject = '<embed src="http://www.ivc4.com/jamesvillas/jvnewbutton.swf" quality="high" wmode="transparent" flashvars="flv=http://www.ivc4.com/jamesvillas/gulf230x130.flv&video_duration=10&bufferSecs=6&linkTo=http://www.jamesvillas.co.uk/regions/florida/index.cfm?gulfcoastvideo=yes" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="230" height="130"></embed>';
		document.write(flashObject);
	}	
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function trim(stringToTrim){
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function animatePleaseWait(id) {	// Booking summary pages
	if (id == undefined) id = 'imgPleaseWait';
	if (document.getElementById(id)) document.getElementById(id).src = "/images/misc/progress.gif";
}						

function delayedPleaseWait() {
	window.setTimeout("pleaseWait()", 8000);
}			

function pleaseWaitSetup() {
	
	if (document.body.scrollWidth) {
		var docW = document.body.scrollWidth;
	} else {
		var docW = document.documentElement.offsetWidth;
		if (window.scrollMaxX) docW += window.scrollMaxX;
	}
	if (screen.width > docW) docW = screen.width - 25;
	var docH = (document.body.scrollHeight) ? document.body.scrollHeight : document.documentElement.offsetHeight;
	var vh = window.innerHeight || document.documentElement.clientHeight || document.getElementsByTagName('body')[0].clientHeight;
	var vw = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;

	var overlay = document.getElementById('fullPageOverlay');
	if (!overlay) {
		overlay = document.createElement("div");
		overlay.id = "fullPageOverlay";
		document.getElementsByTagName('body')[0].appendChild(overlay);
	}
	
	docW = screen.width;
	document.getElementsByTagName('body')[0].style.overflowX = "hidden";
	document.getElementsByTagName('html')[0].style.overflowX = "hidden";
	
	overlay.style.width = docW + "px";
	
	// If has debug page can be too high to do the transparent overlay (IE issue for large divs)
	if (docH > 10000) docH = 10000;
	overlay.style.height = docH + "px";				

	// IE6 uses position:absolute instead of fixed so need to take account of the user having scrolled down the page
	if (navigator.appVersion.indexOf("MSIE") != -1 && parseFloat(navigator.appVersion.split("MSIE")[1]) <= 6) {
		var scrollTop = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
		
		var elem = document.getElementsByTagName("select");
		for (var i=0;i<elem.length;i++) {
			elem[i].style.visibility = "hidden";
		}
		
	} else {
		var scrollTop = 0;
	}
	
	var dimens = function(width, height, scrollTop) {
			this.width = width;
			this.height = height;
			this.scrollTop = scrollTop;
	}
	
	return new dimens(vw, vh, scrollTop);
}

function paste_handle()	{
	window.clipboardData.clearData();
}

function show_full_image(image) {
	document.getElementById('full_image').src = image;
}

function popup(url) {
	var popup = window.open(url,'jvhwindow','height=450,width=450,resizable=yes,scrollbars=yes');
	if (window.focus) {popup.focus()}
}

function roll(element) {
	if (element) {
		var len = element.src.length;
		var state = element.src.substring(len-5,len-4);
		var new_state = (state == "a") ? "b" : "a";
		element.src = element.src.substring(0, len-5) + new_state + element.src.substring(len-4);
	}
}

var tempX = 0, tempY = 0;

function getMouseXY(e) {
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		tempX = e.pageX;
		tempY = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		tempX = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		tempY = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
}


// Rotating banner images
function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

function changeOpac(opacity, id) {
	opac = (opacity == 100)?99:opacity;
	var object = document.getElementById(id).style;
	object.opacity = (opac / 100);
	object.MozOpacity = (opac / 100);
	object.KhtmlOpacity = (opac / 100);
	object.filter = "alpha(opacity=" + opac + ")";
} 

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	orig_src = document.getElementById(imageid).src;
	changeOpac(0, imageid);
	document.getElementById(imageid).src = imagefile;
	document.getElementById(divid).style.backgroundImage = "url(" + orig_src + ")";
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function submitForm(){
	if(checkDate()) {
		document.quicksearch_daily.region_id.value = document.getElementById("region_select").value;
		document.quicksearch_daily.resort_id.value = document.getElementById("resort_select").value;
		document.quicksearch_daily.duration.value = document.getElementById("duration_select").options[document.getElementById("duration_select").selectedIndex].value;
		document.quicksearch_daily.action = form_action;
		document.quicksearch_daily.submit();
	}
}



/*** Print Preview functions ***/
	function addLoadEvent(func) {
	  var oldonload = window.onload;
	  if (typeof window.onload != 'function') {
		window.onload = func;
	  } else {
		window.onload = function() {
		  if (oldonload) {
			oldonload();
		  }
		  func();
		}
	  }
	}

	addLoadEvent( function(){ add_print_link( 'nav' ) } );

	function add_print_link( id ){
	  if( !document.getElementById ||
		  !document.getElementById( id ) ) return;
	
	  // add extra functions to page tools list
	  var print_page = document.getElementById( id );
	
	  // create print link
	  var print_function = document.createElement('p');
	  print_function.className = 'print-link';
	  print_function.onclick = function(){ print_preview(); return false; };
	  print_function.appendChild( document.createTextNode( 'Print the Page' ) );
	
	}

	function print_preview() {
		// Switch the stylesheet
		setActiveStyleSheet('Print Preview');
		
		// Create preview message
		add_preview_message();
	
		// Print the page
		window.location.hash = "top";
		window.print();
	}

	function add_preview_message(){
		var main_content = document.getElementById('bodyPage');
	
		if (main_content != undefined){
			
			var main_body = main_content.parentNode;
			
			var preview_message = document.createElement('div');
			preview_message.id = 'preview-message';
		
			// Create Heading
			var preview_header = document.createElement('h3');
			var preview_header_text = document.createTextNode(print_message);		// 'This is a print preview of this page'
			preview_header.appendChild(preview_header_text);
			
			// Create paragraph
			var preview_para = document.createElement('p');
			
			var cancel_function_link = document.createElement('a');
				cancel_function_link.onclick = function(){ cancel_print_preview(); return false; };
				cancel_function_link.setAttribute('href', '#');	
			var cancel_function_link_text = document.createTextNode(print_link);	// 'Return to the existing page.'
			cancel_function_link.appendChild(cancel_function_link_text);
			preview_para.appendChild(cancel_function_link);
			
			// Put it all toegether
			preview_message.appendChild(preview_header); 
			preview_message.appendChild(preview_para);
			main_body.insertBefore(preview_message, main_content);
	
		}
	}

	function cancel_print_preview() {
		// Destroy the preview message
		var print_preview = document.getElementById('preview-message');
		var main_body = print_preview.parentNode;
		main_body.removeChild(print_preview);
		
		// Switch back stylesheet
		setActiveStyleSheet('default');
	}

	function setActiveStyleSheet(title) {
	   var i, a, main;
	   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		 if(a.getAttribute("rel").indexOf("style") != -1
			&& a.getAttribute("title")) {
		   a.disabled = true;
		   if(a.getAttribute("title") == title) a.disabled = false;
		 }
	   }
	}
/*** END/Print Preview functions ***/

/*** Menubar functions ***/
	var lastId = "";
	var delayHide = "";
	var actionDelay = "";
	var lastTopBackground = "";
	var defaultMenuItem = "";
	var menubar_country_id = "";
	var patternMenuItems = "";	
					  
	function highlightTab(numb) {
		for (var i=0;i<20;i++) {
			var tab = document.getElementById('top' + i + '_' + menubar_country_id);
			var subline = document.getElementById('sub' + i);		
			if (tab) {			
				if (patternMenuItems.indexOf("," + i + ",") > -1) {
					tab.className = (i == numb) ? "topLevelMenuItemDefaultPattern" : "topLevelMenuItemPattern";
				} else {
					tab.className = (i == numb) ? "topLevelMenuItemDefault" : "topLevelMenuItem";
				}
				if (subline) {
					subline.style.display = (i == numb) ? "inline" : "none";			
				}
			} else {
				break;
			}
		}
	}
	
	/*	JRivers 05/10/07
	*	This function either shows or hides a sub list in the menu depending on 2 variables
	*		id =  The sub list ID that is in question (the caller)
	*		hideDelay = whether the list must auto hide after a delay. (This is either TRUE or FALSE)
	*/
	function showHideActions(id, hideDelay) {	
		if(hideDelay == "setup"){
			var defaultElement = document.getElementById(defaultMenuItem);
			defaultElement.style.display = 'inline';
			highlightTab(defaultMenuItem.substr(3));
		}
		
		if(hideDelay == true){
			if(id == defaultMenuItem){
				//do nothing as its already shown
			}
			else{
				//Hide Current
				var element = document.getElementById(id);
				element.style.display = 'none';
				//Show the default Item
				var defaultElement = document.getElementById(defaultMenuItem);
				defaultElement.style.display = 'inline';
				highlightTab(defaultMenuItem.substr(3));
				
			}
		}
		if(hideDelay == false){
			//if the current id is not the default
			if(defaultMenuItem != id){
				//Hide last item
				var lastElement = document.getElementById(lastId);
				lastElement.style.display = 'none';
				//Show current
				var element = document.getElementById(id);
				element.style.display = 'inline';
				highlightTab(id.substr(3));
				//Hide default
				var defaultElement = document.getElementById(defaultMenuItem);
				defaultElement.style.display = 'none';
			}
			else if(id == defaultMenuItem && lastId != id){
				//Show the default item
				var defaultElement = document.getElementById(defaultMenuItem);
				defaultElement.style.display = 'inline';
				highlightTab(defaultMenuItem.substr(3));
				//Hide last item
				var lastElement = document.getElementById(lastId);
				lastElement.style.display = 'none';
			}
		}
		lastId = id;
		
		// This aligns the text to the center of the block.
		var subs = document.getElementById(id);
		if (subs) {
			var lis = subs.getElementsByTagName('li');
			if (lis && lis.length) {
				var width = 0;
				for(var i=0;i<lis.length;i++) {
					width += lis[i].offsetWidth;
				}
				if (lis[0]) lis[0].style.marginLeft = ((977 - ((lis.length - 1) * 12) - width) / 2) + "px";
			}
		}
		
	}
	
	function showHide(id, hideDelay){
		clearTimeout(delayHide);
		passedId = id;
		passedHideDelay = hideDelay;
		actionDelay = setTimeout("showHideActions(passedId, false);", 400);
	}
	
	// This function allows a sub list to be hidden after a time lapse
	function hideDelay(id){
		passedId = id;
		clearTimeout(actionDelay);
		delayHide = setTimeout("showHideActions(passedId, true);", 175);
	}
/*** END/Menubar functions ***/

/*** JCMS Block functions ***/
	function switchLateDealBlock(nights) {		
		if(document.getElementById('latedeals_7')) {
			var ld7 = document.getElementById('latedeals_7');
			var ld14 = document.getElementById('latedeals_14');
			var ldt7 = document.getElementById('latedeals_tab_7');
			var ldt14 = document.getElementById('latedeals_tab_14');			
			ldt7.className = (nights == 7) ? "ldtabon" : "ldtab";
			ldt14.className = (nights == 14) ? "ldtabon" : "ldtab";			
			ld7.style.display = (nights == 7) ? "block" : "none";
			ld14.style.display = (nights == 14) ? "block" : "none";			
		}
	}
/*** END/JCMS Block functions ***/

	/* check if image has loaded */
	
	function IsImageLoaded(img) {
		// During the onload event, IE correctly identifies any images that
		// weren’t downloaded as not complete. Others should too. Gecko-based
		// browsers act like NS4 in that they report this incorrectly.

		if (!img.complete && !window.opera) {
			return false;
		}
		
		// However, they do have two very useful properties: naturalWidth and
		// naturalHeight. These give the true size of the image. If it failed
		// to load, either of these should be zero.
		if (typeof img.naturalWidth	!= "undefined" && img.naturalWidth	== 0) {
			return false;
		}
		
		// No other way of checking: assume it’s ok.
		return true;
	}


/*** Rotating Banner ***/
	
	var rotating_banner_start = new Array();
	var rotating_banner_index = new Array();
	var rotating_banner_timeout = new Array();
	var rotating_banner_trans_time = new Array();
	var rotating_banner_pics = new Array();
	var rotating_banner_div = new Array();
	var rotating_banner_stopped = new Array();
	
	function jump_to_banner (id, pic) {		
		if(rotating_banner_index[id] != pic){
			var previousIndx = rotating_banner_index[id];	
			rotating_banner_index[id] = pic;
			blendimageout_rotating_banner(id,rotating_banner_div[id]+rotating_banner_index[id],rotating_banner_div[id]+previousIndx,600);
		}		
		rotating_banner_stopped[id] = true;	
		//rotating_banner_tab_highlight(id);
	}

	var arrLoaded = new Array();
	function init_rotating_banner (id, div, total_pics, timeout, trans_time) {
		if(document.getElementById(div + "_imageTest0")){
			for (var i = 0; i < total_pics; i++) {
				arrLoaded[i] = false;
			}
			var all_loaded = true;
			for (var i = 0; i < total_pics; i++) {
				if(!arrLoaded[i] && IsImageLoaded(document.getElementById(div + '_imageTest'+i))){
					if (i == 0 || arrLoaded[0]) {
						document.getElementById(div+i).style.backgroundImage = "url(" + document.getElementById(div + '_imageTest'+i).src + ")";
						arrLoaded[i] = true;
					}						
				}
				else if(!arrLoaded[i]){
					all_loaded = false;
				}
			}
			if(all_loaded && arrLoaded[0]){
				for (var i = 0; i < total_pics; i++) {
					document.getElementById(div+i).style.display = 'block';
				}
				start_rotating_banner(id, div, total_pics, timeout, trans_time);
			}
			else{	
				setTimeout("init_rotating_banner(" + id + ",'" + div + "'," + total_pics + "," + timeout + "," + trans_time + ")",100);
			}	
		}
		else{
			start_rotating_banner(id, div, total_pics, timeout, trans_time);
		}
	}
	
	function start_rotating_banner (id, div, total_pics, timeout, trans_time) {
		rotating_banner_start[id] = new Date();
		rotating_banner_index[id] = 0;
		rotating_banner_timeout[id] = timeout;
		rotating_banner_trans_time[id] = trans_time;
		rotating_banner_pics[id] = total_pics;
		rotating_banner_div[id] = div;
		rotating_banner_stopped[id] = false;
				
		for(var i = 1; i < total_pics; i++) {
			var e = document.getElementsByName(div+i);
			for(var j=0;j!=e.length;j++) { e[j].style.display = "none"; }
		}
		
		setTimeout("change_pic_rotating_banner(" + id + ")",rotating_banner_timeout[id]);
	}
	
	function change_pic_rotating_banner (id) {
		if (!rotating_banner_stopped[id]) {
			var previousIndx = rotating_banner_index[id];	
			if (rotating_banner_index[id] < rotating_banner_pics[id]-1) {
				rotating_banner_index[id]++;
			}
			else {
				rotating_banner_index[id] = 0;
			}
		blendimageout_rotating_banner(id,rotating_banner_div[id]+rotating_banner_index[id],rotating_banner_div[id]+previousIndx,rotating_banner_trans_time[id]);
			//rotating_banner_tab_highlight(id);
		}
	}	
	
	function rotating_banner_tab_highlight(id){
		for(var i = 0; i < rotating_banner_pics[id];i++){
			if(document.getElementById(rotating_banner_div[id]+ '_tab'+i)){
				var tab = document.getElementById(rotating_banner_div[id]+ '_tab'+i);
				if(i == rotating_banner_index[id]){
					tab.style.backgroundColor = 'gray';
				}
				else{
					tab.style.backgroundColor = '';
				}
			}
		}
	}
	
	function blendimageout_rotating_banner (id, newdivid, olddivid, millisec) {
		var speed = Math.round(millisec / 100);
		var i = 0;
		
		rotating_banner_start[id] = new Date();

		do {
			setTimeout("changeOpac2_rotating_banner(" + id + "," + i + ",'" + newdivid + "', '" + olddivid + "'," + speed + ")",(i * speed));
			i=i+7;
		} while (i < 100);
		setTimeout("changeOpac2_rotating_banner(" + id + ",100,'" + newdivid + "', '" + olddivid + "'," + speed + ")",(100 * speed));
	}	
	
	function changeOpac2_rotating_banner (id, opacity, newid, oldid, speed) {
		var start_time = new Date();
		opac = (start_time-rotating_banner_start[id])/speed;
		var objects = document.getElementsByName(newid);
		
		for(var j=0;j!=objects.length;j++) {
			if (objects[j].style.display != "block") { objects[j].style.display = "block"; }
			objects[j].style.opacity = (opac / 100);
			objects[j].style.MozOpacity = (opac / 100);
			objects[j].style.KhtmlOpacity = (opac / 100);
			objects[j].style.filter = "alpha(opacity=" + opac + ")";
		}
		
		if(opacity == 100) {
			var oldobjects = document.getElementsByName(oldid);	
			for(var j=0;j!=oldobjects.length;j++) { oldobjects[j].style.display = "none"; oldobjects[j].style.zIndex = 50; objects[j].style.zIndex = 0; }
			setTimeout("change_pic_rotating_banner(" + id + ")",rotating_banner_timeout[id]);
			
		}
	}
	
/*** END/Rotating Banner ***/

/*** Rotating Regions ***/
	function rg(name,url_name) {
		this.name = name;
		this.url_name = url_name;
	}
	function setRegion() {
		var startPos = curReg + 1;
	
		for (j=1;j<=rgList.length;j++) {
			if (!document.getElementById("reg"+j)) {
				break;
			}
			document.getElementById("reg"+j).innerHTML = "";
		}		
	
		for (i=1;i<=rgList.length;i++) {
			if (!document.getElementById("reg"+i)) {
				break;
			}
			document.getElementById("reg"+i).innerHTML = '<div style="margin:0;padding:0;clear:both;float:left;width:17px;padding-right:10px;text-align:right">' + (curReg+1) + '</div><a style="float:left" href="/regions/' + rgList[curReg].url_name + '/' + rotate_regions_url_ext + '">' + rgList[curReg].name + '</a>';
			curReg++;
			if (curReg >= rgList.length) {
				curReg = 0;
				break;
			} 
		}
		
		endPos = (startPos > curReg) ? rgList.length : curReg;
		document.getElementById("pageno").innerHTML = startPos + " - " + endPos + " " + rotate_regions_of_text + " " + rgList.length;
		
		if (curReg < 0) {
			curReg = rgList.length + curReg;
		} 
		window.setTimeout("setRegion()",5000);
	}
/*** END/Rotating Regions ***/

/*** Late Deals functions ***/
	function rotate(numb) {
		if (numb == 1) {
			img1 = document.getElementById('image1');
			img2 = document.getElementById('image2');
		} else {
			img1 = document.getElementById('image2');
			img2 = document.getElementById('image1');
		}
		cur = img2.style.opacity;
		if (cur > 0) {
			img2.style.filter = "alpha(opacity=" + ((cur-0.05)*100) + ");";
			img2.style.opacity = (cur-0.05);
			window.setTimeout("rotate(" + numb + ")", 40);
		} else {
			img2.style.zIndex = 1;
			img1.style.zIndex = 2;
			img2.style.filter = "alpha(opacity=100);";
			img2.style.opacity = 1;
			newImage = (numb == 2) ? 1 : 2;
			window.setTimeout("rotate(" + newImage + ")", 5000);
		}
	}
	
	function refreshForm() {
		document.frmResults.action = 'late-deals.cfm';
		document.frmResults.method = 'POST';
		document.frmResults.submit();					
	}
	
	function setPage(num) {
		document.frmResults.page.value = num;
		refreshForm();
	}
	
	function changeLateDealsPax() {
		document.frmResults.dep_air_id.value = document.frmTailor.dep_air_id.value;
		document.frmResults.paxa.value = document.frmTailor.paxa.value;		
		document.frmResults.paxc.value = document.frmTailor.paxc.value;		
		document.frmResults.paxi.value = document.frmTailor.paxi.value;
		refreshForm();
	}
	
	function setOrderBy() {
		setPage(1);
	}
	
	function switchLateDeal(val) {
		document.frmResults.type.value = val;
		document.frmResults.page.value = 1;
		refreshForm();
	}
	
	function submitToQS() {
		document.frmQSResults.action = '/q_search.cfm';
		document.frmQSResults.method = 'GET';					
		document.frmQSResults.submit();
	}
	
	function checkAll(pos) {
		if (pos == "") {
		var check = document.getElementById('checkall').checked;
		} else {
			var check = document.getElementById('checkall1').checked;
		}
		
		var inputs = document.getElementById('results').getElementsByTagName('input');
		for (var i=0;i<inputs.length;i++) {
			if (inputs[i].type == "checkbox") {
				inputs[i].checked = check;
			}
		}
		
		if (pos == "") {
			document.getElementById('checkall1').checked = check;
		} else {
			document.getElementById('checkall').checked = check;
		}		
	}
/*** END/Late Deals functions ***/

/*** Villa, Resort, Region page functions ***/
	var hand = "hand";
	if (navigator.appName == "Netscape") {
		hand = "pointer";
	}
	
	function galleryImage (pMain, pThumb, pText) {
		this.main = pMain;
		this.thumb = pThumb;
		this.text = pText;
	}
	function imageSet (pimg1, pimg2, pimg3) {
		this.img1 = pimg1;
		this.img2 = pimg2;
		this.img3 = pimg3;
	}
	
	function showHideLinks(){								
		if(document.getElementById("bookmarks")){
			if(document.getElementById("bookmarks").style.display =='block'){
				document.getElementById("bookmarks").style.display ='none';
				document.getElementById("plusminus").src = "/images/jvh08/Plus.jpg";
			}	else {
				document.getElementById("bookmarks").style.display ='block';
				document.getElementById("plusminus").src = "/images/jvh08/minus.jpg";
			}
		}			
	}
	
	function villa (id, name, villa_link, picture, bedrooms, boj, lux, rental_type, sleeps, beds, baths, car, air_con, heated_pool, private_pool, shared_pool, rental_type_id, occupancy_rate, resort_type_id, region_id, max_occ, resort_id, accom_type_id, res_date, accom_only_rrp, hml_prices,lowSeasons, midSeasons, highSeasons) {
		this.id = id;
		this.name = name;
		this.villa_link = villa_link;
		this.picture = picture;
		this.bedrooms = bedrooms;
		this.boj = boj;
		this.lux = lux;
		this.rental_type = rental_type;
		this.sleeps = sleeps;
		this.beds = beds;
		this.baths = baths;
		this.car = car;
		this.air_con = air_con;
		this.heated_pool = heated_pool;
		this.private_pool = private_pool;
		this.shared_pool = shared_pool;
		this.rental_type_id = rental_type_id;
		this.occupancy_rate = occupancy_rate;
		this.resort_type_id = resort_type_id;
		this.region_id = region_id;
		this.max_occ = max_occ;
		this.accom_type_id = accom_type_id;
		if(typeof resorts !== "undefined") {
			for (var i=0;i<resorts.length;i++) {
				if (resort_id == resorts[i].id) {
					this.resort_name = resorts[i].name;
					break;
				}
			}
		}
		if(typeof regions !== "undefined") {
			for (var i=0;i<regions.length;i++) {
				if (region_id == regions[i].id) {
					this.region_name = regions[i].name;
					break;
				}
			}
		}
		if(typeof res_date !== "undefined") {
			this.res_date = d(res_date);
		}
		this.accom_only_rrp = accom_only_rrp;
		this.hml_prices = hml_prices;
		this.lowSeasons = lowSeasons;
		this.midSeasons = midSeasons;
		this.highSeasons = highSeasons;
	}
	
	function displayVilla (villaObj) {			
		var isBoj = (villaObj.boj == 1);
		var isLux = (villaObj.lux == 1);
		var myhref = "href=";
		var linkStartHTML = '<a '+myhref+'"'+villaObj.villa_link+lblCookieValue+'">';
		var linkEndHTML = "</a>";
		var myimg = "img src";
		
		var imageHTML = '<'+myimg+'="'+lblWebsiteUrl+'images/galleries/'+lblRegionID+lblRegionName+'/Villas/Photos/' + lblRegionID + villaObj.picture + '/' + lblRegionID + villaObj.picture + '_ext_5.jpg" alt="' + villaObj.name + '" style="margin-bottom:10px;" />';
		
		if (isLux) featureIconsEXT = "lux/large/";
		else if (isBoj) featureIconsEXT = "boj/large/";
		else featureIconsEXT = "std/large/";
		
		var featureIconsHTML = "<"+myimg+"='" + featureIconsPath + featureIconsEXT + "sleeps" + villaObj.sleeps + ".jpg' alt='" + eval("sleeps" + villaObj.sleeps + "ALT") + "' style='margin-right:2px' align='top' /><img src='" + featureIconsPath + featureIconsEXT + "beds" + villaObj.beds + ".jpg' alt='" + eval("beds" + villaObj.beds + "ALT") + "' style='margin-right:2px' align='top' /><img src='" + featureIconsPath + featureIconsEXT + "baths" + villaObj.baths + ".jpg' alt='" + eval("baths" + villaObj.baths + "ALT") + "' style='margin-right:2px' align='top' />";
		if (villaObj.car != 4) {
			var carVal = "car_recommended-" + lblLanguageCode;
			if (villaObj.car == 3) {
				carVal = "car_essential-" + lblLanguageCode;
			}
			else if (villaObj.car == 1) {
				carVal = "car_optional-" + lblLanguageCode;
			}
			featureIconsHTML = featureIconsHTML + "<"+myimg+"='" + featureIconsPath + featureIconsEXT + carVal + ".jpg' alt='" + eval("car" + villaObj.car + "ALT") + "' style='margin-right:2px' align='top' />";
		}
		if (villaObj.air_con == 1) {
			featureIconsHTML = featureIconsHTML + "<"+myimg+"='" + featureIconsPath + featureIconsEXT + "aircon.jpg' alt='" + airconALT + "' style='margin-right:2px' align='top' />";
		}
		
		// pools icons: private, private heated, shared, shared heated
		if (villaObj.private_pool == 1 || villaObj.shared_pool == 1) {
			featureIconsHTML += '<img alt="';					
			if (villaObj.private_pool == 1) featureIconsHTML += 'Private ';
			else if (villaObj.shared_pool == 1) featureIconsHTML += 'Shared ';
			if (villaObj.heated_pool == 1) featureIconsHTML += 'Heated ';
			featureIconsHTML += '" src="' + featureIconsPath + featureIconsEXT;
			if (villaObj.private_pool == 1) featureIconsHTML += 'private';
			else if (villaObj.shared_pool == 1) featureIconsHTML += 'shared';
			if (villaObj.heated_pool == 1) featureIconsHTML += '_heated';
			featureIconsHTML += 'pool-' + lblLanguageCode + '.jpg" style="margin-right:2px" align="top" />';
		}
				
		var HTML = linkStartHTML + imageHTML + linkEndHTML + "<br />" + featureIconsHTML + "<div style='margin-top:5px;'></div>" + linkStartHTML + villaObj.name + linkEndHTML + "<div style='margin-top:10px;'></div>";

		if (isLux) {
			var bojHTML = '<'+myimg+'="'+lblWebsiteUrl+'images/accom/luxury-' + lblLanguageCode + '.jpg" alt="' + lblqs_lux + '" style="margin-bottom:5px;" />';
			var bojBorder = "";
		}
		else if (isBoj) {
			var bojHTML = '<'+myimg+'="'+lblWebsiteUrl+'images/accom/best-of-james-' + lblLanguageCode + '.jpg" alt="' + lblqs_boj + '" style="margin-bottom:5px;" />';
			var bojBorder = "";
		}
		else {
			var bojHTML = (setUpType != 1) ? '<div style="height:27px;"></div>' : '';			
			var bojBorder = "";
		}
		
		HTML = "<table cellspacing='0' cellpadding='0' border='0'><tr><td width='230' align='center' style='" + bojBorder + "padding-top:10px;'>" + "<table cellspacing='0' cellpadding='0' border='0'><tr><td width='220' align='left'>" + bojHTML + HTML + "</td></tr></table></td></tr></table>";
		return HTML;
	}
	
	var currentBedroomSelection = 0;
	var currentDisplayAmount = 12;
	var villaList;
	var startNumber;
	var endNumber;
	
	function displayPage (bedrooms, page, setting) {
		if (setting == 1) {
			currentDisplayAmount = 12;
		}
		if (setUpType == 3 || setUpType == 4) {
			var setValue = false;
			for (var i = 0; i < document.frmDisplayAmount.displayDropDown.length - 1; i++) {
				if (document.frmDisplayAmount.displayDropDown[i].value == currentDisplayAmount) {
					document.frmDisplayAmount.displayDropDown.selectedIndex = i;
					document.frmDisplayAmount_footer.displayDropDown.selectedIndex = i;
					setValue = true;
					break;
				}
			}
			if (!setValue) {
				document.frmDisplayAmount.displayDropDown.selectedIndex = document.frmDisplayAmount.displayDropDown.length - 1;
				document.frmDisplayAmount_footer.displayDropDown.selectedIndex = document.frmDisplayAmount_footer.displayDropDown.length - 1;
			}
		}
		
		if (setUpType == 4) {
			displayLinks(bedrooms);
		}
		displayVillas(bedrooms, page);
		if (setUpType == 3 || setUpType == 4) {
			displayResults(bedrooms, page);
			displayPageNumbers(bedrooms, page);
		}
		currentBedroomSelection = bedrooms;
		if (document.getElementById('saveOptions')) {
			document.getElementById('saveOptions').value = bedrooms+','+page+','+setting;
		}
	}
	
	function displayLinks (bedrooms) {
		var text = "";		
		for (var i = 0; i < bedroomList.length; i++) {
			if (bedroomList[i] == bedrooms) {
				if (bedroomList[i] == 0) {
					text = text + lblviewall;
				}
				else if (bedroomList[i] == -1) {
					text = text + "Best of James" + "&nbsp;|&nbsp;";
				}
				else if (bedroomList[i] == 1) {
					text = text + bedroomList[i] + " " + bedroomText + "&nbsp;|&nbsp;";
				}
				else {
					text = text + bedroomList[i] + " " + bedroomsText + "&nbsp;|&nbsp;";
				}
			}
			else {
				if (bedroomList[i] == 0) {
					text = text + "<a href='JavaScript:displayPage(" + bedroomList[i] + ",1,1);'>" + lblviewall + "</a>";
				}
				else if (bedroomList[i] == -1) {
					text = text + "<a href='JavaScript:displayPage(" + bedroomList[i] + ",1,1);'>Best of James&nbsp;</a>&nbsp;|&nbsp;";
				}
				else if (bedroomList[i] == 1) {
					text = text + "<a href='JavaScript:displayPage(" + bedroomList[i] + ",1,1);'>" + bedroomList[i] + " " + bedroomText + "</a>&nbsp;|&nbsp;";
				}
				else {
					text = text + "<a href='JavaScript:displayPage(" + bedroomList[i] + ",1,1);'>" + bedroomList[i] + " " + bedroomsText + "</a>&nbsp;|&nbsp;";
				}
			}
		}
		
		if (setUpType == 4) {
			document.getElementById("bedrooms_links").innerHTML = text;
		}
	}
	
	function displayResults (bedrooms, page) {
		var text = lblresults + " " + (startNumber + 1) + " - " + endNumber + " " + lblof + " " + villaList.length;
		document.getElementById("results").innerHTML = text;
		document.getElementById("results_footer").innerHTML = text;
	}
	
	function displayPageNumbers (bedrooms, page) {
		var prevPage = page - 1;
		if (prevPage == 0) {
			var prev = lblprevious;
		}
		else {
			var prev = '<a href="Javascript:displayPage(' + bedrooms + ',' + prevPage + ',2);">' + lblprevious + '</a>';
		}
		var nextPage = page + 1;
		if (startNumber + currentDisplayAmount >= villaList.length) {
			var next = lblnext;
		}
		else {
			var next = '<a href="Javascript:displayPage(' + bedrooms + ',' + nextPage + ',2);">' + lblnext + '</a>';
		}
		var pages = parseInt(villaList.length / currentDisplayAmount);
		if (pages != (villaList.length / currentDisplayAmount)) {
			pages++;
		}
		if (pages > 1) {
			var pagesText = "";
			for (var i = 1; i < pages + 1; i++) {
				if (i == page) {
					pagesText = pagesText + page + " ";
				}
				else {
					pagesText = pagesText + "<a href='Javascript:displayPage(" + bedrooms + "," + i + ",2);'>" + i + "</a> ";
				}
			}
			var text = prev + " " + pagesText + next;
			document.getElementById("pages").innerHTML = text;
			document.getElementById("pages_footer").innerHTML = text;
		}
		else {
			document.getElementById("pages").innerHTML = "";
			document.getElementById("pages_footer").innerHTML = "";
		}
	}
	
	function displayVillas (bedrooms, page) {
		villaList = new Array();
		for (var i = 0; i < villas.length; i++) {
			if (bedrooms == 0) {
				villaList[villaList.length] = villas[i];
			}
			else if (bedrooms == -1 && villas[i].boj == 1) {
				villaList[villaList.length] = villas[i];
			}
			else if (villas[i].bedrooms == bedrooms) {
				villaList[villaList.length] = villas[i];
			}
		}
		startNumber = currentDisplayAmount * (page - 1);
		endNumber = startNumber + currentDisplayAmount;
		if (endNumber > villaList.length) {
			endNumber = villaList.length;
		}
		var counter = 0;
		var text = "<table cellspacing='0' cellpadding='0' border='0'>";
		for (var i = startNumber; i < endNumber; i++) {
			if (counter % 3 == 0) {
				text = text + "<tr><td width='230'>" + displayVilla(villaList[i]) + "</td><td width='10'></td>";
			}
			else if (counter % 3 == 1) {
				text = text + "<td width='230'>" + displayVilla(villaList[i]) + "</td><td width='10'></td>";
			}
			else {
				text = text + "<td width='230'>" + displayVilla(villaList[i]) + "</td></td></tr>";
				if (i < endNumber - 1) {
					text = text + "<tr><td colspan='5'><hr></td></tr>";
				}
			}
			counter++;
		}
		if (counter % 3 == 1) {
			text = text + "<td width='230'></td><td width='10'></td><td width='210'></td></tr>";
		}
		else if (counter % 3 == 2) {
			text = text + "<td width='230'></td></td></tr>";
		}
		text = text + "</table>";
		document.getElementById("villasTD").innerHTML = text;
	}
	
	function displayAmount (amount,run_page) {
		if (amount == 0) {
			currentDisplayAmount = parseInt(villas.length);
		}
		else {
			currentDisplayAmount = parseInt(amount);
		}
		if (run_page) {
			displayPage(currentBedroomSelection,1,2);
		}
	}
	
	function leftscrolldown() {
		if (scrollTimer == null) {
			scrollTimer = setInterval('scrolltick(true);', 10);
		}
	}
	
	function scrollup() {
		clearInterval(scrollTimer);
		delete(scrollTimer);
		scrollTimer = null;
	}
	
	function scrolltick(scrollleft) {
		if(scrollleft) {
			leftvalue -= 10;
		}
		else {
			leftvalue += 10;
		}
		
		if(leftvalue < 0) leftvalue=0;
		if( maxleft > 0) {
			if(leftvalue > maxleft) leftvalue=maxleft;
		} else {
			leftvalue=0;
		}
		
		var imagels = document.getElementById('imagejfvk');
		imagels.scrollLeft = leftvalue;
	}
	
	function rightscrolldown() {
		if (scrollTimer == null) {
			scrollTimer = setInterval('scrolltick(false);', 10);
		}
	}
	
	function setThumb_villa (set, num, pos) {
		if ((set >= imageSets.length) || (eval("imageSets[" + set + "].img" + num).thumb == null)) {
			document.getElementById("photoViewer" + pos + "img").src = lbl_villa_website_url + "images/photo_viewer/none.jpg";
			document.getElementById("photoViewer" + pos + "img").alt = "";
			document.getElementById("photoViewer" + pos).onmouseover = "";
			document.getElementById("photoViewer" + pos).onmouseout = "";
			document.getElementById("photoViewer" + pos).onclick = "";
		}
		else {
			document.getElementById("photoViewer" + pos + "img").src = eval("imageSets[" + set + "].img" + num).thumb;
			document.getElementById("photoViewer" + pos + "img").alt = eval("imageSets[" + set + "].img" + num).text;
			document.getElementById("photoViewer" + pos + "img").title = eval("imageSets[" + set + "].img" + num).text;
			document.getElementById("photoViewer" + pos).onmouseover = function () {document.getElementById("photoViewer" + pos).style.cursor = hand; setPhoto_villa(set,num);};
			document.getElementById("photoViewer" + pos).onmouseout = function () {setPhoto_villa(currentImageSet, currentImageNum);};
			document.getElementById("photoViewer" + pos).onclick = function () {currentImageSet = set; currentImageNum = num; setPhoto_villa(set,num);};
		}
	}
	
	function setPhoto_villa (set, num) {
		document.getElementById("photoViewerMain").src = eval("imageSets[" + set + "].img" + num).main;
		document.getElementById("photoViewerMain").alt = eval("imageSets[" + set + "].img" + num).text;
		document.getElementById("photoViewerMain").title = eval("imageSets[" + set + "].img" + num).text;
		//document.getElementById("photoViewerLabel").innerHTML = eval("imageSets[" + set + "].img" + num).text;
	}
	
	function showPhotos_villa (i) {						
		var x = (parseInt(i / 2) * 6) + 1;
		var y = (parseInt(i / 2) * 6) + 6;
		if (y > totalImages) {
			y = totalImages;
		}
		document.getElementById("photoViewerXofY").innerHTML = "Photos " + x + " - " + y + " " + lbl_villa_gallery_of + " " + totalImages;
		
		if (villa_gallery_images_count > 6) {
			var pages = parseInt(totalImages / 6);
			if (pages != (totalImages / 6)) {
				pages++;
			}
			if ((i - 2) < 0) {
				var prev = lbl_villa_gallery_prev;
			}
			else {
				var prev = "<a href='JavaScript:showPhotos_villa(" + (i - 2) + ")'>" + lbl_villa_gallery_prev + "</a>";
			}
			if ((parseInt(i / 2) + 1) >= pages) {
				var next = lbl_villa_gallery_next;
			}
			else {
				var next = "<a href='JavaScript:showPhotos_villa(" + (i + 2) + ")'>" + lbl_villa_gallery_next + "</a>";
			}
			var pagesText = "";
			for (var j = 1; j < pages + 1; j++) {
				var page = (j - 1) * 2;
				if (i == page) {
					pagesText = pagesText + j + " ";
				}
				else {
					pagesText = pagesText + "<a href='Javascript:showPhotos_villa(" + page + ");'>" + j + "</a> ";
				}
				if (j < pages) {
					pagesText = pagesText + "| ";
				}
			}
			document.getElementById("photoViewerPages").innerHTML = prev + " " + pagesText + " " + next;
		}
		
		setThumb_villa(i,1,1);
		setThumb_villa(i,2,2);
		setThumb_villa(i,3,3);
		
		setThumb_villa(i+1,1,4);
		setThumb_villa(i+1,2,5);
		setThumb_villa(i+1,3,6);
	}
/*** END/Villa, Resort, Region page functions ***/

/* Customer reviews */
var expectImg = null;
function miniReview(e, obj, ratings, type) {
	var minus = '/images/jvh08/minus.jpg';
	var plus = '/images/jvh08/plus.jpg';
	var mini = document.getElementById('mini_review');
	var villa_reviews = document.getElementById('villa_reviews');
	var img = villa_reviews.getElementsByTagName('img');
	
	if (obj.src.indexOf(plus) > -1) {
		if (expectImg) expectImg.src = plus;
		obj.src = minus;
		expectImg = obj;
		
		getMouseXY(e);
		mini.style.left = tempX + "px";
		mini.style.top = tempY + "px";
		mini.style.display = '';			
		var tbl = document.getElementById('mini_review_tbl');
		for (var i=0;i<ratings.length;i++) {
			if (ratings[i] == '') {
				tbl.rows[i].style.display = 'none';
			} else {
				tbl.rows[i].cells[1].innerHTML = ratingIconsNew(ratings[i], 5, 'small', tbl.rows[i].cells[0].innerText + ' rating ' + ratings[i] + ' out of 5', type);			
				tbl.rows[i].style.display = '';
			}
		}
	}
}
	
function closeMiniReview() {
	var plus = '/images/jvh08/plus.jpg';
	var mini = document.getElementById('mini_review');
	if (expectImg) expectImg.src = plus;
	expectImg = null;
	if (mini) mini.style.display = 'none';
}

function ratingIcons(rating, total, size, alt) {
	var tickIcon = Math.floor(rating);
	if (rating > Math.floor(rating)) tickIcon += ".5";
	return '<img src="/images/accom_page/tick-' + size + '-' + tickIcon + '.gif" alt="' + alt + '" />';
}

function ratingIconsNew(rating, total, size, alt, type) {
	var tickIcon = Math.floor(rating);
	if (rating > Math.floor(rating)) tickIcon += ".5";
	return '<img src="/images/accom/ratings/' + type + '/tick-' + size + '-' + tickIcon + '.jpg" alt="' + alt + '" />';
}

/* JQuery gallery image browsers & scrolling */
var jqGalleries = new Array();
					
// object to hold the gallery settings
function JQGallery(args) {
	/*addJQGallery({
		id: "lux-gallery",
		type: 1,
		totalImages: #ListLen(imageList) - 1#,
		totalSets: #Ceiling(ListLen(imageList) / 6)#,
		runOnLoad: true,
		fadeTime: 1500,
		displayTime: 4000,
		scrollPixels: 846
	});	*/
	
	var gallery = this;
	gallery.id = args.id;
	gallery.currentImg = 0;
	gallery.currentSet = 1;
	gallery.maxImgs = args.totalImages;
	gallery.maxSets = args.totalSets;
	gallery.imagesPerSet = args.imagesPerSet;
	gallery.slideShow = args.runOnLoad;
	gallery.fadeTime = args.fadeTime;
	gallery.displayTime = args.displayTime;
	gallery.combinedTime = args.fadeTime + args.displayTime;
	gallery.scrollPixels = args.scrollPixels;
	
	if (args.type == 1) {
		gallery.thumbOverlayOpacity = "0.5";		
	}
	
	// switches to an image
	gallery.showImage = function (img, continueSlideShow) {
		
		// if the image has not loaded, wait and then try again
		if (!IsImageLoaded(document.getElementById(gallery.id + '-' + img))) {
			setTimeout("showJQGalleryNextImg('" + gallery.id + "')", 500);
			return;
		};

		// centre image
		if (args.type == 1 && img > 0) {
			var imgObj = $("#" + gallery.id + '-' + img);
			var parentW = imgObj.parent().width();
			if (imgObj.width() > 0) {
				imgObj.parent().css('left',((parentW-imgObj.width())/2)+"px");
			}
		}

		// stop any current images from fading
		for (var i = 0; i <= gallery.maxImgs; i++) {
			if (i != img) {
				$("#" + gallery.id + '-' + i).stop(true, true);
				if (args.type == 2) $("#" + gallery.id + '-heading-' + i).stop(true, true);
			}
		}
		
		// fade in the new image
		$("#" + gallery.id + '-' + img).fadeIn(gallery.fadeTime);
		if (args.type == 1) {
			var imgW = $("#" + gallery.id + '-thumb-image-' + img).width();
			var bW = parseInt($("#" + gallery.id + '-thumb-border-' + img).css("border-left-width"))*2;
			var b2W = parseInt($("#" + gallery.id + '-thumb-border2-' + img).css("border-left-width"))*2;

			$("#" + gallery.id + '-thumb-border-' + img).css("width",(imgW-bW)+"px").show();
			$("#" + gallery.id + '-thumb-border2-' + img).css("width",(imgW-b2W)+"px").show();
			$("#" + gallery.id + '-thumb-image-' + img).css("opacity", "1");
		} else if (args.type == 2) {
			$("#" + gallery.id + '-heading-' + img).show();
			$("#" + gallery.id + '-number-off-' + img).fadeOut(gallery.fadeTime);
			$("#" + gallery.id + '-number-on-' + img).fadeIn(gallery.fadeTime);			
		} else if (args.type == 4) {
			$("#" + gallery.id + '-thumb-text-' + img).css("font-weight", "bold");
			$("#" + gallery.id + '-thumb-text-' + img).css("text-decoration", "underline");
		}
		
		// fade out all other images
		for (var i = 0; i <= gallery.maxImgs; i++) {
			if (i != img) {
				$("#" + gallery.id + '-' + i).fadeOut(gallery.fadeTime);
				if (args.type == 1) {
					$("#" + gallery.id + '-thumb-border-' + i).hide();
					$("#" + gallery.id + '-thumb-border2-' + i).hide();
					$("#" + gallery.id + '-thumb-image-' + i).css("opacity", gallery.thumbOverlayOpacity);
				} else if (args.type == 2) {
					$("#" + gallery.id + '-heading-' + i).hide();	
					$("#" + gallery.id + '-number-on-' + i).fadeOut(gallery.fadeTime);
					$("#" + gallery.id + '-number-off-' + i).fadeIn(gallery.fadeTime);
				} else if (args.type == 4) {
					$("#" + gallery.id + '-thumb-text-' + i).css("font-weight", "normal");
					$("#" + gallery.id + '-thumb-text-' + i).css("text-decoration", "none");
				}
			}
		}
		
		// pause the slide show
		if (!continueSlideShow) {
			gallery.slideShow = false;
		} else {
			setTimeout("showJQGalleryNextImg('" + gallery.id + "')", gallery.combinedTime);
		}
		if (args.type == 1 && !gallery.slideShow) $("#" + gallery.id + '-Play').fadeIn();
		
		gallery.currentImg = img;
					
	}
	
	// switches to the next image
	gallery.nextImage = function () {
		if (gallery.slideShow) {
			var nextImg = (gallery.currentImg >= gallery.maxImgs - 1) ? 0 : gallery.currentImg + 1;
			gallery.showImage(nextImg, true);			
		}
	}
	
	// if its a gallery browser with a pop-up scrolling thumb section
	if (args.type == 1 || args.type == 3) {
		
		gallery.addXtoYofZ = function () {
			var galleryX = ((gallery.currentSet - 1) * gallery.imagesPerSet) + 1;
			var galleryY = gallery.currentSet * gallery.imagesPerSet;
			galleryY = (galleryY > gallery.maxImgs) ? gallery.maxImgs : galleryY;
			if (galleryX == galleryY) {
				$("#" + gallery.id + "-ThumbsXYZ").text(galleryX + " of " + gallery.maxImgs);
			} else {
				$("#" + gallery.id + "-ThumbsXYZ").text(galleryX + " to " + galleryY + " of " + gallery.maxImgs);
			}
		}
		
		gallery.scrollLeft = function (nextSet) {
			$("#" + gallery.id + "-Thumbs-" + gallery.currentSet).animate({left: gallery.scrollPixels + "px"}, "fast");
			$("#" + gallery.id + "-Thumbs-" + nextSet).animate({left: "0"}, "fast");
			gallery.currentSet = nextSet;
			gallery.addXtoYofZ();	
		}
		
		gallery.scrollRight = function (nextSet) {
			$("#" + gallery.id + "-Thumbs-" + gallery.currentSet).animate({left: "-" + gallery.scrollPixels + "px"}, "fast");
			$("#" + gallery.id + "-Thumbs-" + nextSet).animate({left: "0"}, "fast");				
			gallery.currentSet = nextSet;
			gallery.addXtoYofZ();
		}
		
		gallery.scrollLeftMain = function () {
			if (args.type == 1 && gallery.maxSets > 1) {
				for (var i = 1; i <= gallery.maxSets; i++) {
					if (i != gallery.currentSet) $("#" + gallery.id + "-Thumbs-" + i).css("left", "-" + gallery.scrollPixels + "px");
				}
			}
			if (gallery.currentSet > 1) {
				gallery.scrollLeft(gallery.currentSet - 1);
			} else if (args.type == 1 && gallery.maxSets > 1) {				
				gallery.scrollLeft(gallery.maxSets);				
			}
			gallery.setScrollers();
		}
		
		gallery.scrollRightMain = function () {
			if (args.type == 1 && gallery.maxSets > 1) {
				for (var i = 1; i <= gallery.maxSets; i++) {
					if (i != gallery.currentSet) $("#" + gallery.id + "-Thumbs-" + i).css("left", gallery.scrollPixels + "px");
				}
			}
			if (gallery.currentSet < gallery.maxSets) {
				gallery.scrollRight(gallery.currentSet + 1);		
			} else if (args.type == 1 && gallery.maxSets > 1) {				
				gallery.scrollRight(1);
			}
			gallery.setScrollers();
		}
		
		// adds scrolling actions for a gallery
		$("#" + gallery.id + "-ScrollLeft").click(function() {gallery.scrollLeftMain();}).css("cursor", "pointer");
		
		$("#" + gallery.id + "-ScrollRight").click(function() {gallery.scrollRightMain();}).css("cursor", "pointer");
		
		// sets up the left and right scrollers
		gallery.setScrollers = function() {
			if ((args.type != 1 && gallery.currentSet == 1) || (args.type == 1 && gallery.maxSets == 1)) $("#" + gallery.id + "-ScrollLeft").children("img").hide();
			else $("#" + gallery.id + "-ScrollLeft").children("img").show();
				
			if ((args.type != 1 && gallery.currentSet == gallery.maxSets) || (args.type == 1 && gallery.maxSets == 1)) $("#" + gallery.id + "-ScrollRight").children("img").hide();
			else $("#" + gallery.id + "-ScrollRight").children("img").show();
		}
		
		gallery.setScrollers();
		gallery.addXtoYofZ();
		
		// if a default image has been passed in, the thumbs will scroll to that set
		if (args.type == 3 && args.default_img != -1) {
			var showSet = Math.ceil(args.default_img / gallery.imagesPerSet);
			if (showSet > 1) {
				for (var i = 1; i < showSet; i++) {
					gallery.scrollRightMain();
				}
			}
		}
	}
	
	if (args.type == 1) {
		// plays a gallery slideshow
		$("#" + gallery.id + "-Play").click(function() {
			if (!gallery.slideShow)  {
				gallery.slideShow = true;
				setTimeout("showJQGalleryNextImg('" + gallery.id + "')", 0);
				$("#" + gallery.id + '-Play').fadeOut();
			}
		}).css("cursor", "pointer");
		
		// adds functionality for the thumbs
		$("#" + gallery.id + "-ThumbsContainer").mouseenter(function() {
			$("#" + gallery.id + "-ThumbsInner").animate({marginTop: "0px"}, "fast");
			$("#" + gallery.id + "-ThumbsHeaderMore").fadeOut("fast");
			if (!gallery.slideShow) $("#" + gallery.id + "-Play").fadeIn("fast");
		}).mouseleave(function() {
			$("#" + gallery.id + "-ThumbsInner").animate({marginTop: "100px"}, "fast");
			$("#" + gallery.id + "-ThumbsHeaderMore").fadeIn("fast");
			if (!gallery.slideShow) $("#" + gallery.id + "-Play").fadeOut("fast");
		});
		
		$("#" + gallery.id + "-Thumbs").children().children().mouseenter(function() {
			var imgW = $(this).children("img").width();
			var bW = parseInt($(this).children(".galleryThumbImageBorder").css("border-left-width"))*2;
			$(this).children(".galleryThumbImageBorder").css("width",(imgW-bW)+"px").show();
			$(this).children("img").css("opacity", "1");
		}).mouseleave(function() {
			if ($(this).children("img").attr("id") != gallery.id + '-thumb-image-' + gallery.currentImg) {
				$(this).children(".galleryThumbImageBorder").hide();
				$(this).children("img").css("opacity", gallery.thumbOverlayOpacity);
			}
		}).css("cursor", "pointer");
		
	} else if (args.type == 2 || args.type == 4) {
		$("#" + gallery.id + "-Thumbs").children().css("cursor", "pointer");
	}
	
	// starts the rotation onload
	setTimeout("showJQGalleryNextImg('" + gallery.id + "')", gallery.displayTime);
}

// adds a new gallery
function addJQGallery(args) {
	jqGalleries[args.id] = new JQGallery(args);
}

// displays a specific image
function jumpToJQGalleryImg(id, img) {
	jqGalleries[id].showImage(img, false);	
}

// displays the next gallery image
function showJQGalleryNextImg(id) {
	jqGalleries[id].nextImage();
}

function addFeatureIcons(id,pax,beds,baths,car,ac,heated_pool,private_pool,shared_pool,boj,lux){
	if (lux == 1) iconDir = "lux";
	else if (boj == 1) iconDir = "boj";
	else iconDir = "std";
	
	if (car == 1) carT = "optional";
	else if (car == 2) carT = "recommended";
	else if (car == 3) carT = "essential";
	else carT = "none";
	
	var iconHTML = "<img align=\"left\" alt=\"Villa sleeps "+pax+"\" src=\"/images/accom/feature_icons/"+iconDir+"/large/Sleeps"+pax+".jpg\" />"+
		"<img alt=\""+beds+" bedroom"+addAnS(beds)+"\" src=\"/images/accom/feature_icons/"+iconDir+"/large/Beds"+beds+".jpg\" style=\"padding-left:3px;vertical-align:top\" />"+
		"<img alt=\""+baths+" bathroom"+addAnS(baths)+"\" src=\"/images/accom/feature_icons/"+iconDir+"/large/Baths"+baths+".jpg\" style=\"padding-left:3px;vertical-align:top\" />";

	if (carT != "none") 
		iconHTML += "<img alt=\"car is " + carT +"\" src=\"/images/accom/feature_icons/"+iconDir+"/large/car_"+carT+"-en.jpg\" style=\"padding-left:3px;vertical-align:top\" />";

	if (ac == 1)
		iconHTML += "<img alt=\"Air conditioning is available\" src=\"/images/accom/feature_icons/"+iconDir+"/large/airCon.jpg\" style=\"padding-left:3px;vertical-align:top\" />";
		
	// pools icons: private, private heated, shared, shared heated
	if (private_pool == 1) {
		if (heated_pool == 1) {
			iconHTML += "<img alt=\"Pool heating is available\" src=\"/images/accom/feature_icons/"+iconDir+"/large/private_heatedpool-en.jpg\" style=\"padding-left:3px;vertical-align:top\" />";
		} else {
			iconHTML += "<img alt=\"Pool heating is available\" src=\"/images/accom/feature_icons/"+iconDir+"/large/privatepool-en.jpg\" style=\"padding-left:3px;vertical-align:top\" />";
		}
	} else if (shared_pool == 1) {
		if (heated_pool == 1) {
			iconHTML += "<img alt=\"Pool heating is available\" src=\"/images/accom/feature_icons/"+iconDir+"/large/shared_heatedpool-en.jpg\" style=\"padding-left:3px;vertical-align:top\" />";
		} else {
			iconHTML += "<img alt=\"Pool heating is available\" src=\"/images/accom/feature_icons/"+iconDir+"/large/sharedpool-en.jpg\" style=\"padding-left:3px;vertical-align:top\" />";
		}
	}
	return iconHTML;			
}
function addAnS(n) {
	if (n == "1")
		return "";
	return "s";	
}

// Villa short list function
function fnShortListWrapper (divName, urlParams) {
	ajaxSendD('/villa-shortlist/ajax.cfm?divName=' + divName + '&' + urlParams, 'generic', divName);
}

function d(dt) {
	/* Returns JS date object from '01/01/07' format */
	return new Date(parseFloat(dt.substring(0,2))+2000, parseFloat(dt.substring(2,4))-1, dt.substring(4,6));
}


function addVilla(villa_id, addORrem) {
	if (addORrem) {
		bookmarkedVillas = bookmarkedVillas + villa_id + ",";
	} else {
		bookmarkedVillas = bookmarkedVillas.replace(","+villa_id+",", ",");
	}
}
