  $(function(){
  	$("#keyword").autocomplete('modules/autocomplete/autocomplete.php',
                     {
					 	delay: 10,
						mainChars: 0,
						matchSubset: true,
						matchContains: true,
						cacheLength: 0,
						onItemSelect: selectItem,
						onFindValue: findValue,
						formatItem: formatItem,
						autoFill: false
                     }
                    );
	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;
                      //alert("The value you selected was: " + sValue);
	}
	function selectItem(li) {
    	findValue(li);
	}
	//針對列表格式
	function formatItem(row) {
		return "<table width=95%><tr><td align=left><div id=Search_Result><nobr>" + row[0] + "</nobr></div></td><td align=right class=ResultNum>"  + row[1] + "</td></tr></table>";
	}
});

$(function(){
		$("#NoEnterSubmit").dialog({
			bgiframe: true, 
			autoOpen: false, 
			modal: true,
			buttons:{
					'關閉': function(){
								$(this).dialog('close');
							  },
					Cancel: function() {
						$(this).dialog('close');
					}
			}
		});
		$("#NoEnterKeyword").dialog({
			bgiframe: true, 
			autoOpen: false, 
			modal: true,
			buttons: {
					'關閉': function(){
								$(this).dialog('close');
							  }							  
			 }
		});
		$("#alert_windows").dialog({
			bgiframe: true, 
			autoOpen: false, 
			modal: true,
			buttons: {
					'關閉': function(){
								$(this).dialog('close');
								location.href='index.php';
							  }							  
			 }
		});
});
  
function NoEnterSubmit(){
	if(event.keyCode==13){
		if($('#keyword').val()==''){
			event.cancelBubble = true;
			event.returnValue = false;
			//alert('test');
			$(function(){
				$('#NoEnterKeyword').dialog('open');
			});
		}else{
			/*$(function(){
				$('#NoEnterSubmit').dialog('open');
			});			*/
			CheckKeyword(1);
		}
	}
}
