function gE(ID) {
    return document.getElementById(ID);
}

function gEN(Name) {
    return document.getElementsByName(Name);
}

function gETN(Tag) {
    return document.getElementsByTagName(Tag)
}

String.prototype.replaceAll = function(pattern, replacement) {
  return this.split(pattern).join(replacement);
}

function add_Event_Elm(el, event, funct, params){
	if (document.addEventListener) {
		el.addEventListener (event, function() {funct.apply(el, params);}, false);
	} else if (document.attachEvent) {
		el.attachEvent ("on"+event, function() {funct.apply(el, params);});
	}
}

function add_Event(el, event, funct, params){
	for (i=0; i<el.length; i++){
		add_Event_Elm(el[i], event, funct, params)
	}
}

/*Object.prototype.add_Event = function(event, funct){
	if (document.addEventListener) {
		//alert(this.value)
		this.addEventListener (event, funct, false);
	} else if (document.attachEvent) {
		this.attachEvent ("on"+event, funct);
	}
}*/

function NovaJanela(url, nome, params, Wwidth, Wheight) {
	Swidth = screen.width;
	Sheight = screen.height;
	
	Wleft = (Swidth / 2) - (Wwidth / 2) - 8;
	Wtop = (Sheight / 2) - (Wheight / 2) - 20;

	params = params+",left="+Wleft+",top="+Wtop+",width="+Wwidth+",height="+Wheight;

	Janela = window.open(url, nome, params);
	Janela.focus
}

function Cria_Box(ElemPai, Id_Box){
    var box = document.createElement('div');
    //var textNode = document.createTextNode("iaaaaaaaaaaaaaaaaaa")
    //box.appendChild(textNode)
    box.setAttribute('id', Id_Box);
    
    //box.style.backgroundColor = "#009999";
    box.style.position = "absolute"
    box.style.top = "0px"
    box.style.left = "0px"
    box.style.width = "100%"
    box.style.height = "100%"
    box.style.zIndex = 1000
    //alert(document)
    ElemPai.insertBefore(box, ElemPai.firstChild);
}

// Utilizado para criar o efeito de loading
function loading(opt) {
   //-----------pega resolucao do computador-----------------------------------
   //alert(screen.height) //pega resolucao heigth do computador
   //alert(screen.width) //pega resolucao width do computador
   //-----------tamanho real da pagina, com scroll e tudo----------------------
   //alert(document.body.scrollHeight) funfa no FF e no IE
   //-----------tamanho do conteudo exibido na tela cliente--------------------
   //alert(document.body.offsetHeight) funfa no FF e no IE
   //-----------tamnho apenas da tela que esta sendo mostrada------------------
   //alert(self.innerHeight) //funfa só FF (tamanho da tela do cliente contando a barra de rolagem)
   //alert(document.body.clientHeight) //funfa no FF e no IE (tamanho da tela do cliente sem contar a barra de rolagem)
   //alert(document.body.clientWidth)
   
   if (opt) {
      var refer = gE('box_loading');
      refer.style.textAlign = 'center';
      
      var img = document.createElement('img');
      img.setAttribute('src', 'loading.gif');
      img.setAttribute('id', 'loading');

      img.style.marginTop = ((refer.offsetHeight / 2) + document.body.scrollTop) - (img.height/2) + 'px';
      
      if ( ! document.getElementById('loading')) {
         refer.insertBefore(img, refer.firstChild);
      }
   }else{
      var imgLoading = gE('loading');
      if (imgLoading) {
         setTimeout(function (){imgLoading.parentNode.parentNode.removeChild(imgLoading.parentNode);}, 500)             
      }
   }
}

// Esta função elimina da página o fundo criado sobre o body e o boxCad;
function removerDivs() {
   var bgBody = gE('bgBody');
   var boxCad = gE('boxCad');
   bgBody.parentNode.removeChild(bgBody);
   if (boxCad) {
      // Por que ao clicar X (para deletar um registro) cria - se somente o encobridor e não o boxCad
      boxCad.parentNode.removeChild(boxCad);
   }
}

/* Funções de terceiros */
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){

   var xScroll, yScroll;

   if (window.innerHeight && window.scrollMaxY) {
      xScroll = document.body.scrollWidth;
      yScroll = window.innerHeight + window.scrollMaxY;
   }else if (document.body.scrollHeight > document.body.offsetHeight){
      // all but Explorer Mac
      xScroll = document.body.scrollWidth;
      yScroll = document.body.scrollHeight;
   }else {
      // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
      xScroll = document.body.offsetWidth;
      yScroll = document.body.offsetHeight;
   }
    
   var windowWidth, windowHeight;
   if (self.innerHeight) {
      // all except Explorer
      windowWidth = self.innerWidth;
      windowHeight = self.innerHeight;
   }else if (document.documentElement && document.documentElement.clientHeight) {
      // Explorer 6 Strict Mode
      windowWidth = document.documentElement.clientWidth;
      windowHeight = document.documentElement.clientHeight;
   }else if (document.body) {
      // other Explorers
      windowWidth = document.body.clientWidth;
      windowHeight = document.body.clientHeight;
   }
    
   // for small pages with total height less then height of the viewport
   if(yScroll < windowHeight){
      pageHeight = windowHeight;
   }else {
      pageHeight = yScroll;
   }

   // for small pages with total width less then width of the viewport
   if(xScroll < windowWidth){
      pageWidth = windowWidth;
   }else {
      pageWidth = xScroll;
   }

   arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)

}
