/*  Generic Validation Function  */
function validate(form){
	
    var valid = true;
	var val = new String();
	var id = new String();
	var label = new String();

	$('#'+form+' .required').each( function () {
		id = $(this).attr('id');
		label = $(this).attr('name')+'_lbl';
		val = $(this).val();
		
		//  Reset the text color and border color
		$('#'+label).css('color', text_color);
		if ( ($(this).attr('type') == 'text') || ($(this).attr('type') == 'password') || ($(this).attr('type') == 'hidden') || ($(this).attr('tagName').toLowerCase() == 'textarea') )
			$("#"+id).css("border-color", border_color);
			
		//  Take action on the value
		switch(id){
			case "email":
                if(validEmail(val) == false){
                   	valid = false;
                    $("#"+label).css("color", error_color);
					$("#"+id).css("border-color", error_color);
                }
                break;
			default:
			
				//  If the required field is a checkbox
				if ($(this).attr('type') == 'checkbox'){
					if ($(this).attr('checked') != true){
						valid = false;
						$('#'+label).css('color', error_color);
					}
				}
				
				//  Other Fields
				else if (val.length < 1){
					valid = false;
					$('#'+label).css('color', error_color);
					if ( ($(this).attr('type') == 'text') || ($(this).attr('type') == 'password') || ($(this).attr('type') == 'hidden') || ($(this).attr('tagName').toLowerCase() == 'textarea') )
						$("#"+id).css("border-color", error_color);
				}
				break;
		}
	});
	
	if (valid == false){
		var data = { type:'error', msg:'Error: Missing Required Information'};
		displayNotification(data);
	}
	
	return valid;
}

/*  Validate the email address  */
function validEmail(email){
    var tValid = true;
    if((email.length < 8) ||
        ((email.length>0) && (! email.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.biz)|(\..{2,2}))$)\b/gi)))){
        tValid = false;
    }
    return tValid;
}
