$(function() {
	// output format 
	function format(itm) {
		var whatIsIt;
		switch (itm.iam)
		{
			case "city":
			case "min_city":
			case "min_province_city":
			case "province":
			case "country":
			case "city_resort":
			case "province_resort":
					whatIsIt = ', '+itm.parent;
				break;
			case "attraction":
					whatIsIt = ', '+itm.parent+' [Attraction]';
				break;
			case "excursion":
					whatIsIt = ', '+itm.parent+' [Excursion]';
				break;
			case "city_activity":
			case "resort_activity":
			case "province_activity":
			case "activity":
					whatIsIt = ', '+itm.parent+' [Activity]';
				break;
			case "city_airport":
			case "prov_airport":
			case "airports":
					whatIsIt = ', '+itm.parent+' [Airport]';
				break;
			case "events":
			case "prov_event":
			case "city_event":			
					whatIsIt = ', '+itm.parent+' [Event]';
				break;
			default:
					whatIsIt = ', '+itm.parent+' ['+itm.iam.capitalize()+']';
				break;
		}
		return itm.name + whatIsIt;
	}
	// ajax call and setup
	$("#destination_search").autocomplete('/apps/thirdParty/travel/wt-destination-search.php', {
		extraParams: { clid: 'RYjFcWUVcUxeHZeJbs9agRTQvZ8er8zX' },
		minChars: 3, // num chars before start searching
		autoFill:false,
		matchCase : false,
		mustMatch :false,
		matchContains:false,
		cacheLength : 10,
		scrollHeight: 150, // custom height of drop down
		scroll:true,
		delay:450, // custom delay
		parse: function(data) {
			return $.map(eval(data), function(row) {
				return {
					data: row,
					value: row.url,
					result: row.name
				}
			});
		},
		formatItem: function(item) {
			return format(item);
		}
	}).result(function(e, item) {
		// move page location
		document.location='http://iafrica.wordtravels.com'+item.url;
	});
});

// this capitalizes strings :D wa wa weeeeeee wa!
String.prototype.capitalize = function(){
    return this.replace(/\w+/g, function(a){
        return a.charAt(0).toUpperCase() + a.slice(1).toLowerCase();
    });
};


function disableEnterKey(e)
{
     var key;     
     
     if(window.event)
	key = window.event.keyCode; //IE
     else
	key = e.which; //firefox     
        return (key != 13);

}


