function EscondeDiv(objeto){
		
	if (document.getElementById(objeto).style.display=="none"){
		document.getElementById(objeto).style.display = "block";		
	}
	else{
		document.getElementById(objeto).style.display = "none";					
	}

}

function abrirpopup(pagina,alvo,largura,altura){
	config="toolbar=no,location=no,width="+largura+",height="+altura+",status=no,menubar=no,scrollbars=no,resible=no,top=30,left=30";
pop=window.open(pagina,alvo,config);

}

function criaMascara(_RefObjeto, _Modelo){

    var valorAtual = _RefObjeto.value;
    var valorNumerico = '';
    var nIndexModelo = 0;
    var nIndexString = 0;
    var valorFinal = '';
    var adicionarValor = true;


      // limpa a string valor atual para verificar
      // se todos os caracteres são números
      for (i=0;i<_Modelo.length;i++){
        if (_Modelo.substr(i,1) != '#'){
          valorAtual = valorAtual.replace(_Modelo.substr(i,1),'');
      }}

      // verifica se todos os caracteres são números
      for (i=0;i<valorAtual.length;i++){
        if (!isNaN(parseFloat(valorAtual.substr(i,1)))){
          valorNumerico = valorNumerico + valorAtual.substr(i,1);
      }}
      
      // aplica a máscara ao campo informado usando
      // o modelo de máscara informado no script
      for (i=0;i<_Modelo.length;i++){

        if (_Modelo.substr(i,1) == '#'){
          if (valorNumerico.substr(nIndexModelo,1) != ''){
            valorFinal = valorFinal + valorNumerico.substr(nIndexModelo,1);
            nIndexModelo++;nIndexString++;
          }
            else {
              adicionarValor = false;
        }}

          else {
            if (adicionarValor && valorNumerico.substr(nIndexModelo,1) != ''){
            valorFinal = valorFinal + _Modelo.substr(nIndexString,1)
            nIndexString++;
          }}
      }

      //alert(valorFinal)
      _RefObjeto.value = valorFinal
}

function limpaString(S)
{
	// Deixa so' os digitos no numero
	var Digitos = "0123456789";
	var temp = "";
	var digito = "";

	for (var i=0; i<S.length; i++)
	{
		digito = S.charAt(i);
		if (Digitos.indexOf(digito)>=0)
		{
			temp=temp+digito;
		}
	} //for

	return temp;
}

function isCnpj(s)
{
	s = limpaString(s);
	
	if (s == "11111111111111")
	{
		return false;
	}

	if (s == "22222222222222")
	{
		return false;
	}

	if (s == "33333333333333")
	{
		return false;
	}

	if (s == "44444444444444")
	{
		return false;
	}

	if (s == "55555555555555")
	{
		return false;
	}

	if (s == "66666666666666")
	{
		return false;
	}

	if (s == "77777777777777")
	{
		return false;
	}

	if (s == "88888888888888")
	{
		return false;
	}

	if (s == "99999999999999")
	{
		return false;
	}

	var a = new Array();
	var b = new Number;

	var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
	
	for (i=0; i<12; i++)
	{
		a[i] = s.charAt(i);
		b += a[i] * c[i+1];
	}
	
	if ((x = b % 11) < 2)
	{
		a[12] = 0;
	} else {
		a[12] = 11-x;
	}
	
	b = 0;
	for (y=0; y<13; y++)
	{
		b += (a[y] * c[y]);
	}
	
	if ((x = b % 11) < 2)
	{
		a[13] = 0;
	} else {
		a[13] = 11-x;
	}
	
	if ((s.charAt(12) != a[12]) || (s.charAt(13) != a[13]))
	{
		return false;
	}
	
	return true;
}