function clearAndLoad(area)
{
	// document.getElementById("region_1_drop").innerHTML = '';
	
	var areaOption = document.searchform['region_'+area];
	var areaSelected = areaOption.options[areaOption.selectedIndex].value;
	
	if (areaSelected != '' && area < 3)
	{
		xhrLoadAndStuff('/generated/region_lodging_dropdown/region_'+(area+1)+'_'+areaSelected+'.html', null, 'region_'+(area+1)+'_drop');
	}
	else if (areaSelected == '' && area < 3)
	{
		area--;
	}

	for (i = area + 2; i < 4; i++)
	{
		var divLayer = document.getElementById('region_'+i+'_drop');
		if (divLayer)
		{
			divLayer.innerHTML = '<select name="region-'+i+'" style="width:100%;" onchange="javascript:clearAndLoad('+i+');" disabled></select>';
		}
	} 
	
}

function resetRegion()
{
	var areaOption = document.searchform['region_1'];
	areaOption.selectedIndex = 0;
	
	clearAndLoad(1);
}


/*
| Highlight an element
*/
function highlightElement(element, color)
{
	element.style.backgroundColor = color;
}

/*
| Unhighlight the element
*/
function highlightElement(element, color)
{
	element.style.backgroundColor = color;
}

function setInMotionFalse()
{
	inMotion = false;
}

var lfBoxOpened = 'deals';
var lfBoxClosed = 'packages';

var lfScrollBoxOpened = 'deals-scroll-box';
var lfScrollBoxClosed = 'packages-scroll-box';

var inMotion = false;

/* 
| Slide elements of the packages and incredideals
*/
function slideElements(upID, downID)
{
	if ($(upID) && $(upID).style.display == '')
	{
		if (inMotion == true)
		{
			return;
		}

		inMotion = true;
		
		new Effect.Parallel(
			[
				Effect.BlindDown(downID,
					{
						delay: .1,
						afterFinish: function() { setInMotionFalse(); }
					}
				),
				Effect.BlindUp(upID)
			],
			{
				duration: .3
			}
		);
		
		
		temp = lfScrollBoxOpened;
		lfScrollBoxOpened = lfScrollBoxClosed;
		lfScrollBoxClosed = temp;

		return true;
	}
	
	if ($(downID) && $(downID).style.display == 'none')
	{
		if (inMotion == true)
		{
			return;
		}

		inMotion = true;
		
		new Effect.Parallel(
			[
				Effect.BlindDown(downID,
					{
						delay: .1
					}
				),
				Effect.BlindUp(upID,
					{
						afterFinish: function() { setInMotionFalse(); }
					}
				)
			],
			{
				duration: .3
			}
		);
		
		temp = lfScrollBoxOpened;
		lfScrollBoxOpened = lfScrollBoxClosed;
		lfScrollBoxClosed = temp;
		
		return false;
	}
	
	return;
}

var numberOfScrolls = 1;

// Scrolls the packages and incredideals
function scrollBoxes()
{
		new Effect.SlideUp($(lfScrollBoxOpened).firstDescendant(),
			{
				duration: .4,
				afterFinish: function()
					{
						$($(lfScrollBoxOpened).firstDescendant()).remove();
					}
			}
		);
		
		numberOfScrolls++;

		if (numberOfScrolls == 8)
		{
			numberOfScrolls = 1;

			new Ajax.Updater(lfScrollBoxOpened, '/includes/widgets/' + lfBoxOpened + 'Box.php',
				{
					method: 'get',
					insertion: Insertion.Bottom
				}
			);
		}
}

var linkNum = 1;

// Hides and shows quicksearch/map on homepage
function switchLinks()
{
	if (linkNum == 1)
	{
		$('switch-heading').innerHTML = '<h4><a href="javascript:switchLinks()"><strong class="search-box-headings-deselected">Search by Map</strong></a></h4><h4><strong>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;</strong></h4><h4><strong class="search-box-headings-selected">Quick Search</strong></h4>';
		
		$('search-by-map').style.display = 'none';
		$('quick-search').style.display = '';
		
		$('search-input').focus();
		
		tempNum = 2;
	}

	if (linkNum == 2)
	{
		$('switch-heading').innerHTML = '<h4><strong class="search-box-headings-selected">Search by Map</strong></h4><h4><strong>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;</strong></h4><h4><a href="javascript:switchLinks()"><strong class="search-box-headings-deselected">Quick Search</strong></a></h4>';

		$('quick-search').style.display = 'none';
		$('search-by-map').style.display = '';
		
		tempNum = 1;
	}
	
	linkNum = tempNum;
}

// Callback function from the flash destination video that sets the title above the destination video
function setDestinationTitle(title)
{
	$('destination-title').innerHTML = '<h4>' + title + '</h4>';
}

//function dealClick(dealID, clickUrl, type)
//{
//	var url = '/util/travelDealsClickStats.php';
//
//	new Ajax.Request(url, {
//		method: 'post',
//		parameters: {
//			channel: 'ral',
//			deal_id: dealID,
//			section: 'home'
//		},
//		onComplete: function (transport)
//		{
//			window.open(clickUrl, type);
//		}
//	});
//}

function dealClick(page, regionId, table, filterfield, filtervalue, listingId, target, websiteurl, newpage)
{
	var url = '/util/travelDealsClickStats.php';

	new Ajax.Request(url, {
		method: 'post',
		parameters: {
			p: page,
			r: regionId,
			t: table,
			f: filterfield,
			v: filtervalue,
			l: listingId,
			u: target
		},
		onComplete: function (transport)
		{
			if ( newpage )
				window.open(websiteurl,'','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
			else
				location.href = websiteurl;
		}
	});
}