function sm_checkForm(objForm)
{
  var arClass, bValid, objEmail, objConfirm_Email, objAddress, objTelephone;
  var objField = objForm.getElementsByTagName('*');
  
  for (var iFieldCounter=0; iFieldCounter<objField.length; iFieldCounter++)
  {
    var w;

    // Allow for multiple values being assigned to the class attribute
    arClass = objField[iFieldCounter].className.split(' ');
    for (var iClassCounter=0; iClassCounter<arClass.length; iClassCounter++)
    {
      switch (arClass[iClassCounter])
      {
		case 'optional':
 		    bValid = true;
			break;
      	case 'required':
           bValid = sm_isPresent(objField[iFieldCounter].value);
      	   break;
        case 'string':
           bValid = sm_isString(objField[iFieldCounter].value.replace(/^\s*|\s*$/g, ''));
           break;
        case 'number' :
           bValid = sm_isNumber(objField[iFieldCounter].value);
           break;
        case 'email' :
           bValid = true;
		   if (sm_isPresent(objField[iFieldCounter].value))
	           bValid = sm_isEmail(objField[iFieldCounter].value);
           break;
        default:
           bValid = true;
      }

      if (bValid == false)
      {
        // If field invalid... quit and alert the user by changing warning text 
        w = document.getElementById('sm_warning');
        w.innerHTML = '<span class="smallred">*&nbsp;ERROR - Please check the value you entered for : ' + objField[iFieldCounter].name + '</span>';

//      w.childNodes[1].nodeValue = '<span class="smallred">*&nbsp;ERROR - Please check the value you entered for : ' + objField[iFieldCounter].name + '</span>';

        objField[iFieldCounter].select();
        objField[iFieldCounter].focus();

        return false;
      }
    }
  }

// check e-mail / confirm e-mail  match - at this point they may be blank or undefined
  objEmail = document.getElementById('email');
  objConfirm_Email = document.getElementById('confirm_email');
  if (sm_isPresent(objEmail.value)) 
  	bValid = sm_isMatch(objEmail.value, objConfirm_Email.value);  
  if (bValid == false)
  {
    // If e-mail addresses don't match...
    // alert the user by changing warning text
    w = document.getElementById('sm_warning');
    w.innerHTML = '<span class="smallred">*&nbsp;ERROR - The e-mail values are not the same!</span>';
    return false;
  }

// check at least one contact field completed
  objAddress = document.getElementById('address');
  objTelephone = document.getElementById('telephone');
  if ((!sm_isPresent(objEmail.value)) && (!sm_isPresent(objAddress.value)) && (!sm_isPresent(objTelephone.value))) 
  {
    w = document.getElementById('sm_warning');
    w.innerHTML = '<span class="smallred">*&nbsp;ERROR - At least one contact field is required!</span>';
    return false;
  }
  
  return true;
}

function sm_isPresent(fieldValue)
{
  return ((fieldValue != null) && (fieldValue.replace(/^\s*|\s*$/g,"") != ''));
}

function sm_isString(strValue)
{
  return (typeof strValue == 'string' && strValue != '' && isNaN(strValue));
}

function sm_isNumber(strValue)
{
  return (!isNaN(strValue) && strValue != '');
}

function sm_isEmail(strValue)
{
  var objRE = /^[\w-\.\']{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,}$/;
  return (strValue != '' && objRE.test(strValue));
}

function sm_isMatch(strValue1, strValue2)
{
   return (strValue1 == strValue2);
}

function updateMSG()
{
    w = document.getElementById('sm_warning');
    w.innerHTML = '<span class="smallred">*&nbsp;Please ensure that all required fields are completed. (At least one of the contact fields is required.)</span>';	
}

// ***** scratch area *****
function dothis()
{
	var objEmail, objConfirm_email;
	alert('In dothis!');
	try {
	  // check e-mail / confirm e-mail  match
	  objEmail = document.getElementById('email');
	  objConfirm_Email = document.getElementById('confirm_email');
	  alert(objEmail.value);
	  alert(objConfirm_Email.value);
	  alert(''+(sm_isMatch(objEmail.value, objConfirm_Email.value)?'true':'false'));
	} catch (er) {
		alert('Error occurred!');
		return false;
	}
	alert('Leaving dothis!');
	return false;
}


