 
 
 
 
 
var popUp;
var oldRowClass;
var isNav4, isNav, isIE;
if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
  isNav = (navigator.appName=="Netscape") ? true : false;
  isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
}
if (navigator.appName=="Netscape") {
	isNav4 = (parseInt(navigator.appVersion.charAt(0))==4);
}
 
function tirarZerosEsquerda(STR){
  var sAux='';
  var i=0;
  STR=new String(STR);
  while (i < STR.length ){
    if ((STR.charAt(i)!='.') && (STR.charAt(i)!=',')){
	  sAux += STR.charAt(i);
    }
	i++;
  }
  STR = new String(sAux);
  sAux = '';
  i=0;
  while (i < STR.length ){
    if (STR.charAt(i) != '0'){
      sAux = STR.substring(i,STR.length)
	  i = STR.length;
	}
    i++;
  }
  return  sAux;
}
 
	var theobj;
	var sOpenMenuID = "";
	var iChunk = 0;
	var iChunkStep = 10;
	var iChunkDelay = 20;
	var lastid = -1;
	var sMenuPos = "right";
	var sMenuStyle = "diagonal";
	function DoCombo(sOpenMenuID,textBox) 
	{
		var			eSrc = window.event.srcElement;
		var         i, j;
			if ("object" == typeof(document.all[sOpenMenuID])) 
			{
				var eMenu = document.all[sOpenMenuID];
				if( eMenu.style.visibility != "visible")
				{
					var max;
					var length;
					document.getElementById(textBox).className = 'TextoComboBranco';
					iChunk = iChunkStep;
					var eTR;
					var eTABLE = eSrc.parentElement.parentElement.parentElement.parentElement;
					eTR = eTABLE.children(0);
					if ("right" == sMenuPos) 
					{
						eMenu.style.left = eTABLE.offsetLeft;
						eMenu.style.top = 0;
					}
					else 
					{
						eMenu.style.left = eTABLE.offsetLeft + 26;
						eMenu.style.top = eTABLE.offsetTop + eTR.offsetTop + eSrc.height;
					}
					eMenu.style.clip = "rect(0 0 0 0)";
					eMenu.style.visibility = "visible";
					return window.setTimeout("ShowMenu(" + eMenu.id + ")", iChunkDelay);
				}
				else
				{
					eMenu.style.visibility = "hidden";
					document.getElementById(textBox).className = 'TextoComboNormal';
				}
				
			}
	}
	function DoMenu(sOpenMenuID) 
	{
		var			eSrc = window.event.srcElement;
		var         i, j;
			if ("object" == typeof(document.all[sOpenMenuID])) 
			{
				var eMenu = document.all[sOpenMenuID];
				if( eMenu.style.visibility != "visible")
				{
					var max;
					var length;
					
					iChunk = iChunkStep;
					var eTR;
					var eTABLE = eSrc.parentElement.parentElement.parentElement.parentElement;
					eTR = eTABLE.children(0);
					if ("right" == sMenuPos) 
					{
						eMenu.style.left = eTABLE.offsetLeft + (eSrc.width / 2);
						eMenu.style.top = eTABLE.offsetTop;
					}
					else 
					{
						eMenu.style.left = eTABLE.offsetLeft + 26;
						eMenu.style.top = eTABLE.offsetTop + eTR.offsetTop + eSrc.height;
					}
					eMenu.style.clip = "rect(0 0 0 0)";
					eMenu.style.visibility = "visible";
					return window.setTimeout("ShowMenu(" + eMenu.id + ")", iChunkDelay);
				}
				else
				{
					eMenu.style.visibility = "hidden";
				}
			}
	}
	function GetShowStyle() {
		if ("down" == sMenuStyle) return "rect(0 100% " + iChunk + "% 0)";
		if ("across" == sMenuStyle) return "rect(0 " + iChunk + "% 100% 0)";
		if ("diagonal" == sMenuStyle) return "rect(0 " + iChunk + "% " + iChunk + "% 0)";
		else return "rect(0 100% " + iChunk + "% 0)";
	}
	function ShowMenu(eMenu) {
		eMenu.style.clip = GetShowStyle();
		if (100 >= iChunk) {
			window.setTimeout("ShowMenu(" + eMenu.id + ")", iChunkDelay);
		}
		iChunk += iChunkStep;
	}
function timer(sec,sOpenMenu) {
	seconds=parseInt(sec)
	if(seconds>0) {
		seconds--
		timerID=setTimeout("timer(seconds,'" + sOpenMenu +  "')",1000)
	}else{
		CloseMenu(sOpenMenu)
	}
}
function CloseMenu(sOpenMenuID)
{
	var eMenu = document.all[sOpenMenuID];
	eMenu.style.visibility="hidden";
}
function Calcular() {
	var data1 = document.forms[0].txtDPrevistaDATA.value;
	var data2 = document.forms[0].txtDVencimento.value;	 
	var laterdate = stringtodate(data1);
	var earlierdate = stringtodate(data2);
    var difference = laterdate.getTime() - earlierdate.getTime();
    var daysDifference = Math.floor(difference/1000/60/60/24);
    difference -= daysDifference*1000*60*60*24
    var hoursDifference = Math.floor(difference/1000/60/60);
    difference -= hoursDifference*1000*60*60
    var minutesDifference = Math.floor(difference/1000/60);
    difference -= minutesDifference*1000*60
    var secondsDifference = Math.floor(difference/1000);
	var valor1 = parseFloat(document.forms[0].txtTJuros.value.replace(",",".")) / 100
	var valor2 = valor1 * parseFloat(document.forms[0].ValCalculo.value)
	document.forms[0].lblJCalculado.value = 'R$ ';
    document.forms[0].lblJCalculado.value += daysDifference * valor2 + parseFloat(document.forms[0].ValCalculo.value);
}
function SelectAllGridCheckboxes(gridid){
var theBox=document.getElementById('__chkgrd_' + gridid +'_ALL')
xState=theBox.checked;	
	elm=theBox.form.getElementsByTagName('INPUT');
	for(i=0;i<elm.length;i++)
	{
	if(elm[i].type=="checkbox" && elm[i].id!=theBox.id  && (elm[i].id.indexOf(gridid) > 0) && elm[i].checked!=xState)
		{
		elm[i].click();
		}
	}
}
function OpenCalendar(idname, postBack)
{
	popUp = window.open('Calendar.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
		'popupcal', 
		'width=165,height=228,left=200,top=250');
}
function SetDate(formName, id, newDate, postBack)
{
	eval('var theform = document.' + formName + ';');
	popUp.close();
	theform.elements[id].value = newDate;
	if (postBack)
		__doPostBack(id,'');
}		
function VerTextoCombo(idText, idDivMenu)
{
	var			eSrc = window.event.srcElement;
	var			eText = document.getElementById(idText);
	eText.value = eSrc.parentElement.innerText;
	eText.className = 'TextoComboNormal';
	CloseMenu(idDivMenu)
}
function toggle_div(div_id) 
{
if (document.getElementById(div_id).style.display == 'none')
{
		document.getElementById('imgDIV_' + div_id).src = 'imagens/controles/minus.gif';
		document.getElementById(div_id).style.display = 'block';
	}
	else
	{
		document.getElementById('imgDIV_' + div_id).src = 'imagens/controles/plus.gif';
	   	document.getElementById(div_id).style.display = 'none';
	 }
}
function toggle_div_form(div_id) 
{
if (document.getElementById(div_id).style.display == 'none')
{
		document.getElementById(div_id).src = 'imagens/controles/up_new.gif';
		document.getElementById(div_id).style.display = 'block';
	}
	else
	{
		document.getElementById(div_id).src = 'imagens/controles/dn_new.gif';
	   	document.getElementById(div_id).style.display = 'none';
	 }
}
function AbreGridXML(div_id, xmlfile, titulo, tampagina, where)
{
	var url = "ResultGridXML.aspx?titulo=" + titulo + "&XMLFile=" + xmlfile + "&tamPagina=" + tampagina + "&sqlWhere=" + URLEncode(where);
	if (document.getElementById(div_id).style.display == 'none')
	{
		document.getElementById(div_id).style.display = 'block';
		document.getElementById(div_id).innerHTML = "<IMG SRC='imagens/controles/progbar.gif'><br>Carregando...";
	}
	var func = 'CarregaDivXML("' + url  + '", "' + div_id + '")';
	window.setTimeout(func, 150);
}
function VerCHKTreeView(chk_id, div_id){
	var theBox=document.getElementById(chk_id);
	if( !theBox.checked )
	{ 
		var theDIV = document.getElementById(div_id);
		xState=false;
		if (theDIV)
		{
			theDIV.style.display = 'none';
			document.getElementById('img'+ div_id).src = 'imagens/controles/plus.gif';
			elm=theDIV.getElementsByTagName('INPUT');
			for(i=0;i<elm.length;i++)
			{
				if(elm[i].type=="checkbox" && elm[i].checked!=xState)
					{
					elm[i].click();
					}
			}		
		}
	}
	else
	{
		var id_pai = chk_id.substring(0,chk_id.lastIndexOf("_")); 
		var id_avo = id_pai.substring(0,id_pai.lastIndexOf("_")); 
		var chkPai=document.getElementById(id_pai);
		var chkAvo=document.getElementById(id_avo);
		if( chkPai )
			if ( ! chkPai.checked )
				chkPai.click();
				
		if( chkAvo )
			if ( ! chkAvo.checked )
				chkAvo.click();
		
	}
}
function toggle_div_tree(idestruturaitemx, nestrutura, nordem, ultimonivel) 
{
	if (document.getElementById('DIV' + idestruturaitemx).style.display == 'none')
	{
		
		document.getElementById('img'+ idestruturaitemx).src = 'imagens/controles/minus.gif';
		document.getElementById('DIV' + idestruturaitemx).style.display = 'block';
		if (document.getElementById('DIV' + idestruturaitemx).parentElement.parentElement.previousSibling.firstChild.nextSibling.firstChild.checked)
			document.getElementById('DIV' + idestruturaitemx).parentElement.parentElement.previousSibling.firstChild.nextSibling.firstChild.click();
 
		var func = 'CarregaDivXML("NoEstrutura.aspx?IDESTRUTURAITEMXPAI=' + idestruturaitemx +  '&NESTRUTURA=' + nestrutura +'&NORDEM=' + nordem + '&ULTIMONIVEL=' + ultimonivel + '", "' + idestruturaitemx + '")';
		window.setTimeout(func, 150);
		
	}
	else
	{
		document.getElementById('img'+ idestruturaitemx).src = 'imagens/controles/plus.gif';
	   	document.getElementById('DIV' + idestruturaitemx).style.display = 'none';
	 }
}
function CarregaDivXML(url,div_id)
{
	if (document.getElementById('DIV' + div_id).innerHTML.substring(0,3) == '<IM')
	{
		var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		xmlhttp.open("GET", url, false);
		xmlhttp.send("");
		var rs = xmlhttp.responseText;
		
		document.getElementById('DIV' + div_id).innerHTML = rs;
	}
 
}
function URLEncode(plaintext)
{
	var SAFECHARS = "0123456789" +
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";
	var HEX = "0123456789ABCDEF";
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" + ch + "' cannot be encoded using standard URL encoding.\n" +
				        "(URL encoding only supports 8-bit characters.)\n" +
						"A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	}
	return encoded;
};
function fscroll (DivId, Vdir, Vvel, Vloop) {
	Vloop = true;
	Vdirecao = null;
	Vvelocidade = 10;
	Vsincronismo = null;
	Vdiv = null;
	if (document.getElementById)
	{
		var Vpagina = eval("document.getElementById('" + DivId + "').style");
	}
	Vdirecao = Vdir;
	Vvelocidade = parseInt(Vvel);
	Vdiv = DivId;
	var Vpos_y = parseInt(Vpagina.top);
	if (Vloop == true){
		if (Vdirecao == "baixo"){
			Vpagina.top = (Vpos_y - (Vvelocidade));}
		else{				
			if (Vdirecao == "cima" && Vpos_y < 50){
				Vpagina.top = (Vpos_y + (Vvelocidade));}
			else{
				if (Vdirecao == "top"){Vpagina.top = 0;}
			}
		}
		Vsincronismo = setTimeout("fscroll(Vdiv, Vdirecao, Vvelocidade)", 1);
	}
}
function fscrollStop() {
 
	Vloop = false;
	clearTimeout(Vsincronismo);
}
function stringtodate(arg) 
{ 
	var comps;
	Window.dateformat="DD/MM/YYYY";
	var month, day, year;
	var datetime = arg.split(" ");
	var d = datetime[0];
	if (d.indexOf("/") != -1) 
	{ comps = d.split("/");
		if (comps.length == 2) 
		{	month = parseInt(comps[0],10)-1;
			day = 1;
 			year = parseInt(comps[1],10);
		}
		else if (window.dateformat == "DD/MM/YYYY") 
		{ 
			day = parseInt(comps[0],10);
			month = parseInt(comps[1],10)-1;
			year = parseInt(comps[2],10);
		}
		else 
		{ 
			month = parseInt(comps[0],10)-1;
			day = parseInt(comps[1],10);
			year = parseInt(comps[2],10);
		}
	}
	else if (d.indexOf(".") != -1) 
	{ 
		comps = d.split(".");
		if (comps.length == 2) 
		{ 
			day = 1;
			month = parseInt(comps[0],10);
			year = parseInt(comps[1],10)-1;
		}
		else 
		{
			day = parseInt(comps[0],10);
			month = parseInt(comps[1],10)-1;
			year = parseInt(comps[2],10);
		}
	}
	else if (d.indexOf("-") != -1) 
	{ 
		comps = d.split("-");
		var ms = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC";
		if (comps.length == 2) 
		{ 
			day = 1;
			month = parseInt(comps[0],10);
			year = ms.indexOf(comps[1].toUpperCase())/3;
		}
		else 
		{ 
			day = parseInt(comps[0],10);
			month = ms.indexOf(comps[1].toUpperCase())/3;
			year = parseInt(comps[2],10);
		}
	}
	 
	var result;
	var t = datetime[1];
	if (t != null) 
	{ 
		comps = t.split(":");
		var hour = parseInt(comps[0],10);
		var min = parseInt(comps[1],10);
		var sec = (comps[2] != null ? parseInt(comps[2],10) : 0);
		if (datetime[2].toLowerCase() == "pm") 
			hour += 12;
		result = new Date(year,month,day,hour,min,sec);
	}
	else 
		result = new Date(year,month,day);
		
	if (year < 50) 
		nlSetFullYear(r, year+2000);
	else if (year < 100) 
		nlSetFullYear(r, year+1900);
 
	return result;
}
function AtivaTab(id)
{
	for(i=1;i<5;i++)
	{
		tab = document.getElementById('HP___tab_ctl' + i);
		if(tab)
			if( i == id )
				tab.className='tab';
			else
				if( tab.className == 'tab' )
					tab.className = 'backtab';
	}
}
function AtivaTab(prefixo, id)
{
	for(i=1;i<5;i++)
	{
		tab = document.getElementById(prefixo + i);
		if(tab)
			if( i == id )
				tab.className='tab';
			else
				if( tab.className == 'tab' )
					tab.className = 'backtab';
	}
}
function PopupErro(icone,msgErro)
{
	window.open('Msgbox.aspx?img=' + icone + "&erro=" + msgErro ,'Mensagem_de_Erro','width=280,height=140,left=200,top=250');
	return true;
}
function MsgStatus(mensagem)
{
	try
	{
		if (parent.parent.frames("status"))
		{
			if(mensagem == "")
			{
				parent.parent.frames("status").document.all.progress.style.display = 'none';
			}
			else
			{
				parent.parent.frames("status").document.all.progress.style.display = 'block';
			}
			parent.parent.frames("status").document.all.msg.innerText = mensagem;
		}
	}
	catch (e)
	{
		// Ignora
	}	
}
function HiLightRow(row)
{
	var chk = false;
	if( row.className == 'gridover' )
	{	
		if( row.firstChild.firstChild.type=="checkbox" )
		{
			chk = row.firstChild.firstChild.checked;
		}
		if (chk != true)
		{		
			row.className = oldRowClass;
		}
	}
	else
	{
		oldRowClass = row.className;
		row.className = 'gridover';					
	}
}
function GoURL(row)
{
	var url = row.firstChild.firstChild.href;
	location.href = url;
	row.firstChild.firstChild.click();
}
function SelectRow(row)
{
	row.firstChild.firstChild.click();
}
var resp;
function VerificaControle()
{
	var span = document.forms[0].getElementsByTagName("SPAN")
	var valido;
	var controle;
	var retorno = true;
 
	for (i=0;i<span.length;i++)
	{	
		var texto = span[i].outerHTML;
		
		valido  = texto.substring(texto.indexOf('isvalid'));
		controle = texto.substring(texto.indexOf('controltovalidate'));
						
		controle = retiraLixo(controle);
		valido = retiraLixo(valido);
		
		if (valido == 'false')
		{
			AlteraCorBorda(controle,false);
			retorno = false;
		}
					
	}
		
		return retorno;
}
function ValidaControle(idControle,obrigatorio)
{
	if (resp != '1')
	{
	var text = document.forms[0].getElementsByTagName("INPUT")
	
		for (i=0;i<text.length;i++)
			{
				if (obrigatorio == true)
				{
				if (text[i].id == idControle && text[i].value == '') 
					AlteraCorBorda(idControle,false);
					else
					    {
						if (text[i].id == idControle)
							AlteraCorBorda(idControle,true);
						}
				}
				else
					{
						var campo = text[i].id;
						var campoatual;
						if (idControle.indexOf("_") >0)
							campoatual = campo;
							else
							campoatual = campo.substring(campo.indexOf("_")+1);
						
						if (campoatual == idControle)
							AlteraCorBorda(text[i].id,true);
					}
			
			}
			
	}
	else
		resp = 0;
}
	function retiraLixo(texto)
	{
		var strTexto; 
		strTexto = texto.substring(texto.indexOf("\"") + 1);
		strTexto = strTexto.substring(0,strTexto.indexOf("\""));
	   return strTexto;
	}
function SenhaDif(val,campo) 
{
	var text = val.id.split('_')
	var texto1 = document.getElementById(text[1]).value;
	var texto2 = document.getElementById(text[2]).value;
	if (texto1 == texto2) 
		{
		AlteraCorBorda(val.id,true,true);
		}
		else {
		campo.IsValid = false;
		AlteraCorBorda(val.id,false,true);
		}
		
		resp = 1;
	}
function AlteraCorBorda(id,valid,SplitText)
{
	var i;
	var campo; 
	var color;
	if (valid != true) color='red'; else color='#727771';
if (SplitText == true)
{
	if (id.indexOf("_") > 0)
		{i = 1;}
	else {i = 0;}
	
	campo = id.split('_');
 
	while (i < campo.length)
	{
		document.getElementById(campo[i]).style.borderColor = color;
		i++;
	}
}
else
	{
		if (id.indexOf("_cv") > 0)
			campo = id.substring(0,id.indexOf("_cv"));
			else
			campo = id;
			document.getElementById(campo).style.borderColor = color;
	}
}
function fValidaData(val,campo)
{
var a= campo.Value;
var chk = 0;
var maxDay = 0;
var mascara = document.getElementById('masc').value;	
var dd = 0;
var mm = 0;
var yyyy = 0;
var arrData,arrMascara;
var carSplit,carSplitMasc;
 
		if (mascara.indexOf("/") > -1)
				carSplitMasc = "/";				
			else if (mascara.indexOf(".") > -1)
				carSplitMasc = ".";
			else if (mascara.indexOf("-") > -1)
				carSplitMasc = "-";
arrMascara = mascara.split(carSplitMasc);
			if (a.indexOf("/") > -1)
				carSplit = "/";				
			else if (a.indexOf(".") > -1)
				carSplit = ".";
			else if (a.indexOf("-") > -1)
				carSplit = "-";
if (a.indexOf(carSplit) > -1)
{
arrData = a.split(carSplit);					
 
	for(i=0;i<arrMascara.length;i++)
		{
			if(arrMascara[i].indexOf("D") > -1)
					dd = arrData[i];
				else if(arrMascara[i].indexOf("M") > -1)
					mm = arrData[i];
				else if(arrMascara[i].indexOf("Y") > -1)
					yyyy = arrData[i];
		}
}
	
maxDay = max_day(mm,yyyy);
	if((dd <= 0) || (dd > maxDay))
	{ chk = 1;}
	else if((mm <=0) || (mm > 12))
	{ chk = 1;}
	else if(yyyy <= 0)
	{ chk = 1; }
	else if(a.length >10)
	{ chk = 1; }
	
	if(chk ==1)
	{
		campo.IsValid = false;
		AlteraCorBorda(val.id,false)
		resp = 1;
		return false;
	}
	else 
	{ 
		AlteraCorBorda(val.id,true)
	
		var strNomeObj = val.id.substring(0,val.id.indexOf("_cv"));
		var strValorAlterado;
	switch(carSplit)
	{
		case "/":
		strValorAlterado = a.replace(/[/]/g,carSplitMasc);
		break;
		case "-":
		strValorAlterado = a.replace(/-/g,carSplitMasc);
		break;
		case ".":
		strValorAlterado = a.replace(/[.]/g,carSplitMasc);
		break;
	}
	
		document.getElementById(strNomeObj).value  = strValorAlterado;
		return true; 
	}
}
 
function max_day(mn,yr)
{
	var mDay;
	if ((mn == 4) || (mn == 6) || (mn == 11))
	{ mDay = 30; }
	else if (mn == 2)
	{ mDay = isLeapYear(yr) ? 29 : 28; }
	else
	{ mDay = 31; }
	return mDay;
}
 
function isLeapYear(yr)
{
	if (yr % 2 == 0)
	return true; 
	return false;
}
 
 
function SelectAllSubCheckboxes(chk_id,div_id,chk_idPai)
{
	var theBox=document.getElementById(chk_id);
		var theDIV = document.getElementById(div_id);
		var theBoxPai = document.getElementById(chk_idPai)
			if (theBoxPai != null)
			{
				theBoxPai.checked = true;
				theBoxPai.click();
			}
			
	if( theBox.checked )
	{ 
		if (theDIV != null)
		{
			var pos = theDIV.id.indexOf('idchave_') + 8;
			var idChave = theDIV.id.substring(pos, theDIV.id.length);
			xState=false;
			
			if (theDIV.style.display != 'none')
			{
				theDIV.style.display = 'none';
				elm=theDIV.getElementsByTagName('INPUT');
				
				for(i=0;i<elm.length;i++)
				{
					if(elm[i].type=="checkbox" && elm[i].checked!=xState)
						{
						elm[i].click();
						}
				}
			
			}
		}
	}
}
 
function PreencheTextCombo(objCheck,desc,textbox)
	{
	try
	{
		var ck = document.getElementById(objCheck);
		var objtextbox = document.getElementById(textbox);
 
		if (ck.checked)
		{
			if (objtextbox.value == ' ' || objtextbox.value == '')
				objtextbox.value = desc;
			else
				objtextbox.value += desc;
		}
		else
		{
			objtextbox.value = objtextbox.value.replace(desc,'');
		}

					
		objtextbox.title = objtextbox.value;
		
	}
	catch (e)
	{
		//ignora
	}
	}
function Mascara(formato,objeto){
  campo = eval (objeto);
  var keypress = window.event.keyCode;
  
  
  if((keypress >= 48) && (keypress <= 57)) {
    if (formato=='CEP'){
      separador = '-';	
      conjunto1 = 5;
      if (campo.value.length == conjunto1) {
        campo.value = campo.value + separador;
      }
    }
    if (formato=='MM/YYYY'){
      separador = '/';	
      conjunto1 = 2;
      if (campo.value.length == 0) {
        if(keypress > 49)  {
          return false;
        }
      }
      if (campo.value.length == conjunto1){
        campo.value = campo.value + separador;
      }
    }
    if (formato=='DD/MM/YYYY'){
      separador = '/';	
      conjunto1 = 2;
      conjunto2 = 5;
 
      if (campo.value.length == 0) {
        if(keypress > 51)  {
          return false;
        }
      }
      if (campo.value.length == 2) {
        if(keypress > 51)  {
          return false;
        }
      }
      if (campo.value.length == conjunto1){
        campo.value = campo.value + separador;
      }
      if (campo.value.length == conjunto2){
        campo.value = campo.value + separador;
      }
 
    }
    if (formato=='DD/MM/YYYY hh:mm'){
      separador1 = '/';	
      separador2 = ' ';	
      separador3 = ':';	
      conjunto1 = 2;
      conjunto2 = 5;
      conjunto3 = 10;
      conjunto4 = 13;
      if (campo.value.length == 0) {
        if(keypress > 51)  {
          return false;
        }
      }
      if (campo.value.length == 3) {
        if(keypress > 49)  {
          return false;
        }
      }      
      if (campo.value.length == 11) {
        if(keypress > 50)  {
          return false;
        }
      }      
      if (campo.value.length == 14) {
        if(keypress > 53)  {
          return false;
        }
      }
      if (campo.value.length == conjunto1){
        campo.value = campo.value + separador1;
      }
      if (campo.value.length == conjunto2){
        campo.value = campo.value + separador1;
      }
      if (campo.value.length == conjunto3){
        campo.value = campo.value + separador2;
      }
      if (campo.value.length == conjunto4){
        campo.value = campo.value + separador3;
      }
      
    }
 
    if (formato=='DD/MM/YYYY hh:mm:ss'){
      separador1 = '/';	
      separador2 = ' ';	
      separador3 = ':';	
      conjunto1 = 2;
      conjunto2 = 5;
      conjunto3 = 10;
      conjunto4 = 13;
      conjunto5 = 16;
      if (campo.value.length == 0) {
        if(keypress > 51)  {
          return false;
        }
      }
      if ((campo.value.length == 3) || (campo.value.length == 11)) {
        if(keypress > 50)  {
          return false;
        }
      }      
      if ((campo.value.length == 14) || (campo.value.length == 17)) {
        if(keypress > 53)  {
          return false;
        }
      }
      if (campo.value.length == conjunto1){
        campo.value = campo.value + separador1;
      }
      if (campo.value.length == conjunto2){
        campo.value = campo.value + separador1;
      }
      if (campo.value.length == conjunto3){
        campo.value = campo.value + separador2;
      }
      if (campo.value.length == conjunto4){
        campo.value = campo.value + separador3;
      }
      if (campo.value.length == conjunto5){
        campo.value = campo.value + separador3;
      }
    }
    if (formato=='hh:mm'){
      separador = ':';	
      conjunto1 = 2;
      if (campo.value.length == 0) {
        if(keypress > 51)  {
          return false;
        }
      }
      if (campo.value.length == 3) {
        if(keypress > 53)  {
          return false;
        }
      }
      if (campo.value.length == conjunto1){
        campo.value = campo.value + separador;
      }
    }
    if (formato=='hh:mm:ss'){
      separador = ':';	
      conjunto1 = 2;
      conjunto2 = 5;
      if (campo.value.length == 0){
        if(keypress > 50)  {
          return false;
        }
      }
      if ((campo.value.length == 2) || (campo.value.length == 5)) {
        if(keypress > 53)  {
          return false;
        }
      }
      if (campo.value.length == conjunto1){
        campo.value = campo.value + separador;
      }
      if (campo.value.length == conjunto2){
        campo.value = campo.value + separador;
      }
    }
    if (formato=='TELEFONE'){
      separador = '-';	
      conjunto1 = 4;
      if (campo.value.length == conjunto1){
        campo.value = campo.value + separador;
      } 
    }
    if (formato=='DDDTELEFONE'){
	  separador1 = '(';	
      conjunto1 = 0;
      separador2 = ')';	
      conjunto2 = 3;
      separador3 = '-';	
      conjunto3 = 8;
      if (campo.value.length == conjunto1){
        campo.value = separador1 + campo.value;
      } 
      if (campo.value.length == conjunto2){
        campo.value = campo.value + separador2;
      } 
      if (campo.value.length == conjunto3){
        campo.value = campo.value + separador3;
      } 
 
    }
    if (formato=='DDD'){
	  separador1 = '(';	
      conjunto1 = 0;
      separador2 = ')';	
      conjunto2 = 3;
      if (campo.value.length == conjunto1){
        campo.value = separador1 + campo.value;
      } 
      if (campo.value.length == conjunto2){
        campo.value = campo.value + separador2;
      } 
    }
 
    if (formato=='CPF'){
      separador1 = '.';	
      separador2 = '-';	
      if (campo.value.length == 3){
        campo.value = campo.value + separador1;
      } 
 
      if (campo.value.length == 7){
        campo.value = campo.value + separador1;
      } 
 
      if (campo.value.length == 11){
        campo.value = campo.value + separador2;
      } 
    }
 
    if (formato=='CNPJ'){
      separador1 = '.';	
      separador2 = '/';	
      separador3 = '-';	
      
      if (campo.value.length == 2){
        campo.value = campo.value + separador1;
      } 
 
      if (campo.value.length == 6){
        campo.value = campo.value + separador1;
      } 
 
      if (campo.value.length == 10){
        campo.value = campo.value + separador2;
      } 
      if (campo.value.length == 15){
        campo.value = campo.value + separador3;
      } 
    }
  }
  else {
	window.event.keyCode=null;
	return false;
	
  }
}
function VerificaModulo11(valor,mensagem) {
 
	while (valor.indexOf('.') > -1)
		{
			valor = valor.replace('.','')		
		}
        valor = valor.replace('-','')
		valor = valor.replace('/','') 
				
	primeiro=valor.substr(1,1);
	var falso=true;
	var size=valor.length;
	var proximo;
	for (i=2; i<size-1; ++i){
	  	proximo=(valor.substr(i,1));
	  	if (primeiro!=proximo) {
		falso=false
		}
	}
	if (falso){
	if (mensagem != null)
		alert(mensagem);
	return false;
	}
		
	if(modulo(valor.substring(0,valor.length - 2)) + "" + modulo(valor.substring(0,valor.length - 1)) != valor.substring(valor.length - 2,valor.length)) {
		if (mensagem != null)
			alert(mensagem);
		return false;
	}
	return true
}		
 
function modulo(str) 
{
	soma=0;
    ind=2;
 	for(pos=str.length-1;pos>-1;pos=pos-1) 
 	{
   		soma = soma + (parseInt(str.charAt(pos)) * ind);
   		ind++;
		if(str.length>11)
			if(ind>9) 
			ind=2;
 	}
    resto = soma - (Math.floor(soma / 11) * 11);
    if(resto < 2)
     	return 0;
	else 
    	return 11 - resto;
}	
 
function formatarOnKeyDown(OBJ,tammax,teclapres, usadec){
  var decimal,inteiro;
  var i,count;
  STR = new String(OBJ.value);
 
  inteiro='';
 
  if (isIE) {
	if (STR.length <= OBJ.maxLength ){
	
	if (usadec == 1)
	{
		if (STR.indexOf(",") == -1)
		{
			if (OBJ.maxLength  <= 6)
			STR = STR.substring(0,OBJ.maxLength - 1);
			else
			STR = STR.substring(0,OBJ.maxLength - 2);
		}
			
	}
	else
	{
		if (STR.indexOf(".") == -1 )
		{
			STR = STR.substring(0,OBJ.maxLength - 2);	
		}
	}
	
	  STR = tirarZerosEsquerda(STR);
if (!(event.keyCode > 35 && event.keyCode < 41)) 		
{
		if (((event.keyCode > 47) && (event.keyCode < 59)) || ((event.keyCode > 95) && (event.keyCode < 106))   )
		{	  
			if (STR.length == 0){
			  inteiro  = '0';
			  if( usadec == 1 )
				decimal = '0' + STR;
			}
			else {
			  if (STR.length == 1){
			    if( usadec == 1 )
			    {
				    inteiro  = '0';
					decimal = STR;
				}
				else
					inteiro = STR;
			  }
			  else{
				if( usadec == 1 )
				{
					decimal = STR.substring(STR.length-2,STR.length);
					i=3;
				}
				else
				i=0;
			    count=0;
			    while (i<=STR.length){
			    	if (STR.length >3)
			    	{
						if (count == 3) {
					 		inteiro = '.' + inteiro;
			  				count = 0;
			  		}
			  	}
			  		
					  inteiro = STR.charAt(STR.length-i) + inteiro;
					if (inteiro != "")
			  			count++;
			  		i++;
			    }
			  }
			}
 
	  }
	  else{
	    if (event.keyCode == 8){
 
	      if (STR.length == 0){
			  if( usadec == 1 )
				s=1;
			}
			else {
			  if (STR.length == 1){
			    if( usadec == 1 )
			    {
    			    inteiro  = '0';
					decimal = '00' + STR;
				}
				else
					inteiro = STR;
				
			  }
			  else {
			    if (STR.length == 2){
   		          if( usadec == 1 )
   				  {
			          inteiro  = '0';
					  decimal = '0' + STR;
				  }
				  else
					var s = 1;
			     }
		         else{
	 			   if( usadec == 1 )
	 			   {
	 					decimal = STR.substring(STR.length-2,STR.length);
						i=3;
					}
					else
						i = 0;
				   count=0;
				 while (i<=STR.length){
					if (STR.length >3)
					{
				 		if (count == 3) {
					 		inteiro = '.' + inteiro;
			  				count = 0;
			  		}
			  	}
			  		
					  inteiro = STR.charAt(STR.length-i) + inteiro;
					if (inteiro != "") 
			  			count++;
			  		i++;
			    }
			     }
			  }
	      }
	    }
	    else {
 
	      if (STR.length == 1){
		 	  if( usadec == 1 )
		 	  {
  		 	    inteiro  = '0';
				decimal = '0' + STR;
			  }
			  else
				  inteiro = STR;
				
			}
			else {
			  if (STR.length == 2){
				  if( usadec == 1 )
				  {
	    		    inteiro  = '0';
					decimal = STR;
				  }
				  else
					inteiro = STR;
					
				}
				else{
				  if( usadec == 1 )
				  {
					decimal = STR.substring(STR.length-2,STR.length);
					i=3;
				  }
				  else
					i=0;
				  count=0;
				  while (i<=STR.length){
				  	
			 		if (count==3) {
					  inteiro = '.' + inteiro;
					  count = 0;
					}
				
				    inteiro = STR.charAt(STR.length-i) + inteiro;
					count++;
					i++;
				  }
				}
			}
	    }
	   }
	   
	  if (OBJ.value.length == 2) 
	  {
		if (OBJ.value.indexOf(",") != -1)
		{
			OBJ.value = OBJ.value.replace(",","");
		}
	  }
 
	  if (inteiro == '') {
	    inteiro = '0';
	    s=1;
	  }
 
 
	  if (usadec == 1 )
	  {
		if (decimal == '' ) {
			decimal = '00';
			s=1;
		}
		if (inteiro != "0")
			OBJ.value = inteiro+','+decimal;
		}
	  else
	  if (inteiro != "0")
		OBJ.value = inteiro;
		
	}
  }
  else
  {
	var tecla = teclapres.keyCode;
	valorSemFormato = OBJ.value;
	valorSemFormato = valorSemFormato.replace( ",", "" );
	valorSemFormato = valorSemFormato.replace( ".", "" );
	valorSemFormato = valorSemFormato.replace( ".", "" );
	valorSemFormato = valorSemFormato.replace( ".", "" );
	valorSemFormato = valorSemFormato.replace( ".", "" );
	tamanho = valorSemFormato.length;
 
	if (tecla == 46) {
	     OBJ.value = OBJ.value;
 
	}if (tamanho < tammax && tecla != 8) {
	    tamanho = valorSemFormato.length + 1;
 
	}if (tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) {
	     if (tecla == 8) {
	         tamanho = tamanho - 1;
	     }
 
	     if (tamanho <= 2) {
	 		 OBJ.value = valorSemFormato;
 
	 	 }else if ((tamanho > 2) && (tamanho <= 5)) {
	 		 OBJ.value = valorSemFormato.substr(0, tamanho - 2) + ',' +
	 		               valorSemFormato.substr(tamanho - 2, tamanho);
 
	 	 }else if ((tamanho >= 6) && (tamanho <= 8)) {
	 	 	 OBJ.value = valorSemFormato.substr(0, tamanho - 5) + '.' +
	 	 	               valorSemFormato.substr(tamanho - 5, 3) + ',' +
	 		               valorSemFormato.substr(tamanho - 2, tamanho);
 
	 	 }else if ((tamanho >= 9) && (tamanho <= 11)) {
	 		 OBJ.value = valorSemFormato.substr(0, tamanho - 8) + '.' +
	 		               valorSemFormato.substr(tamanho - 8, 3) + '.' +
	 		               valorSemFormato.substr(tamanho - 5, 3) + ',' +
	 		               valorSemFormato.substr(tamanho - 2, tamanho);
 
	 	 }else if ((tamanho >= 12) && (tamanho <= 14)) {
	 	 	 OBJ.value = valorSemFormato.substr(0, tamanho - 11) + '.' +
	 		               valorSemFormato.substr(tamanho - 11, 3) + '.' +
	 		               valorSemFormato.substr(tamanho - 8, 3)  + '.' +
	 		               valorSemFormato.substr(tamanho - 5, 3)  + ',' +
	 		               valorSemFormato.substr(tamanho - 2, tamanho);
 
	 	 }else if ((tamanho >= 15) && (tamanho <= 17)) {
	 	 	 OBJ.value = valorSemFormato.substr(0, tamanho - 14) + '.' +
	 		               valorSemFormato.substr(tamanho - 14, 3) + '.' +
	 		               valorSemFormato.substr(tamanho - 11, 3) + '.' +
	 		               valorSemFormato.substr(tamanho - 8, 3)  + '.' +
	 		               valorSemFormato.substr(tamanho - 5, 3)  + ',' +
	 		               valorSemFormato.substr(tamanho - 2, tamanho);
	    }
	}
  }  
  
  if (!(event.keyCode > 35 && event.keyCode < 41))
  {
  if (!(event.keyCode > 45 && event.keyCode < 59))
  {
	if(!(event.keyCode > 95 && event.keyCode < 106))
	{
		if (event.keyCode != 8 && event.keyCode != 9)
			{				
				event.keyCode=null;				
				return false;
			}
	}
	
  }
   }      
}
}
 
function formatarOnKeyUp(OBJ){
  var decimal,inteiro;
  var i,count;
  STR = new String(OBJ.value);
  STR = tirarZerosEsquerda(STR);
  inteiro='';
  if (isIE) {
		if (STR.length == 1){
			}
			else {
			  if (STR.length == 2){
				}
				else{
				  decimal = STR.substring(STR.length-2,STR.length);
				  i=3;
				  count=0;
				  while (i<=STR.length){
			 		if (count==3) {
					  inteiro = '.' + inteiro;
					  count = 0;
					}
				    inteiro = STR.charAt(STR.length-i) + inteiro;
					count++;
					i++;
				  }
				}
			}
		if (inteiro == '') {
		}
		if (decimal == '') {
		}
		OBJ.value = inteiro+','+decimal;
  }
  else
  {
	if (navigator.appName=="Netscape"){
		var versao = navigator.userAgent;
		versao=versao.toString();
		menorVersao = versao.search("/6.0");
		if (menorVersao>-1){
			var isNS6="sim";
		}
	}
	if(isNS6=="sim")
		OBJ.style.textAlign	= "left";
	if(STR=="")
	if((STR.length==1 || STR.length==2 || STR.length==3) && OBJ.value.substr(0,1)=='0')
	if((STR.length==2) && OBJ.value.substr(0,1)!='0')
	if((STR.length==1) && OBJ.value.substr(0,1)!='0')
	if(isNS6=="sim")
		OBJ.style.textAlign	= "right";
  }
}
function FormataOnKeyPress(obj){
if(event.keyCode==13)
  {event.keyCode=9;}
  else{
if (!(event.keyCode > 36 && event.keyCode < 41)) 		
{
if (!(event.keyCode > 45 && event.keyCode < 59))
  {
	if(!(event.keyCode > 95 && event.keyCode < 106))
	{
		if (event.keyCode != 8 && event.keyCode != 9)
			{
				event.keyCode=null;
				return false;
			}
	}
	
  }
  }
}
}
function Mascara(formato,objeto){
  campo = eval (objeto);
  var keypress = window.event.keyCode;
  
  if (formato=='PLACA'){      
		separador2 = '-';		
		if (campo.value.length <= 2){						
			if( (keypress > 47) && (keypress < 58) ){			
				window.event.keyCode=null;
				return false;		
			}
		}else{
			if(!(((keypress > 47)&&(keypress < 58)))) {					
				window.event.keyCode=null;
				return false;				
			}			
		}
		return;
	} 
  
  if((keypress >= 48) && (keypress <= 57)) {
	if (formato=='RNTRC'){
      separador2 = '/';	
      separador3 = '-';	
      
      if (campo.value.length == 2){
        campo.value = campo.value + separador3;
      } 
 
      if (campo.value.length == 5){
        campo.value = campo.value + separador3;
      } 
 
      if (campo.value.length == 8){
        campo.value = campo.value + separador2;
      } 
      if (campo.value.length == 16){
        campo.value = campo.value + separador3;
      } 
    }
	if (formato=='TRO'){
      separador2 = '/';	
           
      
      if (campo.value.length == 5){
        campo.value = campo.value + separador2;
      } 
 
     }
    if (formato=='CEP'){
      separador = '-';	
      conjunto1 = 5;
      if (campo.value.length == conjunto1) {
        campo.value = campo.value + separador;
      }
    }
	if (formato=='CEP-RNTRC'){
      separador1 = '.';	
      separador2 = '/';	
      separador3 = '-';	
      
      if (campo.value.length == 2){
        campo.value = campo.value + separador1;
      } 
 
      if (campo.value.length == 6){
        campo.value = campo.value + separador2;
      } 
      
    }
    if (formato=='MM/YYYY'){
      separador = '/';	
      conjunto1 = 2;
      if (campo.value.length == 0) {
        if(keypress > 49)  {
          return false;
        }
      }
      if (campo.value.length == conjunto1){
        campo.value = campo.value + separador;
      }
    }
    if (formato=='DD/MM/YYYY'){
      separador = '/';	
      conjunto1 = 2;
      conjunto2 = 5;
 
      if (campo.value.length == 0) {
        if(keypress > 51)  {
          return false;
        }
      }
      if (campo.value.length == 2) {
        if(keypress > 51)  {
          return false;
        }
      }
      if (campo.value.length == conjunto1){
        campo.value = campo.value + separador;
      }
      if (campo.value.length == conjunto2){
        campo.value = campo.value + separador;
      }
 
    }
    if (formato=='DD/MM/YYYY hh:mm'){
      separador1 = '/';	
      separador2 = ' ';	
      separador3 = ':';	
      conjunto1 = 2;
      conjunto2 = 5;
      conjunto3 = 10;
      conjunto4 = 13;
      if (campo.value.length == 0) {
        if(keypress > 51)  {
          return false;
        }
      }
      if (campo.value.length == 3) {
        if(keypress > 49)  {
          return false;
        }
      }      
      if (campo.value.length == 11) {
        if(keypress > 50)  {
          return false;
        }
      }      
      if (campo.value.length == 14) {
        if(keypress > 53)  {
          return false;
        }
      }
      if (campo.value.length == conjunto1){
        campo.value = campo.value + separador1;
      }
      if (campo.value.length == conjunto2){
        campo.value = campo.value + separador1;
      }
      if (campo.value.length == conjunto3){
        campo.value = campo.value + separador2;
      }
      if (campo.value.length == conjunto4){
        campo.value = campo.value + separador3;
      }
      
    }
    if (formato=='DD/MM/YYYY hh:mm:ss'){
      separador1 = '/';	
      separador2 = ' ';	
      separador3 = ':';	
      conjunto1 = 2;
      conjunto2 = 5;
      conjunto3 = 10;
      conjunto4 = 13;
      conjunto5 = 16;
      if (campo.value.length == 0) {
        if(keypress > 51)  {
          return false;
        }
      }
      if ((campo.value.length == 3) || (campo.value.length == 11)) {
        if(keypress > 50)  {
          return false;
        }
      }      
      if ((campo.value.length == 14) || (campo.value.length == 17)) {
        if(keypress > 53)  {
          return false;
        }
      }
      if (campo.value.length == conjunto1){
        campo.value = campo.value + separador1;
      }
      if (campo.value.length == conjunto2){
        campo.value = campo.value + separador1;
      }
      if (campo.value.length == conjunto3){
        campo.value = campo.value + separador2;
      }
      if (campo.value.length == conjunto4){
        campo.value = campo.value + separador3;
      }
      if (campo.value.length == conjunto5){
        campo.value = campo.value + separador3;
      }
    }
    if (formato=='hh:mm'){
      separador = ':';	
      conjunto1 = 2;
      if (campo.value.length == 0) {
        if(keypress > 51)  {
          return false;
        }
      }
      if (campo.value.length == 3) {
        if(keypress > 53)  {
          return false;
        }
      }
      if (campo.value.length == conjunto1){
        campo.value = campo.value + separador;
      }
    }
    if (formato=='hh:mm:ss'){
      separador = ':';	
      conjunto1 = 2;
      conjunto2 = 5;
      if (campo.value.length == 0){
        if(keypress > 50)  {
          return false;
        }
      }
      if ((campo.value.length == 2) || (campo.value.length == 5)) {
        if(keypress > 53)  {
          return false;
        }
      }
      if (campo.value.length == conjunto1){
        campo.value = campo.value + separador;
      }
      if (campo.value.length == conjunto2){
        campo.value = campo.value + separador;
      }
    }
    if (formato=='TELEFONE'){
      separador = '-';	
      conjunto1 = 4;
      if (campo.value.length == conjunto1){
        campo.value = campo.value + separador;
      } 
    }
    if (formato=='TELEFONE-RNTRC'){
      separador = '-';	
      conjunto1 = 4;
      if (campo.value.length == 3){
        campo.value = campo.value + separador;
      } 
      if (campo.value.length == 8){
        campo.value = campo.value + separador;
      } 
    }
    if (formato=='DDDTELEFONE'){
	  separador1 = '(';	
      conjunto1 = 0;
      separador2 = ')';	
      conjunto2 = 3;
      separador3 = '-';	
      conjunto3 = 8;
      if (campo.value.length == conjunto1){
        campo.value = separador1 + campo.value;
      } 
      if (campo.value.length == conjunto2){
        campo.value = campo.value + separador2;
      } 
      if (campo.value.length == conjunto3){
        campo.value = campo.value + separador3;
      } 
    }
    if (formato=='DDD'){
	  separador1 = '(';	
      conjunto1 = 0;
      separador2 = ')';	
      conjunto2 = 3;
      if (campo.value.length == conjunto1){
        campo.value = separador1 + campo.value;
      } 
      if (campo.value.length == conjunto2){
        campo.value = campo.value + separador2;
      } 
    }
    if (formato=='CPF'){
      separador1 = '.';	
      separador2 = '-';	
      if (campo.value.length == 3){
        campo.value = campo.value + separador1;
      } 
 
      if (campo.value.length == 7){
        campo.value = campo.value + separador1;
      } 
 
      if (campo.value.length == 11){
        campo.value = campo.value + separador2;
      } 
    }
 
    if (formato=='CNPJ'){
      separador1 = '.';	
      separador2 = '/';	
      separador3 = '-';	
      
      if (campo.value.length == 2){
        campo.value = campo.value + separador1;
      } 
 
      if (campo.value.length == 6){
        campo.value = campo.value + separador1;
      } 
 
      if (campo.value.length == 10){
        campo.value = campo.value + separador2;
      } 
      if (campo.value.length == 15){
        campo.value = campo.value + separador3;
      } 
    }
  }
  else {
	window.event.keyCode=null;
	return false;
	
  }
}
function EscondeDiv(obj){
	if(obj.checked == true)
	{				
		div1.style.display = '';
        div2.style.display = 'none';
	}else{
		div1.style.display = 'none';
        div2.style.display = '';
	}   
}
function MontaTela(obj){
	document.all.txtCpfCnpj.value = '';
	
	if(obj.checked == false){
		lblNome.innerText = '*Razão Social / Nome da Empresa:';
		lblCpf.innerText = '*CGC / CNPJ:';		
		document.all.txtCpfCnpj.outerHTML = document.all.txtCpfCnpj.outerHTML.replace('CPF','CNPJ');
		document.all.ibtEnviar.outerHTML = document.all.ibtEnviar.outerHTML.replace('CPF','CNPJ');
		document.all.txtCpfCnpj.maxLength=18;
		document.all.hdPessoa.value = 'J';		
	}else{
		lblNome.innerText = '*Nome Completo:';
		lblCpf.innerText = '*CPF:';		
		document.all.txtCpfCnpj.outerHTML = document.all.txtCpfCnpj.outerHTML.replace('CNPJ','CPF');
		document.all.ibtEnviar.outerHTML = document.all.ibtEnviar.outerHTML.replace('CNPJ','CPF');
		document.all.txtCpfCnpj.maxLength=14;
		document.all.hdPessoa.value = 'F';
	}
}
function Limpar(){
	var icampos = document.all.length;
	for(i=0; i < icampos; i++)
	{
		if (document.all.item[i].type == 'text')
			document.all.item[i].value = '';
		else			
			document.all.item[i].innerText = '';
	}
}
var gskn;
function pop_detalhe_status(msg) 
{
var nav = (document.layers); 
var iex = (document.all);
var skn = (nav) ? document.all.topdeck : topdeck.style;
gskn = skn;
if (nav) document.captureEvents(Event.MOUSEMOVE);
 
  var content= "<TABLE WIDTH=300 BORDER=0 CELLPADDING=2 CELLSPACING=0 class=form2><TR><TD width=239 align=center class=tbl-vermelho>Detalhes</TD><TD width=51 align=center class=tbl-vermelho><a href='javascript:kill();' title='Fechar detalhes'; class=tbl-vermelho>Fechar</a></TD></TR><TR><TD colspan=2 class=fundo-cinza3>" + msg + "</TD></TR></TABLE>"
  if (nav) { 
   get_mouse(nav,document.onmousemove,skn);
    skn.document.write(content); 
   skn.document.close();
   skn.display.style = "none";
  }
    else if (iex){
   get_mouse(nav,document.onmousemove,skn);
   document.all("topdeck").innerHTML = content;
   skn.visibility = "visible";  
  }
}
function get_mouse(e,nav,skn){
	var x = (nav) ? e.pageX : event.x+document.body.scrollLeft; 
	var y = (nav) ? e.pageY : event.y+document.body.scrollTop;
	skn.left = x - 60;
  skn.top  = y+10;
}
function kill(){
  gskn.visibility = "hidden";
}
function mostradetalhestatus(){
	//não faz nada
}
function DoCombo1(sOpenMenuID){
		var			eSrc = window.event.srcElement;
		var         i, j;
			if ("object" == typeof(document.all[sOpenMenuID])){
				var eMenu = document.all[sOpenMenuID];
				if( eMenu.style.visibility != "visible"){
					var max;
					var length;
					iChunk = iChunkStep;
					var eTR;
					var eTABLE = eSrc.parentElement.parentElement.parentElement.parentElement;
					eTR = eTABLE.children(0);
					if ("right" == sMenuPos){
						eMenu.style.left = eTABLE.offsetLeft;
						eMenu.style.top = 0;
					}
					else {
						eMenu.style.left = eTABLE.offsetLeft + 26;
						eMenu.style.top = eTABLE.offsetTop + eTR.offsetTop + eSrc.height;
					}
					eMenu.style.clip = "rect(0 0 0 0)";
					eMenu.style.visibility = "visible";
					return window.setTimeout("ShowMenu(" + eMenu.id + ")", iChunkDelay);
				}
				else{
					eMenu.style.visibility = "hidden";
				}
				
			}
	}
function MudaCampo(obj){
	if(event.keyCode==13) event.keyCode=9;
}
function RetiraCaracter(){
	if (event.keyCode == 60 || event.keyCode == 62 || event.keyCode == 37)
		 event.keyCode = null;
}
if (document.layers) {navigator.family = "nn4"}
if (document.all) {navigator.family = "ie4"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {navigator.family = "gecko"}
descarray = new Array(
"Os Fundos Municipais dos Direitos da Criança e do Adolescente são contas bancárias, abertas em bancos oficiais, administradas pelos Conselhos Municipais dos Direitos da Criança e Adolescente, instituídas pelo Estatuto da Criança e do Adolescente. Esses fundos podem receber recursos de diversas fontes, inclusive de contribuintes Pessoa Física e Pessoa Jurídica, sendo que estes recursos são utilização na promoção e atendimento aos direitos da criança e adolescente.",
"O Conselho Municipal dos Direitos da Criança e Adolescente é um órgão paritário (50% representantes do poder público e 50% representantes eleitos pela sociedade civil). Suas atribuições são: elaboração do diagnóstico local da situação social da criança e adolescente e do plano de ação, com a efetiva aplicação dos recursos; registro das entidades e inscrição dos projetos; edição de resoluções normativas que atendam às necessidades de defesa e promoção dos direitos da criança e adolescente e gestão do fundo dos direitos da criança e adolescente.",
"O IDI foi elaborado pela Unicef em 2001 e leva em consideração indicadores como: percentual de crianças com mães com escolaridade precária; crianças com pais com escolaridade precária; coberturas de vacinação (sarampo e DTP), entre outros. Obs.: cerca de 1.300 municípios brasileiros (24% do total) possuem um IDI até 0,4, o que significa um índice de desenvolvimento infantil muito baixo.",
"O IES foi elaborado pela Unicamp em 2003 e leva em consideração indicadores como: porcentagem de chefes de família pobres no município; taxa de desemprego formal na população em idade ativa; desigualdade de renda; alfabetização de pessoas acima de 5 anos; número médio de anos de estudo do chefe de domicílio; porcentagem de jovens na população e número de homicídios.&#13;&#10;Obs.: 2.290 municípios (42% do total) possuem um IES até 0,4, o que significa um alto índice de exclusão social",
"Informe o valor do lucro líquido de sua empresa. Obs.: Não devem ser informados lucros, rendimentos ou ganhos de capital oriundos do exterior, uma vez que não são passíveis de dedução fiscal.",
"Informe o valor total dos rendimentos tributáveis no ano. Exemplos: receitas obtidas pelo títular ou dependentes, como: salário, 13º salário, aposentadoria, aluguéis, pensão alimentícia, lucro na venda de bens, ganhos obtidos com investimentos no mercado financeiro, prêmios obtidos em loterias, entre outros. Obs.: São isentos e não-tributáveis ganhos de caderneta de poupança e saque do Fundo de Garantia do Tempo de Serviço (FGTS).",
"Informe o valor recolhido de INSS pelo declarante e dependente (se houver) do ano do exercício fiscal (2004). As despesas serão integralmente dedutíveis.",
"Indique o número de dependentes. <b>O valor fixo para dedução é de R$ 1.272,00 anuais, por dependente.</b>",
"Informe os gastos com despesas médicas para tratamento próprio, de dependentes e alimentandos.  São consideradas despesas com médicos, dentistas, psicólogos, exames, hospitais, serviços de radiologia, próteses dentárias, entre outras.",
"Informe a despesa integral com pensão alimentícia. Esta dedução somente é válida para  pensões homologadas judicialmente. As despesas médicas e com instrução pagas pelo alimentante não são dedutíveis como pensão alimentícia judicial.",
"Informe a soma dos pagamentos com Previdência Privada. <b>O valor da dedução é limitado a 12% do total dos Rendimentos Tributáveis.</b> O valor excedente não poderá ser considerado como despesa dedutível.",
"Informe aqui os gastos com sua instrução. <b>O valor individual dedutível é limitado a R$1.998.00.</b>",
"Informe aqui os gastos com a instrução de seus dependentes e alimentandos (homologados judicialmente). <b>O valor individual dedutível é limitado a R$1.998.00.</b>",
"Segurados com 65 anos, completos em 2003, ou mais, podem deduzir até R$ 12.696. Segurados cuja idade de 65 anos for alcançada ao longo de 2004 poderão multiplicar o valor de R$ 1.058,00 pelo número de meses faltantes para completar o exercício de 2004. Exemplo: Segurados que completam 65 anos em agosto de 2004 podem multiplicar R$ 1.058,00 por 4 (meses), ou seja, valor informado deverá ser R$ 4.232,00.",
"Soma das despesas dedutíveis.",
"Este valor é resultado da subtração dos Rendimentos Tributáveis com o Total das despesas dedutíveis, e determina qual alíquota deve ser aplicada ao contribuinte, conforme abaixo:Base de cálculo para resultados até R$ 12.696,00 – Isento. Base de cálculo para resultados acima de R$ 12.696,00 até R$ 25.380,00 – Aplica-se alíquota de 15% e será deduzido o valor de R$ 1.904,40. Base de cálculo para resultados acima de R$ 25.380,00 – Aplica-se alíquota de 27,5% e será deduzido o valor de R$ 5.076,90",
"Este valor é resultado da aplicação da alíquota correspondente à Base de Cálculo.",
"Este resultado é equivalente a 6% do Imposto de Renda Devido, sendo o limite máximo dedutível das doações feitas aos <b>Fundos dos Direitos da Criança e do Adolescente</b>. O valor excedente será considerado como doação não dedutível. Obs.: O limite de 6% é cumulativo aos incentivos fiscais direcionados a projetos culturais e audiovisuais aprovados pelo Ministério da Cultura.",
"Este valor é resultado da subtração do IR devido com o valor do campo Doação aos Fundos dos Direitos da Criança e do Adolescente.",
"Informe o valor anual do seu Imposto de Renda Retido na Fonte.",
"Este valor é resultado da subtração do Imposto de Renda Retido na Fonte com o Resultado do IR devido após a dedução."
);
 
overdiv="0";
 
function popLayer(obj, a){
 
if (navigator.family == "gecko") {pad="0"; bord="1 bordercolor=black";}
else {pad="1"; bord="0";}
desc = 	  "<table cellspacing=0 cellpadding="+pad+" border="+bord+"  bgcolor=#A6BEBE><tr><td>\n"
	+"<table cellspacing=0 cellpadding=3 border=0 width=100%><tr><td bgcolor=#FFF9D9><font size=1px face=arial>\n"
	+descarray[a]
	+"\n</font></td></tr></table>\n"
	+"</td></tr></table>";
 
if(navigator.family =="nn4") {
	document.object1.document.write(desc);
	document.object1.document.close();
	document.object1.left=x+1;
	document.object1.top=y+2;
	}
else if(navigator.family =="ie4"){
	object1.style.pixelWidth = 300;
	object1.innerHTML=desc;
	
	object1.style.pixelTop=document.body.scrollTop + document.body.parentElement.offsetHeight-300;
	object1.style.pixelLeft=document.body.scrollLeft + document.body.parentElement.offsetWidth-300;
	
	object1.style.pixelHeight = object1.firstChild.offsetHeight ;
	object1.style.pixelWidth = object1.firstChild.offsetWidth ;
	
	object1.style.pixelTop=document.body.scrollTop + AcertaPos(y, object1.style.pixelHeight , document.body.parentElement.offsetHeight);
	object1.style.pixelLeft=document.body.scrollLeft +AcertaPos(x, object1.style.pixelWidth , document.body.parentElement.offsetWidth);
}
else if(navigator.family =="gecko"){
	document.getElementById("object1").innerHTML=desc;
	document.getElementById("object1").style.left=x+1;
	document.getElementById("object1").style.top=y+2;
	
	}
	
}
function AcertaPos(coord, offset, total)
{
	if( (coord + offset + 30) > total)
		return coord - offset - 10;
	else
		return coord + 10;
}
 
function hideLayer(){
if (overdiv == "0") {
	if(navigator.family =="nn4") {eval(document.object1.top="-500");}
	else if(navigator.family =="ie4"){object1.innerHTML="";object1.style.pixelTop=-500;}
	else if(navigator.family =="gecko") {document.getElementById("object1").style.top="-500";}
	}
}
 
var isNav = (navigator.appName.indexOf("Netscape") !=-1);
 
function handlerMM(e){
x = (isNav) ? e.pageX : event.clientX;
y = (isNav) ? e.pageY : event.clientY;
}
if (isNav){document.captureEvents(Event.MOUSEMOVE);}
document.onmousemove = handlerMM;
