﻿
    function e(elemento){
     return document.getElementById(elemento);
    }
    
    function p(indice){
     return eval("document.forms[0]."+indice);
    }

    function adiciona(el,obj){
     try{
      e(el).insertBefore(obj);
     }catch(ex){
       e(el).insertBefore(obj,e(el).childNodes[0]);
     }
    } 

    function limpa(el){
      el = e(el);
       if(el.hasChildNodes()){
        while(el.hasChildNodes()){
         el.removeChild(el.childNodes[0]);
        }
       }
    }
 
 function carregando(el){
  img = document.createElement("IMG")
  img.setAttribute("src","../../imagens/carregando.gif");
  adiciona(el,img);
 }

function abrePerguntaItem(id){

try{
carregando("carregandoFaq");
 var oHTTPRequest = createXMLHTTP(); 
       
     oHTTPRequest.open("post", "Handler.ashx?id="+id, true);
     oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	 
	 if (oHTTPRequest.readyState!=4){
	  void(0);
	 }

     oHTTPRequest.onreadystatechange=function(){
      if (oHTTPRequest.readyState==4){
        eval(oHTTPRequest.responseText);
		}
		 }
       oHTTPRequest.send("");
      limpa("carregandoFaq");
      
      }catch(e){}
       
      
}


function pegaPergunta(source,args){

if(p("q").value == "" || p("q").value.length < 3){
 alert("Digite sua dúvida na caixa de pesquisa!");
 p("q").focus();
 return args.IsValid = false;
}
 try{
  carregando("carregandoFaq");
  
 
    var query = document.getElementById("q").value;
       var oHTTPRequest = createXMLHTTP(); 
     oHTTPRequest.open("post", "Handler.ashx?q="+query, true);
     oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	 
 if (oHTTPRequest.readyState!=4){
	  void(0);
	 }

     oHTTPRequest.onreadystatechange=function(){
      if (oHTTPRequest.readyState==4){
        eval(oHTTPRequest.responseText);
        limpa("carregandoFaq")
          }
		 }
       oHTTPRequest.send("");
      
      }catch(e){
      }
      
      return args.IsValid = false;
      
}


function adicionaPerguntaFaq(cod,pergunta,tipo){
 var el;
 var t; //Textos
 var a; //Link
  
 div = document.createElement("DIV");
 t = document.createTextNode(pergunta);
 a = document.createElement("A");
 
 if(tipo!=1){
     a.appendChild(t);
     a.setAttribute("href","javascript:abrePerguntaItem("+cod+");");
     div.appendChild(a);
 }else{
    div.appendChild(t)
 }
 
 div.className = "respostaFAQ";

  adiciona("boxRespostaFaq",div);

}