// JavaScript Document
var bug = 0;
$(function(){
				$('input#send_button').click(function(){$('#contactForm').submit();});
				$('#contactForm').submit(function(){return chkForm();});
		   });
// Check Email for validity
function chkEmail(o){
	if ( !((/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i).test($(o).val())) ) return false;
	else return true;
}

// Check wheather the field is empty or not
function chkEmpty(o){
	if($.trim($(o).val()).length > 0) return true;
	else return false;
}

// Check wheather the field is empty or not if it is add class otherwise remove class
function chkField(o){
	if(!chkEmpty($(o).get())){
		$(o).addClass('fld_error');
		bug++;
		return false;
	}
	else if( $(o).attr('id') == "uemail" && !chkEmail($(o).get()) ){
		$(o).addClass('fld_error');
		bug++;
		return false;
	}
	else{
		$(o).removeClass('fld_error');
		return true;
	}
}

function chkForm(){
	$('input#send_button').attr('disabled','disabled');
	bug		= 0;
	var nf	= (chkField($('input#uname').get()))?true:false;
	var ef	= (chkField($('input#uemail').get()))?true:false;
	var cf	= (chkField($('textarea#comment').get()))?true:false;
	if(nf && ef && cf){
		return true;
	}
	else{
		$('input#send_button').removeAttr('disabled');
		alert("You have done "+bug+" mistake(s).\n Please correct the highlighted field(s) first!");
	}
	return false;
}
