// -------------------------------------------------------------------------
//  Name: Trim
//  Abstract: Trim leading and trailing white space.
// -------------------------------------------------------------------------
function Trim( strString )
{
	try
	{
		var strBuffer = "" + strString;	// Force copy by value using ""
		
		// Replace leading with space with nothing( global/ignore case )
		strBuffer = strBuffer.replace( /^\s*/gi, "");
		
		// Replace trailing with space with nothing( global/ignore case )
		strBuffer = strBuffer.replace( /\s*$/gi, "");
		
		return strBuffer;
	}
	catch( expError )
	{
		alert( "scripts/validate_form.js::Trim( ).\n Error:" + expError.number + ", " + expError.description );
	}
} // Trim


// -------------------------------------------------------------------------
//  Name: btnSubmit_Click
//  Abstract: Called when Submit is clicked.
// -------------------------------------------------------------------------
function btnSubmit_Click( )
{
	var blnValidData = false;
	
	try
	{
		// Did they enter a valid selection
		if( ValidData( ) ) 
		{
			// Yes
			blnValidData = true;
		}			
	}
	catch( expError )
	{
		alert( "scripts/validate_form.js::btnSubmit_Click( ).\n Error:" + expError.number + ", " + expError.description );
	}
	
	return blnValidData;
} // btnOK_Click


// -------------------------------------------------------------------------
//  Name: ValidData
//  Abstract: Check all the form data and make sure it is valid
// -------------------------------------------------------------------------
function ValidData( )
{
	try
	{
		var frmForm = 0;
		var blnResult = true;
		var strErrorMessage = "";
		
		// Get a reference to the form
		frmForm = document.getElementById("frmWhitePaper");
		
		// Trim leading and trailing spaces on required fields
		frmForm.txtName.value			= Trim(frmForm.txtName.value);
		frmForm.txtBusinessName.value	= Trim(frmForm.txtBusinessName.value);
		frmForm.txtEmailAddress.value	= Trim(frmForm.txtEmailAddress.value);
					
		strErrorMessage  = "------------------------------------------------------------\n";
		strErrorMessage += "Please correct the following error(s):\n";
		strErrorMessage += "------------------------------------------------------------\n";
		
		// Name
		if( frmForm.txtName.value == "" )
		{
			strErrorMessage += "-Name cannot be blank\n";
			blnResult = false;
		}
		
		// Business Name
		if( frmForm.txtBusinessName.value == "" )
		{
			strErrorMessage += "-Business Name cannot be blank\n";
			blnResult = false;
		}
		
		// Email Address
		if( frmForm.txtEmailAddress.value == "" )
		{
			strErrorMessage += "-Email Address cannot be blank\n";
			blnResult = false;
		}
		
		/*
		// EXAMPLE FOR DROP DOWN LISTS
		if( frmForm.cboInterest[frmForm.cboInterest.selectedIndex].value == "0" )
		{
			strErrorMessage += "-An Interest must be selected\n";
			blnResult = false;
		}
		*/
		
		// Warn the user
		if( blnResult == false ) alert( strErrorMessage );				
		
		// Return result
		return blnResult;
	}
	catch( expError )
	{
		alert( "scripts/validate_form.js::ValidData( ).\n Error:" + expError.number + ", " + expError.description );
	}
} // ValidData