  window.defaultStatus = "ESDM - Escola Superior de Direito Municipal";

	var wd
  function parseelement(thisone)
  {    
   wd="w"
   var tempnum=thisone.value
   for (i=0;i<tempnum.length;i++)
   {
    if (tempnum.charAt(i)==",")
    {
     wd="d"
     break
    }
   }
   if (wd=="w")
    thisone.value=tempnum+",00"
   else
   {
    if (tempnum.charAt(tempnum.length-2)==",")
    {
     thisone.value=tempnum+"0"
    }
    else if (tempnum.charAt(tempnum.length-1)==",")
    {
     thisone.value=tempnum+"00"
    }
   }
  }
 
	function proximoCampo(cForm, cNext){
		formname = cForm;
		nextfield = cNext; // nome do próximo campo
		
			netscape = "";
			ver = navigator.appVersion; len = ver.length;
			for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
				netscape = (ver.charAt(iln+1).toUpperCase() != "C");

				function keyDown(DnEvents) {
					// ve quando e o netscape ou IE
					k = (netscape) ? DnEvents.which : window.event.keyCode;
					if (k == 13) { // preciona tecla enter
						if (nextfield == 'submit'){
//							valida(cForm);
							document.form.submit()
						}else{
							eval('document.form.' + nextfield + '.focus()');
							return false;
						}
					}
				}
		
			document.onkeydown = keyDown; // work together to analyze keystrokes
			if (netscape) document.captureEvents(Event.KEYDOWN|Event.KEYUP);
		// End -->
	}

	function selecionar_tudo(frm){
		for (i=0;i<document.getElementById(frm).elements.length;i++)
			if(document.getElementById(frm).elements[i].type == "checkbox")	
				document.getElementById(frm).elements[i].checked=1
	}	
	
	function deselecionar_tudo(frm){
		for (i=0;i<document.getElementById(frm).elements.length;i++)
			if(document.getElementById(frm).elements[i].type == "checkbox")	
				document.getElementById(frm).elements[i].checked=0
	}	
	
	function mostra(aux){
		document.getElementById(aux).style.display='block';
	}

	function esconde(aux){
		document.form.idItem.value ='';
		document.form.codigo.value ='';
		document.getElementById(aux).style.display='none';
	}
	
	function campo(cmp){
		document.getElementById(cmp).focus();	
	}

	function imprime_lpt1(arg1) {
		//Cria objeto para manipulacao de arquivos no cliente.
		var fso = new ActiveXObject("Scripting.FileSystemObject");
		//Verifica a existencia do arquivo de impressao antigo e o deleta;
		if ( fso.FileExists("c:\\temp\\imprime.prn") ) {
			fso.DeleteFile("c:\\temp\\imprime.prn");
		} //if
		//Verifica a nao existencia do arquivo responsavel pela impressao na impressora bematech.
		if ( !(fso.FileExists("c:\\temp\\imprime.bat")) ) {
			//Cria o arquivo imprime.bat, escreve o comando responsavel pela impressao e fecha o arquivo.
			var b = fso.CreateTextFile("c:\\temp\\imprime.bat", true);
			b.WriteLine("net use lpt1 /delete");
			b.WriteLine("net use lpt1 \\\\exata8\\ZDesigne");
			b.WriteLine("type c:\\temp\\imprime.prn > prn");
			b.Close();
		} //if
		//Cria o arquivo imprime.prn, escreve todo o texto para ser impresso e fecha o arquivo.
		var a = fso.CreateTextFile("c:\\temp\\imprime.prn", true);
		a.WriteLine(arg1);
		a.Close();
		//Cria um objeto para execucao de um programa no computador do cliente.
		var WshShell = new ActiveXObject("WScript.Shell");
		//Executa o arquivo responsavel pela impressao do arquivo imprime.prn.
		var oExec = WshShell.Exec("c:\\temp\\imprime.bat");
	} //Fim do imprime_lpt1

	function escondeCamada(camada) {
		var obj = document.getElementById(camada);
		obj.style.visibility = 'hidden';
	}
	
	function mostraCamada(camada,esq,topo) {
		var obj = document.getElementById(camada);
		
//		var divEsquerda = 0 + esq;
//		var divTopo = 0 + topo;
		
		if (document.body.scrollWidth>770) esquerda = (document.body.scrollWidth - 770)/2;	
//		topo = 337;
		obj.style.left = esq;
		obj.style.top = topo;
		obj.style.visibility='visible';
	}

  //limpa os campos
  
  function (c){
    while((cx=c.indexOf("-"))!=-1){		
      c = c.substring(0,cx)+c.substring(cx+1);
    }
    while((cx=c.indexOf("/"))!=-1){		
      c = c.substring(0,cx)+c.substring(cx+1);
    }
    while((cx=c.indexOf(","))!=-1){		
      c = c.substring(0,cx)+c.substring(cx+1);
    }
    while((cx=c.indexOf("."))!=-1){		
      c = c.substring(0,cx)+c.substring(cx+1);
    }
    while((cx=c.indexOf("("))!=-1){		
      c = c.substring(0,cx)+c.substring(cx+1);
    }
    while((cx=c.indexOf(")"))!=-1){		
      c = c.substring(0,cx)+c.substring(cx+1);
    }
    while((cx=c.indexOf(" "))!=-1){		
      c = c.substring(0,cx)+c.substring(cx+1);
    }
    return(c);
  }

// mask para Data (dd/mm/aaaa) evento OnKeyUp
	function maskData(event, obj) {
		tam = obj.value.length;
		if ((tam==2) || (tam==5)) obj.value = obj.value + "/";
	}

// mask para CEP (00000-000) evento OnKeyUp
	function maskCEP(event, obj) {
		tam = obj.value.length;
		if (tam==5) obj.value = obj.value + "-";
	}

// mask para Hora (hh:mm:ss) evento OnKeyUp
	function maskHora(event, obj) {
		tam = obj.value.length;
		if ((tam==2) || (tam==5)) obj.value = obj.value + ":";
	}

	function maskHora5(event, obj) {
		tam = obj.value.length;
		if (tam==2) obj.value = obj.value + ":";
	}

	function ehHora(horas){ 
		hrs = (horas.substring(0,2)); 
		min = (horas.substring(3,5)); 
								 
		estado = ""; 

		if ((hrs < 00 ) || (hrs > 23) || ( min < 00) ||( min > 59)){ 
			return false;
		}else if (horas == "") { 
			return false;
		}else if (estado == "errada") { 
			return false;
		}else if (horas.length != 5){ 
			return false;
		}
		
		return true;
	} 

// mask para CNPJ (00000000/0000-00) evento OnKeyUp
	function maskCNPJ(event, obj) {
		tam = obj.value.length;
		if (tam==8) obj.value = obj.value + "/";
		if (tam==13) obj.value = obj.value + "-";
	}

// mask para Código (0000-000-0000-AAAA)
	function maskItem(event, obj) {
		tam = obj.value.length;
		if (tam==4) obj.value = obj.value + "-";
		if (tam==8) obj.value = obj.value + "-";
		if (tam==13) obj.value = obj.value + "-";
	}
	
	function selectOption(selectID, Option){
		obj = document.getElementById(selectID);
		for(var i=0;i<obj.options.length;i++){
			//alert(obj.options[i].selected + ' = ' + (obj.options[i].value == Option) );
			//alert( obj.options[i].value );
			obj.options[i].selected = (obj.options[i].value == Option);
		}
	}

	// troca a cor da linha ao selecionar o checkbox
	var arCor = new Array();
	function cor(obj,i, chk){
		if (arCor[i]=="1") {
			obj.style.backgroundColor = (i % 2 == 1)?"#F0F0F0":"#FFFFFF";
			arCor[i]="0";
		} else {
			obj.style.backgroundColor = '#dbd9d8';
			arCor[i]="1";
		}
	}

	var arCor2 = new Array();
	function cor2(obj,i, chk){
		if (arCor2[i]=="1") {
			obj.style.backgroundColor = "#F0F0F0";
			arCor2[i]="0";
		} else {
			obj.style.backgroundColor = '#dbd9d8';
			arCor2[i]="1";
		}
	}

	var arCor3 = new Array();
	function cor3(obj,i, chk){
		if (arCor3[i]=="1") {
			obj.style.backgroundColor = "#F0F0F0";
			arCor3[i]="0";
		} else {
			obj.style.backgroundColor = '#dbd9d8';
			arCor3[i]="1";
		}
	}
//valida CNPJ
  function validaCNPJ(StrCGC){
    
    var varFirstChr = StrCGC.charAt(0);
    var vlMult,vlControle,s1, s2 = "";
    var i,j,vlDgito,vlSoma = 0;
    
    for ( var i=0; i<=13; i++ ){
      var c = StrCGC.charAt(i);
      if(!(c>="0") && (c<="9")){
        return false;
      }
      if(c!=varFirstChr){
        vaCharCGC = true;
      }
    }
    
    if(!vaCharCGC){
      return false;
    }
    
    s1 = StrCGC.substring(0,12);
    s2 = StrCGC.substring(12,15);
    vlMult = "543298765432";
    vlControle = "";
     
    for (j=1; j<3; j++){
      vlSoma = 0;
      for (i=0; i<12; i++){
        vlSoma += eval( s1.charAt(i) )* eval( vlMult.charAt(i) );
      }
     
      if(j == 2){
        vlSoma += (2 * vlDgito);
      }
      
      vlDgito = ((vlSoma*10) % 11);
      
      if(vlDgito == 10){
        vlDgito = 0;
      }
      
      vlControle = vlControle + vlDgito;
      vlMult = "654329876543";
    }
  
    if(vlControle != s2){
      return false;
    } else {
      return true;
    }
  }

  //valida CPF
  function validaCPF(StrCPF){
    
    x = 0;
    soma = 0;
    dig1 = 0;
    dig2 = 0;
    texto = "";
    StrCPF1="";
    len = StrCPF.length;
    x = len -1;
    
    for (var i=0; i <= len - 3; i++){
      y = StrCPF.substring(i,i+1);
      soma = soma + ( y * x);
      x = x - 1;
      texto = texto + y;
    }
    
    dig1 = 11 - (soma % 11);
    if (dig1 == 10) dig1=0 ;
    if (dig1 == 11) dig1=0 ;
    StrCPF1 = StrCPF.substring(0,len - 2) + dig1 ;
    x = 11; soma=0;
    
    for (var i=0; i <= len - 2; i++){
      soma = soma + (StrCPF1.substring(i,i+1) * x);
      x = x - 1;
    }
    
    dig2= 11 - (soma % 11);
    
	if (dig2 == 10) dig2=0;
    if (dig2 == 11) dig2=0;
    if ((dig1 + "" + dig2) == StrCPF.substring(len,len-2)){
      return true;
    } else {
      return false;
	}
  }

  //valida a data
  function isdate(Data){
    
    var dma = -1;
    var data = Array(3);
    var ch = Data.charAt(0); 
    for(i=0; i < Data.length && (( ch >= '0' && ch <= '9' ) || ( ch == '/' && i != 0 ) ); ){
     data[++dma] = '';
     if(ch!='/' && i != 0) return false;
     if(i != 0 ) ch = Data.charAt(++i);
     if(ch=='0') ch = Data.charAt(++i);
     while( ch >= '0' && ch <= '9' ){
     data[dma] += ch;
     ch = Data.charAt(++i);
     } 
    }
    if(ch!='') return false;
    if(data[0] == '' || isNaN(data[0]) || parseInt(data[0]) < 1) return false;
    if(data[1] == '' || isNaN(data[1]) || parseInt(data[1]) < 1 || parseInt(data[1]) > 12) return false;
    if(data[2] == '' || isNaN(data[2]) || ((parseInt(data[2]) < 0 || parseInt(data[2]) > 99 ) && (parseInt(data[2]) < 1900 || parseInt(data[2]) > 9999))) return false;
    if(data[2] < 50) data[2] = parseInt(data[2]) + 2000;
    else if(data[2] < 100) data[2] = parseInt(data[2]) + 1900;
    switch(parseInt(data[1])){
     case 2: { if(((parseInt(data[2])%4!=0 || (parseInt(data[2])%100==0 && parseInt(data[2])%400!=0)) && parseInt(data[0]) > 28) || parseInt(data[0]) > 29 ) return false; break; }
     case 4: case 6: case 9: case 11: { if(parseInt(data[0]) > 30) return false; break;}
     default: { if(parseInt(data[0]) > 31) return false;}
    }
    return true;
    
  }

  //valida o e-mail
  function validaemail(src) {
    emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[a-zA-Z]$"
    var regex = new RegExp(emailReg);
    return regex.test(src);	
  }
  
  //somente números são desbloqueados
  function digitos(digit){
	digit.keyCode = ((digit.keyCode < 48) || (digit.keyCode > 57))?0:digit.keyCode;
  }

  //somente dígitos e vírgula são aceitos
  function valores(digit){
	digit.keyCode = (((digit.keyCode < 48) || (digit.keyCode > 57)) && (digit.keyCode != 44))?0:digit.keyCode;
  }
  
  //somente dígitos e barra são aceitos
  function datas(digit){
	digit.keyCode = ((digit.keyCode < 47) || (digit.keyCode > 57))?0:digit.keyCode;
  }
	
	function FormataReais(fld, milSep, decSep, e) {
		var sep = 0;
		var key = '';
		var i = j = 0;
		var len = len2 = 0;
		var strCheck = '0123456789';
		var aux = aux2 = '';
		var whichCode = (window.Event) ? e.which : e.keyCode;
	
		if (whichCode == 13) return true;
		key = String.fromCharCode(whichCode);// Valor para o código da Chave
	
		if (strCheck.indexOf(key) == -1) return false; // Chave inválida
	
		len = fld.value.length;
		
		for(i = 0; i < len; i++)
			if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
		aux = '';
		for(; i < len; i++)
			if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
		aux += key;
		len = aux.length;
		
		if (len == 0) fld.value = '';
		if (len == 1) fld.value = '0'+ decSep + '0' + aux;
		if (len == 2) fld.value = '0'+ decSep + aux;
		if (len > 2) {
			aux2 = '';
			for (j = 0, i = len - 3; i >= 0; i--) {
				if (j == 3) {
					aux2 += milSep;
					j = 0;
				}
			aux2 += aux.charAt(i);
			j++;
		}
		
		fld.value = '';
		
		len2 = aux2.length;
		
		for (i = len2 - 1; i >= 0; i--)
			fld.value += aux2.charAt(i);
			fld.value += decSep + aux.substr(len - 2, len);
		}
		
		return false;
		
	}
	//Fim da Função FormataReais -->

  
  
  //vê se tem algum checkbox marcado
  function selecionoucheck(checkitem){
    selecionou = false;
	if (isNaN(checkitem.length)){
	  selecionou = checkitem.checked;
	} else {
	  i = 0;
	  while ( (i <= (checkitem.length -1)) && (!selecionou) ){
/*
		if (checkitem[i].checked){
		  selecionou = true;
		}
*/
	selecionou = checkitem[i].checked;
    	i++;
	  }
	}
    return selecionou;
  }
  
  function getTimeNow(ano, mes, dia){
    var now = new Date();
    var data = new Date(ano, mes, dia, now.getHours(),now.getMinutes(), now.getSeconds());
	return data;
  }
  
  //cria um objeto do tipo date
  function createdate(dia, mesano){
	mes = mesano;
	ano = mesano;
	
	mes = mes.substring(0, 2) - 1;
	ano = ano.substring(3, ano.length);
	
    var data = getTimeNow(ano, mes, dia);//, now.getMilliseconds());
	return data;
  }
  
  //converte uma string de data no formato brasileiro em um objeto do tipo date;
  function cdate(strdata){
    strdata = strdata.split('/');
    datacv  = getTimeNow(strdata[2], strdata[1] - 1, strdata[0]);
    return datacv;
  }
  
  //verifica se é numérico
  function isNumeric (str){
    if (str.length == 0) {
	  return false;
	} else {
	  //return !isNaN(String(str.replace('.', '')).replace(',', '.'))
	  return !isNaN(str.replace(',', '.'))
	}
  }
  
  
  //tira os espaços em branco e retorna o tamanho da string
  function limpa(str){
	var x = String(str).trim();
	x = x.replace(/[^A-Za-z0-9_]*/, '');
	
	// cadeia inteira => @#$%¨&*()[]{}^~_-="'<>/\|;:`´,•+?!
	// cadeia que passa => _-="'<>/\|;:`´,•+?!
	
//	chars = '@#$%¨&*()[]{}^~_-="\'<>/\\|;:`´,•+\?\!';
//	alert(chars +'\n'+ str);
//	for (i=0; i < chars.length; i++){
//	  c = chars.charAt(i);
//	  x = x.replace(c, '');
//	  alert(x);
//	}
	return x.length;
  }
  
  //procura por caracteres inválidos na string
  function ehvalido(str){
	var aux = str.trim();
	if (aux.length == 0){
	  return false;
	} else {
	  chars = '@#$%¨&*()[]{}^~_-="\'<>/\\|;:`´,•+\?\!';
	  i = 0;
	  invalido = false;
	  while ((i < chars.length) && (!invalido)){
		c = chars.charAt(i);
		if (aux.indexOf(c) != -1) { invalido = true; }
		i++;
	  }
	  return !invalido;
	}
  }  
  
  //pôe o cursor no objeto e seleciona o conteúdo
  function setfocus(obj){
	obj.focus();
	obj.select();
  }
  /*

  //instancia o método trim
  String.prototype.trim = function(){
	var x=this;
	x=x.replace(/^\s*(.*)/, "$1");
	x=x.replace(/(.*?)\s*$/, "$1");
	return x;
  }
  
  //instancia o método strRev
  String.prototype.strRev = function(){
	var tmp = "";
	var str = this;
	for (i=str.length-1; i>=0; i--){
      tmp += str.charAt(i);
	}
	return tmp;
  }
  */
  function PopUp(I, W, H){
	lpos = (screen.availWidth/2) - (W/2);
	tpos = (screen.availHeight/2) - (H/2);
	window.open(I,'','scrollbars=0,left='+lpos+',top='+tpos+',width='+W+',height='+H).focus();
  }

  function PopUp2(I, W, H){
		lpos = (screen.availWidth/2) - (W/2);
		tpos = (screen.availHeight/2) - (H/2);
		window.open(I,'teste','scrollbars=0,left='+lpos+',top='+tpos+',width='+W+',height='+H).focus();
  }
	
  function PopUpRolagem(I, W, H){
	lpos = (screen.availWidth/2) - (W/2);
	tpos = (screen.availHeight/2) - (H/2);
	window.open(I,'','scrollbars=yes,left='+lpos+',top='+tpos+',width='+W+',height='+H).focus();
  }

  function PopUpScroll(I, W, H){
	lpos = (screen.availWidth/2) - (W/2);
	tpos = (screen.availHeight/2) - (H/2);
	window.open(I,'janela','scrollbars=yes,left='+lpos+',top='+tpos+',width='+W+',height='+H).focus();
  }
  
  // xinelage pra mandar além do ID informações adicionais com checkbox escondido
  function setacheckhidden(chkvisible, chkhidden){
	for (i=0; i < chkvisible.length; i++){
	  chkhidden[i].checked = (chkvisible[i].checked)?true:false;
	}
  }