
function carregarCalendario(mes, ano, base) { 
	req = null;
	var url = base + "/principal/calendario/?mes=" + mes + "&ano=" + ano;
	document.getElementById('calendario-tab-dias').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-tab-dias" e insere o conteudo 
            // retornado nela, como texto HTML 
            document.getElementById('calendario-tab-dias').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, base) {
	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, base);
}
function trocarCalendario(valor, base) {
	// 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, base);
	
	carregarCalendarioMesAno(mes, ano);
}
var meses, data, mes, ano, base;

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" ><table width="100%" cellpadding="0" cellspacing="0">\n' +
'			<tr><td></td><td></td></tr></table></td>\n' +
'	  </tr>\n' +
'	  <tr>\n' +
'		<td bgcolor=cccccc width="1"></td>\n' +
'		<td height="18" align="right" nowrap class="texto_destaque">\n' +
'			<b> <img src="../imagens/ajax-loader.gif" &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";
		}

}
