/*
	// Form validation via jquery
	// Written by Bobby Hash
	// February 2nd 2009
	// Modified May 13 2009
*/
$(document).ready(function(){		
	
	//Control the status message and class depending on length on blur
	$('#name').blur(function() {
		var nameVal = $('#name').val().length;
		if(nameVal < 1){
			$('#name_error').html('Enter Your Name');
			$('#name_error').addClass('alert2');
		} 
		else{
			$('#name_error').html('');
			$('#name_error').removeClass('alert2');
		}
	})
	//email...
	$('#email').blur(function() {
		var emailVal = $(this).val().length;
		var emailVal2 = $(this).val();
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		if(emailVal < 1){
			$('#email_error').html('Enter Your E-mail');
			$('#email_error').addClass('alert2');
			$('#email_error2').html('');
			$('#email_error2').removeClass('alert2');
		}
		// is it the correct format?
	    else if (emailReg.test(emailVal2) == false){
			$('#email_error2').html('Invalid Format');
			$('#email_error2').addClass('alert2');
			$('#email_error').html('');
			$('#email_error').removeClass('alert2');
		}
		else{
			$('#email_error').html('');
			$('#email_error2').html('');
			$('#email_error').removeClass('alert2');
			$('#email_error2').removeClass('alert2');			
		}
	})
	//feedback....
	$('#fback').blur(function() {
		var fbackVal = $('#fback').val().length;
		if(fbackVal == ''){
			$('#feedback_error').html('Specify Concern of Feedback');
			$('#feedback_error').addClass('alert2');
		} 
		else{
			$('#feedback_error').html('');
			$('#feedback_error').removeClass('alert2');
		}
	})
	//comments....
		$('#comments').blur(function() {
		var commentsVal = $(this).val().length;
		if(commentsVal < 1){
			$('#comments_error').html('Enter Your Comments');
			$('#comments_error').addClass('alert2');
		}
		else{
			$('#comments_error').html('');
			$('#comments_error').removeClass('alert2');
		}
	})
	//Count the Comment Characters
	$('#comments').keyup(function() {
		var c_length = 1500 - ($(this).val().length);
		// Displays count
		$('#counter').html(c_length + ' characters remaining');		
		// Alerts when 250 characters is reached
		if (c_length > 0 ){
			$('#comments_error').html('');
			$('#comments_error').removeClass('alert2');
			$('#char_warn').html('');
			$('#char_warn').removeClass('alert2');

		}
		//if they are over, keep the static red alert at zero and then alert user how 
		//many characters they are over
		if(c_length < 0){
			$('#char_warn').html('You are <span id="counter2"> </span> characters over');
			$('#char_warn').addClass('alert2');
			$('#counter').html('0 characters remaining ');
			$('#counter2').html(0-c_length);

		}
	});	
	// end document ready function	
})
//end file