String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
o = function(id){
	return document.getElementById(id);
}
m = function(obj,formato){
	var valorFinal='';
	var validos = '0123456789';

				
		for (var i=0;i<obj.value.length;i++){  
			if(formato.indexOf(obj.value.charAt(i))!=-1 || validos.indexOf(obj.value.charAt(i))!=-1){
				if(!(formato.indexOf(obj.value.charAt(i))!=-1)){
					if(formato.charAt(i)!='#'){
						valorFinal += formato.charAt(i);
					}
					
				}
				
				valorFinal +=  obj.value.charAt(i);	
			}
		}
		obj.value =valorFinal;
		return true;
}

// UTILIZADO PARA CONFIGURAR E ENVIAR FORMULARIOS.
do_send = function(f){
	return new send(f);
}
send = function(frm){
	this.action = function(act){
		o(frm).action = act.trim();
		return new send(frm);
	}
	this.method = function(met){
		o(frm).method = met.trim();
		return new send(frm);
	}
	this.submit = function(){
		o(frm).submit();
	}
	this.addHiddenField = function(name, value){
		var oh = document.createElement("input");
		oh.type = "hidden";
		oh.name = name;
		oh.value = value;
		o(frm).appendChild(oh);
		return new send(frm);
	}
				
}
// UTILIZADO PARA APLICAR MASCARA NOS CAMPOS DE UM FORMULARIO.
do_mask = function(f){
	return new mask(f);
}
mask = function(cpo){
	this.format = function(fmt){
		o(cpo).maxLength = fmt.length;
		o(cpo).onkeyup = function(){
			m(o(cpo),fmt);
		}
		
	}
	this.reset = function(){
		o(cpo).onkeyup = function(){
			return true;
		}
	}

}

do_reset = function(){
	for(var i=0, cpo; cpo=document.getElementsByTagName('input')[i];i++)
		cpo.value = '';
}



/*calendario = function(class){
	
	this.carregar = function(d){
		document.data='';
		try{
			data=d;
		}catch(e){
			data = '';
		}
		$(class).datePicker();
		
	}
	
}*/