/*============================  D O C U M E N T  ============================*/	
$(document).ready( function() {

	$("span.mail").each( function(i) { 
		var mail = $(this).html().replace(':','@');
		var text = '<a href="mailto:' + mail + '">' + mail + '</a>'
		$(this).html(text);
	});
	
	$("input").click(function() {
		$(this).next().hide();
	});
	
	$("textarea").click(function() {
		$(this).next().hide();
	});

	
	 $("input[name*='phone']").keyup(function(e){
      var exp = /[^\d-+.]/g;
      var value = $(this).val().replace(exp,'');
      $(this).val(value);
	});
	
	$("#polec").children('form').submit(function() {
		
		var email_from = $("input[name='email_from']").val();
		var email_to = $("input[name='email_to']").val();
				
		var error = 0;
		
			if (email_from == '' || ValidMail(email_from) == false) {
				$("input[name='email_from']").next().show();
				error = 1;
			}
			
			if (email_to == '' || ValidMail(email_to) == false) {
				$("input[name='email_to']").next().show();
				error = 1;
			}
			
		if (error == 0) {
						
			$.ajax({
			
				type: "POST",
				url: "class/send_mail.php",
				data: "email_from="+email_from+"&email_to="+email_to,
				async: false,
				
				success: function(msg){
					$("#polec").prev().hide();
					$("#polec").children('form').hide();
					$("#polec").children("span.zm").hide();
					$("#polec").children("span.dz").show();
				    $("#polec").show('fast');
				}
				
			});
		}	
		
		return false;
	});

});	
	
/*============================  F U N C T I O N S  ============================*/

function ValidMail(src) {
  var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
  return regex.test(src);
}

