jQuery(document).ready(function() {
	jQuery('form').submit(function(){
		var erros = '';
		jQuery.each($(this).find('.obrigatorio'),function(i,campoObrigatorio){

			if(!jQuery(campoObrigatorio).val()){
				if(!erros) primeiroErro = campoObrigatorio;
				erros += $(campoObrigatorio).attr('title')+";\n";
			}
		});
		if(erros){
			jQuery.erro("Restrições de obrigatoriedade:",erros);
			if(primeiroErro) $(primeiroErro).focus();
			return false;
		}
		return true;
	});
	jQuery('.obrigatorio')
		.focus(function(){jQuery(this).campoObrigatorio();})
		.keypress(function(){jQuery(this).campoObrigatorio();})
		.blur(function(){$('#'+jQuery(this).attr('id')+'_obrigatoriedade').html('*');});
		
		jQuery.fn.campoObrigatorio = function(){if(!jQuery(this).val()) jQuery('#'+jQuery(this).attr('id')+'_obrigatoriedade').html('* Campo obrigatÃ³rio');}
jQuery.msg = function(titulo,msg){alert(titulo+"\n\n"+msg);}
jQuery.erro = function(titulo,msg){alert(titulo+"\n\n"+msg);}
jQuery.submeter = function(formulario){
	formulario = formulario || document.formulario;
	jQuery(formulario).trigger('submit');
}
jQuery.getURLParam = function(strParamName){
	var strReturn = "";
	var strHref = window.location.href;
	var bFound=false;
	var cmpstring = strParamName + "=";
	var cmplen = cmpstring.length;
	if ( strHref.indexOf("?") > -1 ){
		var strQueryString = strHref.substr(strHref.indexOf("?")+1);
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
			if (aQueryString[iParam].substr(0,cmplen)==cmpstring){
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				bFound=true;
				break;
			}
		}
	}
	if (bFound==false) return null;
	return strReturn;
}
});
