function mostraTBody(id){
	if (document.getElementById(id).style.display=='') {
		document.getElementById(id).style.display='none';
	} else {
		document.getElementById(id).style.display='';
	}
}
///////////////////////////////////=======================================
// funcao para centralizar página	
function centraliza(w,h){
	largura = w;
	altura = h;
	if (parseInt(navigator.appVersion) >= 4) 
		window.moveTo((screen.width/2)-(largura/2+10),(screen.height/2)-(altura/2+20));
}
///////////////////////////////////=======================================
// Ajax
function loadXMLDoc(url,div_id){

	var req;
	var id = div_id;
	//
    req = null;
    // Procura por um objeto nativo (Mozilla/Safari)
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
		req.overrideMimeType('text/xml; charset=iso-8859-1');
        req.send(null);
    // Procura por uma versao ActiveX (IE)
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
	function processReqChange(){
    	// apenas quando o estado for "completado"
    	if (req.readyState == 4) {
        	// apenas se o servidor retornar "OK"
        	if (req.status == 200) {
            	// procura pela div id="atualiza" e insere o conteudo
            	// retornado nela, como texto HTML
				document.getElementById(id).innerHTML = req.responseText;
        	} else {
            	alert("Houve um problema ao obter os dados:\n" + req.statusText);
        	}
    	}
	}
}

function CarregaAjax(url,div_id){
	loadXMLDoc(url,div_id);
	document.getElementById(div_id).innerHTML = "Aguarde, carregando...";
} 
function formataValor(val,len)
{
   n='__0123456789';
   d=val.value;
   l=d.length;
   r='';
   if (l > 0)
   {
    z=d.substr(0,l-1);
    s='';
    a=2;
    for (i=0; i < l; i++)
    {
        c=d.charAt(i);
        if (n.indexOf(c) > a)
        {
            a=1;
            s+=c;
        };
    };
    l=s.length;
    t=len-1;
    if (l > t)
    {
        l=t;
        s=s.substr(0,t);
    };
    if (l > 2)
    {
        r=s.substr(0,l-2)+','+s.substr(l-2,2);
    }
    else
    {
        if (l == 2)
        {
            r='0,'+s;
        }
        else
        {
            if (l == 1)
            {
                r='0,0'+s;
            };
        };
    };
    if (r == '')
    {
        r='0,00';
    }
    else
    {
        l=r.length;
        if (l > 6)
        {
            j=l%3;
            w=r.substr(0,j);
            wa=r.substr(j,l-j-6);
            wb=r.substr(l-6,6);
            if (j > 0)
            {
                w+='.';
            };
            k=(l-j)/3-2;
            for (i=0; i < k; i++)
            {
                w+=wa.substr(i*3,3)+'.';
            };
            r=w+wb;
        };
    };
   };
   if (r.length <= len)
   {
    val.value= '' + r;
   }
   else
   {
    val.value= '' + z;
   };
   return 'ok';
};
