/*# retorna número da versão do ID instalado */
function getIEVersion() {
	var ua = navigator.userAgent;
	var MSIEOffset = ua.indexOf("MSIE ");

	if (MSIEOffset == -1) {
		return 0;
	} else {
		return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
	}
}

 // frase padrão do campo BUSCA
function buscaDefault(objCampo) {
	if (objCampo.value == '') {
		objCampo.value = 'Busca';
	}
}

// limpa campo BUSCA
function buscaClean(objCampo) {
	if (objCampo.value == 'Busca') {
		objCampo.value = '';
	}
}

// tratamento para links externos inseridos nos menus dinâmicos
function LinkExternoBlank(campo) {
	var lkItem = campo.getElementsByTagName('a')[0];
	
	if (lkItem.getAttribute('target')) {
		// link EXTERNO
		window.open(lkItem.href);
	} else {
		// link INTERNO
		top.location.href = lkItem.href;
	}
}

function exibirOcultarMapa(id, mapa, src) {

    if (document.getElementById(mapa).style.display == "none") {
        document.getElementById(mapa).style.display = "block";
        document.getElementById(mapa).src = src;
        document.getElementById("im" + id).src = "../Imagens/layout/im_07.gif";
    }
    else {
        document.getElementById(mapa).style.display = "none";
        document.getElementById(mapa).src = "";
        document.getElementById("im" + id).src = "../Imagens/layout/im_06.gif";
    }
}

function imprimirMapa() {

    window.print();
}

// navigation functions
function DestacaLink(navName) {
  
	if (navName.length == 0) return;

	var obj_link = document.getElementById(navName);

	if (obj_link.className != 'nav-select') {
		obj_link.className = 'nav-select';
	}
}

function DestacaLinkMenu(navName) {
  
	if (navName.length == 0) return;

	var obj_link = document.getElementById(navName);

	if (obj_link.className != 'lnav-select') {
		obj_link.className = 'lnav-select';
	}
}

function DestacaLinkSubMenu(navName) {
  
	if (navName.length == 0) return;

	var obj_link = document.getElementById(navName);

	if (obj_link.className != 'lnav-2-select') {
		obj_link.className = 'lnav-2-select';
	}
}

function navOn(navName) {
	if (document.getElementById) {
		if (document.getElementById(navName).className != 'nav-select') {
			document.getElementById(navName).style.background = '#a28f7f';
		}
	}
}

function navOff(navName) {
	if (document.getElementById) {
		if (document.getElementById(navName).className != 'nav-select') {
			document.getElementById(navName).style.background = '#73563f';
		}
	}
}

function dnavSelect(navName) {
	if (document.getElementById) {
		document.getElementById(navName).className = 'dnav-select';
	}
}

function dnavOn(navName) {
	if (document.getElementById) {
		if (document.getElementById(navName).className != 'dnav-select') {
			document.getElementById(navName).style.backgroundColor = '#ede9e6';
		}
	}
}

function dnavOff(navName) {
	if (document.getElementById) {
		if (document.getElementById(navName).className != 'dnav-select') {
			document.getElementById(navName).style.backgroundColor = '#ffffff';
		}
	}
}

function showMenu(divName) {
	if (divName.length == 0) return;
	if (!document.getElementById(divName)) return;

	if (document.getElementById) {
		document.getElementById(divName).style.display = 'block';
	}
}

function hideMenu(divName) {
	if (divName.length == 0) return;
	if (!document.getElementById(divName)) return;

	if (document.getElementById) {
		document.getElementById(divName).style.display = 'none';
	}
}

// investor info change

function showInv1() {
	if (document.getElementById) {
		document.getElementById('inv-tab-l-a').style.color = '#000000';
		document.getElementById('inv-tab-r-a').style.color = '#cc3300';
		document.getElementById('inv-tab-l-p').style.borderTop = '4px solid #e44c16';
		document.getElementById('inv-tab-r-p').style.borderTop = '4px solid #c1b5aa';
		document.getElementById('inv-info1').style.display = 'block';
		document.getElementById('inv-info2').style.display = 'none';
	}
}

function showInv2() {
	if (document.getElementById) {
		document.getElementById('inv-tab-l-a').style.color = '#cc3300';
		document.getElementById('inv-tab-r-a').style.color = '#000000';
		document.getElementById('inv-tab-l-p').style.borderTop = '4px solid #c1b5aa';
		document.getElementById('inv-tab-r-p').style.borderTop = '4px solid #e44c16';
		document.getElementById('inv-info1').style.display = 'none';
		document.getElementById('inv-info2').style.display = 'block';
	}
}


// investor info callout change

function showInvCallout1() {
	if (document.getElementById) {
		document.getElementById('inv-call-tab-l-a').style.color = '#000000';
		document.getElementById('inv-call-tab-r-a').style.color = '#cc3300';
		document.getElementById('inv-call-info1').style.display = 'block';
		document.getElementById('inv-call-info2').style.display = 'none';
	}
}

function showInvCallout2() {
	if (document.getElementById) {
		document.getElementById('inv-call-tab-l-a').style.color = '#cc3300';
		document.getElementById('inv-call-tab-r-a').style.color = '#000000';
		document.getElementById('inv-call-info1').style.display = 'none';
		document.getElementById('inv-call-info2').style.display = 'block';
	}
}

// content tabs change

function showContent1() {
	if (document.getElementById) {
		document.getElementById('content-tab-l-a').style.color = '#000000';
		document.getElementById('content-tab-r-a').style.color = '#a28f7f';
		document.getElementById('content-tab-l').style.borderBottom = '1px solid #ffffff';
		document.getElementById('content-tab-l-p').style.borderTop = '4px solid #e44c16';
		document.getElementById('content-tab-r').style.borderBottom = '1px solid #e4e2cf';
		document.getElementById('content-tab-r-p').style.borderTop = '4px solid #c1b5aa';
		document.getElementById('content-info1').style.display = 'block';
		document.getElementById('content-info2').style.display = 'none';
	}
}

function showContent2() {
	if (document.getElementById) {
		document.getElementById('content-tab-l-a').style.color = '#a28f7f';
		document.getElementById('content-tab-r-a').style.color = '#000000';
		document.getElementById('content-tab-l').style.borderBottom = '1px solid #e4e2cf';
		document.getElementById('content-tab-l-p').style.borderTop = '4px solid #c1b5aa';
		document.getElementById('content-tab-r').style.borderBottom = '1px solid #ffffff';
		document.getElementById('content-tab-r-p').style.borderTop = '4px solid #e44c16';
		document.getElementById('content-info1').style.display = 'none';
		document.getElementById('content-info2').style.display = 'block';
	}
}

// dropdown select location change
function sel(Url) {
	if (Url) {
		window.open(Url, "_blank");
	}
}

// open a popup window
function openwin(url, w, h, s) {
	var scrl;
	if (s) { scrl = "scrollbars=yes,"; w = w + 16; }
	else { scrl = "scrollbars=no,"; }

	if (!w) w = 640;
	if (!h) h = 480;

	fenster = window.open(url, "_blank", scrl + "resizable=yes,width=" + w + ",height=" + h + ",screenX=50,screenY=50");

	if (fenster == null) {
	    alert('Por favor, desabilite todos os bloqueadores de pop-ups!');
	    return;
	}
	else {
	    fenster.focus();
	}
}

//hide/show lang dropdown when onmouseover/onmouseout on main navigation
function showHideLang() {
	if (document.getElementById) {
		lang_container = document.getElementById('lang-container');
		if (lang_container) {
			if (lang_container.style.visibility == 'hidden') {
				lang_container.style.visibility = 'visible';
			} else {
				lang_container.style.visibility = 'hidden';
			}
		}
	}
}

// JavaScript Server Side Includes - XML Requests

function funcClientSideInclude(id, url) {
	var req = false;

	// Safari, Firefox, and other non-MS browsers
	if (window.XMLHttpRequest) {
		try {
			req = new XMLHttpRequest();
		}
		catch (err) {
			req = false;
		}
	}
	else if (window.ActiveXObject) {
		// For Internet Explorer on Windows
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (err) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (err) {
				req = false;
			}
		}
	}

	var element = document.getElementById(id);
	if (!element) {
		alert("ID error: " + id + " passed to clientSideInclude. You need a div or span element with this id in your page.");
		return;
	}

	if (req) {
		// Synchronous request
		req.open('http://www.novartis.com.br/GET', url, false);
		req.send(null);
		element.innerHTML = req.responseText;
	}
	else {
		element.innerHTML =
	"Sorry, your browser does not support XMLHTTPRequest objects. This page requires Internet Explorer 5 or better for Windows, or Firefox for any system, or Safari. Other compatible browsers may also exist.";
	}
}

var excludeUrls = Array();
function excludeUrl(url) {
	for (var l = 0; l < excludeUrls.length; l++) {
		if (url.indexOf(excludeUrls[l]) == 0) {
			return true;
		}
	}
	return false;
}

/*******************************************************************************
Desenvolvido em:    18/12/2008							Autor:	CARLOS MONTEIRO
Funcionalidade:	    Permite digitar apenas números
*******************************************************************************/
function SoNumeros(evtKeyPress) {
	var nTecla;

	nTecla = (evtKeyPress.which) ? evtKeyPress.which : evtKeyPress.keyCode;

	if ((nTecla > 47 && nTecla < 58) || nTecla == 8 || nTecla == 9) {
		return true;
	}
	else {
		return false;
	}
}

/*******************************************************************************
Desenvolvido em:    19/01/2008							Autor:	CARLOS MONTEIRO
Funcionalidade:	    Permite digitar apenas números
*******************************************************************************/
function ExibeNovaCategoria(exibir) {

	if (exibir == 1) {
		document.getElementById("dvNovaCategoria").style.display = "block";
		document.getElementById("lkNovaCategoria").style.display = "none";
	}
	else {
		document.getElementById("dvNovaCategoria").style.display = "none";
		document.getElementById("lkNovaCategoria").style.display = "block";
	}
}

function ConfirmaExclusaoMassa() {
	var resposta = confirm('A exclusão desta categoria excluirá todas as perguntas relacionadas a ela.\n\nDeseja realmente excluir esta categoria?');

	if (resposta) {
		Mensagem("Dados excluídos com sucesso");
	}

	return resposta
}

/*******************************************************************************
Desenvolvido em:    04/02/2009						Autor:THIAGO DE ASSIS LUCA
Funcionalidade:	    Abre O div com as informações das paginas e campos
*******************************************************************************/
function mostraInformacoes(id) {
	var current = document.getElementById(id);
	if (current.style.display == 'none') {
		current.style.display = 'block';
		//window.setTimeout(ocultaInformacoes,8000);
	}
}

function ocultaInformacoes(id) {
	var current = document.getElementById(id);
	if (current.style.display == 'block') {
		current.style.display = 'none';
	}
}

/***************************************************************************************
Desenvolvido em:    05/02/2009						Autor:  THIAGO DE ASSIS LUCA
Alterado em:        12/02/2009						Autor:  CARLOS MONTEIRO

Funcionalidade:	    Recupera a posição do mouse em coordenadas x e y e abre o Pie Menu
****************************************************************************************/
var pieID = "";
function abrePieMenu(event, id) {

	fechaPieMenu();

	// Captura a posição do mouse descontando a barra de rolagem (crossbrowser)
	// A atribuição do valor da variável funciona como um if inline: x = (IE) || (Outros) || 0; 
	var x = (event.clientX + document.documentElement.scrollLeft) || (event.clientX + window.pageXOffset) || 0;
	var y = (event.clientY + document.documentElement.scrollTop) || (event.clientY + window.pageYOffset) || 0;

	var current = document.getElementById('pieMenu' + id);

	pieID = id;

	if (current.style.display == 'none') {

		current.style.display = 'block';
		current.style.top = y + 'px';
		current.style.left = x + 'px';

		setTimeout(fechaPieMenu, 10000);
	}
}

function fechaPieMenu() {
	if (pieID == "") {
		return;
	}
	else {
		var current = document.getElementById('pieMenu' + pieID);
		if (current.style.display == 'block') {

			current.style.display = 'none';
			current.style.top = 0;
			current.style.left = 0;
		}
	}
}

function ConfirmaExclusao() {
	var resposta = confirm('Deseja realmente excluir este registro?');

/*	if (resposta) {
		alert('Dados excluídos com sucesso');
	}
*/
	return resposta
}

/*# garante que a senha terá mais de 8 caracteres */
function VerificaSenha(src, args) {
	if (args.Value.length < 8)
		args.IsValid = false;
	else
		args.IsValid = true;
}

function RedirecionarErro(url, tempo) {
    setInterval("RedirecionaPagina('" + url + "'," + tempo + ")", 1000);
}

function RedirecionaPagina(url, tempo){

    var cont = document.getElementById("ctl00$ContentPlaceHolder1$txtContar");

    cont.value = parseInt(cont.value) + 1;

    if (cont.value == tempo) {
        parent.location.href = url;
    }
}

function trataAvisoCRM() {

    var conselho    = document.getElementById("ctl00$content$ddlNrRefConselho").value;
    var uf          = document.getElementById("ctl00$content$ddlSgUf").value;
    
    if (conselho == 1 && uf == "RJ") {
        document.getElementById("divAviso").style.display = "block";
    }
    else {
        document.getElementById("divAviso").style.display = "none";
    }    
 }