/***********************************************
 ***********************************************
 ** 
 ** This script be used for validating fields
 ** for Tymeware customer registration
 **
 ***********************************************
 ***********************************************/
 
<!--

// Display invalid field message and set focus
// to offending field
function invalidWarning(pfld_offender, psz_message)
{
	//Display message...
	pfld_offender.focus();
	pfld_offender.select();
	alert(psz_message);
}


//Strip out any whitespace in a string
function stripWhiteSpace(psz_string)
{

	var i;
	var sz_normalized = '';

	for (i=0; i <= psz_string.length; i++)
	{
		if (psz_string.charCodeAt(i) != 32)
			sz_normalized += psz_string.charAt(i);
	}

	return sz_normalized;
}


// Ensure all required fields are entered
function validateForm(pfrm_Registration)
{
	//Locals...
	var b_retCode = true;
	var sz_missingFields = '';
	var focusField;
	var b_focusSet = false;
	

	//Check that all required fields are entered...
	with (pfrm_Registration)
	{
		if (stripWhiteSpace(txtFirstName.value).length == 0)	
		{
			sz_missingFields += '\nFirst Name';
			focusField = txtFirstName;
			b_focusSet = true;
		}
		if (stripWhiteSpace(txtLastName.value).length == 0){
			sz_missingFields += '\nLast Name';
			if (!b_focusSet) {
				focusField = txtLastName;
				b_focusSet = true;}
		} 
		/*****************************************************
		if (stripWhiteSpace(txtAreaCode.value).length == 0) {
			sz_missingFields += '\nArea Code';
			if (!b_focusSet) {
				focusField = txtAreaCode;
				b_focusSet = true;}
		}			
		*****************************************************/
		if (stripWhiteSpace(txtBusLine.value).length == 0) {
			sz_missingFields += '\nBusiness Phone';	
			if (!b_focusSet) {
				focusField = txtBusLine;
				b_focusSet = true;}
		}					
		if (stripWhiteSpace(txtEmail.value).length == 0){
			sz_missingFields += '\nEmail Address';	
			if (!b_focusSet) {
				focusField = txtEmail;
				b_focusSet = true;}		
		}
		if (stripWhiteSpace(txtCompany.value).length == 0){
			sz_missingFields += '\nCompany Name';
			if (!b_focusSet) {
				focusField = txtCompany;
				b_focusSet = true;}
		}			
		if (stripWhiteSpace(txtMailAddr1.value).length == 0){
			sz_missingFields += '\nCompany Address';
			if (!b_focusSet) {
				focusField = txtMailAddr1;
				b_focusSet = true;}
		}																		
	}
	
	//See if there are any missing fields...
	if (sz_missingFields.length > 0)
	{
		invalidWarning(focusField, 'The following required fields were missing:\n' + sz_missingFields);
		b_retCode = false;
	}
	
	return b_retCode;

}
// -->
