function get( id )
{
	if (document.all) {
		var returnVar = document.all[id];
	}
	else 
	{
		if (document.layers) {
			var returnVar = document.layers[id];
		}
		else
		{
			if (document.getElementById) {
				var returnVar = document.getElementById(id);
			}
		}
	}
    return returnVar;
}

String.prototype.trim = function()
{
return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

function buscaCep()
{
	if ((get('cep').value.length) < 9)
	{
		get('endereco').value = '';
		get('bairro').value = '';
		get('cidade').value = '';
		get('estado').selectedIndex = 0;
		return false;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		return false;
	} 
	var url="../inc/cep.php";
	url=url+"?cep="+get('cep').value;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=resultadoCep;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function buscaCepEntrega()
{
	if ((get('cepEntrega').value.length) < 9)
	{
		get('enderecoEntrega').value = '';
		get('bairroEntrega').value = '';
		get('cidadeEntrega').value = '';
		get('estadoEntrega').selectedIndex = 0;
		return false;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		return false;
	} 
	var url="../inc/cep.php";
	url=url+"?cep="+get('cepEntrega').value;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=resultadoCepEntrega;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function buscaCepPagamento()
{
	if ((get('cepPagamento').value.length) < 9)
	{
		get('enderecoPagamento').value = '';
		get('bairroPagamento').value = '';
		get('cidadePagamento').value = '';
		get('estadoPagamento').selectedIndex = 0;
		return false;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		return false;
	} 
	var url="../inc/cep.php";
	url=url+"?cep="+get('cepPagamento').value;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=resultadoCepPagamento;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function resultadoCep() 
{ 
	if (xmlHttp.readyState==4)
	{
		var_resultado = xmlHttp.responseText;
		vetor_resultado = var_resultado.split('$%$');
		estadoId = parseInt(vetor_resultado[3]);
		if ((vetor_resultado[0]) && (vetor_resultado[0] != ' ')) {
			get('endereco').value = vetor_resultado[0];
		}
		if (vetor_resultado[1]) {
			get('bairro').value = vetor_resultado[1];
		}
		if (vetor_resultado[2]) {
			get('cidade').value = vetor_resultado[2];
		}
		get('estado').selectedIndex = estadoId;
	}
}

function resultadoCepEntrega() 
{ 
	if (xmlHttp.readyState==4)
	{
		var_resultado = xmlHttp.responseText;
		vetor_resultado = var_resultado.split('$%$');
		estadoId = parseInt(vetor_resultado[3]);
		if ((vetor_resultado[0]) && (vetor_resultado[0] != ' ')) {
			get('enderecoEntrega').value = vetor_resultado[0];
		}
		if (vetor_resultado[1]) {
			get('bairroEntrega').value = vetor_resultado[1];
		}
		if (vetor_resultado[2]) {
			get('cidadeEntrega').value = vetor_resultado[2];
		}
		get('estadoEntrega').selectedIndex = estadoId;
	}
}

function resultadoCepPagamento() 
{ 
	if (xmlHttp.readyState==4)
	{
		var_resultado = xmlHttp.responseText;
		vetor_resultado = var_resultado.split('$%$');
		estadoId = parseInt(vetor_resultado[3]);
		if ((vetor_resultado[0]) && (vetor_resultado[0] != ' ')) {
			get('enderecoPagamento').value = vetor_resultado[0];
		}
		if (vetor_resultado[1]) {
			get('bairroPagamento').value = vetor_resultado[1];
		}
		if (vetor_resultado[2]) {
			get('cidadePagamento').value = vetor_resultado[2];
		}
		get('estadoPagamento').selectedIndex = estadoId;
	}
}

function loadFormasPagamento()
{
	xmlHttp=new GetXmlHttpObject();
	if (xmlHttp==null)
	{
		return false;
	}
	var url = "../inc/formasTeste.php";
	url = url + "?meioPagamento="+get('meioPagamentoSelecionado').value;
	url = url + "&cursoSemestre="+get('cursoSelecionado').value;
	url = url + "&empresaDesconto="+get('selectEmpresas1')[get('selectEmpresas1').selectedIndex].value;
	url = url + "&cpf="+get('cpf').value;
	xmlHttp.onreadystatechange=loadFormasPagamentoAux;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	get('formaPagamentoSelecionado').value = "";
	//alert('teste');
}

function loadFormasPagamentoAux()
{
	if (xmlHttp.readyState ==4)
	{
		var resposta = xmlHttp.responseText;
		get('formasPagamento').innerHTML = resposta;
		//alert(get('formasPagamento').innerHTML);
	}
}

function loadEmpresas()
{
	xmlHttp2= new GetXmlHttpObject();
	if (xmlHttp2==null)
	{
		return false;
	}
	var url2 = "../inc/empresas.php";
	url2 = url2 + "?cursoSemestre="+get('cursoSelecionado').value;
	xmlHttp2.onreadystatechange=loadEmpresasAux;
	xmlHttp2.open("GET",url2,true);
	xmlHttp2.send(null);
}

function loadEmpresasAux()
{
	if (xmlHttp2.readyState ==4)
	{
		var resposta2 = xmlHttp2.responseText;
		get('selectEmpresas').innerHTML = resposta2;
		//alert(resposta2);
	}
}

function mascara(o,f){
	v_obj=o;
	v_fun=f;
	setTimeout("execmascara()",1);
}

function execmascara(){
	v_obj.value=v_fun(v_obj.value);
}

function mNumeros(v){
	v = v.replace(/\D/g,"");
	return v;
}

function mTelefone(v){
    v=v.replace(/\D/g,"");
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2");
    v=v.replace(/(\d{4})(\d)/,"$1-$2");
    return v;
}

function mCpf(v){
    v=v.replace(/\D/g,"");
    v=v.replace(/(\d{3})(\d)/,"$1.$2");
    v=v.replace(/(\d{3})(\d)/,"$1.$2");
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2");
    return v;
}

function mData(v){
    v=v.replace(/\D/g,"");
    v=v.replace(/(\d{2})(\d)/,"$1/$2");
    v=v.replace(/(\d{2})(\d)/,"$1/$2");
    return v;
}

function mCep(v){
    v=v.replace(/D/g,"");
    v=v.replace(/^(\d{5})(\d)/,"$1-$2");
    return v;
}

function mCnpj(v){
    v=v.replace(/\D/g,"");
    v=v.replace(/^(\d{2})(\d)/,"$1.$2");
    v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3");
    v=v.replace(/\.(\d{3})(\d)/,".$1/$2");
    v=v.replace(/(\d{4})(\d)/,"$1-$2");
    return v;
}

function nada() {
	return false;
}

function carregaMatricula(id,token) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		return false;
	}
	var url = "../inc/consultaMatricula.php";
	url = url + "?id="+id;
	url = url + "&token="+token;
	xmlHttp.onreadystatechange=preencheMatricula;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function preencheMatricula() {
	if (xmlHttp.readyState ==4)
	{
		get('cursoFieldset').className = 'obshide';
		get('pagamentoFieldset').className = 'obshide';
		get('responsavelPagamentoFieldset').className = 'obshide';
		var resposta = xmlHttp.responseText;
		dados = resposta.split("!@#$%&*()_+_)(*&%$#@!")
		get('matriculaAux').value = dados[0];
		get('matriculaId').value = dados[0];
		get('email').value = dados[1];
		get('nome').value = dados[2];
		get('cpf').value = dados[3];
		get('dataNascimento').value = dados[4];
		//get('sexo').value = dados[5];
		var i;
		for (i=0;i<get('sexo').options.length;i++){
			if (get('sexo').options[i].value == dados[5]) {
				get('sexo').selectedIndex = i;
				i = get('sexo').options.length;
			}
		}
		get('cidadeNaturalidade').value = dados[6];
		//get('estadoNaturalidade').value = dados[7];
		for (i=0;i<get('estadoNaturalidade').options.length;i++){
			if (get('estadoNaturalidade').options[i].value == dados[7]) {
				get('estadoNaturalidade').selectedIndex = i;
				i = get('estadoNaturalidade').options.length;
			}
		}
		//get('estadoCivil').value = dados[8];
		for (i=0;i<get('estadoCivil').options.length;i++){
			if (get('estadoCivil').options[i].value == dados[8]) {
				get('estadoCivil').selectedIndex = i;
				i = get('estadoCivil').options.length;
			}
		}
		//get('nacionalidade').value = dados[9];
		for (i=0;i<get('nacionalidade').options.length;i++){
			if (get('nacionalidade').options[i].value == dados[9]) {
				get('nacionalidade').selectedIndex = i;
				i = get('nacionalidade').options.length;
			}
		}
		//get('pais').value = dados[10];
		var i;
		for (i=0;i<get('pais').options.length;i++){
			if (get('pais').options[i].value == dados[10]) {
				get('pais').selectedIndex = i;
				i = get('pais').options.length;
			}
		}
		get('cep').value = dados[11];
		get('endereco').value = dados[12];
		get('bairro').value = dados[13];
		get('complemento').value = dados[14];
		get('cidade').value = dados[15];
		//get('estado').value = dados[16];
		for (i=0;i<get('estado').options.length;i++){
			if (get('estado').options[i].value == dados[16]) {
				get('estado').selectedIndex = i;
				i = get('estado').options.length;
			}
		}
		get('telefone').value = dados[17];
		get('celular').value = dados[18];
		//mascara(get('celular'),mTelefone);
		get('fax').value = dados[19];
		//mascara(get('fax'),mTelefone);
		//get('tipoEntrega').value = dados[20];
		if (dados[20] != 1) {
			tipoEntregaOutro();
			get('enderecoAluno').checked = 0;
			get('enderecoOutro').checked = 1;
			//get('paisEntrega').value = dados[21];
			for (i=0;i<get('paisEntrega').options.length;i++){
				if (get('paisEntrega').options[i].value == dados[21]) {
					get('paisEntrega').selectedIndex = i;
					i = get('paisEntrega').options.length;
				}
			}
			get('cepEntrega').value = dados[22];
			//mascara(get('cepEntrega'),mCep);
			get('enderecoEntrega').value = dados[23];
			get('bairroEntrega').value = dados[24];
			get('complementoEntrega').value = dados[25];
			get('cidadeEntrega').value = dados[26];
			//get('estadoEntrega').value = dados[27];
			for (i=0;i<get('estadoEntrega').options.length;i++){
				if (get('estadoEntrega').options[i].value == dados[27]) {
					get('estadoEntrega').selectedIndex = i;
					i = get('estadoEntrega').options.length;
				}
			}
			get('telefoneEntrega').value = dados[28];
			//mascara(get('telefoneEntrega'),mTelefone);
			get('faxEntrega').value = dados[29];
			//mascara(get('faxEntrega'),mTelefone);
			//get('escolaridade').value = dados[30];
		}
		for (i=0;i<get('escolaridade').options.length;i++){
			if (get('escolaridade').options[i].value == dados[30]) {
				get('escolaridade').selectedIndex = i;
				i = get('escolaridade').options.length;
			}
		}
		//get('areaConhecimento').value = dados[31];
		for (i=0;i<get('areaConhecimento').options.length;i++){
			if (get('areaConhecimento').options[i].value == dados[31]) {
				get('areaConhecimento').selectedIndex = i;
				i = get('areaConhecimento').options.length;
			}
		}
		//get('tipoInstituicao').value = dados[32];
		for (i=0;i<get('tipoInstituicao').options.length;i++){
			if (get('tipoInstituicao').options[i].value == dados[32]) {
				get('tipoInstituicao').selectedIndex = i;
				i = get('tipoInstituicao').options.length;
			}
		}
		get('anoConclusao').value = dados[33];
		//get('empregado').value = dados[34];
		//get('cargo').value = dados[36];
		if (dados[34] == 1) { 
			funcEmpregadoSim();
			get('empregadoSim').checked = 1;
			get('empregadoNao').checked = 0;
			get('empresa').value = dados[35];
			for (i=0;i<get('cargo').options.length;i++){
				if (get('cargo').options[i].value == dados[36]) {
					get('cargo').selectedIndex = i;
					i = get('cargo').options.length;
				}
			}
		//get('faixaSalarial').value = dados[37];
			for (i=0;i<get('faixaSalarial').options.length;i++){
				if (get('faixaSalarial').options[i].value == dados[37]) {
					get('faixaSalarial').selectedIndex = i;
					i = get('faixaSalarial').options.length;
				}
			}
		}
		else
		{
			get('empregadoSim').checked = 0;
			get('empregadoNao').checked = 1;
			funcEmpregadoNao();
		}

		//get('meioPagamento').value = dados[38];
		//get('formaPagamento').value = dados[39];
		//get('tipoPagamento').value = dados[40];
		if (dados[40] != 1) {
			responsavelPagamentoOutro();
			if (dados[57] != 1) {
				tipoResponsavelJuridica();
				get('cnpjPagamento').value = mCnpj(dados[42]);
			}
			else
			{
				tipoResponsavelFisica();
				get('cpfPagamento').value = mCpf(dados[42]);
			}
			get('nomePagamento').value = dados[41];
			get('responsavelAluno').checked = 0;
			get('responsavelOutro').checked = 1;
			for (i=0;i<get('paisPagamento').options.length;i++){
				if (get('paisPagamento').options[i].value == dados[43]) {
					get('paisPagamento').selectedIndex = i;
					i = get('paisPagamento').options.length;
				}
			}
			get('cepPagamento').value = dados[44];
			get('enderecoPagamento').value = dados[45];
			get('bairroPagamento').value = dados[46];
			get('complementoPagamento').value = dados[47];
			get('cidadePagamento').value = dados[48];
			for (i=0;i<get('estadoPagamento').options.length;i++){
				if (get('estadoPagamento').options[i].value == dados[49]) {
					get('estadoPagamento').selectedIndex = i;
					i = get('estadoPagamento').options.length;
				}
			}
			get('telefonePagamento').value = dados[50];
			get('faxPagamento').value = dados[51];
		}
		var cursoId = dados[56];
		cursoIdStr = 'curso' + cursoId;
		get(cursoIdStr).checked = 1;
		mudaCurso(dados[56]);
		get('cpf').value = mCpf(get('cpf').value);
		get('cpf').value = mCpf(get('cpf').value);
		get('cep').value = mCep(get('cep').value);
		get('cepEntrega').value = mCep(get('cepEntrega').value);
		get('cepPagamento').value = mCep(get('cepPagamento').value);
		get('telefone').value = mTelefone(get('telefone').value);
		get('celular').value = mTelefone(get('celular').value);
		get('fax').value = mTelefone(get('fax').value);
		get('telefoneEntrega').value = mTelefone(get('telefoneEntrega').value);
		get('faxEntrega').value = mTelefone(get('faxEntrega').value);
		get('telefonePagamento').value = mTelefone(get('telefonePagamento').value);
		get('faxPagamento').value = mTelefone(get('faxPagamento').value);
		get('formaPagamentoSelecionado').value = dados[39];
		get('meioPagamentoSelecionado').value = dados[38];
		strMeio = 'meioPagamento' + dados[38];
		get(strMeio).checked = true;
		loadFormasPagamento();
		strForma = 'forma-pagamento-' + dados[39];
		get(strForma).checked = true;
	}
}

function carregaDados() {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		return false;
	}
	var url = "../inc/consultaDados.php";
	url = url + "?cpf="+get('cpf').value;
	xmlHttp.onreadystatechange=preencheDados;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function preencheDados() {
	if (xmlHttp.readyState ==4)
	{
		var resposta = xmlHttp.responseText;
		dados = resposta.split("!@#$%&*()_+_)(*&%$#@!");
		get('email').value = dados[1];
		get('nome').value = dados[2];
		get('cpf').value = dados[3];
		get('dataNascimento').value = dados[4];
		//get('sexo').value = dados[5];
		var i;
		for (i=0;i<get('sexo').options.length;i++){
			if (get('sexo').options[i].value == dados[5]) {
				get('sexo').selectedIndex = i;
				i = get('sexo').options.length;
			}
		}
		get('cidadeNaturalidade').value = dados[6];
		//get('estadoNaturalidade').value = dados[7];
		for (i=0;i<get('estadoNaturalidade').options.length;i++){
			if (get('estadoNaturalidade').options[i].value == dados[7]) {
				get('estadoNaturalidade').selectedIndex = i;
				i = get('estadoNaturalidade').options.length;
			}
		}
		//get('estadoCivil').value = dados[8];
		for (i=0;i<get('estadoCivil').options.length;i++){
			if (get('estadoCivil').options[i].value == dados[8]) {
				get('estadoCivil').selectedIndex = i;
				i = get('estadoCivil').options.length;
			}
		}
		//get('nacionalidade').value = dados[9];
		for (i=0;i<get('nacionalidade').options.length;i++){
			if (get('nacionalidade').options[i].value == dados[9]) {
				get('nacionalidade').selectedIndex = i;
				i = get('nacionalidade').options.length;
			}
		}
		//get('pais').value = dados[10];
		var i;
		for (i=0;i<get('pais').options.length;i++){
			if (get('pais').options[i].value == dados[10]) {
				get('pais').selectedIndex = i;
				i = get('pais').options.length;
			}
		}
		get('cep').value = dados[11];
		get('endereco').value = dados[12];
		get('bairro').value = dados[13];
		get('complemento').value = dados[14];
		get('cidade').value = dados[15];
		//get('estado').value = dados[16];
		for (i=0;i<get('estado').options.length;i++){
			if (get('estado').options[i].value == dados[16]) {
				get('estado').selectedIndex = i;
				i = get('estado').options.length;
			}
		}
		get('telefone').value = dados[17];
		get('celular').value = dados[18];
		//mascara(get('celular'),mTelefone);
		get('fax').value = dados[19];
		//mascara(get('fax'),mTelefone);
		//get('tipoEntrega').value = dados[20];
		if (dados[20] != 1) {
			tipoEntregaOutro();
			get('enderecoAluno').checked = 0;
			get('enderecoOutro').checked = 1;
			//get('paisEntrega').value = dados[21];
			for (i=0;i<get('paisEntrega').options.length;i++){
				if (get('paisEntrega').options[i].value == dados[21]) {
					get('paisEntrega').selectedIndex = i;
					i = get('paisEntrega').options.length;
				}
			}
			get('cepEntrega').value = dados[22];
			//mascara(get('cepEntrega'),mCep);
			get('enderecoEntrega').value = dados[23];
			get('bairroEntrega').value = dados[24];
			get('complementoEntrega').value = dados[25];
			get('cidadeEntrega').value = dados[26];
			//get('estadoEntrega').value = dados[27];
			for (i=0;i<get('estadoEntrega').options.length;i++){
				if (get('estadoEntrega').options[i].value == dados[27]) {
					get('estadoEntrega').selectedIndex = i;
					i = get('estadoEntrega').options.length;
				}
			}
			get('telefoneEntrega').value = dados[28];
			//mascara(get('telefoneEntrega'),mTelefone);
			get('faxEntrega').value = dados[29];
			//mascara(get('faxEntrega'),mTelefone);
			//get('escolaridade').value = dados[30];
		}
		for (i=0;i<get('escolaridade').options.length;i++){
			if (get('escolaridade').options[i].value == dados[30]) {
				get('escolaridade').selectedIndex = i;
				i = get('escolaridade').options.length;
			}
		}
		//get('areaConhecimento').value = dados[31];
		for (i=0;i<get('areaConhecimento').options.length;i++){
			if (get('areaConhecimento').options[i].value == dados[31]) {
				get('areaConhecimento').selectedIndex = i;
				i = get('areaConhecimento').options.length;
			}
		}
		//get('tipoInstituicao').value = dados[32];
		for (i=0;i<get('tipoInstituicao').options.length;i++){
			if (get('tipoInstituicao').options[i].value == dados[32]) {
				get('tipoInstituicao').selectedIndex = i;
				i = get('tipoInstituicao').options.length;
			}
		}
		get('anoConclusao').value = dados[33];
		//get('empregado').value = dados[34];
		//get('cargo').value = dados[36];
		if (dados[34] == 1) { 
			funcEmpregadoSim();
			get('empregadoSim').checked = 1;
			get('empregadoNao').checked = 0;
			get('empresa').value = dados[35];
			for (i=0;i<get('cargo').options.length;i++){
				if (get('cargo').options[i].value == dados[36]) {
					get('cargo').selectedIndex = i;
					i = get('cargo').options.length;
				}
			}
		//get('faixaSalarial').value = dados[37];
			for (i=0;i<get('faixaSalarial').options.length;i++){
				if (get('faixaSalarial').options[i].value == dados[37]) {
					get('faixaSalarial').selectedIndex = i;
					i = get('faixaSalarial').options.length;
				}
			}
		}
		else
		{
			get('empregadoSim').checked = 0;
			get('empregadoNao').checked = 1;
			funcEmpregadoNao();
		}

		//get('meioPagamento').value = dados[38];
		//get('formaPagamento').value = dados[39];
		//get('tipoPagamento').value = dados[40];
		if (dados[40] != 1) {
			responsavelPagamentoOutro();
			if (dados[57] != 1) {
				tipoResponsavelJuridica();
				get('cnpjPagamento').value = mCnpj(dados[42]);
			}
			else
			{
				tipoResponsavelFisica();
				get('cpfPagamento').value = mCpf(dados[42]);
			}
			get('nomePagamento').value = dados[41];
			get('responsavelAluno').checked = 0;
			get('responsavelOutro').checked = 1;
			for (i=0;i<get('paisPagamento').options.length;i++){
				if (get('paisPagamento').options[i].value == dados[43]) {
					get('paisPagamento').selectedIndex = i;
					i = get('paisPagamento').options.length;
				}
			}
			get('cepPagamento').value = dados[44];
			get('enderecoPagamento').value = dados[45];
			get('bairroPagamento').value = dados[46];
			get('complementoPagamento').value = dados[47];
			get('cidadePagamento').value = dados[48];
			for (i=0;i<get('estadoPagamento').options.length;i++){
				if (get('estadoPagamento').options[i].value == dados[49]) {
					get('estadoPagamento').selectedIndex = i;
					i = get('estadoPagamento').options.length;
				}
			}
			get('telefonePagamento').value = dados[50];
			get('faxPagamento').value = dados[51];
		}
		for (i=0;i<get('tipoProfessor').options.length;i++){
				if (get('tipoProfessor').options[i].value == dados[60]) {
					get('tipoProfessor').selectedIndex = i;
					i = get('tipoProfessor').options.length;
				}
			}
			for (i=0;i<get('tipoEscola').options.length;i++){
				if (get('tipoEscola').options[i].value == dados[61]) {
					get('tipoEscola').selectedIndex = i;
					i = get('tipoEscola').options.length;
				}
			}
		get('formacao').value = dados[62];
		get('rg').value = dados[63];
		get('cpf').value = mCpf(get('cpf').value);
		get('cpf').value = mCpf(get('cpf').value);
		get('cep').value = mCep(get('cep').value);
		get('cepEntrega').value = mCep(get('cepEntrega').value);
		get('cepPagamento').value = mCep(get('cepPagamento').value);
		get('telefone').value = mTelefone(get('telefone').value);
		get('celular').value = mTelefone(get('celular').value);
		get('fax').value = mTelefone(get('fax').value);
		get('telefoneEntrega').value = mTelefone(get('telefoneEntrega').value);
		get('faxEntrega').value = mTelefone(get('faxEntrega').value);
		get('telefonePagamento').value = mTelefone(get('telefonePagamento').value);
		get('faxPagamento').value = mTelefone(get('faxPagamento').value);
	}
}


function tipoEntregaAluno() {
	get('paisEntregaLI').style.display = 'none';
	get('cepEntregaLI').style.display = 'none';
	get('enderecoEntregaLI').style.display = 'none';
	get('bairroEntregaLI').style.display = 'none';
	get('complementoEntregaLI').style.display = 'none';
	get('cidadeEntregaLI').style.display = 'none';
	get('estadoEntregaLI').style.display = 'none';
	get('telefoneEntregaLI').style.display = 'none';
	get('faxEntregaLI').style.display = 'none';
}

function tipoEntregaOutro() {
	get('paisEntregaLI').style.display = '';
	get('cepEntregaLI').style.display = '';
	get('enderecoEntregaLI').style.display = '';
	get('bairroEntregaLI').style.display = '';
	get('complementoEntregaLI').style.display = '';
	get('cidadeEntregaLI').style.display = '';
	get('estadoEntregaLI').style.display = '';
	get('telefoneEntregaLI').style.display = '';
	get('faxEntregaLI').style.display = '';
}

function funcEmpregadoSim() {
	get('empresaLI').style.display = '';
	get('cargoLI').style.display = '';
	get('faixaSalarialID').style.display = '';
}

function funcEmpregadoNao(){
	get('empresaLI').style.display = 'none';
	get('cargoLI').style.display = 'none';
	get('faixaSalarialID').style.display = 'none';
}

function responsavelPagamentoAluno() {
	get('tipoPagamentoLI').style.display = 'none';
	get('nomePagamentoLI').style.display = 'none';
	get('cpfPagamentoLI').style.display = 'none';
	get('cnpjPagamentoLI').style.display = 'none';
	get('paisPagamentoLI').style.display = 'none';
	get('cepPagamentoLI').style.display = 'none';
	get('enderecoPagamentoLI').style.display = 'none';
	get('bairroPagamentoLI').style.display = 'none';
	get('complementoPagamentoLI').style.display = 'none';
	get('cidadePagamentoLI').style.display = 'none';
	get('estadoPagamentoLI').style.display = 'none';
	get('telefonePagamentoLI').style.display = 'none';
	get('faxPagamentoLI').style.display = 'none';
}

function responsavelPagamentoOutro() {
	get('tipoPagamentoLI').style.display = '';
	get('nomePagamentoLI').style.display = '';
	get('cpfPagamentoLI').style.display = '';
	get('cnpjPagamentoLI').style.display = '';
	get('paisPagamentoLI').style.display = '';
	get('cepPagamentoLI').style.display = '';
	get('enderecoPagamentoLI').style.display = '';
	get('bairroPagamentoLI').style.display = '';
	get('complementoPagamentoLI').style.display = '';
	get('cidadePagamentoLI').style.display = '';
	get('estadoPagamentoLI').style.display = '';
	get('telefonePagamentoLI').style.display = '';
	get('faxPagamentoLI').style.display = '';
	tipoResponsavelFisica();
}

function tipoResponsavelFisica() {
	get('cpfPagamentoLI').style.display = '';
	get('cnpjPagamentoLI').style.display = 'none';
	get('tipoFisica').checked = 1;
	get('tipoJuridica').checked = 0;
}

function tipoResponsavelJuridica() {
	get('cpfPagamentoLI').style.display = 'none';
	get('cnpjPagamentoLI').style.display = '';
	get('tipoFisica').checked = 0;
	get('tipoJuridica').checked = 1;
}

function init() {
	tipoEntregaAluno();
	responsavelPagamentoAluno();
	get('infoGti').style.display = 'none';	
}

function initGTI() {
	mudaCurso(1380);
	tipoEntregaAluno();
	responsavelPagamentoAluno();
}

function mudaCurso(curso) {
	//alert(curso);
	get('cursoSelecionado').value = curso;
	loadFormasPagamento();	
	loadEmpresas();
	
	if (curso==1380) {
		get('infoGti').style.display = '';	
	}
	else
	{
		get('infoGti').style.display = 'none';	
	}
}

function mudaPagamento(meio) {
	get('meioPagamentoSelecionado').value = meio;
	loadFormasPagamento();
}

function mudaFPagamento(forma) {
	get('formaPagamentoSelecionado').value = forma;
}

function buscaAluno()
{
	xmlHttpb=GetXmlHttpObject();
	if (xmlHttpb==null)
	{
		return false;
	}
	setTimeout("loadFormasPagamento()",1);
	var url = "../inc/buscaMatricula.php";
	url = url + "?cpf="+get('cpf').value;
	xmlHttpb.onreadystatechange=loadAluno;
	xmlHttpb.open("GET",url,true);
	xmlHttpb.send(null);
}

function mudaEmpresa() {
	setTimeout("loadFormasPagamento()",1);	
}

function loadAluno()
{
	if (xmlHttpb.readyState ==4)
	{
		var resposta = xmlHttpb.responseText;
		if (resposta.trim() != '') {
			get('observacao').className = 'obs';
			get('listaCursosExistente').innerHTML = resposta;
		}
		else
		{
			get('observacao').className = 'obshide';
		}
		//alert(get('formas-de-pagamento').innerHTML);
	}
}

function validaCpf(cpf) {
      var numeros, digitos, soma, i, resultado, digitos_iguais;
	  cpf = cpf.replace(".","");
	  cpf = cpf.replace(".","");
	  cpf = cpf.replace("-","");
      digitos_iguais = 1;
      if (cpf.length < 11)
            return false;
      for (i = 0; i < cpf.length - 1; i++)
            if (cpf.charAt(i) != cpf.charAt(i + 1))
                  {
                  digitos_iguais = 0;
                  break;
                  }
      if (!digitos_iguais)
            {
            numeros = cpf.substring(0,9);
            digitos = cpf.substring(9);
            soma = 0;
            for (i = 10; i > 1; i--)
                  soma += numeros.charAt(10 - i) * i;
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(0))
                  return false;
            numeros = cpf.substring(0,10);
            soma = 0;
            for (i = 11; i > 1; i--)
                  soma += numeros.charAt(11 - i) * i;
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(1))
                  return false;
            return true;
            }
      else
            return false;
      }

function validaCnpj(cnpj)
      {
		  cnpj = cnpj.replace(".","");
		  cnpj = cnpj.replace(".","");
		  cnpj = cnpj.replace("/","");
		  cnpj = cnpj.replace("-","");
      var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
      digitos_iguais = 1;
      if (cnpj.length < 14 && cnpj.length < 15)
            return false;
      for (i = 0; i < cnpj.length - 1; i++)
            if (cnpj.charAt(i) != cnpj.charAt(i + 1))
                  {
                  digitos_iguais = 0;
                  break;
                  }
      if (!digitos_iguais)
            {
            tamanho = cnpj.length - 2
            numeros = cnpj.substring(0,tamanho);
            digitos = cnpj.substring(tamanho);
            soma = 0;
            pos = tamanho - 7;
            for (i = tamanho; i >= 1; i--)
                  {
                  soma += numeros.charAt(tamanho - i) * pos--;
                  if (pos < 2)
                        pos = 9;
                  }
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(0))
                  return false;
            tamanho = tamanho + 1;
            numeros = cnpj.substring(0,tamanho);
            soma = 0;
            pos = tamanho - 7;
            for (i = tamanho; i >= 1; i--)
                  {
                  soma += numeros.charAt(tamanho - i) * pos--;
                  if (pos < 2)
                        pos = 9;
                  }
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(1))
                  return false;
            return true;
            }
      else
            return false;
      } 



function validaFormulario() {
	var valido = true;
	var msg = '';
	if (get('email').value == '') {
		msg += 'O campo Email é obrigatório\n';
		valido = false;
	}
	if (get('cpf').value == '') {
		msg += 'O campo CPF é obrigatório\n';
		valido = false;
	}
	if (!validaCpf(get('cpf').value)) {
		msg += 'O CPF informado é inválido\n';
		valido = false;
	}
	if (get('nome').value == '') {
		msg += 'O campo Nome é obrigatório\n';
		valido = false;
	}
	
	if (get('rg').value == '') {
		msg += 'O campo Identidade/UF é obrigatório\n';
		valido = false;
	}

	if (get('cursoSelecionado').value == '') {
		msg += 'O campo Curso é obrigatório\n';
		valido = false;
	}
	
	if (get('dataNascimento').value == '') {
		msg += 'O campo Data de Nascimento é obrigatório\n';
		valido = false;
	}
	if (get('sexo').selectedIndex == 0) {
		msg += 'O campo Sexo é obrigatório\n';
		valido = false;
	}
	if (get('estadoCivil').selectedIndex == 0) {
		msg += 'O campo Estado Civil é obrigatório\n';
		valido = false;
	}
	if (get('cidadeNaturalidade').value == '') {
		msg += 'O campo Naturalidade é obrigatório\n';
		valido = false;
	}
	if (get('estadoNaturalidade').selectedIndex == 0) {
		msg += 'O campo Estado (Naturalidade) é obrigatório\n';
		valido = false;
	}
	if (get('nacionalidade').selectedIndex == 0) {
		msg += 'O campo Nacionalidade é obrigatório\n';
		valido = false;
	}
	if (get('pais').selectedIndex == 0) {
		msg += 'O campo País é obrigatório\n';
		valido = false;
	}
	if (get('cep').value == '') {
		msg += 'O campo CEP é obrigatório\n';
		valido = false;
	}
	if (get('endereco').value == '') {
		msg += 'O campo Endereço é obrigatório\n';
		valido = false;
	}
	if (get('bairro').value == '') {
		msg += 'O campo Bairro é obrigatório\n';
		valido = false;
	}
	if (get('cidade').value == '') {
		msg += 'O campo Cidade é obrigatório\n';
		valido = false;
	}
	if (get('estado').selectedIndex == 0) {
		msg += 'O campo Estado é obrigatório\n';
		valido = false;
	}
	if (get('telefone').value == '') {
		msg += 'O campo Telefone é obrigatório\n';
		valido = false;
	}
	if (get('enderecoOutro').checked == true)
	{
		if (get('paisEntrega').selectedIndex == 0) {
			msg += 'O campo País (Entrega) é obrigatório\n';
			valido = false;
		}
		if (get('cepEntrega').value == '') {
			msg += 'O campo CEP (Entrega) é obrigatório\n';
			valido = false;
		}
		if (get('enderecoEntrega').value == '') {
			msg += 'O campo Endereço (Entrega) é obrigatório\n';
			valido = false;
		}
		if (get('bairroEntrega').value == '') {
			msg += 'O campo Bairro (Entrega) é obrigatório\n';
			valido = false;
		}
		if (get('cidadeEntrega').value == '') {
			msg += 'O campo Cidade (Entrega) é obrigatório\n';
			valido = false;
		}
		if (get('estadoEntrega').selectedIndex == 0) {
			msg += 'O campo Estado (Entrega) é obrigatório\n';
			valido = false;
		}
		if (get('telefoneEntrega').value == '') {
			msg += 'O campo Telefone (Entrega) é obrigatório\n';
			valido = false;
		}
	}	
	if (get('areaConhecimento').selectedIndex == 0) {
		msg += 'O campo Área de Conhecimento é obrigatório\n';
		valido = false;
	}
	if (get('tipoInstituicao').selectedIndex == 0) {
		msg += 'O campo Tipo de Instituição é obrigatório\n';
		valido = false;
	}
	if (get('anoConclusao').value == '') {
		msg += 'O campo Ano de Conclusão é obrigatório\n';
		valido = false;
	}
	
	if(get('empregadoSim').checked == true) {
		if (get('selectEmpresas').selectedIndex == 0) {
			if (get('empresa').value == '') {
				msg += 'O campo Empresa é obrigatório\n';
				valido = false;
			}
		}
		if (get('cargo').selectedIndex == 0) {
			msg += 'O campo Cargo é obrigatório\n';
			valido = false;
		}
		if (get('faixaSalarial').selectedIndex == 0) {
			msg += 'O campo Faixa Salarial é obrigatório\n';
			valido = false;
		}
	}
	if (get('cursoSelecionado').value=='1380') {
		if (get('miniCurriculoGTI').value == '') {
			msg+='O campo Mini Currículo é obrigatório\n';	
			valido=false;
		}
	}	if (get('meioPagamentoSelecionado').value == '') {
		msg += 'O campo Meio de Pagamento é obrigatório\n';
		valido = false;
	}
	if (get('formaPagamentoSelecionado').value == '') {
		msg += 'O campo Forma de Pagamento é obrigatório\n';
		valido = false;
	}
	
	if (get('responsavelOutro').checked == true)
	{
		if (get('nomePagamento').value == '') {
			msg += 'O campo Nome/Razão Social (Pagamento) é obrigatório\n';
			valido = false;
		}
		if (get('tipoFisica').checked == true) {
			if (get('cpfPagamento').value == '') {
				msg += 'O campo CPF (Pagamento) é obrigatório\n';
				valido = false;
			}
			if (!validaCpf(get('cpfPagamento').value)) {
				msg += 'O CPF (Pagamento) informado é inválido\n';
				valido = false;
			}
		}
		else
		{
			if (get('cnpjPagamento').value == '') {
				msg += 'O campo CNPJ (Pagamento) é obrigatório\n';
				valido = false;
			}
			if (!validaCnpj(get('cnpjPagamento').value)) {
				msg += 'O CNPJ (Pagamento) informado é inválido\n';
				valido = false;
			}
		}
		if (get('paisPagamento').selectedIndex == 0) {
			msg += 'O campo País (Pagamento) é obrigatório\n';
			valido = false;
		}
		if (get('cepPagamento').value == '') {
			msg += 'O campo CEP (Pagamento) é obrigatório\n';
			valido = false;
		}
		if (get('enderecoPagamento').value == '') {
			msg += 'O campo Endereço (Pagamento) é obrigatório\n';
			valido = false;
		}
		if (get('bairroPagamento').value == '') {
			msg += 'O campo Bairro (Pagamento) é obrigatório\n';
			valido = false;
		}
		if (get('cidadePagamento').value == '') {
			msg += 'O campo Cidade (Pagamento) é obrigatório\n';
			valido = false;
		}
		if (get('estadoPagamento').selectedIndex == 0) {
			msg += 'O campo Estado (Pagamento) é obrigatório\n';
			valido = false;
		}
		if (get('telefonePagamento').value == '') {
			msg += 'O campo Telefone (Pagamento) é obrigatório\n';
			valido = false;
		}
	}	
	if (valido) {
		return true;
	}
	else
	{
		alert(msg);
		return false;
	}
}