// JavaScript Document
function IsNumeric_OLD(sText) {
	var ValidChars = "-0123456789.";
	var IsNumber=true;
	var Char;

	for (i=0; i<sText.length && IsNumber == true; i++) { 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}

	return IsNumber;
}

function IsNumeric(strString) {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i=0; i<strString.length && blnResult == true; i++) {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1) {
         blnResult = false;
       }
    }
   return blnResult;
}

function SNIRH_AnohYYYY_YY(mes,ano)  {
	// Devolve o ano hidrológico no formato YYYY/YY
	var saida = new String();

	if(mes >= 10) {
		saida = ano + "/" + new String(ano).substr(2,2);
	} else {
		saida = (ano-1) + "/" + new String(ano).substr(2,2);
	}

	return saida;
}

function ShowHideLayer(obj,accao) {
	if(accao == 1) {
		if (navigator.appName == "Microsoft Internet Explorer") {
			document.all[obj].style.visibility = "visible";
			document.all[obj].style.display = "block";
		} else {
			document.getElementById(obj).style.visibility = "visible";
			document.getElementById(obj).style.display = "block";
		}
	} else {
		if (navigator.appName == "Microsoft Internet Explorer") {
			document.all[obj].style.visibility = "hidden";
			document.getElementById(obj).style.display = "none";
		} else {
			document.getElementById(obj).style.visibility = "hidden";
			document.getElementById(obj).style.display = "none";
		}
	}
}

function SNIRH_RemoveAcentosVogais(str) {
var s=str;

var rExps=[ /[\xC0-\xC2]/g, /[\xE0-\xE2]/g,
/[\xC8-\xCA]/g, /[\xE8-\xEB]/g,
/[\xCC-\xCE]/g, /[\xEC-\xEE]/g,
/[\xD2-\xD4]/g, /[\xF2-\xF4]/g,
/[\xD9-\xDB]/g, /[\xF9-\xFB]/g ];

var repChar=['A','a','E','e','I','i','O','o','U','u'];

for(var i=0; i<rExps.length; i++)
s=s.replace(rExps[i],repChar[i]);

return s;
}

function SNIRH_ValidarEnderecoEmail(str) {
	// Remover de funcoes.js ValidarEnderecoEmail
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(str);
}

function SNIRH_InnerWidthHeight() {
	
	var myWidth = 0, myHeight = 0;
	
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	
	return new Array(myWidth,myHeight);
}

function SNIRH_PageWidthHeight() {
	
 var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return new Array(scrOfX, scrOfY);
}

Array.prototype.avg = function() {
	var av = 0;
	var cnt = 0;
	var len = this.length;
	for (var i = 0; i < len; i++) {
	var e = +this[i];
	if(!e && this[i] !== 0 && this[i] !== '0') e--;
	if (this[i] == e) {av += e; cnt++;}
	}
	return av/cnt;
}

function SNIRH_RadioGroupValue(form,groupname) {
	// Get select value from a radio group
	// v1.0 MiguelNA - 15MAY2009

	var val;
	for(i=0; i<form[groupname].length; i++) {
		if(form[groupname][i].checked == true ) {
			val = form[groupname][i].value;
		}
	}
	
	return val;
}

if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}