// JavaScript Document

function removeSpaces(string) {
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring;
}

function validTrabalhe() {
	var form = document.getElementById("form");
	var tt_curriculo = document.getElementById("tt_curriculo");
	var email = document.getElementById("email");
	
	var dt_nascimento = document.getElementById("dt_nascimento");
	var nacionalidade = document.getElementById("nacionalidade");
	var id_estado_civil = document.getElementById("id_estado_civil");
	var endereco = document.getElementById("endereco");
	var bairro = document.getElementById("bairro");
	var cidade = document.getElementById("cidade");
	var estado = document.getElementById("estado");
	var pais = document.getElementById("pais");
	var ddd_telefone = document.getElementById("ddd_telefone");
	var telefone = document.getElementById("telefone");
	var id_faixa_pretensao = document.getElementById("id_faixa_pretensao");
			
	// Regra para a validação de e-mail.
	var reEmail = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	
	
	if(removeSpaces(tt_curriculo.value) == "") {
		alert("Field name is mandatory.");
		tt_curriculo.focus();
		return;
	}
	
	
	if(email.value == "") {
		alert("Field email is mandatory");
		email.focus();
		return;
	} else {
		valid_email = reEmail.exec(email.value)
		if(valid_email == null) {
			alert("(Invalid E-mail !");
			email.focus();
			return;
		}
	}
	
	if(removeSpaces(dt_nascimento.value) == "") {
		alert("Field birthdate is mandatory");
		dt_nascimento.focus();
		return;
	}
	
	if(removeSpaces(nacionalidade.value) == "") {
		alert("Field nationality is mandatory.");
		nacionalidade.focus();
		return;
	}
	
	if(removeSpaces(id_estado_civil.value) == "") {
		alert("Field marital status is mandatory");
		id_estado_civil.focus();
		return;
	}
	
	if(removeSpaces(endereco.value) == "") {
		alert("Field address is mandatory.");
		endereco.focus();
		return;
	}
	
	if(removeSpaces(bairro.value) == "") {
		alert("Field Neighborhood is mandatory");
		bairro.focus();
		return;
	}
	
	if(removeSpaces(cidade.value) == "") {
		alert("Field city is mandatory");
		cidade.focus();
		return;
	}
	
	if(removeSpaces(estado.value) == "") {
		alert("Field state is mandatory.");
		estado.focus();
		return;
	}
	
	if(removeSpaces(pais.value) == "") {
		alert("Field country is mandatory.");
		pais.focus();
		return;
	}
	
	if(removeSpaces(ddd_telefone.value) == "") {
		alert("Field DDD is mandatory.");
		ddd_telefone.focus();
		return;
	}
	
	if(removeSpaces(telefone.value) == "") {
		alert("Field telephone is mandatory");
		telefone.focus();
		return;
	}
	
	if(removeSpaces(id_faixa_pretensao.value) == "") {
		alert("Field How Much do you wat to gain is mandatory.");
		id_faixa_pretensao.focus();
		return;
	}
		
	form.submit();
}

function MudarTipo(tipo)
{
	if(tipo == "RM")
	{
		window.location = 'trabalhe_representante.php';	
	}
	else
	{
		window.location = 'trabalhe.php';	
	}
}

