function loadPage(offset, inputString, limit) 
{
	if(offset != "" && inputString == "false" && (limit == "false" || limit == ""))
	{
		
		url = 'http://www.starpak.pl/starpak/oferta';
		div = "#prod_display";
		searcher = '<img src="http://www.starpak.pl/images/ajax-loader.gif" alt="loader" class="loader" />';
		input = offset;	
 	}
 	else if(offset == '' && inputString != 'false' && limit == "false")
 	{
 	
		url = 'http://www.starpak.pl/starpak/ajax';
		div = "#autoSuggestionsList";
		searcher = '<img src="http://www.starpak.pl/images/ajax-loader-min.gif" alt="loader"/>';
	
		input = inputString;

	}
	else if(limit == 'link' && inputString == 'false' && offset != '' )
	{
		
		url = 'http://www.starpak.pl/starpak/oferta';
		div = "#link_twr";
		searcher = '<img src="http://www.starpak.pl/images/ajax-loader-min.gif" alt="loader" style="padding-left:130px;padding-top:15px" />';
		input = offset;	
	}
 	
 		if(inputString.length == 0) 
		{
	        // Hide the suggestion box.
	        $("#suggestions").hide();
	    } 
 	
 	if($("#inputString").val().indexOf(' ')!=-1  && inputString.length != '0' || offset != '')
 	{
 	
 		  jQuery(div).html(searcher);
		 	jQuery.ajax({
			   	type: "POST",
			   	url: url,
			   	data: {offset : input, limit : limit},
				success: function(data, textStatus)
			   	{
				/*jQuery(div).ajaxSend(
					function(evt, request, settings)
					{
					
						
			   			
			   			//jQuery("#follower").html('starpak > oferta');
					});*/
					
				if(inputString != "false")	
				{	
					if(data.length >0)
					{
						$("#suggestions").show();
		   			    $("#autoSuggestionsList").html(data);
						
					}
					
				}
				else
				{
					 jQuery(div).html(data);
					 tb_init('a.thickbox, area.thickbox, input.thickbox');
					 //jQuery("#follower").html();
				}
			   
					}
			 		});
		}
 	
 	
 
}

function brandStatus(klik,klik_szare,klik_kolor)
{
  var src="http://www.euro-trade.nazwa.pl/uploads/starpak/images/";
  $.ajax({url: "http://www.starpak.pl/starpak/findCheckedBrand",
          type: "POST",
          dataType: "json",
          success: function(data)
          {
            if(data.id!=0)
            {
              if(klik==data.id) //klikniety ten ktory byl zaznaczony - tylko odznaczyc
              {
                $("#brand"+klik+"_img").attr("src",src+klik_szare);
              }
              else //klikniety inny niz juz zaznaczony - odznaczyc i zaznaczyc nowy
              {
                $("#brand"+data.id+"_img").attr("src",src+data.szary);
                $("#brand"+klik+"_img").attr("src",src+klik_kolor);
              }
            }
            else //nie bylo zaznaczonego
            {
              $("#brand"+klik+"_img").attr("src",src+klik_kolor);
            }
          }
        })
  
  
  
  jQuery.post("http://www.starpak.pl/starpak/brandStatus/"+klik,
             {notreload: true},
             function(data){if(data!='p') loadPage(data,'false','');});
}
/*
function brandStatus(name)
{


  var newSrc="";
  var jest=false; //czy istnieje zaznaczony
  if($("#logotypy > a > img").is("[src$='_color.jpg']:first")) jest=true;
  //alert(zaznaczony.attr("src"));

  if(jest)
  {
    if($("#"+name+"_img").is("[src$='_color.jpg']")) //klikniety ten ktory byl zaznaczony - tylko odznaczyc
    {
      newSrc = $("#"+name+"_img").attr("src").replace("_color.jpg",".jpg");
      $("#"+name+"_img").attr("src",newSrc);
    }
    else //klikniety inny niz juz zaznaczony - odznaczyc i zaznaczyc nowy
    {
      var zaznaczony=$("#logotypy > a > img[src$='_color.jpg']:first");
      newSrc = zaznaczony.attr("src").replace("_color.jpg",".jpg");
      zaznaczony.attr("src",newSrc);
      
      newSrc = $("#"+name+"_img").attr("src").replace(".jpg","_color.jpg");
      $("#"+name+"_img").attr("src",newSrc);
    }
  }
  else //nie bylo zaznaczonego
  {
    newSrc = $("#"+name+"_img").attr("src").replace(".jpg","_color.jpg");
    $("#"+name+"_img").attr("src",newSrc);
  }
  
  jQuery.post("http://www.starpak.pl/starpak/brandStatus/"+name,
             {notreload: true},
             function(data){if(data!='p') loadPage(data,'false','');});
}
*/

function lookup(inputString) 
{
	
    
   
}

       		
       		
       		
function fill(thisValue) {
	
	var string = thisValue.toString();
    $("#inputString").val(string);
   $("#suggestions").hide();
   
}





function makeSublist(parent,child,isSubselectOptional,childVal)
{
	$("body").append("<select style='display:none' id='"+parent+child+"'></select>");
	$('#'+parent+child).html($("#"+child+" option"));
	
		var parentValue = $('#'+parent).attr('value');
		$('#'+child).html($("#"+parent+child+" .sub_"+parentValue).clone());
	
	childVal = (typeof childVal == "undefined")? "" : childVal ;
	//$("#"+child+' option[@value="'+ childVal +'"]').attr('selected','selected');
	$('#'+child).val(["'+ childVal +'"]).attr('selected','selected');
	$('#'+parent).change( 
		function()
		{
			var parentValue = $('#'+parent).attr('value');
			$('#'+child).html($("#"+parent+child+" .sub_"+parentValue).clone());
			if(isSubselectOptional) $('#'+child).prepend("<option value='0'> Wszystkie </option>");
			$('#'+child).trigger("change");
                        $('#'+child).focus();
		}
	);
}





		function check(id,szare,kolor)
		{
			var path="http://www.euro-trade.nazwa.pl/uploads/starpak/images/"
			if (document.getElementById(id).checked)
			{
				document.getElementById(id+"_img").src=path+kolor;
			}
			else
			{
				document.getElementById(id+"_img").src=path+szare;
			}
		}
		
	
	

		function change()
		{
			var val=-1;
			if(document.getElementById('parent'))
			{
				val = document.getElementById('parent').value;	
			}
			
			
			
			if(val == "157" || val == "158")
			{
				document.getElementById('child').style.display= 'none';
				document.getElementById('grandson').style.display= 'none';
			}
			
			else if(val!=-1)
			{
				document.getElementById('child').style.display= 'inline';
				document.getElementById('grandson').style.display= 'inline';
				
			}
			
			
			if(val == "107")
			{
				document.getElementById('piktogramy').style.display= 'none';
			}
			else if(val!=-1)
			{
				document.getElementById('piktogramy').style.display= 'block';
			}
			
			
		}



function showValid()
{
	
	document.getElementById('valid').style.display = 'inline';
	
}

function hideValid()
{
	document.getElementById('valid').style.display = 'none';
}

function clearInput()
{
	if(document.getElementById("inputString").value != "")
	{
		document.getElementById("inputString").setAttribute( "autocomplete","off" )
	}
	
}
  $(document).ready(function(){
    
    $("#szukaj_focus").hover(function () {
		var szukaj_focus=$('<div id="sufler" class="sufler-1" style="color:#777777;line-height:12px;margin:10px 15px;padding-top:10px"><b>Wyszukiwanie towarów</b><br />Wpisz poszukiwany przedmiot, następnie kliknij niebieski przycisk.</div>');
         $(this).parent().parent().parent().append(szukaj_focus);
    },function(){
		$('#sufler').remove();
	});
	 $("#newsletter_focus").hover(function () {
		var newsletter_focus=$('<div id="sufler" class="sufler-2" style="color:#777777;line-height:12px;padding:10px 15px"><b>Newsletter</b><br />Wpisz w pole powyżej swój adres e-mail jeśli chcesz otrzymywać newsletter Starpaka, następnie kliknij niebieski przycisk. </div>');
         $(this).parent().parent().parent().append(newsletter_focus);
    },function(){
		$('#sufler').remove();
	});
	 $("#recommend_focus").hover(function () {
		var recommend_focus=$('<div id="sufler" class="sufler-3" style="color:#777777;line-height:12px;padding:10px 15px"><b>Poleć Starpaka</b><br />Wpisz w pole powyżej adres e-mail osoby której chcesz polecić oferte Starpaka, następnie kliknij niebieski przycisk. </div>');
         $(this).parent().parent().parent().append(recommend_focus);
    },function(){
		$('#sufler').remove();
	});
  });
$(function(){
		$('.lb_photo').lightBox();
	})

