﻿// JScript File

function validateFeedback( email, subject, message)
{
    var validEmail = false;
    var validSubject = false;
    var validMessage = false;
        
    // check the items we want to validate
    if( trim( email.value ).length <= 0 )
    {
        document.getElementById('errorEmail2').style.display = 'none';
        document.getElementById('errorEmail').style.display = '';
        validEmail = false;
    }//end if
    else
    {
        document.getElementById('errorEmail').style.display = 'none';
        
        // once we have text, make sure we have a valid email address
        if( !checkMail( trim( email.value ) ) )
        {
            document.getElementById('errorEmail2').style.display = '';
            validEmail = false;
        }//end if
        else
        {
            document.getElementById('errorEmail2').style.display = 'none';
            validEmail = true;
        }//end else
    }//end else
        
    if( trim( subject.value ).length <= 0 )
    {
        document.getElementById('errorSubject').style.display = '';
        validSubject = false;
    }//end if
    else
    {
        document.getElementById('errorSubject').style.display = 'none';
        validSubject = true;
    }//end else
    
    if( trim( message.value ).length <= 0 )
    {
        document.getElementById('errorMessage').style.display = '';
        validMessage = false;
    }//end if
    else
    {
        document.getElementById('errorMessage').style.display = 'none';
        validMessage = true;
    }//end else
    
    if( validEmail && validSubject && validMessage )
    {
        return true;
    }//end if
    else
    {
        return false;
    }//end else
}//end function


function trim( sString )
{
    while (sString.substring(0,1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }//end while
    
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
        sString = sString.substring(0,sString.length-1);
    }//end while
    
    return sString;
    
}

function checkMail( email )
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if( filter.test( email ) )
	{
	    return true;
	}//end if
	else
	{
	    return false;
	}//end else
}
