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 validarNome(nome) {
	validos = 'qazwsxedcrfvtgbyhnujmikolp1234567890_-';
	pos = 0;
	
	nome = nome.toLowerCase();                         
	if (trim(nome) == '') 
	{
		return false;
	}
	
	for (var indice = 0; indice < nome.length; indice++) 
	{
		pos = 0;
		for (var indiceI = 0; indiceI < validos.length; indiceI++) 
		{
			if (nome.charAt(indice) == validos.charAt(indiceI)) 
			{
				pos++;
			}
		}
		if (pos == 0) 
		{
		  return false;
		}
	}
	return true;
}


// Função para validar Email
function validarEmailDominio(text)
{ 
  var    arroba = "@", 
		 ponto = ".", 
		 virgula = ",",
		 posponto = 0, 
		 posarroba = 0; 
  
  // testa se está vazio
  if (text =="") 
	 return false; 

  // Verifica se existe o simbolo '@' e sua posição
  for (var indice = 0; indice < text.length; indice++)
  { 
	 if (text.charAt(indice) == arroba) 
	 { 
		posarroba = indice; 
		break; 
	 } 
  } 

  // Verifica se existe o simbolo '.' e sua posição
  for (var indice = posarroba; indice < text.length; indice++)
  { 
	 if (text.charAt(indice) == ponto) 
	 { 
		posponto = indice; 
		break; 
	 } 
  } 
  
  // Verifica se existe o simbolo ',' e sua posição
  for (var indice = 0; indice < text.length; indice++)
  { 
	 if (text.charAt(indice) == virgula) 
	 { 
		return false;
		break; 
	 } 
  }
  
  // Verifica a posicão do simbolo '@' em relação  ao simbolo '.'
  if (posponto == 0) 
	 return false; 
  if (posponto == (posarroba + 1)) 
	 return false; 
  if ((posponto + 1) == text.length) 
	 return false; 
  
  return true; 
}

function validarData(Data){
	var err = 0;
	var string = Data;
	var valid = "0123456789/";
	var ok = "yes";

	for (var i=0; i<string.length; i++)
	{
		var temp = "" + string.substring(i, i+1);

		if (valid.indexOf(temp) == "-1")
			err = 1;
	}

	if (string.length != 10)
		err = 1;

	dia = string.substring(0, 2);
	barra1 = string.substring(2, 3);
	mes = string.substring(3, 5);
	barra2 = string.substring(5, 6);
	ano = string.substring(6, 10);
	
	if ((dia < 1) || (dia > 31))
		err = 1;
	if (barra1 != '/')
		err = 1;
	
	if ((mes < 1) || (mes > 12))
		err = 1;
	
	if (barra2 != '/')
		err = 1;
	
	if (ano < 0)
		err = 1;
	
	if (mes == 4 || mes == 6 || mes == 9 || mes == 11)
	{
		if (dia == 31)
			err = 1;
	}
	
	if (mes == 2)
	{
		var g = parseInt(ano/4);

		if (isNaN(g))
			err = 1;

		if (dia > 29)
			err = 1;

		if ((dia == 29) && (((ano/4) != parseInt(ano/4))))
			err = 1;
	}

	if (err == 1)
		return(false);
	else
		return(true);
}


function validarEmail(email) { 
	var arroba = "@", 
	ponto = ".", 
	posponto = 0, 
	posarroba = 0; 
  
  	// testa se está vazio
	if (email =="") return false; 

 	validos = 'qazwsxedcrfvtgbyhnujmikolp1234567890@._-';
	pos = 0;
	
	email = email.toLowerCase();                         
	for (var i = 0; i < email.length; i++) 
	{
		pos = 0;
		for (var j = 0; j < validos.length; j++) 
		{
			if (email.charAt(i) == validos.charAt(j)) 
			{
				pos++;
			}
		}
		if (pos == 0) 
		{
		  return false;
		}
	}
	
  	// Verifica se existe o simbolo '@' e sua posição
  	for (var indice = 0; indice < email.length; indice++)
  	{ 
	 	if (email.charAt(indice) == arroba) 
	 	{ 
			posarroba = indice; 
			break; 
	 	} 
  	} 

  	// Verifica se existe o simbolo '.' e sua posição
  	for (var indice = posarroba; indice < email.length; indice++)
  	{ 
		if (email.charAt(indice) == ponto) 
	 	{ 
			posponto = indice; 
			break; 
	 	} 
  	} 
 	// Verifica a posicão do simbolo '@' em relação  ao simbolo '.'
  	if (posponto == 0 || posarroba == 0) 	return false; 
  	if (posponto == (posarroba + 1)) 	return false; 
  	if ((posponto + 1) == email.length) 	return false; 
    
  	return true; 
}


function validarIP1(ip) {

  	validos = '01234567890.';
	
	contPonto = 0;
	
	ip = trim(ip.toLowerCase());                         
	
	for (var i = 0; i < ip.length; i++) 
	{
		pos = 0;

		if (ip.charAt(i) == '.') {
			contPonto++;
		}

		for (var j = 0; j < validos.length; j++) 
		{
			if (ip.charAt(i) == validos.charAt(j)) 
			{
				pos++;
			}
		}
		if (pos == 0) 
		{
		  return false;
		}
	}
	
	if (contPonto != 3) {
		return false;
	}
	
	reIP = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;


	if (!reIP.test(ip)) {
		return false;
	}
	
	return true;
}


function validarIP(IPvalue) {
	errorString = ""; 
	theName = "IPaddress"; 

	var ipArray=IPvalue.split(".");

	if (IPvalue == "0.0.0.0") 
  		//errorString = erroralert('rere');
  		return true;
		
	else if (IPvalue == "255.255.255.255") 
  		//errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.(5)'; 
		return false;
	if (!ipArray||!ipArray[0]||!ipArray[1]||!ipArray[2]||!ipArray[3]||ipArray.length>4) 
  		//errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.(1)'; 
		return false;
	else { 
		for (i = 0; i < 4; i++) { 
    		thisSegment = ipArray[i]; 
    		if (thisSegment > 255) { 
      			//errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.(2)'; 
				return false;
      			i = 4; 
    		} 
    		if ((i == 0) && (thisSegment > 255)) { 
      			//errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.(3)'; 
				return false;
      			i = 4; 
    		} 
  		} 
	} 
	extensionLength = 3; 

  	return true; 
} 


function validarPorta(porta) {
	
	porta = trim(porta.toLowerCase());
	
	validos = '1234567890';
	
	for (var i = 0; i < porta.length; i++) 
	{
		pos = 0;

		for (var j = 0; j < validos.length; j++) 
		{
			if (porta.charAt(i) == validos.charAt(j)) 
			{
				pos++;
			}
		}
		if (pos == 0) 
		{
		  return false;
		}
	}
	
	return true;
}


function sairSistema() {
	document.forms[0].acao.value = 'SAIR';
	document.forms[0].submit();
}
	
function mensagem(texto) {
	
	browsername = navigator.appName;
	
	if (browsername == 'Microsoft Internet Explorer') {
		window.open("../home/mensagem.php?mensagem=" + texto + "","Mensagem","scrollbars=no,left=300,top=300,width=300,height=122");
	} else {
		window.open("../home/mensagem.php?mensagem=" + texto + "","Mensagem","scrollbars=no,screenX=300,screenY=300,width=300,height=122");
	}
}

function validarCamposDominio(campo) {

	campo = trim(campo.toLowerCase());	
	
	if (campo == '-1') {
		
		return true;
	}

	if ((campo.charAt(0) == '0') && (campo.length > 1)) {
	
		return false;
	}
	
	validos = '0123456789';
	
	for (var i = 0; i < campo.length; i++) 
	{
		pos = 0;

		for (var j = 0; j < validos.length; j++) 
		{
			if (campo.charAt(i) == validos.charAt(j)) 
			{
				pos++;
			}
		}
		if (pos == 0) 
		{
		  return false;
		} 
	}
	
	if (pos != 0)
		return true;
		
	return false;
}

function validarNumero(campo) {

	campo = trim(campo);
	
	validos = '0123456789';
	
	for (var i = 0; i < campo.length; i++) 
	{
		pos = 0;

		for (var j = 0; j < validos.length; j++) 
		{
			if (campo.charAt(i) == validos.charAt(j)) 
			{
				pos++;
			}
		}
		if (pos == 0) 
		{
		  return false;
		} 
	}
	
	if (pos != 0)
		return true;
		
	return false;
}

function validarHora(campo) {

	if (validarNumero(campo)) {
		
		if (campo<0 || campo>23) {
			return false;
		} 
		
	} else {
		return false;
	}
	
	return true;

}

function validarMinuto(campo) {

	if (validarNumero(campo)) {
		
		if (campo<0 || campo>59) {
			return false;
		} 
		
	} else {
		return false;
	}
	return true;
}


var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|co|uk|es)$/;

function validarDominio(FormField,NoWWW,CheckTLD) {
	// NoWWW y CheckTLD son opcionales, ambos aceptan los valores true, false, y null.
	// NoWWW se utiliza para verificar que un nombre de dominio no comience con 'www.', ejem. para WHOIS.
	DomainName=FormField.value.toLowerCase();
	if (CheckTLD==null) {CheckTLD=true}
	var specialChars="/\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var atom=validChars + '+';
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=DomainName.split(".");
	var len=domArr.length;
	if (len==1) { FormField.focus(); return false}
	for (i=0;i<len;i++) {if (domArr[i].search(atomPat)==-1) { FormField.focus(); return false}}
	if ((CheckTLD) && (domArr[domArr.length-1].length!=2) && (domArr[domArr.length-1].search(knownDomsPat)==-1)) { FormField.focus(); return false}
	if ((NoWWW) && (DomainName.substring(0,4).toLowerCase()=="www.")) { FormField.focus(); return false}
	return true;
}

function FSfncValidateEmailAddress (FormField,CheckTLD) {
	// CheckTLD es opcionalis optional, acepta los valores true, false, y null.
	emailStr = FormField.value.toLowerCase()
	if (CheckTLD==null) {CheckTLD=true}
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {alert(FormField.title + " parece ser incorrecta (Compruebe arroba (@) y puntos (.))"); FormField.focus(); FormField.focus(); return false}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {if (user.charCodeAt(i)>127) {alert(FormField.title + ": nombre de usuario contiene caracteres inválidos"); return false}}
	for (i=0; i<domain.length; i++) {if (domain.charCodeAt(i)>127) {alert(FormField.title + ": nombre de dominio contiene caracteres inválidos"); FormField.focus(); return false}}
	if (user.match(userPat)==null) {alert(FormField.title + ": nombre de usuario no es válido."); FormField.focus(); return false}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {for (var i=1;i<=4;i++) {if (IPArray[i]>255) {alert(FormField.title + ": dirección IP no es válida"); FormField.focus(); return false}}; return true}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {if (domArr[i].search(atomPat)==-1) {alert(FormField.title + ": nombre de dominio no es válido."); FormField.focus(); return false}}
	if ((CheckTLD) && (domArr[domArr.length-1].length!=2) && (domArr[domArr.length-1].search(knownDomsPat)==-1)) {alert(FormField.title + ": debe terminar en dominio bien conocido o país de dos letras."); FormField.focus(); return false}
	if (len<2) {alert(FormField.title + ": le falta un nombre de anfitrión"); FormField.focus(); return false}
	return true;
}

function marcarLista(objeto) {

	srcLen = objeto.options.length;
	if (srcLen != 0) {
		for (var x=0; x<srcLen; x++) 
		{
			objeto.options[x].selected="true";
		}
	}
}

function desmarcarLista(objeto) {

	srcLen = objeto.options.length;
	if (srcLen != 0) {
		for (var x=0; x<srcLen; x++) 
		{
			objeto.options[x].selected="false";
		}
	}
}

function retornaExtensao(imagem) 
{
	tam = imagem.length;
	imagem = imagem.toLowerCase();
	extensao = imagem.substring(tam-3,tam);

	return extensao;   
}

// Retorna se a extensao é valida ou não para ser inserido no banco
function validarImagem(imagem) 
{

	varExt = new Array();
	varExt [0] = "gif";
	varExt [1] = "png";
	varExt [2] = "jpg";
	varExt [3] = "jpeg";
	
	extensao = retornaExtensao(imagem);
	for (k=0; k < 5; k++) {
	   if (extensao == varExt[k]) {
		  return true;
	   }
	}
	return false;
}




//------------ Para rearrumar -------------------
function textCounter(field,maxlimit)
{
  if (field.value.length > maxlimit) // if too long...trim it! 
  { field.value = field.value.substring(0, maxlimit); }
}
//--------------------------------
function isNum( caractere,charFormat )
{
  var charlib="";
  if (charFormat==0)  // Moeda
    { charlib=","; }
  else if (charFormat==1)  // CEP/Telefone
    { charlib="-"; }
  else if (charFormat==2)  // Hora
    { charlib=":"; }
  else if (charFormat==3)  // Data
    { charlib="/"; }
  if (charFormat==4)  // Número entre 0 e 9
    { charlib=""; }
  if (charFormat==5)  // Quant
    { charlib=","; }
  if (charFormat.length>1)  // Definiu a limitação
    { charlib=charFormat; }

  var strValidos = charlib+"0123456789"
  if ( strValidos.indexOf( caractere ) == -1 ) return false;
  return true;
}
//--------------------------
function validaNum(campo, event, charFormat)
{
  var BACKSPACE= 8;
  var key;
  var tecla;

  CheckTAB=true;
  if(navigator.appName.indexOf("Netscape")!= -1)
    tecla= event.which;
  else
    tecla= event.keyCode;
  if ( tecla == 46 && charFormat==5 )
  {
    if(navigator.appName.indexOf("Netscape")!= -1)
      event.which=44;
    else
      event.keyCode=44;
    tecla=44;
  }
  key = String.fromCharCode( tecla);
  if ( tecla == 13 ) { return false; }
  if ( tecla == BACKSPACE ) return true;
  return ( isNum(key,charFormat));
}
//--------------------------
var AgntUsr=navigator.userAgent.toLowerCase();
//---------------------------
function CarregaCombo() {
	var cont=1;
	var aux="";
	var id="";
	var id2="";
	var cons="";
	var cmb="";

	gurl=arguments[0];
	while(cont < arguments.length) {		
	  if(cont!=1) { sep=":-)"; } else { sep=""; }
		id=id+sep+arguments[cont];
		cont++;
		id2=id2+sep+arguments[cont];
		cont++;
		cons=cons+sep+arguments[cont];
		cont++;
		cmb=cmb+sep+arguments[cont];
  	remove_tudo(arguments[cont]);
		cont++;
	}
	var aux="http://www.acbeubahia.org.br/sis/utcombo.asp?"+aux;
	
	var NavYes=AgntUsr.indexOf('mozilla')!=-1&&AgntUsr.indexOf('compatible')==-1?1:0;
	c_iframe=NavYes? document.getElementById("sframe") : document.all.sframe

	aux=aux+"id="+id+
	"&id2="+id2+
	"&cons="+cons+
	"&cmb="+cmb;
	
	c_iframe.src=aux;	
}
//---------------------------
function adiciona(texto,valor,objeto) {
	
	linha = document.createElement("OPTION");
	linha.text = texto;
	linha.value = valor;
	document.forms[0].elements[objeto].options.add(linha);
}
//---------------------------
function remove_tudo(objeto) { //Limpa a combo
	var tam = document.forms[0].elements[objeto].length;
	while( tam > 0 ) { document.forms[0].elements[objeto].remove(tam-1); 	tam--;	}
}
//---------------------------
function PegaValor() {
	var cont=1;
	var aux="";
	var id="";
	var id2="";
	var cons="";
	var obj="";
	var vdef="";

	gurl=arguments[0];
	while(cont < arguments.length) {		
	  if(cont!=1) { sep=":-)"; } else { sep=""; }
		id=id+sep+arguments[cont];
		cont++;
		id2=id2+sep+arguments[cont];
		cont++;
		cons=cons+sep+arguments[cont];
		cont++;
		obj=obj+sep+arguments[cont];
		cont++;
  	vdef=vdef+sep+arguments[cont];
//alert(vdef);
		cont++;
	}
  var aux=gurl+"/sis/utbusca.asp?"+aux;
	
	var NavYes=AgntUsr.indexOf('mozilla')!=-1&&AgntUsr.indexOf('compatible')==-1?1:0;
	c_iframe=NavYes? document.getElementById("sframe") : document.all.sframe

	aux=aux+"id="+id+
	"&id2="+id2+
	"&cons="+cons+
	"&obj="+obj+
	"&vdef="+vdef;
	c_iframe.src=aux;	
}
//---------------------------
function SetaCampo(valor,objeto) 
{
	while(valor.indexOf('<br>')!=-1)
	{ valor=valor.replace( "<br>", "\n" ); }
	
	if(objeto=="lblidade") {
	  	document.all[objeto].innerHTML = valor;

		//-- Habilita | Desabilita campos
		Obrigatorios();

	}else{
		document.forms[0].elements[objeto].value=valor; 
		if(objeto=="tipotabela") { EnabledTipo(); }
	
	}
	
}
//---------------------------
function Obrigatorios(){
  	valor = document.all["lblidade"].innerHTML;
	idade = valor.split(" ");
	asterisco="";
	asteriscomenor="*";

	if(typeof(document.all["lblMENOR1"])!="undefined" && typeof(document.all["omesmo"])!="undefined"){
		if(ConverteVal(idade[0]) >=18){ //maior
			/*
			document.all["nomeresp"].id = MudaId(0,document.all["nomeresp"].id);
			document.all["DTNASCRESPONS"].id = MudaId(0,document.all["DTNASCRESPONS"].id);
			document.all["RGRESPONSAVEL"].id = MudaId(0,document.all["RGRESPONSAVEL"].id);
			document.all["cpfresponsavel"].id = MudaId(0,document.all["cpfresponsavel"].id);
			document.all["e_mailresp"].id = MudaId(0,document.all["e_mailresp"].id);
			document.all["ve_mailresp"].id = MudaId(0,document.all["ve_mailresp"].id);
			document.all["ESTADOCIVILRESP"].id = MudaId(0,document.all["ESTADOCIVILRESP"].id);
			document.all["parentesco"].id = MudaId(0,document.all["parentesco"].id);
			document.all["CODOCUPACAORESP"].id = MudaId(0,document.all["CODOCUPACAORESP"].id);
			*/
			valorobriga = 0;
			if(document.all["omesmo"].value==0){
				valorobriga = 1;
				asteriscomenor="";
				asterisco="* ";
			}
			document.all["nomeresp"].id = MudaId(valorobriga,document.all["nomeresp"].id);
			document.all["DTNASCRESPONS"].id = MudaId(valorobriga,document.all["DTNASCRESPONS"].id);
			document.all["RGRESPONSAVEL"].id = MudaId(valorobriga,document.all["RGRESPONSAVEL"].id);
			document.all["cpfresponsavel"].id = MudaId(valorobriga,document.all["cpfresponsavel"].id);
			document.all["e_mailresp"].id = MudaId(valorobriga,document.all["e_mailresp"].id);
			document.all["ve_mailresp"].id = MudaId(valorobriga,document.all["ve_mailresp"].id);
			document.all["ESTADOCIVILRESP"].id = MudaId(valorobriga,document.all["ESTADOCIVILRESP"].id);
			document.all["parentesco"].id = MudaId(valorobriga,document.all["parentesco"].id);
			document.all["CODOCUPACAORESP"].id = MudaId(valorobriga,document.all["CODOCUPACAORESP"].id);
			if(typeof(document.all["rg"])!="undefined") {
				if(valorobriga==1){ 
					vo = 0; 
				} else {
					vo = 1; 
				}
				document.all["rg"].id = MudaId(vo,document.all["rg"].id);
				document.all["cpf"].id = MudaId(vo,document.all["cpf"].id);
			}
					
		}else{ //menor
			//document.all["omesmo"].value = 0;
			//habilitaResponsavel(); 
			
			asteriscomenor="";
			asterisco="* ";
			document.all["nomeresp"].id = MudaId(1,document.all["nomeresp"].id);
			document.all["DTNASCRESPONS"].id = MudaId(1,document.all["DTNASCRESPONS"].id);
			document.all["RGRESPONSAVEL"].id = MudaId(1,document.all["RGRESPONSAVEL"].id);
			document.all["cpfresponsavel"].id = MudaId(1,document.all["cpfresponsavel"].id);
			document.all["e_mailresp"].id = MudaId(1,document.all["e_mailresp"].id);
			document.all["ve_mailresp"].id = MudaId(1,document.all["ve_mailresp"].id);
			document.all["ESTADOCIVILRESP"].id = MudaId(1,document.all["ESTADOCIVILRESP"].id);
			document.all["parentesco"].id = MudaId(1,document.all["parentesco"].id);
			document.all["CODOCUPACAORESP"].id = MudaId(1,document.all["CODOCUPACAORESP"].id);
	
			if(typeof(document.all["rg"])!="undefined") {
				document.all["rg"].id = MudaId(0,document.all["rg"].id);
				document.all["cpf"].id = MudaId(0,document.all["cpf"].id);
			}
		}	
		
		for(x=1;x<10;x++){
			document.all["lblRESP"+x].innerHTML = asterisco;
		}	
	
		if(typeof(document.all["lblMENOR1"])!="undefined") {
			document.all["lblMENOR1"].innerHTML = asteriscomenor;		
		}	
		if(typeof(document.all["lblMENOR2"])!="undefined") {
			document.all["lblMENOR2"].innerHTML = asteriscomenor;		
		}
		
		if(document.all["cpfresponsavel"].value.length==14) { // Pessoa Jurídica
			document.all["DTNASCRESPONS"].id = MudaId(0,document.all["DTNASCRESPONS"].id);
			document.all["RGRESPONSAVEL"].id = MudaId(0,document.all["RGRESPONSAVEL"].id);
			document.all["ESTADOCIVILRESP"].id = MudaId(0,document.all["ESTADOCIVILRESP"].id);
			document.all["CODOCUPACAORESP"].id = MudaId(0,document.all["CODOCUPACAORESP"].id);
			document.all["lblRESP2"].innerHTML = "";
			document.all["lblRESP3"].innerHTML = "";
			document.all["lblRESP6"].innerHTML = "";
		}	
	}
	
}
//---------------------------
function ObrigatoriosBolsa(){
  	valor = document.all["lblidade"].innerHTML;
	idade = valor.split(" ");
	asterisco="";
	asteriscomenor="*";

	if(typeof(document.all["lblMENOR1"])!="undefined" && typeof(document.all["omesmo"])!="undefined"){
		if(ConverteVal(idade[0]) >=18){ //maior de idade
			valorobriga = 0;
			if(document.all["omesmo"].value==0){
				valorobriga = 1;
				asteriscomenor="";
				asterisco="* ";
			}
			document.all["nomeresp"].id = MudaId(valorobriga,document.all["nomeresp"].id);
			document.all["DTNASCRESPONS"].id = MudaId(valorobriga,document.all["DTNASCRESPONS"].id);
			document.all["RGRESPONSAVEL"].id = MudaId(valorobriga,document.all["RGRESPONSAVEL"].id);
			document.all["cpfresponsavel"].id = MudaId(valorobriga,document.all["cpfresponsavel"].id);
			document.all["e_mailresp"].id = MudaId(valorobriga,document.all["e_mailresp"].id);
			document.all["ve_mailresp"].id = MudaId(valorobriga,document.all["ve_mailresp"].id);
			document.all["ESTADOCIVILRESP"].id = MudaId(valorobriga,document.all["ESTADOCIVILRESP"].id);
			document.all["parentesco"].id = MudaId(valorobriga,document.all["parentesco"].id);
			document.all["CODOCUPACAORESP"].id = MudaId(valorobriga,document.all["CODOCUPACAORESP"].id);
			if(typeof(document.all["rg"])!="undefined") {
				if(valorobriga==1){ 
					vo = 0; 
				} else {
					vo = 1; 
				}
				document.all["rg"].id = MudaId(vo,document.all["rg"].id);
				document.all["cpf"].id = MudaId(vo,document.all["cpf"].id);
			}
					
		}else{ //menor de idade	
			asteriscomenor="";
			asterisco="* ";
			valorobriga = 1;
			if(document.all["omesmo"].value==1){
				asteriscomenor="* ";
				asterisco="";
				valorobriga = 0;
			}
			document.all["nomeresp"].id = MudaId(valorobriga,document.all["nomeresp"].id);
			document.all["DTNASCRESPONS"].id = MudaId(valorobriga,document.all["DTNASCRESPONS"].id);
			document.all["RGRESPONSAVEL"].id = MudaId(valorobriga,document.all["RGRESPONSAVEL"].id);
			document.all["cpfresponsavel"].id = MudaId(valorobriga,document.all["cpfresponsavel"].id);
			document.all["e_mailresp"].id = MudaId(valorobriga,document.all["e_mailresp"].id);
			document.all["ve_mailresp"].id = MudaId(valorobriga,document.all["ve_mailresp"].id);
			document.all["ESTADOCIVILRESP"].id = MudaId(valorobriga,document.all["ESTADOCIVILRESP"].id);
			document.all["parentesco"].id = MudaId(valorobriga,document.all["parentesco"].id);
			document.all["CODOCUPACAORESP"].id = MudaId(valorobriga,document.all["CODOCUPACAORESP"].id);
	
			if(typeof(document.all["rg"])!="undefined") {
				document.all["rg"].id = MudaId(0,document.all["rg"].id);
				document.all["cpf"].id = MudaId(0,document.all["cpf"].id);
			}
		}	
		
		for(x=1;x<10;x++){
			document.all["lblRESP"+x].innerHTML = asterisco;
		}	
	
		if(typeof(document.all["lblMENOR1"])!="undefined") {
			document.all["lblMENOR1"].innerHTML = ""; //asteriscomenor;		
		}	
		if(typeof(document.all["lblMENOR2"])!="undefined") {
			document.all["lblMENOR2"].innerHTML = ""; //asteriscomenor;		
		}
		
		if(document.all["cpfresponsavel"].value.length==14) { // Pessoa Jurídica
			document.all["DTNASCRESPONS"].id = MudaId(0,document.all["DTNASCRESPONS"].id);
			document.all["RGRESPONSAVEL"].id = MudaId(0,document.all["RGRESPONSAVEL"].id);
			document.all["ESTADOCIVILRESP"].id = MudaId(0,document.all["ESTADOCIVILRESP"].id);
			document.all["CODOCUPACAORESP"].id = MudaId(0,document.all["CODOCUPACAORESP"].id);
			document.all["lblRESP2"].innerHTML = "";
			document.all["lblRESP3"].innerHTML = "";
			document.all["lblRESP6"].innerHTML = "";
		}	
	}
	
}
//---------------------------
function MudaId(id,valor){
  valid=valor.split(":");
	return valid[0]+":"+valid[1]+":"+id;
}
//---------------------------
function ValidaHora(CHora)
{
  //--CHora em formato HH:MM:SS
  if (CHora.value!="")
  {
		//hr = (CHora.value.substring(0,2));
		//min = (CHora.value.substring(3,5));

		var tmp=Chora.value.split(":");
		hora = tmp[0];
		minuto = tmp[1];

		
		situacao = 1;
		// verifica se a hora é válida
		if (hora < 00 || hora > 23 || hora.length<2)
		  { situacao = 0; }

		// verifica se o min e válido
		if (minuto < 00 || minuto > 59  || minuto.length<2)
		  { situacao = 0; }

		// verifica se e o segundo é válido
		//if (seg< 00 || seg > 59)
		//  { situacao = 0; }
		
		if (CHora.value == "")  { situacao = 0; }

		if (situacao == 0)
		{
		  alert("Hora inválida! Entre Hora no formato hh:mm"); //hh:mm:ss
		  CHora.focus();
		}
	}	
}
//-----------------------------------------
function ValidaCpfCnpj(CThis){
  var soma=0
  var Resto=0
  var x=0
  var st=CThis.value

	if (st.length==0){ // Vazio
    return (true); 
  }

	//verifica cpf/cnpj com valor repetido: Ex.: 1111111111111111, 2222222222222222222
	if(st.length!=0){
		dif=0;
		compara=st.substring(0,1);
		for(x=0;x<st.length;x++){
			if(st.substring(x,x+1)!=compara){
				dif=1;
			}
		}
  
		if(dif==0){
			if(st.length==14){
				alert("Formato inválido para \"CNPJ\". ");
			}else{
				alert("Formato inválido para \"CPF\". ");
			}
			CThis.value=""
			CThis.focus();
			return (false);
		}
  }
	  	
	
	if (st.length==11){ // CPF
    for (x = 1 ; x < 10 ; x++){
      soma=soma+parseInt(st.substring(x-1,x)) * (11 - x) 
		}
    Resto = 11 - (soma - (parseInt(soma / 11) * 11))
    if (Resto==10 || Resto==11) {Resto=0}
    if (parseInt(Resto)!=parseInt(st.substring(9, 10))) {
      alert("Formato inválido para \"CPF\". ");
      CThis.value=""
      CThis.focus();
      return (false);
    }
    soma = 0
    for (x = 1 ; x < 11 ; x++){ 
			soma=soma+parseInt(st.substring(x-1,x)) * (12 - x) 
		}
    Resto = 11 - (soma - (parseInt(soma / 11) * 11))
    if (Resto == 10 || Resto == 11) {Resto = 0}
    if (parseInt(Resto)!= parseInt(st.substring(10,11))) {
      alert("Formato inválido para \"CPF\". ");
      CThis.value=""
      CThis.focus();
      return (false);
    }
    return (true);

  }else if (st.length==14){ // CNPJ
    var Retorno=0
    var A=0
    var j=5
    var i=0
    var d1=0
    var d2=0
		
   for (x = 1; x < 13 ; x++)  {
     A = A + (parseInt(st.substring(x-1,x)) * j)
     if (j>2) {j = j - 1} else {j= 9}
   }
   A = A%11

   if (A>1) {d1 = 11 - A} else {d1 = 0}
   A = 0
   i = 0
   j = 6
    for (x = 1; x < 14 ; x++) {
      A = A + (parseInt(st.substring(x-1,x)) * j)
      if (j>2) {j = j - 1} else  {j= 9}
      }
    A = A % 11

    if(A >1 ) 
		{ d2=11-A; }
		else
		{ d2=0; }
		
    if (d1 == parseInt(st.substring(12, 13)) && d2 == parseInt(st.substring(13, 14))){
      return (true); 
		}else{
      alert("Formato inválido para \"CNPJ\". ");
      CThis.value=""
      CThis.focus();
      return (false);
		}
  }

  alert("Número de caracteres inválidos para \"CPF-CNPJ\". ");
  CThis.focus();
  return (false);
}
//--------------------------
function ConverteVal(numero){
  if ((numero==null) || (numero=='')) { numero = "0.00";  return numero;  }
  string_ponto = numero.toString()
  numero = numero.toString();
  var CTam=string_ponto.length;
  posicao_ponto = string_ponto.indexOf(",")
  if (posicao_ponto!= -1){
    numero = numero.replace("." , "");
    numero = numero.replace("," , ".");
  }
  return numero;
}
//-----------------------------------------
function abrirPopUp(url){
  	win = window.open(url,"ACBEU","toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=no,scrollbars=yes,left=0,top=0,width=800,height=600")
	win.focus();
}
//---------------------------
function abrirJanela(url){
  	win=window.open(url,"ACBEU","toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=yes,scrollbars=yes,left=0,top=0,width=800,height=600")
	win.focus();
}
//---------------------------
function abrirJanela2(url){
	win=window.open(url,"ACBEU","toolbar=yes,location=no,directories=no,status=yes,menubar=yes,resizable=yes,scrollbars=yes,left=0,top=0,width=800,height=600")
	win.focus();
}
//---------------------------
function abrirJanela3(url){
  	win=window.open(url,"ACBEU","toolbar=yes,location=no,directories=no,status=yes,menubar=no,resizable=yes,scrollbars=yes,left=0,top=0,width=800,height=600")
	win.focus();
}
//---------------------------
function difDatas(data1,data2){
	//Formato das datas em dd/mm/aaaa
	//Retorna a diferença em dias de 2 datas diferentes

	dt = data1.split("/");
	var data1 = new Date(dt[2],Math.floor(dt[1])-1,dt[0]);

	dt = data2.split("/");
	var data2 = new Date(dt[2],Math.floor(dt[1])-1,dt[0]);
	
	var diferenca = data2.getTime() - data1.getTime();
	var diferenca = Math.floor(diferenca / (1000 * 60 * 60 * 24));
	return diferenca;
}
//-----------------------------
function setFoco(field) {
	try{
		field.focus();
	}catch(e){          
	}

}
