function changeVenue(type) {
	if (type == "E") {
		$('l_venue_name').style.display = "none";
		$('l_venue_address1').style.display = "none";
		$('l_venue_address2').style.display = "none";
		$('l_venue_address3').style.display = "none";
		$('l_venue_postcode').style.display = "none";

		$('existing_venue').style.display = "";
	}
	else {
		$('l_venue_name').style.display = "";
		$('l_venue_address1').style.display = "";
		$('l_venue_address2').style.display = "";
		$('l_venue_address3').style.display = "";
		$('l_venue_postcode').style.display = "";

		$('existing_venue').style.display = "none";
	}
}


function eventStage2() {
	this.addBand = function() {
		var band_id = $('search_id').value;
		var band_name = $('search_band').value;

		if (band_name != "") {
			// Set Loading Indicator
			$('indicator').show();

			var params = 'object=event&action=add_band&band_id=' +  band_id  + '&band_name=' + band_name;

			var myAjax = new Ajax.Request('/ajax/add.ajax.php', {method: 'post', parameters: params, onComplete: this.addBandResponse});
		}
	}

	this.addBandResponse = function(r) {
		var r = eval('('+ r.responseText +')');

		if (r.response == "OK") {
			var id = r.eventband_id;

			var tr = document.createElement('tr');
			tr.setAttribute('id', 'row_'+id);

			// Band Name Cell
			var td_band_name = document.createElement('td');
			td_band_name.setAttribute('class', 'band_name');
			var txt_band_name = document.createTextNode(r.band_name);
			td_band_name.appendChild(txt_band_name);

			// Time Cell
			var td_time = document.createElement('td');
			td_time.setAttribute('class', 'time');

			// Create Hour Dropdown
			var select_hour = document.createElement('select');
			select_hour.setAttribute('id', 'band_'+id+'_hour');
			select_hour.onchange = function() {
							stage2.saveTime(id, this);
						}

			var new_option = document.createElement('option');
			new_option.appendChild(document.createTextNode('HH'));
			select_hour.appendChild(new_option);



			for (h = 0; h <= 23; h++) {
				var new_option = document.createElement('option');
				new_option.setAttribute('label', h);
				new_option.setAttribute('value', h);
				new_option.appendChild(document.createTextNode(h));

				select_hour.appendChild(new_option);
			}

			// Create Minute Dropdown
			var select_minute = document.createElement('select');
			select_minute.setAttribute('id', 'band_'+id+'_minute');
			select_minute.onchange = function() {
							stage2.saveTime(id, this);
						}

			var new_option = document.createElement('option');
			new_option.appendChild(document.createTextNode('MI'));
			select_minute.appendChild(new_option);

			for (i=0; i<=55; i=i+5) {
				var new_option = document.createElement('option');
				new_option.setAttribute('label', i);
				new_option.setAttribute('value', i);
				new_option.appendChild(document.createTextNode(i));

				select_minute.appendChild(new_option);
			}


			td_time.appendChild(select_hour);
			td_time.appendChild(document.createTextNode(' : '));
			td_time.appendChild(select_minute);

			// Create Headliner Radio Button
			td_headliner = document.createElement('td');
			td_headliner.setAttribute('class', 'headline');

			input_headliner = document.createElement('input');
			input_headliner.setAttribute('type', 'radio');
			input_headliner.setAttribute('name', 'headliner');
			input_headliner.setAttribute('value', id);

			input_headliner.onclick = function() {
							stage2.saveHeadliner(id);
						}

			td_headliner.appendChild(input_headliner);

			// Create Options Cell
			td_options = document.createElement('td');
			td_options.setAttribute('class', 'options');

			var a_remove = document.createElement('a');
			a_remove.setAttribute('href', '#');
			a_remove.onclick = function() {
							stage2.deleteBand(id);
						}

			txt_remove = document.createTextNode('REMOVE');

			a_remove.appendChild(txt_remove);
			td_options.appendChild(a_remove);

			// Append Cells
			tr.appendChild(td_band_name);
			tr.appendChild(td_time);
			tr.appendChild(td_headliner);
			tr.appendChild(td_options);

			// Append to table
			var bl = $('bands_list');

			bl.appendChild(tr);

			// Clear text box/hidden value
			$('search_band').value = "";
			$('search_id').value = "";

			// Remove 'no bands' message if neccessary.
			var nobands = $('nobands');
			if (nobands) {
				var tr = nobands.parentNode;
				var p = tr.parentNode;
				p.removeChild(tr);
			}

			stage2.displayBandResponse(r.confirmation, 'confirmation');
		}
		else {
			stage2.displayBandResponse(r.error, 'error');
		}

		$('indicator').hide();
	}

	this.displayBandResponse = function(response_text, style) {
		var response = $('response');

		response.setAttribute('class', style);
		response.innerHTML = response_text;

		Effect.BlindDown('response');

		setTimeout("Effect.BlindUp('response')", 5000);
	}

	this.saveHeadliner = function(id) {
		$('indicator').show();

		var params = 'object=event&action=save_headliner&id='+id;
		var myAjax = new Ajax.Request('/ajax/add.ajax.php', {method: 'post', parameters: params, onComplete: function() {$('indicator').hide();}});

	}

	this.saveTime = function(id) {
		var hour_select = $('band_'+id+'_hour');
		var hour = hour_select.options[hour_select.selectedIndex].value;

		var minute_select = $('band_'+id+'_minute');
		var minute = minute_select.options[minute_select.selectedIndex].value;

		if (hour != "HH" && minute != "MI") {
			$('indicator').show();

			var params = 'object=event&action=save_time&time='+ hour +':'+ minute+'&id='+id;
			var myAjax = new Ajax.Request('/ajax/add.ajax.php', {method: 'post', parameters: params, onComplete: function() {$('indicator').hide();}});
		}
	}

	this.deleteBand = function(id) {
		if (confirm('Are you sure you want to remove this band?')) {
			$('indicator').show();

			var params = 'object=event&action=remove_band&id='+id;

			var myAjax = new Ajax.Request('/ajax/add.ajax.php', {method: 'post', parameters: params, onComplete: this.deleteBandResponse});
		}
	}

	this.deleteBandResponse = function(r) {
		var r = eval('('+ r.responseText +')');

		if (r.response == "OK") {
			var row = $('row_'+ r.id);

			if (row) {
				p = row.parentNode;
				p.removeChild(row);

				stage2.displayBandResponse(r.confirmation, 'confirmation');

				// If no children, add no bands tr
				if (!p.hasChildNodes()) {
					var tr = document.createElement('tr');
					var td = document.createElement('td');
					td.setAttribute('id', 'nobands');
					td.setAttribute('colspan', 4);

					var text = document.createTextNode('You haven\'t added any bands to this event.');

					td.appendChild(text);
					tr.appendChild(td);

					p.appendChild(tr);
				}
			}
		}

		$('indicator').hide();
	}
}


function reviewSelectType() {
	this.typeChange = function() {
		rs.clearDetails();

		var type = $('type');

		var type_code = type.options[type.selectedIndex].value;

		if (type_code == 1) {
			rs.addEventSearchForm();
		}
		else if (type_code == 2) {
			$('indicator').show();

			var params = 'ajax=venuelist';
			var myAjax = new Ajax.Request('/add/', {method: 'get', parameters: params, onComplete: rs.addVenueSearchForm});
		}
		else if (type_code == 3) {
			rs.addBandSearchForm();
		}
		else if (type_code == 4) {
			//this.addAlbumForm();
		}
	}

	this.clearDetails = function() {
		var rd = $('review-details');

		while (rd.firstChild) {
			rd.removeChild(rd.firstChild);
		}
	}


	this.addVenueSearchForm = function(r) {
		var venues = eval('('+ r.responseText +')');

		var rd = $('review-details');

		var legend = document.createElement('legend');
		var legend_text = document.createTextNode('Venue Details');
		legend.appendChild(legend_text);

		var ul = document.createElement('ul');

		// Create Description item
		var li_d = document.createElement('li');
		li_d_t = document.createTextNode('Please choose an existing venue from the list or provide venue details if the venue does not already exist in our database.');
		li_d.appendChild(li_d_t);
		ul.appendChild(li_d);


		// Create Venue Existing
		var li_ex = document.createElement('li');
		li_ex.setAttribute('class', 'radio');

		li_ex_input = document.createElement('input');
		li_ex_input.setAttribute('type', 'radio');
		li_ex_input.setAttribute('id', 'venue_type_e');
		li_ex_input.setAttribute('name', 'venue_type');
		li_ex_input.setAttribute('value', 'E');

		li_ex_input.checked = 1;

		li_ex_input.onclick = function() {
				this.checked = 1;
				$('venue_type_n').checked = 0;
				changeVenue('E');
		}

		li_ex_label = document.createElement('label');
		li_ex_label.setAttribute('for', 'venue_type_e');
		li_ex_label_t = document.createTextNode('Existing Venue');

		li_ex_label.appendChild(li_ex_label_t);
		li_ex.appendChild(li_ex_input);
		li_ex.appendChild(li_ex_label);

		ul.appendChild(li_ex);

		// Create Existing Venue Select
		li_ev = document.createElement('li');
		li_ev.setAttribute('id', 'existing_venue');

		li_ev_s = document.createElement('select');
		li_ev_s.setAttribute('name', 'venue_id');


		for (i=0; i<venues.length; i++) {
			var option = document.createElement('option');
			option.value = venues[i].value;
			var option_text = document.createTextNode(venues[i].text);
			option.appendChild(option_text);

			li_ev_s.appendChild(option);
		}

		li_ev.appendChild(li_ev_s);

		ul.appendChild(li_ev);


		// Create New Venue Details item
		var li_new = document.createElement('li');
		li_new.setAttribute('class', 'radio');

		li_new_input = document.createElement('input');
		li_new_input.setAttribute('type', 'radio');
		li_new_input.setAttribute('id', 'venue_type_n');
		li_new_input.setAttribute('name', 'venue_type');
		li_new_input.setAttribute('value', 'N');
		li_new_input.onclick = function() {
				this.checked = 1;
				$('venue_type_e').checked = 0;
				changeVenue('N');
		}

		li_new_label = document.createElement('label');
		li_new_label.setAttribute('for', 'venue_type_n');
		li_new_label_t = document.createTextNode('New Venue');

		li_new_label.appendChild(li_new_label_t);
		li_new.appendChild(li_new_input);
		li_new.appendChild(li_new_label);

		ul.appendChild(li_new);


		// Create Venue Name list item
		li_v_n = document.createElement('li');
		li_v_n.setAttribute('id', 'l_venue_name');
		li_v_n.style.display="none";

		li_v_n_l = document.createElement('label');
		li_v_n_l.setAttribute('for', 'venue_name');
		li_v_n_l.appendChild(document.createTextNode('Venue Name'));

		li_v_n_i = document.createElement('input');
		li_v_n_i.setAttribute('type', 'text');
		li_v_n_i.setAttribute('name', 'venue_name');
		li_v_n_i.setAttribute('id', 'venue_name');
		li_v_n_i.setAttribute('size', 15);

		li_v_n.appendChild(li_v_n_l);
		li_v_n.appendChild(li_v_n_i);

		ul.appendChild(li_v_n);


		// Create Venue Address 1 list item
		li_v_a1 = document.createElement('li');
		li_v_a1.setAttribute('id', 'l_venue_address1');
		li_v_a1.style.display="none";

		li_v_a1_l = document.createElement('label');
		li_v_a1_l.setAttribute('for', 'venue_address1');
		li_v_a1_l.appendChild(document.createTextNode('Address 1'));

		li_v_a1_i = document.createElement('input');
		li_v_a1_i.setAttribute('type', 'text');
		li_v_a1_i.setAttribute('name', 'venue_address1');
		li_v_a1_i.setAttribute('id', 'venue_address1');
		li_v_a1_i.setAttribute('size', 15);

		li_v_a1.appendChild(li_v_a1_l);
		li_v_a1.appendChild(li_v_a1_i);

		ul.appendChild(li_v_a1);


		// Create Venue Address 2 list item
		li_v_a2 = document.createElement('li');
		li_v_a2.setAttribute('id', 'l_venue_address2');
		li_v_a2.style.display="none";

		li_v_a2_l = document.createElement('label');
		li_v_a2_l.setAttribute('for', 'venue_address2');
		li_v_a2_l.appendChild(document.createTextNode('Address 2'));

		li_v_a2_i = document.createElement('input');
		li_v_a2_i.setAttribute('type', 'text');
		li_v_a2_i.setAttribute('name', 'venue_address2');
		li_v_a2_i.setAttribute('id', 'venue_address2');
		li_v_a2_i.setAttribute('size', 15);

		li_v_a2.appendChild(li_v_a2_l);
		li_v_a2.appendChild(li_v_a2_i);

		ul.appendChild(li_v_a2);


		// Create Venue Address 3 list item
		li_v_a3 = document.createElement('li');
		li_v_a3.setAttribute('id', 'l_venue_address3');
		li_v_a3.style.display="none";

		li_v_a3_l = document.createElement('label');
		li_v_a3_l.setAttribute('for', 'venue_address3');
		li_v_a3_l.appendChild(document.createTextNode('Address 3'));

		li_v_a3_i = document.createElement('input');
		li_v_a3_i.setAttribute('type', 'text');
		li_v_a3_i.setAttribute('name', 'venue_address3');
		li_v_a3_i.setAttribute('id', 'venue_address3');
		li_v_a3_i.setAttribute('size', 15);

		li_v_a3.appendChild(li_v_a3_l);
		li_v_a3.appendChild(li_v_a3_i);

		ul.appendChild(li_v_a3);


		// Create Venue Post Code list item
		li_v_pc = document.createElement('li');
		li_v_pc.setAttribute('id', 'l_venue_postcode');
		li_v_pc.style.display="none";

		li_v_pc_l = document.createElement('label');
		li_v_pc_l.setAttribute('for', 'venue_postcode');
		li_v_pc_l.appendChild(document.createTextNode('Post Code'));

		li_v_pc_i = document.createElement('input');
		li_v_pc_i.setAttribute('type', 'text');
		li_v_pc_i.setAttribute('name', 'venue_postcode');
		li_v_pc_i.setAttribute('id', 'venue_postcode');
		li_v_pc_i.setAttribute('size', 15);

		li_v_pc.appendChild(li_v_pc_l);
		li_v_pc.appendChild(li_v_pc_i);

		ul.appendChild(li_v_pc);

		// Create submit button
		li_submit = document.createElement('li');
		li_submit.setAttribute('className', 'button');

		li_submit_inp = document.createElement('input');
		li_submit_inp.setAttribute('type', 'submit');
		li_submit_inp.setAttribute('value', 'Next');
		li_submit_inp.onclick = function() {
					return rs.checkForm();
				}

		li_submit.appendChild(li_submit_inp);

		ul.appendChild(li_submit);

		
		rd.appendChild(legend);
		rd.appendChild(ul);

		$('indicator').hide();
	}

	this.addEventSearchForm = function() {
		$('indicator').show();

		var rd = $('review-details');

		var legend = document.createElement('legend');
		var legend_text = document.createTextNode('Event Search');
		legend.appendChild(legend_text);

		var ul = document.createElement('ul');

		// Create Description item
		var li_d = document.createElement('li');
		var li_d_t = document.createTextNode('Enter details of the event you wish to review below.');
		li_d.appendChild(li_d_t);
		ul.appendChild(li_d);

		var li_date = document.createElement('li');
		var li_date_label = document.createElement('label');
		var li_date_label_text = document.createTextNode('Date:');
		li_date_label.appendChild(li_date_label_text);

		li_date.appendChild(li_date_label);


		var today = new Date();


		// add date drop down
		var day_select = document.createElement('select');
		day_select.setAttribute('id', 'event_day');
		day_select.setAttribute('name', 'event_day');

		for (i=1; i<=31; i++) {
			var day_select_option = document.createElement('option');

			day_select_option.setAttribute('value', i);
			var day_select_text = document.createTextNode(i);
			day_select_option.appendChild(day_select_text);

			if (today.getDate() == i) day_select_option.setAttribute('selected', '1');

			day_select.appendChild(day_select_option);
		}

		li_date.appendChild(day_select);

		// add month drop down
		var month_select = document.createElement('select');
		month_select.setAttribute('id', 'event_month');
		month_select.setAttribute('name', 'event_month');

		var months = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
		for (i=0; i<months.length; i++) {
			month = i + 1;

			var month_select_option = document.createElement('option');

			month_select_option.setAttribute('value', month);
			var month_select_text = document.createTextNode(months[i]);
			month_select_option.appendChild(month_select_text);

			if (today.getMonth() == i) month_select_option.setAttribute('selected', '1');

			month_select.appendChild(month_select_option);
		}

		li_date.appendChild(month_select);

		// add year drop down
		var year_select = document.createElement('select');
		year_select.setAttribute('id', 'event_year');
		year_select.setAttribute('name', 'event_year');

		for (i=2007; i<=2007+10; i++) {
			var year_select_option = document.createElement('option');

			year_select_option.setAttribute('value', i);
			var year_select_text = document.createTextNode(i);
			year_select_option.appendChild(year_select_text);

			if (today.getFullYear() == i) year_select_option.setAttribute('selected', '1');

			year_select.appendChild(year_select_option);
		}

		li_date.appendChild(year_select);

		ul.appendChild(li_date);


		// add time li
		var li_time = document.createElement('li');

		// add time label
		var li_time_label = document.createElement('label');
		var li_time_label_text = document.createTextNode('Time:');
		li_time_label.appendChild(li_time_label_text);

		li_time.appendChild(li_time_label);

		// add hour drop down
		var hour_select = document.createElement('select');
		hour_select.setAttribute('id', 'event_hour');
		hour_select.setAttribute('name', 'event_hour');

		var hour_blank = document.createElement('option');
		var hour_blank_text = document.createTextNode('-');
		hour_blank.appendChild(hour_blank_text);
		hour_select.appendChild(hour_blank);

		for (i=1; i<=23; i++) {
			var hour_select_option = document.createElement('option');

			if (i < 10) h = '0'+i;
			else h = i

			hour_select_option.setAttribute('value', h);
			var hour_select_text = document.createTextNode(h);
			hour_select_option.appendChild(hour_select_text);

			hour_select.appendChild(hour_select_option);
		}

		li_time.appendChild(hour_select);

		// add minute drop down
		var minute_select = document.createElement('select');
		minute_select.setAttribute('id', 'event_minute');
		minute_select.setAttribute('name', 'event_minute');

		var minute_blank = document.createElement('option');
		var minute_blank_text = document.createTextNode('-');
		minute_blank.appendChild(minute_blank_text);
		minute_select.appendChild(minute_blank);

		for (i=0; i<=55; i=i+5) {
			var minute_select_option = document.createElement('option');

			if (i < 10) m = '0'+i;
			else m = i;

			minute_select_option.setAttribute('value', m);
			var minute_select_text = document.createTextNode(m);
			minute_select_option.appendChild(minute_select_text);

			minute_select.appendChild(minute_select_option);
		}

		li_time.appendChild(minute_select);

		ul.appendChild(li_time);

		// add venue li
		var li_venue = document.createElement('li');

		// add venue label
		var li_venue_label = document.createElement('label');
		var li_venue_label_text = document.createTextNode('Venue Name:');
		li_venue_label.setAttribute('for', 'venue_name');
		li_venue_label.appendChild(li_venue_label_text);

		li_venue.appendChild(li_venue_label);

		var venue_input = document.createElement('input');
		venue_input.setAttribute('id', 'venue_name');
		venue_input.setAttribute('name', 'venue_name');

		li_venue.appendChild(venue_input);

		ul.appendChild(li_venue);


		// Create submit button
		li_submit = document.createElement('li');
		li_submit.setAttribute('className', 'button');

		li_submit_inp = document.createElement('input');
		li_submit_inp.setAttribute('type', 'submit');
		li_submit_inp.setAttribute('value', 'Search');
		li_submit_inp.onclick = function() {
					return rs.eventSearch();
				}

		li_submit.appendChild(li_submit_inp);

		ul.appendChild(li_submit);

		rd.appendChild(legend);
		rd.appendChild(ul);

		$('indicator').hide();
	}

	this.eventSearch = function() {
		$('indicator').show();

		var event_day = $('event_day');
		var day = event_day.options[event_day.selectedIndex].value;

		var event_month = $('event_month');
		var month = event_month.options[event_month.selectedIndex].value;

		var event_year = $('event_year');
		var year = event_year.options[event_year.selectedIndex].value;

		var event_hour = $('event_hour');
		var hour = event_hour.options[event_hour.selectedIndex].value;

		var event_minute = $('event_minute');
		var minute = event_minute.options[event_minute.selectedIndex].value;

		var venue_name = escape($('venue_name').value);


		var params = 'ajax=eventsearch&day='+day+'&month='+month+'&year='+year+'&hour='+hour+'&minute='+minute+'&venue_name='+venue_name;

		var myAjax = new Ajax.Request('/add/', {method: 'get', parameters: params, onComplete: rs.displayEventResults});

		return false;
	}

	this.displayEventResults = function(r) {
		var events = eval('(' + r.responseText + ')');

		var fs = $('event-search-results');

		if (fs) {
			var p = fs.parentNode;

			p.removeChild(fs);
		}

		// Create new fieldset
		var fs = document.createElement('fieldset');
		fs.setAttribute('id', 'event-search-results');
		fs.setAttribute('class', 'form');

		var legend = document.createElement('legend');
		var legend_text = document.createTextNode('Event Search Results');

		legend.appendChild(legend_text);
		fs.appendChild(legend);

		// Create Table
		var t = document.createElement('table');
		t.setAttribute('cellspacing', 0);
		t.setAttribute('cellpadding', 0);
		t.setAttribute('border', 0);

		// Create head
		var thead = document.createElement('thead');

		// create time header
		var th_time = document.createElement('th');
		var th_time_text = document.createTextNode('Date & Time');
		th_time.setAttribute('class', 'time');
		th_time.appendChild(th_time_text);

		thead.appendChild(th_time);

		// create details header
		var th_details = document.createElement('th');
		var th_details_text = document.createTextNode('Event');
		th_details.setAttribute('class', 'details');
		th_details.appendChild(th_details_text);

		thead.appendChild(th_details);

		// create venue header
		var th_venue = document.createElement('th');
		var th_venue_text = document.createTextNode('Venue');
		th_venue.setAttribute('class', 'venue');
		th_venue.appendChild(th_venue_text);

		thead.appendChild(th_venue);

		// create select header
		var th_review = document.createElement('th');
		var th_review_text = document.createTextNode('Review?');
		th_review.setAttribute('class', 'review');
		th_review.appendChild(th_review_text);

		thead.appendChild(th_review);
		t.appendChild(thead);

		// Create tbody
		var tbody = document.createElement('tbody');

		if (events.length > 0) {
			// Create row for each search result

			for (i=0; i<events.length; i++) {
				var tr = document.createElement('tr');

				// create time cell
				var td_time = document.createElement('td');
				var td_time_text = document.createTextNode(events[i].event_shortdate);
				td_time.setAttribute('class', 'time');
				td_time.appendChild(td_time_text);

				tr.appendChild(td_time);

				// create details cell
				var td_details = document.createElement('td');
				var td_details_text = document.createTextNode(events[i].event_title);
				td_details.appendChild(td_details_text);

				tr.appendChild(td_details);

				// create venue cell
				var td_venue = document.createElement('td');
				var td_venue_text = document.createTextNode(events[i].venue_name);
				td_venue.setAttribute('class', 'venue');
				td_venue.appendChild(td_venue_text);

				tr.appendChild(td_venue);


				// create select cell
				var td_review = document.createElement('td');

				var radio_event = document.createElement('input');
				radio_event.setAttribute('type', 'radio');
				radio_event.setAttribute('name', 'event_id');
				radio_event.setAttribute('id', 'event_id_' + i);
				radio_event.setAttribute('value', events[i].event_id);

				radio_event.className='event_radios';

				radio_event.onclick = function() {
					var inputs = document.getElementsByClassName('event_radios');

					for (i=0; i<inputs.length; i++) {
						inputs[i].checked = 0;
					}

					this.checked = 1;
				}

				td_review.setAttribute('class', 'details');
				td_review.appendChild(radio_event);

				tr.appendChild(td_review);

				tbody.appendChild(tr);
			}

			var tr_submit = document.createElement('tr');

			// add submit button
			var td_submit = document.createElement('td');
			td_submit.setAttribute('class', 'button');

			var submit_button = document.createElement('input');
			submit_button.setAttribute('type', 'submit');
			submit_button.setAttribute('name', 'submit');
			submit_button.setAttribute('value', 'Review Event');

			submit_button.onclick = function() {
				return rs.checkForm();
			}

			td_submit.appendChild(submit_button);
			tr_submit.appendChild(td_submit);
			tbody.appendChild(tr_submit);			
		}
		else {
			// display 'no results'
			var tr = document.createElement('tr');

			// create time cell
			var td = document.createElement('td');
			var td_text = document.createTextNode('Your search has returned no results.');
			td.setAttribute('colspan', 4);
			td.setAttribute('id', 'no-results');
			td.appendChild(td_text);

			tr.appendChild(td);
			tbody.appendChild(tr);
		}

		t.appendChild(tbody);

		fs.appendChild(t);


		var rd = $('review-details');
		var p = rd.parentNode;

		p.appendChild(fs);

		$('indicator').hide();
	}


	this.addBandSearchForm = function() {
		$('indicator').show();

		var rd = $('review-details');

		var legend = document.createElement('legend');
		var legend_text = document.createTextNode('Band Search');
		legend.appendChild(legend_text);

		var ul = document.createElement('ul');

		// Create Description item
		var li_d = document.createElement('li');
		var li_d_t = document.createTextNode('Enter details of the band you wish to review below.');
		li_d.appendChild(li_d_t);
		ul.appendChild(li_d);


		// add band li
		var li_band = document.createElement('li');

		// add band label
		var li_band_label = document.createElement('label');
		var li_band_label_text = document.createTextNode('Band Name:');
		li_band_label.setAttribute('for', 'band_name');
		li_band_label.appendChild(li_band_label_text);

		li_band.appendChild(li_band_label);

		var band_input = document.createElement('input');
		band_input.setAttribute('id', 'band_name');
		band_input.setAttribute('name', 'band_name');

		li_band.appendChild(band_input);

		ul.appendChild(li_band);


		// Create submit button
		li_submit = document.createElement('li');
		li_submit.setAttribute('className', 'button');

		li_submit_inp = document.createElement('input');
		li_submit_inp.setAttribute('type', 'submit');
		li_submit_inp.setAttribute('value', 'Search');
		li_submit_inp.onclick = function() {
					return rs.bandSearch();
				}

		li_submit.appendChild(li_submit_inp);

		ul.appendChild(li_submit);

		rd.appendChild(legend);
		rd.appendChild(ul);

		$('indicator').hide();
	}

	this.bandSearch = function() {
		var band_name = escape($('band_name').value);

		if (band_name != "") {
			$('indicator').show();

			var params = 'ajax=bandsearch&band_name='+band_name;
			var myAjax = new Ajax.Request('/add/', {method: 'get', parameters: params, onComplete: rs.displayBandResults});
		}

		return false;
	}



	this.displayBandResults = function(r) {
		var bands = eval('(' + r.responseText + ')');

		var fs = $('band-search-results');

		if (fs) {
			var p = fs.parentNode;

			p.removeChild(fs);
		}

		// Create new fieldset
		var fs = document.createElement('fieldset');
		fs.setAttribute('id', 'band-search-results');
		fs.setAttribute('class', 'form');

		var legend = document.createElement('legend');
		var legend_text = document.createTextNode('Band Search Results');

		legend.appendChild(legend_text);
		fs.appendChild(legend);

		// Create Table
		var ul = document.createElement('ul');


		if (bands.length > 0) {
			// Create row for each search result
			for (i=0; i<bands.length; i++) {
				// add li
				var li = document.createElement('li');

				// Add img
				var img = document.createElement('img');
				img.setAttribute('src', bands[i].avatar);
				img.setAttribute('alt', bands[i].band_name);
				img.setAttribute('border', 0);

				li.appendChild(img);


				// create review input div
				var d = document.createElement('div');
				//d.setAttribute('class', 'reviewinput');
				d.className = 'reviewinput';

				var di = document.createElement('input');
				di.setAttribute('type', 'radio');
				di.setAttribute('name', 'band_id');
				di.setAttribute('value', bands[i].band_id);
				di.className = 'band_radios';

				if (i==0) di.checked = 1;

				di.onclick = function() {
					var inputs = document.getElementsByClassName('band_radios');

					for (i=0; i<inputs.length; i++) {
						inputs[i].checked = 0;
					}

					this.checked = 1;
				}



				d.appendChild(di);

				li.appendChild(d);


				// add band name
				var name = document.createElement('span');
				//name.setAttribute('class', 'band_name');
				name.className='band_name';
				name_text = document.createTextNode(bands[i].band_name);
				name.appendChild(name_text);

				li.appendChild(name);


				// add band information
				var info = document.createElement('span');
				//info.setAttribute('class', 'information');
				info.className='information';

				info_text = document.createTextNode(bands[i].information);
				info.appendChild(info_text);

				li.appendChild(info);
				

				ul.appendChild(li);
			}


			// add submit button
			var li_submit = document.createElement('li');
			//li_submit.setAttribute('class', 'button');
			li_submit.className = 'button';

			var submit_button = document.createElement('input');
			submit_button.setAttribute('type', 'submit');
			submit_button.setAttribute('name', 'submit');
			submit_button.setAttribute('value', 'Review Band');

			submit_button.onclick = function() {
				return rs.checkForm();
			}

			li_submit.appendChild(submit_button);
			ul.appendChild(li_submit);
		}
		else {
			// create time cell
			var li = document.createElement('li');
			var li_text = document.createTextNode('Your search has returned no results.');
			li.setAttribute('id', 'no-results');
			li.appendChild(li_text);

			ul.appendChild(li);
		}


		fs.appendChild(ul);

		var rd = $('review-details');
		var p = rd.parentNode;

		p.appendChild(fs);

		$('indicator').hide();
	}

	this.checkForm = function() {
		var error = 0;
		var type = $('type');

		var type_code = type.options[type.selectedIndex].value;

		if (type_code == 1) {
			error = 1;
			var inputs = document.getElementsByClassName('event_radios');

			for (i=0; i<inputs.length; i++) {
				if (inputs[i].checked == 1) {
					error = 0;
					break;
				}
			}
		}
		else if (type_code == 2) {
			var venue_type_e = $('venue_type_e');
			var venue_type_n = $('venue_type_n');


			if (venue_type_n.checked) {
				var v_name = $('venue_name');
				var v_address1 = $('venue_address1');
				var v_postcode = $('venue_postcode');

				if (v_name.value == "") {
					error = 1;
					v_address1.setAttribute('class', 'required');
				}
				else if (v_address1.value == "") {
					error = 1;
					v_address1.setAttribute('class', 'required');
				}
				else if (v_postcode.value == "") {
					error = 1;
					v_postcode.setAttribute('class', 'required');
				}
			}
		}
		else if (type_code == 3) {
			error = 1;
			var inputs = document.getElementsByClassName('band_radios');

			for (i=0; i<inputs.length; i++) {
				if (inputs[i].checked == 1) {
					error = 0;
					break;
				}
			}
		}
		else if (type_code == 4) {
			// album
		}

		var errormsg = $('validation-error');

		if (error == 1) {
			if (typeof errormsg == "undefined") {
				// Create Error
				var error = document.createElement('div');
				error.setAttribute('id', 'validation-error');
				error.setAttribute('class', 'error');

				var error_text = document.createTextNode('You have not entered all required fields');

				error.appendChild(error_text);

				var rd = $('review-details');
				rd.insertBefore(error, rd.firstChild);

			}

			return false;
		}
		else {
			if (errormsg) {
				var p = errormsg.parentNode;
				p.removeChild(errormsg);
			}

			return true;
		}
	}

}

