// shouldn't need to edit

function isEmpty( the_field )
{
	if( the_field == "" )
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

function isValidEmail( the_email )
{
	var email_regexp = /^.+@.+\..{2,3}$/;
	
	if( !( email_regexp.test( the_email ) ) )
	{ 
		return 0;
	}
	else
	{
		var bad_chars = /[\(\)\<\>\,\;\:\\\"\[\]]/;
		//var bad_chars = /[\`\~\!\#\$\%\^\&\*\(\) (\)\<\>\,\;\:\\\"\[\]]/;

		if( the_email.match( bad_chars ) )
		{
			return 0;
		}
	}
	
	return 1;
}

function isOkPhone( the_phone )
{
	var the_clean_phone = the_phone.replace( /[\(\)\.\-\ ]/g, '' );
	
	if( the_clean_phone.length != 10 )
	{
		return 0;
	}
		
	for( i = 0; i < the_clean_phone.length; i++ )
	{
		if( isNaN( the_clean_phone.charAt(i) ) )
		{
			return 0;
		}
	}
	
	return 1;
}

function processErrors( arr_errors )
{
	var error_message = "The following required fields are have not been completed or contain invalid information. Please correct these errors and click \"Submit\".";

	for( i = 0; i < arr_errors.length; i++ )
	{
		error_message += "\n" + ( i + 1 ) + ". " + arr_errors[i];
	}
	
	alert( error_message );
}

function validateCatalogForm()
{
	var arr_errors = new Array();
	
	if( isEmpty( document.catalog_form.f_name.value ) )
	{
		arr_errors.push( "Name" );
	}

	if( isEmpty( document.catalog_form.f_address.value ) )
	{
		arr_errors.push( "Address" );
	}

	if( isEmpty( document.catalog_form.f_city.value ) )
	{
		arr_errors.push( "City" );
	}

	if( isEmpty( document.catalog_form.f_state.value ) )
	{
		arr_errors.push( "State" );
	}

	if( isEmpty( document.catalog_form.f_zip.value ) )
	{
		arr_errors.push( "Zip" );
	}

	if( isEmpty( document.catalog_form.f_country.value ) )
	{
		arr_errors.push( "Country" );
	}

	if( isEmpty( document.catalog_form.f_email.value ) )
	{
		arr_errors.push( "Email" );
	}
	else if( !emailCheck( document.catalog_form.f_email.value ) )
	//else if( isValidEmail( document.catalog_form.f_email.value ) )
	{
		arr_errors.push( "Email" );
	}
	
	if( isEmpty( document.catalog_form.f_telephone.value ) )
	{
		arr_errors.push( "Daytime Telephone" );
	}
	else if( !isOkPhone( document.catalog_form.f_telephone.value ) )
	{
		arr_errors.push( "Daytime Telephone" );
	}
	
	if ( arr_errors.length > 0 )
	{
		processErrors( arr_errors );
	   	return false;
	}

	return true;
}