<!-- 

var Language = "PT";
var Rounding = true;

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "navegador desconhecido";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "versão desconhecida";
		this.OS = this.searchString(this.dataOS) || "sistema desconhecido";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function Dimension(element) {
  this.x = -1;
  this.y = -1;
  this.w = 0;
  this.h = 0;
  if ( element == document ) {
    this.x = element.body.scrollLeft;
    this.y = element.body.scrollTop;
    this.w = element.body.clientWidth;
    this.h = element.body.clientHeight;
  } else if ( element != null ) {
    var e = element;
    var l = e.offsetLeft;
    while ( ( e = e.offsetParent ) != null ) { 
      l += e.offsetLeft; 
    }
    var e = element;
    var t = e.offsetTop;
    while( ( e = e.offsetParent ) != null ) { 
      t += e.offsetTop; 
    }
    this.x = l;
    this.y = t;
    this.w = element.offsetWidth;
    this.h = element.offsetHeight;
  }
}

function FindObject(n, d) {
  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 = FindObject(n, d.layers[i].document);
  if ( !x && d.getElementById ) x = d.getElementById(n);
  return x;
}

function ValidateForm() {
  var k = 0, i, p, q, nm, test, val, num, vmin, vmax, errors = "", args = ValidateForm.arguments;
  for ( i = 0; i < ( args.length - 2 ); i += 3 ) {
    test = args[i+2]; val = FindObject(args[i]);
    if ( val ) {
      nm = ( args[i+1] != "" )?args[i+1]:val.name; nm = "Campo " + nm;
      if ( val.type == "select-one" || val.type == "select-multiple" ) {
        if ( val.options && val.selectedIndex <= 0 ) errors += "- " + nm + " deve ser selecionado.\n";
      } else {
        //if ( trim(( val = val.value ), " ") != "" ) {
        val = val.value;
        if ( trim(val, " ") != "" ) {
          if ( test.indexOf("isEmail") != -1 ) {
            p = val.indexOf("@"); if ( p < 1 || p == ( val.length - 1 ) ) errors += "- " + nm + " deve ser um endereço de e-mail válido.\n";
          } else if ( test != "R" ) {
            p = val.indexOf(","); if ( p != -1 ) val = val.substring(0, p) + "." + val.substring(p + 1);
            num = parseFloat(val); if ( val != "" + num && val.indexOf(".") == -1 ) errors += "- " + nm + " deve conter um número.\n";
            if ( test.indexOf("inRange") != -1 ) {
              p = test.indexOf(":"); vmin = parseFloat(test.substring(8,p)); vmax=parseFloat(test.substring(p+1));
              if ( num < vmin || vmax < num ) errors += "- " + nm + " deve conter um número entre " + vmin + " e " + vmax + ".\n";
            }
          }
        } else if ( test.charAt(0) == "R" ) errors += "- " + nm + " é requerido.\n";
      }
    }
  }
  return errors;
}

function CheckAll(f) {
  var df;
  if ( !f ) df = document.forms[0];
  else if ( typeof(f) == "object" ) df = f;
  else if ( isNaN(f) ) df = document.forms(f);
  else df = document.forms[f];
  new_value = ( !df.elements[0].checked );
  for ( var i = 0; i < df.elements.length; i++ ) {
    df.elements[i].checked = new_value;
  }
}

function CheckCount(f) {
  var df;
  if ( !f ) df = document.forms[0];
  else if ( typeof(f) == "object" ) df = f;
  else if ( isNaN(f) ) df = document.forms(f);
  else df = document.forms[f];
  counter = 0;
  for ( var i = 0; i < df.elements.length; i++ ) {
    if ( df.elements[i].type == "checkbox") {
      if ( df.elements[i].checked ) counter++;
    }
  }
  return counter;
}

function DisableAll(f) {
  var df;
  if ( !f ) df = document.forms[0];
  else if ( typeof(f) == "object" ) df = f;
  else if ( isNaN(f) ) df = document.forms(f);
  else df = document.forms[f];
  for ( var i = 0; i < df.elements.length; i++ ) {
    if ( df.elements[i].type == "text" ) df.elements[i].disabled = false;
    if ( df.elements[i].type == "button" ) df.elements[i].disabled = ( BrowserDetect.browser.toUpperCase() != "FIREFOX" );
  }
}

function EnableAll(f) {
  var df;
  if ( !f ) df = document.forms[0];
  else if ( typeof(f) == "object" ) df = f;
  else if ( isNaN(f) ) df = document.forms(f);
  else df = document.forms[f];
  for ( var i = 0; i < df.elements.length; i++ ) {
    if ( df.elements[i].type == "button" ) df.elements[i].disabled = false;
  }
}

function CloseDisplay() {
  var i, val, args = CloseDisplay.arguments;
  for ( i = 0; i < args.length; i++ ) {
    val = FindObject(args[i]);
	if ( val && val.tagName != "DIV" && typeof(val.style.display) != "undefined" ) val.style.display = "none";
    else if ( val && typeof(val.style.visibility) != "undefined" ) val.style.visibility = "hidden";
    else if ( val && typeof(val.style.display) != "undefined" ) val.style.display = "none";
  }
}

function Redimension() {
  var args = Redimension.arguments, x = 0, y = 0;
  
  if ( args.length == 0 ) {
    x = self.document.body.scrollWidth + self.document.body.offsetWidth - self.document.body.clientWidth + 7;
    y = self.document.body.scrollHeight + self.document.body.offsetHeight - self.document.body.clientHeight + 15 + 58;
  } else if ( args.length >= 2 ) {
    if ( args.length >= 1 ) x = args[0];
    if ( args.length >= 2 ) y = args[1];
  }
  
  if ( x > 0 && y > 0 ) self.resizeTo(x, y);
  
  //if ( args.length >= 3 ) Reposition();
}

function CharsLeft() {
  var args = CharsLeft.arguments;
  if ( args.length > 1 ) {
    var val = args[0].value, hlp = FindObject("LIM_" + args[0].name);
    len = parseInt(args[1]) - val.length;
    if ( len == parseInt(args[1]) ) hlp.innerHTML = "";
    else if ( len > 0 ) hlp.innerHTML = "Restam " + len + " caracteres!";
    else if ( len <= 0 ) {
      hlp.innerHTML = "Espaço esgotado!";
      args[0].value = val.substring(0, parseInt(args[1]));
    }
  }
}

function IntegerOnly(myfield, e) {
  if ( myfield.length == 0 ) myfield.value = 0;
  var key;
  var keychar;
  if ( window.event ) key = window.event.keyCode;
  else if ( e ) key = e.which;
  else return true;
  keychar = String.fromCharCode(key);
  if ( (key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27) ) return true;
  else if ( (("0123456789").indexOf(keychar) > -1) ) return true;
  else return false;
}

function NumberOnly(myfield, e) {
  if ( myfield.length == 0 ) myfield.value = 0;
  var key;
  var keychar;
  if ( window.event ) key = window.event.keyCode;
  else if ( e ) key = e.which;
  else return true;
  keychar = String.fromCharCode(key);
  if ( (key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27) ) return true;
  else if ( (("0123456789,").indexOf(keychar) > -1) ) return true;
  else return false;
}

function TRhover(obj, odd, evt) {
  if ( evt == "over" ) {
    obj.style.background = "LightSteelBlue";
    obj.style.cursor = "pointer";
  } else {
    if ( odd == 1 ) obj.style.background = "WhiteSmoke";
    else obj.style.background = "Gainsboro";
    obj.style.cursor = "default";
  }
}

function OnlySpecified(string, possible) {
  string = String(string);
  possible = String(possible);
  for ( var i = 0; i < string.length; i++ ) {
    if ( possible.indexOf(string.charAt(i)) == -1 ) string = string.replace(string.charAt(i), "");
  }
  return string;
}

function OnlyNumbers(string) {
  return OnlySpecified(string, "0123456789");
}

function OnlyValidIdChars(string) {
  return OnlySpecified(string, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!$()*+-./:<=>@[\]_{|}");
}

function trim(str, chars) {
  return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
  chars = chars || "\\s";
  return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
  chars = chars || "\\s";
  return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function cnum(str) {
  p = str.indexOf(","); if ( p != -1 ) str = str.substring(0, p) + "." + str.substring(p + 1);
  return str;
}

function ShowNumber(num, dig) {
  num = num.toString().replace(/\$|\,/g,'');
  if ( isNaN(num) ) num = "0";
  sign = ( num == ( num = Math.abs(num) ) );
  if ( Rounding ) num = Math.floor(num*Math.pow(10,dig)+0.50000000001);
  else num = Math.floor(num*Math.pow(10,dig)+0.00000000001);
  frac = num%Math.pow(10,dig); frac = frac.toString();
  if ( Rounding ) num = Math.floor(num/Math.pow(10,dig)).toString();
  else num = Math.floor(num/Math.pow(10,dig)).toString();
  while ( frac.length < dig ) frac = "0" + frac;
  return ( ((sign)?"":"-") + num + ((dig>0)?("," + frac):"") );
}

function ShowCurrency(num) {
  num = num.toString().replace(/\$|\,/g,'');
  if ( isNaN(num) ) num = "0";
  sign = ( num == ( num = Math.abs(num) ) );
  if ( Rounding ) num = Math.floor(num*100+0.50000000001);
  else num = Math.floor(num*100+0.00000000001);
  cents = num%100;
  if ( Rounding ) num = Math.floor(num/100).toString();
  else num = Math.floor(num/100).toString();
  if ( cents < 10 ) cents = "0" + cents;
  for ( var i = 0; i < Math.floor((num.length-(1+i))/3); i++ ) {
    num = num.substring(0,num.length-(4*i+3)) + "." + num.substring(num.length-(4*i+3));
  }
  return ( ((sign)?"":"-") + "R$" + num + "," + cents );
}

function VerCPF(cpf) {
  cpf = OnlyNumbers(cpf);
  //--- CPF (Cadastro de Pessoa Física)
  //--- O CPF é composto por 9 dígitos, mais 2 DVs, resultando em um número com 11 casas decimais.
  //--- Os 8 primeiros são chamados de número-base, o 9º define a Região Fiscal, o 10º é o DV módulo 11 dos 9 anteriores, e o último é o DV módulo 11 dos 10 anteriores.
  var OK = false;
  if ( cpf.length == 11 && cpf.substring(0, 9) != "000000000" ) {
    var RegiaoFiscal = "";
    switch ( cpf.substring(8, 9) ) {
      case "1": RegiaoFiscal = "DF, GO, MS, MT, TO"; break;
      case "2": RegiaoFiscal = "AC, AM, AP, PA, RO, RR"; break;
      case "3": RegiaoFiscal = "CE, MA, PI"; break;
      case "4": RegiaoFiscal = "AL, PB, PE, RN"; break;
      case "5": RegiaoFiscal = "BA, SE"; break;
      case "6": RegiaoFiscal = "MG"; break;
      case "7": RegiaoFiscal = "ES, RJ"; break;
      case "8": RegiaoFiscal = "SP"; break;
      case "9": RegiaoFiscal = "PR, SC"; break;
      case "0": RegiaoFiscal = "RS"; break;
    }
    var NumBase = cpf.substring(0, 9), Peso, Soma;
    Peso = 9; Soma = 0;
    for ( d = NumBase.length; d > 0; d-- ) {
      Soma += eval(NumBase.charAt(d - 1)) * Peso;
	  Peso--; if ( Peso < 0 ) Peso = 9;
    }
	var DV1 = Soma % 11; if ( DV1 == 10 ) DV1 = 0;
	NumBase += DV1;
    Peso = 9; Soma = 0;
    for ( d = NumBase.length; d > 0; d-- ) {
      Soma += eval(NumBase.charAt(d - 1)) * Peso;
	  Peso--; if ( Peso < 0 ) Peso = 9;
    }
	var DV2 = Soma % 11; if ( DV2 == 10 ) DV2 = 0;
	NumBase += DV2;
    OK = ( cpf == NumBase );
  }
  return OK;
}

function VerCNPJ(cnpj) {
  cnpj = OnlyNumbers(cnpj);
  //--- CNPJ (Cadastro Nacional de Pessoa Jurídica)
  //--- O CNPJ é composto por 8 dígitos de número base, seguidos de 4 dígitos de ordem das filiais da empresa, e 2 DVs - totalizando 14 casas decimais.
  //--- A base para sequência de somatória e multiplicação inicia em 9, e termina em 2.
  //--- Também deve-se validar o 8º dígito pela somatória da múltiplicação dos 7 primeiros dígitos, usando como base a sequência 2 1 2 1 2 1 2 somando resultados noves fora e módulo 10.
  var OK = false;
  if ( cnpj.length == 14 && cnpj.substring(0, 8) != "00000000" && cnpj.substring(8, 12) != "0000" ) {
    var NumBase = cnpj.substring(0, 12), Peso, Soma;
    Peso = 9; Soma = 0;
    for ( d = NumBase.length; d > 0; d-- ) {
      Soma += eval(NumBase.charAt(d - 1)) * Peso;
      Peso--; if ( Peso < 2 ) Peso = 9;
    }
	var DV1 = Soma % 11; if ( DV1 == 10 ) DV1 = 0;
	NumBase += DV1;
    Peso = 9; Soma = 0;
    for ( d = NumBase.length; d > 0; d-- ) {
      Soma += eval(NumBase.charAt(d - 1)) * Peso;
      Peso--; if ( Peso < 2 ) Peso = 9;
    }
	var DV2 = Soma % 11; if ( DV2 == 10 ) DV2 = 0;
	NumBase += DV2;
    OK = ( cnpj == NumBase );
    if ( OK && cnpj.charAt(0) > "0" ) {
      var Resultado, NovesFora;
      NumBase = cnpj.substring(0, 7);
      Peso = 2; Soma = 0;
      for ( d = 1; d <= NumBase.length; d++ ) {
        Resultado = eval(NumBase.charAt(d - 1)) * Peso;
        while ( Resultado > 9 ) {
          NovesFora = String(Resultado);
          Resultado = eval(NovesFora.charAt(0)) + eval(NovesFora.charAt(1));
        }
        Soma += Resultado;
        Peso--; if ( Peso < 1 ) Peso = 2;
      }
	  var D8 = ( ( 10 - ( Soma % 10 ) ) % 10 );
      //OK = ( cnpj.substring(7, 8) == D8 );
    }
  }
  return OK;
}

function VerCPFCNPJ(nrf) {
  return ( VerCPF(nrf) || VerCNPJ(nrf) );
}

//-->
