$(document).ready(function() {
	//wycena
	$('#ask2, #ask3, #ask4').hide();
	$('.next').click(function(){
		if ($('input:eq(0)').val() == '' || ($('#age').val() == 0 && ($('#ask2').css('display') == 'block')) || ($('#competition').val() == 0 && $('#ask3').css('display') == 'block')) $(this).after('<span class="error">To pole musi zostać wypełnione</span>');
		else {
			$(this).parent().hide();
			$(this).parent().next().fadeIn('slow');
		}
	});
	$('#eval').submit(function(){
		if ($('input:eq(0)').val() == '' || $('select:eq(0)').val() == 0 || $('select:eq(1)').val() == 0) return false;
		else if ($('input:eq(0)').val() != '' && $('select:eq(0)').val() != 0 && $('select:eq(1)').val() != 0) {
			$('#ask3').hide();
			results = $('#results').val().replace(/ /g,'');
			results = results.replace(/,/g,'');
			if (results > 5000000) {
				gg('Wpisałeś słowo kluczowe na które jest '+results+' wyników. Nie pozycjonujemy takich słów kluczowych.');
				window.location = "wycena-pozycjonowania.php";
			}
			else if (results>0) {
				age = $('#age').val();
				competition = $('#competition').val();
				result = Math.round(3*Math.sqrt(10*age*competition*results/1000000))/10;
				result2 = Math.round(10*result * 0.8)/10;
				$('table tr:eq(1) td').eq(0).text("już od " + result +" zł");
				$('table tr:eq(1) td').eq(1).text("już od " + result2 + " zł");
				$('#ask4').show();
				document.forms['eval'].reset()
			} else $('input:eq(1)').after('<span class="error">To pole musi zostać wypełnione</span>');
			return false;
		}
	});
//fastContact
$('#fastContact').submit(function(){
$('*').removeClass('inputErr');
z = 0;
var emailReg = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
if ($('#fastContact input:eq(0)').val() == '' || !emailReg.test($('#fastContact input:eq(0)').val())) {
	$('#fastContact input:eq(0)').addClass('inputErr');
  gg('Nieprawidłowy adres e-mail');
return false;
}
 $.ajax({
   type: "POST",
   url: "sendemail.php",
   data: $(this).serialize(),
   success: function(msg){
	 if (msg == true) {
		$('#fastContact input:eq(0), #fastContact textarea').val('');
		gg('Wiadomość została wysłana. Odpowiemy w przeciągu 12h.');
	}
   }
 });
return false;
	});
	$('.link').each(function(){
var anchor = $(this).text();
var href = $(this).attr('rel');
$(this).replaceWith('<a href="'+href+'">'+anchor+'</a>');
});

});
function gg(napis){
$('body').prepend('<div id="cover" style="position:absolute;top:0;left:0;height:'+screen.height+'px;width:'+screen.width+'px;background-color:#000;filter:alpha(opacity=75);opacity:0.75;z-index:10"></div>');
$('body').prepend('<div id="getka" style="position:absolute;top:50%;left:50%;background-color:#fff;z-index:11;border:5px solid #7DC523;padding:50px"><strong id="close" style="position:absolute;right:5px;top:3px;cursor:pointer">X</strong>'+napis+'</div>');
$('#getka').css({'margin-top':-($('#getka').height()/2+40),'margin-left':-($('#getka').width()/2+40),'width':$('#getka').width()});
$('#getka #close').click(function(){
$('#getka,#cover').remove();
});
}

