// CHECKS USER'S EMAIL ADDRESS
function chk_email( str, req )
{
	var email_RegEx = /^\w+([-.]\w+)*\@\w+([-.]\w+)*\.\w+$/;
	if( str.length == 0 && !req )
		return 0;
	var found = email_RegEx.test( str );
	if( found == false ) 
		return 1;
	return 0;
}
// CHECKS VALIDITY OF STRING
function chk_string( str, req, min, max )
{
	if( str.length == 0 && !req )
		return 0;
	var string_RegEx = /^\s+$/;
	if( string_RegEx.test( str ) == true )
		return 1;
	if( str.length < min || str.length > max )
		return 1;
	return 0;
}
// CHECKS VALIDITY OF PHONE NUMBER
// Valid characters are 0-9, (, ), " ", - 
// The phone number must be at least 7 characters long
function chk_phone( str, req )
{
	var phone_RegEx = /^[0-9\+\(\)\-\.\s]{7,}$/;
	if( str.length == 0 && !req )
		return 0;
	var found = phone_RegEx.test( str );
	if( found == false )
		return 1;
	return 0;
}
// Check validity of URL address
function chk_url( str, req )
{
	var url_RegEx = /^(http:\/\/){1}\w+([-]\w+)*\.\w+([-]\w+)*\.\w+\S*[^.]$/;
	if( str.length == 0 && !req )
		return 0;
	var found = url_RegEx.test( str );
	if( found == false )
		return 1;
	return 0;
}
function Capture_OnSubmit()
{
	var ErrorTxt="";
	var ProductCheck="";
	
	if( chk_string( document.contactFormSubmit.Name.value, 1, 3, 50 ) )
		ErrorTxt+="   Name not specified\n";
	
	if( chk_string( document.contactFormSubmit.BusinessName.value, 1, 3, 50 ) )
		ErrorTxt+="   Business Name not specified\n";
		
	if( chk_url( document.contactFormSubmit.WebsiteURL.value, 0 ) )
		ErrorTxt+="   Website URL invalid (e.g. http://www.mysite.com)\n";

	if( chk_string( document.contactFormSubmit.City.value, 1, 2, 50 ) )
		ErrorTxt+="   City must be at least 2 characters\n";
	
	if( document.contactFormSubmit.Country.value == "United States" ) {
		if( document.contactFormSubmit.State.value == "" )
			ErrorTxt+="   State not specified\n";
	}

	if( chk_phone( document.contactFormSubmit.Telephone.value, 1 ) )
		ErrorTxt+="   Telephone number is invalid or incomplete\n";

	if( chk_email( document.contactFormSubmit.EmailAddress.value, 0 ) )
		ErrorTxt+="   Email invalid or not specified\n";
	
	if( document.contactFormSubmit.Products_0.checked )
		ProductCheck="OK";
	if( document.contactFormSubmit.Products_1.checked )
		ProductCheck="OK";
	if( document.contactFormSubmit.Products_2.checked )
		ProductCheck="OK";
	if( document.contactFormSubmit.Products_3.checked )
		ProductCheck="OK";
	if( ProductCheck != "OK" )
		ErrorTxt+="   Products of Interest not specified\n";
	
/*	if( document.contactFormSubmit.Products_0.checked && document.contactFormSubmit.Products_1.checked && document.contactFormSubmit.Products_2.checked && document.contactFormSubmit.Products_3.checked )
		ErrorTxt+="   Product of Interest not specified\n";
	
/*	if( chk_string( document.contactFormSubmit.Products.value, 1, 2, 15 ) )
		ErrorTxt+="   Product of Interest not specified\n";
*/	
	if( chk_string( document.contactFormSubmit.MonthlyVolume.value, 1, 2, 25 ) )
		ErrorTxt+="   Monthly Volume not specified\n";
		
	if( chk_string( document.contactFormSubmit.Comments.value, 1, 2, 1000 ) )
		ErrorTxt+="   Comments/Questions not specified\n";
	
	if( ErrorTxt != "" )
	{
		alert("Please correct the following errors:\n\n"+ErrorTxt);
		return false;
	}
	document.Capture.Submit.disabled = true;
	return true;
}