var browser = ""; // Will hold string code for browser


// if Mozilla-compliant
if (document.getElementById)
{
	browser = "mozilla";
}
// if IE 4
else if (document.all)
{
	browser = "ie4";
}
// if N 4
else if (document.layers)
{
	browser = "n4";
}
else
{
	browser = "other";
}


function verify()
{

	var signupForm;
	if (browser == "mozilla") // Mozilla-compliant, determined in rotateImages.js
	{
		signupForm = document.getElementById("signup");
	}
	if (browser == "ie4") // Internet Explorer 4, determined in rotateImages.js
	{
		signupForm = document.all.signup;
	}
	else
	{
		signupForm = document.signup;
	}
	
	var verifyMsg;
	
	verifyMsg = verifyInfo(signupForm);
		if (verifyMsg == "")
		{
			signupForm.submit();
		}
	else
	{
		alert('The signup form can not be submitted with the information you provided:\n' + verifyMsg);
	}
	
}

function verifyInfo(htmlForm)
{
	var returnString = "";

/*
//	Developing debugging: list out input values
	var valueReport = "firstName: " + htmlForm.elements['firstName'].value + "\n";
	valueReport += "lastName: " + htmlForm.elements['lastName'].value + "\n";
	...
	
//	alert(valueReport);
*/

//  Validate name and orgo
	var stringStripped = htmlForm.elements['firstName'].value.replace(/\s/, '');
	if (stringStripped.length == 0)
	{
		returnString += "\nYou did not enter your first name.";
		htmlForm.elements['firstName'].value = "";
	}
	
	stringStripped = htmlForm.elements['lastName'].value.replace(/\s/, '');
	if (stringStripped.length == 0)
	{
		returnString += "\nYou did not enter your last name.";
		htmlForm.elements['lastName'].value = "";
	}
	
	stringStripped = htmlForm.elements['organization'].value.replace(/\s/, '');
	if (stringStripped.length == 0)
	{
		returnString += "\nYou did not enter the name of your organization.";
		htmlForm.elements['organization'].value = "";
	}

//	Validate email address
	stringStripped = htmlForm.elements['email'].value.replace(/\s/, '');
	var emailFilter=/^.+@.+\..{2,3}$/;
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	
	if (stringStripped.length == 0)
	{
		returnString += "\nYou did not enter your email.";
		htmlForm.elements['email'].value = "";
	}	
	else if (!(emailFilter.test(htmlForm.elements['email'].value))) { 
	      returnString += "\nThe email address you entered does not appear to be valid. Please check it.";
	}
	else if (htmlForm.elements['email'].value.match(illegalChars)) {
	    returnString += "\nThe email address you entered contains illegal characters.";
	}

//	Validate Phone Number

	//strip out acceptable non-numeric characters
	stringStripped = htmlForm.elements['phone'].value.replace(/\s/, '');
	var stripped = htmlForm.elements['phone'].value.replace(/[\(\)\.\-\ \+]/g, '');
	if (stringStripped.length == 0)
	{
		returnString += "\nYou did not enter your phone number.";
		htmlForm.elements['phone'].value = "";
	}	
	else if (stripped.length < 10) // Too short
	{
		returnString += "\nThe phone number you entered appears to be too short to be valid. Did you include your area code?";
	}
	
		
	return returnString;
}


	