var keys   = new Array();
var fields = new Array();
<br />
<b>Warning</b>:  mysql_num_fields() expects parameter 1 to be resource, boolean given in <b>/home/wmedia2/public_html/includes/classes/db/db.php</b> on line <b>123</b><br />
<br />
<b>Warning</b>:  mysql_fetch_array() expects parameter 1 to be resource, boolean given in <b>/home/wmedia2/public_html/includes/classes/db/db.php</b> on line <b>38</b><br />
var labels = new Array();
var types  = new Array('input','textarea');
var form   = '.';
var istyle = 'color:#900; font-weight:bold;'
var errors = new Array();
var msg	   = '';
$(document).ready(function(){
	for(i=0; i<types.length; i++){
		var type =	$(form).find(types[i]);
		$(type,this).each(function(){
			if(checkType($(this))){
				keys.push($(this));
			}
		});
		$(type,this).focus(function(){ 
			if(checkType($(this)) && fields[$(this).attr('name')] == $(this).attr('value')){
				$(this).attr('value','');
			}
		});
		$(type,this).blur(function(){
			if($(this).attr('value') == '' || !checkThis($(this))){
				if($(this).attr('value') == ''){
					$(this).attr('value',fields[$(this).attr('name')]);
				}
				if($(this).parent().attr('class') == 'required_field'){
					setInvalid($(this));
				}
			}
		});
	}
	$(form).submit(function(){
		errors 		= new Array();
		var msg	   	= '----- Required Fields (invalid/empty) -----'+"\n";
		$(keys,this).each(function(){
			checkThis($(this));
		});
		if(errors.length > 0){
			$(errors,this).each(function(){
				msg += setInvalid($(this));
			});
			alert(msg);
			return false;
		}else{
			return true;	
		}
	});
});

function checkType(div){
	if($(div).attr('type') == 'submit' || $(div).attr('type') == 'reset' || $(div).attr('type') == 'button' || $(div).attr('type') == 'hidden'){
		return false;
	}else{
		return true;	
	}
}

function checkEmail(value){
	filter=/^.+@.+\..{2,3}$/
 return (filter.test(value));
}

function getLabel(div){
	var c = $(div);
	while($(c).find('label').length == 0){
		c = $(c).parent();	
	}
	return $(c).find('label');	
}

function setInvalid(div){
	if(fields[$(div).attr('name')].match(':')){
		var label = getLabel($(div));
		$(label).attr('style',istyle);
		label	  = $(label).html().replace('*','');
		return label.replace(':',"\n");
	}else{
		$(div).attr('style',istyle);
		return fields[$(div).attr('name')].replace('*','')+"\n";
	}
	return false;
}

function checkThis(div){
	if(!checkRequired(div)){ return false; }
	if($(div).attr('value') == '' || $(div).attr('value') == fields[$(div).attr('name')]){
		errors.push($(div));
	}else
	if($(div).attr('name').match('email') && !checkEmail($(div).attr('value'))){
		errors.push($(div));		
	}else{
		if(fields[$(div).attr('name')].match(':')){
			$(getLabel($(div))).attr('style','');
		}else{
			$(div).attr('style','');
		}
		return true;
	}
	return false;
}

$.fn.tagName = function() {
    return this.get(0).tagName;
}


function checkRequired(div){
	var tag = div;
	while($(tag).tagName() != 'DIV'){
		tag = $(tag).parent();	
	}
	if($(tag).attr('class').match('required_field')){
		return true;
	}else{
		return false;	
	}
}
