function checkForm(theForm) {
 
 	var why = "";  
    
    if ( document.getElementById('contact-form') ) {
    
  
    
		why += checkText(theForm.firstname.value, "your first name.");
		why += checkText(theForm.lastname.value, "your last name.");
		why += checkText(theForm.company.value, "a company.");
		why += checkText(theForm.title.value, "a title.");
		why += checkText(theForm.address.value, "an address.");
		why += checkText(theForm.city.value, 'a city');
		why += checkText(theForm.phone_day.value, 'a valid phone number');
		why += checkText(theForm.state.value, 'state'); 
		why += checkSelect(theForm.industry.value, 'industry'); 
		why += checkSelect(theForm.country.value, 'country'); 
		why += checkEmail(theForm.email.value);
	
	}
	
	 if ( document.getElementById('case-form') ) {
   		why += checkText(theForm.firstname.value, "your first name.");
		why += checkText(theForm.lastname.value, "your last name.");
		why += checkEmail(theForm.email.value);
		why += checkSelect(theForm.product.value, "product."); 
		why += checkSelect(theForm.issues.value, "issue.");	
	}
	
	if ( document.getElementById('training-form') ) {
 		why += checkText(theForm.firstname.value, "your name.");
		why += checkText(theForm.company.value, "a company.");
		why += checkEmail(theForm.email.value);
		why += checkText(theForm.email_confirm.value, "a confirmation email address");
		why += checkText(theForm.phone_day.value, 'a contact number');
		why += checkSelect(theForm.course.value, 'course'); 
		
		why += checkDupe(theForm.email.value, theForm.email_confirm.value, "Not matching");
		
	}
	
	if ( document.getElementById('imaging-form') ) {
    
  		why += checkText(theForm.lastname.value, "your first name.");
		why += checkText(theForm.company.value, "a company.");
		why += checkText(theForm.phone_day.value, 'a valid phone number');
		why += checkEmail(theForm.email.value);
		why += checkSelect(theForm.region.value, 'region'); 
		why += checkSelect(theForm.quantity.value, 'quantity'); 
		why += checkSelect(theForm.timeframe.value, 'timeframe'); 
	
	}
	
	if ( document.getElementById('imaging-form-2') ) {
    
  		why += checkText(theForm.lastname.value, "your first name.");
		why += checkText(theForm.company.value, "a company.");
		why += checkText(theForm.phone_day.value, 'a valid phone number');
		why += checkEmail(theForm.email.value);
		why += checkSelect(theForm.quantity.value, 'quantity');
		why += checkSelect(theForm.country.value, 'country');
		why += checkSelect(theForm.timeframe.value, 'timeframe'); 
	
	}
	
	if ( document.getElementById('imaging-download-form') ) {
    
  		why += checkText(theForm.lastname.value, "your first name.");
		why += checkEmail(theForm.email.value);
	
	}
	
	
	 if ( document.getElementById('gartner-form') ) {
    
  
    
		why += checkText(theForm.firstname.value, "your first name.");
		why += checkText(theForm.lastname.value, "your last name.");
		why += checkText(theForm.company.value, "a company.");
		why += checkText(theForm.address.value, "an address.");
		why += checkText(theForm.city.value, 'a city');
		why += checkText(theForm.phone_day.value, 'a valid phone number');
		why += checkText(theForm.state.value, 'state'); 
		why += checkSelect(theForm.industry.value, 'industry'); 
		why += checkSelect(theForm.country.value, 'country'); 
		why += checkEmail(theForm.email.value);
	
	}
	
	if ( document.getElementById('magic-quadrant') ) {
    
  
    
		why += checkText(theForm.firstname.value, "your first name.");
		why += checkText(theForm.lastname.value, "your last name.");
		why += checkText(theForm.company.value, "a company.");
		why += checkText(theForm.title.value, "a title.");
		why += checkText(theForm.address.value, "an address.");
		why += checkText(theForm.city.value, 'a city');
		why += checkText(theForm.phone_day.value, 'a valid phone number');
		why += checkText(theForm.state.value, 'state'); 
		why += checkSelect(theForm.industry.value, 'industry'); 
		why += checkSelect(theForm.country.value, 'country'); 
		why += checkText(theForm.zip.value, 'a zip code');
		why += checkEmail(theForm.email.value);
	
	}
	
	 if ( document.getElementById('process-designer') ) {
    
  
    
		why += checkText(theForm.firstname.value, "your first name.");
		why += checkText(theForm.lastname.value, "your last name.");
		why += checkText(theForm.company.value, "a company.");
		why += checkText(theForm.title.value, "a title.");
		why += checkText(theForm.city.value, 'a city');
		why += checkText(theForm.phone_eve.value, 'a valid phone number');
		why += checkText(theForm.state.value, 'state'); 
		why += checkEmail(theForm.email.value);
	
	}
	
	 if ( document.getElementById('nomination-form') ) {
    
		why += checkText(theForm.lastname.value, "your name.");
		why += checkText(theForm.company.value, "a company.");
		why += checkText(theForm.title.value, "a title.");
		why += checkText(theForm.department.value, 'a department');
		why += checkText(theForm.phone_eve.value, 'a valid phone number');
		why += checkEmail(theForm.email.value);
	
	}
	
	if ( document.getElementById('rewards360-form') ) {
    
		why += checkText(theForm.lastname.value, "your name.");
		why += checkText(theForm.company.value, "a company.");
		why += checkText(theForm.title.value, "a title.");
		why += checkText(theForm.department.value, 'a department');
		why += checkText(theForm.phone_eve.value, 'a valid phone number');
		why += checkEmail(theForm.email.value);
	
	}
	
	if ( document.getElementById('partner-form') ) {
    
		why += checkText(theForm.lastname.value, "your name.");
		why += checkText(theForm.partner_name.value, "a partner name.");
		why += checkText(theForm.phone_eve.value, 'a valid phone number');
		why += checkEmail(theForm.email.value);
		
		why += checkText(theForm.partner_address.value, "a partner address.");
		why += checkText(theForm.value_proposition.value, "a value proposition.");
		why += checkText(theForm.geographical_coverage.value, "a geographical coverage area.");
		why += checkText(theForm.company_size.value, "a company size.");
		why += checkText(theForm.domain_expertise.value, "a doamin expertise.");
		why += checkText(theForm.product_expertise.value, "a product expertise.");
	
	}
	
	if ( document.getElementById('solution-form') ) {
    
		why += checkText(theForm.lastname.value, "your name.");
		why += checkText(theForm.partner_name.value, "a partner name.");
		why += checkText(theForm.partner_solution.value, "a partner solution.");
		why += checkText(theForm.industry.value, "an industry.");
		why += checkText(theForm.phone_eve.value, 'a valid phone number');
		why += checkEmail(theForm.email.value);
		
		why += checkText(theForm.value_proposition.value, "a value proposition.");
		why += checkText(theForm.sales_assets.value, "sales assets.");
		why += checkText(theForm.implementation_assets.value, "implementation assets.");
		why += checkText(theForm.sales_tools.value, "sales tools.");
		why += checkText(theForm.products_utilized.value, "products utilized.");
		why += checkText(theForm.sample_wins.value, "sample wins.");

		
	}
	
	
	 if ( document.getElementById('webinar-form') ) {
    
    	why += checkText(theForm.name.value, "your name.");
		why += checkText(theForm.Company.value, "a company.");
		why += checkText(theForm.JobTitle.value, "a title.");
		why += checkText(theForm.Address.value, 'an address');
		why += checkText(theForm.City.value, "a city.");
		why += checkText(theForm.State.value, 'a state/province');
		why += checkText(theForm.Zip.value, 'a postal code');
		why += checkText(theForm.Country.value, 'a country');
		why += checkText(theForm.Phone.value, 'a valid phone number');
		why += checkEmail(theForm.Email.value);
	
	}
	
	 if ( document.getElementById('seminar-form') ) {
    
    	var chkarray = [	[ 'cm-fo-auhuh', 'seminar date' ] 	];
  		why += checkcheckArray(theForm, chkarray, "Please pick a ");
    
    	why += checkText(theForm.name.value, "your name.");
		why += checkText(theForm.Company.value, "a company.");
		why += checkText(theForm.Title.value, "a title.");
		why += checkText(theForm.Address.value, 'an address');
		why += checkText(theForm.TelephoneNumber.value, 'a valid phone number');
		why += checkEmail(theForm.Email.value);
	
	}
	
	if ( document.getElementById('superannuation-form') ) {
    
    	var chkarray = [	[ 'cm-fo-gjrhh', 'seminar date' ] 	];
  		why += checkcheckArray(theForm, chkarray, "Please pick a ");
    
    	why += checkText(theForm.name.value, "your first ame.");
    	why += checkText(theForm.LastName.value, "your last name.");
		why += checkText(theForm.Company.value, "a company.");
		why += checkText(theForm.JobTitle.value, "a title.");
		why += checkText(theForm.TelephoneNumber.value, 'a valid phone number');
		why += checkEmail(theForm.Email.value);
	
	}
	
	
	if ( document.getElementById('ea-form') ) {
    
  		why += checkText(theForm.lastname.value, "your name.");
		why += checkText(theForm.company.value, "a company.");
		why += checkText(theForm.title.value, "a title.");
		why += checkText(theForm.phone_day.value, 'a valid phone number');
		why += checkEmail(theForm.email.value);
	
	}
	
    if (why != "") {
       alert(why);
       return false;
    }
 
	return true;
}

function checkcheckArray(theForm, chkarray, errorMsg) {
	
	var checkvalue = "";
   	var error = "";
   	
   	for(x=0; x < chkarray.length; x++)
			{
			
				for (i=0, n=theForm[chkarray[x][0]].length; i<n; i++) {
				 if (theForm[chkarray[x][0]][i].checked) {
					  var checkvalue = theForm[chkarray[x][0]][i].value;
					  break;
				   }
				}
				error += checkcheckBox(checkvalue, chkarray[x][1], errorMsg);
			}
			
	return error;
}


function checkcheckBox(checkvalue, fields, errorMsg) {
	var error = "";
	if (!errorMsg) errorMsg = "Pick at least one "
	   if (!(checkvalue)) {
		   error = errorMsg + fields + "\n";
		}
	return error;    
}

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "Please enter a valid email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}

function checkText (strng, formfield) {
 var error = "";
 if (strng == "") {
    error = "Please enter " + formfield + "\n";
 }
 return error;
 }

function checkSelect (strng, formfield) {
 var error = "";
 if (strng == "" || strng == 'choose' ) {
    error = "Please select a " + formfield + "\n";
 }
 return error;
 }

function checkDupe (strng, dupeStrng, formfield) {
 var error = "";
 if (strng != dupeStrng) {
    error = "The email and confirmation email addresses do not match " + "\n";
 }
 return error;
 }


function checkPhone (strng) {
 	
 	var error = "";
 
	if (strng == "") {
	   error = "Please enter a daytime phone number.\n";
	   return error;
	}

 
	var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
	//strip out acceptable non-numeric characters
	
	if (isNaN(parseInt(stripped))) {
	 	error = "The phone number contains illegal characters.";
	 
	}
	
	if (!(stripped.length == 10)) {
		error = "The phone number is not a complete phone number with area code.\n";
	}
 
 	return error;
 }


function checkDropdown(choice, strng) {
    var error = "";
    if (choice == "") {
       error = strng + "\n";
    }    
return error;
}   

function checkRadios(theForm, radioSet, errorMsg) {
	
	var radios = theForm[radioSet];
    var error = "";
	
	for(var y = 0; y < radios.length; y++ ) {
		var isChecked = false;
		if (radios[y].checked) {
		 	return error; // we have one checked! return blank.
		}
	}
	
	if (!isChecked) {
		error = errorMsg + "\n";
	}
	
	return error;
	
}

if( document.getElementById('training-form') ) {
	document.getElementById('training-form').onsubmit = function() { return checkForm(document.getElementById('training-form')) }
}

if( document.getElementById('contact-form') ) {
	document.getElementById('contact-form').onsubmit = function() { return checkForm(document.getElementById('contact-form')) }
}

if( document.getElementById('imaging-buy-form') ) {
	document.getElementById('imaging-buy-form').onsubmit = function() { return checkForm(document.getElementById('imaging-buy-form')) }
}

if( document.getElementById('imaging-download-form') ) {
	document.getElementById('imaging-download-form').onsubmit = function() { return checkForm(document.getElementById('imaging-download-form')) }
}

if( document.getElementById('magic-quadrant') ) {
	document.getElementById('magic-quadrant').onsubmit = function() { return checkForm(document.getElementById('magic-quadrant')) }
}

if( document.getElementById('process-designer') ) {
	document.getElementById('process-designer').onsubmit = function() { return checkForm(document.getElementById('process-designer')) }
}

if( document.getElementById('nomination-form') ) {
	document.getElementById('nomination-form').onsubmit = function() { return checkForm(document.getElementById('nomination-form')) }
}

if( document.getElementById('rewards360-form') ) {
	document.getElementById('rewards360-form').onsubmit = function() { return checkForm(document.getElementById('rewards360-form')) }
}

if( document.getElementById('partner-form') ) {
	document.getElementById('partner-form').onsubmit = function() { return checkForm(document.getElementById('partner-form')) }
}

if( document.getElementById('solution-form') ) {
	document.getElementById('solution-form').onsubmit = function() { return checkForm(document.getElementById('solution-form')) }
}

if( document.getElementById('imaging-form') ) {
	document.getElementById('imaging-form').onsubmit = function() { return checkForm(document.getElementById('imaging-form')) }
}

if( document.getElementById('imaging-form-2') ) {
	document.getElementById('imaging-form-2').onsubmit = function() { return checkForm(document.getElementById('imaging-form-2')) }
}

if( document.getElementById('webinar-form') ) {
	document.getElementById('webinar-form').onsubmit = function() { return checkForm(document.getElementById('webinar-form')) }
}

if( document.getElementById('superannuation-form') ) {
	document.getElementById('superannuation-form').onsubmit = function() { return checkForm(document.getElementById('superannuation-form')) }
}

if( document.getElementById('ea-form') ) {
	document.getElementById('ea-form').onsubmit = function() { return checkForm(document.getElementById('ea-form')) }
}

if( document.getElementById('seminar-form') ) {
	document.getElementById('seminar-form').onsubmit = function() { return checkForm(document.getElementById('seminar-form')) }
}

if( document.getElementById('case-form') ) {
	document.getElementById('case-form').onsubmit = function() { return checkForm(document.getElementById('case-form')) }
}