﻿// ==============================================================================================================
//   Ajax.js - Biblioteca para Funcoes do JavaScript Versao 1.1
// - Anderson Mautone Ferreira
// - Servidor Logical
// ==============================================================================================================


// ==============================================================================================================
// Controle das mensagens
	var strmensagem = "<span class='loading'><div class='content'><img src='../img/spinner.gif' /> - <font size='2'> \r\n <strong> PROCESSANDO INFORMACAO , \r\n AGUARDE... \r\n ESTE PROCEDIMENTO PODERA LEVAR 1 MINUTO <strong></font></div> </span>";
	var strmensagemLogin = "<img src='../img/spinner.gif' /> - <font size='2'> \r\n <strong> PROCESSANDO INFORMACAO , \r\n AGUARDE... </font></div> </span>";
	var strmensagemLoginrepositorio = "<span class='loading'><div class='content'><img src='../img/spinner.gif' /> - <font size='2'> \r\n <strong> Processando repositorio , aguarde ... </font></div> </span>";
// ==============================================================================================================


//==================================================================
// Mautone Ferreira
// Data 13/02/2008
// Ajuste de tela automatico da tela do Sguardo
//==================================================================

function redimencionar_tela_sguardo()
{
	var height = window.innerWidth;
	if (document.body.clientHeight)
	{
		height=document.body.clientHeight;
	}
	document.getElementById("mainFrame").style.height = parseInt((height+6)-document.getElementById("mainFrame").offsetTop-8)+"px";
}

	window.onresize = redimencionar_tela_sguardo;

//==================================================================


// ==============================================================================================================
// Funcao para popup centralizado
// Anderson Mautone Ferreira
// ==============================================================================================================

function popupcenter_titulo(mypage,myname,w,h,scroll,Strvariavel)
{
	if(Strvariavel == 0)
	{
		if(tree.getSelectedItemId() == "")
		{
			fnOpen("ATENCAO , NENHUM ITEM FOI SELECIONADO NA TELA DO REPOSITORIO.");
			return false;
			window.close();
		}
		else
		{
			LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
			TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
			settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',status=yes,resizable'
			win_center = window.open(mypage+"&cod_acervo=" + tree.getSelectedItemId() ,myname,settings)
		}
	}
	else
	{
		LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
		settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',status=yes,resizable'
		win_center = window.open(mypage,myname,settings)
	}

		if(!win_center)
		{
			alert(" Favor habilitar o Pop-Up. ");
		}
}

function popupcenter_titulo_novo(mypage,myname,w,h,scroll,Strvariavel)
{
	if(Strvariavel == 0)
	{
		LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
		settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',status=yes,resizable'
		win_center = window.open(mypage+"&cod_acervo=" + tree.getSelectedItemId()+"&cod_tema="+document.getElementById("codtema").value + "&cod_genero=" + document.getElementById("codgenero").value ,myname,settings)
	}

	if(!win_center)
	{
		alert(" Favor habilitar o Pop-Up. ");
	}
}


function popupcenter_titulo_novo_item(mypage,myname,w,h,scroll,Strvariavel)
{
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',status=yes,resizable'
	win_center = window.open(mypage+"&cod_acervo=" + tree.getSelectedItemId()+"&cod_tema="+document.getElementById("codtema").value + "&cod_genero=" + document.getElementById("codgenero").value ,myname,settings)

	if(!win_center)
	{
		alert(" Favor habilitar o Pop-Up. ");
	}
}

// ==============================================================================================================


function popupcenter_assegurada(mypage,myname,w,h,scroll,strGenerico)
{
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',status=yes,resizable=no'
	win_center = window.open(mypage + "&idqliAsseg=" + strGenerico,myname,settings)

	if(!win_center)
	{
		alert(" Favor habilitar o Pop-Up. ");
	}
}



function list_dados( valor )
{
	var exibeResultado 	= document.getElementById("resultado_select"); // div que exibirá o resultado da busca.
	var ranNum = Math.floor(Math.random()*372766);
	http.open("GET", "../processos/generos.php?id=" + valor + "&cache=" + ranNum + "&CTL=<?=$CTL;?>", true);
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
	http.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	http.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
	http.setRequestHeader("Pragma", "no-cache");
	http.onreadystatechange = function()
	{
		if(http.readyState == 1) 
		{ // Quando estiver carregando, exibe: carregando...
			exibeResultado.innerHTML = strmensagemLogin;
		}
		if(http.readyState == 4) 
		{ // Quando estiver tudo pronto.
			if(http.status == 200) 
			{
				campo_select = document.form1.subcategoria;
				campo_select.options.length = 0;
				results = http.responseText.split(",");

				for( i = 0; i < results.length; i++ )
				{   
					string = results[i].split("|");
					campo_select.options[i] = new Option(string[0],string[1]);
				}
				exibeResultado.innerHTML = "";
			} 
			else 
			{
				exibeResultado.innerHTML = "Erro: Nao foi encontrado nenhuma informacao  ";
			}
		}
	}
	http.send(null); // submete
}


// ==============================================================================================================
// Funcao para Preload das Imagens
// - Anderson Mautone Ferreira
// ==============================================================================================================
	function MM_reloadPage(init)
	{
		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);
// ==============================================================================================================

function validar_radio(strvalidacao,strcampo)
{
	document.getElementById(strcampo).value = strvalidacao;
}

// ==============================================================================================================
// Processo de paginacao do sistema
// - Anderson Mautone Ferreira
// ==============================================================================================================

function ajax_paginando(Strpagina,StrDivPagina)
{

	var exibeResultado 	= document.getElementById(StrDivPagina);
	var ranNum 			= Math.floor(Math.random()*3727266);
	var ajax 			= abrirAjax(); // Inicia o Ajax.
	
	ajax.open("GET", Strpagina + "&nochache=" + ranNum, true);

	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
	ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	ajax.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
	ajax.setRequestHeader("Pragma", "no-cache");
	
	ajax.onreadystatechange = function()
	{

		if(ajax.readyState == 1) 
		{ // Quando estiver carregando, exibe: carregando...
			exibeResultado.innerHTML = strmensagem;
		}

		if(ajax.readyState == 4)
		{ // Quando estiver tudo pronto.

			var resultado = ajax.responseText;
			resultado = resultado.replace(/\+/g," "); 
			resultado = unescape(resultado);
			exibeResultado.innerHTML = resultado.replace('°','&ordm');
	
			if(ajax.status == 200)
			{
				var resultado = ajax.responseText;
				resultado = resultado.replace(/\+/g," ");
				resultado = unescape(resultado);
				exibeResultado.innerHTML = resultado.replace('°','&ordm');
			} 
			else
			{
				exibeResultado.innerHTML = resultado.replace('°','&ordm');
			}
		}
	}
	ajax.send(null); // submete
}





// ==============================================================================================================
// Principal modulo de abertura do Ajax.
// - Anderson Mautone Ferreira
// ==============================================================================================================

function abrirAjax() 
{

	var httpRequest;

	if (window.XMLHttpRequest) 
	{ 
		httpRequest = new XMLHttpRequest(); // Mozilla, Safari, ...
	} 

	if (typeof XMLHttpRequest != "undefined") 
	{
		return new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
	   var aVersions = [ "MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];
	   for (var i = 0; i < aVersions.length; i++) 
	   {
		    try 
			{
				var oXmlHttp = new ActiveXObject(aVersions[i]);
				return oXmlHttp;
			} 
			catch (oError)
			{
				fnOpen("MSXML NAO INSTALADO EM SUA MAQUINA");
			}
	   }
	}
	throw new Error("XMLHttp Nao esta instalado em sua maquina");
}

// ==============================================================================================================



// ==============================================================================================================
// Funcao de Scroll Bar Position para posicionamento de uma palavra qualquer no site
// - Anderson Mautone Ferreira
// ==============================================================================================================

function scrollToPosition(Strindice)
{
	var theElement 	= document.getElementById(Strindice)
	elemPosX 		= theElement.offsetLeft  
	elemPosY 		= theElement.offsetTop;  
	theElement 		= theElement.offsetParent; 
	
	while(theElement != null)
	{    
		elemPosX += theElement.offsetLeft     
		elemPosY += theElement.offsetTop;    
		theElement = theElement.offsetParent;  
	}
	window.scrollTo(elemPosX ,elemPosY);
}

// ==============================================================================================================

// ==============================================================================================================
// Funcao para retorno de dados de um Frame (framemenu) 
// Pagina : menu/repositorio.php 
// Linha 182
// - Anderson Mautone Ferreira
// ==============================================================================================================

function retornodoajax(Strpagina)
{

	window.parent.framemenu.document.getElementById("info_result_cadastro").style.display = "none";

	var ranNum = Math.floor(Math.random()*372766);
	var ajax = abrirAjax(); // Inicia o Ajax.
	ajax.open("GET", Strpagina + "&nochache=" + ranNum, true); 
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
	ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	ajax.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
	ajax.setRequestHeader("Pragma", "no-cache");
	ajax.onreadystatechange = function()
	{
		if(ajax.readyState == 1) 
		{ // Quando estiver carregando, exibe: carregando...
			window.parent.framemenu.document.getElementById("result_cadastro_repositorio").innerHTML = strmensagem;
		}
		if(ajax.readyState == 4)
		{ // Quando estiver tudo pronto.

			var resultado = ajax.responseText;
			resultado = resultado.replace(/\+/g," "); 
			resultado = unescape(resultado);
			window.parent.framemenu.document.getElementById("result_cadastro_repositorio").innerHTML = resultado.replace('°','&ordm');
	
			if(ajax.status == 200)
			{
				var resultado = ajax.responseText;
				resultado = resultado.replace(/\+/g," ");
				resultado = unescape(resultado);
				window.parent.framemenu.document.getElementById("result_cadastro_repositorio").innerHTML = resultado.replace('°','&ordm');
			} 
			else
			{
				window.parent.framemenu.document.getElementById("result_cadastro_repositorio").innerHTML = resultado.replace('°','&ordm');
			}
		}
	}
	ajax.send(null); // submete
}
// ==============================================================================================================


// ==============================================================================================================
// Funcao para retorno de dados do texto RICH aplicado nas paginas de texto ( EDICAO E INSERCAO )
// Pagina : cadastro/cadastrar_editar_excluir.php
// - Anderson Mautone Ferreira
// ==============================================================================================================
function AjaxTexto(Strdivpagina,Strpagina)
{
		
		var termo 			= Strdivpagina;
		var exibeResultado 	= document.getElementById(Strdivpagina); 		// div que exibirá o resultado da busca.
		var strtexto 		= document.getElementById("freeRTE").contentWindow.document.body.innerHTML; 	// div que exibirá o resultado da busca.
		var ranNum 			= Math.floor(Math.random()*372766);

		if(strtexto == "")
		{
			alert("ERRO AO CADASTRAR, CAMPO EM BRANCO.");
			document.getElementById("freeRTE").contentWindow.document.body.focus();
			return false;
		}

		if(termo !== "" && termo !== null && termo.length >= 3) 
		{ // Verifica se o campo não está vazio, ou se foi digitado no mínimo três caracteres.
			var ajax = abrirAjax(); // Inicia o Ajax.
			
			ajax.open("GET", Strpagina + "&cache=" + ranNum + "&texto=" + strtexto, true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
			ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
			ajax.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
			ajax.setRequestHeader("Pragma", "no-cache");
			ajax.onreadystatechange = function() 
			{
				if(ajax.readyState == 1) 
				{ // Quando estiver carregando, exibe: carregando...
					exibeResultado.innerHTML = strmensagem;
				}
				if(ajax.readyState == 4) 
				{ // Quando estiver tudo pronto.
					
					var resultado = ajax.responseText; // Coloca o resultado (da busca) retornado pelo Ajax nessa variável (var resultado).
					resultado = resultado.replace(/\+/g," "); // Resolve o problema dos acentos
					resultado = unescape(resultado); // Resolve o problema dos acentos
					exibeResultado.innerHTML = resultado.replace('°','&ordm');

					if(ajax.status == 200)
					{
						var resultado = ajax.responseText; // Coloca o resultado (da busca) retornado pelo Ajax nessa variável (var resultado).
						resultado = resultado.replace(/\+/g," "); // Resolve o problema dos acentos
						resultado = unescape(resultado); // Resolve o problema dos acentos
						exibeResultado.innerHTML = resultado.replace('°','&ordm');
					} 
					else 
					{
						exibeResultado.innerHTML = resultado.replace('°','&ordm');
					}
				}
			}
		ajax.send(null); // submete
	}
}

// ==============================================================================================================


// ==============================================================================================================
// Funcao para retorno de paginas
// Pagina cadastro/cadastrar_novo_repo.php
// - Anderson Mautone Ferreira
// ==============================================================================================================
function voltar_paginas(strpagina)
{
	window.location = strpagina;	
}
// ==============================================================================================================

// ==============================================================================================================
// Funcao para Auto Complete do Sistema de Itens 
// Pagina cadastro/cadastrar_editar_excluir.php
// - Anderson Mautone Ferreira
// ==============================================================================================================
function autocomplet(string,divstring)
{
	var AC = new dmsAutoComplete(string,divstring);
	AC.clearField = false; //Definir que texto escolhido não deve ser removido do campo
	AC.chooseFunc = function(id,label)
	{
		document.getElementById("str_glossario_titulo").value = id;
	}
}
// ==============================================================================================================


// ==============================================================================================================
// Funcao para propriedades de Auto Upper case
// - Anderson Mautone Ferreira
// ==============================================================================================================
function case_checker(str)
{
	var st = document.getElementById(str).value;
	document.getElementById(str).value = st.toUpperCase();
}
// ==============================================================================================================

// ==============================================================================================================
// Funcao para propriedades de Auto Lower Case
// - Anderson Mautone Ferreira
// ==============================================================================================================
function change_case()
{
	document.form1.type.value = document.form1.type.value.toLowerCase();
}

// ==============================================================================================================
// Funcao para retorno de pagina
// - Anderson Mautone Ferreira
// ==============================================================================================================
function mudar(which) 
{
	voltar_paginas(which);
}
// ==============================================================================================================

// ==============================================================================================================
// Funcao para filtrar temas
// - Anderson Mautone Ferreira
// ==============================================================================================================
function filtro_temas(filtro,data1,data2)
{
	if((document.getElementById("filtro_niveis").type == "select-one") && (document.getElementById("filtro_niveis").value == 0))
	{
		fnOpen("GENERO NAO SELECIONADO , FAVOR VERIFICAR");
		return false;
	}
	else
	{
		window.location = filtro + "&DataInicial=" + data1 + "&DataFinal=" + data2;
	}
}
// ==============================================================================================================


// ==============================================================================================================
// Funcao para mudar o Select quando seletionado
// ==============================================================================================================
function mudarselect(StrValue,Strplaceselect,Strplaceinput,divisualiza,Strdisplay) 
{
	document.getElementById(Strplaceinput).value = document.getElementById(Strplaceselect).value
	document.getElementById(divisualiza).style.display = 'block';
	if(Strdisplay != "")
	{
		document.getElementById(Strdisplay).disabled = false;	
	}
	
}
// ==============================================================================================================


// ==============================================================================================================
// Funcao para Mudar de campo quando atingir o tamanho exigido
// - Anderson Mautone Ferreira
// ==============================================================================================================

var campo=0;

function TabNext(obj,event,len,next_field) 
{
	if (event == "down") 
	{
		campo=obj.value.length;
	}
	else if (event == "up") 
	{
		if (obj.value.length != campo) 
		{
			campo=obj.value.length;
			if (campo == len) 
			{
				next_field.focus();
			}
		}
	}
}

function TabNextSelect(obj)
{
	obj.focus();
}


// ==============================================================================================================

// ==============================================================================================================
// - Anderson Mautone Ferreira
// ==============================================================================================================
function MascaraData(Objeto) 
{

	Tamanho 		= Objeto.value.length;
	Valor 			= Objeto.value;
	ValorDigitado 	= Objeto.value.substring(Tamanho-1,Tamanho);

	if (ValorDigitado == "/")
		if (Tamanho == 1)
			Objeto.value = "";
		else 
		{
			Objeto.value = Objeto.value.substring(0, (Tamanho-1));
		}
		else 
		{
		
			if (Tamanho == 1) 
			{
				if (Valor >= 4) 
				{	
					Objeto.value = "0" + Valor + "/"
				}
		}
		else if (Tamanho == 2) 
		{
			if (Valor.substring(1,2) == "/") 
			{
				Objeto.value = "0" + Valor
			}
			else 
				{
					Objeto.value = Objeto.value + "/"
				}
			}
		else if (Tamanho == 4) 
		{
			if (Valor.substring(3,5) > 1) 
			{
					var tempMes = Valor.substring(3,5);
					Objeto.value = Valor.substring(0,3) + "0" + tempMes + "/"
			}
		}
		else if (Tamanho == 5) 
		{
			Objeto.value = Objeto.value + "/"
		}
		else if (Tamanho == 7) 
		{
			if (Valor.substring(6,7) > 2)
			{
				Objeto.value = Valor.substring(0,6) + "19" + Valor.substring(6,7)
			}
			else 
				if (Valor.substring(6,7) == 0)
				{
					Objeto.value = Valor.substring(0,6) + "20" + Valor.substring(6,7)
				}		
			}
		else if (Tamanho == 10) 
		{
			if (!(ValidaData(Objeto.value))) 
			{
					Objeto.value = "";
					Objeto.focus();
			}
		}
	} 
}


function mascara(o,f)
{
	v_obj=o
	v_fun=f
	setTimeout("execmascara()",1)
}

function execmascara()
{
	v_obj.value=v_fun(v_obj.value)
}


function soLetras(v){
return v.replace(/\d/g,"") //Remove tudo o que não é Letra
}

function soLetrasMA(v){
v=v.toUpperCase() //Maiúsculas
return v.replace(/\d/g,"") //Remove tudo o que não é Letra ->maiusculas
}

function soLetrasMI(v){
v=v.toLowerCase() //Minusculas
return v.replace(/\d/g,"") //Remove tudo o que não é Letra ->minusculas
}

function soNumeros(v)
{
	return v.replace(/\D/g,"") //Remove tudo o que não é dígito
}

function telefone(v){
v=v.replace(/\D/g,"") //Remove tudo o que não é dígito
v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
v=v.replace(/(\d{4})(\d)/,"$1-$2") //Coloca hífen entre o quarto e o quinto dígitos
return v
}

function cpf(v){
v=v.replace(/\D/g,"") //Remove tudo o que não é dígito
v=v.replace(/(\d{3})(\d)/,"$1.$2") //Coloca um ponto entre o terceiro e o quarto dígitos
v=v.replace(/(\d{3})(\d)/,"$1.$2") //Coloca um ponto entre o terceiro e o quarto dígitos
//de novo (para o segundo bloco de números)
v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
return v
}

function cep(v){
v=v.replace(/\D/g,"") //Remove tudo o que não é dígito
v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
return v
}

function cnpj(v){
v=v.replace(/\D/g,"") //Remove tudo o que não é dígito
v=v.replace(/^(\d{2})(\d)/,"$1.$2") //Coloca ponto entre o segundo e o terceiro dígitos
v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dígitos
v=v.replace(/\.(\d{3})(\d)/,".$1/$2") //Coloca uma barra entre o oitavo e o nono dígitos
v=v.replace(/(\d{4})(\d)/,"$1-$2") //Coloca um hífen depois do bloco de quatro dígitos
return v
}

function romanos(v){
v=v.toUpperCase() //Maiúsculas
v=v.replace(/[^IVXLCDM]/g,"") //Remove tudo o que não for I, V, X, L, C, D ou M
//Essa é complicada! Copiei daqui: http://www.diveintopython.org/refactoring/refactoring.html
while(v.replace(/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,"")!="")
v=v.replace(/.$/,"")
return v
}

function data(v){
v=v.replace(/\D/g,"") //Remove tudo o que não é dígito
v=v.replace(/(\d{2})(\d)/,"$1-$2") //Coloca um ponto entre o segundo e o terceiro dígitos
v=v.replace(/(\d{2})(\d)/,"$1-$2") //Coloca um ponto entre o quarto e o quinto dígitos
//v=v.replace(/^[0-3]?\d\/[01]?\d\/(\d{2}|\d{4})$/)
v=v.replace(/^((0[1-9]|[12]\d)\-(0[1-9]|1[0-2])|30\-(0[13-9]|1[0-2])|31\-(0[13578]|1[02]))\-\d{4}$/)
//v=v.replace(/^(0[1-9]|[012][0-9]|3[01])/\-(0[1-9]|1[012])/\-([12][0-9]{3})/,"") 
return v
}


function hora(v)
{
	v = v.replace(/(\d{2})(\d)/,"$1:$2") //Coloca dois ponto entre o segundo e o terceiro dígitos
	v.match( (/[01][0-9]:[0-5][0-9]|[2][0-4]:[0-5][0-9]/))?v=v:v=''
	return v

}

function site(v)
{
	//Esse sem comentarios para que você entenda sozinho;-)
	v=v.replace(/^http:\/\/?/,"")
	dominio=v
	caminho=""
	if(v.indexOf("/")>-1)
	dominio=v.split("/")[0]
	caminho=v.replace(/[^\/]*/,"")
	dominio=dominio.replace(/[^\w\.\+-:@]/g,"")
	caminho=caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,"")
	caminho=caminho.replace(/([\?&])=/,"$1")
	if(caminho!="")
	dominio=dominio.replace(/\.+$/,"")
	v="http://"+dominio+caminho
	return v
}



function formata_valor(xvalorcampo)
{
	if (((event.keyCode) > 47) && ((event.keyCode) < 58))
	{
		NumDig = xvalorcampo.value;
		TamDig = NumDig.length;
		Contador = 0;
		if (TamDig > 1 && TamDig < 10)
		{
			numer = "";
			for (i = TamDig; (i >= 0); i--)
			{
			if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9))
			{
				Contador++;
				if ((Contador == 2) && ((TamDig -i) < 4))
				{
					numer = ","+numer;
					Contador = 0;
				}
				else if (Contador == 3)
				{
					numer = "."+numer;
					Contador = 0;
				}
				numer = NumDig.substr(i, 1)+numer;
			}
		}
		xvalorcampo.value = numer;
		};
		return(true);
	}
	else
	{
		mascara(xvalorcampo,soNumeros);
		return false;
	}
}

function formataCasasDecimais(obj)
{
	var numero;
	numero = obj.value;
	if(numero.indexOf(",")<0){
		if (numero == "" || numero == null){
			numero = 0
		}
		obj.value = numero + ",00";	
	}
}

function checa_string(campo) 
{
   var arrstrings = new Array();
   arrstrings['txtCNPJ'] = "0123456789";      
   //arrstrings['txtNome'] = "ABCDEFGHIJKLMNOPQRSTUVWXYZÇÀÁÂÃÈÉÊÌÍÎÒÓÔÕÙÚÛÜ ";
   arrstrings['txtCPF'] = "0123456789";   
   arrstrings['txtHonorarios'] = "0123456789,.";    
   arrstrings['txtMultaAVB'] = "0123456789,."; 
   arrstrings['txtEntrada'] = "0123456789,.";   
   
   
   //arrstrings['email'] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789&@.-_ ";

   var stringvalida = arrstrings[campo.name];
   

   var flagerro = 1;
   for(i=0;i < campo.value.length;i++){
      for(j=0; j < stringvalida.length;j++){
	     if(stringvalida.charAt(j) == campo.value.charAt(i).toUpperCase()){
		    flagerro = 0; 
			break; 
		 }else{flagerro = 1;}
	  }
	  
	  if(flagerro == 1){
	     charinvalido = campo.value.charAt(i);
	     campo.value = campo.value.substring(0,campo.value.length - 1);
		 var msg = "Esse campo não pode conter o caracter '"+charinvalido+"'";
         alert(msg);
         campo.select();
         campo.focus();
	  }
   }  
}


function ValidaData(dateStr) 
{
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	var matchArray = dateStr.match(datePat);
	if (matchArray == null) 
	{	    
		alert("Data em formato inválido! Use o formato DD/MM/AAAA")
		return false;
	}
		
	month = matchArray[3];
	day = matchArray[1];
	year = matchArray[4];
	if (month < 1 || month > 12) 
	{ 
		alert("Mes Inválido");
		return false;
	}
	if (day < 1 || day > 31) 
	{
		alert("Dia Inválido");
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		alert("Mes Inválido!")
		return false
	}
	if (month == 2) 
	{
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) 
		{
			alert("Dia inválido");
			return false;
		}
	}
	return true;
}




// ==============================================================================================================
// Funcao para popup centralizado
// - Anderson Mautone Ferreira
// ==============================================================================================================

var win_center = null;

function popupcenter(mypage,myname,w,h,scroll)
{
	if(tree.getSelectedItemId() == "")
	{
		fnOpen("ATENCAO , NENHUM ITEM FOI SELECIONADO NA TELA DO REPOSITORIO.");
		return false;
		window.close();
	}
	else
	{
		LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
		settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',status=yes,resizable'
		win_center = window.open(mypage,myname,settings)
	
		if(!win_center)
		{
			alert(" Favor habilitar o Pop-Up. ");
		}
	}
}
// ==============================================================================================================


// ==============================================================================================================
// Funcao para centralizar as imagens do sistema
// - Anderson Mautone Ferreira
// ==============================================================================================================

function MM_findObj(n, d)
{ 
	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.form1.length;i++)
	{
		x=d.form[i][n];
	}
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
	{
		x=MM_findObj(n,d.layers[i].document); 
	}
	
	return x;
}
// ==============================================================================================================

// ==============================================================================================================
// Funcao para aplicar exigencias no campo ( Somente letras )
// - Anderson Mautone Ferreira
// ==============================================================================================================

function CAPS(objeto) 
{
	objeto.value = objeto.value.toUpperCase();
	var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";

	for (var i = 0; i < objeto.value.length; i++) 
	{
		if (iChars.indexOf(objeto.value.charAt(i)) != -1)
		{
			alert ("::ERRO , \n\n CAMPO ACEITA APENAS LETRAS");
			objeto.value = "";
			return false;
		}
	}
}
// ==============================================================================================================

// ==============================================================================================================
// Funcao para alerta de erro personalizada ( showModalDialog ) 
// - Anderson Mautone Ferreira
// ==============================================================================================================
function fnOpen(StrAlert)
{
   var sFeatures="dialogWidth:500px;dialogHeight:150px;status:no;center:1;edge:sunken;unadorned:no;dialogHide:no;resizable:no;scroll:no;";
   window.showModalDialog("../error/ShowError.php?StrAlert=" + StrAlert,"",sFeatures)
}
// ==============================================================================================================

function removeCaracteresEspeciais(vStrTexto)
{ 

alert(vStrTexto)
	   vStrTexto=vStrTexto.replace("º", "");
       vStrTexto=vStrTexto.replace("ª", "");
       vStrTexto=vStrTexto.replace("~", "");
       vStrTexto=vStrTexto.replace("´", "");
       vStrTexto=vStrTexto.replace("`", "");
       vStrTexto=vStrTexto.replace("^", "");
       vStrTexto=vStrTexto.replace("¨", "");
       vStrTexto=vStrTexto.replace(".", " ");
       vStrTexto=vStrTexto.replace(",", " ");
       vStrTexto=vStrTexto.replace(";", " ");
       vStrTexto=vStrTexto.replace(":", " ");
       vStrTexto=vStrTexto.replace("/", " ");
       vStrTexto=vStrTexto.replace("<", " ");
       vStrTexto=vStrTexto.replace("'", " ");
       vStrTexto=vStrTexto.replace(">", " ");
       vStrTexto=vStrTexto.replace("'", " ");
}


String.prototype.trim = function()
{
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function Trim(str)
{
	return str.replace(/^\s+|\s+$/g,"");
}

// ==============================================================================================================
// Funcao dinamica do sistema ( Retorno ou validacao nas paginas )
// - Anderson Mautone Ferreira
// ==============================================================================================================
function ajax_dinamic(StrNomeForm,StrPagina,StrDivPagina,StrObrigatorioValue,StrMsgErro,StrRedirecionamento,StrPerguntar,StrTextButton,StrRefresh,StrButtonId,StrDisableButton)
{

		var elem 					= document.getElementById(StrNomeForm).elements;
		var exibeResultado 			= document.getElementById(StrDivPagina);
		var ranNum 					= Math.floor(Math.random()*372766);
		var array_count 			= StrObrigatorioValue.split("|");
		var StrMsgErro_count		= StrMsgErro.split("|");
		exibeResultado.innerHTML 	= "";
		var warning					= "";
		var strRetorno				= "";
		var vCodPaginas				= "";
		var vCount 					= 0;
		var StrPonto				= "";
		var array_buton				= StrDisableButton.split("|");

		if(StrPerguntar == 1)
		{
			var r=confirm(StrTextButton)
			if (r==true)
			{
				var strStatus = true;
			}
			else
			{
				return false;	
			}
		}

		for(var i = 0; i < elem.length; i++)
		{
			if(elem[i].type == "radio" || elem[i].type == "checkbox")
			{
				if(elem[i].checked)
				{
					strRetorno = strRetorno + "&" + elem[i].name + "=" + escape(elem[i].value);
				}
			}
			else
			{
				strRetorno = strRetorno + "&" + elem[i].name + "=" + escape(elem[i].value);
			}
		}
		
		
		if(StrObrigatorioValue != "")
		{
			for (var loop=0; loop < array_count.length; loop++)
			{
				if((document.getElementById(array_count[loop]).value == "") || (document.getElementById(array_count[loop]).value == 0))
				{
					warning = warning + " - " + StrMsgErro_count[loop] + "<br>";
				}
			}
			

			if(warning != "")
			{
				fnOpen(warning);
			}
		}

		if(StrObrigatorioValue != "")
		{
			for (var loop=0; loop < array_count.length; loop++)
			{
				if(vCount >= 0)
				{
					if((document.getElementById(array_count[loop]).value == "") || (document.getElementById(array_count[loop]).value == 0))
					{
						if((document.getElementById(array_count[loop]).type == "select-one") && (document.getElementById(array_count[loop]).value == 0))
						{
						  document.getElementById(array_count[loop]).focus();
						}
						else if((document.getElementById(array_count[loop]).type == "text") && (document.getElementById(array_count[loop]).disabled != true))
						{
							document.getElementById(array_count[loop]).focus();
						}
						else
						{
							return false;	
						}
						return false;
					}
				}
				vCount = vCount + 1;
			}
		}
	     
		var ajax = abrirAjax(); // Inicia o Ajax.
		//document.write (StrPagina + strRetorno + "&nochache=" + ranNum);
	
		ajax.open("GET", StrPagina + strRetorno + "&nochache=" + ranNum, true);
		
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
		ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
		ajax.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
		ajax.setRequestHeader("Pragma", "no-cache");
		ajax.onreadystatechange = function()
		{
			if(ajax.readyState == 1) 
			{
				exibeResultado.innerHTML = strmensagem;
			}

			if(ajax.readyState == 4) 
			{ // Quando estiver tudo pronto.

				var resultado 			 = ajax.responseText;
				resultado 				 = resultado.replace(/\+/g," ");
				resultado 				 = unescape(resultado);
				exibeResultado.innerHTML = resultado.replace('°','&ordm');

				if(ajax.readyState == 200)
				{

					var resultado 	= ajax.responseText;
					resultado 		= resultado.replace(/\+/g," ");
					resultado 		= unescape(resultado);

					if(StrRedirecionamento == "")
					{
						exibeResultado.innerHTML = resultado.replace('°','&ordm');
					}
					else
					{
						if (resultado.indexOf("AJAXRedirect") > 0)
						{
							window.location = StrRedirecionamento;
						}
					}
				}
				else 
				{
					exibeResultado.innerHTML = resultado.replace('°','&ordm');
					
					if(StrRefresh == 1)
					{
						if(StrButtonId != "" && StrButtonId != "undefined" && StrButtonId != null)
						{
							if(array_buton.length > 0 || array_buton != "" || array_buton != null)
							{
								for (var i=0; i < array_buton.length; i++)
								{
									document.getElementById(array_buton[i]).disabled = true;
								}
							}

							if(StrObrigatorioValue != "")
							{
								Limpa();
								document.getElementById(StrButtonId).click();
							}

						}
					}
				}
			}
		}
	ajax.send(null); // submete
}
// ==============================================================================================================


function retorno_busca(Strpagina,StrDivPagina)
{
	var exibeResultado 	= document.getElementById(StrDivPagina);
	var exibeResultadoR = document.getElementById("retorno_inserindo");
	var ranNum 			= Math.floor(Math.random()*372766);
	var ajax 			= abrirAjax(); // Inicia o Ajax.
	ajax.open("GET", Strpagina + "&nochache=" + ranNum, true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
	ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	ajax.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
	ajax.setRequestHeader("Pragma", "no-cache");
	ajax.onreadystatechange = function()
	{
		if(ajax.readyState == 1) 
		{
			exibeResultadoR.innerHTML = strmensagem;
		}
		
		if(ajax.readyState == 4)
		{ // Quando estiver tudo pronto.

			var resultado = ajax.responseText;
			resultado = resultado.replace(/\+/g," "); 
			resultado = unescape(resultado);
			exibeResultado.innerHTML = resultado.replace('°','&ordm');
	
			if(ajax.status == 200)
			{
				var resultado = ajax.responseText;
				resultado = resultado.replace(/\+/g," ");
				resultado = unescape(resultado);
				exibeResultadoR.innerHTML = "";
				exibeResultado.innerHTML = resultado.replace('°','&ordm');
			} 
			else
			{
				exibeResultado.innerHTML = resultado.replace('°','&ordm');
			}
		}
	}
	ajax.send(null); // submete
}



//Constantes para cores de controles de tela

var CorSeleciona 	= '#FFFFCC';
var CorAtivo	 	= '#D6FED7';
var CorInativo		= '#E6E6E6';

function AlterarCor(pIDElemento, pNumElemento)
{
	//Declaração de Variáveis
	var vstrNomeElemento;
	var vEx;

	try
	{
		
		//Verifica caso a cor esta como ativo para o mouse, caso contrario retorna cor original
		if	(pIDElemento.bgColor.toUpperCase() != CorSeleciona)
		{
			pIDElemento.bgColor = CorSeleciona;
		}
		else
		{
			vstrNomeElemento = "CorOrigem" + pNumElemento;
			pIDElemento.bgColor = document.getElementById(vstrNomeElemento).value;
		}
	}
	catch(vEx)
	{
		alert(vEx.message);
	}
}

function Marcar(vnumVvalor,vnumVText,StrCampoIdFor,StrCampoIdValue,StrCampoFocus,strGenerica)
{

		//Declaração de Variáveis
		var array_count 		= StrCampoIdFor.split("|");
		var arrar_values		= StrCampoIdValue.split("|");
		
		window.scrollTo(0 ,0);

		document.getElementById(StrCampoFocus).focus();
		
		if(document.getElementById("btnAlterar").disabled == true || document.getElementById("btnExcluir").disabled == true)
		{
			document.getElementById("btnAlterar").disabled = false;
			document.getElementById("btnExcluir").disabled = false;
		}
		
	
		if (document.getElementById('img' + vnumVvalor).style.display == 'none')
		{
			document.getElementById("IdSelecionado").value += '_' + vnumVvalor;
			document.getElementById("IdSelecionado_banco").value = vnumVvalor;
		
			for (var loop=0; loop < array_count.length; loop++)
			{
				document.getElementById(array_count[loop]).value = arrar_values[loop];
			}
			
		}
		else
		{
			document.getElementById('img' + vnumVvalor).style.display = 'none';
			document.getElementById("IdSelecionado").value = document.getElementById("IdSelecionado").value.replace('_' + vnumVvalor, '');
		}
		
		if(strGenerica == 1)
		{
			//document.getElementById("txtHistoricoFornecedor").disabled = false;
			//document.getElementById("txtElementoFornecedores").disabled = false;
			document.getElementById("txtContatosFornecedores").disabled = false;
			document.getElementById("txtEndereco").disabled = false;
		}
}


function Marcar_item(vnumVvalor,vnumDiv)
{
	
	var exibeResultadoR = document.getElementById(vnumDiv);
	exibeResultadoR.innerHTML = "";
	window.scrollTo(0 ,0);
	document.getElementById("IdSelecionado_banco").value = vnumVvalor;
	
	document.getElementById("cboproduto").disabled = false;
	document.getElementById("cbounidade").disabled = false;
	document.getElementById("txtqtde").disabled = false;
	
	document.getElementById("DivInclusao").style.display = "none";
	document.getElementById("DivInclusaoitens").style.display = "block";
	
}

function refresh_page(Strpagina,StrDivPagina)
{

	var exibeResultado 	= document.getElementById(StrDivPagina);
	var ranNum 			= Math.floor(Math.random()*372766);
	var ajax 			= abrirAjax(); // Inicia o Ajax.
	
	ajax.open("GET", Strpagina + "&nochache=" + ranNum, true);

	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
	ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	ajax.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
	ajax.setRequestHeader("Pragma", "no-cache");
	ajax.onreadystatechange = function()
	{
		if(ajax.readyState == 4)
		{ // Quando estiver tudo pronto.

			var resultado = ajax.responseText;
			resultado = resultado.replace(/\+/g," "); 
			resultado = unescape(resultado);
			exibeResultado.innerHTML = resultado.replace('°','&ordm');
	
			if(ajax.status == 200)
			{
				var resultado = ajax.responseText;
				resultado = resultado.replace(/\+/g," ");
				resultado = unescape(resultado);
				exibeResultado.innerHTML = resultado.replace('°','&ordm');
			} 
			else
			{
				exibeResultado.innerHTML = resultado.replace('°','&ordm');
			}
		}
	}
	ajax.send(null); // submete
}



// ==============================================================================================================
// Funcao para Filtro da pagina de GENERO E TEMA
// - Anderson Mautone Ferreira
// ==============================================================================================================

function ajax_filtro(Strinput,Strdiv,StrAll) 
{

	var resultado_indice = document.getElementById(Strdiv);
	resultado_indice.innerHTML = "";

	if(StrAll == "filtro_todos")
	{
		var Strinput 		= "filtro_todos";
		var StrElemento 	= document.getElementById('resultadoBusca');
	}
	else
	{
		if(Strinput != "strgenero")
		{
			if(document.getElementById("genero_fk").value == 0)
			{
				alert("SELECIONE UM GENERO PARA CONTINUAR A PESQUISA")
				return false;
			}
		}

		if(document.getElementById(Strinput).value == "")
		{
			alert("CAMPO DE FILTRO EM BRANCO , FAVOR VERIFICAR.");
			document.getElementById(Strinput).focus();
			return false;
		}
	}

	if(document.getElementById)
	{
		var termo 			= document.getElementById(Strinput).value;
		var Strtabela		= document.getElementById("Strtabela").value;
		var ranNum 			= Math.floor(Math.random()*372766);
		var exibeResultado 	= document.getElementById('resultadoBusca');
		
		if(Strtabela == "tb_tema")
		{
			var StrCodGenero	= document.getElementById("genero_fk").value;
		}
		
		if(termo !== "" && termo !== null && termo.length >= 1) 
		{
			var ajax = abrirAjax();
			ajax.open("GET", "../retorno_ajax/filtro_genero_tema.php?strfiltro=" + termo + "&Nochache=" + ranNum + "&Strtabela=" + Strtabela + "&StrCodGenero=" + StrCodGenero + "&filtro_todos=" + StrAll, true); 
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
			ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
			ajax.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
			ajax.setRequestHeader("Pragma", "no-cache");
			ajax.onreadystatechange = function() 
			{
				if(ajax.readyState == 1) 
				{
					exibeResultado.innerHTML = strmensagem;
				}
				if(ajax.readyState == 4) 
				{ // Quando estiver tudo pronto.

					var resultado = ajax.responseText;
					resultado = resultado.replace(/\+/g," ");
					resultado = unescape(resultado);
					exibeResultado.innerHTML = resultado;

					if(ajax.status == 200)
					{
						var resultado = ajax.responseText; 
						resultado = resultado.replace(/\+/g," "); 
						resultado = unescape(resultado); 
						exibeResultado.innerHTML = resultado;
					} 
					else 
					{
						exibeResultado.innerHTML = resultado;
					}
				}
			}
			ajax.send(null); // submete
		} 
	}
}

// ==============================================================================================================

// ==============================================================================================================
// Funcao dinamica do sistema ( Retorno ou validacao nas paginas )
// - Anderson Mautone Ferreira
// ==============================================================================================================

function ajax_login_request(StrNomeForm,StrPagina,StrDivPagina,StrObrigatorioValue,StrMsgErro,StrRedirecionamento,StrPerguntar,StrTextButton,StrRefresh)
{

		var strRetorno				= "";
		var vCodPaginas				= "";
		var vCount 					= 0;
		var resultHtml				= "";
		var elem 					= document.getElementById(StrNomeForm).elements;
		var exibeResultado 			= document.getElementById(StrDivPagina);
		var ranNum 					= Math.floor(Math.random()*372766);
		var array_count 			= StrObrigatorioValue.split("|");
		
		exibeResultado.innerHTML 	= "";

		if(StrPerguntar == 1)
		{
			var r=confirm(StrTextButton)
			if (r==true)
			{
				var strStatus = true;
			}
			else
			{
				return false;	
			}
		}

		for(var i = 0; i < elem.length; i++)
		{
			if(elem[i].type == "radio" || elem[i].type == "checkbox")
			{
				if(elem[i].checked)
				{
					strRetorno = strRetorno + "&" + elem[i].name + "=" + escape(elem[i].value);
				}
			}
			else
			{
				strRetorno = strRetorno + "&" + elem[i].name + "=" + escape(elem[i].value);
			}
		}

		if(StrObrigatorioValue != "")
		{
			for (var loop=0; loop < array_count.length; loop++)
			{
				if(vCount >= 0)
				{
					if((document.getElementById(array_count[loop]).value == "") || (document.getElementById(array_count[loop]).value == 0))
					{
						if(StrMsgErro == "")
						{
							fnOpen("ERRO AO CADASTRAR, CAMPO EM BRANCO.");
							if(document.getElementById(array_count[loop]).type != "hidden")
							{
								document.getElementById(array_count[loop]).focus();
							}
							return false;
						}
						else
						{
							fnOpen(StrMsgErro);
							if((document.getElementById(array_count[loop]).type == "select-one") && (document.getElementById(array_count[loop]).value == 0))
							{
							  document.getElementById(array_count[loop]).focus();
							}
							else if((document.getElementById(array_count[loop]).type == "text") && (document.getElementById(array_count[loop]).disabled != true))
							{
								document.getElementById(array_count[loop]).focus();
							}
							else
							{
								return false;	
							}
							return false;
						}
					}
				}
				vCount = vCount + 1;
			}
		}
	
		var ajax = abrirAjax(); // Inicia o Ajax.
		ajax.open("GET", StrPagina + strRetorno + "&nochache=" + ranNum, true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
		ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
		ajax.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
		ajax.setRequestHeader("Pragma", "no-cache");
		ajax.onreadystatechange = function()
		{

			if(ajax.readyState == 1) 
			{
				exibeResultado.innerHTML = strmensagemLogin;
			}
			
			if(ajax.readyState == 4) 
			{ // Quando estiver tudo pronto.

				var resultado = ajax.responseText;
				resultado = resultado.replace(/\+/g," ");
				resultado = unescape(resultado);
				resultHtml = resultado.replace('°','&ordm');
				
				if(StrRefresh == 1)
				{
					exibeResultado.innerHTML = strmensagemLogin;
				}

				if(ajax.status == 200)
				{
					var resultado = ajax.responseText;
					resultado = resultado.replace(/\+/g," ");
					resultado = unescape(resultado);

					if(StrRedirecionamento == "")
					{
						exibeResultado.innerHTML = resultado.replace('°','&ordm');
					}
					else
					{
						if(resultHtml.substr(0,20) == "221133")
						{
							window.location = StrRedirecionamento
						}
						else if(resultHtml.substr(0,64) == "221133")
						{
							window.location = StrRedirecionamento
						}
						else
						{
							exibeResultado.innerHTML = resultado.replace('°','&ordm');
						}
					}
				}
				else 
				{
					exibeResultado.innerHTML = resultado.replace('°','&ordm');
				}
			}
		}
	ajax.send(null); // submete
}


// ==============================================================================================================


// ==============================================================================================================
// Validacao de CNPJ , CPF , TELEFONE e outros.
// - Anderson Mautone Ferreira
// ==============================================================================================================

function MascaraCNPJ(cnpj){
    if(mascaraInteiro(cnpj)==false){
        event.returnValue = false;
    }    
    return formataCampo(cnpj, '00.000.000/0000-00', event);
}

//adiciona mascara de cep
function MascaraCep(cep){
        if(mascaraInteiro(cep)==false){
        event.returnValue = false;
    }    
    return formataCampo(cep, '00.000-000', event);
}

//adiciona mascara de data
function MascaraData(data){
    if(mascaraInteiro(data)==false){
        event.returnValue = false;
    }    
    return formataCampo(data, '00/00/0000', event);
}


//adiciona mascara ao telefone
function MascaraTelefone(tel)
{    
    if(mascaraInteiro(tel)==false)
	{
        event.returnValue = false;
    }    
    return formataCampo(tel, '(000) 0000-0000', event);
}

//adiciona mascara ao CPF
function MascaraCPF(cpf){
    if(mascaraInteiro(cpf)==false){
        event.returnValue = false;
    }    
    return formataCampo(cpf, '000.000.000-00', event);
}

//valida telefone
function ValidaTelefone(tel){
    exp = /\(\d{2}\)\ \d{4}\-\d{4}/
    if(!exp.test(tel.value))
        alert('Numero de Telefone Invalido!');
}

//valida CEP
function ValidaCep(cep){
    exp = /\d{2}\.\d{3}\-\d{3}/
    if(!exp.test(cep.value))
        alert('Numero de Cep Invalido!');        
}

//valida data
function ValidaData(data){
    exp = /\d{2}\/\d{2}\/\d{4}/
    if(!exp.test(data.value))
        alert('Data Invalida!');            
}

//valida o CPF digitado
function ValidarCPF(Objcpf){
    var cpf = Objcpf.value;
    exp = /\.|\-/g
    cpf = cpf.toString().replace( exp, "" ); 
    var digitoDigitado = eval(cpf.charAt(9)+cpf.charAt(10));
    var soma1=0, soma2=0;
    var vlr =11;
    
    for(i=0;i<9;i++){
        soma1+=eval(cpf.charAt(i)*(vlr-1));
        soma2+=eval(cpf.charAt(i)*vlr);
        vlr--;
    }    
    soma1 = (((soma1*10)%11)==10 ? 0:((soma1*10)%11));
    soma2=(((soma2+(2*soma1))*10)%11);
    
    var digitoGerado=(soma1*10)+soma2;
    if(digitoGerado!=digitoDigitado)    
        alert('CPF Invalido!');        
}

//valida numero inteiro com mascara
function mascaraInteiro(){
    if (event.keyCode < 48 || event.keyCode > 57){
        event.returnValue = false;
        return false;
    }
    return true;
}

//valida o CNPJ digitado
function ValidarCNPJ(ObjCnpj){
    var cnpj = ObjCnpj.value;
    var valida = new Array(6,5,4,3,2,9,8,7,6,5,4,3,2);
    var dig1= new Number;
    var dig2= new Number;
    
    exp = /\.|\-|\//g
    cnpj = cnpj.toString().replace( exp, "" ); 
    var digito = new Number(eval(cnpj.charAt(12)+cnpj.charAt(13)));
        
    for(i = 0; i<valida.length; i++){
        dig1 += (i>0? (cnpj.charAt(i-1)*valida[i]):0);    
        dig2 += cnpj.charAt(i)*valida[i];    
    }
    dig1 = (((dig1%11)<2)? 0:(11-(dig1%11)));
    dig2 = (((dig2%11)<2)? 0:(11-(dig2%11)));
    
    if(((dig1*10)+dig2) != digito)    
        alert('CNPJ Invalido!');
        
}

//formata de forma generica os campos
function formataCampo(campo, Mascara, evento) { 
    var boleanoMascara; 
    
    var Digitato = evento.keyCode;
    exp = /\-|\.|\/|\(|\)| /g
    campoSoNumeros = campo.value.toString().replace( exp, "" ); 
   
    var posicaoCampo = 0;     
    var NovoValorCampo="";
    var TamanhoMascara = campoSoNumeros.length;; 
    
    if (Digitato != 8) { // backspace 
        for(i=0; i<= TamanhoMascara; i++) { 
            boleanoMascara  = ((Mascara.charAt(i) == "-") || (Mascara.charAt(i) == ".")
                                || (Mascara.charAt(i) == "/")) 
            boleanoMascara  = boleanoMascara || ((Mascara.charAt(i) == "(") 
                                || (Mascara.charAt(i) == ")") || (Mascara.charAt(i) == " ")) 
            if (boleanoMascara) { 
                NovoValorCampo += Mascara.charAt(i); 
                  TamanhoMascara++;
            }else { 
                NovoValorCampo += campoSoNumeros.charAt(posicaoCampo); 
                posicaoCampo++; 
              }            
          }     
        campo.value = NovoValorCampo;
          return true; 
    }else { 
        return true; 
    }
}
// ==============================================================================================================


// ==============================================================================================================
// Limpando os campos solicitados do formulario inteiro
// - Anderson Mautone Ferreira
// ==============================================================================================================

	function Limpa()
	{
		var input       = document.getElementsByTagName('input')
		var select      = document.getElementsByTagName('select')
		var textarea    = document.getElementsByTagName('textarea')
		
		/*for(var i=0; i<select.length; i++)
			select[i].selectedIndex = 0;*/
			
		for(var i=0; i<textarea.length; i++)
			textarea[i].value = '';
					   
		for(var i=0; i<input.length; i++)
			switch (input[i].type)
			{
				case 'text':
				if(input[i].disabled == false)
				{
					input[i].value      = '';
				}

				case 'password':
				if(input[i].disabled == false)
				{
					input[i].value      = '';
				}


				break;
				case 'radio'    :   input[i].checked    = ''; 
				break;
				case 'checkbox' :   input[i].checked    = ''; 
				break;
			}
		
	}

// ==============================================================================================================
//Constantes para cores fixas selecionadas

var CorSeleciona22 		= '#FFFFCC';
var CorAtivo22	 		= '#FFFFCC';
var CorInativo22		= '#FFFFCC';

function AlterarCor22(pIDElemento, pNumElemento,strGenerico)
{
	
	//Declaração de Variáveis
	var vstrNomeElemento;
	var vEx;

	try
	{
		if(strGenerico == 1)
		{

			if(document.getElementById("img_" + pNumElemento).style.display == "block")
			{
				document.getElementById("img_" + pNumElemento).style.display = "none";
				document.getElementById("IdSelecionado").value = "";
			}
			else
			{
				document.getElementById("img_" + pNumElemento).style.display = "block";
				document.getElementById("IdSelecionado").value = pNumElemento;
			}
		}
		
		//Verifica caso a cor esta como ativo para o mouse, caso contrario retorna cor original
		if	(pIDElemento.bgColor.toUpperCase() != CorSeleciona22)
		{
			pIDElemento.bgColor = CorSeleciona22;
		}
		else
		{
			vstrNomeElemento = "CorOrigem" + pNumElemento;
			pIDElemento.bgColor = document.getElementById(vstrNomeElemento).value;
		}
	}
	catch(vEx)
	{
		alert(vEx.message);
	}
}


// inicio BLOCO COMPOSICAO
function transferdata(valor)
{
	document.formAtribuicaoComposicaoElementos.txtCoeficiente.value='';
	document.formAtribuicaoComposicaoElementos.txtCoeficiente.focus();

	document.formAtribuicaoComposicaoElementos.hidselected.value=valor;

}
function transferdata2(valor)
{

	document.formAtribuicaoComposicaoElementos.hidselected.value=valor;
}


function GravarComposicao()
{
var CTL = document.formAtribuicaoComposicaoElementos.ctlhid.value;
var papa = document.formAtribuicaoComposicaoElementos.papahid.value;
var filho = document.formAtribuicaoComposicaoElementos.hidselected.value;
var coefic = document.formAtribuicaoComposicaoElementos.txtCoeficiente.value;

	if(coefic == '')
	{
	alert ("Por favor, digite o Valor de Coeficiente.");
	document.formAtribuicaoComposicaoElementos.txtCoeficiente.focus();
	}
	if(coefic != '')
	{
	document.formAtribuicaoComposicaoElementos.txtCoeficiente.value='';
	ajax_dinamic('formAtribuicaoComposicaoElementos','../retorno_ajax/filtro_atrib2.php?CTL='+CTL+'&filtro_todos=filtro_todos&pai='+papa+'&focusedpai='+papa+'&filho='+filho+'&newsave=1&coefic='+coefic+'','retorno_inserindo2','','','',0,'',0,'','');
	}

 
}

function ApagarComposicao()
{
var CTL = document.formAtribuicaoComposicaoElementos.ctlhid.value;
var papa = document.formAtribuicaoComposicaoElementos.papahid.value;
var filho = document.formAtribuicaoComposicaoElementos.hidselected.value;
		document.formAtribuicaoComposicaoElementos.txtCoeficiente.value='';
	ajax_dinamic('formAtribuicaoComposicaoElementos','../retorno_ajax/filtro_atrib.php?CTL='+CTL+'&filtro_todos=filtro_todos&focusedpai='+papa+'&focusedpai2='+papa+'&filho='+filho+'&newdelete=1','retorno_inserindo','','','',0,'',0,'','');
	
	
}


function list_dados(genero)
{
var CTL = document.formAtribuicaoComposicaoElementos.ctlhid.value;

ajax_dinamic('formAtribuicaoComposicaoElementos','../retorno_ajax/filtcombo.php?CTL='+CTL+'&filtro_todos=filtro_todos&genero='+genero+'','combo2','','','',0,'',0,'','');
}

function list_dados_elemento(genero)
{
var CTL = document.formItemEtapa.ctlhid.value;

ajax_dinamic('formItemEtapa','../retorno_ajax/filtcombo.php?CTL='+CTL+'&filtro_todos=filtro_todos&genero='+genero+'','combo2','','','',0,'',0,'','');
}

function list_dados_caracteristica(genero)
{
var CTL = document.formCaracteristica.ctlhid.value;
document.formCaracteristica.cboGenero.value=genero;
ajax_dinamic('formCaracteristica','../retorno_ajax/filtcombo_tpchar.php?CTL='+CTL+'&filtro_todos=filtro_todos&genero='+genero+'','combo2','','','',0,'',0,'','');
}

function list_dados_caracteristica2(genero,tipochar)
{
var CTL = document.formCaracteristica.ctlhid.value;
document.formCaracteristica.cboGenero.value=genero;

ajax_dinamic('formCaracteristica','../retorno_ajax/filtcombo_tpchar.php?CTL='+CTL+'&filtro_todos=filtro_todos&tipochar='+tipochar+'&genero='+genero+'','combo2','','','',0,'',0,'','');
}
// FIM

// INICIO BLOCO CARACTERISTICA

function transferchar(valor)
{
	document.formAtribuicaoCaracteristicasElementosConceitos.txtAtribuicao.value='';
	document.formAtribuicaoCaracteristicasElementosConceitos.txtAtribuicao.focus();

	document.formAtribuicaoCaracteristicasElementosConceitos.hidselected.value=valor;

}

function GravarCaracteristica()
{
var CTL = document.formAtribuicaoCaracteristicasElementosConceitos.ctlhid.value;
var papa = document.formAtribuicaoCaracteristicasElementosConceitos.papahid.value;
var filho = document.formAtribuicaoCaracteristicasElementosConceitos.hidselected.value;
var atrib = document.formAtribuicaoCaracteristicasElementosConceitos.txtAtribuicao.value;
var tipo_char = document.formAtribuicaoCaracteristicasElementosConceitos.tipo_char.value;

	if(atrib == '')
	{
	alert ("Por favor, digite o Valor de Atribuição.");
	document.formAtribuicaoCaracteristicasElementosConceitos.txtAtribuicao.focus();
	}
	if(atrib != '')
	{
	document.formAtribuicaoCaracteristicasElementosConceitos.txtAtribuicao.value='';
	ajax_dinamic('formAtribuicaoCaracteristicasElementosConceitos','../retorno_ajax/filtro_charright.php?CTL='+CTL+'&filtro_todos=filtro_todos&pai='+papa+'&focusedpai='+papa+'&filho='+filho+'&newsave=1&tipo_char='+tipo_char+'&atrib='+atrib+'','retorno_inserindo2','','','',0,'',0,'','');
	}

 
}

function transferchar2(valor)
{

	document.formAtribuicaoCaracteristicasElementosConceitos.hidselected.value=valor;
}

function ApagarCaracteristica()
{
	var CTL = document.formAtribuicaoCaracteristicasElementosConceitos.ctlhid.value;
	var papa = document.formAtribuicaoCaracteristicasElementosConceitos.papahid.value;
	var filho = document.formAtribuicaoCaracteristicasElementosConceitos.hidselected.value;
	var tipo_char = document.formAtribuicaoCaracteristicasElementosConceitos.tipo_char.value;
	document.formAtribuicaoCaracteristicasElementosConceitos.txtAtribuicao.value='';
	ajax_dinamic('formAtribuicaoCaracteristicasElementosConceitos','../retorno_ajax/filtro_charleft.php?CTL='+CTL+'&filtro_todos=filtro_todos&focusedpai='+papa+'&focusedpai2='+papa+'&filho='+filho+'&newdelete=1&tipo_char='+tipo_char+'','retorno_inserindo','','','',0,'',0,'','');
}

// fim do bloco
// inicio BLOCO ANEXOS
function transferanexo(valor)
{
	document.formAnexoElementoConceito.hidselected.value=valor;
}
function transferanexo2(valor)
{

	document.formAnexoElementoConceito.hidselected.value=valor;
}

// fix pagina funcionario
function indicausuario(indicacao)
{
	if(indicacao == 'N')
	{
	document.formFuncionario.rdbIndUsuario2.checked=1;
	nao();
	}
	if(indicacao == 'S')
	{
	document.formFuncionario.rdbIndUsuario1.checked=1;
	sim();
	}


}

//Função para Limpar campos do form Funcionário
function LimpaFuncionario()
	{
		var input       = document.getElementsByTagName('input')
		var select      = document.getElementsByTagName('select')
		var textarea    = document.getElementsByTagName('textarea')
		
		/*for(var i=0; i<select.length; i++)
			select[i].selectedIndex = 0;*/
			
		for(var i=0; i<textarea.length; i++)
			textarea[i].value = '';
					   
		for(var i=0; i<input.length; i++)
			switch (input[i].type)
			{
				case 'text':
				if(input[i].disabled == false)
				{
					input[i].value      = '';
				}
				
				break;
				case 'radio'    :   input[i].checked    = ''; 
				break;
				case 'checkbox' :   input[i].checked    = ''; 
				break;
			}
			
	     document.getElementById("txtSenha").value = ""
		 document.getElementById("cboUnidadeOrganizacional").value = "0"
		 document.getElementById("cboCargo").value = "0"
		 document.getElementById("cboIdioma").value = "0"
		 document.getElementById("cboUnidadeOrganizacional").value = "0"
	     document.getElementById('btnAlterar').disabled=true;
		 document.getElementById('btnExcluir').disabled=true;
	}

//Função para Limpar campos do form Cargo
function LimpaCargo()
	{
		var input       = document.getElementsByTagName('input')
		var select       = document.getElementsByTagName('select')
		var textarea     = document.getElementsByTagName('textarea')
		
		/*for(var i=0; i<select.length; i++)
			select[i].selectedIndex = 0;*/
			
		for(var i=0; i<textarea.length; i++)
			textarea[i].value = '';
					   
		for(var i=0; i<input.length; i++)
			switch (input[i].type)
			{
				case 'text':
				if(input[i].disabled == false)
				{
					input[i].value      = '';
				}
				
				break;
				case 'radio'    :   input[i].checked    = ''; 
				break;
				case 'checkbox' :   input[i].checked    = ''; 
				break;
			}
			
		 document.getElementById('btnAlterar').disabled=true;
		 document.getElementById('btnExcluir').disabled=true;
	}

//Função para Limpar campos do form Organizacao
function LimpaOrganizacao()
	{
		var input       = document.getElementsByTagName('input')
		var select      = document.getElementsByTagName('select')
		var textarea    = document.getElementsByTagName('textarea')
		
		/*for(var i=0; i<select.length; i++)
			select[i].selectedIndex = 0;*/
			
		for(var i=0; i<textarea.length; i++)
			textarea[i].value = '';
					   
		for(var i=0; i<input.length; i++)
			switch (input[i].type)
			{
				case 'text':
				if(input[i].disabled == false)
				{
					input[i].value      = '';
				}
				
				break;
				case 'radio'    :   input[i].checked    = ''; 
				break;
				case 'checkbox' :   input[i].checked    = ''; 
				break;
			}
			
			 document.getElementById("cboUnidOrg").value = "0"
			 document.getElementById("cboFuncionario").value = "0"
			 document.getElementById("txtDataInicio").value = ""
			 document.getElementById("txtDataFim").value = ""
			 document.getElementById('btnAlterar').disabled=true;
			 document.getElementById('btnExcluir').disabled=true;
	}


/////////////////////////////////////////////////////////////
// fix radios caracteristica
/////////////////////////////////////////////////////////////

function indicaref(indicacao,indicacao2)
{
	if(indicacao == 1)
	{
		document.formCaracteristica.rdbRefrenciaElementoTipo1.checked=1;
	}
	if(indicacao == 0)
	{
		document.formCaracteristica.rdbRefrenciaElementoTipo2.checked=1;
	}

	if(indicacao2 == 1)
	{
		document.formCaracteristica.radiobuttonSinal1.checked=1;
	}
	if(indicacao2 == 0)
	{
		document.formCaracteristica.radiobuttonSinal2.checked=1;
	}
}
/////////////////////////////////////////////////////////////



///////////////////////////////////////////////////////////////////////
// INICIO BLOCO CARACTERISTICA

function transferchare(valor)
{
	document.formAtribuicaoCaracteristicasElementosConceitos.txtAtribuicao.value='';
	document.formAtribuicaoCaracteristicasElementosConceitos.txtAtribuicao.focus();
	document.formAtribuicaoCaracteristicasElementosConceitos.hidselected.value=valor;
}

/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////
// Grava Caracteristicae
/////////////////////////////////////////////////////////////

function GravarCaracteristicae()
{
	var CTL 		= document.formAtribuicaoCaracteristicasElementosConceitos.ctlhid.value;
	var papa 		= document.formAtribuicaoCaracteristicasElementosConceitos.papahid.value;
	var filho 		= document.formAtribuicaoCaracteristicasElementosConceitos.hidselected.value;
	var atrib 		= document.formAtribuicaoCaracteristicasElementosConceitos.txtAtribuicao.value;
	var tipo_char 	= document.formAtribuicaoCaracteristicasElementosConceitos.tipo_char.value;

	if(atrib == '')
	{
	alert ("Por favor, digite o Valor de Atribuição.");
	document.formAtribuicaoCaracteristicasElementosConceitos.txtAtribuicao.focus();
	}
	if(atrib != '')
	{
	document.formAtribuicaoCaracteristicasElementosConceitos.txtAtribuicao.value='';
	ajax_dinamic('formAtribuicaoCaracteristicasElementosConceitos','../retorno_ajax/filtro_e_charright.php?CTL='+CTL+'&filtro_todos=filtro_todos&pai='+papa+'&focusedpai='+papa+'&filho='+filho+'&newsave=1&tipo_char='+tipo_char+'&atrib='+atrib+'','retorno_inserindo2','','','',0,'',0,'','');
	}
}

/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////
// Transferencia 2e.
/////////////////////////////////////////////////////////////

function transferchar2e(valor)
{
	document.formAtribuicaoCaracteristicasElementosConceitos.hidselected.value=valor;
}

/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////
// ApagarCaracteristicae
/////////////////////////////////////////////////////////////

function ApagarCaracteristicae()
{
	var CTL = document.formAtribuicaoCaracteristicasElementosConceitos.ctlhid.value;
	var papa = document.formAtribuicaoCaracteristicasElementosConceitos.papahid.value;
	var filho = document.formAtribuicaoCaracteristicasElementosConceitos.hidselected.value;
	var tipo_char = document.formAtribuicaoCaracteristicasElementosConceitos.tipo_char.value;
	document.formAtribuicaoCaracteristicasElementosConceitos.txtAtribuicao.value='';
	ajax_dinamic('formAtribuicaoCaracteristicasElementosConceitos','../retorno_ajax/filtro_e_charleft.php?CTL='+CTL+'&filtro_todos=filtro_todos&focusedpai='+papa+'&focusedpai2='+papa+'&filho='+filho+'&newdelete=1&tipo_char='+tipo_char+'','retorno_inserindo','','','',0,'',0,'','');
}

/////////////////////////////////////////////////////////////

// REMOVER UMA RELACAO MANUALMENTE ENTER ELEMENTO E CONCEITO
function delete_eve(valor)
{

	document.formItemEtapa.hidselected.value=valor;
}
function apagar_eve()
{
	var CTL = document.formItemEtapa.ctlhid.value;
	var papa = document.formItemEtapa.papahid.value;
	ajax_dinamic('formItemEtapa','../retorno_ajax/filtro_element_assoc.php?CTL='+CTL+'&filtro_todos=filtro_todos&focusedpai='+papa+'','retorno_inserindo2','','','',0,'',0,'','');
	ajax_dinamic('formItemEtapa','../retorno_ajax/filtro_element_list.php?CTL='+CTL+'&filtro_todos=filtro_todos&focusedpai='+papa+'&delete=delete','retorno_inserindo','','','',0,'',0,'','');
}

// ADICIONAR RELACAO MANUALMENTE ENTER ELEMENTO E CONCEITO

function novo_eve(valor,pai)
{
	document.formItemEtapa.hidselected.value=valor;
	document.formItemEtapa.papahid.value=pai;
}

function adiciona_eve()
{
	var CTL = document.formItemEtapa.ctlhid.value;
	var papa = document.formItemEtapa.papahid.value;
	var filho = document.formItemEtapa.hidselected.value;
	ajax_dinamic('formItemEtapa','../retorno_ajax/filtro_element_list.php?CTL='+CTL+'&filtro_todos=filtro_todos&filho='+filho+'&focusedpai='+papa+'&adiciona=adiciona','retorno_inserindo','','','',0,'',0,'','');
	ajax_dinamic('formItemEtapa','../retorno_ajax/filtro_element_assoc.php?CTL='+CTL+'&filtro_todos=filtro_todos&focusedpai='+papa+'','retorno_inserindo2','','','',0,'',0,'','');
}


// ==================================================================
// Mautone
// Validacao da Hora de acordo padrao Brasileiro
// ==================================================================

function mascara_hora(Hora,strForm)
{
	
	var hora01 	= '';
	hora01 = hora01 + Hora;
	
	if (hora01.length == 2)
	{ 
		hora01 = hora01 + ':'; 
		document.getElementById(strForm).value = hora01;
	}
	
	if (hora01.length == 5)
	{ 
		Verifica_Hora(strForm);
	}
	
} 

function Verifica_Hora(strForm)
{
	var strForm;
	
	hrs = (document.getElementById(strForm).value.substring(0,2));
	min = (document.getElementById(strForm).value.substring(3,5));
	
	estado = ""; 
	if ((hrs < 00 ) || (hrs > 23) || ( min < 00) ||( min > 59))
	{ 
		estado = "errada"; 
	} 

	if (document.getElementById(strForm).value == "")
	{
		estado = "errada";
	}
	if (estado == "errada")
	{ 
		alert("Hora invalida!"); 
		document.getElementById(strForm).focus(); 
	} 
	
} 

// ==================================================================

function GravarAnexos()
{
	var CTL = document.formAnexoElementoConceito.ctlhid.value;
	var papa = document.formAnexoElementoConceito.papahid.value;
	var filho = document.formAnexoElementoConceito.hidselected.value;
	ajax_dinamic('formAnexoElementoConceito','../retorno_ajax/filtro_anexo_elem_right.php?CTL='+CTL+'&filtro_todos=filtro_todos&pai='+papa+'&focusedpai='+papa+'&filho='+filho+'&newsave=1','retorno_inserindo2','','','',0,'',0,'','');
}

function ApagarAnexos()
{
	var CTL 	= document.formAnexoElementoConceito.ctlhid.value;
	var papa 	= document.formAnexoElementoConceito.papahid.value;
	var filho 	= document.formAnexoElementoConceito.hidselected.value;
	ajax_dinamic('formAnexoElementoConceito','../retorno_ajax/filtro_anexo_elem_left.php?CTL='+CTL+'&filtro_todos=filtro_todos&focusedpai='+papa+'&focusedpai2='+papa+'&filho='+filho+'&newdelete=1','retorno_inserindo','','','',0,'',0,'','');
}


function list_tipo_char(genero)
{
	var CTL = document.formAtribuicaoCaracteristicasElementosConceitos.ctlhid.value;
	ajax_dinamic('formAtribuicaoCaracteristicasElementosConceitos','../retorno_ajax/filtcombo_tpchar.php?CTL='+CTL+'&filtro_todos=filtro_todos&genero='+genero+'','combo2','','','',0,'',0,'','');
}

function list_estado(pais, estado)
{
	var CTL = document.formItemEtapa.ctlhid.value;
	ajax_dinamic('formItemEtapa','../retorno_ajax/filtcombo_estado.php?CTL='+CTL+'&filtro_todos=filtro_todos&estado='+estado+'&pais='+pais+'','estado','','','',0,'',0,'','');
}

function list_cidade(estado, cidade)
{
	var CTL = document.formItemEtapa.ctlhid.value;
	ajax_dinamic('formItemEtapa','../retorno_ajax/filtcombo_cidade.php?CTL='+CTL+'&filtro_todos=filtro_todos&cidade='+cidade+'&estado='+estado+'','cidade','','','',0,'',0,'','');
}

function list_zona(cidade, zona)
{
	var CTL = document.formItemEtapa.ctlhid.value;
	ajax_dinamic('formItemEtapa','../retorno_ajax/filtcombo_zona.php?CTL='+CTL+'&filtro_todos=filtro_todos&zona='+zona+'&cidade='+cidade+'','zona','','','',0,'',0,'','');
}




// ==================================================================
// Mautone
// Funcao para Validar Emails do sistema
// ==================================================================

function checkMail(mail)
{
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    
	if(typeof(mail) == "string")
	{
        if(er.test(mail))
		{ 
			return true; 
		}
    }
	else if(typeof(mail) == "object")
	{
        if(er.test(mail.value))
		{ 
           return true; 
        }
    }
	else
	{
        return false;
    }
}

function open_popup(strPage,width,height,vw_vars)
{

	var wk_feat = 'unadorned:yes;status:no;center:yes;help:no;minimize:no;maximize:no;scroll:yes;border:thin;statusbar:no;dialogWidth:'+width+'px;dialogHeight:'+height+'px';
	var wk_titu = 'ORIA FOODS RESTAURANTE'
	var ranNum 	= Math.floor(Math.random()*372766);

	var retn        = self.showModalDialog(strPage+"?ctl=" + ranNum + vw_vars, wk_titu, wk_feat)
	//window.open(strPage+"?ctl=" + ranNum,"Produtos")
	return
}


