function findValue(li) {
	if( li == null ) return false;

	// if coming from an AJAX call, let's use the CityId as the value
	if( !!li.extra ) var sValue = li.extra[0];

	$("#ffSearch").val(sValue);
	$("#fastFind").submit();
}

function selectItem(li) {
	findValue(li);
}

function formatItem(row) {
	return row[0];
}

$(document).ready(function(){
	// this adds corners through jquery, basically you are drawing a div with a background color and rounding the edges.  then to simulate a border, we're drawing ANOTHER div inside our original div with a different color to make it seem like a border.  the amount of padding controls the thickness of the border.  *** note that you start with the INNER div and work out to the main div, which is a little counter intuitive.
	$(".jq-rounded-inner,.jq-rounded-inneryellow").corner("round 3px").parent().css('padding', '1px').corner("round 5px");
	// $("THE NAME OF THE HTML ELEMENT TO ADD A CURVE TO").corner("TYPE AND RADIUS OF THE BORDER").parent().css('padding', 'CONTROLS HOW THICK THE BORDER IS').corner("TYPE AND RADIUS OF THE PARENT ELEMENT");
	// this adds borders with fixed bgcolor in corner cap, but problems in IE6 - probably don't need this
	$('<div class="tr"></div><div class="tl"></div><div class="br"></div><div class="bl"></div>').appendTo(".rounded");
	
	$("#SearchInfoDialog").dialog({
		autoOpen: false,
		draggable: false,
		resizable: false,
		width: 325,
		height: 150
	});
	$("#SearchInfoDialog").css("display", "block");
	$("#SearchInfoOk").click(function(e) {
		e.preventDefault();
		$("#SearchInfoDialog").dialog("close");
	});
	
	AddTitleBackgrounds();
	
	//Add login dialog
	$("#jqLoginDialog").dialog({
		autoOpen: false,
		draggable: false,
		resizable: false
	});
	$("#jqLoginDialog").css("display", "block");
	
	$("#ffSearch").autocomplete(
		"/cfc/remote/QuickSearch.cfm",
		{
			autoFill:false,
			delay:200,
			cacheLength:10,
			formatItem:formatItem,
			matchSubset:1,
			matchContains:1,
			maxItemsToShow:10,
			minChars:3,
			onItemSelect:selectItem,
			onFindValue:findValue
		}
	);
	
});

var popSearchMessage = function(msg) {
	$("#SearchInfoMessage").html(msg);
	$("#SearchInfoDialog").dialog("open");
};


function AddTitleBackgrounds() {
	var inputArr = new Array();
	inputArr = document.getElementsByTagName("input");
	for (i=0; i<inputArr.length; i++) {
		if (inputArr[i].type == "text" && inputArr[i].title != "") {
			if (inputArr[i].value == "" || inputArr[i].value == inputArr[i].title) {
				inputArr[i].style.color = "#808080";
				inputArr[i].value = inputArr[i].title;
			}
			inputArr[i].onfocus = function() {
				if (this.value == this.title) {
					this.value = "";
					this.style.color = "#000000";
				}
			}
			inputArr[i].onblur = function() {
				if (this.value == "") {
					this.style.color = "#808080";
					this.value = this.title;
				}
			}
		}
	}
}

function clearTitles() {
	var inputArr = new Array();
	inputArr = document.getElementsByTagName("input");
	for (i=0; i<inputArr.length; i++) {
		if (inputArr[i].value == inputArr[i].title) {
			inputArr[i].value = "";
		}
	}
	return true;
}

function popWindow(theLink, w, h) {

	var w = (w == null) ? "700" : w;
	var h = (h == null) ? "800" : h;

	var initialX =	100;
	var initialY = 100;
	
	if (navigator.appName == "Netscape")
	{
		theWindow = window.open(theLink,'Lookup', 'width=' + w + ',height=' + h + ',' + ',scrollbars,resizable=yes');
	}
	else
	{
		theWindow = open(theLink, 'Lookup', 'width=' + w + ',height=' + h + ',left=' + initialX + ',top=' + initialY + ',scrollbars,resizable=yes');
	}
	theWindow.focus();
}