/**
	NEW EVENT LIGHTBOX
**/

/**
* Function to call the JavaScript Validation.
*
* @name 	load_form_new_event
* @access 	public
* @param 	var-type none
* @return 	none
* @author 	Ever Barreto
* @email	ever@amediacreative.com
*/ 
function load_form_new_event()  {

	var check_list = new Array();
		check_list[0] = '.val_min_len_1';
		check_list[1] = '.val_min_len_3';
		check_list[2] = '.val_min_len_20';
		check_list[3] = '.val_min_len_50';
		check_list[4] = '.val_file';
		check_list[5] = '.val_email';

	var form = $('event_post_form');
	var callback = 'call_add_event_step2(obj)';
	init_val(check_list, form, callback);
	file('event_photo');
	
	if ($('event_date_month')) dropdown('event_date_month');
	if ($('event_date_day')) dropdown('event_date_day');
	if ($('event_date_year')) dropdown('event_date_year');
	
	if ($('event_stime_hour')) dropdown('event_stime_hour');
	if ($('event_stime_minute')) dropdown('event_stime_minute');
	if ($('event_stime_tc')) dropdown('event_stime_tc');
	
	if ($('event_etime_hour')) dropdown('event_etime_hour');
	if ($('event_etime_minute')) dropdown('event_etime_minute');
	if ($('event_etime_tc')) dropdown('event_etime_tc');
	
	submit_toggle();

}

/**
* Function to process new event
*
* @name 	call_add_event_step2
* @param 	obj form
* @return 	none
* @author 	Ever Barreto
* @email	e.barreto@amediacreative.com
*/ 
function call_add_event_step2(obj) {

	var photo = $('event_uploaded_photo_name');
	if ( ! photo.get('value')) {

		var iframe_photo_input = frames['event_upl_photo'].document.forms[0].photo;
		var iframe_valdiv = iframe_photo_input.getParent().getParent();
		iframe_valdiv.addClass('val_error');
		return;

	}
	
	obj.set('send', { 
		onComplete: function(response) {
			var id_hide = obj.get('id');
 			var id_show = 'add_event_step1_ajax_page';
			
			$(id_hide).setStyle('display','none');
			
			var ajax_page = new Element('div', {'id': id_show, 'html': response, 'class': ''});
			ajax_page.inject(obj.getParent(), 'bottom');
			event_step_edit(id_hide, id_show, 'btn_edit_goback');
			load_form_event_step2();
			submit_toggle();
		}
	});

	obj.send();
	
}

/**
* Function to call the JavaScript Validation.
*
* @name 	load_form_event_step2
* @access 	public
* @param 	var-type none
* @return 	none
* @author 	Ever Barreto
* @email	e.barreto@amediacreative.com
*/ 
function load_form_event_step2()  {

	var check_list = new Array();
		check_list[0] = '.val_min_len_3';

	var form = $('event_post_2_form');
	var callback = 'call_add_event_step3(obj)';
	if (form) init_val(check_list, form, callback);
	submit_toggle();

}

/**
* Function to process new event
*
* @name 	call_add_event_step3
* @param 	obj form
* @return 	none
* @author 	Ever Barreto
* @email	e.barreto@amediacreative.com
*/ 
function call_add_event_step3(obj) {

	obj.set('send', { 
		onComplete: function(response) {
			var id_hide = obj.get('id');
 			var id_show = 'add_event_step2_ajax_page';
			$(id_hide).setStyle('display','none');
			var ajax_page = new Element('div', {'id': id_show, 'html': response, 'class': 'global_input_wrapper'});
			ajax_page.inject(obj.getParent(), 'bottom');
			event_step_edit(id_hide, id_show, 'btn_edit_goback1');
			event_step3(obj, id_show);
			submit_toggle();
		}
	});

	obj.send();
}

/**
* Function to process new event - go back and edit.
*
* @name 	event_step_edit
* @param 	str id_hide
* @param 	str id_show
* @return 	none
* @author 	Ever Daniel Barreto
* @email	ever@amediacreative.com
*/ 
function event_step_edit(h, s, btn_edit) {

	var button = $(btn_edit);
	if (button) {

		button.addEvent('click', function() {
						 
			$(s).dispose();
			$(h).setStyle('display','block');

		});
	}
}

/**
* Function to process new event - Submit
*
* @name 	event_step3
* @param 	obj form
* @param 	str id_show
* @return 	none
* @author 	Ever Daniel Barreto
* @email	ever@amediacreative.com
*/ 
function event_step3(obj, s) {

	var button = $('add_event_step3');

	if (button) {
		
		button.addEvent('click', function() {

			var final_request = new Request({

				url: '/ajax',
				data: obj.toQueryString() + '&ajax_method=event.step3',

				onComplete: function(response) {

					$(s).dispose();	
					var ajax_page = new Element('div', {'id': s, 'html': response, 'class': 'global_input_wrapper'});
					ajax_page.inject(obj.getParent(), 'bottom');
					obj.reset();	
					//frames['event_upl_photo'].location.href = frames['event_upl_photo'].location.href;

				}
			});

			final_request.send();

		});
	}
}

/**
* Function to attach the photo from iframe to the main form
*
* @name 	event_attach_photo
* @param 	str file_name
* @param 	str file_id
* @return 	none
* @author 	Ever Daniel Barreto
* @email	ever@amediacreative.com
*/ 
function event_attach_photo(fl,fi) {

	var up = $('event_uploaded_photo_name');
	if (up)
		up.set('value',fl);
	var up = $('event_uploaded_photo_id');
	if (up)
		up.set('value',fi);

}


/**
* Function to remove the photo data from inputs
*
* @name 	event_remove_photo
* @param 	none
* @return 	none
* @author 	Bart Jedrychowski
* @email	bart@amediacreative.com
*/ 
function event_remove_photo() {

	var up = $('event_uploaded_photo_name');
	if (up)
		up.set('value','');
	var up = $('event_uploaded_photo_id');
	if (up)
		up.set('value','');

}



/*
	EDIT EVENT LIGHTBOX FORM
*/

/**
* Function to call the JavaScript Validation.
*
* @name 	load_form_edit_event
* @access 	public
* @param 	var-type none
* @return 	none
* @author 	Ever Barreto
* @email	ever@amediacreative.com
*/ 
function load_form_edit_event()  {

	var check_list = new Array();
		check_list[0] = '.val_min_len_1';
		check_list[1] = '.val_min_len_3';
		check_list[2] = '.val_min_len_20';
		check_list[3] = '.val_min_len_50';
		check_list[4] = '.val_file';
		check_list[5] = '.val_email';

	var form = $('event_edit_form');
	var callback = 'call_edit_event_step2(obj)';
	init_val(check_list, form,callback);
	file('event_photo');
	
	if ($('edit_event_date_month')) dropdown('edit_event_date_month');
	if ($('edit_event_date_day')) dropdown('edit_event_date_day');
	if ($('edit_event_date_year')) dropdown('edit_event_date_year');
	
	if ($('edit_event_stime_hour')) dropdown('edit_event_stime_hour');
	if ($('edit_event_stime_minute')) dropdown('edit_event_stime_minute');
	if ($('edit_event_stime_tc')) dropdown('edit_event_stime_tc');
	
	if ($('edit_event_etime_hour')) dropdown('edit_event_etime_hour');
	if ($('edit_event_etime_minute')) dropdown('edit_event_etime_minute');
	if ($('edit_event_etime_tc')) dropdown('edit_event_etime_tc');
	
	submit_toggle();

}

/**
* Function to process edit event
*
* @name 	call_edit_event_step2
* @param 	obj form
* @return 	none
* @author 	Ever Barreto
* @email	ever@amediacreative.com
*/ 
function call_edit_event_step2(obj) {

	obj.set('send', {
			
		onComplete: function(response) {
			
			var id_hide = obj.get('id');
 			var id_show = 'edit_event_ajax_page';

			$(id_hide).setStyle('display','none');

			var ajax_page = new Element(
								'div', {
									'id': id_show,
									'html': response,
									'class': 'global_input_wrapper'
								});
			ajax_page.inject(obj.getParent(), 'bottom');
			event_edit_step2(id_hide, id_show); 	
			submit_toggle();
			
		}
		
	});

	obj.send();
}

/**
* Function to process edit event - go back and edit.
*
* @name 	event_edit_step2
* @param 	str id_hide
* @param 	str id_show
* @return 	none
* @author 	Ever Daniel Barreto
* @email	ever@amediacreative.com
*/ 
function event_edit_step2(h, s) {

	var button = $('btn_edit_goback');
	if (button) {

		button.addEvent('click', function() {
						 
			$(s).dispose();
			$(h).setStyle('display','block');

		});
	}
}

/**
* Function to attach the photo from iframe to the main form
*
* @name 	edit_event_attach_photo
* @param 	str file_name
* @param 	str file_id
* @return 	none
* @author 	Ever Daniel Barreto
* @email	ever@amediacreative.com
*/ 
function edit_event_attach_photo(fl,fi) {

	var up = $('edit_event_uploaded_photo_name');
	if (up) up.set('value',fl);
	
	var up = $('edit_event_uploaded_photo_id');
	if (up) up.set('value',fi);

}


/**
* Function to remove the photo data from inputs
*
* @name 	event_remove_photo
* @param 	none
* @return 	none
* @author 	Bart Jedrychowski
* @email	bart@amediacreative.com
*/ 
function edit_event_remove_photo() {

	var up = $('edit_event_uploaded_photo_name');
	if (up) up.set('value','');
	
	var up = $('edit_event_uploaded_photo_id');
	if (up) up.set('value','');

}



/*
	SEND TO A FRIEND LIGHTBOX FORM
*/

/**
* Function to call the JavaScript Validation.
*
* @name 	load_form_edit_event
* @access 	public
* @param 	var-type none
* @return 	none
* @author 	Ever Barreto
* @email	ever@amediacreative.com
*/ 
function load_form_send_event()  {

	var check_list = new Array();
		check_list[0] = '.val_min_len_3';
		check_list[1] = '.val_min_len_20';
		check_list[2] = '.val_min_len_50';
		check_list[3] = '.val_file';
		check_list[3] = '.val_email';

	var form = $('event_send_form');
	var callback = 'call_send_event_step2(obj)';
	init_val(check_list, form, callback);
	submit_toggle();

}

/**
* Function to process edit event
*
* @name 	call_edit_event_step2
* @param 	obj form
* @return 	none
* @author 	Ever Barreto
* @email	ever@amediacreative.com
*/ 
function call_send_event_step2(obj) {

	obj.set('send', { 
		onComplete: function(response) {
			var id_hide = obj.get('id');
 			var id_show = 'send_event_ajax_page';

			$(id_hide).setStyle('display','none');

			var ajax_page = new Element(
								'div', {
									'id': id_show,
									'html': response,
									'class': 'global_input_wrapper'
								});
			ajax_page.inject(obj.getParent(), 'bottom');
			event_send_step2(id_hide, id_show); 	
			submit_toggle();
		}
	});

	obj.send();
}

/**
* Function to process edit event - go back and edit.
*
* @name 	event_send_step2
* @param 	str id_hide
* @param 	str id_show
* @return 	none
* @author 	Ever Daniel Barreto
* @email	ever@amediacreative.com
*/ 
function event_send_step2(h, s) {

	var button = $('btn_send_goback');
	if (button) {

		button.addEvent('click', function() {
						 
			$(s).dispose();
			$(h).setStyle('display','block');

		});
	}
}



/*
	CANCEL LIGHTBOX FORM
*/

/**
* Function to call the JavaScript Validation.
*
* @name 	load_form_cancel_event
* @access 	public
* @param 	var-type none
* @return 	none
* @author 	Ever Barreto
* @email	ever@amediacreative.com
*/ 
function load_form_cancel_event()  {

	if ($('agree_checkboxes')) call_agree_multiselect();
	var check_list = new Array();
		check_list[0] = '.val_min_len_3';
		check_list[1] = '.val_email';

	var form = $('event_cancel_form');
	var callback = 'call_cancel_event_step2(obj)';
	init_val(check_list, form, callback);
	submit_toggle();

}

/**
* Function to process cancel event
*
* @name 	call_cancel_event_step2
* @param 	obj form
* @return 	none
* @author 	Ever Barreto
* @email	ever@amediacreative.com
*/ 
function call_cancel_event_step2(obj) {

	obj.set('send', { 
		onComplete: function(response) {
			var id_hide = obj.get('id');
 			var id_show = 'cancel_event_ajax_page';

			$(id_hide).setStyle('display','none');

			var ajax_page = new Element(
								'div', {
									'id': id_show,
									'html': response,
									'class': 'global_input_wrapper'
								});
			ajax_page.inject(obj.getParent(), 'bottom');
			event_cancel_step2(id_hide, id_show); 	
			submit_toggle();
		}
	});

	obj.send();
}

/**
* Function to process edit event - go back and edit.
*
* @name 	event_cancel_step2
* @param 	str id_hide
* @param 	str id_show
* @return 	none
* @author 	Ever Daniel Barreto
* @email	ever@amediacreative.com
*/ 
function event_cancel_step2(h, s) {

	var button = $('btn_cancel_goback');
	if (button) {

		button.addEvent('click', function() {
						 
			$(s).dispose();
			$(h).setStyle('display','block');

		});
	}
}



/*
|--------------------------------------------------------------------------
| Amedia Creative Community > Events > Comment Event related functions
|--------------------------------------------------------------------------
|
*/

/**
* Function to call the JavaScript Validation for the Edit Article Lightbox Form
*
* @name 	load_form_comment_event
* @access 	public
* @param 	var-type none
* @return 	none
* @author 	Ever Daniel Barreto
* @email	ever@amediacreative.com
*/ 
function load_form_comment_event()  {

	var check_list = new Array();
		check_list[0] = '.val_min_len_3';
		check_list[1] = '.val_min_len_50';
		check_list[2] = '.val_min_len_100';

	var form = $('comment_form');
	var callback = 'call_comment_event(obj)';
	init_val(check_list, form, callback);
	submit_toggle();
	
}

/**
* Function to process comment event.
*
* @name 	call_comment_event
* @param 	obj form
* @return 	none
* @author 	Ever Daniel Barreto
* @email	ever@amediacreative.com
*/ 
function call_comment_event(form_object) {

	form_object.set('send', {
		onComplete: function(response) {
			
			var id_hide = form_object.get('id');
 			var id_show = 'event_article_ajax_page';
			var id = $('id_event');

			$(id_hide).setStyle('display','none');

			var ajax_page = new Element('div', {'id': id_show, 'html': response, 'class': 'global_input_wrapper' });
			ajax_page.inject(form_object.getParent(), 'bottom');
			event_comment_step2(id_hide, id_show);
			submit_toggle();
			if ($('id_event')) update_comments_container($('id_event').get('value'), '/event/ajax_get_comments', 'comment_box');
			
		}
	});
	form_object.send();

}

/**
* Function to process comment event - go back and edit.
*
* @name 	event_comment_step2
* @param 	str id_hide
* @param 	str id_show
* @return 	none
* @author 	Bart Jedrychowski
* @email	bart@amediacreative.com
*/ 
function event_comment_step2(h,s) {

	var button = $('btn_comment_goback');
	if (button) {

		button.addEvent('click', function() {
						 
			$(s).dispose();
			$(h).setStyle('display','block');

		});
	}
}