﻿function ApenasNumeros(campo, e, dec) { 
    var chave; 
    var caracter; 
    if (window.event) 
        chave = window.event.keyCode;
    else if (e) 
        chave = e.which;
    else 
        return true; 
        
    caracter = String.fromCharCode(chave);

    if ((chave == null) || (chave == 0) || (chave == 8) || (chave == 9) || (chave == 13) || (chave == 27))
        return true; 
    else if ((("0123456789").indexOf(caracter) > -1)) 
        return true; 
    else if (dec && (caracter == ".")) { 
        campo.form.elements[dec].focus();
        return false; 
    }else 
        return false; 
}

function changeStatus(obj,origem,st){
	if(origem == 'menu' &&obj.parentNode.className != 'selecionado'){
		if(st == 'on'){
			obj.parentNode.className = 'over';
		}
		else obj.parentNode.className = '';
	}
	if(origem == 'destaque'){
		if(st == 'on'){
			obj.className = 'destaquePrincipalSelecionado'
		}
		else obj.className = 'destaquePrincipal';
	}
}

// função para alterar o tamanho da fonte do site
var tam = 10; // tamanho padrão
var tamMax = 11; // tamanho maximo
var tamMin = 9; // tamanho minimo

function mudaFonte(obj) {
	switch (obj) {
	    case '+':
	        if(tam < tamMax) tam = tam + 1;
	        break;
	    case '-':
			if(tam > tamMin) tam = tam - 1;
	        break;		
	}
	document.body.style.fontSize = tam + 'px';
}

var valorOriginal;
function clearField(obj,valor){
	if(valor == obj.value){
		valorOriginal = obj.value
		obj.value = '';
	}		
}

function returnField(obj){
	if(obj.value == ''){
	    if(!(valorOriginal = '')){
		    obj.value = valorOriginal;
		    valorOriginal = '';
		}
	}
}

function mnExtranet(obj, act) {
    if (obj.className != 'sel') {
        if (act == 'on') {
            obj.className = 'on';
        } else {
            obj.className = '';
        }
    }
}

function showHide(obj){
    if(document.getElementById(obj).style.display == 'block'){
        document.getElementById(obj).style.display = 'none';
    }else document.getElementById(obj).style.display = 'block';
}

function fecharPopLembrarSenha(){
    document.getElementById('lembraSenha').style.display = 'none';
}

function abrirPopLembrarSenha() {
    document.getElementById('topo1_txtCpf').value = '';
    document.getElementById('lembraSenha').style.display = 'block';
}

function selecionaItemMenu(objSelecionado){
    limpaItemMenu();
    document.getElementById(objSelecionado).className = 'png sel';
}
function limpaItemMenu(){
    document.getElementById('mnInicio').className = 'png';
    document.getElementById('mnRede').className = 'png';
    document.getElementById('mnPecas').className = 'png';
    document.getElementById('mnServicos').className = 'png';
    document.getElementById('mnProcedimentos').className = 'png';
    document.getElementById('mnCadastro').className = 'png';
}

function selecionaItemMenuFerramenta(obj){
    document.getElementById(obj).className = "selecionado";
}

function ApenasNumero(Campo, teclapres)
    {
        var tecla = teclapres.keyCode;
        var strCheck = '0123456789';
        var rcode = (window.Event) ? event.which : event.keyCode;
        var vr = new String(Campo.value);
        if(rcode == 13 || rcode == 0)
        {
            //Enter
            key=String.fromCharCode(rcode);
            if(rcode!=13 && rcode!=0)
            {
                return false;
            }
            return true;
        }

        //Get key value from key code
        key=String.fromCharCode(rcode);
    	
        if(strCheck.indexOf(key)==-1)
        {
            //Not a valid key
            return false;
        }
        
        //Campo.value = Campo.value + separador;
    }

    function ChamarImpressao(strid)
	{
         var prtContent = document.getElementById(strid);
         var WinPrint = window.open('','','letf=0,top=0,width=800,height=600,toolbar=0,status=0');
	     WinPrint.document.writeln( '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
         WinPrint.document.writeln( '<html' + ' xmlns="http://www.w3.org/1999/xhtml"' + '>');
         WinPrint.document.writeln( '<' + 'head>');
         WinPrint.document.writeln( '<' + 'title></' + 'title>');
         WinPrint.document.writeln( '<' + 'link href=' + '"' + '"../../css/style_impressao.css"' + '"' + ' rel=' + '"' + 'stylesheet' + '"' + ' type=' + '"' + 'text/css' + '"' + '/>');
         WinPrint.document.writeln( '</'+ 'head>');
         WinPrint.document.writeln( '<' + 'body' + 'bgcolor=#ffffff leftmargin=0 topmargin=0 marginheight="0" marginwidth="0"' + ' >');
         WinPrint.document.writeln( '<form method="post">');
         WinPrint.document.writeln( '<div id="ctContainer">');
         WinPrint.document.writeln( '<div id="ctContent">');
         WinPrint.document.writeln(prtContent.innerHTML);
         WinPrint.document.writeln( '</div>');
         WinPrint.document.writeln( '</div>');
         WinPrint.document.writeln( '</form' + '>');         
         WinPrint.document.writeln( '</' + 'body' + '>' + '</' + 'html>');
         WinPrint.document.close();
         WinPrint.document.referrer
         WinPrint.focus();
         WinPrint.print();
         WinPrint.close();
    }

function onPops(pop) {
  resizePop(pop);
  document.getElementById('bkgPops').style.display = "block";
  document.getElementById(pop).style.display = "block";
  document.getElementById('frm').style.display = "block";
}

function offPops(pop) {
  document.getElementById('bkgPops').style.display = "none";
  document.getElementById(pop).style.display = "none";
  document.getElementById('frm').style.display = "none";
}

function resizePop(pop) {
  if (!document.all) {
    document.getElementById('bkgPops').style.height = window.innerHeight + 'px';
    document.getElementById('frm').style.height = window.innerHeight + 'px';
    if (window.innerHeight < document.body.clientHeight) {
      document.getElementById('bkgPops').style.height = document.body.clientHeight + 'px';
      document.getElementById('frm').style.height = document.body.clientHeight + 'px';
    }
  } else {
    if (document.documentElement.clientHeight < document.body.clientHeight) {
      document.getElementById('bkgPops').style.height = document.body.clientHeight + 'px';
      document.getElementById('frm').style.height = document.body.clientHeight + 'px';
    } else {
      document.getElementById('bkgPops').style.height = document.documentElement.clientHeight + 'px';
      document.getElementById('frm').style.height = document.documentElement.clientHeight + 'px';
    }
  }
}
// manter isso comentado, pois isso faz parar o script de acessibilidade, fonte
//window.onresize = resizePop;

function FormataCNPJ(el,teclapres) 
{ 
    var tecla = teclapres.keyCode;
    var strCheck = '0123456789';
    var rcode = (window.Event) ? event.which : event.keyCode;
    var vr = new String(el.value);
    separador1 = '.';
    separador2 = '/'; 
    separador3 = '-';
    conjunto1 = 2;
    conjunto2 = 6;
    conjunto3 = 10;
    conjunto4 = 15;
    
    if(rcode == 13 || rcode == 0)
    {
        //Enter
        key=String.fromCharCode(rcode);
        if(rcode!=13 && rcode!=0)
        {
            return false;
        }
        return true;
	}

    //Get key value from key code
    key=String.fromCharCode(rcode);
    if(strCheck.indexOf(key)==-1)
    {
        //Not a valid key
        return false;
    }
    tam = vr.length; 
    if (tam == conjunto1)
    {
        el.value = el.value + separador1;
    }
    else if(tam == conjunto2)
    {
        el.value = el.value + separador1;
    }
    else if(tam==conjunto3)
    {
       el.value = el.value + separador2;
    }
    else if(tam==conjunto4)
    {
       el.value = el.value + separador3;
    }
    return true; 
} 

function achaAltura(obj,bloco){

    if(navigator.appName.indexOf('Internet Explorer')>0 && navigator.appVersion.indexOf('MSIE 6.0')>0){
        document.getElementById(bloco).style.top = (obj.offsetTop - document.getElementById('marcoZero').offsetTop - 10) + 'px';
        document.getElementById(bloco).style.display = 'block';
        document.getElementById('iframeAjuda').style.top = document.getElementById(bloco).style.top;
        document.getElementById('iframeAjuda').style.height = document.getElementById(bloco).offsetHeight
        document.getElementById('iframeAjuda').style.display = 'block';

    }else{
        document.getElementById(bloco).style.top = (obj.offsetTop - 5) + 'px';
        document.getElementById(bloco).style.display = 'block';
    }    
}

function fechaAjuda(obj){
    document.getElementById(obj).style.display = 'none';
    document.getElementById('iframeAjuda').style.display = 'none';
}


/**
*
* Javascript Tooltip
*
* @author Rogerio Alencar Lino Filho
* @url http://rogeriolino.wordpress.com
*
*/
/* Configura��o */
var id = "minhaTooltip";
var background = "#fff2d4";
var border = "none";
var display = "none";
var font = "13px Arial, Sans-serif";
var color = "#656565";
var marginX = 10; //distancia do mouse em x
var marginY = 0; //distancia do mouse em y
var opacity = 100; // 0 a 100
var padding = "8px";
var position = "absolute";
var _x = -10;
var _y = -10;
//
function setPos(event) {
	if (document.all) {//IE
		_x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		_y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		_x += (window.event.clientX+marginX);
		_y += (window.event.clientY+marginY);
	} else {//Good Browsers
		_x = (event.pageX+marginX);
		_y = (event.pageY+marginY);
	}
}
//
function showTip(text) {
	var t = document.getElementById(id);
	t.style.display = "block";
	document.onmousemove = function(event) {
		setPos(event);
		t.innerHTML = text;
		t.style.left = _x+"px";
		t.style.top = _y+"px";
	}
}
//
function hideTip() {
	var t = document.getElementById(id).style;
	t.display = "none";
}
//
function tooltip() {
	var body = document.getElementById("helptip");
	//body = body[0];
	document.body.innerHTML += "<div id='"+id+"' style='max-width:180px'></div>";
	var t = document.getElementById(id).style;
	t.background = background;
	t.border = border;
	t.display = display;
	t.font = font;
	t.color = color;
	t.opacity = opacity/100;
	t.filter = "alpha(opacity="+opacity+")";
	t.padding = padding;
	t.position = position;
	var links = document.getElementsByTagName("img");
	for (i=0; i<links.length; i++) {
		var title = links[i].getAttribute("title");
		if (title) {
			links[i].setAttribute("tptitle", title);
			links[i].removeAttribute("title");
			links[i].onmouseover = function() { showTip(this.getAttribute("tptitle")/*+"<br />"+this.href*/); }
		}/* else {
			links[i].onmouseover = function() { showTip(this.href); }
		}*/
		links[i].onmouseout = function() { hideTip(); }
	}
}
//
//window.onload = function() {
//	tooltip();
//}
