	function extractResults( term, pg, ck1 )
		{
			if (term=="")
		  	{
				document.getElementById("txtHint").innerHTML="";
		  		return;
		  	}
			if (window.XMLHttpRequest)
		  	{// code for IE7+, Firefox, Chrome, Opera, Safari
		  		xmlhttp=new XMLHttpRequest();
		  	}
			else
		  	{// code for IE6, IE5
		  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  	}
			
			xmlhttp_ini=new XMLHttpRequest();
			xmlhttp_ini.open("GET","http://www.listenspotify.com/search_xml/search_ini.php?q="+escape(term),true);
			xmlhttp_ini.send();
			xmlhttp_ini.onreadystatechange=function()
		  	{
				document.getElementById("searchResult").innerHTML=xmlhttp_ini.responseText;
			}
			
			xmlhttp.onreadystatechange=function()
		  	{
		  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					document.getElementById("searchResult").innerHTML=xmlhttp.responseText;
					var addthis_ui_config =
						{}
					var addthis_share_config = 
						{
							url: "http://www.listenspotify.com/?q="+escape(term)+"&T=s&pg="+pg,
							title: "Music search results for \'"+term+"\'",
						    templates: {twitter: '{{title}}: {{url}} via @ListenSpotify'},							
						}
					addthis.button(document.getElementById('addthis_list'), addthis_ui_config, addthis_share_config);
				}
		  	}
			if (ck1){
				xmlhttp.open("GET","http://www.listenspotify.com/search_xml/search_list.php?q="+escape(term)+"&ck1=true&pg="+pg,true);
				xmlhttp.send();
			}else{
				xmlhttp.open("GET","http://www.listenspotify.com/search_xml/search_playlist.php?q="+escape(term)+"&ck1=false&pg="+pg,true);
				xmlhttp.send();
			}
			document.getElementById('main_result').className = 'main_result';
			if(document.getElementById("check1").checked){
				window.location.hash="q="+term+"&T=s&pg=1";
			}else{
				window.location.hash="q="+term+"&T=p&pg=1";
			}
		}
////////////////////////////////////////////////////////////////////////////////////////////////////////////		
	$(function() {
		function split( val ) {
			return val.split( /,\s*/ );
		}
		function extractLast( term ) {
			return split( term ).pop();
		}
		
		function extractResults( term, pg, ck1 )
		{
			document.getElementById("searchResult").innerHTML="";
			if (term=="")
		  	{
				document.getElementById("searchResult").innerHTML="";
		  		return;
		  	}
			if (window.XMLHttpRequest)
		  	{// code for IE7+, Firefox, Chrome, Opera, Safari
		  		xmlhttp=new XMLHttpRequest();
		  	}
			else
		  	{// code for IE6, IE5
		  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  	}
			
			xmlhttp_ini=new XMLHttpRequest();
			xmlhttp_ini.open("GET","http://www.listenspotify.com/search_xml/search_ini.php?q="+escape(term),true);
			xmlhttp_ini.send();
			xmlhttp_ini.onreadystatechange=function()
		  	{
				document.getElementById("searchResult").innerHTML=xmlhttp_ini.responseText;
			}
			
			xmlhttp.onreadystatechange=function()
		  	{
		  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					document.getElementById("searchResult").innerHTML=xmlhttp.responseText;
					var addthis_ui_config =
						{}
					var addthis_share_config = 
						{
							url: "http://www.listenspotify.com/?q="+escape(term)+"&T=s&pg="+pg,	
							title: "Music search results for \'"+term+"\'",
						    templates: {twitter: '{{title}}: {{url}} via @ListenSpotify'},
						}
					addthis.button(document.getElementById('addthis_list'), addthis_ui_config, addthis_share_config);
				}
		  	}
			if (ck1){
				xmlhttp.open("GET","http://www.listenspotify.com/search_xml/search_list.php?q="+escape(term)+"&ck1="+ck1+"&pg="+pg,true);
				xmlhttp.send();
			}else{
				xmlhttp.open("GET","http://www.listenspotify.com/search_xml/search_playlist.php?q="+escape(term)+"&ck1="+ck1+"&pg="+pg,true);
				xmlhttp.send();
			}
			document.getElementById('main_result').className = 'main_result';
		}

		$( "#birds" ).autocomplete({
			source: function( request, response ) {
				var ck1 = document.getElementById("check1").checked ;
				var term_tmp=request.term;
				$.getJSON( "http://www.listenspotify.com/search_xml/search_auto.php?ck1="+ck1+"&term="+escape(term_tmp), response );
			},
			search: function() {
				// custom minLength
				var term = extractLast( this.value );
				if ( term.length < 2 ) {
					return false;
				}else{
					var term1 = extractResults( this.value, 1, document.getElementById("check1").checked );
					document.getElementById('searchbox').className = 'searchboxfi';
					document.getElementById('searchbox1').className = 'onecontainer_searchfi';
					document.getElementById('searchbox2').className = 'sec_searchfi';
					document.getElementById('searchbox3').className = 'ui-widgetfi';
					document.getElementById('searchbox_title').className = 'onecontainer_search_title_fi';
					document.getElementById('main_result').className = 'ui-autocomplete-loading_result';
					document.getElementById('search_checkbox').className = 'search_checkbox_fi';
					document.getElementById('ui-widget').className = 'ui-widget_fi';
					if(document.getElementById("check1").checked){
						window.location.hash="q="+term+"&T=s&pg=1";
					}else{
						window.location.hash="q="+term+"&T=p&pg=1";
					}
				}
			},
			focus: function() {
				// prevent value inserted on focus
				return false;
			},
			select: function( event, ui ) {
				var terms = split( this.value );
				// remove the current input
				terms.pop();
				// add the selected item
				terms.push( ui.item.value );
				// add placeholder to get the comma-and-space at the end
				terms.push( "" );
				this.value = terms.join( "" );
				return false;
			}
		});
	});
