<!--

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 FindObject(n, d) {
  var p, i, x; if ( !d ) d = document;
  if ( ( p = n.indexOf("?") ) > 0 && d.forms.length ) {
    d = d.forms[n.substring(p+1)]; 
    n = n.substring(0, p);
  } else 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, num, vmin, vmax, errs = "", 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.options && val.selectedIndex <= 0 ) errs += "" + nm + " deve ser selecionado\n";
      else if ( (val=val.value) != "" ) {
        if ( test.indexOf("isEmail") != -1 ) {
          p = val.indexOf("@"); if ( p < 1 || p == ( val.length - 1 ) ) errs += "" + nm + " deve conter 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 ) errs += "" + 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 ) errs += "" + nm + " deve conter um número entre " + vmin + " e " + vmax + "\n";
          }
        }
      } else if ( test.charAt(0) == "R" ) errs += "" + nm + " é requerido\n";
    }
  }
  return errs;
}

function CharsLeft(f, h, m) {
  val = FindObject(f);
  hlp = FindObject(h);
  if ( val && hlp ) {
    l = m - val.value.length;
    if ( l > 0 ) hlp.innerHTML = "Restam " + l + " caracteres até o limite!";
    else if ( l == 0 ) hlp.innerHTML = "Limite de caracteres esgotado!";
    else val.value = val.value.substring(0, m);
  }
}

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 AddLoadEvent(func) {
  var oldonload = window.onload;
  if ( typeof window.onload != "function" ) window.onload = func;
  else {
    window.onload = function() {
      if ( oldonload ) oldonload();
      func();
    }
  }
}

function Redimension() {
  var args = Redimension.arguments;
  
  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 ) { x = args[0]; y = args[1]; }
  
  self.resizeTo(x, y);
  
  x = ( screen.availWidth - x ) / 2;
  y = ( screen.availHeight - y ) / 2;
  if ( x > 0 && y > 0 ) window.moveTo(x, y);
  
  self.focus();
}

function OpenWindow(theURL, winName, features) {
  window.open(theURL, winName, features);
}

function CloseWindow() {
  window.opener.focus();
  window.close();
}

function CNumber(num) {
  num = num.toString().replace(/\$/g,'');
  num = num.toString().replace(/\,/g,'.');
  if ( isNaN(num) ) num = "0";
  return num;
}

function FormatNumber(num) {
  num = num.toString().replace(/\$|\,/g,'');
  if ( isNaN(num) ) num = "0";
  sign = ( num == ( num = Math.abs(num) ) );
  num = Math.floor(num*100+0.50000000001);
  cents = num%100;
  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)?'':'-') + num + ',' + cents );
}

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 getPositionTop(element) {
  var offset = 0; 
  while ( element ) { 
    offset += element["offsetTop"]; 
    element = element.offsetParent; 
  } 
  return offset; 
} 
 
function isElementVisible(eltId) {
  var elt = document.getElementById(eltId); 
  if ( !elt ) return false; 
  var posTop = getPositionTop(elt); 
  var posBottom = posTop + elt.offsetHeight; 
  var visibleTop = document.body.scrollTop; 
  var visibleBottom = visibleTop + document.documentElement.offsetHeight; 
  return ( ( posBottom >= visibleTop ) && ( posTop <= visibleBottom ) ); 
}

//-->
