function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

//==========================================================================================================================
// Função Ajax 
//==========================================================================================================================
function ajaxInit()  //Inicia a biblioteca para funcionar o AJAX
{
	var req;
	try
    {
	    req = new ActiveXObject("Microsoft.XMLHTTP");
	}

        catch(e)
        {
  	        try
            {
	            req = new ActiveXObject("Msxml2.XMLHTTP");
	        }

            catch(ex)
            {
	            try
                {
		            req = new XMLHttpRequest();
		        }

                catch(exc)
		        {
		            alert("Esse Navegador não tem recursos para uso do Ajax! Atualize seu Navegador!");
		            req = null;
		        }
            }
        }

	return req;
}
//==========================================================================================================================
// Escreve a data por extenso

hoje = new Date()
dia  = hoje.getDate()
dias = hoje.getDay()
mes  = hoje.getMonth()
ano  = hoje.getYear()

if (dia < 10){dia = "0" + dia}

function CriaArray (n) {this.length = n }

NomeDia    = new CriaArray(7)
NomeDia[0] = "Domingo"
NomeDia[1] = "Segunda-feira"
NomeDia[2] = "Terça-feira"
NomeDia[3] = "Quarta-feira"
NomeDia[4] = "Quinta-feira"
NomeDia[5] = "Sexta-feira"
NomeDia[6] = "Sábado"

NomeMes    = new CriaArray(12)
NomeMes[0] = "Janeiro"
NomeMes[1] = "Fevereiro"
NomeMes[2] = "Março"
NomeMes[3] = "Abril"
NomeMes[4] = "Maio"
NomeMes[5] = "Junho"
NomeMes[6] = "Julho"
NomeMes[7] = "Agosto"
NomeMes[8] = "Setembro"
NomeMes[9] = "Outubro"
NomeMes[10] = "Novembro"
NomeMes[11] = "Dezembro"

//=================================================================================== 
function EscreveData()
	{document.write(", " + dia + " de " + NomeMes[mes] + " de " + ano)}

//=================================================================================== 
function popup(pagina,nome,altura,largura,top,left,scroll,toolbar,location,menu,resize) 
{
	var janela;
	var top = (screen.height - altura) / 2;
	var left = (screen.width  - largura) / 2; 
	
	if (altura == 0){
		top = 0;
		altura = screen.height;
	}
	if (largura == 0){
		left = 0; 
		largura = screen.width;
	}
	
	janela = window.open(pagina,nome,'width='+largura+',height='+altura+',top='+top+',left='+left+',scrollbars='+scroll+',toolbar='+toolbar+',location='+location+',menubar='+menu+',resizable='+resize);
	janela.focus();
}

//=================================================================================== 
function limita (campo, tamanhomaximo){
	var tamanho = (campo.value.length);
	var tex = campo.value;
	if (tamanho >= tamanhomaximo) 
	{campo.value=tex.substring(0,tamanhomaximo-1);}
		return true;}

//=================================================================================== 	
function contacampo(campoIN, campoOUT, tamanhomaximo) {
	var campoIN = campoIN;
	var campoOUT = campoOUT;	
	campoOUT.value = tamanhomaximo - campoIN.value.length;}

//===================================================================================
function isDigit(pchar) {
    return ("0123456789,.".indexOf(pchar)>=0);}

//=================================================================================== 		
function isNumeric(ptexto) {
    var numeric = true;
    for (i=0; i < ptexto.length; i++) {
        if (!isDigit(ptexto.charAt(i)) ) {
            numeric = false;
            break; } }
    return numeric;}
    
//=================================================================================== 
function isNumericInt(campo) {
	var t = 0;
	for(cont=0;cont<campo.length;cont++){
		if(campo.charAt(cont) != "0" && campo.charAt(cont) != "1" && campo.charAt(cont) != "2" && campo.charAt(cont) != "3" && campo.charAt(cont) != "4" && campo.charAt(cont) != "5" && campo.charAt(cont) != "6" && campo.charAt(cont) != "7" && campo.charAt(cont) != "8" && campo.charAt(cont) != "9")
			{return (false);}}
	return (true);}
//=================================================================================== 
function isDate (strCheck) {
	if (strCheck.length > 0) {
		if (strCheck.indexOf('-') > 0) { // formato y-m-d
			var iCheckYear = parseInt(strCheck.substring(0, strCheck.indexOf('-')), 10);
			var strCheck = strCheck.substring(strCheck.indexOf('-') + 1);
			var iCheckMonth = parseInt(strCheck.substring(0, strCheck.indexOf('-')), 10);
			var strCheck = strCheck.substring(strCheck.indexOf('-') + 1);
			var iCheckDay = parseInt(strCheck.substring(0), 10);
		} else if (strCheck.indexOf('/') > 0) { // formato d/m/y
			var iCheckDay = parseInt(strCheck.substring(0, strCheck.indexOf('/')), 10);
			var strCheck = strCheck.substring(strCheck.indexOf('/') + 1);
			var iCheckMonth = parseInt(strCheck.substring(0, strCheck.indexOf('/')), 10);
			var strCheck = strCheck.substring(strCheck.indexOf('/') + 1);
			var iCheckYear = parseInt(strCheck.substring(0), 10);
		} else if (strCheck.length == 8) { // formato yyyymmdd
			var iCheckYear = parseInt(strCheck.substring(0, 4), 10);
			var iCheckMonth = parseInt(strCheck.substring(4, 6), 10);
			var iCheckDay = parseInt(strCheck.substring(6, 8), 10);
		}
		// correcao para padrao de mes das funcoes de data do javascript (de 0 a 11)
		iCheckMonth--;
		// para considerar dia 29 de fevereiro, ja que o ano 2000 eh bisexto
		var dteValue = new Date(iCheckYear, iCheckMonth, iCheckDay);
		if (iCheckDay == dteValue.getDate()) {
			if (iCheckMonth == dteValue.getMonth()) {
				if (iCheckYear == dteValue.getYear()) {
					return true;
				}
			}
		}
	}
	return false;
}
//=================================================================================== 	
	function abre_pagina(larg,altu,pagi){
  largura = screen.width;
  altura = screen.height;
  poshor = (largura - larg) / 2;
  posver = (altura - altu) / 2;
  comando = "window.open('" + pagi + "','nova','top=" + posver + ",scrollbars=yes,resizable=no,left=" + poshor + ",width=" + larg + ",height=" + altu + "');";
  eval(comando);
}
