 $(document).ready(function(){
	$("#email").focus(function(){
		if( typeof $('body').data('email') == 'undefined' ) {
			$('body').data('email','edited');
			$("#email").val("");
		}
	});
	$("#telefon").focus(function(){
		if( typeof $('body').data('telefon') == 'undefined' ) {
			$('body').data('telefon','edited');
			$("#telefon").val("");
		}
	});
	$("#text").focus(function(){
		if( typeof $('body').data('text') == 'undefined' ) {
			$('body').data('text','edited');
			$("#text").val("");
		}
	});
	$("#email").focusout(function(){
                if( $("#email").val() == '' ) {
			$("#email").val("váš e-mail");
                        $('body').removeData('email');
		}
	});
	$("#telefon").focusout(function(){
                if( $("#telefon").val() == '' ) {
			$("#telefon").val("vaše telefonní číslo");
                        $('body').removeData('telefon');
		}
	});
	$("#text").focusout(function(){
		if( $("#text").val() == '' ) {
			$("#text").val("text zprávy...");
                        $('body').removeData('text');
		}
	});
	$("#sendmail").click(function(){
		var valid = '';
		var countErr = 0;
		var mail = $("#email").val();
		var telefon = $("#telefon").val();
		var text = $("#text").val();
                var intRegex = /[0-9 -()+]+$/;
		if (!mail.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
			valid += '<ul><li>Email je ve špatném tvaru.</li></ul>';
		}
		if ($("#telefon").val() == 'vaše telefonní číslo') {
			telefon = '';
		}
		else if(telefon.length<9 || !intRegex.test(telefon)) {
			valid += '<ul><li>Telefoní číslo má špatný tvar.</li></ul>';
		}
		if (text.length<1 || $("#text").val() == 'text zprávy...') {
			valid += '<ul><li>Musíte zadat text poptávky.</li></ul>';
		}
		if (valid!='') {
			$("#response").fadeIn("slow");
			if(countErr==1)$("#response").html("Nastala chyba:"+valid);
			else $("#response").html("Nastaly chyby:"+valid);
		}
		else {
			var datastr ='mail=' + mail + '&telefon=' + telefon + '&text=' + text;
			$("#response").css("display", "block");
			$("#response").html("Odesílám poptávku... ");
			$("#response").fadeIn("slow");
			setTimeout("send('"+datastr+"')",5000);
		}
		return false;
	});
});
function send(datastr){
	$.ajax({
		type: "POST",
		url: "web_files/scripts/mail.php",
		data: datastr,
		cache: false,
		success: function(html){
			$("#response").fadeIn("slow");
			$("#response").html(html);
			setTimeout('$("#response").fadeOut("slow")',5000);
			$("#email").val("váš e-mail");
			$("#telefon").val("vaše telefonní číslo");
			$("#text").val("text zprávy...");
			$('body').removeData('email');
			$('body').removeData('telefon');
			$('body').removeData('text');
		}
	});
}
