 $(document).ready(function(){
	$("#submitbutton").click(function(){
		var valid = '';
		var name = $("#name").val();
		var phone = $("#phone").val();
		var mail = $("#email").val();
		var message = $("#message").val();
		
		if (name.length<1) {
			valid += '<br />Molimo upišite Vaše ime!';
		}
		if (mail.length<1) {
			valid += '<br />Molimo upišite Vašu E-Mail adresu!';
		}
		if (phone.length<1) {
			valid += '<br />Molimo upišite broj telefona!';
		}
		if (message.length<1) {
			valid += '<br />Molimo upisite Vašu poruku.';
		}

		if (valid!='') {
			$("#response").fadeIn("slow");
			$("#response").html("Greška!"+valid);
		}

		else { 
			message = message.replace('\n', '<br />', 'g');
			var datastr ='name=' + name + '&mail=' + mail + '&phone=' + phone + '&message=' + message;
			$("#response").css("display", "block");
			$("#response").html("Slanje poruke...<img src='http://<?php echo $_SERVER['HTTP_HOST']; ?>/wp-content/themes/betontrend//images/sendingmail.gif'>");
			$("#response").fadeIn("slow");
			setTimeout("send('"+datastr+"')",2000);
		}
		return false;
	});
});

function send(datastr){
	$.ajax({	
		type: "POST",
		url: "http://<?php echo $_SERVER['HTTP_HOST']; ?>/wp-content/themes/betontrend/contact-srb.php",
		data: datastr,
		cache: false,
		success: function(html){
		$("#response").fadeIn("slow");
		$("#response").html(html);
		setTimeout('$("#response").fadeOut("slow")',8000);
		setTimeout('$.fancybox.close()', 1000);
	}
	});
}