﻿// JScript File
var XMLHTTPREQUEST_IE = new Array("Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.3.0","Msxml2.XMLHTTP","Microsft.XMLHTTP");
var objXMLHTTPRequest;
function criaXMLHttpRequest(){
    var oXMLhttp = null;
    
    if (window.ActiveXObject != null){
        var bCriado = false;
        for (var i=0; i < XMLHTTPREQUEST_IE.length && ! bCriado; i++){
            try{
                oXMLhttp = new ActiveXObject(XMLHTTPREQUEST_IE[i]);
                bCriado = true;
            } catch(ex){
            }
        }
    }else if (window.XMLHttpRequest != null){
        oXMLhttp = new window.XMLHttpRequest();
    }
    if (oXMLhttp == null)
        objXMLHTTPRequest = false;
    else
        objXMLHTTPRequest = oXMLhttp;
}

var divResp = "";
function Template(id){
   criaXMLHttpRequest();
   divResp = "Div_Centro";
   objXMLHTTPRequest.onreadystatechange = ProcessarResposta;
   objXMLHTTPRequest.open("POST", "WS_Portal.asmx/Template", true);
   objXMLHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   objXMLHTTPRequest.send("Id=" + id);
}

function ProcessarResposta(){
    var DivCentro = document.getElementById(divResp);
    if(objXMLHTTPRequest.readyState == 1){
        DivCentro.innerHTML = "<span id='txtMSG' class='classTitleNews'>Carregando...</span>";
    }else if(objXMLHTTPRequest.readyState == 2){
        DivCentro.innerHTML = "<span id='txtMSG' class='classTitleNews'>Carregando...</span>";
    }else if(objXMLHTTPRequest.readyState == 3){
        DivCentro.innerHTML = "<span id='txtMSG' class='classTitleNews'>Carregando...</span>";
    }else if(objXMLHTTPRequest.readyState == 4){
        if(objXMLHTTPRequest.status == 200){
            var XMLDoc = objXMLHTTPRequest.responseXML;
            DivCentro.innerHTML = XMLDoc.getElementsByTagName("Resp_HTML")[0].childNodes[0].nodeValue;
        }else{
            DivCentro.innerHTML = "<span id='txtMSG' class='classTitleNews'>A página solicitada não foi encontrada. Por favor, tente novamente mais tarde.</span>"
        }
        
    }
}
