function alerta(title, msg){
	jAlert(msg, title, function(r) {});
}

/*POSTAR FORMULARIO*/
function postaForm(form, dest){

	//alert( jQuery(form).attr("action"));
	//alert(jQuery("input, textarea, select, checkbox, radio").serialize());
	//if (!vazios()){

				carregar(true);

				$.ajax({

				  type: jQuery(form).attr("method"), 

				  url: jQuery(form).attr("action"), 

				  data: jQuery("input, textarea, select, checkbox, radio").serialize(),

				  dataType: "html",

				  success: function(msg){ 

					carregar(false);
					
					jQuery(dest).html("");

					jQuery(dest).html(msg);

				  } ,

				  error: function(xhr, ajaxOptions, thrownError){

					  carregar(false);
	                    //alert(xhr.status);
	                    //alert(thrownError);
					    alert("[postagem]: erro na requisição.");

				  }

				});

	//}	

	return false;

}



/*  VERIFICA SE OS CAMPOS SETADOS COM empty ESTÃO VAZIOS  */

function vazios(){

	var err = "";

		

	jQuery(".formContainer .empty").each(function(){
		var id = jQuery(this).attr("id");
		var txt = jQuery(id).val();
		var err = "";
		alert(txt);
		if(jQuery(this).attr("type") == 'radio'){
			txt = jQuery(this).attr("checked");
			if ((txt == false) || (txt == undefined)){
				err = "Os campos obrigatórios estão vazios.\n";
			}
		}else{
			if (txt == ""){
				err = "Os campos obrigatórios estão vazios.\n";
			}
		}
	});

	

	if (err == ""){

		return false;	

	}else{

		alert(err);

		return true;

	}

}



/*CARREGANDO*/

function carregar(bol){

	if (bol){

		$(document.body).append("<div id='carregando'><img src=\"../imagens/ajax-loader.gif\" border=\"0\">Carregando...</div>");

		$("#carregando").fadeIn("slow");

	}else{

		$("#carregando").fadeOut("slow");

		$("#carregando").remove();

	}

}



/*ABRIR LINK*/

function abrirLink(str, dest){

	$(dest).html("<div id=\"carregando\"> Carregando... <img src=\"../imagens/ajax-loader.gif\" border=\"0\"></div>");

	$(dest).load(str,{},function(){

	});

}





jQuery(document).ready(function(){

    $(function() {

		$('a.superbanner').media({ 

			autoplay:  true, 

			caption:   false, // supress caption text 

			width: 776, 

			height: 150,

			bgColor: 'transparent',

			flashVersion:  '9',

			attrs:{wmode: 'transparent'}

		}); 
        
        $('a.player_musica').media({ 

			autoplay:  true, 

			caption:   false, // supress caption text 

			width: 35, 

			height: 35,

			bgColor: 'transparent',

			flashVersion:  '9',

			attrs:{wmode: 'transparent'}

		});
        
        $('a.popup_natal').media({ 

			autoplay:  true, 

			caption:   false, // supress caption text 

			width: 560, 

			height: 500,

			bgColor: 'transparent',

			flashVersion:  '9',

			attrs:{wmode: 'transparent'}

		});	

    });

});

/* TOOL TIP */
function tooltip(){
	$(document.body).each(function(i){
		$(".formContainer input, .formContainer textarea").focus(function(){

				$(this).next("a").css("display","block");

		}).blur(function(){

				$(this).next("a").css("display","none");

		});
        simple_tooltip("a.tooltip_info","tooltip");
	});
}

function simple_tooltip(target_items, name){
 $(target_items).each(function(i){

		if( $("#"+name+i).attr("id") == undefined){

			$(document.body).append("<div class='"+name+"' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");

		}else{

			$("#"+name+i).html("<p>"+$(this).attr('title')+"</p>");

		}

		var my_tooltip = $("#"+name+i);



		$(this).removeAttr("title").mouseover(function(){

				my_tooltip.css({opacity:0.8, display:"none"}).fadeIn(400);

		}).mousemove(function(kmouse){

				my_tooltip.css({left:kmouse.pageX+15, top:kmouse.pageY-(my_tooltip.height()+15)});

		}).mouseout(function(){

				my_tooltip.fadeOut(400);

		});

	});

}


/*ANIMA RESULTADO ENQUETE*/
function animateResults(){
  $("#poll-results div").each(function(){
      var percentage = $(this).next().text();
      $(this).css({width: "0%"}).animate({
				width: percentage}, 'slow');
  });
}

/*RETIRAR ACENTOS*/
function retiraAcentos(palavra) {
	//com_acento = '.áàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÖÔÚÙÛÜÇ ';
    com_acento = '.áàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÖÔÚÙÛÜÇ ';
	sem_acento = '.aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC_';
	nova='';
	for(i=0;i<palavra.length;i++) {
		if (com_acento.search(palavra.substr(i,1))>=0) {
			nova+=sem_acento.substr(com_acento.search(palavra.substr(i,1)),1);
		}else{
			nova+=palavra.substr(i,1);
		}
	}
	
	nova = nova.replace(/ /gi,"_");
	return nova;
}

function extraiext(str){
    var pos = str.lastIndexOf(".");
    var dif = str.length - pos;
    return str.substr(0,(str.length-dif));
}