function ajax() {
	var xmlhttp;
	try { xmlhttp = new XMLHttpRequest(); } catch(ee) { try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch(E) { xmlhttp = false; } } } return xmlhttp;
};

function CkLoginAluno() {
	if($x("emailc").value == "" || $x("senhac").value == "") {
		alert("Email e senha são obrigatórios");
		return false;	
	} else if($x("senhac").value.length < 6) {
		alert("A senha precisa possuir no mínimo 6 caracteres");
		return false;
	}
	if(!ckmRegex.test($x("emailc").value)) {
		alert("O email informado não é valido");
		return false;
	}
	return true;
}

function CadSenhaTelefone() {

	if(!vEmail("cademail")) return false;
	if(!$x("cpfcnpj").value.isCPF() && !$x("cpfcnpj").value.isCNPJ()) {
		alert("O CPF ou CNPJ informado não é válido");
		return false;
	}
	
	s  = document.forms['frmCadSenhaTel'].cadsenha.value;
	rs = document.forms['frmCadSenhaTel'].rcadsenha.value;
	if(s == "") { alert("Escolha uma senha"); return false; }
	if(s.length < 6 || rs.length > 50) { alert("A senha deve possuir no mínimo 6 caracteres e no máximo 50"); return false; }
	if(s != rs) { alert("As senhas não conferem"); return false; }
	
	$x("stcadSenha").style.display = "block";
	
	http=ajax();
	http.open("POST","/library/cadSenhaTel.php",true);
	http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
	http.send("email="+$x("cademail").value+"&senha="+MD5(s)+"&csenha="+MD5(rs)+"&cpfcnpj="+$x("cpfcnpj").value);
	http.onreadystatechange = function() {
		if(http.readyState == 4) {
			if(http.status == 200) {
				if(http.responseText == "sucesso") {
					$x("cadSenhaLk").style.display='none';
					$x("cadSenhaPainel").innerHTML = "<div id='stcadSenha' style='display:block'><strong style='color:#0053a7'>A SUA SENHA FOI CADASTRADA COM SUCESSO</strong><br />Agora para acessar à Central do Aluno basta utilizá-la para realizar o login.<br /><br /><a href='/central_do_aluno'>Continuar >></a></div>";
				} else {
					$x("stcadSenha").innerHTML = "<div style='color:#9B0000'>"+http.responseText+"</div>";
				}
			} else $x("stcadSenha").innerHTML = "ERRO: "+http.responseText;
		}
	}
}

function Indicar() {
	creq = new Array("nomeIndica","emailIndica","nomeAmigo","emailAmigo");
	erro=false;
	for (i in creq) { if($x(creq[i]).value == "") erro = true; }
	if (ckmRegex.test($x("emailAmigo").value) == false) {
		alert("O Email do(a) Amigo(a) não é válido"); $x("emailAmigo").focus(); return false;
	} else if (ckmRegex.test($x("emailIndica").value) == false ) {
		alert("O seu email não é válido"); $x("emailIndica").focus(); return false;
	}
	if(erro) {
		alert("Preencha os campos obrigatórios");
	} else {
		$x("dsind").innerHTML = "Enviando indicação, aguarde...";
		$x("dsind").style.display = "block";
		http=ajax();
		http.open("POST","/library/indicarCurso.php",true);
		http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		http.send("emailAmigo="+$x("emailAmigo").value+"&nomeAmigo="+$x("nomeAmigo").value+"&nome="+$x("nomeIndica").value+"&email="+$x("emailIndica").value+"&mensagem="+escape($x("indicaMsg").value)+"&curso="+$x('cursoInd').value+"&telefoneAmigo="+$x('telefoneAmigo').value);
		http.onreadystatechange = function() {
			if(http.readyState == 4) {
				if(http.status == 200) {
					if(http.responseText == "sucesso") {
						$x("dsind").innerHTML = "<strong>Sua indicação foi enviada com sucesso!</strong> Obrigado por indicar nossos cursos";
						$x("nomeAmigo").value = ""; $x("emailAmigo").value = ""; $x("indicaMsg").value = "";
					} else alert(http.responseText);
				} else $x("stcadSenha").innerHTML = "ERRO: "+http.responseText;
			}
		}//readystatechange*/
	}
}

