function clearBox(f) {
	if(f.value==f.defaultValue) {
		f.value = '';	
	}
}

function restoreBox(f) {
	if(f.value=='') {
		f.value = f.defaultValue;	
	}
}

// Tip flagger						
function flagTip(id)
{	
	if(confirm("Are you sure you wish to flag this tip as innaccurate?"))
	{
		document.getElementById("flagtip"+id).submit();
	}
	else
	{
		return false;
	}
}

// Sidebar search updaters
function updateRegions(country) {
	if(country>0) {
		document.getElementById('search_region').innerHTML = '<select name="search[region]" onchange="updateSubRegions(this.value);">'+regions[country]+'</option>';
		document.getElementById('search_region_row').style.display = 'block';
	}
	else {
		document.getElementById('search_region').innerHTML = '<select name="search[region]" onchange="updateSubRegions(this.value);"><option value="0">Select a Country</option></select>';
		document.getElementById('search_region_row').style.display = 'none';
	}
	
	updateSubRegions(0);
}


function updateSubRegions(region) {
	if(region>0) {
		document.getElementById('search_subregion').innerHTML = '<select name="search[subregion]">'+subregions[region]+'</select>';
		document.getElementById('search_subregion_row').style.display = 'block';
	}
	else {
		document.getElementById('search_subregion').innerHTML = '<select name="search[subregion]"><option value="0">Select a Region</option></select>';
		document.getElementById('search_subregion_row').style.display = 'none';
	}
}

function switchEnabled(region)
{
	if(region > 0)
	{
		document.getElementById('titlebox').disabled = "";
		document.getElementById('tipbox').disabled = "";
		document.getElementById('tipsubmit').disabled = "";
	}
	else
	{
		document.getElementById('titlebox').disabled = "disabled";
		document.getElementById('tipbox').disabled = "disabled";
		document.getElementById('tipsubmit').disabled = "disabled";
	}
}

// Tips Updater
function updateTRegions(country) {
	if(country>0) {
		document.getElementById('tips_region').innerHTML = '<select name="region" onchange="updateTSubRegions(this.value);">'+tregions[country]+'</option>';
		document.getElementById('tips_region_row').className = 'trshow';
	}
	else {
		document.getElementById('tips_region').innerHTML = '<select name="region" onchange="updateTSubRegions(this.value);"><option value="0">Select a Country</option></select>';
		document.getElementById('tips_region_row').className = 'trhide';		
	}
	
	updateTSubRegions(0);
}

function updateTSubRegions(region) {
	if(region>0) {
		document.getElementById('tips_subregion').innerHTML = '<select name="subregion" onchange="updateTTowns(this.value);">'+tsubregions[region]+'</select>';
		document.getElementById('tips_subregion_row').className = 'trshow';
		
	}
	else {
		document.getElementById('tips_subregion').innerHTML = '<select name="subregion" onchange="updateTTowns(this.value);"><option value="0">Select a Region</option></select>';
		document.getElementById('tips_subregion_row').className = 'trhide';		
	}
	
	updateTTowns(0);
}

function updateTTowns(subregion) {
	if(subregion>0) {
		document.getElementById('tips_town').innerHTML = '<select name="tips[town]">'+ttowns[subregion]+'</select>';
		document.getElementById('tips_town_row').className = 'trshow';
		
	}
	else {
		document.getElementById('tips_town').innerHTML = '<select name="tips[town]"><option value="0">Select a Subregion</option></select>';
		document.getElementById('tips_town_row').className = 'trhide';
		
	}
}

// Add Properties Updater
function updateARegions(country) {
	if(country>0) {
		document.getElementById('add_region').innerHTML = '<select name="misc[region]" onchange="updateASubRegions(this.value);">'+aregions[country]+'</option>';
		document.getElementById('add_region_row').className = 'trshow';
	}
	else {
		document.getElementById('add_region').innerHTML = '<select name="misc[region]" onchange="updateASubRegions(this.value);"><option value="0">Select a Country</option></select>';
		document.getElementById('add_region_row').className = 'trhide';
	}
	
	updateASubRegions(0);
}


function updateASubRegions(region) {
	if(region>0) {
		document.getElementById('add_subregion').innerHTML = '<select name="property[subregions_id]" onchange="updateATowns(this.value);">'+asubregions[region]+'</select>';
		document.getElementById('add_subregion_row').className = 'trshow';
		
	}
	else {
		document.getElementById('add_subregion').innerHTML = '<select name="property[subregions_id]" onchange="updateATowns(this.value);"><option value="x">Select a Region</option></select>';
		document.getElementById('add_subregion_row').className = 'trhide';		
	}
	
	updateATowns(0);
}

function updateATowns(subregion) {
	if(subregion>0) {
		document.getElementById('add_town').innerHTML = '<select name="property[towns_id]">'+atowns[subregion]+'</select>';
		document.getElementById('add_town_row').className = 'trshow';
	}
	else {
		document.getElementById('add_town').innerHTML = '<select name="property[towns_id]"><option value="x">Select a Subregion</option></select>';
		document.getElementById('add_town_row').className = 'trhide';
	}
}

// Content Administration updater
function updateCRegions(country) {
	if(country>0) {
		document.getElementById('content_region').innerHTML = '<select name="item[regions_id]" onchange="updateCSubRegions(this.value);">'+cregions[country]+'</option>';
		document.getElementById('content_region_row').className = 'trshow';
	}
	else {
		document.getElementById('content_region').innerHTML = '<select name="item[regions_id]" onchange="updateCSubRegions(this.value);"><option value="0">Select a Country</option></select>';
		document.getElementById('content_region_row').className = 'trhide';
	}
	
	updateCSubRegions(0);
}


function updateCSubRegions(region) {
	if(region>0) {
		document.getElementById('content_subregion').innerHTML = '<select name="item[subregions_id]" onchange="updateCTowns(this.value);">'+csubregions[region]+'</select>';
		document.getElementById('content_subregion_row').className = 'trshow';
		
	}
	else {
		document.getElementById('content_subregion').innerHTML = '<select name="item[subregions_id]" onchange="updateCTowns(this.value);"><option value="0">Select a Region</option></select>';
		document.getElementById('content_subregion_row').className = 'trhide';		
	}
	
	updateCTowns(0);
}

function updateCTowns(subregion) {
	if(subregion>0) {
		document.getElementById('content_town').innerHTML = '<select name="item[towns_id]">'+ctowns[subregion]+'</select>';
		document.getElementById('content_town_row').className = 'trshow';
	}
	else {
		document.getElementById('content_town').innerHTML = '<select name="item[towns_id]"><option value="0">Select a Subregion</option></select>';
		document.getElementById('content_town_row').className = 'trhide';
	}
}

// Tips Administration updater
function updateTARegions(country) {
	if(country>0) {
		document.getElementById('content_region').innerHTML = '<select name="tip[rid]" onchange="updateTASubRegions(this.value);">'+taregions[country]+'</option>';
		document.getElementById('content_region_row').className = 'trshow';
	}
	else {
		document.getElementById('content_region').innerHTML = '<select name="tip[rid]" onchange="updateTASubRegions(this.value);"><option value="0">Select a Country</option></select>';
		document.getElementById('content_region_row').className = 'trhide';
	}
	//
	updateTASubRegions(0);
	
	
}


function updateTASubRegions(region) {
	if(region>0) {
		document.getElementById('content_subregion').innerHTML = '<select name="tip[sid]" onchange="updateTATowns(this.value);">'+tasubregions[region]+'</select>';
		document.getElementById('content_subregion_row').className = 'trshow';
		
	}
	else {
		document.getElementById('content_subregion').innerHTML = '<select name="tip[sid]" onchange="updateTATowns(this.value);"><option value="0">Select a Region</option></select>';
		document.getElementById('content_subregion_row').className = 'trhide';		
	}
	updateTATowns(0);
}

function updateTATowns(subregion) {
	document.getElementById('stown').value = 0;
	if(subregion>0) {
		document.getElementById('content_town').innerHTML = '<select onchange="document.getElementById(\'stown\').value = this.value;" name="item[towns_id]">'+tatowns[subregion]+'</select>';
		document.getElementById('content_town_row').className = 'trshow';
	}
	else {
		document.getElementById('content_town').innerHTML = '<select onchange="document.getElementById(\'stown\').value = this.value;" name="item[towns_id]"><option value="0">Select a Subregion</option></select>';
		document.getElementById('content_town_row').className = 'trhide';
	}
}

// Set Currency function for availability calender
function setAvCurrency(c, u)
{
	hidethis = document.getElementById("s_curr_"+u).value;
	document.getElementById("u_curr_"+u+"_"+hidethis).style.display = "none";
	document.getElementById("u_curr_"+u+"_"+c).style.display = "block";
	document.getElementById("s_curr_"+u).value = c;
	document.getElementById("u_sym_"+u+"_"+hidethis).style.color = "#88ac49";
	document.getElementById("u_sym_"+u+"_"+c).style.color = "#124000";
}

// Menu Opener
function openMenu()
{
	document.getElementById("editmenu").style.display = "block";
	document.getElementById("editbutton").style.display = "none";
}

// Menu closer
function closeMenu()
{

	document.getElementById("editbutton").style.display = "block";
	document.getElementById("editmenu").style.display = "none";	
}

// Amenities boxes
function toggleAmBoxes(id)
{
	if(document.getElementById("d"+id).disabled == false)
	{
		document.getElementById("d"+id).disabled = true;
		document.getElementById("c"+id).style.color = "#aaaaaa";
		document.getElementById("i"+id).style.color = "#aaaaaa";
	}
	else
	{	
		document.getElementById("d"+id).disabled = false;
		document.getElementById("c"+id).style.color = "#333333";
		document.getElementById("i"+id).style.color = "#333333";
	}
}

// Features boxes
function toggleFtBoxes(id)
{
	if(document.getElementById("c"+id).style.color == "#333333" || document.getElementById("c"+id).style.color == "rgb(51, 51, 51)")
	{
		document.getElementById("c"+id).style.color = "#aaaaaa";
	}
	else
	{	
		document.getElementById("c"+id).style.color = "#333333";
	}
}

// Suitability boxes
function toggleStBoxes(id)
{
	if(document.getElementById("s"+id).style.color == "#333333" || document.getElementById("s"+id).style.color == "rgb(51, 51, 51)")
	{
		document.getElementById("s"+id).style.color = "#aaaaaa";
	}
	else
	{	
		document.getElementById("s"+id).style.color = "#333333";
	}
}

// Transport boxes
function toggleTsBoxes(id)
{
	if(document.getElementById("d"+id).disabled == false)
	{
		document.getElementById("d"+id).disabled = true;
		document.getElementById("c"+id).style.color = "#cccccc";
	}
	else
	{	
		document.getElementById("d"+id).disabled = false;
		document.getElementById("c"+id).style.color = "#333333";
	}
}
			

// Units/Deals/Unavailable/Rates toggler
function toggleCurrent(id)
{
	if(document.getElementById("edit"+id).className == "rows hide-row")
	{
		document.getElementById("edit"+id).className = "rows show-row";
		document.getElementById("current"+id).className = "rows hide-row";					
	}
	else
	{
		document.getElementById("edit"+id).className = "rows hide-row";
		document.getElementById("current"+id).className = "rows show-row";
	}
}

// Step next page
function setNextPage(page)
{
	document.getElementById("nextstep").value = page;
	document.step.submit();
	return false;
}

// Rates/Unav/Deal/Unit delete
function setDelete(id)
{
	if(confirm('Are you sure you wish to delete this item?'))
	{
		document.getElementById("d"+id).value = "delete";
		document.getElementById("f"+id).submit();
	}
	else
	{
		return false;
	}
}

// Homepage/property listing currency switcher
function setHpCurrency(c)
{
	var oldCurr = document.getElementById("s_curr").value;
	document.getElementById("s_curr").value = c;
	document.getElementById("prices"+oldCurr).style.display = "none";
	document.getElementById("prices"+c).style.display = "block";
	document.getElementById("cur"+oldCurr).style.color = "#88ac49";
	document.getElementById("cur"+c).style.color = "#124000";
}

// Property currency and unit switcher
function setPyCurrency(c)
{
	var u = document.getElementById("s_unit").value;				
	if((document.getElementById("s_unit").value != -1) && (c != -1))
	{
		var oldCurr = document.getElementById("s_curr").value;
		document.getElementById("cur"+oldCurr).style.color = "#88ac49";
		document.getElementById("cur"+c).style.color = "#124000";
		var hideThis = document.getElementById("temp").value;
							
		if(hideThis != 0)
		{
			document.getElementById(hideThis).style.display = "none";
		}
		document.getElementById("s_curr").value = c;
		document.getElementById("prices"+c+u).style.display = "block";
		document.getElementById("temp").value = "prices"+c+u;
	}
}

function setPyUnit(u)
{
	var c = document.getElementById("s_curr").value;
	
	if((document.getElementById("s_curr").value != -1) && (u != -1))
	{
		var hideThis = document.getElementById("temp").value;
		if(hideThis != 0)
		{
			document.getElementById(hideThis).style.display = "none";
		}
		document.getElementById("prices"+c+u).style.display = "block";
		document.getElementById("temp").value = "prices"+c+u;
	}
}

// Review stars
function starHover(star, row) // Hover
{
	var offset = 14;
	document.getElementById("starsoff"+row).style.marginLeft = (star*offset)+"px";
}

function starReset(row) // Reset
{
	var offset = 14;
	if(document.getElementById("starTemp"+row).value != -1)
	{
		document.getElementById("starsoff"+row).style.marginLeft = (document.getElementById("starTemp"+row).value*offset)+"px";
	}
	else
	{
		document.getElementById("starsoff"+row).style.marginLeft = 0;
	}
}

function starSet(star, row) // Set
{
	var offset = 14;
	if(star != -1)
	{
		document.getElementById("starTemp"+row).value = star;
		document.getElementById("starsoff"+row).style.marginLeft = (document.getElementById("starTemp"+row).value*offset)+"px";	
	}
}

// Faves
function bookmark(url, title) 
{
	if (window.sidebar) { // Mozilla Firefox Bookmark		
		window.sidebar.addPanel(title, url,"");
	} 
	else if( window.external ) { // IE Favorite		
		window.external.AddFavorite( url, title);
	}	
	else if(window.opera && window.print) { // Opera Hotlist		
		return true;
	}
} 
		
		

// Enquiry deleter
function deleteMessage(id)
{
	if(confirm("Are you sure you wish to delete this enquiry?"))
	{
		window.location = '/us-enquiries/delete/'+id;
	}
	else
	{
		return false;
	}
}

// Disable proeprty
function dprop(id)
{
	if(confirm("Clicking OK will disable this property and so remove it from the listings. No-one will be able to find this property, book holidays or make enquiries upon it. Are you sure you wish to continue?"))
	{
		window.location = "/ap-disable/"+id;
	}
	else
	{
		return false;
	}
}

// Enable proeprty
function eprop(id)
{
	if(confirm("Clicking OK will enable this property and restore its listing to fully visible. Are you sure you wish to continue?"))
	{
		window.location = "/ap-enable/"+id;
	}
	else
	{
		return false;
	}
}

// Toggle Calendar IFRAME
function toggleCalendar()
{
	if(document.getElementById("ac").style.display == 'block')
	{
		document.getElementById("ac").style.display = 'none';
	}
	else
	{
		document.getElementById("ac").style.display = 'block';
	}
}

// Delete Property
function deleteProperty(id)
{
	if(confirm("Clicking \"OK\" will completely remove this property from the system. All photos, units and pricing associated with this property will be deleted. However, Salesforce data will not be affected. This process is irreversible. Are you sure you wish to continue?"))
	{
		window.location = "/property-delete.php?id="+id;	
	}
	else
	{
		return false;
	}
}

// Wishlist
function toggleWishlist(id)
{
	c_name = 'wishlist';
	var data;
	var i = 0;
	var myArray = new Array;
	var exists = 0;
	
	var exdate = new Date();
	exdate.setDate(exdate.getDate()+365);
	document.cookie = 'en=1;expires='+exdate.toGMTString()+';path=/';
	
	if(!document.cookie)
	{
		alert("Sorry, but you will need to enable cookies to use this feature.");
	}
	else
	{	
		if(document.cookie.length>0)
		{
			exists = 1;
			c_start=document.cookie.indexOf(c_name + "=");
			
			if (c_start!=-1)
			{
				c_start=c_start + c_name.length+1;
				c_end=document.cookie.indexOf(";",c_start);
				
				if (c_end==-1)
				{
					c_end=document.cookie.length;
				}
				
				data = unescape(document.cookie.substring(c_start,c_end));
			}
			
			if(data)
			{
				var myArray = data.split(',');
				
				for(i=0; i < myArray.length; i++)
				{
					if(myArray[i] == id)
					{
						myArray[i] = 0;
						var gone = 1;
					}
				}
			}
		}
		
		if(gone != 1)
		{
			if(exists == 1)
			{
				myArray[i+1] = id;
			}
			else
			{
				myArray[0] = id;
			}
			if(document.getElementById('wishadd')) document.getElementById('wishadd').style.display = 'none';
			if(document.getElementById('wishrem')) document.getElementById('wishrem').style.display = 'block';
		}
		else
		{
			if(document.getElementById('wishadd')) document.getElementById('wishadd').style.display = 'block';
			if(document.getElementById('wishrem')) document.getElementById('wishrem').style.display = 'none';		
		}
		
		var exdate = new Date();
		exdate.setDate(exdate.getDate()+365);
		document.cookie = 'wishlist='+escape(myArray.toString())+';expires='+exdate.toGMTString()+';path=/';
	}
}

function removeWish(id)
{
	document.getElementById('p'+id).value = '0';
	document.getElementById('wl'+id).style.display = 'none';
	document.getElementById('clicks').value = parseInt(document.getElementById('clicks').value)+1;	
	
	if(document.getElementById('wishes').value == document.getElementById('clicks').value)
	{
		document.getElementById('enqblock').style.display = 'none';
		document.getElementById('haswishes').style.display = 'none';
		document.getElementById('wishright').style.display = 'none';
		document.getElementById('nowishes').style.display = 'block';
		document.getElementById('wishblock').style.display = 'none';
	}
	
	if(rows) 
	{
		rows[wlitems[id]] = rows[wlitems[id]] - 1;
		
		if(rows[wlitems[id]] == 0)
		{
			document.getElementById('row'+wlitems[id]).style.display = 'none';
			document.getElementById('split'+wlitems[id]).style.display = 'none';
		}
	}
}

function toggleSet(id)
{
	if(document.getElementById('p'+id).value == 0)
	{
		document.getElementById('p'+id).value = 1;
	}
	else
	{
		document.getElementById('p'+id).value = 0;
	}
}

// Filters updater
function updateFRegions(country) {
	if(country>0) {
		document.getElementById('add_region').innerHTML = '<select name="region" onchange="updateFSubRegions(this.value);">'+aregions[country]+'</option>';
		document.getElementById('add_region_row').className = 'trshow';
	}
	else {
		document.getElementById('add_region').innerHTML = '<select name="region" onchange="updateASubRegions(this.value);"><option value="0">Select a Country</option></select>';
		document.getElementById('add_region_row').className = 'trhide';
	}
	
	updateFSubRegions(0);
}


function updateFSubRegions(region) {
	if(region>0) {
		document.getElementById('add_subregion').innerHTML = '<select name="subregion" onchange="updateFTowns(this.value);">'+asubregions[region]+'</select>';
		document.getElementById('add_subregion_row').className = 'trshow';
		
	}
	else {
		document.getElementById('add_subregion').innerHTML = '<select name="subregion" onchange="updateFTowns(this.value);"><option value="x">Select a Region</option></select>';
		document.getElementById('add_subregion_row').className = 'trhide';		
	}
	
	updateFTowns(0);
}

function updateFTowns(subregion) {
	if(subregion>0) {
		document.getElementById('add_town').innerHTML = '<select name="town">'+atowns[subregion]+'</select>';
		document.getElementById('add_town_row').className = 'trshow';
	}
	else {
		document.getElementById('add_town').innerHTML = '<select name="town"><option value="x">Select a Subregion</option></select>';
		document.getElementById('add_town_row').className = 'trhide';
	}
}

function dateFilter()
{
	if((document.getElementById('frmADate').value != 'No Preference') && (document.getElementById('frmDDate').value != 'No Preference'))
	{
		document.forms.datef.submit();	
	}
}

function dateReset(f)
{
	if(f.value == '')
	{
		f.value = 'No Preference';
	}
}

function seeDiv(div, hide, shrink)
{
	document.getElementById(div).style.height = 'auto';
	document.getElementById(hide).style.display = 'none';
	document.getElementById(shrink).style.display = 'block';
}

function hideDiv(div, hide, shrink)
{
	document.getElementById(div).style.height = '65px';
	document.getElementById(hide).style.display = 'block';
	document.getElementById(shrink).style.display = 'none';
}