//Datagrid
function cupom(){
Loader();
var cupom = document.getElementById('campocupom').value;
var cliente = document.getElementById('cliente').value;
var curso = document.getElementById('sessaocompra').value;
dados = 'CUPOM='+cupom+'&TABLE=CUPOM&CLIENTE='+cliente+'&CURSO='+curso+'';

$.ajax({
	type: "POST",
	url: "dados_db.php",
	data: dados
}).done(function(msg) {
	Unloader();
	//alert(msg);
	if(msg==""){
	location.reload();
	}
	document.getElementById("cupomspam").innerHTML=msg;
});


/*var cupom = document.getElementById('campocupom').value;
dados = 'CUPOM='+cupom+'&TABLE=CUPOM';


//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
ajax.open('POST', 'dados_db.php', true);
ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
ajax.send(dados);

alert(ajax.responseText);

if(cupom!='port145dm'){
document.getElementById("cupomspam").innerHTML='&nbsp*Cupom Inválido.';
}
else{
document.getElementById("cupomspam").innerHTML='&nbsp*Você ganhou gratuitamente o Curso A Nova Ortografia da Língua Portuguesa.';
}*/
}
function table()
{
	$(document).ready(function(){
		$('table tbody tr:odd').addClass('row1');
		$('table tbody tr:even').addClass('row2');
		//$('table tbody tr').hover(function(){$(this).addClass('select');}, function(){$(this).removeClass('select');});
	});
}

// JavaScript Document/**Accordion Panel*/
$(document).ready(function(){
	$(".bt-exibir").click(function(){
		$("#menurestante").slideToggle();
		
		if(document.getElementById("bt-exibir").value=='EXIBIR +')
		{
			document.getElementById("bt-exibir").value='OCULTAR';
		}
		else
		{
			document.getElementById("bt-exibir").value='EXIBIR +';
		}
	})
});

$(document).ready(function(){
	$(".g-menu-curso-todos-footer").click(function(){
		$(".g-menu-curso-todos-oculto").slideToggle();
		
		if(document.getElementById("visualizar-lista").innerHTML=='VEJA NOSSA LISTA COMPLETA DE CURSOS')
		{
			document.getElementById("visualizar-lista").innerHTML='OCULTAR LISTA COMPLETA';
		}
		else
		{
			document.getElementById("visualizar-lista").innerHTML='VEJA NOSSA LISTA COMPLETA DE CURSOS';
		}
	})
});


//Redirecionamento
function Redirect(url)
{
	Loader();
	location.href = url;	
}

//Carregamento
function Loader()
{
	document.getElementById('aguarde').style.display = 'inline';
}

function Unloader()
{
	document.getElementById('aguarde').style.display = 'none';
}

//Files
function FileEnvio()
{
	document.getElementById('file-envio').innerHTML=document.getElementById('file-original').value;
}

//EnviaFoto
function UploaderFoto()
{
	var foto = document.getElementById('file-original').value;	
	
	if(!foto)
	{
		return false;	
	}
	else
	{
		Loader();
		return true;	
	}
}


/**Limpar Campo*/
function Clear(id)
{
	document.getElementById(id).value='';	
}

//Auto Sugestão
function autoSugestao()
{
	//INICIALIZO O OBJET XHTMLREQUEST
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function()
		{
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)	
				{													
					// LImpo os resultados anteriores
					document.getElementById('auto-sugestao').innerHTML='';
					document.getElementById('auto-sugestao').style.display='none';
					
					//AQUI RETORNO O RESULTADO
					var resultado = ajax.responseText;					
					
					if(resultado)
					{
						document.getElementById("auto-sugestao").style.display='block';
						document.getElementById("auto-sugestao").innerHTML = resultado;
					}
				}
				else
				{
					alert(ajax.statusText);	
				}
			}
		}
		
		var string = document.getElementById("busca-portal").value;

		if((string.length)>5)
		{					
			//MONTA QUERYSTRING
			var dados = 'busca='+string;
		
			//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
			ajax.open('POST', 'sugestao.php', true);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			ajax.send(dados);
		}
	}
	
}

/**Seleciona item autocompletar*/
function selectSugestao(string)
{
	document.getElementById("busca-portal").value = string;
	document.getElementById("auto-sugestao").style.display='none';
	
	/**Monto a pesquisa*/
	var busca = document.getElementById("busca-portal").value;
	var opcaobusca = document.getElementById("opcaobusca").value;
	
	if((busca) && (opcaobusca))
	{
		Loader();
		document.forms["frmBusca"].submit();
	}
}

/**Close Popup*/
function ClosePopup()
{
	document.getElementById('backpopup').innerHTML='';
	document.getElementById('backpopup').style.display='none';		
}

/**Valida Busca**/
function Search()
{
	var busca = document.getElementById("busca-portal").value;
	
	if((!busca) || (busca == "Qual curso você deseja fazer?") || (busca == "Informe sua consulta"))
	{
		document.getElementById("busca-portal").style.background='#FFFFCC';
		document.getElementById("busca-portal").style.borderColor="#FF0000";
		document.getElementById("busca-portal").value = 'Informe sua consulta';
		document.getElementById('backpopup').style.display='inline';
		document.getElementById('backpopup').innerHTML='<div id="containerpopup"><input type="button" class="close" onclick="ClosePopup()"/><div id="bodypopup"><div id="redpopup"><img src="img/error.png" width="40" height="40" hspace="5" vspace="5" /><br/>Os seguintes erros foram encontrados.</div><b>* Informe sua consulta.</b></div></div>';		
		return false;
	}
	else
	{
		Loader();			
	}
}

/**Solicito nova senha*/
function GetPassword()
{
	$('.g-set-password').fadeIn();
}

/**Habilita Formularios*/
function OpenForm(id)
{
	$('#ocultar-certificado').fadeIn();
	$('#ocultar-senha').fadeIn();
	$('#retorno-certificado').hide();
	$('#retorno-senha').hide();
	$('.g-destaque-institucional').hide();
	$('.g-form-destaque').hide();
	$('.g-destaque-banner').hide();
	$('#'+id).fadeIn('slow');	
}

/**Valida consulta Certificado*/
function validaCertificado()
{
	//INICIALIZO O OBJET XHTMLREQUEST
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function()
		{
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)	
				{													
					
					//Cancelo o Loading
					document.getElementById('g-loader-certificado').style.display='none';
					
					//AQUI RETORNO O RESULTADO
					var resultado = ajax.responseText;					
					
					if(resultado)
					{
						$('#retorno-certificado').fadeIn();
						document.getElementById("retorno-certificado").innerHTML=resultado;
					}
				}
				else
				{
					alert(ajax.statusText);	
				}
			}
		}
			
		var matricula = document.getElementById('matricula').value;
		var captcha   = document.getElementById('captcha-certificado').value;
		var confere   = document.getElementById('captcha-confere').value;
		var erro      = 0;
		var msg       = '';
		
		/**Verifico*/	
		if(!matricula)
		{
			  document.getElementById('matricula').style.borderColor="#FF0000";
			  document.getElementById('matricula').style.backgroundColor="#FFF1BB";
			  msg = ' <b>&raquo; Informe o número da matrícula</b><br/><br/>' ;
			  erro = 1;		
		}
		if((!captcha) || (captcha == 'Informe o código da imagem aqui'))
		{
			  document.getElementById('captcha-certificado').style.borderColor="#FF0000";
			  document.getElementById('captcha-certificado').style.backgroundColor="#FFF1BB";
			  msg = msg + '<b> &raquo; Falha na verificação anti-fraude: digite as letras e/ou números conforme são mostrados na imagem.</b><br/><br/>' ;
			  erro = 1;		
		}
		else if(captcha)
		{
			if(captcha != confere)
			{
				  document.getElementById('captcha-certificado').style.borderColor="#FF0000";
				  document.getElementById('captcha-certificado').style.backgroundColor="#FFF1BB";
				  msg = msg + '<b> &raquo; Falha na verificação anti-fraude: digite as letras e/ou números conforme são mostrados na imagem.</b><br/><br/>' ;
				  erro = 1;		
			}
		}
		if(erro)
		{
			document.getElementById('backpopup').style.display='inline';
			document.getElementById('backpopup').innerHTML='<div id="containerpopup"><input type="button" class="close" onclick="ClosePopup()"/><div id="bodypopup"><div id="redpopup"><img src="img/error.png" width="40" height="40" hspace="0" vspace="0" /><br/>Os seguintes erros foram encontrados.</div>'+msg+'</div></div>';
			return false;	
		}
		else
		{
			document.getElementById('ocultar-certificado').style.display='none';
			document.getElementById('g-loader-certificado').style.display='inline';
				
			//MONTA QUERYSTRING
			var dados = 'matricula='+matricula;
		
			//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
			ajax.open('POST', 'verificar_certificado.php', true);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			ajax.send(dados);  
		}
	}			
}

/**Solicitar nova senha*/
function GetSenha()
{
	//INICIALIZO O OBJET XHTMLREQUEST
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function()
		{
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)	
				{													
					
					//Cancelo o Loading
					document.getElementById('g-loader-senha').style.display='none';
					
					//AQUI RETORNO O RESULTADO
					var resultado = ajax.responseText;	//ja esta assim	
					var array = resultado.split('*');		

					if(array[0] == 1)
					{
						$('#retorno-senha').fadeIn();
						document.getElementById("retorno-senha").innerHTML='<div style="text-align:left;">Olá '+array[3]+', os seus dados de acesso foram enviados com sucesso!<br/><br/> Você irá receber em instantes um e-mail do Instituto EADVIRTUAL no endereço: <b>'+array[1]+'</b> contendo seus dados para acesso à Área Restrita e à de Sala de Aula Online.<br/><br/>Caso não receba o e-mail em no máximo 10 minutos, verifique suas configurações ANTI-SPAM. Libere o recebimento de e-mails para o endereço: portal@eadvirtual.com.br <br/>Caso o problema persista, entre em contato conosco pelo e-mail: portal@eadvirtual.com.br</div><div class="clear"></div>';
					}
					else if(array[0] == 0)
					{
						$('#retorno-senha').fadeIn();
						document.getElementById("retorno-senha").innerHTML='<b>Dados não encontrados.<br/><br/> <p align="left">Verifique se você digitou corretamente.<br/><br/>Escolha uma opção abaixo:<br/><br/>Digitar novamente para recuperar dados - <a onclick="OpenForm(\'frmRecuperarSenha\')">clique aqui</a><br/>Fazer o cadastro no Portal EADVIRTUAL - <a href="efetuar-cadastro">clique aqui</a><br/>Entrar em contato com o Instituto EADVIRTUAL - <a href="institucional/34/central-de-Atendimento">clique aqui</a></p>';
					}					
				}
				else
				{
					alert(ajax.statusText);	
				}
			}
		}
			
		var email   = document.getElementById('email-senha').value;
		var captcha = document.getElementById('captcha-senha').value;
		var confere = document.getElementById('captcha-confere-senha').value;
		var erro    = 0;
		var msg     = '';
		
		/**Verifico*/	
		if(!email)
		{
		
			  document.getElementById('email-senha').style.borderColor="#FF0000";
			  document.getElementById('email-senha').style.backgroundColor="#FFF1BB";
			  msg = ' <b>&raquo; E-mail ou CPF não cadastrado</b><br/><br/>' ;
			  erro = 1;		
		}
		if((!captcha) || (captcha == 'Informe o código da imagem aqui'))
		{
			  document.getElementById('captcha-senha').style.borderColor="#FF0000";
			  document.getElementById('captcha-senha').style.backgroundColor="#FFF1BB";
			  msg = msg + '<b> &raquo; Falha na verificação anti-fraude: digite as letras e/ou números conforme são mostrados na imagem.</b><br/><br/>' ;
			  erro = 1;		
		}
		else if(captcha)
		{
			if(captcha != confere)
			{
				  document.getElementById('captcha-senha').style.borderColor="#FF0000";
				  document.getElementById('captcha-senha').style.backgroundColor="#FFF1BB";
				  msg = msg + '<b> &raquo; Falha na verificação anti-fraude: digite as letras e/ou números conforme são mostrados na imagem.</b><br/><br/>' ;
				  erro = 1;		
			}
		}
		if(erro)
		{
			document.getElementById('backpopup').style.display='inline';
			document.getElementById('backpopup').innerHTML='<div id="containerpopup"><input type="button" class="close" onclick="ClosePopup()"/><div id="bodypopup"><div id="redpopup"><img src="img/error.png" width="40" height="40" hspace="0" vspace="0" /><br/>Os seguintes erros foram encontrados.</div>'+msg+'</div></div>';
			return false;	
			
		}
		else
		{
			
			document.getElementById('ocultar-senha').style.display='none';
			document.getElementById('g-loader-senha').style.display='inline';
				
			//MONTA QUERYSTRING
			var dados = 'email='+email+'&TABLE=CLIENTE&ACTION=SENHA';
			
			//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
			ajax.open('POST', 'dados_db.php', true);
			
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			ajax.send(dados);  
			
		}
	}			
}

/**Enviar contato*/
function GetContato()
{
	//INICIALIZO O OBJET XHTMLREQUEST
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function()
		{
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)	
				{													
					
					//Cancelo o Loading
					document.getElementById('g-loader-contato').style.display='none';
					
					//AQUI RETORNO O RESULTADO
					var resultado = parseInt(ajax.responseText);					
					
					if(resultado == 1)
					{
						document.getElementById('nome-contato').value='';
						document.getElementById('email-contato').value='';
						document.getElementById('email-contato-confirmar').value='';
						document.getElementById('telefone-contato').value='';
						document.getElementById('assunto-contato').value='';
						document.getElementById('mensagem-contato').value='';
								
						$('#retorno-contato').fadeIn();
						document.getElementById("retorno-contato").innerHTML='<b>Mensagem enviada com sucesso!</b>';
					}
				}
				else
				{
					alert(ajax.statusText);	
				}
			}
		}
			
		var nome_contato  = document.getElementById('nome-contato').value;
		var email_contato = document.getElementById('email-contato').value;
		var email_contato_confirmar = document.getElementById('email-contato-confirmar').value;
		var telefone_contato = document.getElementById('telefone-contato').value;
		var assunto_contato = document.getElementById('assunto-contato').value;
		var mensagem_contato = document.getElementById('mensagem-contato').value;
		var erro    = 0;
		var msg     = '';
		
		/**Verifico*/	
		if(!nome_contato)
		{
			  document.getElementById('nome-contato').style.borderColor="#FF0000";
			  document.getElementById('nome-contato').style.backgroundColor="#FFF1BB";
			  msg = ' &raquo; Informe o seu nome.<br/><br/>' ;
			  erro = 1;		
		}
		if(!email_contato)
		{
			  document.getElementById('email-contato').style.borderColor="#FF0000";
			  document.getElementById('email-contato').style.backgroundColor="#FFF1BB";
			  msg = msg + ' &raquo; Informe o seu e-mail.<br/><br/>' ;
			  erro = 1;		
		}		
		if(email_contato != email_contato_confirmar)
		{
			  document.getElementById('email-contato').style.borderColor="#FF0000";
			  document.getElementById('email-contato').style.backgroundColor="#FFF1BB";
			  msg = msg + '&raquo; Os e-mails informados não conferem.<br/><br/>' ;
			  erro = 1;		
		}
		if(!assunto_contato)
		{
			  document.getElementById('assunto-contato').style.borderColor="#FF0000";
			  document.getElementById('assunto-contato').style.backgroundColor="#FFF1BB";
			  msg = msg + ' &raquo; Informe o assunto.<br/><br/>' ;
			  erro = 1;		
		}
		if((!mensagem_contato) || (mensagem_contato == 'Coloque sua mensagem aqui'))
		{
			  document.getElementById('mensagem-contato').style.borderColor="#FF0000";
			  document.getElementById('mensagem-contato').style.backgroundColor="#FFF1BB";
			  msg = msg + ' &raquo; Informe a sua mensagem.<br/><br/>' ;
			  erro = 1;		
		}			
		if(erro)
		{
			document.getElementById('backpopup').style.display='inline';
			document.getElementById('backpopup').innerHTML='<div id="containerpopup"><input type="button" class="close" onclick="ClosePopup()"/><div id="bodypopup"><div id="redpopup"><img src="img/error.png" width="40" height="40" hspace="0" vspace="0" /><br/>Os seguintes erros foram encontrados.</div>'+msg+'</div></div>';
			return false;	
		}
		else
		{
			document.getElementById('ocultar-contato').style.display='none';
			document.getElementById('g-loader-contato').style.display='inline';
				
			//MONTA QUERYSTRING
			var dados = 'nome_contato='+nome_contato+'&email_contato='+email_contato+'&telefone_contato='+telefone_contato+'&assunto_contato='+assunto_contato+'&mensagem_contato='+mensagem_contato;
		
			//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
			ajax.open('POST', 'enviar_mensagem.php', true);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			ajax.send(dados);  
		}
	}			
}

/**Habilita e desabilita Empresa - Formulario de Identificação*/
function habilFormEmpresaIdentificacao()
{
	 /**Habilito o formulario*/
	 $("#dados-empresa").fadeIn();
		   	
	var form = '';
	
	form = '<fieldset>'+
    	   '<br/>'+
    	   ''+
           '  	CNPJ:'+
           '    <input type="text" name="empresa-cnpj" class="g-identificacao-form-text" style="width: 130px;" onKeyDown="Mascara(this,Cnpj);" onKeyPress="Mascara(this,Cnpj);" maxlength="18" id="ob"/>'+
           ''+
           ''+
           ' 	Razão Social:'+
           '    <input type="text" name="empresa-razao" class="g-identificacao-form-text" style="width: 130px;" id="ob"/>'+
           ' </fieldset>';
		   
		   document.getElementById('dados-empresa').innerHTML=form;
		   
}
/**Habilita e desabilita Empresa - Formulario de Identificação*/
function habilFormEmpresaIdentificacao1()
{
	 /**Habilito o formulario*/
	 $("#dados-empresa").fadeIn();
		   	
	var form = '';
	
	form = '<fieldset>'+
    	   '<br/>'+
    	   '<div class="g-identificacao-form-item">'+
           '  	<div class="g-identificacao-form-label">CNPJ:</div>'+
           '    <div class="g-identificacao-form-input"><input type="text" name="empresa-cnpj" class="g-identificacao-form-text" onKeyDown="Mascara(this,Cnpj);" onKeyPress="Mascara(this,Cnpj);" maxlength="18" id="ob"/></div>'+
           '</div>'+
           '<div class="g-identificacao-form-item">'+
           ' 	<div class="g-identificacao-form-label">Razão Social:</div>'+
           '     <div class="g-identificacao-form-input"><input type="text" name="empresa-razao" class="g-identificacao-form-text" size="30" id="ob"/></div>'+
           '</div> '+
           '<div class="g-identificacao-form-item">'+
           ' 	<div class="g-identificacao-form-label">Cep:</div>'+
           '     <div class="g-identificacao-form-input"><input type="text" name="empresa-cep1" class="g-identificacao-form-text" size="5" id="empresa-cep1" onKeyDown="Mascara(this,Integer);" onKeyPress="Mascara(this,Integer);" maxlength="5" onblur="JumpCepEmpresa();"/> - <input type="text" name="empresa-cep2" class="g-identificacao-form-text" size="3" id="ob" onKeyDown="Mascara(this,Integer);" onKeyPress="Mascara(this,Integer);" maxlength="3" onblur="PesqCepEmpresa();"/></div>'+
           '</div>'+      
           '<div class="g-identificacao-form-item">'+
           ' 	<div class="g-identificacao-form-label">Endereço:</div>'+
           '     <div class="g-identificacao-form-input"><input type="text" name="empresa-logradouro" class="g-identificacao-form-text" id="empresa-logradouro"/></div>'+
           ' </div> '+
           ' <div class="g-identificacao-form-item">'+
           ' 	<div class="g-identificacao-form-label">Número:</div>'+
           '     <div class="g-identificacao-form-input"><input type="text" name="empresa-numero" class="g-identificacao-form-text" id="empresa-numero"/></div>'+
           ' </div>  '+
           ' <div class="g-identificacao-form-item">'+
           ' 	<div class="g-identificacao-form-label">Complemento:</div>'+
           '     <div class="g-identificacao-form-input"><input type="text" name="empresa-complemento" class="g-identificacao-form-text" id="empresa-complemento"/></div>'+
           ' </div> '+
           ' <div class="g-identificacao-form-item">'+
           ' 	<div class="g-identificacao-form-label">Bairro:</div>'+
           '     <div class="g-identificacao-form-input"><input type="text" name="empresa-bairro" class="g-identificacao-form-text" id="empresa-bairro"/></div>'+
           ' </div>   '+
           ' <div class="g-identificacao-form-item">'+
           ' 	<div class="g-identificacao-form-label">Cidade:</div>'+
           '     <div class="g-identificacao-form-input"><input type="text" name="empresa-cidade" class="g-identificacao-form-text" id="empresa-cidade"/></div>'+
           ' </div> '+
           ' <div class="g-identificacao-form-item">'+
           ' 	<div class="g-identificacao-form-label">Estado:</div>'+
           '     <div class="g-identificacao-form-input">'+
           '             <select name="empresa-estado" id="empresa-estado" class="g-identificacao-form-text">'+
           '                     <option value="" selected="selected">Selecione</option> '+
           '                     <option value="AC" >AC</option>'+
           '                     <option value="AL" >AL</option>'+
           '                     <option value="AM" >AM</option>'+
           '                     <option value="AP" >AP</option>'+
           '                     <option value="BA" >BA</option>'+
           '                     <option value="CE" >CE</option>'+
  
           '                     <option value="DF" >DF</option>'+
           '                     <option value="ES" >ES</option>'+
           '                     <option value="GO" >GO</option>'+
           '                     <option value="MA" >MA</option>'+
           '                     <option value="MG" >MG</option>'+
           '                     <option value="MS" >MS</option>'+
  
           '                     <option value="MT" >MT</option>'+
           '                     <option value="PA" >PA</option>'+
           '                     <option value="PB" >PB</option>'+
           '                     <option value="PE" >PE</option>'+
           '                     <option value="PI" >PI</option>'+
           '                     <option value="PR" >PR</option>'+
  
           '                     <option value="RJ" >RJ</option>'+
           '                     <option value="RN" >RN</option>'+
           '                     <option value="RO" >RO</option>'+
           '                     <option value="RR" >RR</option>'+
           '                     <option value="RS" >RS</option>'+
           '                     <option value="SC" >SC</option>'+
  
           '                     <option value="SE" >SE</option>'+
           '                     <option value="SP" >SP</option>'+
           '                     <option value="TO" >TO</option>'+
           '               </select>                 '+
           '     </div>				'+
           ' </div>'+
           ' </fieldset>';
		   
		   document.getElementById('dados-empresa').innerHTML=form;
		   
}

function DesabilFormEmpresaIdentificacao()
{
	 /**Habilito o formulario*/
	 $("#dados-empresa").fadeOut;
	 	
	document.getElementById('dados-empresa').innerHTML='';	
}

//Valida formulario
function validarFormulario() 
{   
	//LEIO O FORMULARIO E SEUS RESPECTIVOS OBJETOS
	var frm = document.getElementById("frmCadastro");
	var numElementos = frm.elements.length;
	var msg  = '';
	var cep  = 0;
	var nasc = 0;
	var erro = 0;
	
	for(var i = 0; i < numElementos; i++)
	{
		
		if((frm.elements[i].value == '') && (frm.elements[i].id == 'ob'))
		{
			frm.elements[i].style.borderColor="#FF0000";
			frm.elements[i].style.backgroundColor="#FFF1BB";
			erro++;
			
			if(frm.elements[i].name == 'nome')
			{
				msg = msg + ' &raquo; Informe o seu nome<br/><br/>' ;
			}		
			if(frm.elements[i].name == 'dia')
			{
				msg = msg + ' &raquo; Informe o dia do seu nascimento<br/><br/>' ;
			}
			if(frm.elements[i].name == 'mes')
			{
				msg = msg + ' &raquo; Informe o mês do seu nascimento<br/><br/>' ;			
			}
			if(frm.elements[i].name == 'ano')
			{
				msg = msg + ' &raquo; Informe o ano do seu nascimento<br/><br/>' ;					
			}
			if(frm.elements[i].name == 'cpf')
			{
				msg = msg + ' &raquo; Informe o seu CPF<br/><br/>' ;
			}	
			if(frm.elements[i].name == 'ddd')
			{
				msg = msg + ' &raquo; Informe o DDD<br/><br/>' ;
			}	
			if(frm.elements[i].name == 'telefone')
			{
				msg = msg + ' &raquo; Informe o Telefone<br/><br/>' ;
			}
			if(!cep)
			{
				if((frm.elements[i].name == 'cep1') || (frm.elements[i].name == 'cep2'))
				{
					cep++;
				}
				if(cep)
				{
					msg = msg + ' &raquo; Informe o seu CEP<br/><br/>' ;
				}
			}
			if(frm.elements[i].name == 'email')
			{
				msg = msg + ' &raquo; Informe o seu e-mail<br/><br/>' ;
			}
			if(frm.elements[i].name == 'email-confirmar')
			{
				msg = msg + ' &raquo; Confirme o seu e-mail<br/><br/>' ;
			}
			if(frm.elements[i].name == 'senha')
			{
				msg = msg + ' &raquo; Informe sua senha<br/><br/>' ;
			}
			if(frm.elements[i].name == 'senha-confirmar')
			{
				msg = msg + ' &raquo; Confirme sua senha<br/><br/>' ;
			}
			if(frm.elements[i].name == 'empresa_nome')
			{
				msg = msg + ' &raquo; Informe o nome da Empresa<br/><br/>' ;
			}																
			
		}
		else if((frm.elements[i].value != '') && (frm.elements[i].name == 'email'))
		{
			var email = frm.elements[i].value;	
		}
		else if((frm.elements[i].value != '') && (frm.elements[i].name == 'email-confirmar'))
		{
			var email_confirmar = frm.elements[i].value;	
		}
		else if((frm.elements[i].value != '') && (frm.elements[i].name == 'senha'))
		{
			var senha = frm.elements[i].value;	
		}
		else if((frm.elements[i].value != '') && (frm.elements[i].name == 'senha-confirmar'))
		{
			var senha_confirmar = frm.elements[i].value;	
		}
		
		else if((frm.elements[i].id == 'uso-cpf') && (frm.elements[i].value == ''))
		{
			msg = msg + ' &raquo; Informe um CPF válido.<br/><br/>' ;
			erro++;
		}	
		
		else if((frm.elements[i].id == 'uso-cpf') && (frm.elements[i].value == '0'))
		{
			msg = msg + ' &raquo; Informe um CPF válido.<br/><br/>' ;
			erro++;
		}
		
		else if((frm.elements[i].id == 'uso-email') && (frm.elements[i].value == ''))
		{
			msg = msg + ' &raquo; Informe um e-mail válido.<br/><br/>' ;
		}	
		
		else if((frm.elements[i].id == 'uso-email') && (frm.elements[i].value == '0'))
		{
			msg = msg + ' &raquo; Informe um e-mail válido.<br/><br/>' ;
		}													

	}
	
	if(email)
	{
		if ((email.indexOf("@") < 1) && (email.indexOf('.') < 7))
  		{
    		msg = msg + ' &raquo; Informe um e-mail válido<br/><br/>' ;
			erro++;
  		}
		else if(email != email_confirmar)
		{
    		msg = msg + ' &raquo; E-mails não conferem<br/><br/>' ;
			erro++;			
		}
	}
	
	if(senha)
	{
		if(senha != senha_confirmar)
		{
    		msg = msg + ' &raquo; Senhas não conferem<br/><br/>' ;
			erro++;				
		}
		if((senha.length < 6) || (senha.length > 10))
		{
    		msg = msg + ' &raquo; A senha deve conter entre 6 a 10 caracteres.<br/><br/>' ;
			erro++;					
		}
	}
	
	if(erro)
	{
		document.getElementById('backpopup').style.display='inline';
		document.getElementById('backpopup').innerHTML='<div id="containerpopup"><input type="button" class="close" onclick="ClosePopup()"/><div id="bodypopup"><div id="redpopup"><img src="img/error.png" width="40" height="40" hspace="0" vspace="0" /><br/>Os seguintes erros foram encontrados.</div>'+msg+'</div></div>';
		return false;	
	}
	else
	{
		Loader();
    	return true;   
	}
}


//Valida formulario login
function validarFormularioLogin() 
{   
	//LEIO O FORMULARIO E SEUS RESPECTIVOS OBJETOS
	var frm = document.getElementById("frmLogin");
	var numElementos = frm.elements.length;
	var msg  = '';
	var erro = 0;
	var email = '';
	var senha = '';
	
	for(var i = 0; i < numElementos; i++)
	{		
		if((frm.elements[i].value == '') && (frm.elements[i].id == 'ob'))
		{
			frm.elements[i].style.borderColor="#FF0000";
			frm.elements[i].style.backgroundColor="#FFF1BB";
			erro++;

			if(frm.elements[i].name == 'login-email')
			{
				msg = msg + ' &raquo; Informe o seu e-mail<br/><br/>' ;
			}

			if(frm.elements[i].name == 'login-senha')
			{
				msg = msg + ' &raquo; Informe sua senha<br/><br/>' ;
			}
		}
		else if((frm.elements[i].value != '') && (frm.elements[i].name == 'login-email'))
		{
			var email = frm.elements[i].value;	
		}			
	}
	
	
	
	if(erro)
	{
		document.getElementById('backpopup').style.display='inline';
		document.getElementById('backpopup').innerHTML='<div id="containerpopup"><input type="button" class="close" onclick="ClosePopup()"/><div id="bodypopup"><div id="redpopup"><img src="img/error.png" width="40" height="40" hspace="0" vspace="0" /><br/>Os seguintes erros foram encontrados.</div>'+msg+'</div></div>';
		return false;	
	}
	else
	{
		Loader();
    	return true;   
	}
}


/**Salta campo CEP*/
function JumpCep()
{ 
	//LEIO O FORMULARIO E SEUS RESPECTIVOS OBJETOS
	var frm = document.getElementById("frmDadosPessoais");
	var numElementos = frm.elements.length;
	
	for(var i = 0; i < numElementos; i++)
	{		
		if((frm.elements[i].name == 'cep1') && (frm.elements[i].value.length == 5))
		{
			i++;
			frm.elements[i].focus();
		}	
	}
}

/**Salta campo CEP*/
function JumpCepEmpresa()
{ 
	//LEIO O FORMULARIO E SEUS RESPECTIVOS OBJETOS
	var frm = document.getElementById("frmCadastro");
	var numElementos = frm.elements.length;
	
	for(var i = 0; i < numElementos; i++)
	{		
		if((frm.elements[i].name == 'empresa-cep1') && (frm.elements[i].value.length == 5))
		{
			i++;
			frm.elements[i].focus();
		}	
	}
}

/**Salta campo DDD*/
function JumpDDD(campo)
{ 
	//LEIO O FORMULARIO E SEUS RESPECTIVOS OBJETOS
	var frm = document.getElementById("frmCadastro");
	var numElementos = frm.elements.length;
	
	for(var i = 0; i < numElementos; i++)
	{		
		if((frm.elements[i].name == campo) && (frm.elements[i].value.length == 2))
		{
			i++;
			frm.elements[i].focus();
		}
	}
}

//Autenticação junto ao carrinho de compras
function CartLogin()
{
	//INICIALIZO O OBJET XHTMLREQUEST
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function()
		{
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)	
				{				
					//AQUI RETORNO O RESULTADO COM AS DEVIDAS PORCENTAGENS 
					var resultado = ajax.responseText;
					
					//OCULTO O LOADER
					Unloader();
					
					//CAPTURO OS DADOS DA CONSULTA		
					var array = resultado.split("*");
														
					if(array[0] == 1)
					{
						document.getElementById('dados-login-cart').style.display='none';
						document.getElementById('g-carrinho-cadastro').style.display='none';
						document.getElementById('usuario-cart').style.display='inline';
						document.getElementById('usuario-cart').innerHTML='Seja bem-vindo(a) <b>'+ array[1] + '</b> (' + array[2] +')';
						document.getElementById('insert-cart').style.display='inline';
						document.getElementById('insert-cart').innerHTML='<div class="clear"></div><div class="welcome">&nbsp;</div>';
						
						/**Aqui armazeno o ID do cliente que esta efetuando a compra*/
						document.getElementById('cliente-id').value=array[3];
					}
					else if(array[0] == 0)
					{
						document.getElementById('usuario-cart').style.display='inline';
						document.getElementById('usuario-cart').innerHTML='<span class="red">E-MAIL ou SENHA inválidos!</span>';
					}
				}
				else
				{
					alert(ajax.statusText);	
				}
			}
		}
		
		//CAMPOS INFORMADOS
		var email = document.getElementById('cart-login-email').value;
		var senha = document.getElementById('cart-login-senha').value;
		var erro  = '';
		var msg   = '';		

		/**Verifico se foi informado o email*/
		if(!email)
		{
			document.getElementById('cart-login-email').style.borderColor="#FF0000";
			document.getElementById('cart-login-email').style.backgroundColor="#FFF1BB";
			msg = ' &raquo; E-mail ou CPF não cadastrado.<br/><br/>' ;
			erro++;			
		}
		
		/**Verifico se foi informado a senha*/
		if(!senha)
		{
			document.getElementById('cart-login-senha').style.borderColor="#FF0000";
			document.getElementById('cart-login-senha').style.backgroundColor="#FFF1BB";
			msg = msg + ' &raquo; Informe a senha utilizada no cadastro<br/><br/>' ;
			erro++;			
		}
		
		/**Verifico se o email informado é válido*/
						

		if(erro)
		{
			document.getElementById('backpopup').style.display='inline';
			document.getElementById('backpopup').innerHTML='<div id="containerpopup"><input type="button" class="close" onclick="ClosePopup()"/><div id="bodypopup"><div id="redpopup"><img src="img/error.png" width="40" height="40" hspace="0" vspace="0" /><br/>Os seguintes erros foram encontrados.</div>'+msg+'</div></div>';
			return false;	
		}
		
		else
		{
			//HABILITO O LOADER
			Loader();
								
			//MONTA QUERYSTRING
			dados = 'login-email='+email+'&login-senha='+senha+'&TABLE=CLIENTE&ACTION=LOGINCART';
		
			//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
			ajax.open('POST', 'dados_db.php', true);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			ajax.send(dados);
		}				
	}	
}

function CartNewLogin()
{
	$('#usuario-cart').fadeOut();
	$('#dados-login-cart').fadeIn();
	
	/**Retiro o ID do cliente que esta efetuando a compra*/
	document.getElementById('cliente-id').value='';			
}

/**Formulario de cadastro carrinho de compras*/
function CartInsertUser()
{
	//INICIALIZO O OBJET XHTMLREQUEST
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function()
		{
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)	
				{													
					
					//Cancelo o Loading
					Unloader();
					
					//AQUI RETORNO O RESULTADO
					var resultado = ajax.responseText;					

					var array = resultado.split("*");
					
					if(array[3])
					{
						location.href='#carrinhotop';
						document.getElementById('g-carrinho-cadastro').style.display='none';
						document.getElementById('dados-login-cart').style.display='none';
						/*document.getElementById('frmLoginCart').style.display='none';*/
						$('#frmCadastro').fadeOut();
						//$('#frmLoginCart').fadeOut();
						document.getElementById('cliente-id').value=array[3];
						document.getElementById('insert-cart').style.display='inline';
						document.getElementById('insert-cart').innerHTML='<div class="welcome"></div>';
						document.getElementById('usuario-cart').style.display='inline';
						document.getElementById('usuario-cart').innerHTML='Seja bem-vindo(a) <b>'+ array[1] + '</b> (' + array[2] +')';

					}
				
				}
				else
				{
					alert(ajax.statusText);	
				}
			}
		}
		
		//LEIO O FORMULARIO E SEUS RESPECTIVOS OBJETOS
		var frm = document.getElementById("frmCadastro");
		var numElementos = frm.elements.length;
		var email = '';
		var erro = '';
		var msg = '';
		var contcep = 0;
		var conttel = 0;
		var contnas = 0;

		
		for(var i = 0; i < numElementos; i++)
		{		
			if((frm.elements[i].value == '') && (frm.elements[i].id == 'ob'))
			{
				frm.elements[i].style.borderColor="#FF0000";
				frm.elements[i].style.backgroundColor="#FFF1BB";
				erro++;
	
				if(frm.elements[i].name == 'empresa-nome')
				{
					msg = msg + ' &raquo; Informe o nome da Empresa<br/><br/>' ;
				}
								
				if(frm.elements[i].name == 'nome')
				{
					msg = msg + ' &raquo; Informe o seu nome<br/><br/>' ;
				}
	
				if((frm.elements[i].name == 'dia') || (frm.elements[i].name == 'mes') || (frm.elements[i].name == 'ano'))
				{
					if(contnas == 0)
					{
						msg = msg + ' &raquo; Informe a data completa do seu nascimento: dd/mm/aaaa<br/><br/>' ;
					}
					contnas++;
				}
				
				if(frm.elements[i].name == 'cpf')
				{
					msg = msg + ' &raquo; Informe o seu Cpf<br/><br/>' ;
				}
				
				if((frm.elements[i].name == 'ddd') || (frm.elements[i].name == 'telefone'))
				{
					if(conttel == 0)
					{
						msg = msg + ' &raquo; Informe o seu Telefone + DDD<br/><br/>' ;
					}
					conttel++;
				}
				
				if((frm.elements[i].name == 'cep1') || (frm.elements[i].name == 'cep2'))
				{
					if(contcep == 0)
					{
						msg = msg + ' &raquo; Informe o seu CEP<br/><br/>' ;
					}
					
					contcep++;
				}
												
				if(frm.elements[i].name == 'email')
				{
					msg = msg + ' &raquo; Informe o seu e-mail<br/><br/>' ;
				}
				if(frm.elements[i].name == 'email-confirmar')
				{
					msg = msg + ' &raquo; Confirme o seu e-mail<br/><br/>' ;
				}
				if(frm.elements[i].name == 'senha')
				{
					msg = msg + ' &raquo; Informe sua senha<br/><br/>' ;
				}
				if(frm.elements[i].name == 'senha-confirmar')
				{
					msg = msg + ' &raquo; Confirme sua senha<br/><br/>' ;
				}																
				
			}
			
			/**Capturo os dados da empresa caso estejam habilitados**/
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'empresa-cnpj'))
			{
				var empresa_cnpj = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'empresa-nome'))
			{
				var empresa_razao = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'empresa-cep1'))
			{
				var empresa_cep1 = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'empresa-cep2'))
			{
				var empresa_cep2 = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'empresa-logradouro'))
			{
				var empresa_logradouro = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'empresa-numero'))
			{
				var empresa_numero = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'empresa-complemento'))
			{
				var empresa_complemento = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'empresa-bairro'))
			{
				var empresa_bairro = frm.elements[i].value;	
			}	
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'empresa-cidade'))
			{
				var empresa_cidade = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'empresa-estado'))
			{
				var empresa_estado = frm.elements[i].value;	
			}																										
			
			
			/**Capturo os dados do cliente**/	
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'nome'))
			{
				var nome = frm.elements[i].value;	
			}
			if(frm.elements[i].type=="radio" && frm.elements[i].checked)
			{
				var sexo = frm.elements[i].value;
			}		
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'dia'))
			{
				var dia = frm.elements[i].value;	
			}	
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'mes'))
			{
				var mes = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'ano'))
			{
				var ano = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'cpf'))
			{
				var cpf = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'ddd'))
			{
				var ddd = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'telefone'))
			{
				var telefone = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'ddd-comercial'))
			{
				var ddd_comercial = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'telefone-comercial'))
			{
				var telefone_comercial = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'ddd-celular'))
			{
				var ddd_celular = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'celular'))
			{
				var celular = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'cep1'))
			{
				var cep1 = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'cep2'))
			{
				var cep2 = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'logradouro'))
			{
				var logradouro = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'numero'))
			{
				var numero = frm.elements[i].value;	
			}	
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'complemento'))
			{
				var complemento = frm.elements[i].value;	
			}																																														
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'bairro'))
			{
				var bairro = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'cidade'))
			{
				var cidade = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'estado'))
			{
				var estado = frm.elements[i].value;	
			}																		
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'email'))
			{
				var email = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'email-confirmar'))
			{
				var email_confirmar = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'senha'))
			{
				var senha = frm.elements[i].value;	
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'senha-confirmar'))
			{
				var senha_confirmar = frm.elements[i].value;	
			}
			
			else if((frm.elements[i].id == 'uso-cpf') && (frm.elements[i].value == ''))
			{
				msg = msg + ' &raquo; Informe um CPF válido.<br/><br/>' ;
				erro++;
			}	
			
			else if((frm.elements[i].id == 'uso-cpf') && (frm.elements[i].value == '0'))
			{
				msg = msg + ' &raquo; Informe um CPF válido.<br/><br/>' ;
				erro++;
			}
			
			else if((frm.elements[i].id == 'uso-email') && (frm.elements[i].value == ''))
			{
				msg = msg + ' &raquo; Informe um e-mail válido.<br/><br/>' ;
				erro++;
			}	
			
			else if((frm.elements[i].id == 'uso-email') && (frm.elements[i].value == '0'))
			{
				msg = msg + ' &raquo; Informe um e-mail válido.<br/><br/>' ;
				erro++;
			}
			else if((frm.elements[i].value != '') && (frm.elements[i].name == 'informativo'))
			{
				var informativo = frm.elements[i].value;	
			}																
	
		}
		
		if(email)
		{
			if ((email.indexOf("@") < 1) && (email.indexOf('.') < 7))
			{
				msg = msg + ' &raquo; Informe um e-mail válido<br/><br/>' ;
				erro++;
			}
			else if(email != email_confirmar)
			{
				msg = msg + ' &raquo; E-mails não conferem<br/><br/>' ;
				erro++;			
			}
		}
		
		if(senha)
		{
			if(senha != senha_confirmar)
			{
				msg = msg + ' &raquo; Senhas não conferem<br/><br/>' ;
				erro++;				
			}
			if((senha.length < 6) || (senha.length > 10))
			{
				msg = msg + ' &raquo; A senha deve conter entre 6 a 10 caracteres.<br/><br/>' ;
				erro++;					
			}
		}
		
		if(erro)
		{
			document.getElementById('backpopup').style.display='inline';
			document.getElementById('backpopup').innerHTML='<div id="containerpopup"><input type="button" class="close" onclick="ClosePopup()"/><div id="bodypopup"><div id="redpopup"><img src="img/error.png" width="40" height="40" hspace="0" vspace="0" /><br/>Os seguintes erros foram encontrados.</div>'+msg+'</div></div>';
			return false;	
		}
		else
		{
			Loader();
			
			//DADOS EMPRESA
			dados = 'empresa-cnpj='+empresa_cnpj+'&empresa-razao='+empresa_razao+'&empresa-cep1='+empresa_cep1+'&empresa-logradouro='+empresa_logradouro+'&empresa-numero='+empresa_numero+'&empresa-complemento='+empresa_complemento+'&empresa-bairro='+empresa_bairro+'&empresa-cidade='+empresa_cidade+'&empresa-estado='+empresa_estado;
			
			//DADOS CLIENTE
			dados = dados + '&nome='+nome+'&sexo='+sexo+'&dia='+dia+'&mes='+mes+'&ano='+ano+'&cpf='+cpf+'&ddd='+ddd+'&telefone='+telefone+'&ddd-comercial='+ddd_comercial+'&telefone-comercial='+telefone_comercial+'&ddd-celular='+ddd_celular+'&celular='+celular+'&cep1='+cep1+'&cep2='+cep2+'&logradouro='+logradouro+'&numero='+numero+'&complemento='+complemento+'&bairro='+bairro+'&cidade='+cidade+'&estado='+estado+'&email='+email+'&senha='+senha+'&informativo='+informativo;
			
			//DADOS TABELA+AÇÃO
			dados = dados + '&TABLE=CLIENTE&ACTION=INSERTCART';
		
			//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
			ajax.open('POST', 'dados_db.php', true);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			ajax.send(dados);  
		}
	}			
}

//Carrega endereço
function PesqCep()
{
	//INICIALIZO O OBJET XHTMLREQUEST
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function()
		{
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)	
				{				
					//AQUI RETORNO O RESULTADO COM AS DEVIDAS PORCENTAGENS 
					var resultado = ajax.responseText;
					
					//OCULTO O LOADER
					Unloader();
					
					//CAPTURO OS DADOS DA CONSULTA		
					var array = resultado.split("*");
					document.getElementById("logradouro").value=array[1]+' '+array[2];
					document.getElementById("complemento").value=array[2];
					document.getElementById("bairro").value=array[3];
					document.getElementById("cidade").value=array[4];
					document.getElementById("estado").value=array[5];
				}
				else
				{
					alert(ajax.statusText);	
				}
			}
		}
		
		//LEIO O FORMULARIO E SEUS RESPECTIVOS OBJETOS
		var frm = document.getElementById("frmDadosPessoais");
		var numElementos = frm.elements.length;
		
		for(var i = 0; i < numElementos; i++)
		{		
			if((frm.elements[i].name == 'cep1') && (frm.elements[i].value.length == 5))
			{
				var cep1 = frm.elements[i].value;
			}			
			if((frm.elements[i].name == 'cep2') && (frm.elements[i].value.length == 3) && (frm.elements[i].value.length > 2))
			{
				var cep2 = frm.elements[i].value;
			}
		}
		
		var cep = cep1+cep2;
		
		if(cep.length==8)
		{
			//HABILITO O LOADER
			Loader();
								
			//MONTA QUERYSTRING
			dados = 'cep='+cep;
		
			//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
			ajax.open('POST', 'cep.php', true);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			ajax.send(dados);
		}				
	}	
}

//Carrega endereço empresa
function PesqCepEmpresa()
{
	//INICIALIZO O OBJET XHTMLREQUEST
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function()
		{
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)	
				{				
					//AQUI RETORNO O RESULTADO COM AS DEVIDAS PORCENTAGENS 
					var resultado = ajax.responseText;
					
					//OCULTO O LOADER
					Unloader();
					
					//CAPTURO OS DADOS DA CONSULTA		
					var array = resultado.split("*");
					document.getElementById("empresa-logradouro").value=array[1]+' '+array[2];
					document.getElementById("empresa-complemento").value=array[2];
					document.getElementById("empresa-bairro").value=array[3];
					document.getElementById("empresa-cidade").value=array[4];
					document.getElementById("empresa-estado").value=array[5];
				}
				else
				{
					alert(ajax.statusText);	
				}
			}
		}
		
		//LEIO O FORMULARIO E SEUS RESPECTIVOS OBJETOS
		var frm = document.getElementById("frmCadastro");
		var numElementos = frm.elements.length;
		
		for(var i = 0; i < numElementos; i++)
		{		
			if((frm.elements[i].name == 'empresa-cep1') && (frm.elements[i].value.length == 5))
			{
				var cep1 = frm.elements[i].value;
			}			
			if((frm.elements[i].name == 'empresa-cep2') && (frm.elements[i].value.length == 3) && (frm.elements[i].value.length > 2))
			{
				var cep2 = frm.elements[i].value;
			}
		}
		
		var cep = cep1+cep2;
		
		if(cep.length==8)
		{
			//HABILITO O LOADER
			Loader();
								
			//MONTA QUERYSTRING
			dados = 'cep='+cep;
		
			//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
			ajax.open('POST', 'cep.php', true);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			ajax.send(dados);
		}				
	}	
}

//Valida CPF
function PesqCPF()
{
	//INICIALIZO O OBJET XHTMLREQUEST
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function()
		{
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)	
				{				
					//AQUI RETORNO O RESULTADO COM AS DEVIDAS PORCENTAGENS 
					var resultado = parseInt(ajax.responseText);
					
					//OCULTO O LOADER
					document.getElementById('loader-cpf').style.display='none';
					
					//Verifico os dados da consulta
					if(resultado == 1)
					{
						document.getElementById("erro-cpf").innerHTML=' * Cpf inválido';
						document.getElementById("uso-cpf").value = 0;
					}
					else if(resultado == 2)
					{
						document.getElementById("erro-cpf").innerHTML=' <br>* CPF cadastrado. <br>Utilize o formulário ao lado para <b>Acessar</b> ou <b>Recuperar Dados de Acesso</b>';
						document.getElementById("uso-cpf").value = 0;
					}
					else
					{
						document.getElementById("uso-cpf").value = 1;
						document.getElementById("erro-email").innerHTML='';
					}
				}
				else
				{
					alert(ajax.statusText);	
				}
			}
		}
		document.getElementById("erro-cpf").innerHTML='';
		
		//LEIO O FORMULARIO E SEUS RESPECTIVOS OBJETOS
		var frm = document.getElementById("frmCadastro");
		var numElementos = frm.elements.length;
		
		for(var i = 0; i < numElementos; i++)
		{		
			if((frm.elements[i].name == 'cpf') && (frm.elements[i].value.length == 14))
			{
				var cpf = frm.elements[i].value;
			}			
		}
			
		if(cpf.length==14)
		{
			//HABILITO O LOADER
			document.getElementById('loader-cpf').style.display='inline';
								
			//MONTA QUERYSTRING
			dados = 'cpf='+cpf+'&TABLE=CLIENTE&ACTION=CPF';
		
			//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
			ajax.open('POST', 'dados_db.php', true);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			ajax.send(dados);
		}				
	}	
}

//Valida EMAIL
function PesqEmail()
{
	//INICIALIZO O OBJET XHTMLREQUEST
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function()
		{
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)	
				{				
					//AQUI RETORNO O RESULTADO COM AS DEVIDAS PORCENTAGENS 
					var resultado = parseInt(ajax.responseText);
					
					//OCULTO O LOADER
					document.getElementById('loader-email').style.display='none';
					
					//Verifico os dados da consulta
					if(resultado == 1)
					{
						document.getElementById("erro-email").innerHTML=' * E-mail informado inválido';
						document.getElementById("uso-email").value = 0;
					}
					else if(resultado == 2)
					{
						document.getElementById("erro-email").innerHTML=' * Este e-mail já está cadastrado. Utilize <b>outro e-mail</b> ou <b>Recuperar Dados de Acesso</b>';
						document.getElementById("uso-email").value = 0;
					}
					else
					{
						document.getElementById("uso-email").value = 1;
						
					}
					
				}
				else
				{
					alert(ajax.statusText);	
				}
			}
		}
		
		document.getElementById("erro-email").innerHTML='';
		
		//LEIO O FORMULARIO E SEUS RESPECTIVOS OBJETOS
		var frm = document.getElementById("frmCadastro");
		var numElementos = frm.elements.length;
		
		for(var i = 0; i < numElementos; i++)
		{		
			if(frm.elements[i].name == 'email')
			{
				var email = frm.elements[i].value;
			}			
		}
			
		if(email)
		{
			//HABILITO O LOADER
			document.getElementById('loader-email').style.display='inline';
								
			//MONTA QUERYSTRING
			dados = 'email='+email+'&TABLE=CLIENTE&ACTION=EMAIL';
		
			//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
			ajax.open('POST', 'dados_db.php', true);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			ajax.send(dados);
		}				
	}	
}


//Envia sugestão de curso
function ValidaSugestaoCurso()
{
	//INICIALIZO O OBJET XHTMLREQUEST
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function()
		{
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)	
				{				
					//AQUI RETORNO O RESULTADO COM AS DEVIDAS PORCENTAGENS 
					var resultado = ajax.responseText;
					
					//OCULTO O LOADER
					Unloader();
					
					//DADOS DO FORMULÁRIO
					document.getElementById('sugerido-nome').value='';
					document.getElementById('sugerido-email').value='';
					document.getElementById('sugerido-descricao').value='';
					
					document.getElementById('sugerido-sucesso').style.display='inline';
					
				}
				else
				{
					alert(ajax.statusText);	
				}
			}
		}
		
		
		//DADOS DO FORMULÁRIO
		var nome = document.getElementById('sugerido-nome').value;
		var email = document.getElementById('sugerido-email').value;
		var descricao = document.getElementById('sugerido-descricao').value;
		
		if(!nome)
		{
			  document.getElementById('sugerido-nome').style.borderColor="#FF0000";
			  document.getElementById('sugerido-nome').style.backgroundColor="#FFF1BB";
			  msg = ' &raquo; Informe o seu nome.<br/><br/>' ;
			  var erro = 1;				
		}
		
		if(!email)
		{
			  document.getElementById('sugerido-email').style.borderColor="#FF0000";
			  document.getElementById('sugerido-email').style.backgroundColor="#FFF1BB";
			  msg = msg + ' &raquo; Informe o seu e-mail.<br/><br/>' ;
			  var erro = 1;				
		}
		
		if(!descricao)
		{
			  document.getElementById('sugerido-descricao').style.borderColor="#FF0000";
			  document.getElementById('sugerido-descricao').style.backgroundColor="#FFF1BB";
			  msg = msg + ' &raquo; Informe a descrição do curso sugerido.<br/><br/>' ;
			  var erro = 1;				
		}
		
		if(erro)
		{
			document.getElementById('backpopup').style.display='inline';
			document.getElementById('backpopup').innerHTML='<div id="containerpopup"><input type="button" class="close" onclick="ClosePopup()"/><div id="bodypopup"><div id="redpopup"><img src="img/error.png" width="40" height="40" hspace="0" vspace="0" /><br/>Os seguintes erros foram encontrados.</div>'+msg+'</div></div>';
			return false;				
		}
		
		else
		{
			//HABILITO O LOADER
			Loader();
								
			//MONTA QUERYSTRING
			dados = 'nome='+nome+'&email='+email+'&descricao='+descricao+'&TABLE=CURSOSUGERIDO';
		
			//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
			ajax.open('POST', 'dados_db.php', true);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			ajax.send(dados);
		}				
	}	
}

/**Enviar comentário*/
function SetComentario()
{
	//INICIALIZO O OBJET XHTMLREQUEST
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function()
		{
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)	
				{													
					
					//Cancelo o Loading
					Unloader();
					
					//AQUI RETORNO O RESULTADO
					var resultado = parseInt(ajax.responseText);					
					
					if(resultado == 1)
					{
						$.msgbox("Depoimento enviado com sucesso.<b><br>A EADVIRTUAL agradece!</b> "); 
						document.getElementById('comentario-texto').value='';
						//document.getElementById('comentario-sucesso').innerHTML='Depoimento efetuado com sucesso!';
						
					}
					else if(resultado == 2)
					{
						$.msgbox("O seu depoimento ainda não foi publicado.<br><br> É necessário que você use o seu e-mail de cadastrado no Instituto EADVIRTUAL.", {type: "error"}); 
						//document.getElementById('comentario-erro').innerHTML='Seu comentário não pode ser efetuado. E-mail ou CPF não cadastrado..';
					}
				
				}
				else
				{
					alert(ajax.statusText);	
				}
			}
		}
		
		document.getElementById('comentario-sucesso').innerHTML='';
		document.getElementById('comentario-erro').innerHTML='';	
		var email = document.getElementById('comentario-email').value;
		var texto = document.getElementById('comentario-texto').value;
		var curso_id = document.getElementById('curso_id').value;
		var erro  = 0;
		var msg   = '';
		
		/**Verifico*/	
		if(!email)
		{
			  document.getElementById('comentario-email').style.borderColor="#FF0000";
			  document.getElementById('comentario-email').style.backgroundColor="#FFF1BB";
			  msg = ' <b>&raquo; E-mail ou CPF não cadastrado.</b><br/><br/>' ;
			  erro = 1;		
		}
		
		if(!texto)
		{
			  document.getElementById('comentario-texto').style.borderColor="#FF0000";
			  document.getElementById('comentario-texto').style.backgroundColor="#FFF1BB";
			  msg = msg + ' <b>&raquo; Informe o seu comentário</b><br/><br/>' ;
			  erro = 1;		
		}		

		if(erro)
		{
			document.getElementById('backpopup').style.display='inline';
			document.getElementById('backpopup').innerHTML='<div id="containerpopup"><input type="button" class="close" onclick="ClosePopup()"/><div id="bodypopup"><div id="redpopup"><img src="img/error.png" width="40" height="40" hspace="0" vspace="0" /><br/>Os seguintes erros foram encontrados.</div>'+msg+'</div></div>';
			return false;	
		}
		else
		{
			Loader()
				
			//MONTA QUERYSTRING
			var dados = 'email='+email+'&texto='+texto+'&curso_id='+curso_id+'&TABLE=DEPOIMENTO';
		
			//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
			ajax.open('POST', 'dados_db.php', true);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			ajax.send(dados);  
		}
	}			
}

/**Enviar comentário*/
function SetComentarioNoticia()
{
	//INICIALIZO O OBJET XHTMLREQUEST
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function()
		{
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)	
				{													
					
					//Cancelo o Loading
					Unloader();
					
					//AQUI RETORNO O RESULTADO
					var resultado = parseInt(ajax.responseText);					
					
					if(resultado == 1)
					{
						
						//document.getElementById('comentario-sucesso').innerHTML='Depoimento efetuado com sucesso!';
						$.msgbox("Obrigado pelo envio do seu comentário!<br><br><b>Em breve será publicado.</b> "); 
						document.getElementById('comentario-texto').value='';
						
					}
					else if(resultado == 2)
					{
						//document.getElementById('comentario-erro').innerHTML='Seu comentário não pode ser efetuado. E-mail ou CPF não cadastrado..';
						$.msgbox("O seu comentário ainda não foi publicado.<br><br> É necessário que você use o seu e-mail de cadastrado no Instituto EADVIRTUAL.", {type: "error"}); 
					}
				
				}
				else
				{
					alert(ajax.statusText);	
				}
			}
		}
		
		document.getElementById('comentario-sucesso').innerHTML='';
		document.getElementById('comentario-erro').innerHTML='';	
		var email = document.getElementById('comentario-email').value;
		var nome = document.getElementById('comentario-nome').value;
		var texto = document.getElementById('comentario-texto').value;
		var noticia_id = document.getElementById('noticia_id').value;
		var erro  = 0;
		var msg   = '';
		
		/**Verifico*/	
		if(!email)
		{
			  document.getElementById('comentario-email').style.borderColor="#FF0000";
			  document.getElementById('comentario-email').style.backgroundColor="#FFF1BB";
			  msg = ' <b>&raquo; E-mail ou CPF não cadastrado.</b><br/><br/>' ;
			  erro = 1;		
		}
		if(!nome)
		{
			  document.getElementById('comentario-nome').style.borderColor="#FF0000";
			  document.getElementById('comentario-nome').style.backgroundColor="#FFF1BB";
			  msg =  msg + ' <b>&raquo; Informe o nome utilizado no cadastro</b><br/><br/>' ;
			  erro = 1;		
		}		
		
		if(!texto)
		{
			  document.getElementById('comentario-texto').style.borderColor="#FF0000";
			  document.getElementById('comentario-texto').style.backgroundColor="#FFF1BB";
			  msg = msg + ' <b>&raquo; Informe o seu comentário</b><br/><br/>' ;
			  erro = 1;		
		}		

		if(erro)
		{
			document.getElementById('backpopup').style.display='inline';
			document.getElementById('backpopup').innerHTML='<div id="containerpopup"><input type="button" class="close" onclick="ClosePopup()"/><div id="bodypopup"><div id="redpopup"><img src="img/error.png" width="40" height="40" hspace="0" vspace="0" /><br/>Os seguintes erros foram encontrados.</div>'+msg+'</div></div>';
			return false;	
		}
		else
		{
			Loader()
				
			//MONTA QUERYSTRING
			var dados = 'email='+email+'&texto='+texto+'&noticia_id='+noticia_id+'&TABLE=DEPOIMENTO';
		
			//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
			ajax.open('POST', 'dados_db.php', true);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			ajax.send(dados);
			
		}
	}			
}

function SetDepoimento()
{
	$("#frmDepoimento").slideToggle();	
}

/**Habilita cadastro de empresa carrinho de compras*/
function HabilitaEmpresaCarrinho()
{
	var dados = '';
	$('#dados-empresa').fadeIn();
	
	dados = '<div class="g-carrinho-cadastro-item">'+
    		'	<div class="g-carrinho-cadastro-label">CNPJ:</div>'+
    		'	<div class="g-carrinho-cadastro-input"><input type="text" name="empresa-cnpj" size="30" /></div>'+
    		'</div>'+
            '<div class="g-carrinho-cadastro-item">'+
            '    	<div class="g-carrinho-cadastro-label">Razão Social:</div>'+
            '       <div class="g-carrinho-cadastro-input"><input type="text" name="empresa-nome" size="27" id="ob" /></div>'+
            '    </div> '+ 
            '    </div>                               ';
		
		document.getElementById('campos-form').innerHTML=dados;
};

function DesabilitaEmpresaCarrinho()
{
	document.getElementById('campos-form').innerHTML='';
	$('#dados-empresa').fadeOut();
}

/**Ocultar dados cartão*/
function HiddenCard(bandeira, valor)
{
	$('#dados-cartao').fadeOut();
	document.getElementById('diners').style.display='none';
	document.getElementById('bandeira').value=bandeira;
	document.getElementById('numparcelas').value=1;
	document.getElementById('valorparcela').value=valor;	
	
}

/**Habilita dados cartão Diners*/
function OpenCardDiners(curso, total)
{
	$('#dados-cartao').fadeOut();
	document.getElementById('diners').style.display='inline';
	document.getElementById('bandeira').value='Diners';
	document.getElementById('numparcelas').value=1;
	document.getElementById('valorparcela').value=total;
	
	//INICIALIZO O OBJET XHTMLREQUEST
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function()
		{
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)	
				{													
					
					//Cancelo o Loading
					Unloader();
					
					//AQUI RETORNO O RESULTADO
					var resultado = ajax.responseText;
					
					document.getElementById('combo-diners').innerHTML=resultado;
					
					/**Informo a bandeira selecionada*/
					document.getElementById('bandeira').value='Diners';
					document.getElementById('numparcelas').value=1;
				
				}
				else
				{
					alert(ajax.statusText);	
				}
			}
		}

		if((curso) && (total))
		{
			Loader();
				
			//MONTA QUERYSTRING
			var dados = 'bandeira=Diners&curso='+curso+'&total='+total+'&TABLE=PAGAMENTO';
		
			//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
			ajax.open('POST', 'dados_db.php', true);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			ajax.send(dados);  
		}
	}			
}

/**Habilita dados cartão*/
function OpenCard(bandeira, curso, total)
{
    document.getElementById('cartao-numero').maxLength=16;
	if((bandeira)=='Diners'){document.getElementById('cartao-numero').value=''; document.getElementById('cartao-numero').maxLength=14;}
	$('#dados-cartao').fadeIn();
	//document.getElementById('diners').style.display='none';
	
	//INICIALIZO O OBJET XHTMLREQUEST
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function()
		{
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)	
				{													
					
					//Cancelo o Loading
					Unloader();
					
					//AQUI RETORNO O RESULTADO
					var resultado = ajax.responseText;
					
					document.getElementById('combo-pagamento').innerHTML=resultado;
					
					/**Informo a bandeira selecionada*/
					document.getElementById('bandeira').value=bandeira;
					document.getElementById('numparcelas').value=1;
				
				}
				else
				{
					alert(ajax.statusText);	
				}
			}
		}

		if((bandeira) && (curso) && (total))
		{
			Loader();
				
			//MONTA QUERYSTRING
			
			var dados = 'bandeira='+bandeira+'&curso='+curso+'&total='+total+'&TABLE=PAGAMENTO';
		
			//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
			ajax.open('POST', 'dados_db.php', true);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			ajax.send(dados);  
		}
	}			
}

/**Gera Pedido*/
function SetCart()
{
	//INICIALIZO O OBJET XHTMLREQUEST
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function()
		{
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)	
				{													
				
					//AQUI RETORNO O RESULTADO
					var resultado = ajax.responseText;
					//alert(resultado);
					location.href=resultado;			
					
				}
				else
				{
					alert(ajax.statusText);	
				}
			}
		}
			
		var cliente_id = document.getElementById('cliente-id').value;
		var bandeira = document.getElementById('bandeira').value;
		var numparcelas = document.getElementById('numparcelas').value;
		var valorparcela = document.getElementById('valorparcela').value;
		var sessaocompra = document.getElementById('sessaocompra').value;
		var erro = '';
		var msg = '';
		
		if(!cliente_id)
		{
			msg = '<b> &raquo; Caso você ja possua o cadastro junto ao Portal EADVIRTUAL. Entre com seu e-mail e senha para efetuar à autenticação. Ou cadastre-se no formulário ao lado.</b><br/><br/>' ;
			erro = 1;				
		}
		if(!bandeira)
		{
			msg = msg + '<b> &raquo; Selecione uma forma de pagamento.</b><br/><br/>' ;
			erro = 1;				
		}	
		if(erro)
		{
			document.getElementById('backpopup').style.display='inline';
			document.getElementById('backpopup').innerHTML='<div id="containerpopup"><input type="button" class="close" onclick="ClosePopup()"/><div id="bodypopup"><div id="redpopup"><img src="img/error.png" width="40" height="40" hspace="0" vspace="0" /><br/>Os seguintes erros foram encontrados.</div>'+msg+'</div></div>';
			return false;	
		}			
		
		/**Verifico*/	
		else if((cliente_id) && (bandeira) && (numparcelas) && (valorparcela) && (sessaocompra))
		{

				/**Verifico a bandeira*/
				if((bandeira == 'Visa') || (bandeira == 'Mastercard') || (bandeira == 'Diners')|| (bandeira == 'Elo'))
				{
					var cartao_titular = document.getElementById('cartao-titular').value;
					var cartao_numero = document.getElementById('cartao-numero').value;
					var cartao_validade_mes = document.getElementById('cartao-validade-mes').value;
					var cartao_validade_ano = document.getElementById('cartao-validade-ano').value;
					var cartao_codigo_seguranca = document.getElementById('cartao-codigo-seguranca').value;
					
					if(!cartao_titular)
					{
						  document.getElementById('cartao-titular').style.borderColor="#FF0000";
						  document.getElementById('cartao-titular').style.backgroundColor="#FFF1BB";
						  msg = '<b> &raquo; Informer o Nome do Titular do Cartão. Como gravado no cartao.</b><br/><br/>' ;
						  erro = 1;							
					}
					if(!cartao_numero)
					{
						  document.getElementById('cartao-numero').style.borderColor="#FF0000";
						  document.getElementById('cartao-numero').style.backgroundColor="#FFF1BB";
						  msg = msg + '<b> &raquo; Informer o Número do Cartão.</b><br/><br/>' ;
						  erro = 1;							
					}
					if(!cartao_validade_mes)
					{
						  document.getElementById('cartao-validade-mes').style.borderColor="#FF0000";
						  document.getElementById('cartao-validade-mes').style.backgroundColor="#FFF1BB";
						  msg = msg + '<b> &raquo; Informer o Mês de validade do seu Cartão.</b><br/><br/>' ;
						  erro = 1;							
					}	
					if(!cartao_validade_ano)
					{
						  document.getElementById('cartao-validade-ano').style.borderColor="#FF0000";
						  document.getElementById('cartao-validade-ano').style.backgroundColor="#FFF1BB";
						  msg = msg + '<b> &raquo; Informer o Ano de validade do seu Cartão.</b><br/><br/>' ;
						  erro = 1;							
					}
					if(!cartao_codigo_seguranca)
					{
						  document.getElementById('cartao-codigo-seguranca').style.borderColor="#FF0000";
						  document.getElementById('cartao-codigo-seguranca').style.backgroundColor="#FFF1BB";
						  msg = msg + '<b> &raquo; Informer o Código de segurança do seu Cartão.</b><br/><br/>' ;
						  erro = 1;							
					}
					if(erro)
					{
						document.getElementById('backpopup').style.display='inline';
						document.getElementById('backpopup').innerHTML='<div id="containerpopup"><input type="button" class="close" onclick="ClosePopup()"/><div id="bodypopup"><div id="redpopup"><img src="img/error.png" width="40" height="40" hspace="0" vspace="0" /><br/>Os seguintes erros foram encontrados.</div>'+msg+'</div></div>';
						return false;	
					}						
					else
					{
						/**MONTO A QUERYSTRING DE ENVIO*/																			
						var dados = 'cliente_id='+cliente_id+'&bandeira='+bandeira+'&numparcelas='+numparcelas+'&valorparcela='+valorparcela+'&sessaocompra='+sessaocompra+'&cartao_titular='+cartao_titular+'&cartao_numero='+cartao_numero+'&cartao_validade_mes='+cartao_validade_mes+'&cartao_validade_ano='+cartao_validade_ano+'&cartao_codigo_seguranca='+cartao_codigo_seguranca+'&TABLE=PEDIDO';
					}
				}
				else
				{
					/**MONTO A QUERYSTRING DE ENVIO*/																			
					var dados = 'cliente_id='+cliente_id+'&bandeira='+bandeira+'&numparcelas='+numparcelas+'&valorparcela='+valorparcela+'&sessaocompra='+sessaocompra+'&TABLE=PEDIDO';
				}
				
				/**Loader*/
				Loader();
				
				//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
				ajax.open('POST', 'dados_db.php', true);
				ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				ajax.send(dados);  

		}
	}			
}

function LoadValorparcela()
{
	var dados = document.getElementById('parcela-cartao').value;
	var array = dados.split("*");
	
	document.getElementById('numparcelas').value=array[0];
	document.getElementById('valorparcela').value=array[1];
}

//ATualizar Dados
function FormDados(form) 
{   
	//INICIALIZO O OBJET XHTMLREQUEST
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function()
		{
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)	
				{													
					
					//AQUI RETORNO O RESULTADO
					var resultado = ajax.responseText;
					
					//alert(resultado);
					
					Unloader();

					if((resultado == 1) && (form == 'frmDadosPessoais'))
					{
							document.getElementById('msg-dados').style.color='#060';
							document.getElementById('msg-dados').innerHTML=' <b> * Dados atualizados com sucesso!</b>';
					}
					
					else if((resultado == 0) && (form == 'frmDadosPessoais'))
					{
							document.getElementById('msg-dados').style.color='#F00';
							document.getElementById('msg-dados').innerHTML=' <b> * Falha na atualização dos dados! Tente novamente.</b>';
					}	
					
					else if((resultado == 1) && (form == 'frmEndereco'))
					{
							document.getElementById('msg-endereco').style.color='#060';
							document.getElementById('msg-endereco').innerHTML=' <b> * Dados atualizados com sucesso!</b>';
					}
					
					else if((resultado == 0) && (form == 'frmEndereco'))
					{
							document.getElementById('msg-endereco').style.color='#F00';
							document.getElementById('msg-endereco').innerHTML=' <b> * Falha na atualização! Tente novamente.</b>';
					}
					
					else if((resultado == 1) && (form == 'frmEmpresa'))
					{
							document.getElementById('msg-empresa').style.color='#060';
							document.getElementById('msg-empresa').innerHTML=' <b> * Dados atualizados com sucesso!</b>';
					}
					
					else if((resultado == 0) && (form == 'frmEmpresa'))
					{
							document.getElementById('msg-empresa').style.color='#F00';
							document.getElementById('msg-empresa').innerHTML=' <b> * Falha na atualização! Tente novamente.</b>';
					}	
					
					else if((resultado == 1) && (form == 'frmEmail'))
					{
							document.getElementById('msg-email').style.color='#060';
							document.getElementById('msg-email').innerHTML=' <b> * Dados atualizados com sucesso!</b>';
					}
					
					else if((resultado == 0) && (form == 'frmEmail'))
					{
							document.getElementById('msg-email').style.color='#F00';
							document.getElementById('msg-email').innerHTML=' <b> * Falha na atualização! Tente novamente.</b>';
					}
					
					else if((resultado == 2) && (form == 'frmEmail'))
					{
							document.getElementById('msg-email').style.color='#F00';
							document.getElementById('msg-email').innerHTML=' <b> * Esse e-mail ja esta sendo utilizado!</b>';
					}					
					
					else if((resultado == 1) && (form == 'frmSenha'))
					{
							document.getElementById('msg-senha').style.color='#060';
							document.getElementById('msg-senha').innerHTML=' <b> * Dados atualizados com sucesso!</b>';
					}
					
					else if((resultado == 0) && (form == 'frmSenha'))
					{
							document.getElementById('msg-senha').style.color='#F00';
							document.getElementById('msg-senha').innerHTML=' <b> * Falha na atualização! Tente novamente.</b>';
					}																											
					
				}
				else
				{
					//alert(ajax.statusText);	
				}
			}
		}
			
		//LEIO O FORMULARIO E SEUS RESPECTIVOS OBJETOS
		var frm = document.getElementById(form);
		var msg  = '';
		var erro = 0;
		
		if(form == 'frmDadosPessoais')
		{
			var nome = document.getElementById('nome').value;
			var sexo = document.getElementById('sexo').value;
			var nascimento = document.getElementById('nascimento').value;
			var ddd = document.getElementById('ddd').value;
			var telefone = document.getElementById('telefone').value;
			var ddd_comercial = document.getElementById('ddd_comercial').value;
			var telefone_comercial = document.getElementById('telefone_comercial').value;
			var ddd_celular = document.getElementById('ddd_celular').value;
			var celular = document.getElementById('celular').value;
			var cliente_id = document.getElementById('cliente-id').value;
			
			if(!nome)
			{
				  document.getElementById('nome').style.borderColor="#FF0000";
				  document.getElementById('nome').style.backgroundColor="#FFF1BB";
				  msg = msg + '<b> &raquo; Informer o seu nome.</b><br/><br/>' ;
				  erro = 1;						
			}
			
			if(!sexo)
			{
				  document.getElementById('sexo').style.borderColor="#FF0000";
				  document.getElementById('sexo').style.backgroundColor="#FFF1BB";
				  msg = msg + '<b> &raquo; Selecione o seu sexo.</b><br/><br/>' ;
				  erro = 1;						
			}
			
			if(!nascimento)
			{
				  document.getElementById('nascimento').style.borderColor="#FF0000";
				  document.getElementById('nascimento').style.backgroundColor="#FFF1BB";
				  msg = msg + '<b> &raquo; Informe a data do seu aniversário.</b><br/><br/>' ;
				  erro = 1;						
			}	
			
			if(!ddd)
			{
				  document.getElementById('ddd').style.borderColor="#FF0000";
				  document.getElementById('ddd').style.backgroundColor="#FFF1BB";
				  msg = msg + '<b> &raquo; Informe os eu DDD.</b><br/><br/>' ;
				  erro = 1;						
			}
			
			if(!telefone)
			{
				  document.getElementById('telefone').style.borderColor="#FF0000";
				  document.getElementById('telefone').style.backgroundColor="#FFF1BB";
				  msg = msg + '<b> &raquo; Informe os eu Telefone.</b><br/><br/>' ;
				  erro = 1;						
			}
			
			var dados = 'id='+cliente_id+'&nome='+nome+'&sexo='+sexo+'&nascimento='+nascimento+'&ddd='+ddd+'&telefone='+telefone+'&ddd-comercial='+ddd_comercial+'&telefone-comercial='+telefone_comercial+'&ddd-celular='+ddd_celular+'&celular='+celular+'&TABLE=CLIENTE&ACTION=UPDATEDADOSPESSOAIS';
			
		}
		
		else if(form == 'frmEndereco')
		{
			var cep = document.getElementById('cep').value;
			var logradouro = document.getElementById('logradouro').value;
			var numero = document.getElementById('numero').value;
			var complemento = document.getElementById('complemento').value;
			var bairro = document.getElementById('bairro').value;
			var cidade = document.getElementById('cidade').value;
			var estado = document.getElementById('estado').value;
			var cliente_id = document.getElementById('cliente-id').value;
				
			if(!cep)
			{
				  document.getElementById('cep').style.borderColor="#FF0000";
				  document.getElementById('cep').style.backgroundColor="#FFF1BB";
				  msg = '<b> &raquo; Informe o seu CEP.</b><br/><br/>' ;
				  erro = 1;						
			}	
			
			if(!logradouro)
			{
				  document.getElementById('logradouro').style.borderColor="#FF0000";
				  document.getElementById('logradouro').style.backgroundColor="#FFF1BB";
				  msg = msg + '<b> &raquo; Informe o seu endereço.</b><br/><br/>' ;
				  erro = 1;						
			}
			
			if(!bairro)
			{
				  document.getElementById('bairro').style.borderColor="#FF0000";
				  document.getElementById('bairro').style.backgroundColor="#FFF1BB";
				  msg = msg + '<b> &raquo; Informe o seu bairro.</b><br/><br/>' ;
				  erro = 1;						
			}
			
			if(!cidade)
			{
				  document.getElementById('cidade').style.borderColor="#FF0000";
				  document.getElementById('cidade').style.backgroundColor="#FFF1BB";
				  msg = msg + '<b> &raquo; Informe a sua cidade.</b><br/><br/>' ;
				  erro = 1;						
			}
			
			if(!estado)
			{
				  document.getElementById('estado').style.borderColor="#FF0000";
				  document.getElementById('estado').style.backgroundColor="#FFF1BB";
				  msg = msg + '<b> &raquo; Selecione o seu estado.</b><br/><br/>' ;
				  erro = 1;						
			}
			
			var dados = 'id='+cliente_id+'&cep='+cep+'&logradouro='+logradouro+'&numero='+numero+'&complemento='+complemento+'&bairro='+bairro+'&cidade='+cidade+'&estado='+estado+'&TABLE=CLIENTE&ACTION=UPDATEENDERECO';
			
		}
		
		else if(form == 'frmEmail')
		{
		
			var email = document.getElementById('email').value;
			var email_confirmar = document.getElementById('email-confirmar').value;
			var cliente_id = document.getElementById('cliente-id').value;
			
			if(!email)
			{
				  document.getElementById('email').style.borderColor="#FF0000";
				  document.getElementById('email').style.backgroundColor="#FFF1BB";
				  msg = '<b> &raquo; Informe o seu e-mail.</b><br/><br/>' ;
				  erro = 1;					
			}
			
			if(!email_confirmar)
			{
				  document.getElementById('email-confirmar').style.borderColor="#FF0000";
				  document.getElementById('email-confirmar').style.backgroundColor="#FFF1BB";
				  msg = msg + '<b> &raquo; Confirme o seu e-mail.</b><br/><br/>' ;
				  erro = 1;					
			}
			
			if((email) && (email_confirmar))
			{
				if(email != email_confirmar)
				{
					document.getElementById('email-confirmar').style.borderColor="#FF0000";
					document.getElementById('email-confirmar').style.backgroundColor="#FFF1BB";
					msg = msg + '<b> &raquo; E-mails não conferem.</b><br/><br/>' ;
					erro = 1;							
				}
			}
			
			var dados = 'id='+cliente_id+'&email='+email+'&TABLE=CLIENTE&ACTION=UPDATEEMAIL';
		}
			
		else if(form == 'frmSenha')
		{
			var senha = document.getElementById('senha').value;
			var senha_confirmar = document.getElementById('senha-confirmar').value;
			var cliente_id = document.getElementById('cliente-id').value;
			
			if(!senha)
			{
				  document.getElementById('senha').style.borderColor="#FF0000";
				  document.getElementById('senha').style.backgroundColor="#FFF1BB";
				  msg = '<b> &raquo; Informe a sua senha.</b><br/><br/>' ;
				  erro = 1;					
			}
			
			if(!senha_confirmar)
			{
				  document.getElementById('senha-confirmar').style.borderColor="#FF0000";
				  document.getElementById('senha-confirmar').style.backgroundColor="#FFF1BB";
				  msg = msg + '<b> &raquo; Confirme a sua senha.</b><br/><br/>' ;
				  erro = 1;					
			}
			
			if((senha) && (senha_confirmar))
			{
				if(senha != senha_confirmar)
				{
					document.getElementById('senha-confirmar').style.borderColor="#FF0000";
					document.getElementById('senha-confirmar').style.backgroundColor="#FFF1BB";
					msg = msg + '<b> &raquo; Senhas não conferem.</b><br/><br/>' ;
					erro = 1;							
				}
				if((senha.length < 6) || (senha.length > 10))
				{
					document.getElementById('senha').style.borderColor="#FF0000";
					document.getElementById('senha').style.backgroundColor="#FFF1BB";
					msg = msg + '<b> &raquo; A senha deve conter entre 6 e 10 caracteres.</b><br/><br/>' ;
					erro = 1;						
				}
			
			}
			
			var dados = 'id='+cliente_id+'&senha='+senha+'&TABLE=CLIENTE&ACTION=UPDATESENHA';
		}
		
		else if(form == 'frmDadosEmpresa')
		{
			var empresa_nome = document.getElementById('empresa_nome').value;
			var empresa_cnpj = document.getElementById('empresa_cnpj').value;
			var empresa_cep = document.getElementById('empresa_cep').value;
			var empresa_logradouro = document.getElementById('empresa_logradouro').value;
			var empresa_numero = document.getElementById('empresa_numero').value;
			var empresa_complemento = document.getElementById('empresa_complemento').value;
			var empresa_bairro = document.getElementById('empresa_bairro').value;
			var empresa_cidade = document.getElementById('empresa_cidade').value;
			var empresa_estado = document.getElementById('empresa_estado').value;
			var cliente_id = document.getElementById('cliente-id').value;
			
			if(!empresa_nome)
			{
				  document.getElementById('empresa_nome').style.borderColor="#FF0000";
				  document.getElementById('empresa_nome').style.backgroundColor="#FFF1BB";
				  msg = msg + '<b> &raquo; Informe o nome da empresa.</b><br/><br/>' ;
				  erro = 1;				
			}
			
			if(!empresa_bairro)
			{
				  document.getElementById('empresa_bairro').style.borderColor="#FF0000";
				  document.getElementById('empresa_bairro').style.backgroundColor="#FFF1BB";
				  msg = msg + '<b> &raquo; Informe o bairro da empresa.</b><br/><br/>' ;
				  erro = 1;				
			}
			
			if(!empresa_cidade)
			{
				  document.getElementById('empresa_cidade').style.borderColor="#FF0000";
				  document.getElementById('empresa_cidade').style.backgroundColor="#FFF1BB";
				  msg = msg + '<b> &raquo; Informe cidade da empresa.</b><br/><br/>' ;
				  erro = 1;				
			}						
			
			var dados = 'TABLE=CLIENTE&ACTION=UPDATEDADOSEMPRESA';
			
		}						
						
			
		if(erro)
		{
			document.getElementById('backpopup').style.display='inline';
			document.getElementById('backpopup').innerHTML='<div id="containerpopup"><input type="button" class="close" onclick="ClosePopup()"/><div id="bodypopup"><div id="redpopup"><img src="img/error.png" width="40" height="40" hspace="0" vspace="0" /><br/>Os seguintes erros foram encontrados.</div>'+msg+'</div></div>';
			return false;	
		}
		else
		{
			Loader();

			//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
			ajax.open('POST', 'dados_db.php', true);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			ajax.send(dados);					   
		}
	}
}

/**Recomendar curso*/
function formRecomendar(id)
{
	document.getElementById('backrecomendar').style.display='inline';
	document.getElementById('containerrecomendar').style.display='inline';
	document.getElementById('curso-indicado').value=id;
}

function CloseIndique()
{
	document.getElementById('backrecomendar').style.display='none';
	document.getElementById('containerrecomendar').style.display='none';
}

//Efetuar indicação do curso
function SendIndicacao()
{
	//INICIALIZO O OBJET XHTMLREQUEST
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function()
		{
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)	
				{								
					//CANCELO O LOADER
					document.getElementById('indique-loader').style.display='none';
					
					//AQUI RETORNO O RESULTADO
					var resultado = ajax.responseText;
					
					if(resultado == 1)
					{
						document.getElementById('indique-msg').innerHTML='<b> Indicação feita com sucesso! </b>';
						
						document.getElementById('indique-nome').value='';
						document.getElementById('indique-email').value='';
						document.getElementById('indique-nome-amigo').value='';
						document.getElementById('indique-email-amigo').value='';
						document.getElementById('indique-mensagem').value='';	
											
					}
					else if(resultado == 0)
					{
						document.getElementById('indique-msg').innerHTML='<b>* Erro ao enviar a mensagem!</b>';	
					}
				}
				else
				{
					alert(ajax.statusText);	
				}
			}
		}
		
		document.getElementById('indique-msg').innerHTML='';
		var indique_nome = document.getElementById('indique-nome').value;
		var indique_email = document.getElementById('indique-email').value;
		var indique_nome_amigo = document.getElementById('indique-nome-amigo').value;
		var indique_email_amigo = document.getElementById('indique-email-amigo').value;
		var indique_mensagem = document.getElementById('indique-mensagem').value;
		var curso_id = document.getElementById('curso-indicado').value;
		var msg = '';
		var erro = 0;
		
		if((!indique_nome) || (indique_nome == 'Informe o seu nome'))
		{
			document.getElementById('indique-nome').value='Informe o seu nome';
			erro++;
		}
		
		if((!indique_email) || (indique_email == 'Informe o seu e-mail'))
		{
			document.getElementById('indique-email').value='Informe o seu e-mail';
			erro++;
		}	
		
		if((!indique_nome_amigo) || (indique_nome_amigo == 'Informe o nome do seu amigo'))
		{
			document.getElementById('indique-nome-amigo').value='Informe o nome do seu amigo';
			erro++;
		}
		
		if((!indique_nome_amigo) || (indique_nome_amigo == 'Informe o nome do seu amigo'))
		{
			document.getElementById('indique-nome-amigo').value='Informe o nome do seu amigo';
			erro++;
		}	
		
		if((!indique_email_amigo) || (indique_email_amigo == 'Informe o e-mail do seu amigo'))
		{
			document.getElementById('indique-email-amigo').value='Informe o e-mail do seu amigo';
			erro++;
		}
		
		if((!indique_mensagem) || (indique_mensagem == 'Informe a sua mensagem'))
		{
			document.getElementById('indique-mensagem').value='Informe a sua mensagem';
			erro++;
		}
		
		if(erro)
		{
			document.getElementById('indique-msg').innerHTML='* Existem campos obrigatórios vazios!';
		}
		
		else
		{					
			//HABILITO O LOADING
			document.getElementById('indique-loader').style.display='inline';
			
			//MONTA QUERYSTRING
			dados = 'indique-nome='+indique_nome+'&indique-email='+indique_email+'&indique-nome-amigo='+indique_nome_amigo+'&indique-email-amigo='+indique_email_amigo+'&indique-mensagem='+indique_mensagem+'&curso_id='+curso_id;
		
			//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
			ajax.open('POST', 'indicar_curso.php', true);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			ajax.send(dados);
		}
	}
	
}

//Enviar mensagem de contato
function SendMessage()
{
	//INICIALIZO O OBJET XHTMLREQUEST
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function()
		{
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)	
				{								
					//CANCELO O LOADER
					document.getElementById('contato-loader').style.display='none';
					
					//AQUI RETORNO O RESULTADO
					var resultado = parseInt(ajax.responseText);
					
					if(resultado == 1)
					{
									
						document.getElementById('g-form-contato').style.display='none';
						document.getElementById('contato-msg').innerHTML='<br/><br/><br/><br/><img src="img/apply.gif" width="24px" style="float:left; margin-left: 200px;"><b style="font-size:16px; position: relative; top:5px; left:3px;"> Mensagem enviada com sucesso! </b><br/><br/><center>Caso você necessite de atendimento, retornaremos no prazo de 24 horas - dias úteis.<br/><br/>Agradecemos o seu contato.<center><img src="gestao/arquivos/logo.png"></center><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/></center>';
						//$.msgbox("O seu e-mail foi enviado!<br><br><b>Agradecemos o seu contato.</b>");
						//$.msgbox("Obrigado pela mensagem!<br><br><b>Em breve entraremos em contato.</b> "); 
						document.getElementById('contato-nome').value='';
						document.getElementById('contato-email').value='';
						document.getElementById('contato-email-confirmar').value='';
						document.getElementById('contato-telefone').value='';
						document.getElementById('contato-assunto').value='';
						document.getElementById('contato-mensagem').value='';	
											
					}
					else if(resultado == 0)
					{
						$.msgbox("Erro ao enviar mensagem.", {type: "error"}); 	
					}
				}
				else
				{
					alert(ajax.statusText);	
				}
			}
		}
		
		document.getElementById('contato-msg').innerHTML='';
		var contato_nome            = document.getElementById('contato-nome').value;
		var contato_email           = document.getElementById('contato-email').value;
		var contato_email_confirmar = document.getElementById('contato-email-confirmar').value;
		var contato_telefone        = document.getElementById('contato-telefone').value;
		var contato_assunto         = document.getElementById('contato-assunto').value;
		var contato_mensagem        = document.getElementById('contato-mensagem').value;
		var msg = '';
		var erro = 0;
		
		if((!contato_nome) || (contato_nome == 'Informe o seu nome'))
		{
			document.getElementById('contato-nome').value='Informe o seu nome';
			erro++;
		}
		
		if((!contato_email) || (contato_email == 'Informe o seu e-mail'))
		{
			document.getElementById('contato-email').value='Informe o seu e-mail';
			erro++;
		}	
		
		if((!contato_email_confirmar) || (contato_email_confirmar == 'Confirme o seu e-mail'))
		{
			document.getElementById('contato-email-confirmar').value='Confirme o seu e-mail';
			erro++;
		}
		
		if(contato_email != contato_email_confirmar)
		{
			document.getElementById('contato-msg').value='E-mails não conferem';
			erro++;				
		}
		
		if((!contato_assunto) || (contato_assunto == 'Informe o assunto'))
		{
			document.getElementById('contato-msg').innerHTML=' <b> * E-mails não conferem </b>';
			erro++;
		}
		
		if((!contato_mensagem) || (contato_mensagem == 'Informe a sua mensagem'))
		{
			document.getElementById('contato-mensagem').value='Informe a sua mensagem';
			erro++;
		}
		
		if(erro)
		{
			document.getElementById('contato-msg').innerHTML='* Existem campos obrigatórios vazios!';
		}
		
		else
		{					
			//HABILITO O LOADING
			document.getElementById('contato-loader').style.display='inline';
			
			//MONTA QUERYSTRING
			dados = 'contato-nome='+contato_nome+'&contato-email='+contato_email+'&contato-email-confirmar='+contato_email_confirmar+'&contato-telefone='+contato_telefone+'&contato-assunto='+contato_assunto+'&contato-mensagem='+contato_mensagem;

			//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
			ajax.open('POST', 'enviar_mensagem.php', true);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			ajax.send(dados);
		}
	}
	
}

/**Autenticação junto ao Moodle*/
function AutoLogin()
{
	//INICIALIZO O OBJET XHTMLREQUEST
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function()
		{
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)	
				{
					//REDIRECIONO
					location.href="sala-de-aula";
					Unloader();
					exit;
				}
				else
				{
					//alert(ajax.status);	
				}
			}
		}
		
	}

		
	//LEIO O FORMULARIO E SEUS RESPECTIVOS OBJETOS
	var user = document.getElementById("user").value;
	var data = document.getElementById("data").value;
	Loader();

	
	//MONTO A QUERY STRING
	dados = 'data='+data+'&user='+user;

	//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
	ajax.open('GET', 'http://www.eadvirtual.com.br/cursos/login/index.php?'+dados, true);
	ajax.send(null);
}

//Andamentos
function OpenAndamento(matricula, action)
{
	
	if(action == true)
	{
	
		//INICIALIZO O OBJET XHTMLREQUEST
		ajax = IniciaAjax();
		if(ajax)
		{
			ajax.onreadystatechange = function()
			{
				if(ajax.readyState == 4)
				{
					if(ajax.status == 200)	
					{								
	
						
						//AQUI RETORNO O RESULTADO
						var resultado = ajax.responseText;
						
						document.getElementById('return-andamento').innerHTML=resultado;
						$('#return-andamento').fadeIn();
						
						
					}
					else
					{
						alert(ajax.statusText);	
					}
				}
			}
				
			if(matricula)
			{					
				
				//MONTA QUERYSTRING
				dados = 'matricula='+matricula;
	
				//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
				ajax.open('POST', 'andamento.php', true);
				ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				ajax.send(dados);
			}
		}
	}
	else
	{
		  document.getElementById('return-andamento').innerHTML='';
		  $('#return-andamento').fadeOut();			
	}
	
}

/**********  NOVA FUNÇÃO PARA CONSULTAR ENDEREÇOS NO AMBIENTE DO ALUNO ************/
function LoadEnd(form)
{
	//INICIALIZO O OBJET XHTMLREQUEST
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function()
		{
			if(ajax.readyState == 4)
			{
				if(ajax.status == 200)	
				{				
					//AQUI RETORNO O RESULTADO COM AS DEVIDAS PORCENTAGENS 
					var resultado = ajax.responseText;
					
					//OCULTO O LOADER
					Unloader();
					
					//CAPTURO OS DADOS DA CONSULTA		
					var array = resultado.split("*");
					document.getElementById("logradouro").value=array[1]+' '+array[2];
					document.getElementById("complemento").value=array[2];
					document.getElementById("bairro").value=array[3];
					document.getElementById("cidade").value=array[4];
					document.getElementById("estado").value=array[5];
				}
				else
				{
					alert(ajax.statusText);	
				}
			}
		}
		
		//LEIO O FORMULARIO E SEUS RESPECTIVOS OBJETOS
		var frm = document.getElementById(form);
		var numElementos = frm.elements.length;
		
		for(var i = 0; i < numElementos; i++)
		{			
			if((frm.elements[i].name == 'cep') && (frm.elements[i].value != ''))
			{
				var cep = frm.elements[i].value;
			}
		}
		
		if(cep.length==9)//Antes de enviar verifico se os 9 digitos foram informados
		{
			//HABILITO O LOADER
			Loader();
								
			//MONTA QUERYSTRING
			dados = 'cep='+cep;
		
			//FAZ A REQUISIÇÃO E O ENVIO PELO METODO POST
			ajax.open('POST', 'cep.php', true);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			ajax.send(dados);
		}				
	}	
}
