function tiraEspaco(texto){
	while(texto.indexOf(" ") != -1){
	  texto = texto.replace(" ","");
	}
    return texto;
}

function submeterComentario(){

	if(tiraEspaco(document.getElementById('autor').value) == ""){
		alert("Informe o nome");
		document.getElementById('autor').focus();
		return;
	}
	if(tiraEspaco(document.getElementById('email').value) == ""){
		alert("Informe o email");
		document.getElementById('email').focus();
		return;
	}else{
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('email').value))){
			alert("Informe o email");
	        document.getElementById('email').focus();
	   	    return;
	    }
	}
	if(tiraEspaco(document.getElementById('texto').value) == ""){
		alert("Informe o comentário");
		document.getElementById('texto').focus();
		return;
	}
	
	setarCamposComentarios();
    
	enviaRequisicao('conteudoCentral','fazerComentario.php?'+campos,'Carregando');

}

function setarCamposComentarios(){
	campos = "autor="+encodeURI(document.getElementById('autor').value);
	campos += "&email="+encodeURI(document.getElementById('email').value);
	campos +="&comentario="+encodeURI(document.getElementById('texto').value);
	campos +="&trabalho="+document.getElementById('trabalho').value;
}

function submeterContato(){

	if(tiraEspaco(document.getElementById('nome1').value) == ""){
		alert("Informe o nome");
		document.getElementById('nome1').focus();
		return;
	}
	if(tiraEspaco(document.getElementById('email').value) == ""){
		alert("Informe o email");
		document.getElementById('email').focus();
		return;
	}else{
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('email').value))){
			alert("Formato de email incorreto!");
	        document.getElementById('email').focus();
	   	    return;
	    }
	}
	if(tiraEspaco(document.getElementById('mensagem').value) == ""){
		alert("Informe a mensagem");
		document.getElementById('mensagem').focus();
		return;
	}

	setarCamposContato();

	enviaRequisicao('enviaForm','enviarContato.php?'+campos,'Enviando...');
}

function setarCamposContato(){
	campos = "nome="+encodeURI(document.getElementById('nome1').value);
	campos += "&email="+encodeURI(document.getElementById('email').value);
	campos +="&mensagem="+encodeURI(document.getElementById('mensagem').value);

}


function carregaJobs(tipoJob){
    var mensagem = '<li style="text-align:center;min-height:150px ">carregando</li>';
    enviaRequisicao('exibeJobs','exibeTrabalhos.php?tipoPortfolio='+tipoJob,mensagem);
}

function lerNoticia(noticia){
    enviaRequisicao('wrapper','noticias.php?destaqueId='+noticia,'carregando');
   
}
function abrirPortfolio(tipoPortfolio){
	location.href="portfolio.php?exibir=1&tipoPortfolio="+tipoPortfolio;
}

/*--------- Área Restrita - Start ---------------*/
function submeterLogin(formulario){
	
	if(formulario =='formAreaReturn'){
		location.href="includes/areaRestrita/loginResult.php";
	}
		
	if (document.getElementById('nome').value == ''){
		alert("Insira o login.");
		document.getElementById('nome').focus();
		return false;
	}
	if (document.getElementById('senha').value  == ''){
		alert("Insira a senha.");
		document.getElementById('senha').focus();
		return false;
	}

    return document.getElementById('formArea').submit();
    document.getElementById('senha').value='';
    document.getElementById('nome').value = '';
}

function enviarComentario(){

	if(tiraEspaco(document.getElementById('nomeComentario').value) == ""){
		alert("informe seu nome");
		document.getElementById('nomeComentario').focus();
		return;
	}
	if(tiraEspaco(document.getElementById('msgComentario').value) == ""){
		alert("Informe o comentário");
		document.getElementById('msgComentario').focus();
		return;
	}

	setarComentario();
	enviaRequisicao('comentarios','enviarComentario.php?'+campos,'enviando');
    document.getElementById('nomeComentario').value='';
    document.getElementById('msgComentario').value='';
}

function setarComentario(){
	campos = "cliente="+encodeURI(document.getElementById('cliente').value);
	campos += "&autor="+encodeURI(document.getElementById('nomeComentario').value);
	campos +="&comentario="+encodeURI(document.getElementById('msgComentario').value);
}

function listaComentario(id){
	 mensagem = '<div align=center style="font-family:Arial, Helvetica;font-size:10px;height:210px;float:center"><br><br><img src=img/loading.gif border=0><br>Carregando...</div>'
     enviaRequisicao('comentarios','enviarComentario.php?cliId='+id,mensagem);
}
function efetuarDownload(fileId,fileKey){
	location.href='download.php?fId='+fileId+'&fKey='+fileKey;
}
function deslogarArea(){
    location.href="logout.php";
}
function deslogarAreaExterna(){
	location.href="includes/areaRestrita/logout.php";
}
/*--------- Área Restrita - End ---------------*/
