// JavaScript Document
// Author: Kurt Freller
// Purpose: Feedback Form Functions
// Date: 26th April 2009 (Update)
// Email: frellerk@gmail.com
// ********************************
// Submitt the Form 
function submitform()
{
  	   document.form1.submit();
}
// Check and validate Email Address and Fields for Errors
function check(objDivId,FieldName,Label){
  valid = Validate_Email_Address(document.getElementsByName('Email')[0].value);
    // Check Empty Fields
 	if (document.getElementsByName(FieldName)[0].value==0){		
	   	document.getElementById(objDivId).className = 'invalid';
	   	document.getElementById(Label).className = 'label_invalid';
		// Change Comment Information to Invalid
		document.getElementById('comment_header').className = 'comment_header_invalid';
		document.getElementById('comment_information').className = 'comment_information_invalid';
	   	return false;
   	}
	else
	{
		document.getElementById(objDivId).className = 'valid';
		document.getElementById(Label).className = 'label_valid';
	}
	// Check and make sure the User Email Address is Valid
 	if (valid == false){
		document.getElementById('user_email').className = 'invalid';
		document.getElementById('label_email').className = 'label_invalid';
		return false;
	}
	else
	{
		document.getElementById('user_email').className = 'valid';
		document.getElementById('label_email').className = 'label_valid';
		return true;
	}
}
// Reset the Form
function form_reset(){
	// Clear Fields
 	document.getElementsByName('Name')[0].value = '';      
    document.getElementsByName('Email')[0].value = '';  
    document.getElementsByName('Comment')[0].value = ''; 
	// Clear Borders
	document.getElementById('user_name').className = 'default';	
	document.getElementById('user_email').className = 'default';
	document.getElementById('user_comment').className = 'default';
	// Clear Labels
	document.getElementById('label_name').className = 'label_default';
	document.getElementById('label_email').className = 'label_default';
	document.getElementById('label_comment').className = 'label_default';
	// Clear Comment Window
	document.getElementById('comment_header').className = 'comment_header_default';
	document.getElementById('comment_information').className = 'comment_information_default';
}
// Check fields required and submit the form when ready
function validateform(){
	if (check('user_name','Name','label_name') && check('user_email','Email','label_email') && check('user_comment','Comment','label_comment')) {
		// Change color of Comment form window - letting user know that all fields have been filled
		document.getElementById('comment_header').className = 'comment_header_valid';
		document.getElementById('comment_information').className = 'comment_information_valid';
		// Submit the Form as All Field Entries has been Filled in
		submitform();
	}
	else
	{
		// Do nothing yet return to the form until the user has filled in the form
	}
}