// JavaScript Document
function abreFoto(url, w, h){
	esquerda = (window.screen.width-w)/2;
	topo = (window.screen.height-h)/2;
	window.open("../admin/foto.php?url="+url, "_blank","left=" + esquerda + ",top=" + topo + ",width="+w+",height="+h+",resizable=no,status=no,scrollbars=no");
}

function abreLinkExterno(url)
{
	window.open(url, "_blank","");
}

//abre uma pagina dentro do IFrame indicado (local)
function abrePaginaIFrame(url,local)
{
	if (local != "")
	{
		document.getElementById(local).src = url;
	}
}

//abre uma pagina normalmente
function abrePagina(url)
{
	window.location.href= url;
	return false;
}

function pertence_imagem(item, array){
	for(i=0; i<array.length; i++){
		if (item == url2name(array[i])){
			return i;
		}
	}
	return -1;
}

function url2name(url){
	aux = url.split("/");
	pos = aux.length-1;
	return aux[pos];
}

function abreJanelaHelp(urlhelp){
	var winhelp = new Window({id: "winhelp", className: "alphacube", title: "Help on-line", top:26, left:30, width:520, height:300, 
							 url: urlhelp, showEffectOptions: {duration:1.5}}) 
	winhelp.setDestroyOnClose();
	winhelp.show();
}


//abre uma janela de pesquisa de itens
function abreJanelaPesquisa(url)
{
	esquerda = (window.screen.width-620)/2;
	topo = (window.screen.height-400)/2;
	window.open(url, "_blank","left=" + esquerda + ",top=" + topo + ",width=620,height=400,resizable=no,status=no,scrollbars=no");
}


//Abre a popup de erro
function abreJanelaErro(url)
{
	esquerda = (window.screen.width-550)/2;
	topo = (window.screen.height-200)/2;
	window.open(url, "popuperro","left=" + esquerda + ",top=" + topo + ",width=550,height=200,resizable=no,status=no,scrollbars=auto");
	//window.showModalDialog(url,"popuperro","dialogHeight: 150px; dialogWidth: 550px; dialogTop: " + topo + "px; dialogLeft: "+ esquerda +"px; edge: Raised; center: Yes; help: no; resizable: no; status: no; scrool: no;");
}

//para exclusao de registros com confirmacao
function excluirRegistro(url)
{
	if (confirm("Tem certeza que deseja excluir?"))
		abrePagina(url);
}

function soInteiro(event)
{
	return soNumeroInteiro(event);
}

function soReal(event)
{
	return soNumeroReal(event);
}


/**
*   Função que insere linhas em uma tabela
*
*   @param	String propriedade id da "<table>" onde as linhas serão inseridas
*   @param	String id do Objeto "Object_<NomeEntidade>" que esta sendo utilizado
*   @param	String propriedade nome do objeto para o "<input type='hidden'>"
*   @param	Array  valores das colunas da linha a ser inserida
*	@author Fabiano Damin
*/
function inserirLinhaTabela(idTabela,idObjeto,nomeIdObjeto,valoresColunas)
{
	if (!procurarItemTabela(idTabela,nomeIdObjeto + idObjeto))
	{
		var tabela = document.getElementById(idTabela).tBodies[0];
		var coluna = null;	
		var checkbox = document.createElement('input');
		var hidden = document.createElement('input');
		var linha = document.createElement('tr');
		checkbox.type = "checkbox";
		//Aqui o id do checkbox é setado para o item não ser readicionado na lista
		checkbox.id = nomeIdObjeto + idObjeto;
		hidden.type = "hidden";
		hidden.name = nomeIdObjeto + "[]";
		hidden.value = idObjeto;
		linha.id = "linha";
		for (var i=0; i<valoresColunas.length; i++)
		{
			coluna = document.createElement('td');
			if (trim(valoresColunas[i]) == "")
			{
				valoresColunas[i] = "-";	
			}
			coluna.appendChild(document.createTextNode(valoresColunas[i]));
			if ((i == 1) || (i == 2))
			{
				coluna.align = "right";	
			}
			linha.appendChild(coluna);
		}
		coluna = document.createElement('td');
		coluna.id = "check";
		coluna.appendChild(hidden);
		coluna.appendChild(checkbox);
		linha.appendChild(coluna);
		tabela.appendChild(linha);
		return true;
	}
	else
	{
		alert("Este item já foi inserido!");
		return false;
	}
}

/**
*   Função que remove linhas com o checkbox marcado de uma tabela
*
*   @param	String propriedade id da "<table>" onde as linhas serão removidas
*	@param	String id a ser procurado no "<input type='checkbox'>" da tabela
*	@author Fabiano Damin
*/
function procurarItemTabela(idTabela,id)
{
	var i = null;
	var j = null;
	var colunas = null;
	var tabela = document.getElementById(idTabela).tBodies[0];
	linhas = tabela.rows;
	for (i=0; i<linhas.length; i++)
	{
		colunas = linhas[i].cells;
		for (j=0; j<colunas.length; j++)
		{
			if (colunas[j].id == "check")
			{
				if (colunas[j].lastChild.id == id)
				{
					return true;
				}
			}	
		}
	}
	return false;
}

/**
*   Função que remove linhas com o checkbox marcado de uma tabela
*
*   @param	String propriedade id da "<table>" onde as linhas serão removidas
*	@author Fabiano Damin
*/
function removerLinhaTabela(idTabela)
{
	var i = null;
	var j = null;
	var colunas = null;
	var tabela = document.getElementById(idTabela).tBodies[0];
	linhas = tabela.rows;	
	for (i=0; i<linhas.length; i++)
	{
		colunas = linhas[i].cells;
		for (j=0; j<colunas.length; j++)
		{
			if (colunas[j].id == "check")
			{
				if (colunas[j].lastChild.checked == true)
				{
					tabela.deleteRow(i);
					removerLinhaTabela(idTabela);
					return false;
				}
			}	
		}
	}
}

function removerLinhaTabelaIframe(iframe,idTabela)
{
	var i = null;
	var j = null;
	var colunas = null;
	var tabelaiframe = iframe.document.getElementById(idTabela).tBodies[0];
	var tabela = document.getElementById(idTabela).tBodies[0];	
	linhas = tabela.rows;	
	for (i=0; i<linhas.length; i++)
	{
		colunas = linhas[i].cells;
		for (j=0; j<colunas.length; j++)
		{
			if (colunas[j].id == "check")
			{
				if (colunas[j].lastChild.checked == true)
				{
					tabela.deleteRow(i);
					tabelaiframe.deleteRow(i);
					removerLinhaTabelaIframe(iframe,idTabela);
					return false;
				}
			}	
		}
	}
}

function removerLinhaTabelaDiv(idTabela)
{
	var i = null;
	var j = null;
	var colunas = null;
	var tabelaDiv = document.getElementById(idTabela+"0").tBodies[0];
	var tabela = document.getElementById(idTabela).tBodies[0];	
	linhas = tabela.rows;	
	for (i=0; i<linhas.length; i++)
	{
		colunas = linhas[i].cells;
		for (j=0; j<colunas.length; j++)
		{
			if (colunas[j].id == "check")
			{
				if (colunas[j].lastChild.checked == true)
				{
					tabela.deleteRow(i);
					tabelaDiv.deleteRow(i);
					removerLinhaTabelaDiv(idTabela);
					return false;
				}
			}	
		}
	}
}

/**
*   Função que remove todas as linhas de uma tabela identificadas por um id
*
*   @param	String propriedade id da "<table>" onde as linhas serão removidas
*	@author Fabiano Damin
*/
function removerLinhas(idTabela)
{
	var i = null;
	var colunas = null;
	var tabela = document.getElementById(idTabela).tBodies[0];
	linhas = tabela.rows;	
	for (i=0; i<linhas.length; i++)
	{
		if (linhas[i].firstChild.nodeName == "TD")
		{
			tabela.deleteRow(i);
			removerLinhas(idTabela);
			return false;
		}
	}
}

function removerLinhasIframe(iframe,idTabela)
{
	var i = null;
	var colunas = null;
	var tabela = document.getElementById(idTabela).tBodies[0];
	var tabelaiframe = iframe.document.getElementById(idTabela).tBodies[0];	
	linhas = tabela.rows;	
	for (i=0; i<linhas.length; i++)
	{
		tabela.deleteRow(i);
		tabelaiframe.deleteRow(i);			
		removerLinhasIframe(iframe,idTabela);
		return false;
	}
}

function removerLinhasDiv(idTabela)
{
	var i = null;
	var colunas = null;
	var tabela = document.getElementById(idTabela).tBodies[0];
	var tabelaDiv = document.getElementById(idTabela+"0").tBodies[0];
	linhas = tabela.rows;	
	for (i=0; i<linhas.length; i++)
	{
		tabela.deleteRow(i);
		tabelaDiv.deleteRow(i);			
		removerLinhasDiv(idTabela);
		return false;
	}
}


function mostraAba(idAbaSel)
{
	var i = 1;

	while ((aba = document.getElementById("aba" + i)) != null)
	{
		aba.className = "aba";
		document.getElementById("aba" + i + "Conteudo").style.display = "none";
		i++;
	}

	document.getElementById(idAbaSel).className = "abaSel";
	document.getElementById(idAbaSel + "Conteudo").style.display = "";
}

///  ******************************* ///
///  **********   MANU  ************ ///
///  ******************************* ///

//FUNCAO QUE VERIFICA SE OS CAMPOS DE UM FORMULARIO ESTAO PREENCHIDOS
function verificaFormulario(formulario,vetor)
{
	var pForm = 0;
	var pVet = 0;
	while (formulario.elements[pForm] != null)
	{
		if ((formulario.elements[pForm].type == "text") || (formulario.elements[pForm].type == "password") || (formulario.elements[pForm].type == "textarea"))
			formulario.elements[pForm].value = trim(filtrarTexto(trim(formulario.elements[pForm].value)));		
		if (formulario.elements[pForm].name == vetor[pVet])
		{
			if ((formulario.elements[pForm].type == "text") || (formulario.elements[pForm].type == "password"))
				if (formulario.elements[pForm].value == "")
				{
					alert("O campo '"+ vetor[pVet+1] + "' não pode ser nulo!");
					formulario.elements[pForm].focus();
					return false;
				}
			if (formulario.elements[pForm].type == "select-one")
				if (formulario.elements[pForm].value == "0")
				{
					alert("O campo '"+ vetor[pVet+1] + "' não pode ser nulo!");
					formulario.elements[pForm].focus();
					return false;
				}
			pVet = pVet + 2;
		}
		pForm++;
	}
	return true;
}

//FAZ A MASCARA DO CNPJ - "##.###.###/####-##"
//EM TEMPO DE "DIGITACAO" --- mascaraCnpj(<nomedoformulario>.<nomedocampo>, event);
function mascaraCnpj(cnpj, e)
{
	if (navigator.appName.indexOf("Microsoft")!= -1) 
		tecla= event.keyCode;
	else
  		tecla = e.which;
	if (tecla == 8)
		return false;
	
    var mycnpj = cnpj.value;

	switch (mycnpj.length)
	{
		case 2:
		case 6:
		{
			mycnpj = mycnpj + '.'; 
			cnpj.value = mycnpj;
		} break;
		case 10:
		{
			mycnpj = mycnpj + '/'; 
			cnpj.value = mycnpj;
		} break;
		case 15:
		{
			mycnpj = mycnpj + '-'; 
			cnpj.value = mycnpj;
		} break;
	}
}

//FAZ A MASCARA DO CEP -- "###.###-###"
function mascaraCep(cep, e)
{
	if(navigator.appName.indexOf("Microsoft")!= -1) 
		tecla= event.keyCode;
	else
  		tecla= e.which;
	if (tecla == 8)
		return false;
	
    var mycep = cep.value;
	
	switch (mycep.length)
	{
		case 2:
		{
			mycep = mycep + '.'; 
			cep.value = mycep;
		} break;		
		case 6:
		{
			mycep = mycep + '-'; 
			cep.value = mycep;
		} break;
	}
}



//FAZ A MASCARA DO TELEFONE - "(##) ####-####"
function mascaraTelefone(telefone, e)
{
	if(navigator.appName.indexOf("Microsoft")!= -1) 
		tecla= event.keyCode;
	else
  		tecla= e.which;
	if (tecla == 8)
		return false;
	
    var mytelefone = telefone.value;
	
	switch (mytelefone.length){
		case 4:{
			mytelefone = mytelefone + '-'; 
			telefone.value = mytelefone;
		}break;
	}
}

//FAZ A MASCARA DO CPF - "###.###.###-##"
function mascaraCpf(cpf, e)
{
	if(navigator.appName.indexOf("Microsoft")!= -1) 
		tecla= event.keyCode;
	else
  		tecla= e.which;
	if (tecla == 8)
		return false;
	
    var mycpf = cpf.value;
	
	switch (mycpf.length)
	{
		case 3:
		{
			mycpf = mycpf + '.'; 
			cpf.value = mycpf;
		} break;		
		case 7:
		{
			mycpf = mycpf + '.'; 
			cpf.value = mycpf;
		} break;		
		case 11:
		{
			mycpf = mycpf + '-'; 
			cpf.value = mycpf;
		} break;		
	}
}

//FAZ A MASCARA DO RG - "###.###.###/#"
function mascaraRg(rg, e)
{
	if(navigator.appName.indexOf("Microsoft")!= -1) 
		tecla= event.keyCode;
	else
  		tecla= e.which;
	if (tecla == 8)
		return false;
	
    var myrg = rg.value;
	
	switch (myrg.length)
	{
		case 3:
		{
			myrg = myrg + '.'; 
			rg.value = myrg;
		} break;		
		case 7:
		{
			myrg = myrg + '.'; 
			rg.value = myrg;
		} break;		
		case 11:
		{
			myrg = myrg + '/'; 
			rg.value = myrg;
		} break;		
	}
}

//FAZ A MASCARA DE DATA - "##/##/####"
function mascaraData(data,e)
{
	if(navigator.appName.indexOf("Microsoft")!= -1) 
		tecla= event.keyCode;
	else
  		tecla= e.which;
	if (tecla == 8)
		return false;
	
    var mydata = data.value;
	
	switch (mydata.length)
	{
		case 2:
		{
			mydata = mydata + '/'; 
			data.value = mydata;
		} break;		
		case 5:
		{
			mydata = mydata + '/'; 
			data.value = mydata;
		} break;		
	}
}

//Verificar esta função!!
function validaCpf(cpf)
{
	return true;
/*	if (trim(cpf.value) == "")
		return true;
	var numeros, digitos, soma, i, resultado, digitos_iguais;
	digitos_iguais = 1;
	if (cpf.length < 11)
	{
		return false;
	}
	for (i = 0; i < cpf.length - 1; i++)
	{
		if (cpf.charAt(i) != cpf.charAt(i + 1))
		{
			digitos_iguais = 0;
			break;
		}
	}
	if (!digitos_iguais)
	{
		numeros = cpf.substring(0,9);
		digitos = cpf.substring(9);
		soma = 0;
		for (i = 10; i > 1; i--)
		{
			soma += numeros.charAt(10 - i) * i;
		}
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(0))
		{
			return false;
		}
		numeros = cpf.substring(0,10);
		soma = 0;
		for (i = 11; i > 1; i--)
		{
			soma += numeros.charAt(11 - i) * i;
		}
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(1))
		{
			return false;
		}
		return true;
	}
	else
	{
		return false;
	}*/
}

//VALIDA O CNPJ JA COM A MASCARA -- validaCnpj(<nomedoformulario>.<campo>.value)
function validaCnpj(campo)
{
	return true;
	CNPJ = campo.value;
	erro = new String;
	if (CNPJ.length < 18)
		erro = "CNPJ Inválido!";
	if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-"))
		if (erro.length == 0)
			erro = "CNPJ Inválido!";
	//substituir os caracteres que não são números
	if(document.layers && parseInt(navigator.appVersion) == 4)
	{
		x = CNPJ.substring(0,2);
		x += CNPJ. substring (3,6);
		x += CNPJ. substring (7,10);
		x += CNPJ. substring (11,15);
		x += CNPJ. substring (16,18);
		CNPJ = x;
	}
	else
	{
	   CNPJ = CNPJ. replace (".","");
	   CNPJ = CNPJ. replace (".","");
	   CNPJ = CNPJ. replace ("-","");
	   CNPJ = CNPJ. replace ("/","");
	}
	var nonNumbers = /\D/;
	if (nonNumbers.test(CNPJ))
		erro = "CNPJ Inválido!";
	var a = [];
	var b = new Number;
	var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
	for (i=0; i<12; i++)
	{
	   a[i] = CNPJ.charAt(i);
		b += a[i] * c[i+1];
	}
	if ((x = b % 11) < 2)
		a[12] = 0
	else
		a[12] = 11-x
	b = 0;
	for (y=0; y<13; y++)
	   b += (a[y] * c[y]);
	if ((x = b % 11) < 2)
		a[13] = 0;
	else
		a[13] = 11-x;
	if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13]))
	   erro ="CNPJ Inválido!";
	if (erro.length > 0)
	{
	   alert('CNPJ Inválido!');
	   campo.focus();
	   return false;
	}
	return true;
}



function validaCep(campo)
{
	if ((campo.value.length < 10) && (trim(campo.value) != ""))
	{
		alert("CEP Inválido!");
		campo.focus();
		return false;
	}
	return true;
}

function validaIP(campo){
	IPvalue = campo.value;
	errorString = "";

	var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
	var ipArray = IPvalue.match(ipPattern); 

	if (IPvalue == "0.0.0.0")
		errorString = IPvalue+' é um IP especial que não pode ser usado!';
	else if (IPvalue == "255.255.255.255")
		errorString = IPvalue+' é um IP especial que não pode ser usado!';
	if (ipArray == null)
		errorString = IPvalue+' não é um IP Válido!';
	else {
		for (i = 0; i <= 4; i++) {
			thisSegment = ipArray[i];
				if (thisSegment > 255) {
					errorString = IPvalue+' não é um IP Válido!';
					break;
				}
   		}
	}
	extensionLength = 3;
	if (errorString != ""){
		campo.focus();
		alert(errorString);
		return false;
	}
	return true;
}


function validaMAC(campo){
	MACvalue = campo.value;
	valid = '0123456789abcdefABCDEF';
	errorString = "";
	//00-0A-E6-D4-A1-C5
	//00-0D-87-C3-C3-59
	var macArray = MACvalue.split("-");
	if (macArray == null){
		errorString = MACvalue+' não é um MAC Válido (null)!';
	}else {
		for (i = 0; i <= 5; i++) {
			thisSegment = macArray[i];
			if(macArray.length == 6){
				if(valid.indexOf(thisSegment.charAt(0)) < 0 || valid.indexOf(thisSegment.charAt(1)) < 0){
					errorString = MACvalue+' não é um MAC Válido,'+thisSegment[0]+' elementos não hexadecimais!';
					break;
				}
			}else{
				errorString = MACvalue+' não é um MAC Válido, número de segmenos diferente de 6!';
				break;
			}
				
		 }
	}
	if (errorString != ""){
		campo.focus();
		alert(errorString);
		return false;
	}
	return true;
}



function validaEmail(campo)
{
	if (campo.value == "")
	{
		return true;
	} else {
		prim = campo.value.indexOf("@")
		if(prim < 2) {
			alert("E-mail inválido!");
			campo.focus();
			campo.select();
			return false;
		}
		if(campo.value.indexOf("@",prim + 1) != -1) {
			alert("E-mail inválido!");
			campo.focus();
			campo.select();
			return false;
		}
		if(campo.value.indexOf(".") < 1) {
			alert("E-mail inválido!");
			campo.focus();
			campo.select();
			return false;
		}
		if(campo.value.indexOf(" ") != -1) {
			alert("E-mail inválido!");
			campo.focus();
			campo.select();
			return false;
		}
		if(campo.value.indexOf("zipmeil.com") > 0) {
			alert("E-mail inválido!");
			campo.focus();
			campo.select();
			return false;
		}
		if(campo.value.indexOf("hotmeil.com") > 0) {
			alert("E-mail inválido!");
			campo.focus();
			campo.select();
			return false;
		}
		if(campo.value.indexOf(".@") > 0) {
			alert("E-mail inválido!");
			campo.focus();
			campo.select();
			return false;
		}
		if(campo.value.indexOf("@.") > 0) {
			alert("E-mail inválido!");
			campo.focus();
			campo.select();
			return false;
		}
		if(campo.value.indexOf(".com.br.") > 0) {
			alert("E-mail inválido!");
			campo.focus();
			campo.select();
			return false;
		}
		if(campo.value.indexOf("/") > 0) {
			alert("E-mail inválido!");
			nform.email.focus();
			nform.email.select();
			return false;
		}
		if(campo.value.indexOf("[") > 0) {
			alert("E-mail inválido!");
			nform.email.focus();
			nform.email.select();
			return false;
		}
		if(campo.value.indexOf("]") > 0) {
			alert("E-mail inválido!");
			nform.email.focus();
			nform.email.select();
			return false;
		}
		if(campo.value.indexOf("(") > 0) {
			alert("E-mail inválido!");
			campo.focus();
			campo.select();
			return false;
		}
		if(campo.value.indexOf(")") > 0) {
			alert("E-mail inválido!");
			campo.focus();
			campo.select();
			return false;
		}
		if(campo.value.indexOf("..") > 0) {
			alert("E-mail inválido!");
			campo.focus();
			campo.select();
			return false;
		}
	}
	return true;
}

/*
function validaEmail(componente) 
{
    if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(componente.value)) 
        return(true);
    alert("Email inválido!");
    componente.focus();
    return (false);
}
*/
function validaTelefone(campo)
{
	//if (campo.value.length == 14 || campo.value.length == 0)
		return true;
	//alert("Telefone Inválido!");
	//campo.focus();
	//return false;
}

//Eliminar espaços em branco na esquerda e na direita
function trim(valor)
{
	var aux = "";
	var s = valor;
	var i = 0;
	while ((i < s.length) && (s.charAt(i) == " "))
	{
		i++;
	}
	for (i=i; i<s.length; i++)
	{
		aux = aux + s.charAt(i);
	}
	i = aux.length - 1;
	s = "";
	while ((i >= 0) && (aux.charAt(i) == " "))
	{
		i--;
	}
	for (j=0; j<=i; j++)
	{
		s = s + aux.charAt(j);
	}
	return(s);
}

function filtrarTexto(dado) 
{
	var aux = '';
	var caracteresValidos = "áàãäâÁÀÃÄÂéèêëÉÈÊËìíîïÌÍÎÏòóôõöÒÓÔÕÖùúûüÙÚÛÜýÝçÇñÑ ,./!@#$%&_-+={}:;|<>´`";
	for (i=0; i<=dado.length-1; i++) 
	{
		c = dado.charAt(i);
		if ((c == "(") || (c == ")") || (c == "[") || (c == "]") || (c == "?") || (c == "*") || (c == "+"))
			result = 1;
		else
			if (c == '\\')
				result = -1;
			else
				result = caracteresValidos.search(c);
		if ( (c < '0' || c > '9') && (c < 'A' || c > 'Z') && (c < 'a' || c > 'z') && (result < 0)) 
			c = "";
		else
			aux = aux + c;
	}
	return aux;
}

function soNumeroInteiro(e) {
	var charCode;
	var ret;
	if(navigator.appName.indexOf("Microsoft")!= -1) 
		charCode = event.keyCode;
	else
  		charCode = e.which;
	if (((charCode >= 48) && (charCode <= 57)) || (charCode == 8) || (charCode == 9) || (charCode == 127) || (charCode == 16) || (charCode == 17) || (charCode == 0))
	{
		return true;
	}
	return false;
}

function soNumeroReal(e) {
	var charCode;
	if(navigator.appName.indexOf("Microsoft")!= -1) 
		charCode= event.keyCode;
	else
  		charCode= e.which;
		
	if (((charCode >= 48) && (charCode <= 57)) || (charCode == 8) || (charCode == 9) || (charCode == 127) || (charCode == 16) || (charCode == 17) || (charCode == 0) || (charCode == 46))
	{
		return true;
	}
	return false;
}

//funcao para validar os campos obrigatorios da tela
// 	necessita um vetor de strings "vtCampos" declarado
//	com os IDs dos campos que sao obrigatorios
function validaCampos()
{
	var resultado = true;

	for (i=0;i<vtCampos.length;i++)
	{
		if (document.getElementById(vtCampos[i]).value == "")
		{
			resultado = false;
		}
	}
	return resultado;
}

//------------------funcao para validar uma data--------------------
//------------------------------------------------------------------
function validardata(p_data) 
{    
	if (p_data != "")
	{                
		barra = p_data.indexOf("/");
		dia = p_data.substring(0,barra);
		string1 = p_data.substring(barra+1);
		barra = string1.indexOf("/");
		mes = string1.substring(0,barra);
		ano = string1.substring(barra+1);
		data = dia + mes + ano;
		if (data.length < 8) 
		{
     		return false;
		}
		if (dia > 31 || dia < 1)
		{
     		return false;
		}
		if (mes > 12 || mes < 1)
		{		
     		return false;
		}
		if (mes == 4 || mes == 6 || mes == 9 || mes == 11)
		{
			if (dia > 30)
			{
    			return false;
			}
		}
		if (mes == 02)
		{
			bis = (ano % 4 == 0 && (ano % 100 != 0 || ano % 400 == 0));
			if (dia>29 || (dia==29 && !bis))
			{
				return false;
			}
		}
        
        return true;
	}
    return false;
}


//------------------funcao para validar caracteres para um campo data--------------------
//------------------------------------------------------------------

function validaCaracterData(e){
    var charCode;
    var ret;
    if(navigator.appName.indexOf("Microsoft")!= -1) 
        charCode = event.keyCode;
    else
        charCode = e.which;
    if (((charCode >= 48) && (charCode <= 57)) || (charCode == 8) || (charCode == 9) || (charCode == 127) || (charCode == 16) || (charCode == 17) || (charCode == 0))
    {
        return true;
    }
    return false;
}

function validaHora(hora){
 		if(hora.value.length > 0){
			if(hora.value.length == 2 && hora.value.substr(0,2) <= 23 || isNaN(hora.value.substr(0,2))){
				hora.value = hora.value + ":00";
				return true;
			}else{
				if(hora.value.length < 5){
					alert("Formato da hora inválido.\n Por favor, informe a hora no formato correto: hh:mm");
					hora.focus();
					return false
				}
				if(hora.value.substr(0,2) > 23 || isNaN(hora.value.substr(0,2))){
					alert("Formato da hora inválido.");
					hora.focus();
					return false
				}
				if(hora.value.substr(3,2) > 59 || isNaN(hora.value.substr(3,2))){
					alert("Formato do minuto inválido.");
					hora.focus();
					return false
				}
			}
		}
		return true;
 }

//------------------funcao para mascarar um campo data--------------------
//------------------------------------------------------------------

function mascaraData(campo,e){    

    if(navigator.appName.indexOf("Microsoft")!= -1) 
        tecla= event.keyCode;
    else
        tecla= e.which;

    if (tecla == 8)
        return false;

    var mydata = campo.value;

    switch (mydata.length){
        case 2: {
            mydata = mydata + '/'; 
            campo.value = mydata;
        } break;		

        case 5:{
            mydata = mydata + '/'; 
            campo.value = mydata;
        } break;		
    }        
}

function mascaraHora(campo,e){
    if(navigator.appName.indexOf("Microsoft")!= -1) 
        tecla= event.keyCode;
    else
        tecla= e.which;

    if (tecla == 8)
        return false;

    var myhora = campo.value;

    switch (myhora.length){
        case 2: {
            myhora = myhora + ':'; 
            campo.value = myhora;
        } break;		

        case 5: {
            myhora = myhora + ':'; 
            campo.value = myhora;
        } break;		
    }        
}


function pontoParaVirgula(objeto){
    return objeto.value.replace(',','.');                                                                             
}


function maximoCarateres(object, max_length){															 
    if (object.value.length >= max_length) {					
        window.event.keyCode=0;					
        object.value = object.value.substring(0,max_length);					
    }			
}

var isIE = document.all?true:false;
var isNS = document.layers?true:false;

function converteMaiscula(){
    var key = (isIE) ? window.event.keyCode : e.which;	    		
    if(isIE){
        window.event.keyCode= String.fromCharCode(key).toUpperCase().charCodeAt(0);
    }else{
        e.which	= String.fromCharCode(key).toUpperCase().charCodeAt(0);			
    }		
}