function verificaMail(email) {
	var campo = email;
	if (campo.indexOf("@")<1) { return false; }
	if (campo.charAt(campo.indexOf("@")-1) == ".") { return false; }
	if (campo.lastIndexOf(".")<=campo.indexOf("@")) { return false; }
	if (campo.lastIndexOf(".") == (campo.length-1)) { return false; }
	return true;
}
function trocaSistema (valor) {
	if (valor == 'todos') {
		location.href='?conteudo=todasSolucoes';
	} else {
		var so = new SWFObject("solucoesFlash.swf", "Solucoes", "205", "450", "8");
		so.addVariable("nIdProd", valor);
		so.addVariable("sArquivo", "solucoes.php");
		so.addParam("wmode", "transparent");
		so.addParam("allowScriptAccess", "sameDomain");
		so.addParam("menu", "false");
		so.addParam("scale", "noscale");
		so.write("flashSolucoes");
	}
}

function valida() {
	document.formContato.submit();
}

function valida2() {
	emailNews = document.getElementById('campoNewsletter').value
	texto = "Favor preencher o campos:\n\n";
	erro = 0;
		if (emailNews == ""){
		erro=erro+1;
		texto=texto+erro+") E-mail\n";
		if(erro==1){
			document.getElementById('campoNewsletter').focus();
		}
	}
	if(erro!=0){
		alert(texto);
	}else{
		document.getElementById('formNews').submit();
	}
}
// SAC
function focoLoginSAC(){
	var f=document.formLogin;
	f.email.focus();
}
function focoChamadoSAC(){
	var f=document.formChamado;
	f.titulo.focus();
}
function validaChamadoSAC(){
	var f=document.formChamado;
	if (f.titulo.value==""){
		alert("Por favor, informe um titulo!");
		f.titulo.focus();
		return false;
	}
	if (f.texto.value==""){
		alert("Por favor, informe o texto!");
		f.texto.focus();
		return false;
	}
	TamanhoString = f.imagem.value.length;
   	extensao = f.imagem.value.substr(TamanhoString - 4,TamanhoString);
   if (TamanhoString != 0 ){
		var ext = new Array('.doc','.DOC','docx','DOCX','.txt','.TXT','.xls','.XLS','.rtf','.RTF','.dat','.DAT','.zip','.ZIP','.rar','.RAR','.ofc','.OFC','.log','.LOG','.jpg','.JPG','jpeg','JPEG','.png','.PNG','.gif','.GIF');
		for(var i = 0; i < ext.length; i++) { 
			if (extensao == ext[i])	{
				flag = "ok";
				break;
			}else{
				flag = "erro";
			}
		}
		if (flag=="erro"){
			alert("Formato de arquivo não permitido!");
			f.imagem.focus();
			return false;
		}
   }
	f.submit();
}
function encerrarChamadoSAC(id){
		if (confirm("Tem certeza que deseja encerrar este chamado?")){
  			location.href='encerrarChamado.php?idChamado='+id;
		}
}
function validaBusca() {
	var f=document.formFaq;
	if (f.busca.value==""){
		alert("Por favor, inserir palavras-chave!");
		f.busca.focus();
		return false;
	}
	f.submit();
}
function abrirChat(id){
	//if (confirm("Tem certeza que deseja encerrar este chamado?")){
		window.open('popChat.php?idChat='+id,'Chat','width=350, height=312');
	//}
}
function apareceDiv(id) {
	document.getElementById(id).style.display='block';
}
function primeiroAcesso (){
	document.getElementById('senhaCliente').style.display = 'none';
	document.getElementById('loginEmail').style.display = 'none';
	document.getElementById('dadosNaoCliente').style.display = '';
	document.getElementById('ehCliente').value = 'nao';
}
function jaSouCliente(){
	document.getElementById('senhaCliente').style.display = '';
	document.getElementById('loginEmail').style.display = '';
	document.getElementById('dadosNaoCliente').style.display = 'none';
	document.getElementById('ehCliente').value = 'sim';
}
function validaLoginSAC(){
	if(document.getElementById('ehCliente').value=='sim'){

		if(document.getElementById('login').value == '' || document.getElementById('senha').value == ''){
			alert('Preencha o campo login e o campo senha.');
		} else {
			var f=document.formLogin;
			f.submit();
		}

	} else if(document.getElementById('ehCliente').value=='nao') {

		sNome = document.getElementById('campoNome').value;
		sCNPJ = document.getElementById('campoCNPJ').value;
		sEmail = document.getElementById('campoEmail').value;

		if(sNome == '' || sEmail == '' || sCNPJ == ''){
			alert('Preencha todos os campos.');
		} else {
			var f=document.formLogin;
			f.submit();
		}

	}
}

function chatPopup(){
	document.getElementById('listaAtends').style.display = 'none';
	document.getElementById('avisoChat').style.display = '';
	document.getElementById('titAtends').style.display = 'none';
}
function chatPopup2(id){
	nChatAtual = id;
	document.getElementById('listaAtends').style.display = 'none';
	document.getElementById('chatAntigo').style.display = 'none';
	document.getElementById('avisoChat').style.display = '';
	document.getElementById('avisoChat').innerHTML = 'O chat está em andamento, caso a janela popup não abra ou foi fechada acidentalmente, <a href="javascript:window.open(\'popChatCliente.php?idChat='+id+'\',\'Chat\',\'width=600,height=400,top=50,left=50\');void(0);">clique aqui</a> para reativar.';

	clearInterval(intervalo);
	intervalo=setInterval('xajax_listaAtendentesAlone('+nChatAtual+')',30000);
}
function chatPopupAntigo(i){
	document.getElementById('chatAntigo'+i).style.display = 'none';
}
function evita_letra(tecla){
	var keyCode = tecla.keyCode ? tecla.keyCode : tecla.which ? tecla.which : tecla.charCode;
	//alert(keyCode);
	if(keyCode !=8 && keyCode !=13 && keyCode !=9) {
		if (keyCode < 48 || keyCode > 57) {
			if (window.event) //IE
			tecla.returnValue = false;
			else //Firefox
			tecla.preventDefault();
		}
	}
}
function formatar(src, mask,event){
	var tecla = event.keyCode;
	var i = src.value.length;
	var saida = mask.substring(0,1);
	var texto = mask.substring(i)
	if (texto.substring(0,1) != saida && tecla!=8)	{
		src.value += texto.substring(0,1);
	}
}
function valLoginChat(){
	var sCnpj = document.getElementById('campoCNPJ').value;
	var sEmail = document.getElementById('campoEmail').value;
	if(sCnpj=='' || sEmail==''){
		alert('Preencha todos os campos.');
	}else if(!verificaMail(sEmail)){
		alert('Digite um e-mail válido.');
	}else{
		xajax_loginChat(xajax.getFormValues('formLoginChat',true));
	}
}
function retEnviaEmail(s){
	if(s=='ok'){
		$('#sucesso').css('display','');
		$('#btEnviarDesab').css('display','');
		$('#imgLoading').html('');
	}else{
		alert(s);
	}
}
function enviaEmailSAC(){
	var sNome = $('#cUser').val();
	var sAssunto = $('#cAssunto').val();
	var sMensagem = $('#cMensagem').val();
	var sEnt = $('#cEnt').val();
	if(sAssunto=='' || sMensagem=='' || sNome==''){
		alert("Preencha todos os campos.");
	}else{
		$('#imgLoading').html('<img src="portalcidadao/images/imgLoading.gif" />');
		$('#enviaEmail').css('display','none');
		$('.btnEnviar').css('display','none');
		$.post('sac_emailEnviar.php', {nome: sNome, assunto: sAssunto, mensagem: sMensagem, ent: sEnt}, function(data){retEnviaEmail(data)});
	}
}
function retLogar(s){
	if(s=='erro'){
		alert('Usuário ou senha inválidos.');
		$('#cUser').val('');
		$('#cSenha').val('');
	}else{
		$('#logar').css('display','none');
		$('#chamado').css('display','');
		$('#bt1').css('display','none');
		$('#bt2').css('display','');
		$('#cIdUser').val(s);
	}
}
function logarChamadoSis(){
	var sUser = $('#cUser').val();
	var sSenha = $('#cSenha').val();
	if(sUser=='' || sSenha==''){
		alert("Preencha todos os campos.");
	}else{
		$.post('sac_chamadoLogar.php', {user: sUser, senha: sSenha}, function(data){retLogar(data)});
	}
}
function retCriaCham(s){
	if(s=='erro'){
		alert('Erro ao criar chamado.');
	}else{
		$('#chamado').css('display','none');
		$('#sucesso').css('display','');
		$('#bt2').css('display','none');
		$('#btEnviarDesab').css('display','');
		$('#numCham').html(s);
	}
	
}
function enviaChamadoSis(){
	var sTit = $('#cTit').val();
	var sMens = $('#cMensagem').val();
	var sIdUser = $('#cIdUser').val();
	var sIdSis = $('#cIdSis').val();
	var sVerSis = $('#cVerSis').val();
	if(sTit=='' || sMens==''){
		alert("Preencha todos os campos.");
	}else{
		$.post('sac_chamadoCria.php', {tit: sTit, mens: sMens, sis: sIdSis, user: sIdUser, vers: sVerSis}, function(data){retCriaCham(data)});
	}
}























