$(document).ready(function(){
	$("a[class='DelFavorite']").click(function(){
		var rel = $(this).attr("rel");
		var dash = rel.indexOf("-");
		var id = rel.substring(0,dash)
		var table = rel.substring(dash+1)
		$.get("/Save-Listing.asp",{DID:id,DT:table},function(){
			$("div[rel="+rel+"]").fadeOut("slow");
		});
		return false;
	});
	$("a[class='DelSearch']").click(function(){
		var id = $(this).attr("href").replace("Save-Search.asp?DID=","");
		$.get("/Save-Search.asp",{DID:id},function(){
			$("#Search"+id).fadeOut("slow");
		});
		return false;
	});
	$("#AddCity").click(function(){
		$("#ChosenCityList").append($("<a>").attr("href","#").text($("#dhCity").val()));
		$("#CityList").val($("#CityList").val() + $("#dhCity").val() + ",");
		return false;
	});
	$("#dhCity").keydown (function(e){
		if (typeof e === "undefined") {e = window.event;}
		if (e.keyCode === 13) {
			$("#ChosenCityList").append($("<a>").attr("href","#").text($("#dhCity").val()));
			$("#CityList").val($("#CityList").val() + $("#dhCity").val() + ",");
		}
	});
	$("#AddCounty").click(function(){
		$("#CountyList").val($("#CountyList").val() + $("#dhCounty").val() + ",");
		$("#ChosenCountyList").append($("<a>").attr("href","#").text($("#dhCounty").val()));
		return false;
	});
	$("#dhCounty").keydown (function(e){
		if (typeof e === "undefined") {e = window.event;}
		if (e.keyCode === 13) {
			$("#CountyList").val($("#CountyList").val() + $("#dhCounty").val() + ",");
			$("#ChosenCountyList").append($("<a>").attr("href","#").text($("#dhCounty").val()));
		}
	});
	$("#ChosenCityList a").live("click",function(){
		$("#CityList").val($("#CityList").val().replace($(this).text()+",",""))
		$(this).remove();
		return false;
	});
	$("#ChosenCountyList a").live("click",function(){
		$("#CountyList").val($("#CountyList").val().replace($(this).text()+",",""))
		$(this).remove();
		return false;
	});
});
