	
hideReq();	

/* sniff the broswer for IE ineptness, yeah it is not the "proper" way 
but this gets results on a page that must display these results regardless of browser quirkyness 
the following checks for IE 6+ */
var isIE = false;
if (document.compatMode && document.all) {
	isIE = true;
}


var ret = true;
var formObj = document.contactForm;
var msg = "The following errors have occurred \n\n";
	
function showExtras() {
	hideReq();
	var pub = document.getElementById("publish");
	var res = document.getElementById("response");
	var topic = document.getElementById("reason");
	var addr = document.getElementById("addressRow");
	var city = document.getElementById("cityRow");
	var state = document.getElementById("stateRow");
	var zip = document.getElementById("zipRow");
	var topicSI = topic.options[topic.selectedIndex].value;
	
	if (topicSI == 1)
	{
		showComplaintReq();
		showCommendationReq();
		res.style.visibility = "visible";
		pub.style.display = "none";
		addr.style.display = "none";
		city.style.display = "none";
		state.style.display = "none";
		zip.style.display = "none";
	}
	if (topicSI == 3)
	{
		showCommendationReq();
		if (isIE) {
			pub.style.display = "inline";
			addr.style.display = "inline";
			city.style.display = "inline";
			state.style.display = "inline";
			zip.style.display = "inline";
		} else {
			pub.style.display = "table-row";
			addr.style.display = "table-row";
			city.style.display = "table-row";
			state.style.display = "table-row";
			zip.style.display = "table-row";	
		}
		res.style.visibility = "hidden";
	}
	if (topicSI == 2)
	{
		showSuggestionReq();
		pub.style.display = "none";
		addr.style.display = "none";
		city.style.display = "none";
		state.style.display = "none";
		zip.style.display = "none";
		res.style.visibility = "hidden";
	}
	if (topicSI == 0)
	{
		pub.style.display = "none";
		addr.style.display = "none";
		city.style.display = "none";
		state.style.display = "none";
		zip.style.display = "none";
		res.style.visibility = "hidden";
	}
}

function validateContactForm() {

	initMsg();
		
	var topic = document.getElementById("reason");
	var topicSI = topic.options[topic.selectedIndex].value;
	
	if (topicSI == 0)
	{
		msg += "You must select the subject. \n";
		ret = false;
		
		dispErrors();
	}
	
	if (topicSI == 1)
	{
		validateComplaint();
		validateCommendation();
		dispErrors();
	}
	
	if (topicSI == 2)
	{
		validateSuggestion();
		dispErrors();
	}
	
	if (topicSI == 3)
	{
		validateCommendation();
		dispErrors();
	}

}

function initMsg() {
	ret = true;
	msg = '';
	msg = "The following errors have occurred \n\n";
}

function dispErrors() {
	if (ret == false)
	{
		alert(msg);
		return false;
	} else {
		document.contactForm.submit();
	}
}

function validateSuggestion() {
	if (validEmail(formObj.Email.value) == false)
	{
		msg += "Your Email address is required. \n";
		ret = false;
	}
	
	if (formObj.RouteNumber.value == "")
	{
		msg += "The route number is required. \n";
		ret = false;
	}
	return ret;
}

function validateComplaint() {
	if (formObj.Name.value == "")
	{
		msg += "Name is required. \n";
		ret = false;
	}
	
	if (validEmail(formObj.Email.value) == false)
	{
		msg += "Your Email address is required. \n";
		ret = false;
	}
	
	if (formObj.DaytimePhone.value == "")
	{
		msg += "Your daytime phone number is required. \n";
		ret = false;
	}
	return ret;
}

function validateCommendation() {
	
	if (formObj.DirectionofTravel.value == "")
	{
		msg += "Direction of travel is required. \n"
		ret = false;
	}
	
	if (formObj.RouteNumber.value == "")
	{
		msg += "Route number is required. \n";
		ret = false;
	}
	
	if (formObj.BoardingLocation.value == "")
	{
		msg += "Boarding location is required. \n";
		ret = false;
	}
	
	if (formObj.OccurredDate.value == "")
	{
		msg += "Occurrence Date is required. \n";
		ret = false;
	}
	
	if (formObj.OccurrenceTime.value == "")
	{
		msg += "Occurrence Time is required. \n";
		ret = false;
	}
	
	if (formObj.OccurrenceLocation.value == "")
	{
		msg += "Occurrence Location is required. \n";
		ret = false;
	}
	return ret;
}

function hideReq() {
	document.getElementById("nameAst").style.visibility = "hidden";
	document.getElementById("emailAst").style.visibility = "hidden";
	document.getElementById("phoneAst").style.visibility = "hidden";
	document.getElementById("dirTravAst").style.visibility = "hidden";
	document.getElementById("routeNumAst").style.visibility = "hidden";
	document.getElementById("boardLocAst").style.visibility = "hidden";
	document.getElementById("occDateAst").style.visibility = "hidden";
	document.getElementById("occTimeAst").style.visibility = "hidden";
	document.getElementById("occLocAst").style.visibility = "hidden";
}

function showComplaintReq() {
	document.getElementById("nameAst").style.visibility = "visible";
	document.getElementById("emailAst").style.visibility = "visible";
	document.getElementById("phoneAst").style.visibility = "visible";
}

function showCommendationReq() {
	document.getElementById("dirTravAst").style.visibility = "visible";
	document.getElementById("routeNumAst").style.visibility = "visible";
	document.getElementById("boardLocAst").style.visibility = "visible";
	document.getElementById("occDateAst").style.visibility = "visible";
	document.getElementById("occTimeAst").style.visibility = "visible";
	document.getElementById("occLocAst").style.visibility = "visible";
}

function showSuggestionReq() {
	document.getElementById("emailAst").style.visibility = "visible";
	document.getElementById("routeNumAst").style.visibility = "visible";
}


function validEmail(emailAddr) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailAddr)){
		return true;
	} else {
		return false;
	}
}
