// FUNÇÃO DE TRATAMENTO DE DATA
//=============================
function longMonthArray() {
        this[0] = "Janeiro";    this[1] = "Fevereiro";  this[2] = "Março";
        this[3] = "Abril";      this[4] = "Maio";        this[5] = "Junho";
        this[6] = "Julho";       this[7] = "Agosto";     this[8] = "Setembro";
        this[9] = "Outubro";    this[10] = "Novembro";  this[11] = "Dezembro";
        return (this);
}

function shortMonthArray() {
        this[0] = "Jan";        this[1] = "Feb";        this[2] = "Mar";
        this[3] = "Apr";        this[4] = "May";        this[5] = "Jun";
        this[6] = "Jul";        this[7] = "Aug";        this[8] = "Sep";
        this[9] = "Oct";        this[10] = "Nov";       this[11] = "Dec";
        return (this);
}

function longDayArray() {
        this[0] = "Domingo,";     this[1] = "Segunda Feira,";     this[2] = "Terça Feira,";
        this[3] = "Quarta Feira,";  this[4] = "Quinta Feira,";   this[5] = "Sexta Feira,";
        this[6] = "Sábado,";
        return (this);
}

function shortDayArray() {
        this[0] = "Dom"; this[1] = "Seg"; this[2] = "Ter"; this[3] = "Qua";
        this[4] = "Qui"; this[5] = "Sex"; this[6] = "Sab";
        return (this);
}

function getShortYear(year)
{
shortyear =  year%100;
     if (shortyear < 10) shortyear = "0"+shortyear;
        return shortyear
}

function getLongYear(year)
{
  if (year > 1900) return year
  return year+1900;
}

function writeDateLong(format)
{
   shortDays = new shortDayArray();
   longDays = new longDayArray();
   shortMonths = new shortMonthArray();
   longMonths = new longMonthArray();
   d = new Date();
   day = d.getDate();
   month = d.getMonth();
        year = d.getYear();
   if (format == 0)
     str = shortDays[d.getDay()] + " " + shortMonths[month] +". " + day + ", "+getLongYear(year);
  else if (format == 1)
     str = shortDays[d.getDay()] + " " + longMonths[month] + " " + day + ", "+getLongYear(year);
  else if (format == 2)
     str = longDays[d.getDay()] + "de" + longMonths[month] + "de" + day + ", "+getLongYear(year);
  else if (format == 3)
     str = longMonths[month] + " " + day + ", "+getLongYear(year);
   else if (format == 4)
     str = shortDays[d.getDay()] + " " + day + " " + shortMonths[month] +". " +getLongYear(year);
  else if (format == 5)
     str = shortDays[d.getDay()] + " " + day + " " + longMonths[month] + " " +getLongYear(year);
  else if (format == 6)
     str = longDays[d.getDay()] + " " + day + " de " + longMonths[month] + " de " + getLongYear(year);
  else if (format == 7)
     str = day + " " + longMonths[month] + ", "+getLongYear(year);
  else {
     month++;
     shortyear = getShortYear(year);
     if (format == 8)
       str = month + "/" + day + "/" + shortyear;
     else if (format == 9)
       str = month + "/" + day + "/" + getLongYear(year);
     else if (format == 10)
       str = day + "/" + month + "/" + shortyear;
     else if (format == 11)
       str = day + "/" + month + "/" + getLongYear(year);
     else if (format == 12)
       str = shortyear + "/" + month + "/" + day;
     else if (format == 13)
       str = shortyear + "/" + month + "/" + day;
     else {
        if (day < 10) day = "0"+day
        if (month < 10) month = "0"+month
        if (format == 14)
          str = month + "/" + day + "/" + shortyear;
        else if (format == 15)
          str = month + "/" + day + "/" + getLongYear(year);
        else if (format == 16)
          str = day + "/" + month + "/" + shortyear;
        else if (format == 17)
          str = day + "/" + month + "/" + getLongYear(year);
        else if (format == 18)
          str = shortyear + "/" + month + "/" + day;
        else if (format == 19)
          str = shortyear + "/" + month + "/" + day;
        }
     }
  document.writeln(str);
}

function writeDate()
{
   writeDateLong(0);
}

function writeTimeLong(format)
{
   d = new Date();
   hour=d.getHours();
   min=d.getMinutes();
   sec=d.getSeconds();
   if (hour < 10) hour = "0"+hour;
   if (min < 10) min = "0"+min;
   if (sec < 10) sec = "0"+sec;
   
   if (format == 0)
      str = hour+":"+min+":"+sec;
   else if (format == 1)
      str = hour+":"+min;
   
   document.writeln(str);
}

function writeTime()
{
   writeTimeLong(0);

};

// FUNÇÃO PARA ABRIR E FECHAR AS TABELAS
//========================================

var on = new Image(1,1);
var off = new Image(1,1);

function TrocaJanela(pstrJanela,pstrImagem)
{
	{
	off.src = "img/setax.gif";
	on.src = "img/seta.gif";
	};

lElemento = document.getElementById(pstrJanela);
lElemento.style.display = (lElemento.style.display==''?'none':'');


lElemento = document.getElementById(pstrImagem);
if (document.all[pstrJanela].style.display=='none')
	{document.all(pstrImagem).src = on.src;};
else
   	{document.all(pstrImagem).src = off.src;};

};


// FUNÇÃO PARA ACENDER OS MENUS
//=============================

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();};
  };


// FUNÇÃO MUDAR A COR DA LINHA
// ===========================
function Clica(id1,CorClk1,CorClk2,id2){
lElemento1 = document.getElementById(id1);
lElemento2 = document.getElementById(id2);

	if(lElemento1.checked==true)
		{lElemento2.bgColor = CorClk1;}
	else
		{lElemento2.bgColor = CorClk2;}

};
// ===========================

// FUNÇÃO PARA ALTERAR STATUS
// ==========================

var checkflag = "false";
function check(field){
    if (checkflag == "false") {
        for (i = 0; i < field.length; i++) {
            field[i].checked = true;}
	    checkflag = "true";
	    return "Desativar"; }
    else {
        for (i = 0; i < field.length; i++) {
            field[i].checked = false; }
            checkflag = "false";
            return "   Ativar   "; }
};
// ===========================


// FUNÇÃO VERIFICA EXCLUSÃO 
// ========================

function VerExcluir(field){
    var X=0
    for (i = 0; i < field.length; i++) {
        if (field[i].checked == true){
            X=1}
    }
    if (X==1){
        var Resp = window.confirm ("Você escolheu excluir os registros selecionados. Para confirmar a exclusão escolha 'Ok' ou clique em 'Cancelar'.");
        if (Resp) {
            return true;}
        else {
            return false;}
    }
};
// ===========================


// FUNÇÃO PARA ABRIR JANELAS
// =========================

function Remote(LOCAL,ONDE,LARG,ALT) {
    var remote = null
    remote=window.open(LOCAL,ONDE,'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,menubar=no,width='+LARG+',height='+ALT)
};
// ===========================

// FUNÇÃO PARA ABRIR JANELAS PARA IMPRESSÃO
// ========================================

function RemoteImp(LOCAL,ONDE,LARG,ALT) {
    var remote = null
    remote=window.open(LOCAL,ONDE,'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no,width='+LARG+',height='+ALT)
};
// ===========================

// FUNÇÃO PARA NAVEGAR
// ===================

function Navegar(LOCAL) {
    	var remote = null
//	Obj1=document.getElementById(S1)
//	a=Obj1.Value
	remote=window.open(LOCAL,'_self')
};
// ===========================


// FUNÇÃO PARA NAVEGAR 2
// =====================

function MM_jumpMenu(targ,selObj,restore){ //v3.0
if (selObj.options[selObj.selectedIndex].value!=0){
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'")};
  if (restore) selObj.selectedIndex=0;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
};

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
};
// =====================

// FUNÇÃO FECHAR JANELA E RETORNAR A NAVEGAÇÃO PARA A DE BAIXO
// ===========================================================

function VoltarURL(URL){
	opener.document.location = URL;
	window.close();
};
// =====================

// Validar formulários
// ===================

function valida(form){
    var X=0
    for (i = 0; i < form.length;++i) {
        var Campo=form[i].name;
		var Carac=Campo.substr(0,1) ;
        if (Carac == '@') {
		    if (form[i].value == '') {
                window.alert ("O campo "+ Campo +" é de preenchimento obribatório e não pode ficar em branco!.");form[i].focus();
                return false;
			};
		else {
	        return true;
	    	};
		};
    };
};
// ==============
