function confirmation() {
	var answer = confirm("Zgadzam się z Polityką Prywatności opublikowaną na łamach serwisu firmy Absolut Invest.")
	if (answer){
		//alert("Bye bye!")
		return true;
	}
	else{
		alert("Adres nie został dodany, ponieważ nie zgodziłeś się z Polityką Prywatności opublikowaną na łamach serwisu firmy Absolut Invest.");
		return false;
	}
}




function unsubscribe(){
	
	var newsletterEmail = document.getElementById('emailAddress');
	
	if (checkNewsletter('unsubscribe') == true)
	{
		document.location.href='skrypt.php?action=unsubscribe&email='+newsletterEmail.value;
	}
	
}


function checkCVForm(){
	
	var imie		= document.getElementById('imie');
	var nazwisko	= document.getElementById('nazwisko');
	var email		= document.getElementById('email');
	var CVfile		= document.getElementById('CVfile');
	var source		= document.getElementById('source');
	var zgoda		= document.getElementById('zgoda');


	if (imie.value == '')
	{
		alert('Pole \"imię\" jest wymagane');
		imie.focus();
		imie.select();
		return false;
	}
	else if (imie.value.length<3)
		{
			alert('Pole \"imię\" musi zawierać co najmniej 3 znaki');
			imie.focus();
			imie.select();
			return false;
		}

	if (nazwisko.value == '')
	{
		alert('Pole \"nazwisko\" jest wymagane');
		nazwisko.focus();
		nazwisko.select();
		return false;
	}
	else if (nazwisko.value.length<3)
		{
			alert('Pole \"nazwisko\" musi zawierać co najmniej 3 znaki');
			nazwisko.focus();
			nazwisko.select();
			return false;
		}

	if (email.value == '')
	{
		alert('Pole \"email\" jest wymagane');
		email.focus();
		email.select();
		return false;
	}
	else if (Wzor_email.test(email.value)!=true)
		{
			alert('Proszę wpisać poprawny adres e-mail');
			email.focus();
			email.select();
			return false;
		}

	if (CVfile.value == '')
	{
		alert('Pole \"plik CV\" jest wymagane');
		CVfile.focus();
		CVfile.select();
		return false;
	}
	else
	{
		var CVfileLength = CVfile.value.length;
		if (CVfile.value.substring(CVfileLength-3)!='doc' && CVfile.value.substring(CVfileLength-3)!='pdf' && CVfile.value.substring(CVfileLength-4)!='docx')
		{
			alert('Proszę załączyć plik w formacie PDF , DOC lub DOCX');
			return false;
		}
	}
	

	

	if (zgoda.checked == false)
	{
		alert('Proszę wyrazić zgodę na przetwarzanie danych osobowych');
		zgoda.focus();
		return false;
	}


	/*
	
	var dataString = 'imie='+ imie.value + '&nazwisko=' + nazwisko.value + '&email=' + email.value + '&CVfile=' + CVfile.value + '&source=' + source.value;
	
	
	$.ajax({
		type: "POST",
		url: "skrypt.php?action=CVFormSend",
		data: dataString,
		success: function(text) {
			
			//ok
			if (text==1)
			{
				
				$(".allCVform").hide();
				$("#cvForm-thanks-ok").fadeIn('slow');
				alert(text);
			}
			//nie ok
			else{
				
				$(".allCVform").hide();
				$("#cvForm-thanks-error").fadeIn('slow');
				alert(text);
				
			}
			
		}
		
	});
	
		


	return false;
	*/

}




var Wzor_email  =/^[0-9a-zA-Z._-]+\@[0-9a-zA-Z_-]+\.[0-9a-zA-Z._]+$/;					


function checkAskAboutProductValidation(){
	
	

	var imie		= document.getElementById('imie');
	var nazwisko	= document.getElementById('nazwisko');
	var email		= document.getElementById('email');
	var pytanie		= document.getElementById('pytanie');
	var polecObrazek= document.getElementById('polecObrazek');
	var zgoda		= document.getElementById('zgoda');


	if (imie.value == '')
	{
		alert('Pole \"imię\" jest wymagane');
		imie.focus();
		imie.select();
		return false;
	}
	else if (imie.value.length<3)
		{
			alert('Pole \"imię\" musi zawierać co najmniej 3 znaki');
			imie.focus();
			imie.select();
			return false;
		}

	if (nazwisko.value == '')
	{
		alert('Pole \"nazwisko\" jest wymagane');
		nazwisko.focus();
		nazwisko.select();
		return false;
	}
	else if (nazwisko.value.length<3)
		{
			alert('Pole \"nazwisko\" musi zawierać co najmniej 3 znaki');
			nazwisko.focus();
			nazwisko.select();
			return false;
		}

	if (email.value == '')
	{
		alert('Pole \"email\" jest wymagane');
		email.focus();
		email.select();
		return false;
	}
	else if (Wzor_email.test(email.value)!=true)
		{
			alert('Proszę wpisać poprawny adres e-mail');
			email.focus();
			email.select();
			return false;
		}

	if (pytanie.value == '')
	{
		alert('Pole \"pytanie\" jest wymagane');
		pytanie.focus();
		pytanie.select();
		return false;
	}
	else if (pytanie.value.length<10)
		{
			alert('Pole \"pytanie\" musi zawierać co najmniej 10 znaki');
			pytanie.focus();
			pytanie.select();
			return false;
		}

	if (zgoda.checked == false)
	{
		alert('Proszę wyrazić zgodę na przetwarzanie danych osobowych');
		zgoda.focus();
		return false;
	}



	$('#submit').hide();
	
	var dataString = 'imie='+ imie.value + '&nazwisko=' + nazwisko.value + '&email=' + email.value + '&pytanie=' + pytanie.value + '&polecObrazek=' + polecObrazek.value;
	
	
	$.ajax({
		type: "POST",
		url: "skrypt.php?action=askAboutProduct",
		data: dataString,
		success: function(text) {
			
			//ok
			if (text==1)
			{
				$("#askAboutProductDiv").fadeOut('slow');
				$("#form-container-thanks-ok").fadeIn('slow');
			}
			//nie ok
			else{
				$("#askAboutProductDiv").fadeOut('slow');
				$("#form-container-thanks-error").fadeIn('slow');
				//$('#submit').show();
				//alert(text);
			}
			
		}
		
	});


	return false;

}




$.ajaxSetup({cache: false}); //wyłączenie cache-owania AJAX


$(document).ready(function newsletter() {
	$("#newsletterBox").focus(function() {
		if ($(this).val()=='wpisz swój adres e-mail')
		{
			$("#newsletterBox").val('');     
		}
	});

	$("#newsletterBox").blur(function() {
		if ($(this).val()=='')
		{
			$("#newsletterBox").val('wpisz swój adres e-mail');
		}
	});

});






var Wzor_email  =/^[0-9a-zA-Z._-]+\@[0-9a-zA-Z_-]+\.[0-9a-zA-Z._]+$/;
var Wzor_cyfry  =/^[0-9]+$/;


function checkValidation(){
	
	

	var imie		= document.getElementById('imie');
	var nazwisko	= document.getElementById('nazwisko');
	var miasto		= document.getElementById('miasto');
	var telefon		= document.getElementById('telFax');
	var email		= document.getElementById('email');
	var pytanie		= document.getElementById('pytanie');
	var captcha		= document.getElementById('captcha');
	var zgoda		= document.getElementById('zgoda');
	var captcha		= document.getElementById('captcha');


	if (imie.value == '')
	{
		alert('Pole \"imię\" jest wymagane');
		imie.focus();
		imie.select();
		return false;
	}
	else if (imie.value.length<3)
		{
			alert('Pole \"imię\" musi zawierać co najmniej 3 znaki');
			imie.focus();
			imie.select();
			return false;
		}

	if (nazwisko.value == '')
	{
		alert('Pole \"nazwisko\" jest wymagane');
		nazwisko.focus();
		nazwisko.select();
		return false;
	}
	else if (nazwisko.value.length<3)
		{
			alert('Pole \"nazwisko\" musi zawierać co najmniej 3 znaki');
			nazwisko.focus();
			nazwisko.select();
			return false;
		}

	if (telefon.value != '' && Wzor_cyfry.test(telefon.value)!=true)
		{
			alert('Pole \"telefon\" musi zawierać cyfry');
			telefon.focus();
			telefon.select();
			return false;
		}
	
	if (email.value == '')
	{
		alert('Pole \"email\" jest wymagane');
		email.focus();
		email.select();
		return false;
	}
	else if (Wzor_email.test(email.value)!=true)
		{
			alert('Proszę wpisać poprawny adres e-mail');
			email.focus();
			email.select();
			return false;
		}

	if (pytanie.value == '')
	{
		alert('Pole \"pytanie\" jest wymagane');
		pytanie.focus();
		pytanie.select();
		return false;
	}
	else if (pytanie.value.length<10)
		{
			alert('Pole \"pytanie\" musi zawierać co najmniej 10 znaki');
			pytanie.focus();
			pytanie.select();
			return false;
		}
	
	if (captcha.value == '')
	{
		alert('Proszę wpisać wynik dodawania');
		captcha.focus();
		captcha.select();
		return false;
	}
	else if (Wzor_cyfry.test(captcha.value)!=true)
		{
			alert('Proszę wpisać poprawny wynik dodawania');
			captcha.focus();
			captcha.select();
			return false;
		}


	if (zgoda.checked == false)
	{
		alert('Proszę wyrazić zgodę na przetwarzanie danych osobowych');
		zgoda.focus();
		return false;
	}
	$("#form-container-thanks-error-captcha").hide();
	$('#submit').hide();
	
	var dataString = 'imie='+ imie.value + '&nazwisko=' + nazwisko.value + '&miasto=' + miasto.value  + '&telefon=' + telefon.value + '&email=' + email.value + '&pytanie=' + pytanie.value + '&captcha=' + captcha.value;
	
	
	$.ajax({
      type: "POST",
      url: "skrypt.php?action=contact",
      data: dataString,
      success: function(text) {

		//błąd captcha
		if (text==1)
		{
			$("#form-container-thanks-error-captcha").fadeIn('slow');
			$('#submit').show();
		}
		else {


		$('#contact-form').slideUp('slow', function() {
			
			
			$("#form-container-thanks").slideDown('slow', function() {
			 
			 //$('#navigation').localScroll({
			 //  target:'#content'
			//});

			 //błąd
			 if (text==0)
			 {
				$("#form-container-thanks-error").fadeIn('slow');
			 }
			 //jest ok!
			 else if (text==2)
			 {
				$("#form-container-thanks-ok").fadeIn('slow');

			 }
			 else 
			 {
				 //debug mode
				 //alert('dataString:'+dataString);
				 //alert('responseText:'+text);
				 $("#form-container-thanks-error").fadeIn('slow');
			 }
			
			});
	 
		
		});
		}
      }
    });


	return false;

}

//-------------------------------------------



function checkValidationNewsletter(){
	
	
	var newsletterActionAdd = document.getElementById('newsletterActionAdd');
	var newsletterActionDel = document.getElementById('newsletterActionDel');

	var email		= document.getElementById('newsletterBox');

	
	if (email.value == '')
	{
		alert('Pole \"email\" jest wymagane');
		email.focus();
		email.select();
		return false;
	}
	else if (Wzor_email.test(email.value)!=true)
		{
			alert('Proszę wpisać poprawny adres e-mail');
			email.focus();
			email.select();
			return false;
		}

	


	
	$("#newsletterForm").hide();
	$("#newsletterLoading").show();


	var radioSelected = jQuery('#newsletterForm input:radio:checked').val();


	var dataString = 'newsletterEmail=' + email.value;
	
	if (radioSelected=='add')
	{
		var actionToDo = 'newsletterAdd';
		//dodawanie adresu email do newslettera
	}
	else {
		var actionToDo = 'newsletterDel';
		//usuwanie adresu email z newslettera
	}
	
	$.ajax({
		type: "POST",
		url: "skrypt.php?action="+actionToDo,
		data: dataString,
		success: function(text) {

		$("#newsletterLoading").hide();	
		 //błąd
		 if (text=='0')
		 {
			$('#newsletterError').slideDown('slow');
			//alert(text);
		 }
		 //jest ok!
		 else if (text=='1')
		 {
			if (actionToDo=='newsletterAdd')
			{
				$('#newsletterThanks').slideDown('slow');
			}else {
				$('#newsletterThanksUnsubscribe').slideDown('slow');
			}
		 }
		 else if (text=='2')
		 {
			if (actionToDo=='newsletterAdd')
			{
				$('#newsletterEmailExists').slideDown('slow');
			}else {
				$('#newsletterEmailNotExists').slideDown('slow');
			}
			
			
			//alert(text);
		 }
		 else 
		 {
			 //debug mode
			// alert('dataString:'+dataString);
			 //alert(text);
			// $("#newsletterForm").show();
			 $('#newsletterError').slideDown('slow');
		 }
			
			
	 
		
	//	});
		
      }
    });


	return false;

}
