var sendPray = {
	init : function() {
		$('.sendPrayForm').submit(this.onSendPray);
	},
	
	onSendPray : function() {
		
		if (sendPray.validateForm())
			return sendPray.submitPray();
		else {
			alert('Please fill in all the fields!');
			return false;
		}
		
	},
	
	submitPray : function() {
		
		 $.ajax({
			   type: "POST",
			   url: "rpcProxy/sendPray",
			   data:  $(".sendPrayForm").serialize(),
			   async: false
 		});

	},
	
	validateForm : function() {
		var required_fields = new Array('email','firstName','lastName','fatherName','motherName', 'phone', 'holyPlace');

		//validate form
		for (i in required_fields) {
			var val = $('#sendPray_' + required_fields[i]).val();
			if (val == '') //field is empty!
				return false;
		}

		return true;
	}
}


$(document).ready(function() {
	sendPray.init();
});

