


function validate_formmail(f)
 {				
	required = 0;
	wymagane = $(".required_field");
	$.each(wymagane, function () {
		title = $(this).attr('title');
		wartosc = $(this).val();
		if(wartosc.length < 3)
		 {
			alert('Wypelnij pole obowiązkowe: '+title);
			required++;
		 }				
	 });	 
	
	if(required > 0)
	 {
		return false;
	 }
 }

function MailIsValid(Email) 
{ 
	var Pattern = /^[a-z0-9-_]+(\.[a-z0-9-_]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/; 
	return (Pattern.test(Email)) ? true : false; 
} 

function testuj_email(f) {			
  if (!MailIsValid(f.newsletter_add.value)) { alert("Niepoprawny adres e-mail"); return false; }			 
}

function usun (link)
{
	komunikat = "Czy napewno chcesz to zrobić?"
	if (confirm(komunikat))	document.location.href = link;
}

function ask (link, komunikat)
{
	
	if (confirm(komunikat))	document.location.href = link;
}

function goToUrl(s) {
	var gourl = s.options[s.selectedIndex].value;	window.top.location.href = gourl;
}

$(".gThumb").click(function() {
	fileReplace = $(this).attr('rel');
	$("#gThumbBig").attr('src', 'public/foto/products/big_'+fileReplace);
	$("#gThumbLink").attr('href', 'public/foto/products/org_'+fileReplace);					
});


$(".cartVariant").click(function() {
	priceVal = $(this).attr('price');
	$("#priceProduct").html(priceVal);
});

$("#ajaxLoginForm").submit(function() {
				
	loginValue = $("#ajaxLoginUser").val();
	passValue = $("#ajaxLoginPass").val();
	
	$.get("Login.html", { ajaxData: "login", login: loginValue, pass: passValue },
	  function(data){			

		if(data == 'USER_LOGGED')
		 {
			alert("Witamy w serwisie!");
			
			$.get("Login.html", { ajaxData: "user", userAccount: 'box' },
			function(userData){
				$("#ajaxLoginForm").remove();
				$("#userAccount").html(userData);
			});
			
			
		 }
		else
		 {
			alert("Błąd logowania! Użytkownik nieistnieje lub konto nie zostało aktywowane");
			$("#userAccount").empty();
		 }
		
		
	  });
	
	return false;		
 });



function PoliczRate(koszyk, nrSklepu) {
	window.open('https://www.eraty.pl/symulator/oblicz.php?numerSklepu='+nrSklepu+'&wariantSklepu=1&typProduktu=0&wartoscTowarow='+koszyk, 'Policz_rate', 'width=630,height=500,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
}


function tooltip()
 {
	
	xOffset = 10;
	yOffset = 20;
	
	$(".pokazOpis").hover(function(e){	
										  
		t = $(this).attr('title');
		baseTitle = t;
		$(this).removeAttr('title');
			  
		$("body").append("<p id='tooltipA'>"+ t +"</p>");
		
		$("#tooltipA")
		.css("top",(e.pageY - xOffset) + "px")
		.css("left",(e.pageX + yOffset) + "px")
		.fadeIn("fast");
		
		
	},
	function(){
		title = baseTitle;
		$(this).attr('title', title);
		$("#tooltipA").remove();				
				
	});	
	
	$(".pokazOpis").mousemove(function(e){
		$("#tooltipA")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
		
	});
	
 }

tooltip();


function moveDivUp(id){
var st = document.getElementById(id).scrollTop;
var przesun = st+348;
document.getElementById(id).scrollTop=przesun;
}

function moveDivDown(id){
var st = document.getElementById(id).scrollTop;
var przesun = st-348;
document.getElementById(id).scrollTop=przesun;
} 

$(function() {	
	/*$('a.lightbox').lightBox({fixedNavigation:true});
	$('#nav').droppy({speed: 1});
	*/
	$(".loadProjectPhoto").mouseover(function() {
		rel = $(this).attr('rel');
		
		$("#projektfoto").attr('src', 'public/foto/'+rel);
	  });
	
	$(".loadProjectPhotoClick").click(function() {
		rel = $(this).attr('rel');
		$(".loadProjectPhotoClick").css('color', '#454445');
		$("#projektfoto").attr('src', 'public/foto/'+rel);
		$(this).css('color', 'white');
	  });
	
	
  $(".up").bind("mousedown", function(){
    var topVal = $(".contentScroll").css("top");
	topVal = parseInt(topVal.replace("px", ""));
	topVal = topVal-100;
    $(".contentScroll").css("top", topVal);
	//$("#topVal").html(topVal);	
	
  });

  $(".dn").bind("mousedown", function(){
  
    var topVal = $(".contentScroll").css("top");
	topVal = parseInt(topVal.replace("px", ""));
		if(topVal < 0)
		 {
		topVal = topVal+100;
		$(".contentScroll").css("top", topVal);
	 	}
		//$("#topVal").html(topVal);
  });
  
  $('.hovers').hover(			
		function () {					
			var sciezka = $(this).attr("src");
			var hover = sciezka.replace('public/gfx/nh/', "public/gfx/h/");
			$(this).attr("src", hover);					
		  },
		  function () {
			var sciezka = $(this).attr("src");
			var hover = sciezka.replace('public/gfx/h/', "public/gfx/nh/");
			$(this).attr("src", hover);	
		  }
		  
	);
 
 bodyHeight = $(window).height();
 topMargin = bodyHeight-500;
 topMargin = topMargin/2;
 $('body').css('padding-top', topMargin);
 
 
var contentDiv = $("#contentDiv").height();
var menuDiv = $("#menu").height();
if(menuDiv < contentDiv)
 {
	$("#scrollButtons").css('display', 'inline'); 
 }

 
 
 
 
 
 
	
});
