function AdicionaCSS(Codigo){
var head = document.getElementsByTagName('head')[0],
    style = document.createElement('style'),
    rules = document.createTextNode(Codigo);

style.type = 'text/css';
if(style.styleSheet)
    style.styleSheet.cssText = rules.nodeValue;
else style.appendChild(rules);
head.appendChild(style);
}
function ReleImagem(id) {
   var obj = PegaElemento(id);
   var src = obj.src;
   var pos = src.indexOf('?');
   if (pos >= 0) {
      src = src.substr(0, pos);
   }
   var date = new Date();
   obj.src = src + '?' + date.getTime();
   return false;
}
function IframeSRC(Id,URL){    
	VarPopUpGetSeparador = '?';
	if (URL.indexOf('?') != -1){
		VarPopUpGetSeparador = '&';
	}
	URL = URL + VarPopUpGetSeparador + 'SubPagina=' + Id + '&IdIframe=' + Id;
	PegaIframe(Id).src = URL;
}
function Iframe(Pagina){
    xajax_Iframe(Pagina);
}
function FecharJanela(){
    parent.$.modal.close();
}
function PegaIframe(Id){
    if (!ObjetoExiste(parent.document.getElementById(Id))){
        Iframe =  document.getElementById(Id);   
    }else{
        Iframe = parent.document.getElementById(Id);
    } 
    return Iframe;   
}
function PegaTamanhoDiv(Div){
    if (PegaElemento(Div).offsetHeight){
        return PegaElemento(Div).offsetHeight;
    }else if (PegaElemento(Div).clientHeight){
        return PegaElemento(Div).clientHeight;
    }    
}
function AjustaTamanhoIframe(){
    var Tamanho;
    Tamanho = PegaTamanhoDiv('Conteudo');
    if (Tamanho){        
        window.frameElement.height = Tamanho;
        window.frameElement.scrolling  = "no";
        if (ObjetoExiste(parent.window.frameElement)){
            parent.AjustaTamanhoIframe();
        }
    }
}
function SubstituiCaracteres(char,charreplace,str){
	charToRemove = char;	
	regExp = new RegExp("["+charToRemove+"]","g");	
	return str.replace(regExp,charreplace);
}
function TipoNavegador(){
	var browser=navigator.appName;
	switch(browser){
	case 'Microsoft Internet Explorer':
		return 'MSIE';
	break;
	}
}
function ExecFuncaoAtraso(Funcao,Segundos){
    Segundos = Segundos * 1000;
    if(window.mytimeout) window.clearTimeout(window.mytimeout);
    eval("window.mytimeout = window.setTimeout(function(){" + Funcao + "}," + Segundos + ")");
 return true;
}
function ImprimirIframe(Iframe){
	if (TipoNavegador() == 'MSIE'){
		window.frames[Iframe].document.execCommand('print', false, null);
	}else{
		window.frames[Iframe].focus();
		window.frames[Iframe].print();
	}
	
}
function AdicionaCodigoCssPagina(Codigo){
	var style = document.createElement("style");
	style.setAttribute("type", "text/css");
	if(style.styleSheet){// IE
	style.styleSheet.cssText = Codigo;
	} else {// w3c
	var cssText = doc.createTextNode(cssStr);
	style.appendChild(cssText);
	}
	document.body.appendChild(style);
}
function PegaQueryString(ji){
    var Resultado;
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		if (ft[0] == ji) {
			Resultado = ft[1];
		}
	}
    if (!Resultado){
        Resultado = '';
    }	
    return Resultado;
}
function RemoveQueryString(Caminho){
    TemQuerystring = Caminho.indexOf('?');
    if (TemQuerystring != -1){
        Caminho = Caminho.substr(0,TemQuerystring); 
    }
    return Caminho;  
}
function homelogado(endereco){
    window.location.href = endereco;
}
function VoltarPaginaAnterior(){
    history.back(-1);
}
function DeletaLinha(tblName, rowindex)
{
    var tbl = document.getElementById(tblName);
    tbl.deleteRow(rowindex);
}
function Redireciona(url){
    parent.window.location.href = url;
}
function CampoVazio(valor) {
	valconv = trim(valor);
	if (valconv == "" || valconv == null || valconv.length == 0 || valconv == '0') {
		return true;
	} else {
   		return false;
	}
}
function over(botao){
    botao.style.cursor='pointer';
}
function trim(str)
{  while(str.charAt(0) == (" ") )
  {  str = str.substring(1);
  }
  while(str.charAt(str.length-1) == " " )
  {  str = str.substring(0,str.length-1);
  }
  return str;
}
function PreloadImagens(Caminho){
    for(i=1;i<arguments.length;i++){
        if (document.images){
          pic1= new Image(1,1);
          pic1.src=Caminho + arguments[i];
        }
    }
}

function in_array(arraydin,valor){
    valorretorno = false;
    for (i in arraydin) {
        if (valor.toString() == arraydin[i].toString()){
            valorretorno = true;
        }
    }
    return valorretorno;
}

function GetObj(objName){
  if(document.getElementById){
      return eval('document.getElementById("' + objName + '")');
  }else if(document.layers){
      return eval("document.layers['" + objName +"']");
  }else{
      return eval('document.all.' + objName);
  }
}
function PegaElemento(Id){
    if (ObjetoExiste(document.getElementById(Id))){
        return document.getElementById(Id);
    }else{
        return false;
    }
}
function ObjetoExiste(Objeto){
    Existe = Objeto != null && Objeto != 'undefined';
    if (Existe){
        return true;
    }else{
        return false;
    }
}    
function MostraOcultaCamada(Id,Acao){
    Atributo(Id,'style.display',Acao);   
}
function RemoveElemento(Elemento){
Objeto = PegaElemento(Elemento);
if (ObjetoExiste(Objeto)){
    Objeto.parentNode.removeChild(Objeto);
    AjustaTamanhoIframe();
} 
}
function Atributo(Id,Atributo,Valor){
    if (ObjetoExiste(PegaElemento(Id))){
        eval("PegaElemento('" + Id + "')." + Atributo + "='" + Valor + "'");
    }
}