function ObjetoXMLHttp()
{
	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 NoLogin() 
{
	var URL="http://www.reserve.com.br/nologin.asp?A=costabrava";

	window.open(URL,'noLogin','width=400,height=300,resizable=no,toolbar=no,status=no,menubar=no,scrollbars=no');

}

function validarsenhaempresa() 
{
	if (document.b2bempresa.Login.value == "")
	{
		alert("Digite Seu Login");
		document.b2bempresa.Login.focus();
		return false;
	}
	if (document.b2bempresa.Senha.value == "")
	{
		alert("Digite Sua Senha");
		document.b2bempresa.Senha.focus();
		return false;
	}
	return true;
}


function validanews() 
{
	if (document.newsletter.nome.value == "")
	{
		alert("Digite seu nome.");
		document.newsletter.nome.focus();
		return (false);
	}
	

	if ((document.newsletter.email.value == "") || (document.newsletter.email.value.indexOf("@") == -1) || (document.newsletter.email.value.indexOf(".") == -1))
	{
		alert("Digite um e-mail válido.");
		document.newsletter.email.focus();
		return (false);
	}

	document.newsletter.submit();
	document.newsletter.nome.value = "";
	document.newsletter.email.value = "";
	return false;
}

function valida_contato() 
{
	if (document.formContato.nome_contato.value == "")
	{
		alert("Digite seu nome");
		document.formContato.nome_contato.focus();
		return false;
	}

	if (document.formContato.email.value == "")
	{
		alert("Digite seu e-mail");
		document.formContato.email.focus();
		return false;
	}
	
	if (document.formContato.telefone.value == "")
	{
		alert("Digite seu telefone");
		document.formContato.telefone.focus();
		return false;
	}
	
	if (document.formContato.comentario.value == "")
	{
		alert("Digite seu comentário");
		document.formContato.comentario.focus();
		return false;
	}
	
	return true;
}



function validadados() 
{
	var doc = document.FORM1;
	if(doc.DE.value.length <3) 
	{
		alert("Por favor selecione o aeroporto de origem");
		doc.DE.focus();
		return false; 
	}
	if(doc.PARA.value.length <3) 
	{
		alert("Por favor selecione o aeroporto de destino");
		doc.PARA.focus();
		return false;
	}
	return true;
}


function mascaraSel(objeto, evento, mascara)
{
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		codigo = evento.keyCode;
	}
	else
	{
		codigo = evento.which;
	}
	if (codigo == 46 || codigo == 8)
	{
		return false;
	}
	
	if (mascara == "cnpj")
	{
		if (limitaNumero(evento))
		{
			if (objeto.value.length == 2)
			{
				objeto.value = objeto.value + ".";
			}
			
			if (objeto.value.length == 6)
			{
				objeto.value = objeto.value + ".";
			}
			if (objeto.value.length == 10)
			{
				objeto.value = objeto.value + "/";
			}
			
			if (objeto.value.length == 15)
			{
				objeto.value = objeto.value + "-";				
			}
			if (objeto.value.length == 18)
			{
				return false;
			}
			return true;
		}
		else
		{
			return false;	
		}
	}

	if (mascara == "cpf")
	{
		if (limitaNumero(evento))
		{
			if (objeto.value.length == 3)
			{
				objeto.value = objeto.value + ".";
			}
			if (objeto.value.length == 7)
			{
				objeto.value = objeto.value + ".";
			}
			if (objeto.value.length == 11)
			{
				objeto.value = objeto.value + "-";
			}
			if (objeto.value.length == 14)
			{
				return false;
			}
			return true;
		}
		else
		{
			return false;	
		}
	}
	if (mascara == "data")
	{
		if (limitaNumero(evento))
		{
			if (objeto.value.length == 2)
			{
				objeto.value = objeto.value + "/";				
			}
			if (objeto.value.length == 5)
			{
				objeto.value = objeto.value + "/";				
			}
			if (objeto.value.length == 10)
			{
				return false;
			}
			return true;
		}
		else
		{
			return false;	
		}
	}

	if (mascara == "horaminuto")
	{
		if (limitaNumero(evento))
		{
			if (objeto.value.length == 2)
			{
				objeto.value = objeto.value + ":";				
			}
			if (objeto.value.length == 5)
			{
				return false;
			}
			return true;
		}
		else
		{
			return false;	
		}
	}
}

function limitaNumero(evento)
{
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		codigo = evento.keyCode;
	}
	else
	{
		codigo = evento.which;
	}
	if ((codigo >= 48) && (codigo <= 57))
	{
		return true;
	}
	if (codigo == 0)
	{
		return true;
	}
	if (codigo == 46)
	{
		return true;
	}
	return false;
}

function limitaNumeroFlutuante(evento, objeto)
{
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		codigo = evento.keyCode;
	}
	else
	{
		codigo = evento.which;
	}
	
	//alert(codigo);
	if ((codigo == 44) || (codigo == 46))
	{
		if (objeto.value.indexOf(",") == -1)
		{
			if (codigo == 46)
			{
				objeto.value = objeto.value + ",";
				return false;
			}
			else
			{
				return true;
			}			
		}
		else
		{
			return false;
		}
	}
	
	if ((codigo >= 48) && (codigo <= 57))
	{
		if (((objeto.value.length - objeto.value.indexOf(",")) > 3 ) && (objeto.value.indexOf(",") != -1))
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	if (codigo == 0)
	{
		return true;
	}
	
	return false;
}



function cadastrarCurriculo()
{
	if (valida_CPF(window.document.login.cpf_curriculo.value) == true)
	{
		obj2 = ObjetoXMLHttp();

		obj2.open("GET", "admin/lib/curriculos.php?acao=verificar_cpf&cpf=" + window.document.login.cpf_curriculo.value,true);
		obj2.onreadystatechange=function() 
		{
			if (obj2.readyState==4)
			{
				if (obj2.responseText == "1")
				{
					window.document.login.action = "talento_cadastrar.php";
					window.document.login.submit();
				}
				else
				{
					alert("Este CPF já encontra-se cadastrado. Efetue o login para editar seus dados.");
				}
			}
		}
		obj2.send(null);
	}
	else
	{
		alert("CPF inválido.");
	}
}

function loginCurriculo()
{
	if (window.document.login.cpf_curriculo.value.length == 0)
	{
		alert("Digite um CPF válido.");
	}
	else if (window.document.login.senha_curriculo.value.length == 0)
	{
		alert("Digite sua senha.");
	}
	else
	{
		window.document.login.action = "talento_editar.php";
		window.document.login.submit();
	}
}



function valida_CPF(s)	{

	var i;

	s = limpa_string(s);

	var c = s.substr(0,9);

	var dv = s.substr(9,2);

	var d1 = 0;

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

	{

		d1 += c.charAt(i)*(10-i);

	}

        if (d1 == 0) return false;

	d1 = 11 - (d1 % 11);

	if (d1 > 9) d1 = 0;

	if (dv.charAt(0) != d1)

	{

		return false;

	}

	d1 *= 2;
	for (i = 0; i < 9; i++)
	{
		d1 += c.charAt(i)*(11-i);
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1)
	{
		return false;
	}
        return true;
}


function limpa_string(S){
	var Digitos = "0123456789";
	var temp = "";
	var digito = "";
	for (var i=0; i<S.length; i++)	{

		digito = S.charAt(i);

		if (Digitos.indexOf(digito)>=0)	{

			temp=temp+digito	}
	} //for
	return temp
}

/// Cadastrar curriculo
function validaForm(tipo_form)
{
	if (window.document.formulario.nome_curriculo.value.length == 0)
	{
		alert("Preencha o campo NOME corretamente.\n\n * todos os campos em negrito são obrigatórios.");
	}
	else if ((window.document.formulario.cpf_curriculo.value.length == 0) || (! valida_CPF(window.document.formulario.cpf_curriculo.value)))
	{
		alert("Preencha o campo CPF corretamente.\n\n * todos os campos em negrito são obrigatórios.");
	}
	else if (window.document.formulario.rg_curriculo.value.length == 0)
	{
		alert("Preencha o campo RG corretamente.\n\n * todos os campos em negrito são obrigatórios.");
	}
	else if (window.document.formulario.nascimento_curriculo.value.length == 0)
	{
		alert("Preencha o campo DATA DE NASCIMENTO corretamente.\n\n * todos os campos em negrito são obrigatórios.");
	}
	else if (window.document.formulario.sexo_curriculo.value.length == 0)
	{
		alert("Preencha o campo SEXO corretamente.\n\n * todos os campos em negrito são obrigatórios.");
	}
	else if (window.document.formulario.endereco_curriculo.value.length == 0)
	{
		alert("Preencha o campo ENDEREÇO corretamente.\n\n * todos os campos em negrito são obrigatórios.");
	}
	else if ((window.document.formulario.email_curriculo.value.length == 0) || (window.document.formulario.email_curriculo.value.indexOf("@") == -1) || (window.document.formulario.email_curriculo.value.indexOf(".") == -1))
	{
		alert("Preencha o campo EMAIL corretamente.\n\n * todos os campos em negrito são obrigatórios.");
	}
	else if (window.document.formulario.codigo_estado_fk.value.length == 0)
	{
		alert("Preencha o campo ESTADO corretamente.\n\n * todos os campos em negrito são obrigatórios.");
	}
	else if (window.document.formulario.codigo_cidade_fk.value.length == 0)
	{
		alert("Preencha o campo CIDADE corretamente.\n\n * todos os campos em negrito são obrigatórios.");
	}	
	else if (window.document.formulario.codigo_escolaridade_fk.value.length == 0)
	{
		alert("Preencha o campo ESCOLARIDADE corretamente.\n\n * todos os campos em negrito são obrigatórios.");
	}
	else if (window.document.formulario.codigo_funcao_fk.value.length == 0)
	{
		alert("Selecione uma ÁREA DE INTERESSE.\n\n * todos os campos em negrito são obrigatórios.");
	}
	else if (window.document.formulario.senha_curriculo.value.length == 0)
	{
		alert("Preencha o campo SENHA corretamente.\n\n * todos os campos em negrito são obrigatórios.");
	}
	else if (tipo_form != 'editar')
	{
		if ((window.document.formulario.arquivo_curriculo.value.length == 0) || ((window.document.formulario.arquivo_curriculo.value.toLowerCase().indexOf(".doc") == -1) && (window.document.formulario.arquivo_curriculo.value.toLowerCase().indexOf(".pdf") == -1) && (window.document.formulario.arquivo_curriculo.value.toLowerCase().indexOf(".docx") == -1)))
		{
			alert("Selecione um ARQUIVO com extenssão .doc, .docx ou .pdf corretamente.\n\n * todos os campos em negrito são obrigatórios.");
		}
		else
		{
			window.document.formulario.action = "talento_cadastrar.php";
			window.document.formulario.submit();	
		}
	}
	else
	{
		window.document.formulario.action = "talento_editar.php";
		window.document.formulario.submit();	
	}
}

function selecionaEstado(codigo_estado, codigo_cidade)
{
	if ((codigo_estado != "") && (codigo_estado != "0"))
	{
		window.document.getElementById("tr_cidade").style.display = "";
		obj1 = ObjetoXMLHttp();
		obj1.open("GET", "admin/lib/curriculos.php?acao=buscar_cidades&codigo_estado="+codigo_estado+"&codigo_cidade="+codigo_cidade,true);
		obj1.onreadystatechange=function() 
		{
			if ((obj1.readyState==1) || (obj1.readyState==2) || (obj1.readyState==3))
			{
				window.document.getElementById("div_cidade").innerHTML = "Carregando cidades, aguarde...";
			}
			if (obj1.readyState==4)
			{
				window.document.getElementById("div_cidade").innerHTML = obj1.responseText;
			}
		}
		obj1.send(null);
	}
	else
	{
		window.document.getElementById("tr_cidade").style.display = "none";
	}
}