function textBoxValidation( inputId )
{
	var input = document.getElementById( inputId );
	
	if( isEmpty( input.value ) )
	{
		input.style.backgroundColor="#fec955";
		return false;
	}
	else
	{
		input.style.backgroundColor="white";
		return true;
	}
}

function validateAppForm(AppForm)
{
    var isValid = true;
    var emailval = document.getElementById( "EmailVal" );
    
    if( textBoxValidation( AppForm.Email.id) == false )
		isValid = false;
	else if( isEmail( AppForm.Email.value ) == false)
	{
		emailval.style.display="block";
		isValid = false;
		AppForm.Email.style.backgroundColor="#fec955";
	}
	else if (isEmail( AppForm.Email.value ) == true )
		emailval.style.display="none";
    
    if( textBoxValidation( AppForm.FirstName.id) == false )
		isValid = false;
		
    if( textBoxValidation( AppForm.LastName.id) == false )
		isValid = false;

    if( textBoxValidation( AppForm.Address.id) == false )
		isValid = false;
	
	if( textBoxValidation( AppForm.City.id) == false )
		isValid = false;
		
    if( textBoxValidation( AppForm.State.id) == false )
		isValid = false;
	
	if( textBoxValidation( AppForm.Zip.id) == false )
		isValid = false;
	
	if( textBoxValidation( AppForm.Phone.id) == false )
		isValid = false;
		
	
	var validator = document.getElementById( "BlanketValidator" );
	var validator2 = document.getElementById( "BlanketValidator2" );
	if( isValid == false )
	{
		validator.style.display = "block";
		validator2.style.display = "block";
	}
	else
	{
		validator.style.display = "none";
		validator2.style.display = "none";
	}
	
	return isValid;
	
	
}

//this is the function used to validate the contact form.
function validate(ContactForm)
{
	var isValid = true;	
	var emailval = document.getElementById( "EmailVal" );
	
	
	if( textBoxValidation( ContactForm.Email.id) == false )
		isValid = false;
	else if( isEmail( ContactForm.Email.value ) == false)
	{
		emailval.style.display="block";
		isValid = false;
		ContactForm.Email.style.backgroundColor="#fec955";
	}
	else if (isEmail( ContactForm.Email.value ) == true )
		emailval.style.display="none";
			
	if( textBoxValidation( ContactForm.Name.id) == false )
		isValid = false;
			
	if( textBoxValidation( ContactForm.Phone.id) == false )
		isValid = false;
		
	if( textBoxValidation( ContactForm.Message.id) == false )
		isValid = false;
						
	
	var validator = document.getElementById( "BlanketValidator" );
	
	if( isValid == false )
	{
		validator.style.display = "block";
	}
	else
	{
		validator.style.display = "none";
	}
	
	return isValid;
}

function makeMeWhiteAgain( inputId )
{
	var input = document.getElementById( inputId );
	
	if( !isEmpty( input.value ) )
		input.style.backgroundColor="white";
}



function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
	// Check that current character isn't whitespace.
	var c = s.charAt(i);

	if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

function isEmail (s)
{   if (isEmpty(s)) 
     return false;   
 
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

