function findValue(li) {
if( li == null ) return alert("No match!");

	// if coming from an AJAX call, let's use the CityId as the value
	if( !!li.extra ) var sValue = li.extra[0];

	// otherwise, let's just display the value in the text box
	else var sValue = li.selectValue;

	window.location = sValue;
}

function selectItem(li) {
	findValue(li);
}

function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

   function chosencurrency() {
	$currency = $("#chosencurrency").val();
	$.ajax({
					type: "POST",
					url: "/ajax/ajax_updatecurrency.php",
					data: "currency=" + $currency,
					success: function(msg){
						//$("#notificationpad").html(msg);
						alert("Currency updated, page will refresh");
						location.reload(true);
					}
				});
	
   }

$(document).ready(function() {
	$('a[rel*=facebox]').facebox();
	
	if ($('img[id="smallcalc"]').length) {
		$('img[id="smallcalc"]').click(function() {
			$.facebox({ ajax: '/modules/mod_choosecurrency.php' });
		});
	}
	
	if ($('#notifybutton').length) {
	// If there's such an element - bind
		$('#notifybutton').click(function() {
			$('#notifytable').toggle();
		});
		$('#notifycounter').click(function() {
			$('#notifytable').toggle(1,function() {
				// Show the loading icon
				$("#notificationpad").html("<div style='width:100%;height:70px;text-align:center;padding-top:35px;'><img src=/images/loading.gif align=center></div>");
				$.ajax({
					type: "POST",
					url: "/ajax/ajax_notifications.php",
					data: "name=John&location=Boston",
					success: function(msg){
						$("#notificationpad").html(msg);
					}
				});
			});			
		});
	}
	

	$("#destinationSearch").autocomplete("/modules/realtimeSearch.php", {			
				matchContains: true,
				width: 350,
				onFindValue:findValue,
				onItemSelect:selectItem,
				minChars:3
			});
			
			
	$("#friendSearch").autocomplete("/ajax/ajax_friendsearch.php", {			
				matchContains: true,
				width: 350,
				resultsClass: "friendsearch",
				onFindValue:findValue,
				onItemSelect:selectItem,
				minChars:3
			});
			
	
});