var origIdx;
function showMoreOptions(dir) {
	if (dir == 1) {
		if ($('hs_MinStarRating')) $('hs_MinStarRating').style.display = 'block';
		if ($('hs_BoardBases')) $('hs_BoardBases').style.display = 'block';
		if ($('hs_adv_opts')) $('hs_adv_opts').style.display = 'block';
		$('lnk_MO').innerHTML = 'Hide Advanced Options <img src="/images/template/sidebar_search_contract.gif" style="border:none;">';
		$('lnk_MO').href = 'javascript:showMoreOptions(0);'
	} else {
		if ($('hs_MinStarRating')) $('hs_MinStarRating').style.display = 'none';
		if ($('hs_BoardBases')) $('hs_BoardBases').style.display = 'none';
		if ($('hs_adv_opts')) $('hs_adv_opts').style.display = 'none';
		$('ff_SR').selectedIndex = 0;
		$('ff_BB').selectedIndex = 0;
		$('lnk_MO').innerHTML = 'Show Advanced Options <img src="/images/template/sidebar_search_expand.gif" style="border:none;">';
		$('lnk_MO').href = 'javascript:showMoreOptions(1);'
	}
}

function js_OnlineClosed() {
	alert('Please try again at 8am. Our supplier\'s system is closed at present and will not be available until then.');
}

var domReady = false;
function cycleUntilReady (callback) {
	if (domReady) {
		callback();
	} else {
		window.setTimeout(function() {cycleUntilReady(callback);},100);
	}
}

function openRatingsExplained(editID, num_height){
	var str_url = "/ratingsExplained.cfm?editID="+editID;
	var tmp_newWindow = window.open(str_url, "ratingsExplained", "HEIGHT="+num_height+",WIDTH=500,toolbar=no,scrollbars=yes,status=no,menubar=no,resizeable=no");
}

function imageWindow(path, imgWidth, imgHeight) {
	var newWindow = window.open('/displayImage.cfm?imageURL='+path, 'imageWindow', 'HEIGHT='+imgHeight+',WIDTH='+imgWidth+',toolbar=no,scrollbar=no,status=no,menubar=no,resizeable=no');
}


function on_availframeload()
{
	Event.stopObserving('availiframe', 'load', on_availframeload);
	resizeAvailFrame();
	var doc;
	if ($('availiframe').contentDocument === undefined)
	{
		doc = $('availiframe').contentWindow.document;
	}
	else
	{
		doc = $('availiframe').contentDocument;
		
	}
	Event.observe(doc.getElementById('room_1_child'), 'change', function(event) {
		window.setTimeout(resizeAvailFrame, 10)
		
	});

}
function resizeAvailFrame()
{
	var doc;
	if ($('availiframe').contentDocument === undefined)
	{
		doc = $('availiframe').contentWindow.document;
	}
	else
	{
		doc = $('availiframe').contentDocument;
		
	}
	
	if (doc.getElementById('atthebottom').cumulativeOffset === undefined)
	{
		offset = doc.getElementById('atthebottom').offsetTop;
	}
	else
	{
		offset = doc.getElementById('atthebottom').cumulativeOffset()[1];
		
	}
	$('availiframe').style.height = offset + 15 + 'px';
}

function showAvailpop(idx, img, xmlid)
{
	origIdx = idx;
	Event.observe('availiframe', 'load', on_availframeload);
	
	var str_nn = '&in_numnights=';
	try {
		if ($('multicom_search_nights') && $('multicom_search_nights').style.display == 'block') {
			str_nn += $('nightsDrop').value;
		} else if ($('hoeseasons_search_nights') && $('hoeseasons_search_nights').style.display == 'block') {
			str_nn += $('nightsDrop_hos').value;
		}
	} catch (e) {
		str_nn = '';	
	}
	
	if (xmlid == Number(xmlid)) {
		$('availiframe').src = "/avail.cfm?str_ref=" + xmlid + str_nn;	
	} else {
		$('availiframe').src = "/avail.cfm?str_xmlID=" + xmlid + "&origIdx=" + idx + str_nn;
	}

	if (img.cumulativeOffset === undefined)
	{
		offsettop = Element.cumulativeOffset(img)[1];
		offsetleft = Element.cumulativeOffset(img)[0];
	}
	else
	{
		offsettop = img.cumulativeOffset()[1];
		offsetleft = img.cumulativeOffset()[0];
	}

	$('availabilitybox').style.top = (offsettop + 30) + 'px';
	$('availabilitybox').style.left = (offsetleft - 380) + 'px'; 
	$('availabilitybox').show();
	$('blackout').show();
	$('blackout').style.height = $('main').offsetHeight + $('availabilitybox').offsetHeight + "px";
	Effect.ScrollTo($('resultanchor_' + idx));
	//$('resultanchor_' + idx).scrollTo();
}

function hideAvailpop()
{
	$('availabilitybox').hide();
	$('blackout').hide();

}