/**
 * Apiki Events WordPress Plugin script file
 *
 * This file is responsible for scripts used
 * in Apiki Events WordPress Plugin.
 *
 * @author Apiki <opensource@apiki.com>
 * @version 0.1
 * @package WordPress
 */

/**
 * Apiki Events object
 */
APIKI_EVENTS = {}

/**
 * Avoid jQuery conflict with other JavaScript libraries
 */
var $ = jQuery.noConflict();

/**
 * Actions to be executed when the page loads
 */
jQuery(function($) {
				
	/**
	 * http://malsup.com/jquery/form/
	 */
	$('#apiki-events-frm').ajaxForm( { beforeSubmit : APIKI_EVENTS.validate, success : APIKI_EVENTS.success } );
	
	/**
	 * Show a confirm message to user when delete events.
	 */
	$('#apiki-events-bulk-actions').click(function() {
		if ( $('select[name="apiki_events_action"]').val() == 'delete' ) {
			return showNotice.warn(apiki_events_msg_about_delete);
		}
	});
		
});

/**
 * Function to be executed after the ajax submission
 */
APIKI_EVENTS.success = function() {
	$('#apiki-events-frm').slideToggle();
	$('.apiki-events-required-info').text('Obrigado pela contribuição. Após análise do editor seu evento será exibido em nosso site.');	
}

/**
 * Funciton to validate the form presented to end user
 */
APIKI_EVENTS.validate = function(formData, jqForm, options) {
	var form = jqForm[0];
	if ( !form.event_summary.value || !form.event_location.value || !form.event_start_hour_hours.value || !form.event_start_hour_minutes.value || !form.event_end_hour_hours.value || !form.event_end_hour_minutes.value || !form.event_description.value ) {
		alert('Por favor, informe os campos requeridos');
		return false;
	}
}