// Charlotte Reach 2010 JavaScript document

//copyright 2003 Hexstream Media


//redirection script
var ie5 = (document.all && document.getElementById);
var w3c = (!document.all && document.getElementById);
var safari = navigator.userAgent.indexOf('Safari');
var mac = navigator.userAgent.indexOf('Mac'); 
var IE = navigator.userAgent.indexOf('MSIE');
var macIE = (mac != -1) && (IE != -1);

if(ie5 && (mac == -1)){}
else if(macIE){}
else if(w3c){}
else{window.location.href="nonStandard.htm";}
	
//setDimensions resizes content to fit in window without scrollbars
function setDimensions() {
	//captures the height
	function liveHeight() {
		if (window.innerHeight != null)
			return window.innerHeight; 
		if (document.body.clientHeight != null)
			return document.body.clientHeight;
		return (null);
		}
		
	var header = 110;
	var footer = 20;
	var difference = header + footer;
	//sets the height of the divider cell
	var dividerHeight = liveHeight() - difference;
	document.getElementById('footerCell').style.height = footer;
	document.getElementById('contentCell').style.height = dividerHeight;
}

//validation script
// onsubmit return value
var returnVal;

function validate(){
	var first = document.moreInfo.firstName.value;
	var last = document.moreInfo.lastName.value;
	var street = document.moreInfo.address.value;
	var city = document.moreInfo.city.value;
	var zip = document.moreInfo.zip.value;
	var email = document.moreInfo.email.value;
	var textBox = document.moreInfo.howInfo.value;
	var firstMes;
	var lastMes;
	var streetMes;
	var cityMes;
	var zipMes;
	var textBoxMes;	
	var emailMes;
	var flag = 0;
	var error = new Array();
	
	if((first.length < 1) || (isNaN(first) == false)){
	 firstMes = "You must enter a valid first name.";
	 error.push(firstMes);
	 flag = 1;
	}
	if((last.length < 1) || (isNaN(last) == false)){
	 lastMes = "You must enter a valid last name.";
	 error.push(lastMes);
	 flag = 1;
	}	
	if(street.length < 2){
	 streetMes = "You must enter a valid address.";
	 error.push(streetMes);
	 flag = 1;
	}	
	if((city.length < 1) || (isNaN(city) == false)){
	 cityMes = "You must enter a valid city name";
	 error.push(cityMes);
	 flag = 1;
	}	
	if((zip.length < 5) || (isNaN(zip) == true)){
	 zipMes = "You must enter a valid zipcode.";
	 error.push(zipMes);
	 flag = 1;
	}	
	if((email.indexOf("@") == -1) || (email.charAt(0) == "@") || (email.indexOf(".") == -1) || (email.charAt(0) == ".") ||(email.length < 6) || (email.charAt(email.indexOf("@")+1) == ".") || (email.charAt(email.indexOf("@")-1) == ".")){
	 emailMes = "You must enter a valid email address.";
	 error.push(emailMes);
	 flag = 1;
	}	
	if((textBox.length < 2)|| (isNaN(textBox) == false)){
	 textBoxMes = "You must enter a valid response as to how you heard of Reach 2010.";
	 error.push(textBoxMes);
	 flag = 1;
	}	

	if(flag == 1){
		errorString =error.join('\r\n');
		alert(errorString);
		returnVal = false;
	}
	else{returnVal = true;}	
}
