function gtsp(id){get=document.getElementById(id); return get==null?false:get}
function el(id,dis){
    if(gtsp(id)) gtsp(id).style.display=dis
}


$(document).ready(function(){

	$("#search_help_input_s").keyup(function()	{
		search_help_delay_s(this);
	});	
	parent.top.search_help_active=0;
	$("#search_help_input_s").blur(function()	{
		var value = jQuery.trim(this.value);
		clearTimeout(parent.top.search_help_time);
		if(value.length)	{
			//alert(parent.top.search_help_active);	
			if(!parent.top.search_help_active)	{
				$("#search_help_content_s").html("");
				$("#search_help_content_s").hide();	
			}
		}	else	{
			this.value='Szukany tekst...';
		}
	});
});
function search_help_delay_s(obj)	{
	var value = jQuery.trim(obj.value);
	clearTimeout(parent.top.search_help_time);
	if(value.length >2)	{
		parent.top.search_help_time = setTimeout("search_help_s('"+obj.value+"')",100);
	}	else	{
		$("#search_help_content_s").html("");
		$("#search_help_content_s").hide();
	}
}

var search_help_buffer = new Array();
function search_help_s(obj)	{
for(i=0;i<search_help_buffer.length;i++)	{
	if(search_help_buffer[i]==obj)	{
		if(search_help_buffer[i+1])	{
			$("#search_help_content_s").html(search_help_buffer[i+1]);
			$('#search_help_content_s').show();
		}	else	{
			$("#search_help_content_s").html("");
			$("#search_help_content_s").hide();
		}
		return false;
	}
}

$.ajax({
  type: "GET",
  url: 'search_help_s.php',
  data: 'search=' + obj,
  dataType: "xml",
  success: function(xml){
         // alert(xml);
          //return;
          var toPrint = '';
		  var ct=0;
		  $(xml).find('res').each(function(){
			if(!ct)	{
				$('#search_help_content_s').html("");
				$('<div class="item_search"></div>').html('<span>PODPOWIEDZI:</span>').appendTo('#search_help_content_s');
			}
			var ad_title = $(this).find('res_title').text();
			var ad_link = $(this).find('res_link').text();
			//alert(ad_title);
			$('<div class="item_search"></div>').html('<a style="color:#03318B;" href="'+ad_link+'">'+ad_title+'</a>').appendTo('#search_help_content_s');
		  
		  	ct++;
		  });
		  var ct2=0;
		  $(xml).find('res2').each(function(){
				if(!ct && !ct2)	{
					$('#search_help_content_s').html("");
					$('<div class="item_search"></div>').html('<span>PROJEKTY:</span>').appendTo('#search_help_content_s');
				}	else if(ct && !ct2)	{
					$('<div class="item_search"></div>').html('<span>PROJEKTY:</span>').appendTo('#search_help_content_s');					
				}
				var ad_title = $(this).find('res2_title').text();
				var ad_link = $(this).find('res2_link').text();
				var ad_foto = $(this).find('res2_foto').text();
				//alert(ad_title);
				$('<div class="item_search" style="clear:both;"></div>').html('<a href="'+ad_link+'"><img style="float:left;margin:3px 3px 0 0;" src="'+ad_foto+'" alt="'+ad_title+'" width="50" height="33"/></a><a style="color:#03318B;" href="'+ad_link+'">'+ad_title+'</a>').appendTo('#search_help_content_s');
			  
			  	ct2++;
			  });
		  if(ct || ct2)	{
		  	search_help_buffer.push(obj);
		  	search_help_buffer.push($('#search_help_content_s').html());
		  	$('#search_help_content_s a').mouseover(function()	{
		  		parent.top.search_help_active=1;
		  	});
		  	$('#search_help_content_s a').mouseout(function()	{
		  		parent.top.search_help_active=0;
		  	});		  	
		  	$('#search_help_content_s').show();
		  	
		  }	else	{
		  	search_help_buffer.push(obj);
		  	search_help_buffer.push("");
		  	$('#search_help_content_s').hide();		  
		  }
  },
  error: function(){
	search_help_buffer.push(obj);
	search_help_buffer.push("");
  	$('#search_help_content_s').html("");
  	$('#search_help_content_s').hide();
  }
});
}