// Base geral

//Execução de onpageload
function int() {
	//Realiza a troca do lançamento
	if (document.getElementById('DIV_lancamentos') != null) {
		
		var Interval_lanca = window.setInterval('makeRequest("ajax_lateral_esquerdo_lancamentos.asp","DIV_lancamentos","1")', 180000);
		var Interval_lanca_seg = window.setInterval('lancamento_seg()', 1000)
		DIV_lancamentos_seg
	}
	
	document.onkeyup = produtos_ferramentas_enter;
	
}

//Exibe o tempo para troca do proximo anuncio
var GL_lancamento_seg = 180;

function lancamento_seg() {
	if (GL_lancamento_seg == 1) {
		GL_lancamento_seg = 180
	} else {
		GL_lancamento_seg = GL_lancamento_seg-1
	}
	
	document.getElementById('DIV_lancamentos_seg').innerHTML=GL_lancamento_seg+'s';
}

try {
request_source = onnavigate("request_source", function(data){

try {	
	var source = $("source")
	makeRequest(data,'');
	//Refreshing the counter
	var counter = $("counter")
} catch(err) { }
})

} catch(err) { };

//Função do ajax
function makeRequest(url,dive,tipo_load) {
				
				 if (!dive) {
					dive = 'Corpo' 
				 }
				 
				loading(dive,tipo_load);
								
				url = antiCacheRand(url);
				
				//toTop();
                http_request = false;

                if (window.XMLHttpRequest) { // Mozilla, Safari,...
                    http_request = new XMLHttpRequest();
                    if (http_request.overrideMimeType) {
                        http_request.overrideMimeType('text/xml');
                    }
                } else if (window.ActiveXObject) { // IE
					
                    try {
                        http_request = new ActiveXObject("Msxml2.XMLHTTP");
						
                    } catch (e) {
                        try {
                        http_request = new ActiveXObject("Microsoft.XMLHTTP");
						
                        } catch (e) {}
                    }
                }

                if (!http_request) {
                    alert('Seu navegador não suporta este site!');
                    return false;
                }
                //alert(http_request.onreadystatechange)
				http_request.onreadystatechange = function(){ carrega_pagina(dive); };
                http_request.open('POST', url, true);
                http_request.send(null);
				
            }

            function carrega_pagina(dive) {

                if (http_request.readyState == 4) {
                    if (http_request.status == 200) {
						document.getElementById(dive).innerHTML=http_request.responseText;
						try {
						document.getElementById('carregando_trab').innerHTML='0';
						} catch (e) {}
						
						try {
						if (voltar_pg) {
							timer_voltar_pagina();		
						}
						} catch (e) {}
						
						try {
							var alert_msg = document.getElementById('alert_msg').value;
							if (alert_msg) {
								alert(alert_msg);
							}
						} catch (e) {}
						
                    } else {
                        alert('Houve um erro nesta página. Tente novamente mais tarde!');
                }
  	 }

}
//a função que gera o randomico *********
function antiCacheRand(aurl){
    var dt = new Date();
    if(aurl.indexOf("?")>=0){// já tem parametros
        return aurl + "&atc=" + encodeURI(Math.random() + "_" + dt.getTime());
    }else{ return aurl + "?atc=" + encodeURI(Math.random() + "_" + dt.getTime());}
}


//Funcao do loading
function loading(dive,tipo) {
	try {
	document.getElementById('carregando_trab').innerHTML='1';
	} catch (e) {}
	if (tipo == undefined) {
		tipo = '1'
	}
	
	if (tipo != '3') {
		if (tipo == '' || tipo == '1') {
			document.getElementById(dive).innerHTML='<center><img src=icon/loading.gif /></center>';
		} else {
			if (tipo == '2') {
				document.getElementById(dive).innerHTML='<span class=FC_tahoma_11_717>carregando...</span>';
			}
		}
	}
}

//MÁSCARA DE VALORES
//onkeypress="return txtBoxFormat(this, '(99)9999-9999', event);"
function txtBoxFormat(objeto, sMask, evtKeyPress) {
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;


if(document.all) { // Internet Explorer
    nTecla = evtKeyPress.keyCode;
} else if(document.layers) { // Nestcape
    nTecla = evtKeyPress.which;
} else {
    nTecla = evtKeyPress.which;
    if (nTecla == 8) {
        return true;
    }
}

    sValue = objeto.value;

    // Limpa todos os caracteres de formatação que
    // já estiverem no campo.
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( " ", "" );
    sValue = sValue.toString().replace( " ", "" );
    fldLen = sValue.length;
    mskLen = sMask.length;

    i = 0;
    nCount = 0;
    sCod = "";
    mskLen = fldLen;

    while (i <= mskLen) {
      bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
      bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

      if (bolMask) {
        sCod += sMask.charAt(i);
        mskLen++; }
      else {
        sCod += sValue.charAt(nCount);
        nCount++;
      }

      i++;
    }

    objeto.value = sCod;

    if (nTecla != 8) { // backspace
      if (sMask.charAt(i-1) == "9") { // apenas números...
        return ((nTecla > 47) && (nTecla < 58)); } 
      else { // qualquer caracter...
        return true;
      } 
    }
    else {
      return true;
    }
  }

