//Funcao AJAX:
function ajaxInit() {
    var xmlhttp ;
    try {
        xmlhttp = new XMLHttpRequest() ;
        } catch ( ee ) {
            try {
                xmlhttp = new ActiveXObject( "Msxml2.XMLHTTP" );
            } catch ( e ) {
                try {
                    xmlhttp = new ActiveXObject( "Microsoft.XMLHTTP" );
                } catch (E) {
                    xmlhttp = false;
                }
            }
    }
    return xmlhttp;
}

// AJAX: Load in DIV:
function loadInDiv(URL,divid,naoajusta) {
  pageDiv = document.getElementById(divid);

  ajax = ajaxInit();
  if (ajax) {
     ajax.open('GET',URL,true);
     ajax.onreadystatechange = function() {
         if ( ajax.readyState == 4) {
            if ( ajax.status == 200) {
                pageDiv.innerHTML = ajax.responseText;
            }
         }
     }
  }
  ajax.send(null);
  
  if (!naoajusta) ajustaMenu(URL);
}


function loadSDInDiv(URL,divid,itMenu) {
  pageDiv = document.getElementById(divid);
  pageDiv.innerHTML = '<iframe width=100% height=100% frameborder=0 marginwidth="0" marginheight="0" src="'+URL+'"></iframe>';
  ajustaMenu(itMenu);
}

//**************************************************************************************************
function ajustaMenu(URL) {
  var ponteiro;

  menuAtual_left = tiraAcentos(menuAtual_left);

  if (menuAtual_left != 'http://www' && document.getElementById('r_'+menuAtual_left) != null) {
    document.getElementById('r_'+menuAtual_left).innerHTML = '';
  }

  var qparts = URL.split(".");
  menuAtual_left = qparts[0];

//---
  if ( menuAtual_left.search('/') >=0 ){
    qparts = URL.split("/");
    menuAtual_left = tiraAcentos(qparts[qparts.length -1]);
    menuAtual_left = menuAtual_left.substring(0,menuAtual_left.search('.php'));
    menuAtual_left = menuAtual_left.replace(/ /g,"_");
  }
//---

  if (menuAtual_left != 'http://www') {
    document.getElementById('r_'+menuAtual_left).innerHTML = '<img src=imagens/setamenu.gif>';
  }
  //printer.style.display = 'inline';
  if (ponteiro != null) {
    document.getElementById('r_'+ponteiro).innerHTML = '<img src=imagens/setamenu.gif>';
    menuAtual_left = ponteiro;
    if (ponteiro.substring(0,2) == 'ds' || ponteiro.substring(0,2) == 'fs') printer.style.display = 'none'
    else printer.style.display = 'inline';
  }
}

function printDiv(divId)
{   var a = window.open('','','width=400,height=400,scrollbars=1');
	a.document.open("text/html");	
	a.document.write(document.getElementById(divId).innerHTML);
	a.location.reload( false );
	a.print();
    a.close();
}

function printFrame(fraId) {
    frames[fraId].focus();
    frames[fraId].print();
}


//---------------------------
/*
Carrega no iframe a URL clicada.
*/
function loadInFrame(URL,frameid) {
  var pageFrame = document.getElementById(frameid);
  pageFrame.src = URL;
}


/*
 * from http://republicavirtual.com.br/js/xml_request.js
 */
function get_url(url_req, funcao, postString){
	req = new XMLHttpRequest();	 
	var req_post = (typeof postString != 'undefined');
	var retorno = "";
	
	if (req) { 
		req.onreadystatechange = function() { 
			if (req.readyState == 4 && req.status == 200) { 
				eval(funcao+"(req.responseText)");				
			} 
		}
		req.open((req_post)?'POST':'GET', url_req); 
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		req.send((req_post)?postString:null);
	}
}

