var job;

$("#searchterm").live('keyup',function(){	
									   
		var term = $(this).val();	
		
		term = term.trim();		
		// 	if too short  
		if( term.length < 3 ){
			if(typeof(job)!="undefined"){
				job.abort();
			}		
		
		// hide suggestions	
		//	if($("#suggestionsContainer").is(":visible") == true){
				$("#suggestionsContainer").hide();	
				$("#suggestions").removeShadow();
				$("#suggestions").hide();
				$("#suggestions").empty();						
		//	}
			
		}
		// do search
		if(term.length > 2 ){
			
			$("#suggestionsContainer").css("left",parseInt((screen.width-990)/2) + 40 + "px");			
		//	$("#suggestionsContainer").show();	
			//if entered another letter abort previous
			if(typeof(job)!="undefined"){
				job.abort();
			}
			
		//	if(term.indexOf("@") > -1)
		//	{
		//		$("#suggestionsContainer").show();
		//		$("#suggestionsContainer").html("<div style='background-color:white;padding:10px'>This is the search! Why are you entering an email address?</div>");	
					
		//		return false;
		//	}
						
			// fetch results		
			var str = $("#searchform").serialize();
				job = jQuery.ajax({
                type: "POST",
                url: "/_ajaxSearch.asp",
                dataType:"html",
                data:str,
                success:function(response){					
					if(response.indexOf("searchRes") > -1){	
					
						$("#suggestionsContainer").html(response);	
						if($("#suggestionsContainer").is(":visible") == false){
							$("#suggestionsContainer").show();					
						}	
						$("#suggestions").show();
					}	
					else
					{	
						$("#suggestionsContainer").empty();	
						$("#suggestionsContainer").hide();	
						$("#suggestions").hide();	
					}
			  	}
			 
            });			
		} 
});
// search authors
var job2;
$("#searchterm2").live('keyup',function() {	
								 
		var term = document.getElementById("searchterm2").value;		
		term = term.trim();	
		
		if(term.length < 4 ){
			if(typeof(job2)!="undefined"){
				job2.abort();
			}	
			// toggle btw loader and submit btn		
			$("#searchloader2").hide();
			$("#gobutton2").show();	
			$("#searching2").hide();	
			// hide suggestions			
			$("#suggestionsContainer2").hide();	
			$("#suggestions2").removeShadow();
			$("#mp").empty();	
			$(".results").empty()
		
		}
		
		if(term.length > 3){
			
			$("#suggestionsContainer2").css("left",parseInt((screen.width-990)/2) + 283 + "px");
			$("#suggestionsContainer2").show();			
			//if entered another letter abort previous
			if(typeof(job2)!="undefined"){
				job2.abort();
			}
			// toggle btw loader and submit btn	
			$("#searchloader2").show();
			$("#gobutton2").hide();									
			$("#searching2").show();
			
			$("#mp").empty();	
			
			// fetch results			
			var str = $("#searchform2").serialize();
				job2 = jQuery.ajax({
                type: "POST",
                url: "/_ajaxSearchAuthor.asp",
                dataType:"html",
                data:str,
                success:function(response){					
					if(response.indexOf("</tr>") > -1){							
						$("#suggestionsContainer2").html(response);	
						if($("#suggestionsContainer2").is(":visible") == false){
						$("#suggestionsContainer2").show();						
						}						
					}	
					else
					{
						$("#searchloader2").hide();
						$("#gobutton2").show();	
						$("#searching2").hide();						
					}
			  	}			  
			 
            });			
		} 
});

function changeSearchTerm(newval){
	document.getElementById("searchterm").value = newval;
	$("#searchform").submit();
}

