// Função para iniciarmos o Ajax no browser do cliente.
function openAjax() {

var ajax;

try{
    ajax = new XMLHttpRequest(); // XMLHttpRequest para browsers decentes, como: Firefox, Safari, dentre outros.
}catch(ee){
    try{
        ajax = new ActiveXObject("Msxml2.XMLHTTP"); // Para o IE da MS
    }catch(e){
        try{
            ajax = new ActiveXObject("Microsoft.XMLHTTP"); // Para o IE da MS
        }catch(E){
            ajax = false;
        }
    }
}
return ajax;
}
// -- Fim Funcao AJAX --------------->

//script para data
hoje = new Date()
dia = hoje.getDate()
dias = hoje.getDay()
mes = hoje.getMonth()
ano = hoje.getYear()
if (dia < 10)
   dia = "0" + dia
if (ano < 2000)
   ano = 1900 + ano
function CriaArray (n) {
this.length = n }
NomeDia = new CriaArray(7)
NomeDia[0] = "Domingo"
NomeDia[1] = "Segunda-feira"
NomeDia[2] = "Ter&ccedil;a-feira"
NomeDia[3] = "Quarta-feira"
NomeDia[4] = "Quinta-feira"
NomeDia[5] = "Sexta-feira"
NomeDia[6] = "S&aacute;bado"
//
NomeMes = new CriaArray(6)
NomeMes[0] = "JAN"
NomeMes[1] = "FEV"
NomeMes[2] = "MAR"
NomeMes[3] = "ABR"
NomeMes[4] = "MAI"
NomeMes[5] = "JUN"
NomeMes[6] = "JUL"
NomeMes[7] = "AGO"
NomeMes[8] = "SET"
NomeMes[9] = "OUT"
NomeMes[10] = "NOV"
NomeMes[11] = "DEZ"
// -- Fim Script data --------------->

// -- Data e relogio juntos--------------->
var timerID = null;
var timerRunning = false;
function stopclock (){
        if(timerRunning)
                clearTimeout(timerID);
        timerRunning = false;
}

function startclock () {
        // Certifica que o relógio está parado
        stopclock();
        showtime();
}

function showtime () {
        var now = new Date();
        var hours = now.getHours();
        var minutes = now.getMinutes();
        var seconds = now.getSeconds()
        var timeValue = "" + ((hours >12) ? hours -12 :hours)
		var exibedatarelogio = document.getElementById('datarelogio');
        timeValue += ((minutes < 10) ? ":0" : ":") + minutes
        timeValue += ((seconds < 10) ? ":0" : ":") + seconds
        timeValue += (hours >= 12) ? " P.M." : " A.M."
        dataValue = now.getDate()+"/"+ [now.getMonth() + 1] +"/"+now.getYear();
        // você poderá utilizar a linha abaixo se quiser visualizar dentro de um campo de formulario
        //document.clock.face.value = timeValue;
		exibedatarelogio.innerHTML = "<IMG SRC=\"imagens/icones/ico_calendario.gif\">&nbsp;"+ timeValue +"&nbsp;&nbsp;&nbsp;"+ dataValue +"&nbsp;&nbsp;";
        // você poderá substituir a linha acima pelo código
        // abaixo e terá o relógio na linha de status:
        //window.status = timeValue;
        timerID = setTimeout("showtime()",1000);
        timerRunning = true;
}
// -- Fim Script data e relogio juntos--------------->

function janela_pop_up(theURL,winName,features) {
  window.open(theURL,winName,features);
}

function janela_pop_up_2(theURL,winName,features) {
  remote = window.open(theURL,winName,features);
  remote.resizeTo(window.screen.availWidth, window.screen.availHeight);
}

function resize() {
var i=0;
  if (navigator.appName == 'Netscape') i=40;
  if (document.images[0]) window.resizeTo(document.images[0].width +12, document.images[0].height+52-i);
}

function mOvr(src,clrOver) {
if (!src.contains(event.fromElement)) {
src.style.cursor = 'hand';
src.bgColor = clrOver;
}
}
function mOut(src,clrIn) {
if (!src.contains(event.toElement)) {
src.style.cursor = 'default';
src.bgColor = clrIn;
}
}

function mClk(src) {
if(event.srcElement.tagName=='TD'){
src.children.tags('A')[0].click();
}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function fechar(){
	window.opener.location.reload()	
    window.close();
}

function alerta_publicacao(){
	window.opener.location.reload()	
	alert("Atenção: falta liberação para a publicação!")
    window.close();
}

function txtBoxFormat(objForm, strField, 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;
    }

    sValue = objForm[strField].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) == "/"))
     bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == ":") || (sMask.charAt(i) == " "))

    if (bolMask) {
     sCod += sMask.charAt(i);
     mskLen++; }
	else {
     sCod += sValue.charAt(nCount);
     nCount++;
    }

    i++;
    }

    objForm[strField].value = sCod;

    if (nTecla != 8) { // backspace
      if (sMask.charAt(i-1) == "9") { // apenas números...
        return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
      else { // qualquer caracter...
        return true;
      } }
      else {
        return true;
      }
}