    /**
      *
      **/
    function obterInstanciaAjax(){
        //Isso garantirá que a cada chamada dessa função uma instância nula do Ajax será criada.
        var xmlhttp = null;
        
        try{
            xmlhttp = new XMLHttpRequest();
        }catch(ee){
            try{
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            }catch(e){
                try{
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }catch(E){
                    xmlhttp = false;
                }//end catch
            }//end catch
        }//end catch
        
        return xmlhttp;
    }
    
    /**
      * @param frm Formulário
      **/
    function valida_formulario_professor(frm){
        //confere a unidade selecionada
        if(frm.prof_unidade.selectedIndex==0){
        //avisa-o
        alert("Seleciona sua unidade!");
        //foca
        frm.prof_unidade.focus();
        //cancela submit
        return false;
        }//end if


        //confere a unidade selecionada
        if(frm.prof_usuario.value == ""){
        //avisa-o
        alert("Preencha o campo usuário!");
        //foca
        frm.prof_usuario.focus();
        //cancela submit
        return false;
        }//end if
        
        
    //caso contrario 
    return true;
    }
    
    /**
      * @param frm Formulário
      **/
    function autenticar_professor(frm){
    
    frm = document.forms[0] 
    //se formulario nao for valido quebra fluxo
    if(!valida_formulario_professor(frm)) return false;
        
    var xmlhttp = obterInstanciaAjax();

    var prof_usuario = frm.prof_usuario.value
    var prof_senha   = frm.prof_senha.value
    var prof_unidade = frm.prof_unidade.value
    var passo = frm.passo.value
        
    var parameters = "prof_usuario=" + encodeURI(prof_usuario) + "&prof_senha=" + encodeURI(prof_senha) + "&prof_unidade=" + encodeURI(prof_unidade) + "&passo=" + encodeURI(passo);
    //alert(parameters)

    xmlhttp.open('POST', "acesso/BD_AutenticarProfessor.php", true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length", parameters.length);
    xmlhttp.setRequestHeader("Connection", "close");

    //setThStatus("Autenticando...");
	//alert('validando formulario');
    xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState==4) {//se a requisicao do arquivo estiver completa
                if (xmlhttp.status==200 || window.location.href.indexOf("http")==-1){//se a requisicao ocorrer com sucesso ou o scrip estiver rodando localmente
                            
                        var texto = xmlhttp.responseText
                        //Desfaz o urlencode, para ajustar bug do acento
                        texto=texto.replace(/\+/g," ")
                        texto=unescape(texto)
                        if(texto.indexOf("ORA-0000:")>=0){
                        //carrega pagina padrao do aluo
                        //window.parent.location = "../intra_unidades/funcionario/default_funcionario.php";
                        window.location = "login_professor_contra_senha.php";
                        //window.location.reload();
                        }//end if
                        else{
                        alert(texto);
                        //seta aviso de retorno
                        setThStatus("");
                        //foca campo senha
                        document.forms[0].prof_senha.focus();
                        }//end else
                    }//fim do if
                }//fim do if
            }//fim da function interna
    //envia parametros
	
    xmlhttp.send(parameters);
    return false;
    }//end autentica_aluno
    
    /**
      * @param msg Mensagem
      **/
    function setThStatus(msg){
    document.getElementById("thStatus").innerHTML = msg;
    }
      
    /**
      *
      **/
    function foco_inicial(){
        try{
            //foca campo
            document.forms[0].prof_usuario.focus();
        }//end try
        catch(e){
            alert(e)
        }//end catch
    }//end foco_inicial


    /**
      * @param cmb
      **/
	  
	function focar_campo_usuario_apos_selecionar_unidade(cmb){
		/*
		if(cmb.value=='pos'){
			document.getElementById('a001').style.display = 'none';
			document.getElementById('a002').style.display = 'none';
			document.getElementById('a003').style.display = 'none';
			document.getElementById('a004').style.display = 'none';
			cmb.selectedIndex=0;
			parent.window.location = "http://200.169.97.109/ge/htmls-por/pro_login.htm";

		}
		else
		{
			document.getElementById('a001').style.display = '';
			document.getElementById('a002').style.display = '';
			document.getElementById('a003').style.display = '';
			document.getElementById('a004').style.display = '';
	
		}*/
	    if(cmb.value!="") document.forms[0].prof_usuario.focus();
	
    }

