//FORM SUBMIT
$(function() {
//$('#content form').submit(function() {
$('#sidebar form, #postingan form').submit(function() {
var kemana = $(this).attr('id');
var dataString = $(this).serialize();
var confirmregex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
//var noregex = /^[0-9]+$/;
var noregex = /^[0-9\.-]+$/;
cek = '';

	$(this).find('.required').each(function() {
	isi = $(this).val();
	rel = $(this).attr('rel');
		if(rel=='nmbr' && !noregex.test(isi)) {
				$(this).focus(); $(".cmail").fadeIn(400).html('Email format');
				cek = "no"; return cek;
				}
		else if(rel=='cmail' && !confirmregex.test(isi)) {
				$(this).focus(); $(".nmbr").fadeIn(400).html('Only number');
				cek = "no"; return cek;
				}
		else if(isi=='') {
				$(this).focus();
				cek = "no"; return cek;
				}
	});

	if(cek=='no') { return false; }
	
	{
		
$.ajax({
type: "POST",
url: "http://fenceworkshop.com/wp-content/themes/fence/post.php?action="+kemana,
data: dataString,
cache: false,
success: function(response){

	if(response=="ulangi"){$("#alert").fadeIn(400).html('Please check your data and try again.').delay(1200).fadeOut(800);}
	else if(response=="good") {
		//$("#alert").fadeIn(400).html('Thank you! A representative will contact you shortly.').delay(1200).fadeOut(800);
		//$('input:not([type=submit]) , textarea').val('');
		top.location.href="http://fenceworkshop.com/thank-you/";
		}
	else {$("#alert").fadeIn(400).html('Sorry, we are getting some error. Please, try again in several minutes.').delay(1200).fadeOut(800);}

	}   
});
	}
    return false;
	});
});

