if (document.location.hostname == "mundi01") {
	var urlsite = "http://mundi01/tribunadopiaui/";
} else {
	var urlsite = "http://www.tribunadopiaui.com.br/";	
}

function showLoading(obj){
	
	var iwidth = $(document).width();
	var iheight = $(document).height();
	
	$("#"+obj).css({"width":""+iwidth+"px", "height":""+iheight+"px"});	
	$("#"+obj).html("<p>Aguarde...</p>");
	$("#"+obj + " p").css({"margin-left":""+parseInt((iwidth/2)-100)+"px","margin-top":""+parseInt((iheight/2))+"px"});
	$("#"+obj).show();
	
}

// Display Form para envio de notícia/coluna por E-mail
function postMail(code,type,obj) {

	jQuery("#"+obj).css({"display":"block"});	
	jQuery("#"+obj).html("<form action=\"\" method=\"post\" id=\"frm_enviar\" name=\"frm_enviar\">" +
				  "<input name=\"postcod\" type=\"hidden\" value=\""+code+"\" style=\"border: 0px;\" />" +
				  "<input name=\"posttip\" type=\"hidden\" value=\""+type+"\" style=\"border: 0px;\" />" + 
				  "  <table width=\"570\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">" + 
				  "    <tr>" + 
				  "      <td width=\"30%\"><label for=\"mfrom\">Seu e-mail:</label></td>" + 
				  "      <td width=\"65%\"><input name=\"mfrom\" type=\"text\" id=\"mfrom\" size=\"70\" maxlength=\"50\" /></td>" + 
				  "    </tr>" + 
				  "    <tr>" + 
				  "      <td><label for=\"mto\">E-mail destinatário:</label></td>" + 
				  "      <td><input name=\"mto\" type=\"text\" id=\"mto\" size=\"70\" maxlength=\"50\" /></td>" + 
				  "    </tr>" + 
				  "    <tr>" + 
				  "      <td>&nbsp;</td>" + 
				  "      <td><input type=\"submit\" name=\"btnok\" id=\"btnok\" value=\"Enviar\" onclick=\"return EnviarPost();\" /></td>" + 
				  "    </tr>" + 
				  "  </table>" + 
				 "</form>")

}

// Enviar News por E-mail
function EnviarPost(formData,jqForm,options) {

	var verificaEmail = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	var mfrom 	= jQuery("#mfrom").val();
	var mto 	= jQuery("#mto").val();
	var postcod = jQuery("#postcod").val();
	var posttip = jQuery("#posttip").val();
	var status 	= "";
	
	if(!mfrom) {
	
		status += 'Informe seu e-mail!\n';
	
	} else {
		
		if(!verificaEmail.test(mfrom)) {
		
			status+='Seu E-mail é inválido!\n';
		
		}
		
	}

	if(!mto) {
	
		status += 'Informe o e-mail do Destinatário!\n';
	
	} else {
		
		if(!verificaEmail.test(mto)) {
		
			status+='E-mail do Destinatário é inválido\n';
		
		}
		
	}
	
	if(status!="") {
		
		alert(status);
		$("#mfrom").focus();
		return false;
		
	} else {
			  
		$("#frm_enviar").submit(function() {
			var options = {
				url: urlsite+"postEmail.asp",
				type: "post",
				
				success: function(resposta) {
					
					alert(resposta);
					$("#utilities_box").html("&nbsp;");
					$("#utilities_box").css({"display":"none"});
					
				}
				
			}
			
			$(this).ajaxSubmit(options);
			
			return false;
			
		});
		
		
		
	}
	
}

/* Recarregar Select com lista de Cidades*/
function getState(){
	
	var estado = $("#estado").val();
	
	$("#cidade").html("<option value=\"0\">recarregando...</option>");
	
	$.post(urlsite+"getState.asp", { estado: estado},
		function(resultado){
			$("#cidade").html(resultado);
			$("#cidade").attr({disabled:""});
	});

}

/* Enviar Comentário */
function getComent(){
	
	var verificaEmail = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	var nome = $("#nome").val();
	var email = $("#email").val();
	var estado = $("#estado").val();
	var cidade = $("#cidade").val();
	var comentario = $("#comentario").val();
	var codpost = $("#codpost").val();
	var tipcoment = $("#tipcoment").val();
	var urlredirect = $("#urlredirect").val();
	var erromessage = "Preencha os campos abaixo corretamente:\n"
	var status = true;
	
	if(!nome) {
	
		erromessage += "- Nome\n";
		status = false;
	
	}
	
	if(!email) {
	
		erromessage += "- E-mail\n";
		status = false;
	
	} else {
		
		if(!verificaEmail.test(email)) {
		
			erromessage += "- E-mail inválido\n";
			status = false;
		
		}
		
	}
	
	if(estado == 0) {
	
		erromessage += "- Estado\n";
		status = false;
	
	}

	if(cidade == 0) {
	
		erromessage += "- Cidade\n";
		status = false;
	
	}

	if(!comentario) {
	
		erromessage += "- Comentário\n";
		status = false;
	
	}
	
	if (status == false){
		
		alert(erromessage);
		return false;
		
	} else {

		$("#btnenviar").attr("disabled","disabled");
		$("#btnenviar").attr("value","Enviando...");
		$("#frmcoment").attr("action",urlsite+"getComent.asp"); 
		$("#frmcoment").submit();
		
	}
	
}

/* Enviar Comentário */
function getMural(){
	
	var verificaEmail = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	var nome = $("#nome").val();
	var email = $("#email").val();
	var para = $("#para").val();
	var estado = $("#estado").val();
	var cidade = $("#cidade").val();
	var comentario = $("#comentario").val();
	var urlredirect = $("#urlredirect").val();
	var erromessage = "Preencha os campos abaixo corretamente:\n"
	var status = true;
	
	if(!nome) {
	
		erromessage += "- Nome\n";
		status = false;
	
	}
	
	if(!email) {
	
		erromessage += "- E-mail\n";
		status = false;
	
	} else {
		
		if(!verificaEmail.test(email)) {
		
			erromessage += "- E-mail inválido\n";
			status = false;
		
		}
		
	}
	
	if(estado == 0) {
	
		erromessage += "- Estado\n";
		status = false;
	
	}

	if(cidade == 0) {
	
		erromessage += "- Cidade\n";
		status = false;
	
	}

	if(!comentario) {
	
		erromessage += "- Comentário\n";
		status = false;
	
	}
	
	if (status == false){
		
		alert(erromessage);
		return false;
		
	} else {

		$("#btnenviar").attr("disabled","disabled");
		$("#btnenviar").attr("value","Enviando...");
		$("#frmcoment").attr("action",urlsite+"getMural.asp"); 
		$("#frmcoment").submit();
		
	}
	
}

function enqueteSite(action,codenq) {
	
	if (action == '0') {
		if (jQuery("#poll input:checked").length == 0) {
			alert("Por favor! Escolha uma das opções disponíveis!");
		}
	}
	
	opcao = jQuery("#poll input:checked").val();
	
	jQuery.ajax({
		url:urlsite+"ajax/enqueteSite.asp",
		type:"GET",
		data:"acao=" + action + "&codenq=" + codenq + "&opcao=" + opcao,				
		success:function(response) {
			
			jQuery("#poll").html(response);
	
		}
		
	});
		
	
}

//Function to open pop up window
function openWin(theURL,winName,features) {
  	window.open(theURL,winName,features);
}

// Texto obj Pesquisa
function limpaInput(obj,msg){
	
	if (jQuery("#"+obj).val() == msg) {
		jQuery("#"+obj).val('');
	}
	
}
	
function mostraInput(obj,msg){

	if (jQuery("#"+obj).val() == '') {
		jQuery("#"+obj).val(msg);;
	}

}

function tipoBusca(tipo){
	/*
	0 - Tribuna
	1 - Google
	*/
	
	if (tipo == 1) {

		jQuery("#cse-search-box").attr({ 
			  action: "http://www.google.com.br/cse",
			  target: "_blank"		
			});

	} else {
		
		jQuery("#cse-search-box").attr({ 
			  action: urlsite+"busca.asp",
			  target: "_blank"		
			});

	
	}
	
}

function buscaNoticia(){

	if (jQuery("#q").val() == "Procuro por...") {
		
		alert("Preencha o campo Busca!");
		return false;
		
	}

}

function fontSize(action, container){
    container = typeof(container) != 'undefined' ? container : "div#HOTWordsTxt" //se não for especificado um container será "div.texto"
    baseSize = parseInt($(container+" p").css("font-size")) //extraímos o font-size padrão, tomando como base o p do nosso container
 
    $els = $(container).children()
 
    $els.each(function(){
        $fs = parseInt($(this).css("font-size"))
        if(action=="plus" && baseSize<16) $fs+=1
        else if(action=="minus" && baseSize>13) $fs-=1
        $(this).css("font-size", $fs)
    })
}

jQuery(function(){
    jQuery(".decrease").click(function(){ fontSize("minus") }).blur() //blur() aqui remove o foco do elemento, logo após o clique
    jQuery(".increase").click(function(){ fontSize("plus") }).blur()
})

function PrevisaoTempo(){
	
	jQuery.post(urlsite+"previsaotempo/PrevisaoTempo.asp", 
				{selectCidade: jQuery("#selectCidade").val()},
				
				function(resultado){
					
					jQuery("#previsaotempo").html(resultado);
					
	});
	
}

function fotosRotativas(posFoto,liSelected){
	
	var totalfotos = 4;
	
	for(icont = 0; icont <= totalfotos;icont++){
	
		jQuery("#foto_pos_"+icont).css("display","none");
		jQuery("#passador_thumb_"+icont).removeClass("jcarousel-tango-selected");
		
	}
	
	jQuery("#foto_pos_"+posFoto).css("display","block");
	jQuery("#"+liSelected).addClass("jcarousel-tango-selected");

}

function passadorFoto(){
	
	featuredcontentglider.init({
		gliderid: "canadaprovinces", //ID of main glider container
		contentclass: "glidecontent", //Shared CSS class name of each glider content
		togglerid: "p-select", //ID of toggler container
		remotecontent: "", //Get gliding contents from external file on server? "filename" or "" to disable
		selected: 0, //Default selected content index (0=1st)
		persiststate: true, //Remember last content shown within browser session (true/false)?
		speed: 1000, //Glide animation duration (in milliseconds)
		direction: "rightleft", //set direction of glide: "updown", "downup", "leftright", or "rightleft"
		autorotate: true, //Auto rotate contents (true/false)?
		autorotateconfig: [5000, 5] //if auto rotate enabled, set [milliseconds_btw_rotations, cycles_before_stopping]
	})
}