var selfEventsTips;
var nationalEventsTips;
var otherEventsTips;

window.addEvent('domready', function(){
	if($('prevCntrl')){
		$('prevCntrl').addEvent('click', function(e){
			e.stop();
			var params = "direction=prev&eventsMonth=" +$('eventsMonth').value+ "&eventsYear=" +$('eventsYear').value;
			
			var req = new Request({	method: 'get',
									url: '/wp-content/plugins/events/includes/ajax/updateCalendar.ajax.php',
									data: params,
									onSuccess: function(output){
										$('eventsCalendarWrap').set('html', "");
										$('eventsCalendarWrap').set('html', output);
										
										initEventsTips();
									}});
			req.send();
		});
	}
	
	if($('currentCntrl')){
		$('currentCntrl').addEvent('click', function(e){
			e.stop();
			var params = "direction=now&currentEventsMonth=" +$('currentEventsMonth').value+ "&currentEventsYear=" +$('currentEventsYear').value;
			
			var req = new Request({	method: 'get',
									url: '/wp-content/plugins/events/includes/ajax/updateCalendar.ajax.php',
									data: params,
									onSuccess: function(output){
										$('eventsCalendarWrap').set('html', "");
										$('eventsCalendarWrap').set('html', output);
										
										initEventsTips();
									}});
			req.send();
		});
	}
	
	if($('nextCntrl')){
		$('nextCntrl').addEvent('click', function(e){
			e.stop();
			var params = "direction=next&eventsMonth=" +$('eventsMonth').value+ "&eventsYear=" +$('eventsYear').value;
			
			var req = new Request({	method: 'get',
									url: '/wp-content/plugins/events/includes/ajax/updateCalendar.ajax.php',
									data: params,
									onSuccess: function(output){
										$('eventsCalendarWrap').set('html', "");
										$('eventsCalendarWrap').set('html', output);
										
										initEventsTips();
									}});
			req.send();
		});
	}
	
	initEventsTips();
});


function initEventsTips(){
	if($$('a.selfEvents')){
		selfEventsTips = new Tips($$('a.selfEvents'), {	className: 'selfEventsTip',
														offsets: {	'x': 15,
																	'y': -5
														}});
	}
	
	if($$('a.nationalEvents')){
		nationalEventsTips = new Tips($$('a.nationalEvents'), {	className: 'nationalEventsTip',
																offsets: {	'x': 15,
																			'y': -5
																}});
	}
	
	if($$('a.otherEvents')){
		otherEventsTips = new Tips($$('a.otherEvents'), {	className: 'otherEventsTip',
															offsets: {	'x': 15,
																		'y': -5
															}});
	}
}


function valSearchForm(form){
	var isFormReady = true;
	
	if(form.events_search_type.value == ""){
		isFormReady = false;
	}
	
	if(form.events_type.value == ""){
		isFormReady = false;
	}
	
	if(form.events_search_val.value == ""){
		isFormReady = false;
	}
	
	if(isFormReady == false){
		form.events_search_val.addClass('searchEventFormError');
		return false;
	}else{
		return true;
	}
}