// JavaScript Document
//criar uma variável boolena para verificar uma instância válida do IE.
var xmlhttp = false;
//verificar se estamos usando IE
try {
	//Se a versão JavaScript for maior que 5.
	xmlhttp = new ActiveXObject("Msxm12.XMLHTTP");
} catch (e) {
	//Se não, então usar o objeto active x mais antigo.
	try {
		//Se estivermos usando IE.
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
		//Ou devemos estar usando um navegador diferente do IE.
		xmlhttp = false;
	}
}
//Se estivermos usando um navegador dferente do IE, criar uma instância JavaScript do objeto.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	xmlhttp = new XMLHttpRequest();
}

function makerequest(serverPage, objID) {

	var obj = document.getElementById(objID);
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

// valida form contato
  function valida(theForm){
            if (isBlank(theForm.txt_nome)){
              alert("Preencha o Campo Nome.");
              return false;}
			               	
				if (isBlank(theForm.txt_email)){
              alert("Preencha o campo E-mail.");
              return false;}
					
					if (!isBlank(theForm.txt_email)){				
					arroba = theForm.txt_email.value.indexOf("@");
					ponto = theForm.txt_email.value.indexOf(".");
						if (arroba == "-1" || ponto == "-1") { 
						alert("E-mail Invalido!"); 
					return false;}						
			  		}			  			  
			  			 		
					if (isBlank(theForm.txt_telefone)){
              			alert("Preencha o Campo Telefone");
              			return false;}
						
					if (!isBlank(theForm.txt_telefone)){				
					 teste2 = theForm.txt_telefone.value;
						if (isNaN(teste2)) { 
						alert("Use Somente numeros para o Telefone!"); 
					return false;}						
			  		}						
			 			
					if (!isBlank(theForm.txt_telefone)){				
					 teste3 = theForm.txt_telefone.value.length;
						if (teste3 < 8) { 
						alert("Telefone deve conter no minimo 8 Digitos!"); 
					return false;}						
			  		}						
						
						 if (isBlank(theForm.txt_mensagem)){
              				alert("Preencha o Campo Mensagem");
              				return false;}			  			  			  			
            return true;}


  function isBlank(txtField){
  if (txtField.value)
    return (false);
  else
    return(true);
}


// valida form contato
  function valida_ouvidoria(theForm){
            if (isBlank(theForm.txt_nome)){
              alert("Preencha o Campo Nome.");
              return false;}
			               	
				if (isBlank(theForm.txt_email)){
              alert("Preencha o campo E-mail.");
              return false;}
					
					if (!isBlank(theForm.txt_email)){				
					arroba = theForm.txt_email.value.indexOf("@");
					ponto = theForm.txt_email.value.indexOf(".");
						if (arroba == "-1" || ponto == "-1") { 
						alert("E-mail Invalido!"); 
					return false;}						
			  		}						
						
						 if (isBlank(theForm.txt_mensagem)){
              				alert("Preencha o Campo Mensagem");
              				return false;}			  			  			  			
            return true;}


  function isBlank(txtField){
  if (txtField.value)
    return (false);
  else
    return(true);
}

// valida form login
  function logar_user(theForm){
	  var tipo = theForm.user_tipe.value
           if (tipo == 0){
              alert("Selecione o tipo de usuário!");
              return false;}
			if (isBlank(theForm.user)){
              alert("Preencha o campo Login.");
              return false;}
			               	
				if (isBlank(theForm.pass)){
              alert("Preencha o campo Senha.");
              return false;}			  			  
}


//Valida a busca de livros
function valida_busca(theForm){
	if (isBlank(theForm.txt_busca)){
    	alert("Preencha o Campo de Busca.");
        return false;}
		
	if (!isBlank(theForm.txt_busca)){				
			teste3 = theForm.txt_busca.value.length;
		if (teste3 < 2) { 
			alert("Sua palavra chave é muito curta!"); 
			return false;}						
		}	
}

//Validação da Reserva de Livros
function reserva(theForm){
	if (isBlank(theForm.nome)){
    	alert("Preencha o Campo Nome.");
        return false;}					
			 			
	if (isBlank(theForm.cpf)){
    	alert("Preencha o Campo CPF");
		return false;}
						
	if (!isBlank(theForm.cpf)){				
		teste2 = theForm.cpf.value;
		if (isNaN(teste2)) { 
			alert("Use Somente numeros para o CPF!"); 
			return false;}						
		}
			 			
	if (!isBlank(theForm.cpf)){				
		teste3 = theForm.cpf.value.length;
		if (teste3 != 11) { 
			alert("O CPF deve conter 11 Digitos!"); 
			return false;}						
		}

	if (isBlank(theForm.email)){
    	alert("Preencha o campo E-mail.");
        return false;}
					
	if (!isBlank(theForm.email)){				
		arroba = theForm.email.value.indexOf("@");
		ponto = theForm.email.value.indexOf(".");
		if (arroba == "-1" || ponto == "-1") { 
			alert("E-mail Invalido!"); 
			return false;}						
		}
}

//Validação da Reserva de Livros
function valida_primeiro_acesso(theForm){
	if (isBlank(theForm.matricula)){
    	alert("Preencha o Campo Matricula.");
        return false;}					
			 			
	if (isBlank(theForm.cpf)){
    	alert("Preencha o Campo CPF");
		return false;}
						
	if (!isBlank(theForm.cpf)){				
		teste2 = theForm.cpf.value;
		if (isNaN(teste2)) { 
			alert("Use Somente numeros para o CPF!"); 
			return false;}						
		}
			 			
	if (!isBlank(theForm.cpf)){				
		teste3 = theForm.cpf.value.length;
		if (teste3 != 11) { 
			alert("O CPF deve conter 11 Digitos!"); 
			return false;}						
		}

	if (isBlank(theForm.senha)){
    	alert("Preencha o campo senha.");
        return false;}
					
	if (!isBlank(theForm.senha)){				
		teste = theForm.senha.value.length;
		if (teste < 5) { 
			alert("O campo senha deve conter no mínimo 5 Digitos!"); 
			return false;}						
		}
		
	if (isBlank(theForm.senha2)){
    	alert("Preencha o campo Confirmar Senha.");
        return false;}
					
	if (!isBlank(theForm.senha2)){			
		senha = theForm.senha.value;
		senha2 = theForm.senha2.value;
		if (senha != senha2) { 
			alert("As duas senhas devem ser iguais!"); 
			return false;}						
		}
}

//função para abrir janela pop-up
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function goto_URL(object) {
window.location.href = object.options[object.selectedIndex].value; }


function abrir(URL,wid,hei) {

  var width = wid;
  var height = hei;
  
  var left = 99;
  var top = 99;

  newwindow = window.open(URL,'janela', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
	if (window.focus) {newwindow.focus()}
  return false;
}


function valida_contato_biblio(theForm){
            if (isBlank(theForm.txt_nome)){
              alert("Preencha o Campo Nome.");
              return false;}
						
						 if (isBlank(theForm.txt_mensagem)){
              				alert("Preencha o Campo Mensagem");
              				return false;}			  			  			  			
            return true;}


  function isBlank(txtField){
  if (txtField.value)
    return (false);
  else
    return(true);
}

