function validateContact( form )
{
    var errorMsg = "";    
    
    // TRIM FORM ENTRIES
    form.Email.value = trim( form.Email.value );
    form.Message.value = trim( form.Message.value );

	//Check email address
    if (form.Email.value.length == 0 )
		errorMsg += "  Email is required.\n";
	else if (!isEmailAddr(form.Email.value))
		errorMsg += "  Email is invalid.\n";   	
	    
   //Check Subject
   var selectedSubject = form.Subject.selectedIndex;
   if (selectedSubject == 0) 
   {	
		errorMsg += "  Subject is required.\n";
   }
   //Check Message
   if ( form.Message.value.length == 0 )
    {
        errorMsg += "  Message is required.\n";
    } 

    // =========================================================================
             
    // IF ERROR OCCURRED THEN DISPLAY ERROR MESSAGE
    if ( errorMsg != "" )
    {
        window.alert( errorMsg );
        return false;
    }   				
	   
    // ELSE SUBMIT FORM    
    else
    {
        form.submit();
        return true;
    }

}


// ==================== TRIM FUNCTIONS ====================

function trim( str )
{
    str = trimLeft( str );
    str = trimRight( str, " " );
   
    return str;
}


function trimLeft( str )
{
    var chIndex = 0;
    var ch;
   
    while ( chIndex < str.length )
    {
        ch = str.charAt( chIndex );
       
        if ( ch != " " )
        {
            break;
        }
       
        chIndex++;
    }
   
    return str.substring( chIndex, str.length );
}

      
function trimRight( str, charsToTrim )
{
    var chIndex = str.length - 1;
    var ch;
   
    while ( chIndex >= 0 )
    {
        ch = str.charAt( chIndex );
       
        if ( charsToTrim.indexOf( ch ) == -1 )
        {
            break;
        }
       
        chIndex--;
    }
   
    return str.substring( 0, chIndex + 1 );
}


function trimAround( str, ch )
{
    var strList = str.split( ch );
   
    if ( strList.length > 1 )
    {
        for ( var strListIndex = 0; strListIndex < strList.length; strListIndex++ )
        {
            strList[ strListIndex ] = trim( strList[ strListIndex ] );
        }

        return strList.join( ch );
    }
    else
    {
        return str;
    }
}

function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}