/*var IE = document.all;
var NS = document.layers;
if (IE) {
	document.write('<link rel=\"stylesheet\" href=\"styles_ie.css\">');
} else if (NS) {
	document.write('<link rel=\"stylesheet\" href=\"styles_ns.css\">');
}
*/
browserType = navigator.appName.charAt(0) + navigator.appVersion.charAt(0);
picture1 = new Image();
picture1.src = "/imagens/men_txt01.gif";
picture2 = new Image();
picture2.src = "/imagens/men_txt02.gif";
picture3 = new Image();
picture3.src = "/imagens/men_txt03.gif";
picture4 = new Image();
picture4.src = "/imagens/men_txt04.gif";
picture5 = new Image();
picture5.src = "/imagens/men_txt05.gif";

function msover(num) {
	document.images['rnd'].src = '/imagens/men_txt0' + num + '.gif';
}

function msout() {
	document.images['rnd'].src = '/imagens/men_txt00.gif';
}

function busca(f){
	var url="";
	if (f.elements[2].selectedIndex == 2) {
		url = "http://www.altavista.com/cgi-bin/query?pg=q&what=web&q=" + f.elements[0].value;
	}
	if (f.elements[2].selectedIndex == 3) {
		url = "http://www.miner.com.br";
	}
	if (f.elements[2].selectedIndex == 4) {
		url = "http://search.yahoo.com/bin/search?p=" + f.elements[0].value;
	}
	if (f.elements[2].selectedIndex == 5) {
		url = "http://busca.cade.com.br/scripts/engine.exe?p=" + f.elements[0].value;
	}
	if (f.elements[2].selectedIndex == 6) {
		url = "http://aonde.com/cgi/consulta2.cgi?keys=" + f.elements[0].value;
	}
	if (f.elements[2].selectedIndex == 7) {
		url = "http://www.hotbot.com/default.asp?MT=" + f.elements[0].value;
	}
	if (f.elements[2].selectedIndex == 8) {
		url = "http://www.webcrawler.com/cgi-bin/WebQuery?searchText=" + f.elements[0].value + "&maxHits=25";
	}
	if (f.elements[2].selectedIndex == 9) {
		url = "http://www.lycos.com/cgi-bin/pursuit?matchmode=and&cat=lycos&query=" + f.elements[0].value + "&backlink=217&maxhits=25";
	}
	launchWindow(url);
}

function launchWindow(myURL,myWidth,myHeight){
	if (browserType == "N2") {
		siteWindow = window.open("", "", "toolbar=1,location=0,directories=0,status=0,menubar=1,scrollbars=0,resizable=1,width=" + myWidth + ",height=" + myHeight);
		siteWindow.opener = self;
		siteWindow = myURL
	}
	if (browserType.charAt(0) == "M") {
		siteWindow = window.open(myURL);
		siteWindow.opener = self;
	} else {
		siteWindow = window.open(myURL);
		siteWindow.opener = self;
	}
}

function abre_janela(url){
/*  window.open(url, 'webmaster', 'toolbar=no,scrollbars=no,resizable=no,menubar=no,width=470,height=350');
  return false;
  */
  alert("obsoleto: utilize abrirJanela01(url)");
}

function abrirJanela01(url){
  var w = null;
  w = window.open(url, 'webmaster', 'toolbar=no, scrollbars=no, resizable=no, menubar=no, width=470, height=520');
  return false;
}

function abrirJanela02(url, nome){
	// Abre uma nova janela do Browser e retorna uma referencia a ela.
	// Parametros: url e nome da janela
	var w = null;
	w = window.open(url, nome, 'toolbar=no, scrollbars=yes, resizable=no, menubar=no, width=490, height=360');
	return w;
}

function abrirJanelaCartaz(url, nome){
	// Abre uma nova janela do Browser e retorna uma referencia a ela.
	// Parametros: url e nome da janela
	var w = null;
	w = window.open(url, nome, 'toolbar=no, scrollbars=yes, resizable=no, menubar=no, width=604, height=277');
	return w;
}

function nova_janela(id){
	if (id != 0) window.open(id, 'juridicos', 'scrollbars=yes, width=401, height=200');
}

function popUp(url) {
	sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
	self.name = "mainWin";
}

function abrir(url){
	window.open(url,"Informativo","top=25,left=25,toolbar=no,location=no,directories=no, menubar=no, scrollbars=no,resizable=no,width=400,height=330,status=no");
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function isIExplorer(){	
	var ua = window.navigator.userAgent;
	var p = ua.indexOf("MSIE", 0);
	var r = false;
	if (p  > -1){
		r = true;
	} else {
		r = false;
	}
	return r;	
}

function imprimir(){
	var da = (document.all) ? 1 : 0;
	var pr = (window.print) ? 1 : 0;
	var mac = (navigator.userAgent.indexOf("Mac") != -1); 

	if (pr) // NS4, IE5
		window.print()
	else if (da && !mac) // IE4 (Windows)
		vbPrintPage()
	else // other browsers
		alert("Desculpe seu browser não suporta esta função. Por favor utilize a barra de trabalho para imprimir a página.");
	
	return false;
}

function printPage(){
	alert('printPage: Obsoleto. Use imprimir()');
}

function testaNPROC1(nomeform){
	// funcao para testar campos de inclusao do numero do processo no push 1o. grau

	if (nomeform.cm.value=="")
		{
		alert("Digite o número da comarca.");
		nomeform.cm.select();
		return false;
		}
	
	else 
		{
		if ((nomeform.cm.value.substring(0,3)!="001") && (nomeform.cm.value.substring(0,3)!="247") && (nomeform.cm.value.substring(0,3)!="402") && (nomeform.cm.value.substring(0,3)!="205") && (nomeform.cm.value.substring(0,3)!="206") && (nomeform.cm.value.substring(0,3)!="208") && (nomeform.cm.value.substring(0,3)!="209") && (nomeform.cm.value.substring(0,3)!="210") && (nomeform.cm.value.substring(0,3)!="246") && (nomeform.cm.value.substring(0,3)!="213") && (nomeform.cm.value.substring(0,3)!="217") && (nomeform.cm.value.substring(0,3)!="218") && (nomeform.cm.value.substring(0,3)!="219") && (nomeform.cm.value.substring(0,3)!="220") && (nomeform.cm.value.substring(0,3)!="424") && (nomeform.cm.value.substring(0,3)!="463") && 
			(nomeform.cm.value.substring(0,3)!="486") && (nomeform.cm.value.substring(0,3)!="222") && (nomeform.cm.value.substring(0,3)!="223") && (nomeform.cm.value.substring(0,3)!="431") && (nomeform.cm.value.substring(0,3)!="224") && (nomeform.cm.value.substring(0,3)!="225") && (nomeform.cm.value.substring(0,3)!="226") && (nomeform.cm.value.substring(0,3)!="230") && (nomeform.cm.value.substring(0,3)!="231") && (nomeform.cm.value.substring(0,3)!="233") && (nomeform.cm.value.substring(0,3)!="444") && (nomeform.cm.value.substring(0,3)!="237") && (nomeform.cm.value.substring(0,3)!="248") && (nomeform.cm.value.substring(0,3)!="240") && (nomeform.cm.value.substring(0,3)!="241") && (nomeform.cm.value.substring(0,3)!="455") && 
			(nomeform.cm.value.substring(0,3)!="243") && (nomeform.cm.value.substring(0,3)!="235") && (nomeform.cm.value.substring(0,3)!="232") && (nomeform.cm.value.substring(0,3)!="203") && (nomeform.cm.value.substring(0,3)!="228") && (nomeform.cm.value.substring(0,3)!="214") && (nomeform.cm.value.substring(0,3)!="410") && (nomeform.cm.value.substring(0,3)!="204") && (nomeform.cm.value.substring(0,3)!="441") && (nomeform.cm.value.substring(0,3)!="207") && (nomeform.cm.value.substring(0,3)!="216") && (nomeform.cm.value.substring(0,3)!="422") && (nomeform.cm.value.substring(0,3)!="430") && (nomeform.cm.value.substring(0,3)!="215") && (nomeform.cm.value.substring(0,3)!="234") && (nomeform.cm.value.substring(0,3)!="451") && 
			(nomeform.cm.value.substring(0,3)!="427") && (nomeform.cm.value.substring(0,3)!="479") && (nomeform.cm.value.substring(0,3)!="201") && (nomeform.cm.value.substring(0,3)!="459") && (nomeform.cm.value.substring(0,3)!="221") && (nomeform.cm.value.substring(0,3)!="415") && (nomeform.cm.value.substring(0,3)!="435") && (nomeform.cm.value.substring(0,3)!="426") && (nomeform.cm.value.substring(0,3)!="244") && (nomeform.cm.value.substring(0,3)!="227") && (nomeform.cm.value.substring(0,3)!="439") && (nomeform.cm.value.substring(0,3)!="403") && (nomeform.cm.value.substring(0,3)!="491") && (nomeform.cm.value.substring(0,3)!="487") && (nomeform.cm.value.substring(0,3)!="401") && (nomeform.cm.value.substring(0,3)!="436") &&
			(nomeform.cm.value.substring(0,3)!="484") && (nomeform.cm.value.substring(0,3)!="460") && (nomeform.cm.value.substring(0,3)!="447") && (nomeform.cm.value.substring(0,3)!="421") && (nomeform.cm.value.substring(0,3)!="437") && (nomeform.cm.value.substring(0,3)!="406") && (nomeform.cm.value.substring(0,3)!="238") && (nomeform.cm.value.substring(0,3)!="456") && (nomeform.cm.value.substring(0,3)!="420") && (nomeform.cm.value.substring(0,3)!="409") && (nomeform.cm.value.substring(0,3)!="423") && (nomeform.cm.value.substring(0,3)!="229") && (nomeform.cm.value.substring(0,3)!="211") && (nomeform.cm.value.substring(0,3)!="412") && (nomeform.cm.value.substring(0,3)!="462") && (nomeform.cm.value.substring(0,3)!="474") &&
			(nomeform.cm.value.substring(0,3)!="475") && (nomeform.cm.value.substring(0,3)!="489") && (nomeform.cm.value.substring(0,3)!="450") && (nomeform.cm.value.substring(0,3)!="245") && (nomeform.cm.value.substring(0,3)!="434") && (nomeform.cm.value.substring(0,3)!="447") && (nomeform.cm.value.substring(0,3)!="490") && (nomeform.cm.value.substring(0,3)!="491") && (nomeform.cm.value.substring(0,3)!="466") && (nomeform.cm.value.substring(0,3)!="467") && (nomeform.cm.value.substring(0,3)!="408") && (nomeform.cm.value.substring(0,3)!="419") && (nomeform.cm.value.substring(0,3)!="461") && (nomeform.cm.value.substring(0,3)!="449") && (nomeform.cm.value.substring(0,3)!="468") && (nomeform.cm.value.substring(0,3)!="212") &&
			(nomeform.cm.value.substring(0,3)!="494") && (nomeform.cm.value.substring(0,3)!="495") && (nomeform.cm.value.substring(0,3)!="469") && (nomeform.cm.value.substring(0,3)!="485") && (nomeform.cm.value.substring(0,3)!="497") && (nomeform.cm.value.substring(0,3)!="411") && (nomeform.cm.value.substring(0,3)!="432") && (nomeform.cm.value.substring(0,3)!="477") && (nomeform.cm.value.substring(0,3)!="472") && (nomeform.cm.value.substring(0,3)!="242") && (nomeform.cm.value.substring(0,3)!="465") && (nomeform.cm.value.substring(0,3)!="454") && (nomeform.cm.value.substring(0,3)!="428") && (nomeform.cm.value.substring(0,3)!="496") && (nomeform.cm.value.substring(0,3)!="478") && (nomeform.cm.value.substring(0,3)!="457") &&
			(nomeform.cm.value.substring(0,3)!="438") && (nomeform.cm.value.substring(0,3)!="429") && (nomeform.cm.value.substring(0,3)!="443") && (nomeform.cm.value.substring(0,3)!="418") && (nomeform.cm.value.substring(0,3)!="502") && (nomeform.cm.value.substring(0,3)!="446") && (nomeform.cm.value.substring(0,3)!="464") && (nomeform.cm.value.substring(0,3)!="476") && (nomeform.cm.value.substring(0,3)!="504") && (nomeform.cm.value.substring(0,3)!="413") && (nomeform.cm.value.substring(0,3)!="236") && (nomeform.cm.value.substring(0,3)!="200") && (nomeform.cm.value.substring(0,3)!="483") && (nomeform.cm.value.substring(0,3)!="452") && (nomeform.cm.value.substring(0,3)!="471") && (nomeform.cm.value.substring(0,3)!="239") &&
			(nomeform.cm.value.substring(0,3)!="202") && (nomeform.cm.value.substring(0,3)!="440") && (nomeform.cm.value.substring(0,3)!="400") && (nomeform.cm.value.substring(0,3)!="500") && (nomeform.cm.value.substring(0,3)!="416") && (nomeform.cm.value.substring(0,3)!="482"))
			
			
		

		{
<!--			alert("Só estão disponíveis processos das comarcas de Recife (001), Olinda (226), Paulista (231), Jaboatao (222), Caruaru (213), Goiana (218), Petrolina (233), Aliança (402), Macaparana (431), Igarassu (220), Itamaracá (463), Toritama (455), Limoeiro (223), Surubim (240), Cabo (210), Timbaúba (241), Glória do Goitá (217), Nazaré da Mata (225) ou Vitória (243), Brejo da madre de Deus (409), Inajá (423), Panelas (229)");
					<!--(07/05/07) - TerraNova (489), Serrita (450), Salgueiro (245), Parnamirim (434)
					<!-- 06/08/2007 - São josé do Belmonte (447), Verdejante (490), Mirandiba (491)-->
					<!-- 28/08/2008 - Buenos aires e Tracunhaém -->
					<!--04/12/08 - Jurema - 428 -->
					<!-- 09/12/08 - Tacaimbó-496 -  >
					<!-- 15/12/08 - Alagoinha - 478 -->
					<!-- 18/12/08 - Venturosa - 457 / Poção - 438 -->
					<!-- 03/02/2009 - Lagoa dos gatos - 429 -->
					<!-- 09/02/2009 - Sanharó - 443 -->
					<!-- 14/04/2009 -Custódia - 418 -->
					<!-- 02/06/2009 - Primavera - 471 -->
					<!-- 02/06/2009 - Sertania - 239 -->
					<!-- sem previsão - Agrestina - 400 -->
					<!-- 09/06/2009 - Altinho - 202 -->
					<!-- 09/06/2009 - Riacho das Almas - 440 -->
					<!-- 15/06/09 - Agrestina - 400 -->
					<!-- 14/07/09 - Caetés - 500  / Cumaru - 416 --> 
					<!-- 03/08/09 - Lagoa do ouro - 482 -->
					
					
					
			alert("Só estão disponíveis processos das comarcas constantes na Caixa de Seleção de Comarca - cm.");
			nomeform.cm.select();
			return false;
			}
		}
		
	if (nomeform.ano.value=="")
		{
		alert("Digite o Ano.");
		nomeform.ano.select();
		return false;
		}
	else
		{ 
		if ((isNaN(nomeform.ano.value)))
			{
			alert("Digite o ano correto.");
			nomeform.ano.select();
			return false;
			}
		}	
	
	if (isNaN(nomeform.vproc1.value))
		{
		if (nomeform.vproc1.value.length!=6)
 			{
			alert("O número do processo deve ter 6 dígitos.");
			nomeform.vproc1.select();
			return false;
			}
		
	else
		{
		alert("O dado para esta pesquisa deve ser numérico.");
		nomeform.vproc1.select();
		return false;
		}	
	}
	
	if (isNaN(nomeform.dv.value))
		{
	 	alert("Dígito incorreto (dv). Digite novamente.");
	 	nomeform.dv.select();
		return false;
		}
	if (isNaN(nomeform.sp.value))
		{
	 	alert("Número incorreto de subprocesso (sp). Digite novamente.");
	 	nomeform.sp.select();
		return false;
		}
}
function filtrarCaracteres01(campo){
	/* Esta funcoes so permite a entrada */
	var campo = document.getElementById(campo);
	var er = /(^\s+)|(\s{2,})|([^a-zA-Z\s\u00C0-\u00FC]+)/;
	if (campo.value.search(er) != -1){
		campo.value = campo.value.replace(er,"");
	}
}
function filtrarCaracteres02(campo){
	var campo = document.getElementById(campo);
	var er = /(\s+$)/;
	if (campo.value.search(er) != -1){
		campo.value = campo.value.replace(er,"");
	}
}

function setRenderStatus(obj, bRender){	
	var o = document.getElementById(obj);
	if (bRender == true) bRender = 'block';
	if (bRender == false) bRender = 'none';
	if (o) o.style.display = bRender;			
}

function getRenderStatus(obj){
	var o = document.getElementById(obj);
	var ret = false;
	if (o){
		if (o.style.display == "block")
			ret = true
		else 
			ret = false;
	}
	return ret;
}

function mascaraDeData(obj){
	// Filtra um campo de data permitindo apenas o formato mm/dd/aaaa com restrição do uso apenas de números
	// Ex.: onKeyUp = mascaraDeData(this)
	var re = /([^\d]+)([\d|\/]*$)/;
	var re1 = /[^\d|\/]$/;
	var re2 = /^(\d{2})(\d+)/;
	var re3 = /^(\d{2}\/\d{2})(\d+)/;
	var re4 = /([^\d]+)([\d]*$)/;
	
	if (obj.value.charAt(0).search(re) != -1) {
		obj.value = obj.value.replace(re, "$2");
	}
	
	if (obj.value.charAt(1).search(re) != -1) {
		obj.value = obj.value.replace(re, "$2");
	}
	
	if (obj.value.charAt(2).search(re1) != -1) {
		obj.value = obj.value.replace(re1, "/");
	}
	else if (obj.value.search(re2) != -1) {
		obj.value = obj.value.replace(re2, "$1/$2");
	}
	
	if (obj.value.charAt(3).search(re) != -1) {
		obj.value = obj.value.replace(re, "/$2");
	}
	
	if (obj.value.charAt(4).search(re4) != -1) {
		obj.value = obj.value.replace(re4, "$2");
		if (obj.value.charAt(4).search(re4) != -1) {
			obj.value = obj.value.replace(re4, "$2/");
		}
	}
	
	if (obj.value.charAt(5).search(re1) != -1) {
		obj.value = obj.value.replace(re1, "/");
	}
	else if (obj.value.search(re3) != -1) {
		obj.value = obj.value.replace(re3, "$1/$2");
	}
	
	if (obj.value.charAt(6).search(re4) != -1) {
		obj.value = obj.value.replace(re4, "/$2");
	}
	
	if (obj.value.charAt(7).search(re4) != -1) {
		obj.value = obj.value.replace(re4, "$2");
	}
	
	if (obj.value.charAt(8).search(re4) != -1) {
		obj.value = obj.value.replace(re4, "$2");
	}
	
	if (obj.value.charAt(9).search(re4) != -1) {
		obj.value = obj.value.replace(re4, "$2");
	}
	if (obj.value.length > 10) {
		obj.value = obj.value.replace(obj.value,obj.value.substring(0,10));
	}
}

function validarCampoVazio(obj){
//	var c = document.getElementById(idCampo.id);
	if (obj){
		if (obj.value.length == 0){
			alert('O campo está vazio');
			obj.focus();
		}
	}
}

function fnEstaVazio(obj){	
	var o = document.getElementById(obj);
	var ret = false;
	if (o){
		if (o.value == "")
			ret = true
		else
			ret = false;
	}
	return ret;
}

function filtraLetras(campo){
/*
	ESTA FUNCAO AINDA PRECISA SER MODIFICADA E PADRONIZADA O NOME
	Autor: Fabio
	Data de Criacao: 14/12/2006
	Descricao: Impede a digitacao de caracteres alfa-numericos 
*/
	var s = campo.value;
	var n = 0;
	for (i = 0; i < s.length; i++){
		n = s.charCodeAt(i);
		if ((n < 48) || (n > 57)){
			campo.value = campo.value.replace(s,"");
		}
	}

/*
	var er = /(^\s+)|(\s{2,})|([^0-9\s\u00C0-\u00FC]+)/;
	if (campo.value.search(er) != -1){
		campo.value = campo.value.replace(er,"");
	}
*/
}

function filtraNumero(campo){
/*
	ESTA FUNCAO AINDA PRECISA SER MODIFICADA E PADRONIZADA O NOME
	Autor: Fabio
	Data de Criacao: 14/12/2006
	Descricao: Impede a digitacao de caracteres alfa-numericos 
*/

	//var campo = document.getElementById(campo);
	var er = /(^\s+)|(\s{2,})|([^a-zA-Z\s\u00C0-\u00FC]+)/;
	if (campo.value.search(er) != -1){
		campo.value = campo.value.replace(er,"");
	}
}

function formatarMoeda(obj){
	
	var valor = obj.value;
	var retorno = "";
	
	if ((window.event.keyCode >= 48) && (window.event.keyCode <= 57) || (String.fromCharCode(window.event.keyCode) == ".") || (String.fromCharCode(window.event.keyCode) == ",")){
		window.status = window.event.keyCode;
		
		
	} else {
		
		window.event.cancelBubble = true;
	}
}

function obterValor(obj){
	var r = "";
	if (typeof(obj) == "string"){
		r = obj;
	}else if(typeof(obj) == "object"){
		
	}
}

function removerEspacos(os){
	/*
		Autor: Alessandro Claudio
		Criacao: 15/12/2006
		Descricao: Remove espacos existentes no inicio e/ou fim de um string
		Entrada: Uma string
		Saida: Uma string com todos os espacos antes e depois removidos
	*/
	if (typeof(os) == "object") s = obterValor(os);
	if (typeof(os) == "string") s = os;
	if (s == " ") s = "";
	if ((s.length > 0) && (s != " ")){
		while (s.charAt(0) == " "){
			s = s.substr(1, s.length - 1);
		}				
		while (s.charAt(s.length - 1) == " "){
			s = s.substr(0, s.length - 1);
		}
	}
	return s;
}

/* Estas funcções que seguem são para validar o campo CPF / CNPJ,
quem as colocou aqui foi Isabella Gayão, para que não fosse criado um arquivo em cada diretório para fazer essa validação.
*/

function showHideLayers(qualSubMenu, showhide) {
	var menu = document.getElementById(qualSubMenu);
	menu.style.display = showhide;
}


var NUM_DIGITOS_CPF  = 11;
var NUM_DIGITOS_CNPJ = 14;
var NUM_DGT_CNPJ_BASE = 8;

function validaDocumento(obj)
{var val = obj.value;
 var base = val.substring(0, val.length-2);
if (base.length >11)
//Verifica se é cpf ou cnpj
{
	if(isCnpj(val) == false){
		alert("Digite corretamente o CNPJ do autor.") ;
		return false;
	}else
		{ return true; }
}else{
	if(isCpf(val)==false){
		alert("Digite corretamente o CPF do autor.");
		return false;
	}
	else{return true;}
}//fim else
}//fim function

function isCpf(pCpf)
{
	var numero = formatCpfCnpj(pCpf, false, false);
	var base = numero.substring(0, numero.length - 2);
	var digitos = dvCpfCnpj(base, false);
	var algUnico, i;

	// Valida dígitos verificadores
	if (numero != base + digitos) return false;

	/* Não serão considerados válidos os seguintes CPF:
	 * 000.000.000-00, 111.111.111-11, 222.222.222-22, 333.333.333-33, 444.444.444-44,
	 * 555.555.555-55, 666.666.666-66, 777.777.777-77, 888.888.888-88, 999.999.999-99.
	 */
	algUnico = true;
	for (i=1; i<NUM_DIGITOS_CPF; i++)
	{
		algUnico = algUnico && (numero.charAt(i-1) == numero.charAt(i));
	}
	return (!algUnico);
} //isCpf

function isCnpj(pCnpj)
{
	var numero = formatCpfCnpj(pCnpj, false, true);
	var base = numero.substring(0, NUM_DGT_CNPJ_BASE);
	var ordem = numero.substring(NUM_DGT_CNPJ_BASE, 12);
	var digitos = dvCpfCnpj(base + ordem, true);
	var algUnico;

	// Valida dígitos verificadores
	if (numero != base + ordem + digitos) return false;

	/* Não serão considerados válidos os CNPJ com os seguintes números BÁSICOS:
	 * 11.111.111, 22.222.222, 33.333.333, 44.444.444, 55.555.555,
	 * 66.666.666, 77.777.777, 88.888.888, 99.999.999.
	 */
	algUnico = numero.charAt(0) != '0';
	for (i=1; i<NUM_DGT_CNPJ_BASE; i++)
	{
		algUnico = algUnico && (numero.charAt(i-1) == numero.charAt(i));
	}
	if (algUnico) return false;

	/* Não será considerado válido CNPJ com número de ORDEM igual a 0000.
	 * Não será considerado válido CNPJ com número de ORDEM maior do que 0300
	 * e com as três primeiras posições do número BÁSICO com 000 (zeros).
	 * Esta crítica não será feita quando o no BÁSICO do CNPJ for igual a 00.000.000.
	 */
	if (ordem == "0000") return false;
	return (base == "00000000"
		|| parseInt(ordem, 10) <= 300 || base.substring(0, 3) != "000");
} //isCnpj

function formatCpfCnpj(pCpfCnpj, pUseSepar, pIsCnpj)
{
	if (pIsCnpj==null) pIsCnpj = false;
	if (pUseSepar==null) pUseSepar = true;
	var maxDigitos = pIsCnpj? NUM_DIGITOS_CNPJ: NUM_DIGITOS_CPF;
	var numero = unformatNumber(pCpfCnpj);

	numero = numero.lpad(maxDigitos, '0');
	if (!pUseSepar) return numero;

	if (pIsCnpj)
	{
		reCnpj = /(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})$/;
		numero = numero.replace(reCnpj, "$1.$2.$3/$4-$5");
	}
	else
	{
		reCpf  = /(\d{3})(\d{3})(\d{3})(\d{2})$/;
		numero = numero.replace(reCpf, "$1.$2.$3-$4");
	}
	return numero;
} //formatCpfCnpj

function dvCpfCnpj(pEfetivo, pIsCnpj)
{
	if (pIsCnpj==null) pIsCnpj = false;
	var i, j, k, soma, dv;
	var cicloPeso = pIsCnpj? NUM_DGT_CNPJ_BASE: NUM_DIGITOS_CPF;
	var maxDigitos = pIsCnpj? NUM_DIGITOS_CNPJ: NUM_DIGITOS_CPF;
	var calculado = formatCpfCnpj(pEfetivo, false, pIsCnpj);
	calculado = calculado.substring(2, maxDigitos);
	var result = "";

	for(j = 1; j <= 2; j++)
	{
		k = 2;
		soma = 0;
		for (i = calculado.length-1; i >= 0; i--)
		{
			soma += (calculado.charAt(i) - '0') * k;
			k = (k-1) % cicloPeso + 2;
		}
		dv = 11 - soma % 11;
		if (dv > 9) dv = 0;
		calculado += dv;
		result += dv
	}

	return result;
} //dvCpfCnpj

String.prototype.lpad = function(pSize, pCharPad)
{
	var str = this;
	var dif = pSize - str.length;
	var ch = String(pCharPad).charAt(0);
	for (; dif>0; dif--) str = ch + str;
	return (str);
} //String.lpad

String.prototype.trim = function()
{
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
} //String.trim

function unformatNumber(pNum)
{
	return String(pNum).replace(/\D/g, "").replace(/^0+/, "");
} //unformatNumber

function Tecla(e)
{
	if (document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
		if (tecla > 47 && tecla < 58) // numeros de 0 a 9
			return true;
		else
		{
			if (tecla != 8) // backspace
				event.keyCode = 0;
				//return false;
			else
				return true;
		}//fim else
}//fim_Tecla(e)

function Limpar(valor, validos) { 
// retira caracteres invalidos da string 
var result = ""; 
var aux; 
for (var i=0; i < valor.length; i++) { 
aux = validos.indexOf(valor.substring(i, i+1)); 
if (aux>=0) { 
result += aux; 
} 
} 
return result; 
} 

// Aqui encerra a validação do CPF/CNPJ

function fnQuantosCheckBoxesSelecionados(){
	var checks = document.all.tags("input");
	var selecionados = 0;
	for (i = 0; i < checks.length; i++){
		if (checks(i).type == "checkbox"){
			if(checks(i).checked == true){
				selecionados++;
			}
		}
	}
	return selecionados;
}

function fnQuantosRadioButtonsSelecionados(){
	var radios = document.getElementsByTagName("input");
	var selecionados = 0;
	for (i = 0; i < radios.length; i++){
		if (radios[i].type == "radio"){
			if(radios[i].checked == true){
				selecionados++;
			}
		}
	}
	return selecionados;
}

function ehEmail(valor)
{

        var i = 1;
        var formatoOk = true;      
        var valorLength = valor.length;
        // procurando a @.
        while ((i < valorLength) && (valor.charAt(i) != "@")) 
        {
          i++;
        }
        if ((i >= valorLength) || (valor.charAt(i) != "@")) formatoOk = false;
        else i += 2;
        // procurando pelo .
        while ((i < valorLength) && (valor.charAt(i) != ".")) 
        {
          i++;
        }
        // Deve existir pelo menos um caracter antes do "."
        if ((i >= valorLength - 1) || (valor.charAt(i) != ".")) formatoOk = false;
	return formatoOk;
}

function interceptarTecla(tipo){
	/*
	*/

	var c = event.keyCode;	

	switch(tipo){
		case 1:{
				if (
				(
					((c >= 65) && (c <= 90)) || 
					((c >= 96) && (c <= 122))) || 
					(c <= 32) || (c == 37) || (c == 39) || (c == 38) || (c == 40) 
				){
				}else {		
					event.returnValue=false;
				}
				break;				
			}
		case 2:{				
			if (
			(
				((c >= 65) && (c <= 90)) || 
				((c >= 96) && (c <= 122))) || 
				(c <= 32) || (c == 37) || (c == 39) || (c == 38) || (c == 40)  || 
				((c >= 0) && (c <= 57))				
			){
			}else {		
				event.returnValue=false;
			}
		}
	}
}

function validarTexto(tipo, evento, texto){
	/*
		recebe um texto e valida conforme o Tipo especificado
		
		tipos:
		
		1 - Retorna True se o texto tem apenas caracteres [a-z] e/ou [A-Z]
	*/
	
	alert(event.keyCode)
	event.returnValue=false;
	
	for (i = 0; i < texto.length; i++){
		var c = texto.charCodeAt(i);
		if ((((c >= 65) && (c < 90)) || ((c >= 97) && (c <= 122))) || (c == 32)){
			// ok
		} else {		
			event.cancelBubble = true;			
			break;
		}
	}
	
}

