function carregaPagina(pPagina, pMetodo, pDIV) {
	var lDIVGeral;
	var lConteudoPagina;
	var lConteudo;

	try{
		XMLHttp = new XMLHttpRequest();
	} catch(ee) {
		try{
			XMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try{
				XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(E) {
				XMLHttp = false;
			}
		}
	}
	lDIVGeral = document.getElementById(pDIV);
	XMLHttp.open(pMetodo, pPagina,true);
	XMLHttp.onreadystatechange = function() {
		if (XMLHttp.readyState == 4) {
			lConteudoPagina = XMLHttp.responseText;
			getScripts(lConteudoPagina);
			lConteudoPagina = lConteudoPagina.replace(/\+/g," ");
			lConteudoPagina = unescape(lConteudoPagina);
			lConteudo = document.getElementById(pDIV);
			lConteudo.innerHTML = lConteudoPagina;
		}
	}
	XMLHttp.send(null);
}

function getScripts(pConteudo) { 
    var lInicio = 0;
	var lFim;
	var lNovoTexto;
	
    while (lInicio != -1){
        lInicio = pConteudo.indexOf('<script', lInicio);
        if (lInicio >= 0){
            lInicio = pConteudo.indexOf('>', lInicio) + 1;
            lFim = pConteudo.indexOf("<\/script>", lInicio);
            codigo = pConteudo.substring(lInicio,lFim);
            lNovoTexto = document.createElement("script")
            lNovoTexto.text = codigo;
            document.body.appendChild(lNovoTexto);
        }
    }
}

function formatarCampo(pSRC, pMask){
	var lCont = pSRC.value.length;
	var lSaida = pMask.substring(0,1);
	var lTexto = pMask.substring(lCont)
	if (lTexto.substring(0,1) != lSaida) {
		pSRC.value += lTexto.substring(0,1);
	}
}

function validaCPF(pValor) {
	var lCont;
	var lSemDigito = pValor.substr(0,9);
	var lDigito = pValor.substr(9,2);
	var lAux = 0;
	for (lCont = 0; lCont < 9; lCont++) {
		lAux += lSemDigito.charAt(lCont)*(10 - lCont);
	}
	if (lAux == 0){
		alert("CPF Invalido")
		return false;
	}
	lAux = 11 - (lAux % 11);
	if (lAux > 9) lAux = 0;
	if (lDigito.charAt(0) != lAux) {
		alert("CPF Invalido")
		return false;
	}
	lAux *= 2;
	for (lCont = 0; lCont < 9; lCont++)	{
		lAux += lSemDigito.charAt(lCont)*(11 - lCont);
	}
	lAux = 11 - (lAux % 11);
	if (lAux > 9) lAux = 0;
	if (lDigito.charAt(1) != lAux) {
		alert("CPF Invalido")
		return false;
	}
	return true;
}

function abreSelectAssunto(pSelect) {
	var lSelect = document.getElementById(pSelect);

	if (lSelect.style.display == 'none') {
		lSelect.style.display = 'inline-block';
		return true;
	}
	
	if (lSelect.style.display == 'inline-block') {
		lSelect.style.display = 'none';
		return true;
	}
	alert(lSelect.style.display);
}

function verificaFormContato() {
	var lNome = document.getElementById('nome');
	var lEmail = document.getElementById('email');
	var lMensagem = document.getElementById('mensagem');
	
	if (lNome.value == '' || lNome.value == 'Nome') {
		alert('Informe seu nome');
		lNome.value = '';
		lNome.focus();
		return true;
	}
	
	if (lEmail.value == '' || lEmail.value.indexOf('@') == -1 || lEmail.value == 'E-mail') {
		alert('Informe seu E-mail');
		lEmail.value = '';
		lEmail.focus();
		return true;
	}
	
	if (lMensagem.value == '' || lMensagem.value == 'Mensagem') {
		alert('Informe sua Mensagem');
		lMensagem.value = '';
		lMensagem.focus();
		return true;
	}
	
	document.forms['formcontato'].submit();
}

function verificaTrabalheConosco() {
	var lNome = document.getElementById('nome');
	var lCPF = document.getElementById('cpf');
	var lIdade = document.getElementById('idade');
	var lAreaAtuacao = document.getElementById('area_atuacao');
	
	if (lNome.value == '' || lNome.value == 'Nome') {
		alert('Informe seu nome');
		lNome.value = '';
		lNome.focus();
		return true;
	}
	
	if (lCPF.value == '' || lCPF.value == 'CPF') {
		alert('Informe seu CPF');
		lCPF.value = '';
		lCPF.focus();
		return true;
	}
	
	if (lIdade.value == '' || lIdade.value == 'Idade') {
		alert('Informe sua Idade');
		lIdade.value = '';
		lIdade.focus();
		return true;
	}
	
	if (lAreaAtuacao.value == '' || lAreaAtuacao.value == 'Área de atuação') {
		alert('Informe a Área de Atuação');
		lAreaAtuacao.value = '';
		lAreaAtuacao.focus();
		return true;
	}
	
	if(!validaCPF(lCPF.value)) {
		document.forms['formclientejuridico'].submit();
	}
	
	document.forms['formtrabalheconosco'].submit();
}

function verificaMultiMarcas() {
	document.forms['formmultimarcas'].submit();
}
