//-----------------------------------------------------------------------------------
// Criado: 20/08/2004 - TTakahase
// Modificado: 11/06/2005 - TTakahase
//
// Para utilizar estes scripts, defina na tag BODY nos forms as seguintes
// propriedades:
//   onload="Intecma_OnLoad(event)"
//   onresize="Intecma_OnResize(event)"
//   onunload="Intecma_OnUnload(event)"
//   onclick="Intecma_OnClick(event)"
//
//-----------------------------------------------------------------------------------
//
//
//
//
//
//
//
//
//
//				CONSTANTES
//
//
//
//
//
//
//
//
//
//-----------------------------------------------------------------------------------
var COOKIE_INTECMA="intecmalib";
var COOKIE_DIV_SCROLL_LOCK="DivScrollLock";
var COOKIE_FOCUS_LOCK="FocusLock";
//-----------------------------------------------------------------------------------
//
//
//
//
//
//
//
//
//
//				VARIÁVEIS GLOBAIS
//
//
//
//
//
//
//
//
//
//-----------------------------------------------------------------------------------
// Facilidade para testar o browser
var GboIsMSIE=(window.navigator.appName=="Microsoft Internet Explorer");
// Array de funções onload()
var GvpOnLoad=null;
// Array de funções onresize()
var GvpOnResize=null;
// Array de funções onunload()
var GvpOnUnload=null;
// Array de funções onclick()
var GvpOnClick=null;
// Determina se TODOS os Divs terão persistência no scroll.
// Chame a função Intecma_SetDivScrollLock() para alterar o valor desta variável.
var GboDivScrollLock=false;
// Determina a persistência de foco nos controles.
// Chame a função Intecma_SetFocuslLock() para alterar o valor desta variável.
var GboFocusLock=false;
// Variável que se contiver um ID válido, este controle receberá foco durante
// o evento onLoad.
var GpcFocusCtrl=null;
// Utilizado para evitar que a persistência de foco retire o foco das janelas
// pop-up. Retorna para false no final do evento onLoad.
var GboAvoidFocusOnce=false;
//-----------------------------------------------------------------------------------
//
//
//
//
//
//
//
//
//
//				FUNÇÕES DE GERÊNCIAMENTO DA IntecmaLib ©
//
//
//
//
//
//
//
//
//
//-----------------------------------------------------------------------------------
// Função integradora para ser usada no body.onload.
// Esta função varre o array de funções onload(), permitindo assim que sejam
// especificadas n funções.
function Intecma_OnLoad(PoEvent)
{	if (GvpOnLoad!=null)
		for (i=0;i<GvpOnLoad.length;i++) GvpOnLoad[i](i,PoEvent);
	if (GboDivScrollLock) Intecma_DivScrollLockControl(true);
	if (GboAvoidFocusOnce==false)
	{	if (GboFocusLock) Intecma_FocusLockControl(true);
		if (GpcFocusCtrl!=null) Intecma_SetFocus(GpcFocusCtrl);
	} else GboAvoidFocusOnce=false;
}
//-----------------------------------------------------------------------------------
// Função integradora para ser usada no body.onresize.
// Esta função varre o array de funções onresize(), permitindo assim que sejam
// especificadas n funções.
function Intecma_OnResize(PoEvent)
{	if (GvpOnResize!=null)
		for (i=0;i<GvpOnResize.length;i++) GvpOnResize[i](i,PoEvent);
}
//-----------------------------------------------------------------------------------
// Função integradora para ser usada no body.onunload.
// Esta função varre o array de funções onunload(), permitindo assim que sejam
// especificadas n funções.
function Intecma_OnUnload(PoEvent)
{	if (GvpOnUnload!=null)
	{	for (i=0;i<GvpOnUnload.length;i++)
			GvpOnUnload[i](i,PoEvent);
	}
	if (GboDivScrollLock) Intecma_DivScrollLockControl(false);
	if (GboFocusLock) Intecma_FocusLockControl(false);
}
//-----------------------------------------------------------------------------------
// Função integradora para ser usada no body.onclick.
// Esta função varre o array de funções onclick(), permitindo assim que sejam
// especificadas n funções.
function Intecma_OnClick(PoEvent)
{	if (GvpOnClick!=null)
		for (i=0;i<GvpOnClick.length;i++) GvpOnClick[i](i,PoEvent);
}
//-----------------------------------------------------------------------------------
// Adiciona no array de funções onload(), para funcionar necessita que a
// função Intecma_OnLoad() seja chamada no onload() do body da página.
// O evento deve ser do seguinte formato XXXX(PiIndex,PoEvent)
function Intecma_AddOnLoadEvent(PpFunc)
{	if (GvpOnLoad==null) GvpOnLoad=new Array();
	GvpOnLoad[GvpOnLoad.length]=PpFunc;
}
//-----------------------------------------------------------------------------------
// Adiciona no array de funções onresize(), para funcionar necessita que a
// função Intecma_OnResize() seja chamada no onresize() do body da página.
// O evento deve ser do seguinte formato XXXX(PiIndex,PoEvent)
function Intecma_AddOnResizeEvent(PpFunc)
{	if (GvpOnResize==null) GvpOnResize=new Array();
	GvpOnResize[GvpOnResize.length]=PpFunc;
}
//-----------------------------------------------------------------------------------
// Adiciona no array de funções onunload(), para funcionar necessita que a
// função Intecma_OnUnload() seja chamada no onunload() do body da página.
// O evento deve ser do seguinte formato XXXX(PiIndex,PoEvent)
function Intecma_AddOnUnloadEvent(PpFunc)
{	if (GvpOnUnload==null) GvpOnUnload=new Array();
	GvpOnUnload[GvpOnUnload.length]=PpFunc;
}
//-----------------------------------------------------------------------------------
// Adiciona no array de funções onclick(), para funcionar necessita que a
// função Intecma_OnClick() seja chamada no onclick() do body da página.
// O evento deve ser do seguinte formato XXXX(PiIndex,PoEvent)
function Intecma_AddOnClickEvent(PpFunc)
{	if (GvpOnClick==null) GvpOnClick=new Array();
	GvpOnClick[GvpOnClick.length]=PpFunc;
}
//-----------------------------------------------------------------------------------
//
//
//
//
//
//
//
//
//
//				FUNÇÕES PARA CONTROLE DE FOCO E PERSISTÊNCIA
//
//
//
//
//
//
//
//
//
//-----------------------------------------------------------------------------------
// Ativa ou não a persistência de foco
function Intecma_SetFocusLock(PboSet)
{	GboFocusLock=PboSet;
}
//-----------------------------------------------------------------------------------
// Função interna
function Intecma_FocusLockControl(PboState)
{	if (PboState) //Load
	{	var LpcCookie;
		
		LpcCookie=Intecma_GetCookieIntecma(COOKIE_FOCUS_LOCK);
		if (LpcCookie!=null) Intecma_SetFocusObject(Intecma_GetObjectByID(LpcCookie));
	}
	else //Unload
	{ if ((document.activeElement!=null)&&(Intecma_IsNotEmpty(document.activeElement.id)))
			Intecma_SetCookieIntecma(COOKIE_FOCUS_LOCK,document.activeElement.id);
}	}
//-----------------------------------------------------------------------------------
// Determina se o controle pode receber foco
// Retorna:
//   true ou false
function Intecma_CanFocus(PoCtrl)
{	if (PoCtrl!=null)
	{	var LpcType=PoCtrl.tagName.toLowerCase();
		if ((LpcType=="select")||(LpcType=="input")||(LpcType=="textarea")||(LpcType=="a"))
		{	if ((PoCtrl.disabled==false)&&(PoCtrl.style.visibility.toLowerCase()!="hidden")
				&&((LpcType!="input")||(PoCtrl.type.toLowerCase()!="hidden")))
				return true;
	}	}
	return false;
}
//-----------------------------------------------------------------------------------
// Define o foco para determinado objeto (precisa ser controle focável)
function Intecma_SetFocusObject(PoCtrl)
{	if (Intecma_CanFocus(PoCtrl)) PoCtrl.focus();
}
//-----------------------------------------------------------------------------------
// Define o foco para um ID de controle
function Intecma_SetFocus(PpcCtrlID)
{	Intecma_SetFocusObject(Intecma_GetObjectByID(PpcCtrlID));
}
//-----------------------------------------------------------------------------------
// Passa o foco para o controle anterior ao PoActiveCtrl
function Intecma_PrevFocus(PoActiveCtrl)
{	if (PoActiveCtrl!=null)
	{	var LiCount=document.all.length;
		for (i=0;i<LiCount;i++)
			if (document.all[i]==PoActiveCtrl)
				for (i--;i>=0;i--)
					if (Intecma_CanFocus(document.all[i]))
					{	document.all[i].focus();
						return true;
					}
	}
	return false;
}
//-----------------------------------------------------------------------------------
// Passa o foco para o controle posterior ao PoActiveCtrl
function Intecma_NextFocus(PoActiveCtrl)
{	if (PoActiveCtrl!=null)
	{	var LiCount=document.all.length;
		for (i=0;i<LiCount;i++)
			if (document.all[i]==PoActiveCtrl)
				for (i++;i<LiCount;i++)
					if (Intecma_CanFocus(document.all[i]))
					{	document.all[i].focus();
						return true;
					}
	}
	return false;
}
//-----------------------------------------------------------------------------------
// Ativa ou não o controle de scroll dos DIVs
function Intecma_SetDivScrollLock(PboSet)
{	GboDivScrollLock=PboSet;
}
//-----------------------------------------------------------------------------------
// Função interna
function Intecma_DivScrollLockControl(PboState)
{	if (PboState) //Load
	{	var LpcCookie,LvpcDivs,LvpcEntry,LoDiv,LvpcSize;
		
		LpcCookie=Intecma_GetCookieIntecma(COOKIE_DIV_SCROLL_LOCK);
		if (LpcCookie!=null)
		{	LvpcDivs=LpcCookie.split("; ");
			for (i=LvpcDivs.length-1;i>=0;i--)
			{	LvpcEntry=LvpcDivs[i].split("=");
				LoDiv=Intecma_GetObjectByID(LvpcEntry[0]);
				if (LoDiv!=null)
				{	LvpcSize=LvpcEntry[1].split(",");
					if (LoDiv.scrollHeight>LoDiv.offsetHeight) LoDiv.scrollTop=LvpcSize[0];
					if (LoDiv.scrollWidth>LoDiv.offsetWidth) LoDiv.scrollLeft=LvpcSize[1];
	}	}	}	}
	else //Unload
	{ var LpcDivs="";
		var LvoDivs=document.getElementsByTagName('div');
		if (LvoDivs!=null)
		{	for (i=LvoDivs.length-1;i>=0;i--)
				if ((LvoDivs[i].scrollTop!=0)||(LvoDivs[i].scrollLeft))
					LpcDivs+=LvoDivs[i].id+"="+LvoDivs[i].scrollTop+","+LvoDivs[i].scrollLeft+"; ";
		}
		if (LpcDivs!="") LpcDivs=LpcDivs.substr(0,LpcDivs.length-2);
		else LpcDivs=null;
		Intecma_SetCookieIntecma(COOKIE_DIV_SCROLL_LOCK,LpcDivs);
}	}
//-----------------------------------------------------------------------------------
// Ativa ou desativa o controle de foco manual e automático pelo período do
// evento onLoad.
function Intecma_AvoidFocusOnce(PboState)
{	GboAvoidFocusOnce=PboState;
}
//-----------------------------------------------------------------------------------
//
//
//
//
//
//
//
//
//
//				FUNÇÕES PARA LOCALIZAR CONTROLES
//
//
//
//
//
//
//
//
//
//-----------------------------------------------------------------------------------
function Intecma_GetObjectByID(PpcID)
{	if (document.getElementById)
	{	var LoID=document.getElementById(PpcID);
		if (LoID) return LoID;
	}
  if ((document.all)&&(document.all(PpcID))) return document.all(PpcID);
  if ((document.layers)&&(document.layers[PpcID])) return document.layers[PpcID];
	return null;
}
//-----------------------------------------------------------------------------------
//
//
//
//
//
//
//
//
//
//				FUNÇÕES PARA MANIPULAR DADOS EM CONTROLES
//
//
//
//
//
//
//
//
//
//-----------------------------------------------------------------------------------
// Pega o indice do item selecionado de uma controle tipo lista
function Intecma_GetSelectedIndex(PpcCtrlID)
{	var LoDDL=Intecma_GetObjectByID(PpcCtrlID);
	if ((LoDDL!=null)&&(LoDDL.selectedIndex!=null)) return LoDDL.selectedIndex;
	return -1;
}
//-----------------------------------------------------------------------------------
// Pega o valor do item selecionado de uma controle tipo lista
function Intecma_GetSelectedValue(PpcCtrlID)
{	var LiIndex=Intecma_GetSelectedIndex(PpcCtrlID);
	if (LiIndex>=0) return Intecma_GetObjectByID(PpcCtrlID).options[LiIndex].value;
	return null;
}
//-----------------------------------------------------------------------------------
// Pega o índice do item selecionado de um CRadioButtonList (apenas NetFramework).
// O parâmetro precisa ser o ClientID do componente da NetFramework como no exemplo:
// Intecma_GetSelectedIndexRBL('<%= m_oMyRBL.ClientID %>')
function Intecma_GetSelectedIndexRBL(PpcCtrlID)
{	var LiIndex=0;
	var LoRB;
	
	while (true)
	{	LoRB=Intecma_GetObjectByID(PpcCtrlID+"_"+LiIndex);
		if (LoRB!=null)
		{	if (LoRB.status) return LiIndex;
			LiIndex++;
		} else break;
	}
	return -1;
}
//-----------------------------------------------------------------------------------
// Pega o valor do item selecionado de um CRadioButtonList (apenas NetFramework).
// O parâmetro precisa ser o ClientID do componente da NetFramework como no exemplo:
// Intecma_GetSelectedIndexRBL('<%= m_oMyRBL.ClientID %>')
function Intecma_GetSelectedValueRBL(PpcCtrlID)
{	var LiIndex=0;
	var LoRB;
	
	while (true)
	{	LoRB=Intecma_GetObjectByID(PpcCtrlID+"_"+LiIndex);
		if (LoRB!=null)
		{	if (LoRB.status) return LoRB.value;
			LiIndex++;
		} else break;
	}
	return null;
}
//-----------------------------------------------------------------------------------
// Verifica se o valor do controle não é null nem vazio retornando true
// nestas condições
function Intecma_IsNotFullEmptyControl(PpcCtrlID)
{	var LoCtrl=Intecma_GetObjectByID(PpcCtrlID);
	return ((LoCtrl!=null)&&(Intecma_IsNotFullEmpty(LoCtrl.value)));
}
//-----------------------------------------------------------------------------------
//
//
//
//
//
//
//
//
//
//				FUNÇÕES PARA ESTADO DE CONTROLES
//
//
//
//
//
//
//
//
//
//-----------------------------------------------------------------------------------
// Verifica se o controle está visível retornando true nesta condição
function Intecma_IsVisible(PpcCtrlID)
{	var LoFocus=Intecma_GetObjectByID(PpcCtrlID);
	if (LoFocus!=null) return (LoFocus.style.visibility.toLowerCase()!='hidden');
	return false;
}
//-----------------------------------------------------------------------------------
// Verifica se o controle está habilitado retornando true nesta condição
function Intecma_Enable(PpcCtrlID,PboEnable)
{	var LoCtrl=Intecma_GetObjectByID(PpcCtrlID);
	if (LoCtrl!=null) LoCtrl.disabled=!PboEnable;
}
//-----------------------------------------------------------------------------------
//
//
//
//
//
//
//
//
//
//				FUNÇÕES PARA POSICIONAMENTO DE CONTROLES
//
//
//
//
//
//
//
//
//
//-----------------------------------------------------------------------------------
// Retorna em pixels a posição Y do controle em relação a área visível do browser
function Intecma_GetOffsetTop(PoCtrl)
{	var LiReturn;
	
	LiReturn=0;
	while ((PoCtrl!=null)&&(PoCtrl.tagName!='FORM'))
	{	if ((PoCtrl.tagName!="TR")&&(PoCtrl.tagName!="TBODY")) LiReturn+=PoCtrl.offsetTop;
		PoCtrl=PoCtrl.parentElement;
	}
	return LiReturn;
}
//-----------------------------------------------------------------------------------
// Retorna em pixels a posição X do controle em relação a área visível do browser
function Intecma_GetOffsetLeft(PoCtrl)
{	var LiReturn;
	
	LiReturn=0;
	while ((PoCtrl!=null)&&(PoCtrl.tagName!='FORM'))
	{	if ((PoCtrl.tagName!="TR")&&(PoCtrl.tagName!="TBODY")) LiReturn+=PoCtrl.offsetLeft;
		PoCtrl=PoCtrl.parentElement;
	}
	return LiReturn;
}
//-----------------------------------------------------------------------------------
//
//
//
//
//
//
//
//
//
//				FUNÇÕES PARA COOKIES
//
//
//
//
//
//
//
//
//
//-----------------------------------------------------------------------------------
// Pega uma entrada de uma string tipo cookie
function Intecma_GetCookieLikeChunk(PpcChunk,PpcKey)
{	if ((Intecma_IsNotEmpty(PpcKey))&&(PpcChunk!=null))
	{	var LvpcCookie=PpcChunk.split("; ");
		if (LvpcCookie!=null)
		{	for (var i=LvpcCookie.length-1;i>=0;i--)
			{	var LvpcEntry=LvpcCookie[i].split("=");
				if (PpcKey==LvpcEntry[0])
				{	if ((LvpcEntry[1]!=null)&&(LvpcEntry[1]!="null")) return unescape(LvpcEntry[1]);
					break;
	}	}	}	}
	return null;
}
//-----------------------------------------------------------------------------------
// Seta uma entrada de uma string tipo cookie
// Se PpcName for null, então remove a entrada
function Intecma_SetCookieLikeChunk(PpcChunk,PpcKey,PpcValue)
{	if (Intecma_IsNotEmpty(PpcKey))
	{	var LvpcCookie,i,LpcEntry;
		
		if (PpcValue!=null) LpcEntry=PpcKey+"="+escape(PpcValue);
		else LpcEntry=null;
		if (PpcChunk!=null) LvpcCookie=PpcChunk.split("; ");
		else LvpcCookie=null;
		if (LvpcCookie!=null)
		{	for (i=LvpcCookie.length-1;i>=0;i--)
				if (PpcKey==LvpcCookie[i].split("=")[0]) break;
			if (i>=0)
			{	if (LpcEntry!=null) LvpcCookie[i]=LpcEntry;
				else LvpcCookie.splice(i,1);
				PpcChunk=LvpcCookie.join("; ");
			} else if (LpcEntry!=null) PpcChunk+="; "+LpcEntry;
		} else PpcChunk=LpcEntry;
	}
	return PpcChunk;
}
//-----------------------------------------------------------------------------------
// Pega uma entrada do cookie
function Intecma_GetCookie(PpcName)
{	return Intecma_GetCookieLikeChunk(document.cookie,PpcName);
}
//-----------------------------------------------------------------------------------
function Intecma_GetCookieIntecma(PpcKey)
{	if (Intecma_IsNotEmpty(PpcKey))
	{	var LpcChunk;

		if ((LpcChunk=Intecma_GetCookie(COOKIE_INTECMA))!=null)
			return Intecma_GetCookieLikeChunk(LpcChunk,PpcKey);
	}
	return null;
}
//-----------------------------------------------------------------------------------
// Seta uma entrada do cookie
function Intecma_SetCookie(PpcKey,PpcValue)
{	if (Intecma_IsNotEmpty(PpcKey)) document.cookie=PpcKey+"="+escape(PpcValue);
}
//-----------------------------------------------------------------------------------
function Intecma_SetCookieIntecma(PpcKey,PpcValue)
{	if (Intecma_IsNotEmpty(PpcKey))
		Intecma_SetCookie(COOKIE_INTECMA,Intecma_SetCookieLikeChunk(Intecma_GetCookie(COOKIE_INTECMA),PpcKey,PpcValue));
}
//-----------------------------------------------------------------------------------
//
//
//
//
//
//
//
//
//
//				FUNÇÕES PARA MANIPULAR STRINGS
//
//
//
//
//
//
//
//
//
//-----------------------------------------------------------------------------------
// Remove espaços a esquerda e caracteres 10 e 13 (LF e CR)
function Intecma_TrimLeft(PpcString)
{	if ((PpcString!=null)&&(PpcString.length>0))
	{	var i;
		for (i=0;i<PpcString.length;i++)
			if ((PpcString.charAt(i)!=' ')&&(PpcString.charAt(i)!='\n')&&(PpcString.charAt(i)!='\r')) break;
		if (i!=PpcString.length)
		{	if (i!=0) PpcString=PpcString.substr(i);
			return PpcString;
	}	}
	return null;
}
//-----------------------------------------------------------------------------------
// Remove espaços a direita e caracteres 10 e 13 (LF e CR)
function Intecma_TrimRight(PpcString)
{	if ((PpcString!=null)&&(PpcString.length>0))
	{	var i;
		for (i=PpcString.length-1;i>=0;i--)
			if ((PpcString.charAt(i)!=' ')&&(PpcString.charAt(i)!='\n')&&(PpcString.charAt(i)!='\r')) break;
		if (i!=-1)
		{	if (i!=PpcString.length-1) PpcString=PpcString.substring(0,i+1);
			return PpcString;
	}	}
	return null;
}
//-----------------------------------------------------------------------------------
function Intecma_Trim(PpcString)
{	return Intecma_TrimLeft(Intecma_TrimRight(PpcString));
}
//-----------------------------------------------------------------------------------
// Verifica se a string não é null nem vazio retornando true nestas condições
function Intecma_IsNotEmpty(PpcText)
{	return ((PpcText!=null)&&(PpcText.length>0));
}
//-----------------------------------------------------------------------------------
// Verifica se a string não é null nem vazio nem com somente espaços em branco
// retornando true nestas condições
function Intecma_IsNotFullEmpty(PpcText)
{	return ((Intecma_IsNotEmpty(PpcText))&&(Intecma_Trim(PpcText)!=null));
}
//-----------------------------------------------------------------------------------
function Intecma_GetDigitsOnly(PpcStr)
{	if (Intecma_IsNotEmpty(PpcStr))
	{	var LpcStr='',i;
		for (i=0;i<PpcStr.length;i++)
			if ((PpcStr.charAt(i)>='0')&&(PpcStr.charAt(i)<='9')) LpcStr+=PpcStr.charAt(i);
		return LpcStr;
	}
	return null;
}
//-----------------------------------------------------------------------------------
// Retorna somente um número, com sinal ou não, com separador de decimal ou não.
// O sinal, se houver, será colocado sempre a esquerda.
// Se utilizado ponto como separador decimal, então será substituido por vírgula.
// A função procura primeiro pela vírgula mais a direita, utilizando-a como
//   separador se encontrado, caso contrário, utiliza o ponto mais a direita.
function Intecma_GetNumberOnly(PpcStr)
{	if (Intecma_IsNotEmpty(PpcStr))
	{	var LpcStr,LcKey,i;
		var LboSignal,LboZero;
		var LbDec;
		
		LpcStr='';
		LboSignal=false;
		LboZero=true;
		LbDec=(PpcStr.indexOf(",")!=-1?0:1);
		for (i=PpcStr.length-1;i>=0;i--)
		{	LcKey=PpcStr.charAt(i);
			if (LcKey=='-') LboSignal=true;
			else if ((LcKey>='0')&&(LcKey<='9'))
			{ LpcStr=LcKey+LpcStr;
				if (LcKey!='0') LboZero=false;
			}
			else if (((LbDec==0)&&(LcKey==','))||((LbDec==1)&&(LcKey=='.')))
			{ LpcStr=','+LpcStr;
				LbDec=2;
		}	}
		if (LpcStr!='')
		{	if (LbDec==2)
			{	if (LpcStr.charAt(0)==',') LpcStr='0'+LpcStr;
				if (LpcStr.charAt(LpcStr.length-1)==',') LpcStr=LpcStr.substr(0,LpcStr.length-1);
			}
			if ((LboSignal)&&(!LboZero)) LpcStr='-'+LpcStr;
			return LpcStr;
	}	}
	return null;
}
//-----------------------------------------------------------------------------------
function Intecma_FormatNumber(PpcValue,PpcMask)
{	var LiMLen,i,LcKey,LpcKey,LpcRet,LpcChunk;
	var LiVLen,j,LcVal;
	var LoReturn,LoPre,LoState,LiState;
	var LcType; //0: Digito, 1: Valor, 2: texto
	
	LoReturn=new Array();
	LoReturn.boReturn=true;
	LoReturn.pcResult='';
	if (!Intecma_IsNotEmpty(PpcValue)) return LoReturn;
	if (!(Intecma_IsNotEmpty(PpcMask)&&(PpcMask.length>1)))
	{	LoReturn.pcResult=PpcValue;
		return LoReturn;
	}
	LcType=PpcMask.charAt(0);
	PpcMask=PpcMask.substr(1);
	LiMLen=PpcMask.length;
	switch (LcType)
	{	case '0': PpcValue=Intecma_GetDigitsOnly(PpcValue); break;
		case '1':
		{ PpcValue=Intecma_GetNumberOnly(PpcValue);
			/*i=PpcMask.indexOf(',');
			if (i!=-1)
			{	j=0;
				while ((++i<LiMLen)&&(PpcMask.charAt(i)=='0')) j++;
				i=PpcValue.indexOf(',');
				if (i!=-1) j-=PpcValue.length-i+1;
				else PpcValue+=',';
				while (j-->0) PpcValue+='0';
			}*/
		} break;
	}
	//Pré processamento da máscara
	LoPre=new Array();
	j=-1;
	for (i=0;i<LiMLen;i++)
	{	LcKey=PpcMask.charAt(i);
		if ((LcKey=='9')||(LcKey=='0')||(LcKey=='[')||(LcKey==']')||(LcKey==','))
		{	LoPre[++j]=new Array();
			LoPre[j].boKey=true;
			LoPre[j].pcData=LcKey.toString();
			if (LcKey==',')
			{	LoPre[j].pcData2=PpcMask.substr(++i,2);
				i++;
			}
			continue;
		}
		if (LcKey=='\\') LcKey=PpcMask.charAt(++i);
		if ((j==-1)||(LoPre[j].boKey))
		{	LoPre[++j]=new Array();
			LoPre[j].boKey=false;
			LoPre[j].pcData='';
		}
		LoPre[j].pcData+=LcKey;
	}
	//Processa texto com máscara
	LiState=-1;
	LoState=new Array();
	j=(LiVLen=PpcValue.length)-1;
	LpcRet='';
	for (i=LoPre.length-1;i>=0;i--)
	{	if (LoPre[i].boKey)
		{	LpcKey=LoPre[i].pcData;
			if (LpcKey=="]")
			{	LoState[++LiState]=new Array();
				LoState[LiState].boFound=false;
				LoState[LiState].iPos=LpcRet.length;
				continue;
			}
			if (LpcKey=="[")
			{	if (LiState>=0)
				{	if (LiState>0) LoState[LiState-1].boFound=LoState[LiState].boFound;
					if (LoState[LiState].boFound==false) LpcRet=LpcRet.substr(LpcRet.length-LoState[LiState].iPos);
					LiState--;
				}
				continue;
			}
			if ((LpcKey=="9")||(LpcKey=="0"))
			{	if (j>=0) LcVal=PpcValue.charAt(j--);
				else LcVal='';
				LpcChunk='';
				if ((LcVal>='0')&&(LcVal<='9')) LpcChunk=LcVal;
				else if ((LpcKey=="0")&&(LcVal=='')) LpcChunk='0';
				if (LpcChunk!='')
				{	LpcRet=LpcChunk+LpcRet;
					if (LiState>=0) LoState[LiState].boFound=true;
			}	}
			continue;
		}
		LpcRet=LoPre[i].pcData+LpcRet;
	}
	LoReturn.pcResult=LpcRet;
	return LoReturn;
}
//-----------------------------------------------------------------------------------
//
//
//
//
//
//
//
//
//
//				FUNÇÕES DA CLASSE CTextBoxPersistent
//
//
//
//
//
//
//
//
//
//-----------------------------------------------------------------------------------
function Intecma_TBPAcceptEnter(PoEvent,PboMulti)
{	if (PoEvent.keyCode==13)
	{	var LboAccept;
		
		if (PboMulti==false) LboAccept=(PoEvent.ctrlKey|PoEvent.shiftKey|PoEvent.altKey==false);
		else LboAccept=(PoEvent.shiftKey|PoEvent.altKey==false)&&(PoEvent.ctrlKey);
		if (LboAccept)
		{ PoEvent.srcElement.m_boReturnValue=false;
			PoEvent.cancelBubble=true;
}	}	}