window.FuncoesGerais = {
	
	//abre um popup	
	popup : function(url,nome,medidas){
		window.open(url,nome,medidas);
	},
	
	//troca imagens do menu principal
	SwapMenu : function (name,image){
		document.images[name].src = image;
	},
	
	//esconde a div de imagem
	SomeImagem : function(objeto){
	    document.getElementById(objeto).style.display='none';
	},
	
	//busca parametro na url
	BuscaParametro : function (parametro){
		valor = '';
		parametros = window.location.search.substr(1);
		array_par = parametros.split('&');
		//loop passa pelo array de parametros para checar se existe o parametro solicitado
		for(c=0;c<array_par.length;c++){
			array_valor = array_par[c].split('=');
			if(array_valor[0]==parametro){
				valor = array_valor[1];
			}
		}
		return valor;
	},
	
	//mostra o nome da pagina atual
	RetornaNomePagina : function (){
		url = window.location.href;
		parametros = window.location.search;
		url = url.replace(parametros,'');
		url_array = url.split('/');
		url_tamanho = url_array.length;
		url_array2 = url_array[url_tamanho-1].split('#');
		return url_array2[0];
	},
	
	//mostra a url atual
	RetornaURL : function (){
		url = window.location.href;
		url_array = url.split('/');
		url_tamanho = url_array.length;
		return url_array[url_tamanho-1];
	},

	//tab automatico entre os campos
	tab_campo : function(nome_campo_ta,nome_campo_vai,tamanho){
		if (document.getElementById(nome_campo_ta).value.length>=tamanho)
			document.getElementById(nome_campo_vai).focus();
	},
	
	ismaxlength : function(obj, teste, mlength) {
		if (obj.getAttribute && obj.value.length>mlength)
			obj.value=obj.value.substring(0,mlength)

		if(arguments[1]){
			arguments[1].innerHTML = mlength - obj.value.length;
		}
	},
	
	Max_caracteres : function(txarea,limite,restante){
		tam = txarea.value.length; 
		str=""; 
		str=str+tam; 
		
		document.getElementById(restante).innerHTML = limite - tam
		
		if (tam > limite){ 
			aux = txarea.value; 
			txarea.value = aux.substring(0,limite); 
		} 
	},
	
	valida_copia : function(){
		if (navigator.userAgent.toLowerCase().indexOf('gecko/') == -1){
			var ctrl=window.event.ctrlKey;
			var tecla=window.event.keyCode;
			if (ctrl && tecla==86) {
				event.keyCode=0; 
				event.returnValue=false;
			}
		}
	},
	
	valida_dados_digitados : function(ponto,event){
		if(navigator.appName.indexOf("Netscape")!= -1) 
			tecla= event.which; 
		else 
			tecla= event.keyCode; 
  
		var ctrl=window.event.ctrlKey;
        var tecla=window.event.keyCode;
        
		if (ctrl && tecla!=86){
			event.keyCode=0;
			event.returnValue=false;
		}else if (tecla != '09'){
			var pKey = String.fromCharCode(tecla);
	
			if(navigator.appName.indexOf("Netscape")!= -1 && tecla==8)
			{
				return(true);
			}
			
			if (ponto==' '){
				var blnRet = ("0123456789".indexOf(pKey)>=0);
			}else if (ponto=='.'){
				var blnRet = ("0123456789.,".indexOf(pKey)>=0);
			}else if (ponto=='-'){
				var blnRet = ("0123456789-".indexOf(pKey)>=0);
			}else if (ponto=='/'){
				var blnRet = ("0123456789/".indexOf(pKey)>=0);
			}
		}
		
		return(blnRet);
	},
	
	//valida preenchimento de radio button
	ValidaRadio : function(campo){
	
		tamanho = campo.length;
		valor = 0;
		for(c=0;c<tamanho;c++){
			if(campo[c].checked)
				valor = 1;
		}
		
		return valor;
	
	},
	
	//retorna radio button selecionado
	RetornaValorRadio : function(campo){
	
		tamanho = campo.length;
		valor = '';
		for(c=0;c<tamanho;c++){
			if(campo[c].checked)
				valor = campo[c].value;
		}
		
		return valor;
	
	},
	
	SelecionaValorRadio : function(campo,valor){
	
		tamanho = campo.length;
		for(c=0;c<tamanho;c++){
			if(campo[c].value ==valor ){
				campo[c].checked = true;
				}
				
		}
		

	},
	
	//retorna check box selecionado
	RetornaValorCheckUnico : function(campo){
		valor = 0;
		if(campo.checked)
			valor = 1;
				
		return valor;
	
	},
	
	//retorna check box selecionado
	RetornaValorCheck : function(campo){
		valor = '';
		if(campo.checked)
			valor = campo.value;
				
		return valor;
	
	},
	
	//Retorna o valor de todos os checks concatenados
	RetornaCheckConcatenado : function(campo){
		str_concatenada = '';
		

		for(i=0;i<campo.length;i++){
			if(campo[i].checked){
				str_concatenada+=campo[i].value; 
			    str_concatenada+= ' / ';
			}
		}
	return str_concatenada; 	
	},
	
	//substitui valor nulo por zero
	TrocaVazio : function(valor){
	
		if (valor=='')
			return 0;
		else if(isNaN(valor))
			return 0;
		else
			return valor;
	},
	
	//valida preenchimento de e-mail
	ValidaEmail : function(email){
	
		if ((email.indexOf("@") == -1) || (email.indexOf(".") == -1))
			return 0;
		else
			return 1;
	
	},
	
	//valida preenchimento de data
	ValidaDataSeparada : function(dia,mes,ano){
	
		retorno=1;
		if(dia=='' || mes=='' || ano==''){
			retorno=0;
		}else if(isNaN(dia) || isNaN(mes) || isNaN(ano)){
			retorno=0;
		}else if(dia<1 || dia>31){
			retorno=0;
		}else if(mes<1 || mes>12){
			retorno=0;
		}else if(ano<1900 || ano>3000){
			retorno=0;
		}
	
		return retorno;
	},
	
	//formata data para o padro sql
	FormataData : function(dia,mes,ano){
		if (dia=='' || mes=='' || ano=='')
			data = '1900-1-1';
		else
			data  = ano + '-' + mes + '-' + dia;
		return data;
	},
	
	//carrega combo de estados	
	CarregaEstado : function(){
		Class_cidades.carregaestados(this.CarregaEstado_CallBack);
	},
	
	//carrega combo de estados
	CarregaEstado_CallBack : function(response){
		if(response.error == null){
			nomecampoestado = document.getElementById("NomeCampoEstado").value;
			var retorno = response.value;
			var ds = retorno;
			if(ds!=null && typeof(ds) == "object" && ds.Tables!=null){
				//define a quantidade de itens do dropdown(1 a mais da quantidade de itens do dataset)
				document.getElementById(nomecampoestado).length =ds.Tables[0].Rows.length+1;
				
				//adiciona um item no dropdown
				document.getElementById(nomecampoestado).options[0].text= 'Selecione';
				document.getElementById(nomecampoestado).options[0].value= '';
				
				//adiciona os itens do dataset no dropdown
				for(var i=0; i<ds.Tables[0].Rows.length; i++){
					var row = ds.Tables[0].Rows[i];
					document.getElementById(nomecampoestado).options[i+1].text= row.uf;
					document.getElementById(nomecampoestado).options[i+1].value= row.uf;
				}
			} 
		}	
	},
	
	//carrega combo de estados
	CarregaEstadoNSelecione : function(){
		Class_cidades.carregaestados(this.CarregaEstado_CallBackNSelecione);
		this.CarregaCidade('AC');
	},
	
	//carrega combo de estados
	CarregaEstado_CallBackNSelecione : function(response){
		if(response.error == null){
			nomecampoestado = document.getElementById("NomeCampoEstado").value;
			var retorno = response.value;
			var ds = retorno;
			if(ds!=null && typeof(ds) == "object" && ds.Tables!=null){
				//define a quantidade de itens do dropdown(1 a mais da quantidade de itens do dataset)
				document.getElementById(nomecampoestado).length =ds.Tables[0].Rows.length;
				
				//adiciona os itens do dataset no dropdown
				for(var i=0; i<ds.Tables[0].Rows.length; i++){
					var row = ds.Tables[0].Rows[i];
					document.getElementById(nomecampoestado).options[i].text= row.uf;
					document.getElementById(nomecampoestado).options[i].value= row.uf;
				}
			} 
		}	
	},
	
	//carrega combo de cidades
	CarregaCidade : function(estado){
		if(estado.length==2)
		Class_cidades.Seleciona(estado,0,this.CarregaCidade_CallBack);
	},
	
	valida_dados_digitados : function(ponto,event){
		if(navigator.appName.indexOf("Netscape")!= -1) 
			tecla= event.which; 
		else 
			tecla= event.keyCode; 
  
		var pKey = String.fromCharCode(tecla);
	
		if(navigator.appName.indexOf("Netscape")!= -1 && tecla==8)
		{
			return(true);
		}
		
		if (ponto==' '){
			var blnRet = ("0123456789".indexOf(pKey)>=0);
		}else if (ponto=='.'){
			var blnRet = ("\/:*?<>. '".indexOf(pKey)<0);
		}else if (ponto=='-'){
			var blnRet = ("0123456789-".indexOf(pKey)>=0);
		}else if (ponto=='/'){
			var blnRet = ("0123456789/".indexOf(pKey)>=0);
		}
		return(blnRet);
	},
	
	//carrega combo de cidades
	CarregaCidade_CallBack : function(response){
		if(response.error == null){ 
			nomecampocidade = document.getElementById("NomeCampoCidade").value;
			var retorno = response.value;
			var ds = retorno;
			
			if(ds!=null && typeof(ds) == "object" && ds.Tables!=null){
				//define a quantidade de itens do dropdown(1 a mais da quantidade de itens do dataset)
				document.getElementById(nomecampocidade).length =ds.Tables[0].Rows.length;
				
				//adiciona os itens do dataset no dropdown
				for(var i=0; i<ds.Tables[0].Rows.length; i++){
					var row = ds.Tables[0].Rows[i];
					document.getElementById(nomecampocidade).options[i].text= row.cidade;
					document.getElementById(nomecampocidade).options[i].value= row.cidade;
				}
			} 
		} 
	
	},
	
	//Funo para validao de CPF
	checaCPF : function(field){
	var cpf = '';
	var digito = '';
	var temp = '';
	var i = 0;
	var j = 0;
	var soma = 0;
	var mt = 0;
	var dg = 0;

	if (field == '')  
	{
		return false; 
	}   
	else
	{
		cpf = field;
	} 
  
  
	for(j = 0; j < cpf.length; j++) 
	{
		if (cpf.charAt(j)>= '0' && cpf.charAt(j) <= '9') temp += cpf.charAt(j);
	}
	cpf = temp;
	if (cpf.length != 11) 
	{
		return false;
	}

	// Testa se o CPF no tem todos os dgitos repetidos.
	if((cpf%11111111111) == 0)
	return false;

	cpf = temp.substring(0,9);
	digito = temp.substring(9,11);
	for (j = 1; j <= 2; j++) 
	{
		soma = 0;
		mt = 2;
		for (i = 8 + j; i >= 1; i--) 
		{
			soma += parseInt(cpf.charAt(i-1),10) * mt;
			mt++;
		}
		dg = 11 - (soma % 11);
		if (dg > 9) {dg = 0};
		cpf += dg;
	}
	
	if (digito != cpf.substring(9,11)){
		return false;}
	else{
		return true;}
	},
	//Fim da Funo para validao de CPF
	
	
	AlteraDisplay : function(elemento,status){
		document.getElementById(elemento).style.display = status;
	},
	
	AlteraTexto : function(elemento,texto){
		document.getElementById(elemento).innerHTML = texto;
	},
	
	SomaTexto : function(elemento,texto){
		document.getElementById(elemento).innerHTML += texto;
	},
	
	AlteraCorFundo : function(elemento,cor){
		document.getElementById(elemento).style.backgroundColor = cor;
	},
	
	AlteraClasse : function(elemento,classe){
		document.getElementById(elemento).className = classe;
	},
	
	AlteraSrc : function(elemento,src){
		document.getElementById(elemento).src = src;
	},
	
	AssinalaChecks : function(elemento,valor){
		Checks = document.getElementById(elemento).getElementsByTagName('input');
		quantidade = Checks.length;
		for(a=0;a<quantidade;a++){
			if(Checks[a].value==valor)
				Checks[a].checked = true;
		}
	},
	
	
	apagaCombos : function(){
		drops = document.body.getElementsByTagName('select');
		for(c=0;c<drops.length;c++){
			drops[c].style.visibility='hidden';
		}
	},
	
	
	reexibeCombos : function(box){
		if (document.getElementById(box)) {
			drops = document.getElementById(box).getElementsByTagName('select');
		}else {
			drops = document.body.getElementsByTagName('select');
		}
		for(c=0;c<drops.length;c++){
			drops[c].style.visibility='visible';
		}
	},
	

	
	ValidaChecks : function(elemento){
		Checks = document.getElementById(elemento).getElementsByTagName('input');
		quantidade = Checks.length;
		for(a=0;a<quantidade;a++){
			if(Checks[a].checked==true)
				return 1;
		}
		return 0;
	},
	
	ConcatenaChecks : function(elemento){
		Checks = document.getElementById(elemento).getElementsByTagName('input');
		quantidade = Checks.length;
		ValorFinal = '';
		for(a=0;a<quantidade;a++){
			if(Checks[a].checked==true){
				if(ValorFinal=='')
					ValorFinal = Checks[a].value;
				else
					ValorFinal += ',' + Checks[a].value;
			}
		}
		return ValorFinal;
	},
	
	CarregaDropCidade : function(estado,objeto){
		if(estado!=''){
			response = Class_cidades.Seleciona(estado,0);
			if(response.error == null){
				objeto.length = 0;
				var retorno = response.value;
				var ds = retorno;
				if(ds!=null && typeof(ds) == "object" && ds.Tables!=null){
					//define a quantidade de itens do dropdown(1 a mais da quantidade de itens do dataset)
					objeto.length =ds.Tables[0].Rows.length+1;
					
					//adiciona um item no dropdown
					objeto.options[0].text= 'Selecione';
					objeto.options[0].value= '';
					
					//adiciona os itens do dataset no dropdown
					for(var i=0; i<ds.Tables[0].Rows.length; i++){
						var row = ds.Tables[0].Rows[i];
						objeto.options[i+1].text= row.cidade;
						objeto.options[i+1].value= row.cidade;
					}
				} 
			}
		}
	},
	
	CarregaFlash : function(caminho,largura,altura,wmode){
		document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' + largura + '" height="' + altura + '" id="index" align="middle">');
		document.write('<param name="allowScriptAccess" value="sameDomain" />');
		document.write('<param name="allowFullScreen" value="false" />');
		document.write('<param name="scale" value="noscale" />');
		document.write('<param name="movie" value="' + caminho + '" />');
		document.write('<param name="quality" value="high" />');
		document.write('<param name="bgcolor" value="#fdc861" />');
		document.write('<param name="wmode" value="' + wmode + '">');
		document.write('<embed src="' + caminho + '" quality="high" wmode="' + wmode + '" scale="noscale" bgcolor="#fdc861" width="' + largura + '" height="' + altura + '" name="index" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
		document.write('</object>');
	},
	
	CarregaFlashDiv : function(caminho,largura,altura,wmode,div){
		var conteudo = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' + largura + '" height="' + altura + '" id="carrossel" align="middle">';
		conteudo += '<param name="allowScriptAccess" value="sameDomain" />';
		conteudo += '<param name="allowFullScreen" value="false" />';
		conteudo += '<param name="movie" value="'+caminho+'">';
		conteudo += '<param name="quality" value="high">';
		conteudo += '<param name="scale" value="noscale">';
		conteudo += '<param name="wmode" value="' + wmode + '">';
		conteudo += '<param name="menu" value="false">';
		conteudo += '<embed src="' + caminho + '" quality="high" wmode="' + wmode + '" scale="noscale" bgcolor="#ffffff" width="' + largura + '" height="' + altura + '" name="destaquePrincipal" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		conteudo += '</object>';
		this.AlteraTexto(div,conteudo);
	},
	

	monta_paginacao : function(tot_itens, itens_pg, pg_atual, arquivo, funcao, id_item){
		paginas = Math.ceil(tot_itens / itens_pg);
		conteudo = '';

		if (paginas <= 1){
			document.getElementById('paginacao').style.display = 'none';
		}else{
			if (pg_atual <= paginas){
				for (cont=0; cont<paginas; cont++){
					nummostra = cont+1;
					
					if (nummostra == pg_atual){
						nummostra = '<b>'+nummostra+'</b>';
					}
					
					conteudo += '<a href="javascript:'+arquivo+'.'+funcao+'('+id_item+','+nummostra+', 3);" id="num_'+nummostra+'">'+nummostra+'</a>';
				}
				document.getElementById('paginacao').innerHTML = conteudo;
				document.getElementById('paginacao').style.display = '';
			}
		}
		
		return paginas;
	}

}