jQuery.fn.teclaPressionada = function(options) {
	
	var o = jQuery.extend({
		formato : "",
		teclas : {}
	}, options);	
	
	var isCtrl = false;
	var isDelete = false;	


	this.keydown(function(event){
		
		switch(getTecla(event)){
			case 8: 
			case 46: isDelete = true; break;
			case 17: isCtrl = true;	break;	
		}
				
	});
	
	this.keyup(function(event){
						   
		switch(getTecla(event)){
			case 8: 
			case 46: isDelete = false; return; break;
			case 17: isCtrl = false; break;
		}
		
		if(o.formato){
			
			var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
	 
			val = this.value;
			val = val.replace(/[\[\\\^\$\.\|\?\*\+\(\)\-\s\/\]]/g,"");
			fldLen = val.length;
			mskLen = o.formato.length;
			
			i = 0;
			nCount = 0;
			sCod = "";
			mskLen = fldLen;			
			
			while (i <= mskLen) {
				bolMask = ((o.formato.charAt(i) == "-") || (o.formato.charAt(i) == ".") || (o.formato.charAt(i) == "/"))
				bolMask = bolMask || ((o.formato.charAt(i) == "(") || (o.formato.charAt(i) == ")") || (o.formato.charAt(i) == " ") || (o.formato.charAt(i) == ":"))

				if (bolMask) {
					sCod += o.formato.charAt(i);
					mskLen++; }
				else {
					sCod += val.charAt(nCount);
					nCount++;
				}

				i++;
			}
			
			if(sCod.length > o.formato.length){
				sCod = sCod.substr(0,o.formato.length);
			}

			this.value = sCod;		
		}
				
	});	
	
	this.keypress(function(event){
		
		if(isCtrl == true){return;}
		
		tecla = getTecla(event);
		if(o.teclas.caracteres){
			if ((tecla != 8) && (tecla != 0) && (tecla <= 43 || tecla >= 58)){
				event.preventDefault();	
			}
		}else if(o.teclas.numeros){
			if ((tecla != 8) && (tecla != 0) && (tecla <= 46 || tecla >= 58)){
				event.preventDefault();	
			}
		}
		
	});
	
	function getTecla(e){
		if($.browser.mozilla){return e.which;}else{return e.keyCode;}
	}
	
	return this;
	
};

function postForm(it,callback){
	
	$it = $(it);
	$action = $it.attr("action");

	if(callback != undefined && (typeof callback == 'function')){
		if(callback.call() == false){
			return false;
		}
	}
	
	$vals = $it.serialize();
	
	 $.ajax({
	   type: "POST",
	   url: $action,
	   data: $vals,
	   success: function(msg){
		   eval(msg);
   	   }
	 });
	
	return false;	
	
}
