$(function(){
	$("#prayer_request_text").charCounter(200);
	
	$(".add").click(function(){
		$.blockUI({ css: { 
			border: 'none', 
			padding: '15px', 
			backgroundColor: '#000', 
			'-webkit-border-radius': '10px', 
			'-moz-border-radius': '10px', 
			opacity: '.5', 
			color: '#fff' 
		} });
		$.post('/resources/library/processors/proc.addPrayer.php', {prayer_request_id: $(this).attr('value')}, function(data){
			alert(whiteSpace(data));
			$.unblockUI();
			window.location.href = window.location.href;
		});
		return false;
	});

	//	Save the Comment
	//	pre-submit callback
	function preSubmit(formData, jqForm, options){
		var errorMsg = '';
		
		if($("#prayer_request_author").val() == ''){
			errorMsg += "Please enter your name.\nYour name will be kept confidential.\n";
		}
		
		if($("#prayer_request_author_email").val() == ''){
			errorMsg += "Please enter your email.\nYour email will be kept confidential.\n";
		}
		
		if($("#captcha_text").val() == ''){
			errorMsg += "Please enter the text you see in the image.\n";
		}
		else{
			$.ajax({
				type: "POST",
				url: "/resources/library/classes/Captcha/image_proc.php",
				data: "captchaTxt=" + $("#captcha_text").val(),
				async: false,
				success: function(data){
					if(whiteSpace(data) != "true"){
						errorMsg += "Your text doesn't match the text in the image.\nYou can click the image to refresh the text.\n";
					}
				}
			});
		}
		
		if($("#prayer_request_text").val() == ''){
			errorMsg += "Please enter your request.\n";
		}
					
		if(errorMsg != ''){
			alert(errorMsg);
			return false;
		}
		$.blockUI({ css: { 
	           border: 'none', 
	           padding: '15px', 
	           backgroundColor: '#000', 
	           '-webkit-border-radius': '10px', 
	           '-moz-border-radius': '10px', 
	           opacity: '.5', 
	           color: '#fff' 
	       } }); 
		return true;
	}
	//	post-submit callback
	function postSubmit(responseText, statusText){
		$.unblockUI();
		alert(whiteSpace(responseText));
		$("#frmRequest").resetForm();
	}
	$("#frmRequest").ajaxForm({beforeSubmit:preSubmit, success:postSubmit, url:"/resources/library/processors/proc.saveRequest.php", type:"post"});
});
