﻿	$(document).ready(function() {
		
		//if submit button is clicked
		$('#submit').click(function () {		
			
			//Get the data from all the fields
			var name = $('input[name=name]');
			var email = $('input[name=email]');
			var website = $('input[name=website]');
			var comment = $('textarea[name=comment]');

			//Simple validation to make sure user entered something
			//If error found, add hightlight class to the text field
			if (name.val()=='') {
				$('.not-message').fadeIn('slow');
				return false;
			} else name.addClass('text');
			
			if (email.val()=='') {
				$('.not-message').fadeIn('slow');
				return false;
			} else email.addClass('text');
			
			if (website.val()=='') {
				$('.not-message').fadeIn('slow');
				return false;
			} else website.addClass('text');
			
			if (comment.val()=='') {
				$('.not-message').fadeIn('slow');
				return false;
			} else comment.addClass('textarea');
			
			if (name.val()=='Podaj swoje imię...') {
				$('.not-message').fadeIn('slow');
				return false;
			} else name.addClass('text');
			
			if (email.val()=='Podaj swój adres e-mail...') {
				$('.not-message').fadeIn('slow');
				return false;
			} else email.addClass('text');
			
			if (website.val()=='Temat wiadomości...') {
				$('.not-message').fadeIn('slow');
				return false;
			} else website.addClass('text');
			
			if (comment.val()=='Wpisz swoje zapytanie...') {
				$('.not-message').fadeIn('slow');
				return false;
			} else comment.addClass('textarea');
			
			//organize the data properly
			var data = 'name=' + name.val() + '&email=' + email.val() + '&website=' + 
			website.val() + '&comment='  + encodeURIComponent(comment.val());
			
			
			
			//start the ajax
			$.ajax({
				//this is the php file that processes the data and send mail
				url: "process.php",	
				
				//GET method is used
				type: "GET",

				//pass the data			
				data: data,		
				
				//Do not cache the page
				cache: false,
				
				//success
				success: function (html) {				
					//if process.php returned 1/true (send mail success)
					if (html==1) {	
						$('.not-message').hide();
						$('.done').fadeIn('slow');
						
					//if process.php returned 0/false (send mail failed)
					} else 
					$('.not-message').fadeIn('slow');
					
				}		
			});
			
			//cancel the submit button default behaviours
			return false;
		});	
		
		
	});	
$(document).ready(function(){
    $('#contact-info a:first').addClass('first');  
});

