function login()
    {
      var ajax = Ajax();
	  var login = document.getElementById('login').value;
	  var senha = document.getElementById('senha').value;
	  var resp = false;
	  	  
	  ajax.onreadystatechange = function()
	    {
	      if(ajax.readyState == 4)
		    {
		      if(ajax.status == 200)
			    {
			      resp = ajax.responseText;
				  
				  if(resp == 'true')
				    {
				      location = 'areadeclientes.php'
				    } else {
				      document.getElementById('login').style.border = '1px solid #FF0000';
					  document.getElementById('senha').style.border = '1px solid #FF0000';
					  document.getElementById('erro_login').innerHTML = '<img border="0" src="imagens/erro.png" widht="50" height="12"> <b>CPF / CNPJ ou SENHA inválido(s)!</b>'
					  document.getElementById('login').focus();
					}
				} else {
			      return false;
				}
			}
		};
	
	  dados = 'login='+login+'&senha='+senha+'&acao=logar';
	  ajax.open('POST','login.php',true);
	  ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded; chasert=UTF-8');
	  ajax.send(dados);
	}

function sair()
    {	
      var ajax = Ajax();
	  var resp = false;
	  	  
	  ajax.onreadystatechange = function()
	    {
	      if(ajax.readyState == 4)
		    {
		      if(ajax.status == 200)
			    {
			      resp = ajax.responseText;
				  if(resp == 'true')
				    {
				      location = 'index.php'
				    } else {
				      return false; 
					}
				} else {
			      return false;
				}
			}
		};
	
	  dados = 'acao=sair';
	  ajax.open('POST','login.php',true);
	  ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded; chasert=UTF-8');
	  ajax.send(dados);      
	}
	
function setMensagem(id_usuario,msg,email)
    {
      var ajax = Ajax();
	  
	  ajax.onreadystatechange = function()
	    {
	      if(ajax.readyState == 4)
		    {
		      if(ajax.status == 200)
			    {
			      alert('Mensagem enviada com sucesso!');
				  msg.style.border = '1px solid #336F9D'
		          document.getElementById('erro_mensagem').innerHTML = '';
				  msg.value = '';
				  total_mensagens(id_usuario);
				  caracteres();
				} else {
			      return false;
				}
			}
		};
	 
	  dados = 'user='+id_usuario+'&msg='+msg.value+'&email='+email+'&acao=cadastrar';
	  ajax.open('POST','mensagem.php',true);
	  ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded; chasert=UTF-8');
	  ajax.send(dados);  
	}

function total_mensagens(id_usuario)
    {	
      var ajax = Ajax();
	  
	  ajax.onreadystatechange = function()
	    {
	      if(ajax.readyState == 4)
		    {
		      if(ajax.status == 200)
			    {
			      var resp = ajax.responseXML;
                  var xml = resp.documentElement; 				 
                  var nodos = xml.childNodes;
				  
				  for(var i=0; i<nodos.length; i++)
				    {
				      if(nodos[i].nodeName == 'hoje')
					    {
					      var hoje = nodos[i].childNodes; 
						  document.getElementById('hoje').innerHTML = hoje[0].nodeValue;
						} 
					 
					  else if(nodos[i].nodeName == 'total') 
					    {
						  var total = nodos[i].childNodes;
						  document.getElementById('total').innerHTML = total[0].nodeValue;
						}
					}
				} else {
			      return false;
				}
			}
		}; 
	 
	  dados = 'user='+id_usuario+'&acao=status';

	  ajax.open('POST','mensagem.php',true);
	  ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded; chasert=UTF-8');
	  ajax.send(dados);
	}
	
function setFocus() {
  
  if(document.getElementById('login').value.length == 14) {
    document.getElementById('senha').focus(); 
  }
}

function checkDigits(dig) {
   
  document.getElementById('login').value = dig.replace(/\D+/,'');
}

function view_detalhes(id) {
    window.open('view_apolice.php?id='+id,'focus','top=0,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=750,height=250');
}

function view_detalhes_proposta(segurado,nome,local,basica,danos,multas,pintura,pintura_externa,vigencia_inicio,vigencia_fim,pagamento,premio_total) {

	dados = "segurado="+segurado+"&nome="+nome+"&local="+local+"&basica="+basica+"&danos="+danos+"&multas="+multas+"&pintura="+pintura+"&pintura_externa="+pintura_externa+"&vigencia_inicio="+vigencia_inicio+"&vigencia_fim="+vigencia_fim+"&pagamento="+pagamento+"&premio_total="+premio_total;
    window.open('view_proposta.php?'+dados+'','focus','top=0,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=750,height=300');
}

function view_detalhes_prospeccao(cod)
        {
         window.open('view_prospeccao.php?id='+cod,'focus','top=0,left=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=750,height=500');
        }

function carta_pendente(cod)
        {
         window.open('impressao_cadastro_pendente.php?id='+cod,'focus','top=0,left=0,toolbar=1,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width=750,height=350');
        }
        
function carta_recusado(cod)
        {
         window.open('impressao_cadastro_recusado.php?id='+cod,'focus','top=0,left=0,toolbar=1,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width=750,height=350');
        }
        
function carta_aprovado(cod)
        {
         window.open('impressao_cadastro_aprovado.php?id='+cod,'focus','top=0,left=0,toolbar=1,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width=750,height=350');
        }