var whoami = "student";

function set_whoami() {
	var select = document.getElementById('whoami');
	whoami = select.options[select.selectedIndex].value;
	
	
	if (whoami == "student" || whoami == "educator") {
//		$('#reg_school').show();
		$('#reg_school .school_label strong').text('School Name');
		$('#reg_address .address_label strong').text('Home Address');
		$('#reg_phone strong').text('Home Phone');
		$('#part2_next').show();
		
	} else if (whoami == "legislator" || whoami == "business") {
//		$('#reg_school').hide();
		$('#reg_school .school_label strong').text('Business Name');
		$('#reg_address .address_label strong').text('Business Address');
		$('#reg_phone strong').text('Phone');
		$('#part2_next').hide();	
	}
	
}

function open_section(section) {
	$('#' + section).show('normal');
}
function close_section(section) {
	$('#' + section).hide('normal');
}

function go(section) {

	if (section == "part3") {
		if (!validatePart2()) {
			return false;
		}
	}

	// close the previous section
	if (section == "part2") {
		close_section("part1");
	} else if (section == "part3") {
		close_section("part2");
	}
	
	// now open this one
	open_section(section);
	
	// show the submit button at the right time
	if (whoami == "legislator" || whoami == "business") {
		if (section == "part2") {
			open_section('submit');
		}
	} else if (whoami == "student" || whoami == "educator") {
		if (section == "part3") {
			open_section('submit');
		}
	}

}

function checkSessionValue(value) {
	var s = document.getElementsByName('session[' + value + ']');
	s = s[0];
	if (s.checked) {
		return true;
	} else {
		return false;
	}
}

function validatePart2() {
	var F = document.forms['reg_form'];

	var msg = new Array();

	if (F.first_name.value == "" || F.first_name.value == "First") {
		msg.push('You must enter a first name.');
	}
	if (F.last_name.value == "" || F.last_name.value == "Last") {
		msg.push('You must enter a last name.');
	}
	if (F.business.value == "") {
		msg.push('You must enter an organization name.');
	}
	if (F.address_1.value == "") {
		msg.push('You must enter an address.');
	}
	if (F.city.value == "" || F.city.value == "City") {
		msg.push('You must enter a city.');
	}
	if (F.state.value == "" || F.state.value == "ST") {
		msg.push('You must enter a state.');
	}
	if (F.zip.value == "" || F.zip.value == "Zip") {
		msg.push('You must enter a zip code.');
	}
	if (F.phone_area.value == "") {
		msg.push('You must enter an area code.');
	}
	if (F.phone_mid.value == "" || F.phone_end.value == "") {
		msg.push('You must enter a phone number.');
	}
	if (F.email.value == "") {
		msg.push('You must enter an email address.');
	}
	// SESSION
	// session, at least one, please
	var session_checked = 0;
	if (checkSessionValue('lunch')) { session_checked++; }
	if (checkSessionValue('afternoon')) { session_checked++; }
	if (session_checked == 0) {
		msg.push('You must select at least one session.');
	}	
	// END SESSION
	
	
	if (msg.length) {
		// we have problems
		var html = '<div id="errors">Errors:<ul>';
		for (var i = 0; i < msg.length; i++) {
			var m = msg[i];
			html += "<li>" + m + "</li>\n";
		}
		html += "</ul></div>";
		
		$('#messages').html(html);
			
		return false;
	}
	else {
		// no problems
		$('#messages').html("");
			
		return true;
	}

}