/* 
	Javascript elements for event creation
	
	These functions are primarily to assist in handling all the visual wizardry for performance creation.
	
*/

function day_name(date) {
	var weekday=new Array(7);
	weekday[0]="Sunday";
	weekday[1]="Monday";
	weekday[2]="Tuesday";
	weekday[3]="Wednesday";
	weekday[4]="Thursday";
	weekday[5]="Friday";
	weekday[6]="Saturday";
	
	return weekday[date.getDay()];
}

function show_performance_repeat(elem) {
	repeat_end = elem.next('.repeat_info');
	weekday_name = repeat_end.down('.day_of_week');
	
	switch(elem.value) {
		case 'X':
			repeat_end.hide();
			weekday_name.hide();
			break;
			
		case 'D':
			repeat_end.show();
			weekday_name.hide();
			break;
			
		case 'W':
			update_day_of_week(weekday_name);
			weekday_name.show();
			repeat_end.show();
			
	}
}

function update_day_of_week(wday_elem, highlight) {
	wday_elem.innerHTML = "on " + day_name(new Date(Element.extend(wday_elem.parentNode).siblings()[0].value));
	if(highlight == true) {
		new Effect.Highlight(wday_elem);
	}
}

function setup_performance_fields(group_elem) {
	group_elem = group_elem || $('performance_fields').childElements().last();
	if($('event_is_open').checked) {
		group_elem.down('.performance_time').hide();
	}
	update_day_of_week(group_elem.down('.repeat_info').down('.day_of_week'));
	show_performance_repeat(group_elem.down('select'));
	group_elem.appear({ duration: 0.25 });
}

function setup_ticket_type_fields(group_elem) {
	group_elem = group_elem || $('ticket_type_fields').childElements().last();
	
	group_elem.appear({duration: 0.25});
}

function update_time_display() {
	$$('.performance_time').each(function(item){
		if($('event_is_open').checked) {
			item.hide();
		} else {
			item.show();
		}
	})
}

function select_sidebar_tab(tab_elem, tab_name) {
	tab_elem.up().childElements().each(function(item){
		item.removeClassName("selected");
	});
	tab_elem.addClassName("selected");
	
	content_tab = $(tab_name + '_content');
	if(content_tab != null){
		$$('.content_tab').each(function(item){
			item.removeClassName("active");
			item.addClassName("inactive");
		});
		content_tab.removeClassName("inactive");
		content_tab.addClassName("active");
	}
}