	function opacity(id, opacStart, opacEnd, millisec) {
		//speed for each frame
		var speed = Math.round(millisec / 100);
		var timer = 0;
	
		//determine the direction for the blending, if start and end are the same nothing happens
		if(opacStart > opacEnd) {
			for(i = opacStart; i >= opacEnd; i--) {
				setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
				timer++;
			}
			//document.getElementById(id).style.display = 'none';
		} else if(opacStart < opacEnd) {
			for(i = opacStart; i <= opacEnd; i++)
				{
				setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
				timer++;
			}
		}
	
	}
	
	//change the opacity for different browsers
	function changeOpac(opacity, id) {
		var object = document.getElementById(id).style;
		object.opacity = (opacity / 100);
		object.MozOpacity = (opacity / 100);
		object.KhtmlOpacity = (opacity / 100);
		object.filter = "alpha(opacity=" + opacity + ")";
		if(opacity > 0) document.getElementById(id).style.display = 'block';
		else document.getElementById(id).style.display = 'none';
	} 
	
	function writeFlash(url_root, width, height, bgcolor, version, name) {
		if (version == null || version == ''){
			version = '7,0,0,0';
		}
		document.writeln("<object name='"+name+"' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'");
		document.writeln(" codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="+version+"' ");
		document.writeln(" width='"+width+"' height='"+height+"'> ");
		document.writeln("<param name='movie' value='"+url_root+"'>");
		document.writeln("<param name='quality' value='high'>");
		document.writeln("<param name='menu' value='false'>");
		document.writeln("<param name='bgcolor' value='#"+bgcolor+"'>");
		if (bgcolor == null || bgcolor == 'FFFFFF'){
			document.writeln("<param name='wmode' value='transparent'>");
		}
		document.writeln("<embed src='"+url_root+"' ");
		if (bgcolor == null || bgcolor == 'FFFFFF'){
			document.writeln(" wmode='transparent' ");
		}
		
		document.writeln(" quality='high' bgcolor='#"+bgcolor+"'  width='"+width+"' height='"+height+"' ");
		document.writeln(" type='application/x-shockwave-flash' ");
		document.writeln(" pluginspage='http://www.macromedia.com/shockwav/download/index.cgi?P1_Prod_Version=ShockwaveFlash'");
		document.writeln(" menu='false'>");
		document.writeln("</embed></object>");
	}
	
/*--------------------------------------------------------------------------------------------------------------------------------------*/;

	function isset(pVariavel) {     
		var undefined;     
		return (pVariavel == undefined?false:true); 
	}

	function isArray(pVariavel) {
		if (isset(pVariavel)) {
			lArray = new Array();
			return (typeof(lArray) == typeof(pVariavel)); 
		} else {
			return false;
		}
	}
	
	function AJAX(pMesagemAJAX, pNomeObjeto){
		this.lMensagemAJAX = pMesagemAJAX;
		this.lNomeObjeto   = pNomeObjeto;
		
		// Inicializa o XHTMLHTTPRequest
		try{
			try {
				netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
			} catch (e) {
			}
			lXMLHTTP = new XMLHttpRequest();
		}catch(ee){
			try{
				lXMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");
			}catch(e){
				try{
					lXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
				}catch(E){
					lXMLHTTP = false;
				}
			}
		}
		
		this.retornaValorArray = function(pVariavel, pPosicao) {
			if (isArray(pVariavel)) {
				return pVariavel[pPosicao];
			} else {
				return pVariavel;
			}
		}
		
		// Carrega a URL;
		/**
		 * Função que carrega uma pagina em qualquer objeto des de que aceite innerHTML
		 * pURL 				-> Texto com a url a ser carregada ou com um array de url.
		 * pDIV 			 	-> Texto com o id da div a ser carregada
		 * pFlagCarregamento	-> Flag para exibição da mensagem definida
		 						-> 0 => Não exibe nenhuma mensagem;
								-> 1 => Apaga conteudo e exibe a mensagem definida;
								-> 2 => Concatena uma div ao conteudo e exibe a mensagem definida;
								-> 3 => Apaga o centeudo e deixa em branco até carregar a url solicitada;
		 * pCursorStyle			-> Texto com o cursor em css EX: 'progress' ou null se não for alterado o cursor durante o carregamento
		 * pMetodo				-> Texto com o metodo de envio
		 						-> 'get'  => quando for solicitada uma página
		 						-> 'post' => quando for para submeter um formulário
		 * pForm				-> Texto com o ID do form caso seja post
		 * pScriptExecutavel	-> Texto com um script qualquer para exibir o que foi carregado document.getElementById("NOME DO CAMPO TEXT").value = lTexto;
		 * pPosicao				-> null se for passada uma string no pURL e 0(zero) caso seja passado um array
		 * 
		 * OBS -> todos os parametros podem ser passados como vetor des de que tenham o mesmo tamnaho do vetor do pURI
		 */;
		this.carregaURL = function(pURL, pDIV, pFlagCarregamento, pCursorStyle, pMetodo, pForm, pScriptExecutavel, pPosicao) {
			
			lCarregado = false;
			
			lMensagemAJAX = this.lMensagemAJAX;
			lNomeObjeto = this.lNomeObjeto; 
			
			if (pPosicao == null) {
				lPosicao = 0;
			} else {
				lPosicao = pPosicao;
			}
			
			lURL = this.retornaValorArray(pURL, lPosicao);
			lDIV = this.retornaValorArray(pDIV, lPosicao);
			lFlagCarregamento = this.retornaValorArray(pFlagCarregamento, lPosicao);
			lCursorStyle = this.retornaValorArray(pCursorStyle, lPosicao);
			lMetodo = this.retornaValorArray(pMetodo, lPosicao);
			lForm = this.retornaValorArray(pForm, lPosicao);
			lScriptExecutavel = this.retornaValorArray(pScriptExecutavel, lPosicao);
			
			lSend = null;
			
			if (lMetodo == 'post') {
				lSend = this.getForm(lForm);
			}
			
			//Exibe o lTexto carregando no div conteúdo
			lDIVConteudo = document.getElementById(lDIV);

			this.selecionaCarregamento(lDIVConteudo, lFlagCarregamento, lCursorStyle);
	
			//Abre a url
			lXMLHTTP.open(lMetodo, lURL, true);
			
			if (lMetodo == 'post') {
				lXMLHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			}
							
			//Executada quando o navegador obtiver o código
			lXMLHTTP.onreadystatechange = function() {
				if (lXMLHTTP.readyState == 4){
					//Lê o lTexto
					lTexto = lXMLHTTP.responseText;
		
					//Desfaz o urlencode do php
					lTexto = lTexto.replace(/\+/g," ");
					lTexto = unescape(lTexto);
					
					//Exibe o lTexto na div conteúdo
					lDIVConteudo.innerHTML = lTexto;
					document.body.style.cursor = 'auto';
					
					if(lScriptExecutavel != null) {
						eval(lScriptExecutavel);
					}	
					
					if (isArray(pURL)) {
						if ((pPosicao != null) && (pURL.length > pPosicao+1)) {
							if (isArray(pURL)) { lpUrl = 'Array(' + insereAspa(pURL) + ')'; } else { lpUrl = '\'' + pURL + '\''; }
							if (isArray(pDIV)) { lpDIV = 'Array(' + insereAspa(pDIV) + ')'; } else { lpDIV = '\'' + pDIV + '\''; }

							if (isArray(pFlagCarregamento)) { lpFlagCarregamento = 'Array(' + pFlagCarregamento + ')'; } else { lpFlagCarregamento = pFlagCarregamento; }
							if (isArray(pCursorStyle)) { lpCursorStyle = 'Array(' + insereAspa(pCursorStyle) + ')'; } else { lpCursorStyle = '\'' + pCursorStyle + '\''; }
							if (isArray(pMetodo)) { lpMetodo = 'Array(' + insereAspa(pMetodo) + ')'; } else { lpMetodo = '\'' + pMetodo + '\''; }
							if (isArray(pForm)) { lpForm = 'Array(' + insereAspa(pForm) + ')'; } else { lpForm = '\'' + pForm + '\''; }
							if (isArray(pScriptExecutavel)) { lpScriptExecutavel = 'Array(' + insereAspa(pScriptExecutavel) + ')'; } else { lpScriptExecutavel = '\'' + pScriptExecutavel + '\''; }
							eval(lNomeObjeto + '.carregaURL(' + lpUrl + ',' + lpDIV + ',' + lpFlagCarregamento + ',' + lpCursorStyle + ',' + lpMetodo + ',' + lpForm + ',' + lpScriptExecutavel + ',' + (pPosicao+1) + ');');
						}
					}
				}
			}
			
			lXMLHTTP.send(lSend);
		}
				
		this.getForm = function(pFormulario){
			lStringForm = '';
			//Faz um laço através dos Inputs contidos no FORM. (coleção Elements) 
			lFormulario = document.getElementById(pFormulario);
			for(a=0; a<lFormulario.elements.length; a++){ 
				if((lFormulario.elements[a].disabled == false)&&(lFormulario.elements[a].type != 'submit')){
					lStringForm = lFormulario.elements[a].name + '=' + escape(lFormulario.elements[a].value) + '&' + lStringForm ;
				}
			}  
			return lStringForm;
		}
		
		this.insereAspa = function(pArray,pContrabarra) {
			lArrayRetorno = Array();
			for (a=0; a<pArray.length; a++) {
					if ((pArray[a]!= null) && (pArray[a]!= true) && (pArray[a]!= false)) {
						if (pContrabarra) {
							lArrayRetorno[a] = '\\\'' + pArray[a] + '\\\'';
						} else {
							lArrayRetorno[a] = '\'' + pArray[a] + '\'';							
						}
					} else {
						lArrayRetorno[a] = pArray[a]; 
					}
			}
			return lArrayRetorno;
		}
		
		this.popupAJAX = function(pDiv, pId, pClass) {
			lDIVConteudo = document.getElementById(pDiv);
			if (document.getElementById(pId)) {
				document.getElementById(pId).style.display = '';
				return true;
			} else {
				lInsere = '<div id="' + pId + '">';
				if(pClass != null) {
					  lInsere += ' class="' + pClass + '"';
				}
				lInsere += '></div>';
				
				lDIVConteudo.innerHTML += lInsere;
				return true;
			}
			
		}
		
		this.selecionaCarregamento = function (pDivConteudo, pFlagCarregamento, pCursorStyle) {
			lMensagemAJAX = this.lMensagemAJAX;
			
			if (pFlagCarregamento == 1) {
				pDivConteudo.innerHTML = '<div id="carregandoajax_' + pDivConteudo.id + '" class="carregandoajax1"><span>' + lMensagemAJAX + '</span></div>';
			} else if (pFlagCarregamento == 2) {
				pDivConteudo.innerHTML = '<div id="carregandoajax_' + pDivConteudo.id + '" class="carregandoajax2"><span>' + lMensagemAJAX + '</span></div>' + pDivConteudo.innerHTML;
			} else if (pFlagCarregamento == 3) {
				pDivConteudo.innerHTML = '';
			}
			if (pCursorStyle != null) {
				document.body.style.cursor = pCursorStyle;
			}
		}
	}
	
/*--------------------------------------------------------------------------------------------------------------------------------------*/

	function redirecionaAJAX(pListaURI,pPosicao,pParametros) {
		lAJAXRedirecionador = new AJAX("Carregando");
		pParametro = pParametros;
		this.insereAspa = function(pArray,pContrabarra) {
			lArrayRetorno = Array();
			for (a=0; a<pArray.length; a++) {
					if ((pArray[a]!= null) && (pArray[a]!= true) && (pArray[a]!= false)) {
						if (pContrabarra) {
							lArrayRetorno[a] = '\\\'' + pArray[a] + '\\\'';
						} else {
							lArrayRetorno[a] = '\'' + pArray[a] + '\'';							
						}
					} else {
						lArrayRetorno[a] = pArray[a]; 
					}
			}
			return lArrayRetorno;
		}

		pParametro =  this.insereAspa(pParametro,false);
		if ((pPosicao+1) < pListaURI.length) {
			pPosicao1 = pPosicao + 1;
			pParametro[pParametro.length] = '\'redirecionaAJAX(Array(' + insereAspa(pListaURI,true) + '),' + pPosicao1 + ',Array(' + insereAspa(pParametros,true) + '))\'';
		} else {
			pParametro[pParametro.length] = 'null';
		}

		pListaURI =  this.insereAspa(pListaURI,false);
		
		eval('lAJAXRedirecionador.carregaURL(' + pListaURI[pPosicao] + ',' + pParametro + ');');
	}
	
/*--------------------------------------------------------------------------------------------------------------------------------------*/;


	/*
	 * Função de validação e formatação de campos(máscara)
	 * obj 		-> Objeto que deseja aplicar a máscara
  	 * str 		-> String que deseja usar.
  	 * strone	-> Realizar ou não a validação.
	 * mask 	-> Texto que representa o nome do objeto que representa o radio. 	 
	 */

	MaskData    	= "  /  /    ";
	MasKCPF			= "   .   .   -  ";
	MasKCNPJ		= "  .   .   /    -  ";
	MaskCEP			= "     -   ";
	MaskHora   		= "  :  ";
	MaskMonetario   = " .   .   .   ,    ";
	
		
	StrAlfaMin		= "abcdefghijklmnopqrstuvwxyz";
	StrAlfaMai		= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	StrNumeros 		= "0123456789";
	StrTodos		= "abcdefghijklmnopqrstuvwxyz. ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789{}[]<>,.;:?/ºª²³¹|\áéíóúÁÉÍÓÚãõÃÕâêîôûÂÊÎÔÛäëïöüÄËÏÖÜàèìòùÀÈÌÒÙçÇ";
	StrEmail   		= "abcdefghijklmnopqrstuvwxyz_-.0123456789";
	StrTelefones 	= "()-x+ 0123456789";
		
	ChrEmail  	= "@";
	ChrBarra   	= "/";
	ChrVirgula 	= ",";
	ChrPonto 	= ".";

	function validaTecla(obj,str,strone,mask) {
		code = (window.Event) ? event.which : event.keyCode;
		mykey=String.fromCharCode(code);
		if(code==8 || code==9 || code==13) return true;
		if ( ( ( str.indexOf(mykey)==-1 & strone.indexOf(mykey)==-1 ) || 
		( obj.value.indexOf(mykey)!=-1 & strone.indexOf(mykey)!=-1) )) return false; 
		else {
			tam=obj.value.length;
			submask=mask.substr(tam,mask.length-tam);
			while (submask.indexOf(' ')!=-1 && submask.indexOf(' ')!=0) {
				obj.value=obj.value+submask.charAt(0);
				tam++;
				submask=mask.substr(tam,mask.length-tam);
			}
			if(obj.value.length<mask.length || mask.length==0) return true; 
			else {
				if(obj.value.length>mask.length) obj.value=obj.value.substr(0,mask.length);
				return false;
			}
		}
	}
