function setInputToggle(elt) {
	$(elt).focus(
		function() {
			if ($(this).val() == $(this).attr('default')) {
				$(this).val('');
			}
		}
	).blur(
		function() {
			if ($(this).val() == '') {
				$(this).val($(this).attr('default'));
			}
		}
	);
	$(elt).blur();
}
function setInputToggleOnForm(form) {
	$(form).find("input[type='text']").each(function() {
		setInputToggle(this);
	});
	$(form).submit(function() {
		$(this).find("input[type='text']").each(function() {
			var elt = $(this);
			if (elt.attr('default') == elt.val()) {
				elt.val('');
			}
		});
	});
}
function createPasswordToggle(elt) {
	var elt = $(elt);
	// create plain
	var eltCopy = $("<input type='text' value='" + elt.attr('default') + "' />").focus(function() {
		$(this).hide();
		elt.show().focus();
	}).insertAfter(elt);
	
	// add on blur to password input
	elt.blur(function() {
		if ($(this).val() == '') {
			$(this).hide();
			eltCopy.show();
		}
	}).hide();
	return elt;
}

function disableSubmitDoubleClick(form) {
	$(form + " :submit").click(function() { $(this).hide() });
}

function renderCertificate() {
	ajaxHTML('/certificate', null, function(html) {
		$('#footer').hide();
		$('#anytimeCertificate').html(html).show();
	});
}

function enterGrandPrize(link) {
	ajax('/person/enter.grand.prize', null, function(json) {
		$('#grandPrizeEnteredContainer').show();
		$('#enterGrandPrizeContainer').hide();
	});
}

function inlinePopup(url) {
	$('#popupcontainer').load(url, function() { $('#popupcontainer').show(); });
}

function closePopup() {
	$('#popupcontainer').hide();
}

function switchtour(id) {
	$('#detailscontainer .tourfeature').html($('#'+id+' .tourfeature').html());
	$('#detailscontainer .tourcontent').html($('#'+id+' .tourcontent').html());
	$('#tournav a').removeClass('selected');
	$('#tournav .'+id).addClass('selected');
}

var Trip = {};
Trip.selected = null;
Trip.preview = function(elt, id) {
	// deselect trip preview link
	if (Trip.selected) {
		Trip.selected.removeClass('selected');
	}
	
	// save and select new preview link
	Trip.selected = $(elt).addClass('selected');

	// show destinations and update take trip link
	$('#preMadeTrips .scrollarea').html($('#preMadeTrip' + id).clone().show());
	$('#takeThisTripLink').unbind('click').click(function() {
		Trip.take(id);
	}).css('display', 'block');
	
	// plot destinations
	destinations.plot(id);
}
Trip.reset = function() {
	if (Trip.selected) {
		Trip.selected.removeClass('selected');
	}
	Trip.selected = null;
	$('#preMadeTrips .scrollarea').empty();
	$('#takeThisTripLink').hide();
}
Trip.take = function(id) {
	// take this trip
	destinations.addTripDestinationsToPending(id)
	ViewManager.tripBuilderFrom('premadeTrips', id);
}


function setMap(value) {
	$('.regions').removeClass().addClass('regions').addClass(value);
	$('.regions').show();
}

function openWindow(url) {
	window.open(url,null,'status=0,scrollbars=1,toolbar=1,menubar=1,resizable=1,width=875,height=768'); return false;
}
