/* JavaScript Document */
/* Framework SAAP - Browser */
/* Juliano V. Baladao */

function frwRequestXMLDoc(url, objId, pos) { 
	
	var method = "GET";
	
	if (!document.getElementById(objId)) return false;

	var FRW_NEW = '<!-- FWR:';
	var FRW_BEGIN = '.BEGIN -->';
	var FRW_END = '.END -->';
	var FRW_LOAD = '<!-- FWR:LOAD_AJAX';
	
	var httpReq = null;
	var objBefore = '';
	var objAfter = '';
	
	var frwProcessReqChange = function() { 
	    // apenas quando o estado for "completado" 
	    if (httpReq.readyState == 4) { 
	        // apenas se o servidor retornar "OK" 
	        if (httpReq.status == 200) { 
	        	// retornado nela, como texto HTML 
	            document.getElementById(objId).innerHTML = objBefore + 
	                                                       FRW_NEW + objId.toUpperCase() + FRW_BEGIN + 
	                                                       httpReq.responseText + 
	                                                       FRW_NEW + objId.toUpperCase() + FRW_END + 
	                                                       objAfter;
				return true;
	        } else { 
	            alert("Atencao: \n Houve um problema ao obter os dados: \n " + httpReq.statusText);
	            document.getElementById(objId).innerHTML = objBefore + objAfter;
	            return false;
	        } 
	    }
	};
	
    // salva conteudo atual antes ou depois da conteudo carregado
    if (pos) {
	    if (pos.toLowerCase() == 'before') objAfter = frwClearOld(document.getElementById(objId).innerHTML);
	    else if (pos.toLowerCase() == 'after') objBefore = frwClearOld(document.getElementById(objId).innerHTML);
	}

	try { httpReq = new XMLHttpRequest(); } catch(e) { 
	    try { httpReq = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { 
	    	try { httpReq = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { 
	    		httpReq = null; 
	    	}
	    }
	}
	            
    if (httpReq) {
		httpReq.open(method.toUpperCase(), url, true);
		httpReq.onreadystatechange = frwProcessReqChange;
       	httpReq.send(null);
        return true;
    } else { 
        alert("Atencao: \n Este browser nao suporta requisicoes AJAX.");
        return false;
    }
}

function getPage(url, returnId, pos) {
    frwRequestXMLDoc(url, returnId, pos);
}

function exibeOcultaColuna(idColuna,idBotao,img1,img2){
	
	if (document.getElementById(idColuna).style.display=='') {	
		document.getElementById(idColuna).style.display='none';
		document.getElementById(idBotao).src='/ajuda/imgs/'+img2;
	}
	else {
		document.getElementById(idColuna).style.display='';
		document.getElementById(idBotao).src='/ajuda/imgs/'+img1;		
	}

}

function ocultaColuna(idColuna,idBotao,img1,img2){

		document.getElementById(idColuna).style.display='none';
		document.getElementById(idBotao).src='/ajuda/imgs/'+img2;
}

function exibeColuna(idColuna,idBotao,img1,img2){

		document.getElementById(idColuna).style.display='';
		document.getElementById(idBotao).src='/ajuda/imgs/'+img1;	
}

function aumentaLetra(idDiv,tam){
		tam = tam.split('px');
		tam[0] = Number(tam[0])+1
		document.getElementById(idDiv).style.fontSize = tam[0]+'px';
}

function diminuiLetra(idDiv,tam){
		tam = tam.split('px');
		tam[0] = Number(tam[0])-1
		document.getElementById(idDiv).style.fontSize = tam[0]+'px';
}

function exibeCat(idCat){
	
	if (document.getElementById(idCat+'cat').style.display=='') {	
		document.getElementById(idCat+'cat').style.display='none';
	}
	else {
		document.getElementById(idCat+'cat').style.display=''

	}

}


function busca(palavra) {

	ocultaColuna('tdRelacionados','btnColuna2','bt_colapse_.gif','bt_colapse.gif');
	getPage('busca.php?palavras='+palavra+'&referer=busca', 'divCentral', '');
	document.getElementById('divRelacionados').value = '&nbsp';
	
}
