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 showAtividade(id,titulo){
	
	jQuery.post( "ajax.html?ajax=getAtividade", "id="+id, 
				function(data){	
				
				$("<div></div>")
					.html("<p>"+data+"</p>")
					.attr("title",titulo)
					.appendTo("body")
					.addClass("dialogAlert")
					.dialog({height:500,width:750,modal:true});		
	});	
	
}

	function cadNewsletter(){
		
		var $emailRegExp = new RegExp(/^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/);	
		
		if($('#nome_news').val() == ""){
			alert("Por favor, preencha o campo \"Nome\"!");
			$('#nome_news').focus();
			return false;
		}
		
		if($('#email_news').val() == ""){
			alert("Por favor, preencha o campo 'Email'");
			$('#email_news').focus();
			return false;
		}
		
		if(!$emailRegExp.test($('#email_news').val())){
			alert("Email informado inválido!");
			$('#email_news').focus();
			return false;
		}
		
		 $.ajax({
		   type: "POST",
		   url: "acoes.html?acao=cadastrarEmail",
		   data: "email="+$('#email_news').val()+"&nome="+$('#nome_news').val(),
		   success: function(msg){
		 	 	//alert(msg);
				eval(msg);
		 
   			}
		
		 });
		
	}
