
function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function


function janelacentralizada(pagina, nomedajanela, w, h) {

 var winl = (screen.width - w) / 2;
 var wint = (screen.height - h) / 2;
 winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',status=no,scrollbars=yes,resizable=no,menubar=no'
 
 win = window.open(pagina, nomedajanela, winprops)
     
 if (parseInt(navigator.appVersion) >= 4) { 
         win.window.focus(); 
     }

}


function janelaposicao(pagina, nomedajanela, w, h, x, y) {

  winprops = 'height='+h+',width='+w+',top='+x+',left='+y+',status=no,scrollbars=yes,resizable=no,menubar=no'
 
 win = window.open(pagina, nomedajanela, winprops)
     
 if (parseInt(navigator.appVersion) >= 4) { 
         win.window.focus(); 
     }

}


function estaVazio(strEntrada){
	strEntrada = trim(strEntrada);
	if ((strEntrada == null) || (strEntrada == "")) {
		return true
	}
	return false
}
	

function emailCorreto(mailField){
  strMail = mailField.value;
  var re = new RegExp;
  re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  var arr = re.exec(strMail);
  if (arr == null)
    return(false);
  else
    return(true);
}

function minimoTam(txtField, minVal){
  strExp = txtField.value;
  l = strExp.length;
  if (l < minVal)
    return(true);
  else
    return(false);
}

function maximoTam(txtField, maxVal){
  strExp = txtField.value;
  l = strExp.length;
  if (l > maxVal)
    return(true);
  else
    return(false);
}

function campoBranco(txtField){
  if (txtField.value)
    return (false);
  else
    return(true);
}

function itemSelecionado(txtField){
  selected = txtField.selectedIndex;
  if (selected == 0)
    return(true);
  else
    return(false);
}

function ehNumero(txtField){
  numExp = txtField;
  if (isNaN(numExp) || (numExp.length == 0))
    return (false);
  else
    return(true);
}



function ehCPF(txtField){ 

  var i; 
  s = txtField;  
  var c = s.substr(0,9); 
  var dv = s.substr(9,2); 
  var d1 = 0; 
  
  for (i = 0; i < 9; i++){ 
    d1 += c.charAt(i)*(10-i); 
  } 
  
  if (d1 == 0) return false;   
  
  d1 = 11 - (d1 % 11); 
  
  if (d1 > 9) d1 = 0; 
  
  if (dv.charAt(0) != d1) return false; 
  
  d1 *= 2; 
  
  for (i = 0; i < 9; i++){ 
    d1 += c.charAt(i)*(11-i);   
  } 
  
  d1 = 11 - (d1 % 11); 
  
  if (d1 > 9) d1 = 0; 
  
  if (dv.charAt(1) != d1) return false; 
  
  return true; 
  
}

function ExibeHora() {
	agora = new Date();
	horas = agora.getHours();
	minutos = agora.getMinutes();
	segundos = agora.getSeconds();

	if (horas < 10){
		horas = "0" + horas;
		}

	if (minutos < 10){
		minutos = "0" + minutos;
		}
		
	if (segundos < 10){
		segundos = "0" + segundos;
		}


// Hora com segundos
document.write(horas+":"+minutos+":"+segundos)
// setTimeout("ExibeHora()",1000);
// se quiser que a hora vá sendo atualizada devemos usar o código acima
// porem esta dando um erro, e tem que exibir no mesmo documento
// está criando outro ?!!

// Hora sem segundos
// document.write(horas+":"+minutos)

}

function ExibeDia(){

	meses = new Array();
	meses[0]="Janeiro";	
	meses[1]="Fevereiro";
	meses[2]="Março";
	meses[3]="April";
	meses[4]="Maio";
	meses[5]="Junho";
	meses[6]="Julho";
	meses[7]="Agosto";
	meses[8]="Setembro";
	meses[9]="Outubro";
	meses[10]="Novembro";
	meses[11]="Dezembro";
	
	
	dias= new Array();
	dias[0]="Domingo";
	dias[1]="Segunda-feira";
	dias[2]="Terça-feira";
	dias[3]="Quarta-feira";
	dias[4]="Quinta-feira";
	dias[5]="Sexta-feira";
	dias[6]="Sábado";
	
	hoje = new Date();
	
	diames = hoje.getDate();
		
	diasem = dias[hoje.getDay()];
	
	
	mes = meses[hoje.getMonth()];
	
	ano = hoje.getFullYear();
	
	// gmt = today.toGMTString();
	// exp = gmt;
	
	
	data =  diasem + ", " + diames + " de " + mes + " de " + ano;

	document.write(data);

}




