﻿var HeaderTabelaDadosIds='';

function TrocaBarra(showHideId, imageId, title, stateId) {
	var objShowHide = document.getElementById(showHideId);
	var objImage = document.getElementById(imageId);
	var objState = document.getElementById(stateId);
	if (objShowHide) {
		if (objShowHide.style.display == "none") {
			objImage.src = "img/tridown.gif";
			objImage.alt = "Mostrar Detalhes "+title;
			objShowHide.style.display = "";
		} else {
			objImage.src = "img/tri.gif";
			objImage.alt = "Esconder Detalhes "+title;
			objShowHide.style.display = "none";
		}
		if (objState) {
			objState.value = (objShowHide.style.display == "none") ? "1": "0";
		}
	}
}
function EscondeObjecto(ids) {
	var arr = ids.split(",");
	for (var index in arr) {
		if (arr[index] != "") {
			var obj = document.getElementById(arr[index]);
			if (obj) {
				obj.style.display='none';
			}
		}
	}
}
function EscondeLinhas(ids) {
	var arr = ids.split(",");
	for (var index in arr) {
		if (arr[index] != "") {
			EscondeLinhaPai(arr[index]);
		}
	}
}
function EscondeLinhaPai(objectId) {
	var obj = document.getElementById(objectId);
	if (obj) {
		var objPai = obj.parentNode;
		while (objPai) {
			if (objPai.tagName == "TR") {
				objPai.style.display='none';
				break;
			}
			objPai = objPai.parentNode;
		} 
	}
}
function EscondeCoberturasAdicionais(objectId, arrayCob) {
  var obj = document.getElementById(objectId);
  if (obj && obj.childNodes && obj.childNodes[0]) {
    var arr = arrayCob.split(",");
    var arrLength = obj.childNodes[0].childNodes;
    for (var i=0; i < arrLength.length; i++) {
      if (arrLength[i] && arrLength[i].childNodes && arrLength[i].childNodes[0] && arrLength[i].childNodes[0].coverageElement) {
        var objTR = arrLength[i];
        var bFound = false;
        for (var index in arr) {
          if (arr[index] == objTR.childNodes[0].coverageElement) {
            bFound = true;
            break;
          }
        }
        if (!bFound) {
          objTR.style.display = "none";
          osjs("td[coverageElement='"+objTR.childNodes[0].coverageElement+"'] ~ td").find("input").val("");
	 }
      }
    }
  }
}

function DesactivaCheckBox(objectId) {
  var obj = document.getElementById(objectId);
  if (obj) {
	obj.checked = false;
  }
}
function exitWebSite(urlHome){
	if (window.opener != null)
		window.close();
	else
		window.location = urlHome;
}
//Scroll da pagina para o seu topo
function ScrollPaginaTopo(){JumpToPageTop();}
var bAgent = navigator.userAgent;
var d = document;
function Sniffer(){this.Win = bAgent.indexOf("Win",0) != -1 ? 1 :0;this.Mac = bAgent.indexOf("Mac",0) != -1 ? 1 :0;this.Moz = ((bAgent.indexOf("Gecko") != -1) && (bAgent.indexOf("Safari",0) == -1)) ? 1 :0;this.OPERA = bAgent.indexOf("Opera",0) != -1 ? 1 :0;this.SAFARI = bAgent.indexOf("Safari",0) != -1 ? 1 :0;	this.checkObj = d.all?(d.getElementById?3:2):(d.getElementById?4:(d.layers?1:0));this.allObj = ((this.checkObj == 1) || (this.checkObj == 2) || (this.checkObj == 3) || (this.checkObj == 4));return this;}
var usr = new Sniffer;
function GetWindowHeight(){if(usr.Mac && usr.checkObj == 1){return window.innerHeight;}else if(usr.Win && usr.checkObj == 1){return window.innerHeight - 16;}else if(usr.checkObj == 4){return window.innerHeight - 15;}else if(usr.OPERA || usr.checkObj == 2 || usr.checkObj == 3){return d.body.clientHeight;}}
function GetWindowXOffset(){if(usr.checkObj == 2 || usr.checkObj == 3){return d.body.scrollLeft;}else if(usr.checkObj == 1 || usr.checkObj == 4){return window.pageXOffset;}}
function GetWindowYOffset(){if(usr.checkObj == 2 || usr.checkObj == 3){return d.body.scrollTop;}else if(usr.checkObj == 1 || usr.checkObj == 4){return window.pageYOffset;}}
function GetDocHeight(){if(usr.checkObj == 1){return GetTagTop('end') + 1;}else if(usr.checkObj == 2 || usr.checkObj == 3 || usr.checkObj == 4){return GetTagTop('end');}}
function GetDistanceMaxY(){if(usr.allObj){return (GetDocHeight() - GetWindowHeight());}}
function SetObj(idName){return d.all ? d.all(idName) : d.getElementById ? d.getElementById(idName) : d.layers[idName];}
function GetTagTop(idName){var obj = SetObj(idName);var tagCoords = new Object();if(usr.OPERA && usr.Mac){return idName;} else if((usr.checkObj == 2) || (usr.checkObj == 3) || (usr.checkObj == 4)) {tagCoords.y = obj.offsetTop;while ((obj = obj.offsetParent) != null){tagCoords.y += obj.offsetTop;}if(usr.Mac && usr.Moz){return tagCoords.y - 12;}else if((usr.Win && usr.Moz) || (usr.Mac && usr.SAFARI)){return tagCoords.y - 9;}else{return tagCoords.y;}} else if(usr.checkObj == 1) {tagCoords.y = d.anchors[idName].y;return tagCoords.y;}return idName;}
/*PageScroller*/
var PageScrollTimer;
function pageScroll(toX,toY,frms,frX,frY){if(PageScrollTimer) clearTimeout(PageScrollTimer);var spd = usr.Mac ? 14 :16;	var actX = GetWindowXOffset();var actY = GetWindowYOffset();if(!toX || toX < 0) toX = 0;if(!toY || toY < 0) toY = 0;if(!frms) frms = usr.NN ? 10 :usr.Mac ? 4 :5;if(!frX) frX = 0 + actX;if(!frY) frY = 0 + actY;frX += (toX - actX) / frms;if (frX < 0) frX = 0;frY += (toY - actY) / frms;if (frY < 0) frY = 0;var posX = Math.ceil(frX);	var posY = Math.ceil(frY);	window.scrollTo(posX, posY);if((Math.floor(Math.abs(actX - toX)) < 1) && (Math.floor(Math.abs(actY - toY)) < 1)){clearTimeout(PageScrollTimer);	window.scroll(toX,toY);	}else if(posX != toX || posY != toY){PageScrollTimer = setTimeout("pageScroll("+toX+","+toY+","+frms+","+frX+","+frY+")",spd);}else{clearTimeout(PageScrollTimer);}}
function JumpToAnchor(idName){if(usr.allObj){if(!!idName){var anchorY = GetTagTop(idName);var dMaxY = GetDistanceMaxY();var setY = (anchorY<1)?0:(anchorY>dMaxY)?dMaxY:anchorY;if(anchorY>1){pageScroll(0,setY);}else if(anchorY<=1){pageScroll(0,0);}else{location.hash = idName;}}else{pageScroll(0,0);}}else{!!idName ? location.hash = idName : location.hash = "top";}}
function JumpToPageTop(){if(usr.allObj){pageScroll(0,0);}else{!!idName ? location.hash = idName : location.hash = "top";}}
// Detectar tecla
function getKey(e) {
	if (e.keyCode) return String.fromCharCode(e.keyCode);
	if (e.which) return String.fromCharCode(e.which);
}

function limitEntryDigits(e) {
	var keyChar = getKey(e);

	if (/\D/.test(keyChar)) return false; //digits only	
		return true;
}
