var inputArray = new Array(8);
var message = "";
var inputFields = new Array(8);
inputFields[0] = "Name";
inputFields[1] = "Email";
inputFields[2] = "Company";
inputFields[3] = "Address";
inputFields[4] = "City";
inputFields[5] = "State";
inputFields[6] = "Phone";
inputFields[7] = "Country";
 

function verifyThis()
{
 	(document.baghouse_caseStudy_download.name.value!='')?inputArray[0]='good':inputArray[0]='bad';
	(document.baghouse_caseStudy_download.email.value!='')?inputArray[1]='good':inputArray[1]='bad';
	(document.baghouse_caseStudy_download.company.value!='')?inputArray[2]='good':inputArray[2]='bad';
	(document.baghouse_caseStudy_download.address.value!='')?inputArray[3]='good':inputArray[3]='bad';
	(document.baghouse_caseStudy_download.city.value!='')?inputArray[4]='good':inputArray[4]='bad';
	(document.baghouse_caseStudy_download.state.value!='')?inputArray[5]='good':inputArray[5]='bad';
	(document.baghouse_caseStudy_download.phone.value!='')?inputArray[6]='good':inputArray[6]='bad';
	(document.baghouse_caseStudy_download.country.options[document.baghouse_caseStudy_download.country.selectedIndex].value!='')?inputArray[7]='good':inputArray[7]='bad';

	var allGood=true;
	for (counter=0;counter<inputArray.length;counter++)
	{
		if (inputArray[counter]!='good')
		{
			message += "\n" + inputFields[counter];
			allGood=false;
		}//end if
	}//end for counter
 	if (allGood)
	{
		changeLocation();
	}
	else
	{
		alert("The following fields have either been left blank or not entered properly:\t\n"+message);
		message="";
	}
		
}//end verifyThis()

function changeLocation()
{
   if (submitIt(document.baghouse_caseStudy_download))	
	{
 		document.baghouse_caseStudy_download.submit();
	}	
}

function validEmail(emailvalue)
{
	var invalidChars="/:,;";
	if (emailvalue!=""){
		for (i=0; i<invalidChars.length; i++) {
			badChar=invalidChars.charAt(i)
			if (emailvalue.indexOf(badChar,0)!= -1) {
				return false;
			}
		}
		atPos=emailvalue.indexOf("@")
		if (atPos==-1){
			return false;
		}
		if (emailvalue.indexOf("@",atPos+1) !=-1) {
			return false;
		}
		periodPos=emailvalue.indexOf(".",atPos)
		if ((periodPos == -1) || (periodPos == (emailvalue.length - 1))) {	   
			return false;	 
		}	 
	} // end of if not equal to blank
	return true;
}

function submitIt(form)
{

	 if (!validEmail(form.email.value)){
	    alert('Invalid email address');
			return false
	 }	
     return true;
}