/*
jQuery Overlay
Copyright (c) 2009 Ylab, www.ylab.nl
Author: Yohan Creemers
*/
function prepareResponseForm(){
	//validate form before submutting
	$('#frmResponse').submit(function(event){
		event.preventDefault();
		if(validateResponseForm.call(this)){
			postResponseForm.call(this);
		}
	});
}

function validateResponseForm(){
	var f = null;

	if(!isNotNull(this.fullname, 'Naam', f) ||
		 !isNotNull(this.content, 'Reactie', f)
	){
		return false;
	}

	return true;
}

function postResponseForm(){
	var params = {};
	var props = jQuery(this).serialize();
	var $this = $(this);
	$this.html('<p>Je reactie wordt opgeslagen...</p>');

	jQuery.ajax({
		type: 'POST',
		url: '/fotolog/react.php',
		data: props,
		success: function(data){
			$this.html('<p>Je reactie is succesvol opgeslagen.</p>');
			$(frmResponseCallee).html(data);
			window.setTimeout(hideResponseForm, 1000);
		}
	});
	return false;
}

function hideResponseForm(){
	objForm.hide();
	objOverlay.hide();
}

function ajaxify(){
	//list with links to frmResponse form
	$('.ajaxify').click(function(event){
		event.preventDefault();
		frmResponseCallee = this;
		//form id is part to show in the lightbox
		showEditForm(this.href + ' #responses', this.title, prepareResponseForm);
	});
}

jQuery(document).ready(function($){
	var frmResponseCallee;
	if($('#responses').size()){
		//page with the frmResponse form
		$('#frmResponse').submit(validateResponseForm);
	}else{
		//list with links to frmResponse form
		ajaxify();
	}
});
