// JavaScript Document
var t = "";
$(document).ready(function()
{
	//$("#text_input").dxCombobox();
	
	$("#company").keyup(function(){
		idNum = getId();
		var letters = $(this).val();
		var letLeg = letters.length;
		//alert(letters);
		if(letLeg >= 3){
			$.ajax({
			   type: "POST",
			   url: "http://www.mcallcommunity.com/contests/custom/readers_choice/ajax/ajax_get_name.php",
			   data: "text_input=" + letters + "&idNumber= " + idNum,
			   success: function(html){
				   var entries = $("li").length;
				   if(entries > 50){
				   $("#combo").css({ height: "200px"});
				   } else if(entries != 0){
					$("#combo").css({ height: "100px"});   
				   } else {
					$("#combo").slideUp('fast');   
				   }
				   
					 if(entries > 0){
					 $("#combo").slideDown('fast');  
					 }
				 
				 $("#combo").html(html);	
				 
				 $("#input_box a").click(function()
					{
						var id = $(this).attr("id");
						var ballot_id = $(this).attr("alt");
						$("#company").val(id);
						$("#ballot_id").val(ballot_id);
						$("#combo").slideUp('fast');
						return false;
					});
			   }
			 });
		} else {
			$("#combo").slideUp('fast');  
		}
		
		
	});			   
		
	$("#combo").mouseover(function()
	{
		clearInterval(t);
		
	});
	$("#combo").mouseout(function()
	{
		t = setInterval(slider, 2000); 						  
								  
	});
						   
	function slider(){
		clearInterval(t);
		$("#combo").slideUp('fast'); 
	}
						   
						   
						   
});

function getId() {
var url = window.location.href;
var urlparts = url.split('/');
var length = (urlparts.length - 1);
return urlparts[length];
}
