
	function valChange(form) {
		var bcolor = $('input').eq(0).css('background-color');	
		$(form + ' input').each(function(index) {
			
			$(this).change(function() {
	
				 if($(this).attr('title') == 'chk') {
					
					if($(this).val() != '') {
					
						$(this).css({'background-color' : bcolor});						
						$(this).next().remove();
					} else {
						$(this).css({'background-color' : '#8F1122'});						
						$(this).next().remove();
						$(this).after(' <span style="margin-left: 5px"> This field is required</span>');						
					}
										
				 } 
			});
		});
		
			var txtr = $(form + " textarea");
			$(txtr).change(function() {
			
				if(txtr.val() == '') {
						$(txtr).css({'background-color' : '#8F1122'});						
						$(txtr).next().remove();
						$(txtr).after('<span style="display:block; padding-left: 170px"> This field is required</span>');
				} else {
				
						$(txtr).css({'background-color' : bcolor});						
						$(txtr).next().remove();
				}
			});
	}
	
	function valSub(form) {
			valChange(form);
		var bcolor = $('input').eq(0).css('background-color');	
	
		$(form).submit(function() {
			
		var submit = true;

			
			$(form + ' input').each(function(index) {
				
				 if($(this).attr('title') == 'chk') {
					
					if($(this).val() == '') {
						submit = false;
						$(this).css({'background-color' : '#8F1122'});						
						$(this).next().remove();
						$(this).after('<span style="margin-left: 5px"> This field is required</span>');
					} else {
			
						$(this).css({'background-color' : bcolor});						
						$(this).next().remove();
					}
					
				 }
			});
			
			var txtr = $(form + " textarea"); 
			if(txtr.val() == '') {
					submit = false;
					$(txtr).css({'background-color' : '#8F1122'});						
					$(txtr).next().remove();
					$(txtr).after(' <span> This field is required</span>');
			} else {

				$(txtr).css({'background-color' : bcolor});						
				$(txtr).next().remove();
			}
			
			if(submit == false) {
	
				return false;
			} else {
	
				return true
			}
		});
	}
	
