function goToProduct(product,pId)
{
	var prodId = product.options[product.selectedIndex].value;
	document.location = "/?pId="+pId+"&id="+prodId
} 

function disableFormFieldsIBW( kategoria, adres )
{
	var kat   = kategoria.options[kategoria.selectedIndex].value;
	document.location = '/?pId='+adres+'&fId='+kat+'&form=1';

}

function toplayer ()
{
	
	  var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myWidth = window.innerWidth;
	    myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	  }
	  
	  var popupLeft = ((myWidth/2)-150); 
	  
	  
	  
	document.getElementById("toplayer_main").style.left=popupLeft+"px";
	document.getElementById("toplayer_main").style.display="block";
}


function findValue(li) {
	if( li == null ) return alert("No match!");
 
	// if coming from an AJAX call, let's use the CityId as the value
	if( !!li.extra ) var sValue = li.extra[0];
 
	// otherwise, let's just display the value in the text box
	else var sValue = li.selectValue;
 
	//alert("The value you selected was: " + sValue);
}
 
function selectItem(li) {
	findValue(li);
}
 
function formatItem(row) {
	return row[0];
}
 
function lookupAjax(){
	var oSuggest = $("#i_city")[0].autocompleter;
 
	oSuggest.findValue();
 
	return false;
}
 
function lookupLocal(){
	var oSuggest = $("#i_city")[0].autocompleter;
 
	oSuggest.findValue();
 
	return false;
}
	


	$(document).ready(
	
	function()
	{

		$("#i_city").autocomplete(
			"/cities.php",
			{
				delay:10,
				minChars:1, 
				matchSubset:1,
				onItemSelect:selectItem,
				onFindValue:findValue,
				formatItem:formatItem,
				maxItemsToShow:10,
				autoFill:true
			}
		); 
		
		$("#show_phone").click(
			function ()
			{
				$("#phone").remove();
				
				if (typeof($("#zip_1").attr("value"))=="undefined")
				{
					alert("Podaj prawidłowy kod pocztowy");
				}
				else
				{
					$.ajax({
					  type: "POST",
					  url: "/inc/php/zipcodes.php",
					  cache: false,
					  data: "zipcode=" + $("#zip_1").attr('value') + '-' + $("#zip_2").attr('value'),
					  success: function(html){
					    var phone = $('<b id="phone">'+html+'</b>').appendTo('#phone_search').end();
					  }
					});
				}

			}
		);
		
		$("#recommendForm input[type=submit]").click(
			function()
			{
				if(typeof($("#recommendForm input[name=name]").attr("value"))=='undefined')
				{
					alert("Uzupełnij polę Imię");
					return false;
				}
				
				if(typeof($("#recommendForm input[name=email]").attr("value"))=='undefined')
				{
					alert("Uzupełnij polę Email");
					return false;
				}
				
				if(typeof($("#recommendForm input[name=friend_email]").attr("value"))=='undefined')
				{
					alert("Uzupełnij polę Adres email znajomego");
					return false;
				}
			}
		);
						
		$("#recommendContainer form input").css("border","1px solid silver").css("width","220px");
		
		$(".showLink").click(
		function()
		{
			$("#recommendContainer").toggle("slow");
		});
		
	});
