$(document).ready(function(){

	// recupera valores de parametros da URL corrente
	var paramView = jQuery.url.param("view");
	var paramApp = jQuery.url.param("app");
	var paramIdConteudo = jQuery.url.param("idConteudo");
	var paramIdNoticia = jQuery.url.param("idNoticia");
	var indexAtual;
	
	// ANIMAÇÃO COMBOBOX TIPO DE PLANOS: PARA SUA EMPRESA >> UNIMED PAULISTANA >> REDE CREDENCIADA
	$('#select-tipoPlano').change(function() {
        $('.tipo-plano').css('display','none');
        if($(this).val()!="default"){
        	$('#'+$(this).val()).show(); 
        }
	});
	
	//MOSTRA NOTICIA SOMENTE QD TIVER IDNOTICIA.
	if(paramIdNoticia != null){
		$(".prt-noticia-view-lista").css('display','block');	
	}
	

	
	// IFRAME OUVIDORIA	
	$('#id-iframe-ouvidoria').load( function(){
        $(this.contentDocument).find('.menu_acoes #botao_menu:first-child').hide();
        $(this.contentDocument).find('.icone_acao_fixo').hide();
        $(this.contentDocument).find('#componenteVisualarquivoOcorrencia').hide();
        $(this.contentDocument).find('body').css('background','transparent');
        $(this.contentDocument).find('table.delimitador').css('background','transparent');
        $(this.contentDocument).find('table.delimitador tr:nth-child(9)').hide();
        $(this.contentDocument).find('table.delimitador tr:nth-child(8)').hide();
        $(this.contentDocument).find('table.delimitador tr:nth-child(7)').hide();
        $(this.contentDocument).find('table.delimitador tr:nth-child(6)').hide();       
        $(this.contentDocument).find('table.delimitador tr:nth-child(5)').hide();
        $(this.contentDocument).find('table.delimitador tr:nth-child(4)').hide();   
        $(this.contentDocument).find('td.secao').addClass('ouvidoria');
        $(this.contentDocument).find('td.secao').toggleClass('secao');
        $(this.contentDocument).find('.ouvidoria').css('color','#777777');
        $(this.contentDocument).find('.ouvidoria').css('font-weight','bold');
        $(this.contentDocument).find('.campo').css('padding', '0');
        $(this.contentDocument).find('.campo').css('margin', '0');
        $(this.contentDocument).find('.campo').css('width','auto');
       /* $(this.contentDocument).find('table.delimitador:nth-child(2) td.titulo:first-child').hide();
        $(this.contentDocument).find('table.delimitador:nth-child(2) td.campo:first-child').hide();*/
        
        $(this.contentDocument).find('table.delimitador input[type=text]').css('width','130px');
        $(this.contentDocument).find('table.delimitador input[type=text]').css('margin','0px');
        $(this.contentDocument).find('table.delimitador input[type=text]').css('margin-right','0px');
        $(this.contentDocument).find('table.delimitador input[type=text]').css('padding','0px');
        $(this.contentDocument).find('table.delimitador select').css('width','140px');
        $(this.contentDocument).find('table.delimitador select').css('margin-right','10px');
        $(this.contentDocument).find('.campo textarea').css('height','100px');
        $(this.contentDocument).find('.campo textarea').css('width','300px');
       
	})
	
    /* Verifica se a página não é inicial e se é interna*/
    if(typeof paramView != "undefined" && paramView.indexOf("interna")> -1){

          // Adiciona classes CSS Menu à esquerda = 160pxl |12px| Conteúdo = 378px |22px|
         $(".coluna4Corpo").addClass("colunaMenu");
         $(".coluna3Corpo").addClass("colunaConteudo");
         $(".coluna2Corpo").addClass("colunaDireita");
         $(".tableCorpo").addClass("tableMiolo");
    }

    if(paramApp == "portalatendimento"){
        // Adiciona classes CSS Menu à esquerda = 160pxl |12px| Conteúdo = 378px |22px|
       $(".coluna4Corpo").addClass("colunaMenu");
       $(".coluna3Corpo").addClass("colunaConteudo");
       $(".coluna2Corpo").addClass("colunaDireita");
       $(".tableCorpo").addClass("tableMiolo");
    }
    
    /* ALTERA MENSAGEM DE STATUS DA PÁGINA PARA CONCLUÍDO 
     * Apenas para ie - ffx é protegido nas preferências do usuário */
    window.status="Concluido";
    
   
    
    
    
    //----------------------------- altera URL - link Chat Online e Newsletter-------------------------------------
    // Valor que define a comunidade (final da URL em chat online e newsletter)
    var numComunidade="";
    var nomComunidade="";
    var newsTitulo="";
    /* Verifica qual é a comunidade corrente e insere seu valor (newsletter)*/
    if( paramView == "newsletter" & paramApp == "portalpravoce" ){
    	newsTitulo="Newsletter - Para Voce";
    	$("#PRT-FORMULARIO .cabecalho").html(newsTitulo);
    }
    else if( paramView == "newsletter" & paramApp == "portalempresa" ){
    	newsTitulo="Newsletter - Empresa";
    	$("#PRT-FORMULARIO .cabecalho").html(newsTitulo);
    }
    else{
    	newsTitulo="Newsletter";
    }
    
    /* Verifica qual é a comunidade corrente e insere seu valor (chat online)*/
    if( paramApp == "portalpravoce" ){
    	numComunidade="25870";
    	nomComunidade = "portalpravoce";
    	$(".praVoce").addClass("praVoceSelecionado");
        $(".colunaEsquerda").hide();
    	$(".colunaTopo").hide();
    	$(".alteraLinkFaleForm").attr("href", $(".alteraLinkFaleForm").attr("href").replace("portalqualicorp", nomComunidade));
    	
    	// chamado 2613
    	$("#iframe").css("width","555");
    	
    }
    else if( paramApp == "portalempresa" ){
    	numComunidade="25868";
    	nomComunidade = "portalempresa";
    	$(".praEmpresa").addClass("praEmpresaSelecionado");
        $(".colunaEsquerda").hide();
    	$(".colunaTopo").hide();
    }
    else if( paramApp == "portalentidade" ){
    	numComunidade="25869";
    	nomComunidade = "portalentidade";
    	$(".entidade").addClass("entidadeSelecionado");
        $(".colunaEsquerda").hide();
    	$(".colunaTopo").hide();
    	$(".alteraLinkFaleForm").attr("href", $(".alteraLinkFaleForm").attr("href").replace("portalqualicorp", nomComunidade));
    }
    else if( paramApp == "portalcorretoraberto" ){
    	$(".corretor").addClass("corretorSelecionado");
    }
    else if( paramApp == "portalqualicorp" | paramApp == "portalsaude" | paramApp == "portalatendimento" | paramApp == null ){
    	numComunidade="32578";
    	nomComunidade = "portalqualicorp";
        $(".colunaEsquerda").hide();
    	$(".colunaTopo").hide();
    }
    else{
    	numComunidade="32578";
    	nomComunidade="portalqualicorp";  
    }
    // Altera URL dinamicamente Fale Conosco
    $(".alteraLinkFale").each(
			function () {
				$(this).attr("href", $(this).attr("href").replace("000", numComunidade));
			}
	);

    // Altera URL dinamicamente Cadastre-se Newsletter
    $(".cadastreNews").each(
			function () {
				$(this).attr("href", $(this).attr("href").replace("aplicacao", nomComunidade));
			}
	);
    
    //------------------------------------------------------------------------------
    
    // LAYOUT TABS
    $('#container-1 > ul').tabs(); // inicializacao tabfolder
	$("table").attr('cellpadding','0').attr('cellspacing','0').attr('cellPadding','0').attr('cellSpacing','0');
	
	// MENU FIXO
	$(".hoverswap").hover(
			function () {
				$(this).attr("src", $(this).attr("src").replace(/.gif/, "_f2.gif"));
			},
			function () {
				$(this).attr("src", $(this).attr("src").replace(/_f2.gif/, ".gif"));
			}
	);
	
	//MENU LATERAL - ACCORDION
	$('#navigation li li').hover(	
		function(){
			var x = $(this).next();
			x.children().addClass("menuHover");
			
		},
		function(){ 
			var x = $(this).next();
			x.children().toggleClass("menuHover");
			
		}
	);
	
	//MENU LATERAL - TABLE
	
	$('table.menu tr td table tr td.menu_item').hover( 
	function() {
		    $(this).next('.menu_item').css('background', '#025896');
		    /*alert($(this));*/
		  /*$(this).children().addClass("menu-hover");*/
		  /*$(this).children().css('background', 'black');*/
	});
	
	/*$('table.menu tr:nth-child(2) td').addClass("menu-espaco");
	$('table.menu table tr:nth-child(2) td.menu_item a').addClass("menu-primeirolink");*/
	
		/*$('table.menu tr td table tr td.menu_item').hover(
		function() {
		
		return this.each(function(){
				  
				  $(this).addClass("menu-hover");
				  
				    if (this.host != window.location.host) {
			        $(this).attr('target', '_new');
			        alert($(this));
				    }
		});
});
	*/
	
	//RETIRA BARRA LATERAL DIREITA PARA PAGINAS QUE PRECISAM: idConteudo=20235 ou idConteudo=20239
	if(paramIdConteudo=="20235" || paramIdConteudo=="20239" ){
	   $("td.coluna2Corpo").hide();
	   $("table.tableMiolo").css("width","100%");
	   $("td.coluna1Corpo").css("width","100%");
	}
	
	//RETIRA SUBMENU - PARA SUA EMREPSA
	if(paramIdConteudo=="20003" || paramIdConteudo=="20006" || paramIdConteudo=="20007" || paramIdConteudo=="20008" || paramIdConteudo=="20010"  ){
		$("table.menu tr:nth-child(2)").hide(); 
		
		$("table.menu tr:nth-child(1) table tr").css('display', '');
	}
	else if(paramIdConteudo="20012" || paramIdConteudo=="20014" || paramIdConteudo=="20013" || paramIdConteudo=="20011" ){
		$("table.menu tr:nth-child(1)").hide();
		$("table.menu tr:nth-child(2) table tr").css('display','')
	}

	
	
	/*para browsers sem suporte a CSS3*/
	$('#navigation li li:first-child a').css('border-top','none');
	$('#navigation li li:last-child a:hover').css('border-bottom','none');
	
	// MENU FIXO 2 - COM HOVER
	$(".textoPraVoce").hide();	
	$(".textoPraEmpresa").hide();	
	$(".textoCorretor").hide();	
	$(".textoEntidade").hide();	
	
	$("div.praVoce").hover(function (){
			$(this).addClass("praVoceOver");
			$(".linkPraVoce").show();
			$(this).prepend("<p class='imgMenuFixo2' width='198px'><a href='/qualicorp/ecp/comunidade.do?app=portalpravoce'><img  class='imgPraVoce' src='/qualicorp/midia/home_titulo_pravoce.gif'/></a></p>");	    	
			$(".textoPraVoce").show();	
		},
		function (){
			$(this).removeClass("praVoceOver");
			$(".imgMenuFixo2").hide();
			$(".textoPraVoce").hide();	
	});
	
	$("div.praEmpresa").hover(function () {
			$(this).addClass("praEmpresaOver");
			$(".linkPraEmpresa").show();
			$(this).prepend("<p class='imgMenuFixo2'><a href='/qualicorp/ecp/comunidade.do?app=portalempresa'><img class='imgPraEmpresa' src='/qualicorp/midia/home_titulo_praempresa.gif'/></a></p>");
			$(".textoPraEmpresa").show();
		},function(){
			$(this).removeClass("praEmpresaOver");
			$(".imgMenuFixo2").hide();
			$(".textoPraEmpresa").hide();
			$(".imgPraEmpresa").parent().remove();
		});
	
	// mudança para que o link 
	var linkCorretor = '';
	if(document.getElementById('usuarioLogadoHidden')){
		if(document.getElementById('usuarioLogadoHidden').value == 'N')
		{
			linkCorretor = "<p class='imgMenuFixo2'><a href='/qualicorp/ecp/comunidade.do?app=portalcorretoraberto'><img class='imgCorretor' src='/qualicorp/midia/home_titulo_corretores.gif'/></a></p>";
		}	
		else
		{	
			linkCorretor = "<p class='imgMenuFixo2'><a href='/qualicorp/ecp/comunidade.do?app=portaldocorretor'><img class='imgCorretor' src='/qualicorp/midia/home_titulo_corretores.gif'/></a></p>";
			$(".linkCorretor").attr('href','/qualicorp/ecp/comunidade.do?app=portaldocorretor');
		}
	}
	
	$("div.corretor").hover(function (){
			$(this).addClass("corretorOver");
			$(".linkCorretor").show();
			$(this).prepend(linkCorretor);
			$(".textoCorretor").show();
		},function () {
			$(this).removeClass("corretorOver");
			$(".imgMenuFixo2").hide();
			$(".textoCorretor").hide();
			$(".imgCorretor").parent().remove();
		});
	
	$("div.entidade").hover(function () 
			{
		$(this).addClass("entidadeOver");
		$(".linkEntidade").show();
		$(this).prepend("<p class='imgMenuFixo2' style='margin-left:1px;'><a href='/qualicorp/ecp/comunidade.do?app=portalentidade'><img class='imgEntidade' src='/qualicorp/midia/home_titulo_entidade.gif'/></a></p>");	  
		$(".textoEntidade").show();
			},function () 
			{
		$(this).removeClass("entidadeOver");
		$(".imgMenuFixo2").hide();
		$(".textoEntidade").hide();
		$(".imgEntidade").parent().remove();
			});     
	$("td.blog").css('padding-right','10px').css('padding-top','15px').css('vertical-align','top');

	//ALTERA CSS PARA FIREFOX 2
	jQuery.each(jQuery.browser, function(i, val) {
		  if(i=="mozilla" && jQuery.browser.version.substr(0,3)=="1.8")
			$(".resumoLancamento").css('padding-bottom','5px');
			$("#PRT-FORM-BT-CONFIRMAR-QLC").css('padding-top','0px');
			$("#PRT-FORM-BT-LIMPAR-QLC").css('padding-top','0px');
//			$(".menuFixo2").css('width','798px');
	});
	//ALTERA CSS PARA FIREFOX 3
	jQuery.each(jQuery.browser, function(i, val) {
		  if(i=="mozilla" && jQuery.browser.version.substr(0,3)=="1.9")
			$("#PRT-FORM-BT-CONFIRMAR-QLC").css('padding-top','0px');
			$("#PRT-FORM-BT-LIMPAR-QLC").css('padding-top','0px');
//			$(".menuFixo2").css('width','798px');
	});
	
	
	//PAGINACAO - por causa do IE6
	$('.noticia-bt-ultima.noticia-bt-numero-selected').addClass('ultima-selected')
	$('.noticia-bt-primeira.noticia-bt-numero-selected').addClass('primeira-selected')
	$('#nav a:first-child').addClass('paginacao-item1');

	//ALTERA CSS BLOG
	$(".tableBlogMes td").addClass('arquivoBorda');
	$(".tableArquivo tr .arquivoBorda:first-child").addClass('first');
	$(".first").css('border-left','0px');
	$(".tableArquivo tr .arquivoBorda:last-child").addClass('last');
	$(".last").css('border-right','0px');
	$(".tableArquivo tr:last-child td").addClass('bottom');
	$(".bottom").css('border-bottom','0px');
	$("li.proximo:nth-child(n+1)").css('background-color', 'black');
	
	
	
	$(".arquivoBorda").css('padding','1px');	

	$(".tabComentarios").tablesorter( {sortList: [[1,1]] } );
	$(".colunaLateralEsquerda").css('width','40px');
	$(".colControle").hide();
	$(".tabComentarios th.header").hide();
	
	$(".mesCorrente").each(function() {
		var $this = $(this);
		var t = $this.text();
		$this.text(t.replace('/',' '));
	});
	
	$(".alteraLink").click(
			function () {
				$(this).attr("href", $(this).attr("href").replace("refresh=s", "refresh=s&view=blog"));
			}
	);
	
	// Altera CSS Para Empresa - Saude
	$(".ui-tabs-panel p:last-child").css('padding','0');
		
	// Esconde botões padrão do portlet de formulário
	$("#PRT-FORM-BT-CONFIRMAR").hide();
	$("#PRT-FORM-BT-LIMPAR").hide();	
	$("#PRT-FORMULARIO .cabecalho").hide();

	// Remove atributo style do elemento retornando a fonte a seu tamanho original
	$(".aumentaFonte").click(function(){
		++tamanhoPadrao;
		alert(tamanhoPadrao);
		if(tamanhoPadrao == 0) {
			alert("remove!");
			var docEl = document.getElementsByTagName("*"); 
			alert(docEl.length);
			for(var i=0; i<=docEl.length; i++){
				alert($(this).css("font-size"));
				$(this).css("font-size","");
				alert($(this).css("font-size"));
			}
		}
	});	
		
	$(".diminuiFonte").click(function(){
		--tamanhoPadrao;
		alert(tamanhoPadrao);
		if(tamanhoPadrao == 0) {
			alert("remove!");
			var docEl = document.getElementsByTagName("*");
			alert(docEl.length);
			for(var j=0; j< docEl.length;j++){
				alert("antes: "+$(this).css("font-size"));
				$(this).css("font-size","");
				alert("depois: "+$(this).css("font-size"));

			}
		}
	});
	
	
	
		
});

		/*AUMENTAR E REDUZIR FONTE */
		var sizes = new Array('10', '12', '14', '16');
		var si = 1;
		function setFontByTag(e, v) {
			try {	
				var elements = document.getElementsByTagName(e);
				for(var i = 0; i < elements.length; i++) {
					elements.item(i).style['fontSize'] = v;
				}
				var iframes = window.frames;
				for(var i = 0; i < iframes.length; i++) {
					var documentIframe = iframes[0].document;
					var elementsIframe = documentIframe.getElementsByTagName(e);
					for(var i = 0; i < elementsIframe.length; i++) {
						elementsIframe.item(i).style['fontSize'] = v;
					}
				}
			} catch (e) {

			}
		}

		function changeSize(inc) {
			try {
				if (!document.getElementsByTagName) {return false;}
				// If the browser doesn't support
				// getElementsByTagName then don't do anything
				if (inc == '1') {
					si+=1;
					if (si>4) {
						si = 4; 
						size=4;
					}
				} else if (inc == '-1') {
					si-=1;
					if (si<0) {
						si = 0;
						size=0;
					}
				}
				setFontByTag('*', sizes[si]+'px');
			} catch (e) {

			}
		}

		/*IMPRESSAO */

		function DoPrinting(){
			if (!window.print){
				alert("Use o Netscape  ou Internet Explorer \n nas versões 4.0 ou superior!")
				return
			}
			window.print()
		}
		
