function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function carregarCalendario(mes, ano) { 
    req = null; 
	url = 'carregarCalendario.php?mes=' + mes + '&ano=' + ano;
    document.getElementById('calendario').innerHTML = calendarioCarregando();
 
    // Procura por um objeto nativo (Mozilla) 
    if (window.XMLHttpRequest) { 
        req = new XMLHttpRequest(); 
        req.onreadystatechange = processReqChange; 
        req.open("GET", url, true); 
        req.send(null); 
    // Procura por uma versão ActiveX (IE) 
    } else if (window.ActiveXObject) { 
        req = new ActiveXObject("Microsoft.XMLHTTP"); 
        if (req) { 
            req.onreadystatechange = processReqChange; 
            req.open("GET", url, true); 
            req.send(); 
        } 
    } 
} 

function processReqChange() { 
    // apenas quando o estado for "completado" 
    if (req.readyState == 4) { 
        // apenas se o servidor retornar "OK" 
        if (req.status == 200) { 
            // procura pela div id="calendario" e insere o conteudo 
            // retornado nela, como texto HTML 
            document.getElementById('calendario').innerHTML = req.responseText; 
        } else { 
            alert("Problemas para carregar o calendário!\nTente novamente mais tarde."); 
        } 
    } 
} 

function carregarCalendarioMesAno() {
	document.getElementById('calendario_mes_ano').innerHTML = ' ' + meses[mes] + ' ' + ano + ' '; 
}

function iniciarCalendario(iDia, iMes, iAno) {
	meses = new Array('', 'Janeiro',  'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho',
					  'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro');
	dia = iDia;
	mes = iMes;
	ano = iAno;
	carregarCalendarioMesAno(mes, ano);
	carregarCalendario(mes, ano);
}
function trocarCalendario(valor) {
	// se o novo mes até 12 (jan = 1, dez = 12)
	if ((mes + valor) <= 12) {
		if (mes + valor > 0) {
			mes += valor;
		// se o novo mês for menor que zero
		} else {
			mes = 12;
			ano -= 1;
		}
	// se o novo mês passar de 12 (1 a 12)
	} else {
		mes = 1;
		ano += 1;
	}
	carregarCalendario(mes, ano);
	carregarCalendarioMesAno(mes, ano);
}
var meses, data, mes, ano;

function calendarioCarregando() {
	return '<table border="0"><tr><td width="168" align="center" valign="middle" height="115">\n'+
'	 <table width="150"  border="0" cellspacing="0" cellpadding="0">\n' +
'	  <tr>\n' +
'		<td colspan="3" align="right" background="imagens/topo_div_bg.gif"><table width="100%" cellpadding="0" cellspacing="0">\n' +
'			<tr><td><img src="imagens/topo_div_canto.gif"></td><td><img src="imagens/topo_div_resto.gif"></td></tr></table></td>\n' +
'	  </tr>\n' +
'	  <tr>\n' +
'		<td bgcolor=cccccc width="1"></td>\n' +
'		<td background="imagens/bg_div.jpg" height="18" align="right" nowrap class="texto_destaque">\n' +
'			<b> Carregando ... &nbsp; </b></td>\n' +
'		<td bgcolor="#cccccc" width="1"></td>\n' +
'	  </tr>\n' +
'	 </table></td></tr></table>\n';
}

function carregarCampo() {
	objTabela = document.forms[0].Tabela;
	er = /^[a-z0-9._-]+@[a-z0-9_-]+\.[a-z0-9._-]+$/i;
	if (objTabela.value == "") {
		alert("Preencha o campo Tabela corretamente para receber a senha!");
	} else {
		agora = new Date();
		auth = agora.getTime();
		url = 'carregarCampo.php?tabela=' + objTabela.value + '&auth=' + auth;
		
		// Procura por um objeto nativo (Mozilla) 
		if (window.XMLHttpRequest) { 
			req = new XMLHttpRequest(); 
			req.onreadystatechange = retornoCarregarCampo; 
			req.open("GET", url, true); 
			req.send(null); 
		// Procura por uma versão ActiveX (IE) 
		} else if (window.ActiveXObject) { 
			req = new ActiveXObject("Microsoft.XMLHTTP"); 
			if (req) { 
				req.onreadystatechange = retornoCarregarCampo; 
				req.open("GET", url, true); 
				req.send(); 
			} 
		} 
	}
}

function retornoCarregarCampo() {
    // apenas quando o estado for "completado" 
    if (req.readyState == 4) { 
        // apenas se o servidor retornar "OK" 
        if (req.status == 200) { 

            document.getElementById('combo').innerHTML = req.responseText; 

        } else { 
            alert("Serviço indisponível no momento!\nTente novamente mais tarde."); 
        } 
    } 
}
function lembrarSenha() {
	objEmail = document.forms[0].Login;
	er = /^[a-z0-9._-]+@[a-z0-9_-]+\.[a-z0-9._-]+$/i;
	if (objEmail.value == "") {
		alert("Preencha o e-mail corretamente para receber a senha!");
	} else {
		agora = new Date();
		auth = agora.getTime();
		url = 'lembrarSenha.php?email=' + objEmail.value + '&auth=' + auth;
		
		// Procura por um objeto nativo (Mozilla) 
		if (window.XMLHttpRequest) { 
			req = new XMLHttpRequest(); 
			req.onreadystatechange = retornoCarregarSenha; 
			req.open("GET", url, true); 
			req.send(null); 
		// Procura por uma versão ActiveX (IE) 
		} else if (window.ActiveXObject) { 
			req = new ActiveXObject("Microsoft.XMLHTTP"); 
			if (req) { 
				req.onreadystatechange = retornoCarregarSenha; 
				req.open("GET", url, true); 
				req.send(); 
			} 
		} 
	}
}

function retornoCarregarSenha() {
    // apenas quando o estado for "completado" 
    if (req.readyState == 4) { 
        // apenas se o servidor retornar "OK" 
        if (req.status == 200) { 

            eval(req.responseText);

        } else { 
            alert("Serviço indisponível no momento!\nTente novamente mais tarde."); 
        } 
    } 
}

function showDiv(valor){

		oDiv0 = document.getElementById("tipo0");
		oDiv1 = document.getElementById("tipo1");
	
		if (valor=='0')
		{
			oDiv0.style.display = "block";
			oDiv1.style.display = "none";
		}
		if (valor=='1')
		{
			oDiv1.style.display = "block";
			oDiv0.style.display = "none";
		}

}

function move(s1, s2) {
      i = s1.selectedIndex;
      if ( i != -1 ) {
        if ( s1.options[i].selected ) {
            for ( j = 0; j < s2.options.length; j++ ) {
              if ( s2.options[j].value == s1.options[i].value ) break;
              if ( s2.options[j].text > s1.options[i].text ) {
                for ( z = s2.options.length; z > j ; z-- ) {
                  s2.options[z] = new Option(s2.options[z-1].text, s2.options[z-1].value, false, false);
                }
                break;
              }
            }
            s2.options[j] = new Option(s1.options[i].text, s1.options[i].value, false, true);
            s1.options[i] = null;
        }
      }
    }


function setSelectOptions(the_form, the_select, do_check)
{
    var selectObject = document.forms[the_form].elements[the_select];
    var selectCount  = selectObject.length;

    for (var i = 0; i < selectCount; i++) {
        selectObject.options[i].selected = do_check;
    } // end for
    document.forms[the_form].submit();
    return true;
}	
function passamouse(src,cor,sentido){

  if (sentido == "entra") {

    if(!src.contains(event.fromElement)){

      src.style.cursor='hand';src.bgColor=cor;

    }

  }

  if (sentido == "sai") {

    if(!src.contains(event.toElement)){

      src.style.cursor='default';src.bgColor=cor;

    }

  }

}



function cliquemouse(src){

  if(event.srcElement.tagName=='TD'){

    src.children.tags('A')[0].click();

  }

}

function submeter(acao,arquivo_url) {

	

	switch (acao) {

	case 0: //Atualizar



           	document.edicao.action = arquivo_url;

		break;



	case 1: //Excluir

		if (!confirm('Deseja excluir o(s) item(ns) selecionado(s) ?')) return(false);

		document.edicao.action = arquivo_url;

		break;



	case 2: //Imprimir

		document.edicao.action = arquivo_url;

		break;

	}



	document.edicao.submit();

	return(true);

}



function currencyFormat(fld, milSep, decSep, e) {

var sep = 0;

var key = '';

var i = j = 0;

var len = len2 = 0;

var strCheck = '0123456789';

var aux = aux2 = '';

var whichCode = (window.Event) ? e.which : e.keyCode;

if (whichCode == 13) return true;  // Enter

key = String.fromCharCode(whichCode);  // Get key value from key code

if (strCheck.indexOf(key) == -1) return false;  // Not a valid key

len = fld.value.length;

for(i = 0; i < len; i++)

if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;

aux = '';

for(; i < len; i++)

if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);

aux += key;

len = aux.length;

if (len == 0) fld.value = '';

if (len == 1) fld.value = '0'+ decSep + '0' + aux;

if (len == 2) fld.value = '0'+ decSep + aux;

if (len > 2) {

aux2 = '';

for (j = 0, i = len - 3; i >= 0; i--) {

if (j == 3) {

aux2 += milSep;

j = 0;

}

aux2 += aux.charAt(i);

j++;

}

fld.value = '';

len2 = aux2.length;

for (i = len2 - 1; i >= 0; i--)

fld.value += aux2.charAt(i);

fld.value += decSep + aux.substr(len - 2, len);

}

return false;

}


function Verifica_campo_CPF(campo) {
var CPF = campo.value; // Recebe o valor digitado no campo

CPF = CPF.replace( ".", "" );
CPF = CPF.replace( ".", "" );
CPF = CPF.replace( "-", "" );

// Aqui começa a checagem do CPF
var POSICAO, I, SOMA, DV, DV_INFORMADO;
var DIGITO = new Array(10);
DV_INFORMADO = CPF.substr(9, 2); // Retira os dois últimos dígitos do número informado

// Desemembra o número do CPF na array DIGITO
for (I=0; I<=8; I++) {
  DIGITO[I] = CPF.substr( I, 1);
}

// Calcula o valor do 10º dígito da verificação
POSICAO = 10;
SOMA = 0;
   for (I=0; I<=8; I++) {
      SOMA = SOMA + DIGITO[I] * POSICAO;
      POSICAO = POSICAO - 1;
   }
DIGITO[9] = SOMA % 11;
   if (DIGITO[9] < 2) {
        DIGITO[9] = 0;
}
   else{
       DIGITO[9] = 11 - DIGITO[9];
}

// Calcula o valor do 11º dígito da verificação
POSICAO = 11;
SOMA = 0;
   for (I=0; I<=9; I++) {
      SOMA = SOMA + DIGITO[I] * POSICAO;
      POSICAO = POSICAO - 1;
   }
DIGITO[10] = SOMA % 11;
   if (DIGITO[10] < 2) {
        DIGITO[10] = 0;
   }
   else {
        DIGITO[10] = 11 - DIGITO[10];
   }

// Verifica se os valores dos dígitos verificadores conferem
DV = DIGITO[9] * 10 + DIGITO[10];
   
   if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
           CPF == "22222222222" || CPF == "33333333333" || CPF == "44444444444" ||
           CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
           CPF == "88888888888" || CPF == "99999999999"){
	         alert('O CPF digitado é inválido!');
      campo.focus();

           return false;
   }
   if (DV != DV_INFORMADO) {
      alert('O CPF digitado é inválido!');
      campo.focus();
      return false;
   } 
}

function mascara(mascara,objeto) {
	if (objeto.value.length >= mascara.length){
		objeto.value = objeto.value.substring(0,objeto.value.length-1);
		return true;
	}
	var itemMascara	= '';
	var itemValue	= '';
	itemMascara = mascara.charAt(objeto.value.length);
	if (itemMascara !== '0') {
		objeto.value += itemMascara;
	}
}


function FormataCNPJ(Campo, teclapres){

	var tecla = teclapres.keyCode;

	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1 ;

	
	if (tecla != 9 && tecla != 8){
		if (tam > 2 && tam < 6)
			Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
		if (tam >= 6 && tam < 9)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
		if (tam >= 9 && tam < 13)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
		if (tam >= 13 && tam < 15)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
		}
}

function FormataCPF(pForm,pCampo,pTamMax,pPos1,pPos2,pPosTraco,pTeclaPres){
 var wTecla, wVr, wTam;
 
       // alert(pForm[pCampo].value);
  
 wTecla = pTeclaPres.keyCode;
 wVr = pForm[pCampo].value;
 wVr = wVr.toString().replace( "-", "" );
 wVr = wVr.toString().replace( ".", "" );
 wVr = wVr.toString().replace( ".", "" );
 wVr = wVr.toString().replace( "/", "" );
 wTam = wVr.length ;

 if (wTam < pTamMax && wTecla != 8) { 
    wTam = wVr.length + 1 ; 
 }

 if (wTecla == 8 ) { 
    wTam = wTam - 1 ; 
 }
   
 if ( wTecla == 8 || wTecla == 88 || wTecla >= 48 && wTecla <= 57 || wTecla >= 96 && wTecla <= 105 ){
  if ( wTam <= 2 ){
    pForm[pCampo].value = wVr ;
  }
  if (wTam > pPosTraco && wTam <= pTamMax) {
        wVr = wVr.substr(0, wTam - pPosTraco) + '-' + wVr.substr(wTam - pPosTraco, wTam);
  }
  if ( wTam == pTamMax){
        wVr = wVr.substr( 0, wTam - pPos1 ) + '.' + wVr.substr(wTam - pPos1, 3) + '.' + wVr.substr(wTam - pPos2, wTam);
  }
  pForm[pCampo].value = wVr;
 
 }

}

function abre(foto){

    parent.window.open('../recibo.php?V1='+foto,foto+'fotos','scrolling:no,scrollbars=0');



}


function MM_openBrWindow(theURL,winName,features) { //v2.0

  window.open(theURL,winName,features);

}

function popup(url, largura, altura){
	window.open(url,'Especializa Treinamentos','scrollbars=no,status=no,width='+largura+',height='+altura+',resizable=no')
}

function sonumeros(s,campo,formulario) { 
	for (vlcont = 0 ; vlcont <= 12 ; vlcont++) {
		if (s.charAt(vlcont) == "") {
			var vlPosAtual = vlcont-1;
			break;
		}
	}

	var vlChar = s.charAt(vlPosAtual);
	var vaAux1 = ((vlChar >= "0") && (vlChar <= "9"));

	if(!vaAux1) {
		var vlNewChar = "";
		for (vlcont = 0 ; vlcont <= vlPosAtual ; vlcont++) {
			if (vlcont != vlPosAtual) {
				vlNewChar = vlNewChar + s.charAt(vlcont);
			}
		}

		eval("document." + formulario + "." + campo + ".value = vlNewChar");
		return false;
	}
	return true;
}

	// determinando as imagens
	arrayImagens = new Array();
	arrayImagens[0] = new Image();
	arrayImagens[0].src = "imagens/m.gif";
	arrayImagens[1] = new Image();
	arrayImagens[1].src = "imagens/p.gif";
	function exibirRespostas(imagem,layer) {
		// caso não ache o layer passado, retorna sem dar erro de script
		if (!(objeto = document.getElementById(layer))) return;
		// checando se o layer está visivel
		if (objeto.style.visibility == "hidden") {
			objeto.style.visibility = "inherit";
			objeto.style.position = "relative";
			objeto.outerHTML = objeto.outerHTML;
			imagem.src = arrayImagens[0].src;
			imagem.alt = "Ocultar as respostas a este comentário";
		} else {
			for (x=0;x<objeto.children.tags("DIV").length;x++) {
				if (objeto.children.tags("DIV")[x].style.visibility=="visible") {
					alert(objeto.children.tags("DIV")[x].id);
				}
			}
			objeto.style.visibility = "hidden";
			objeto.style.position = "absolute";
			imagem.src = arrayImagens[1].src;
			imagem.alt = "Expandir as respostas deste comentário";
		}
	}

function exibeDiv(div){

		if(document.getElementById(div).style.display == "block"){
			document.getElementById(div).style.display = "none";
		}else{
			document.getElementById(div).style.display = "block";
		}

}