function isFunction(functionToCheck) {
	var getType = {};
	return functionToCheck && getType.toString.call(functionToCheck) == '[object Function]';
}

function bgs_showError(item) {
	$(item).parent().find('label').css('color','red');
}

function bgs_showSuccess(item) {
	$(item).parent().find('label').css('color','green');
}

function bgs_valida(form, showerror, showsuccess) {
	var form = $(form);
	var errors = 0;
	
	if(!isFunction(showerror)) { showerror = bgs_showError; }
	if(!isFunction(showsuccess)) { showsuccess = bgs_showSuccess; }
	
	form.find('input[alt="text"]').each(function(){
		if( $(this).val().length < 1 ) { errors++; showerror(this); }
		else{showsuccess(this);}
	});
	
	form.find('input[alt="date"]').each(function(){
		var regexp = new RegExp("^(0[0-9]|[0,1,2][0-9]|3[0,1])/(0[0-9]|1[0,1,2])/[0-9]{4}$");
		var result = regexp.test($(this).val());
		
		if(!result) { errors++; showerror(this); }
		else{showsuccess(this);}
	});
	
	form.find('input[alt="cpf"]').each(function(){
		var regexp = new RegExp("^[0-9]{3}\.[0-9]{3}\.[0-9]{3}-[0-9]{2}$");
		var result = regexp.test($(this).val());
		
		if(!result) { errors++; showerror(this); }
		else{showsuccess(this);}
	});
	
	form.find('input[alt="rg"]').each(function(){
		var regexp = new RegExp("^([0-9]{3}\.){2}([0-9]{2}|[0-9]{3})$");
		var result = regexp.test($(this).val());
		
		if(!result) { errors++; showerror(this); }
		else{showsuccess(this);}
	});
	
	form.find('input[alt="cep"]').each(function(){
		var regexp = new RegExp("^[0-9]{2}\.[0-9]{3}-[0-9]{3}$");
		var result = regexp.test($(this).val());
		
		if(!result) { errors++; showerror(this); }
		else{showsuccess(this);}
	});
	
	form.find('input[alt="email"]').each(function(){
		var regexp = new RegExp("^([0-9a-zA-Z])([0-9a-zA-Z_.-]+)@(([0-9a-zA-Z])([0-9a-zA-Z_.-]+))(\.([a-zA-Z]{2,4}))$");
		var result = regexp.test($(this).val());
		
		if(!result) { errors++; showerror(this); }
		else{showsuccess(this);}
	});
	
	form.find('input[alt="website"]').each(function(){
		var regexp = new RegExp("^(http://)(www\.)[a-zA-Z0-9-\.]+(\.)([a-zA-Z])[a-zA-Z]+$");
		var result = regexp.test($(this).val());
		
		if(!result) { errors++; showerror(this); }
		else{showsuccess(this);}
	});
	
	form.find('input[alt="telefone"]').each(function(){
		var regexp = new RegExp("^\\([0-9]{2}\\) [0-9]{4}\.[0-9]{4}$");
		var result = regexp.test($(this).val());
		
		if(!result) { errors++; showerror(this); }
		else{showsuccess(this);}
	});
	
	form.find('textarea[class="bgs_required"]').each(function(){
		if( $(this).val().length < 1 ) { errors++; showerror(this); }
		else{showsuccess(this);}
	});
	
	form.find('select[class="bgs_required"]').each(function(){
		if( $(this).val().length < 1 ) { errors++; showerror(this); }
		else{showsuccess(this);}
	});
	
	if(errors == 0){return true;}
	else {return false;}
}
