function forceLogin() {
	document.location.href='/member/main';
}

function addToActive(listingID,isUndo) {
	
	isUndo = isUndo || false; 

	if ($("listing" + listingID)) {
		$('#listing'+listingID).effect("highlight", {}, 300).slideUp(150, function() { $('#listing'+listingID).addClass("deleted"); } );
	}
	
	$.ajax({url:'/index.cfm/fuseaction/member.saveListing/listingID/'+listingID+'/isUndo/'+isUndo, error:forceLogin, cache:false });
	
	if (!isUndo) {
		if ($("#savedTab")) $('#savedTab').effect("pulsate", {times:3}, 100);
	}
}


function toggleSaved(listingID,isUndo) {
	$.ajax({url:'/index.cfm/fuseaction/member.saveListing/listingID/'+listingID+'/isUndo/'+isUndo, error:forceLogin, cache:false });
	if (isUndo) {
		$('#listing'+listingID).fadeOut(500, function() { $('#listing'+listingID).addClass('deleted') } );
		$('#toggle'+listingID).removeClass("discardlisting").addClass("restorelisting").attr("href","javascript:toggleSaved("+listingID+",false)");
	} else {
		$('#listing'+listingID).removeClass("undeleted");
		$('#toggle'+listingID).removeClass("restorelisting").addClass("discardlisting").attr("href","javascript:toggleSaved("+listingID+",true)");
	}
}


function excludeListing(listingID,isUndo) {

	isUndo = isUndo || false; 

	if ($("#listing" + listingID)) {
		$("#listing" + listingID).fadeTo(350,0.20).slideUp(150);
	}
	
	$.ajax({url:'/index.cfm/fuseaction/member.excludeListing/listingID/'+listingID+'/isUndo/'+isUndo, error:forceLogin, cache:false });

}

function toggleDeleted(chk) {
	if (chk.checked) {
		$(".deleted").addClass("undeleted").removeClass("deleted").show();
	} else {
		$(".undeleted").addClass("deleted").removeClass("undeleted").hide();
	}
}


function excludeLister(listerID,isExclude) {
	if (isExclude) {
		$('#listerExcludeLink').hide();
		$('#listerExcludeLinkRemove').show();
	} else {
		$('#listerExcludeLink').show();
		$('#listerExcludeLinkRemove').hide();
	}
	$.ajax( {
		url: '/index.cfm/fuseaction/member.excludeLister/listerID/' + listerID + '/isExclude/' + isExclude,
		error: forceLogin,
		cache:false
	});
}


// document.ready
$(function() {
	
	// bind floating box plus/minus triggers
	$('.trigger').click(function() {
		href = this.getAttribute('href');
		part = href.substr(href.indexOf('#'));
		$(part).toggle(100);
		$(this).toggleClass('open');
		$(this).blur();
		$.post('/index.cfm/fuseaction/member.toggleDetailPref', { pref:$(part).attr('id') });
		return false;
	});
	
	// save confirmation dialog DIV
	$('#savedConfirmation').dialog({ resizable:false, modal:true, autoOpen:false, title:'Saved!', dialogClass:'alert', width:400 });
	// bind save listing links to Ajax
	$('a#saveListing').click(function() {
		$.get(this.getAttribute('href'));
		$('#keepLooking').hide();
		$('#savedNotification').show();
		$('#savedConfirmation').dialog('open');
		$('#savedConfirmation a').blur();
		return false;
	});
	
	// contact information dialog DIV
	$('#contactInformation').dialog({ resizable:false, modal:true, autoOpen:false, dialogClass:'rolodex', width:650 });
	// bind contact button links to Ajax
	$('a#contactButton').click(function() {
		$('#contactInformation').dialog('open');
		$('#contactInformation a').blur();
		$('#contactInformation input').blur();
		return false;
	});


	// add tolltips
	$('span.notdisclosed').hover(function(){JT_show('tip_notdisclosed.htm',this,'')},function(){$('#JT').remove()}).addClass('jTip');
	$('ul.locked').hover(function(){JT_show('tip_dealtermslocked.htm',this,'')},function(){$('#JT').remove()}).addClass('jTip');
	$('img.asking').hover(function(){JT_show('tip_asking.htm',this,'Asking Price',true)},function(){$('#JT').remove()}).addClass('jTip');
	$('img.sales').hover(function(){JT_show('tip_sales.htm',this,'Sales Range',true)},function(){$('#JT').remove()}).addClass('jTip');

});
