function checa(obj, focou, padrao){
  if(focou){
    if(obj.value==padrao)
      obj.value='';
     else
       obj.select();
  } else {
    if(obj.value=='')
    obj.value=padrao;
  }
}

function abreProcessos(id){
  if(bloqueadorPopUpAtivo())
    window.open("popup.php?pg=galeria&id="+id+"&ops=processos", "centro");
  janLarg = 620;
  janAlt = 440;
  largura = screen.width;
  altura = screen.height;
  xPos = (largura - janLarg) / 2;
  yPos = (altura - janAlt) / 2;
  self.focus();
  window.open("galeria.php?id="+id+"&tipo=processos","processos","width="+janLarg+",height="+janAlt+",top="+yPos+",left="+xPos);
  void(0);
}

function checkSearch(){
  var erro = '';
  var focou = false;
  var objFocus = null;
  var form = document.getElementById('formBusca');

  if(form.arg.value.length == 0){
    erro += "  - Preencha o nome do produto a ser pesquisado\n";
    if(!focou){
      focou = true;
      objFocus = form.arg;
    }
  }

  if(erro!=''){
    alert("Corrija o(s) seguinte(s) erro(s):\n" + erro);
    objFocus.focus();
    return void(0);
  } else {
    form.submit();
    return void(0);
  }
}

function bloqueadorPopUpAtivo(){
  var b;
  var j = window.open('', '', 'width=1,height=1,left=0,top=0,scrollbars=no');
  if(j){
    b = false;
    j.close();
  } else
    b = true;

  return b;
}

function LTrim(value) {  
  var re = /\s*((\S+\s*)*)/;
  return value.replace(re, "$1");
}

function RTrim(value) {
  var re = /((\s*\S+)*)\s*/;
  return value.replace(re, "$1");
}

function trim(value) {
  return LTrim(RTrim(value));
}

function showHide(objName){

  var obj = document.getElementById(objName);
  var obj2 = document.getElementById("ModeloSubMenu");

  if(obj == null || obj == undefined || obj2 == null || obj2 == undefined){
    alert("Não foi possível exibir os submenus!");
  } else {
    if(obj.style.display == "none"){
      obj.style.display = obj2.style.display;
    } else {
      obj.style.display = "none";
    }
  }
  void(0);

}
function amplia(img, imprimir){
  var ptr = "";
  if(imprimir!=null && imprimir!='undefined' && imprimir)
    ptr += "&print=true";
  window.open("ampliaImg.php?foto="+img+ptr,"","width=1,height=1,top=0,left=0")
  void(0);
}
function abrePOPUP(pg, id, ops){
  if(bloqueadorPopUpAtivo())
    alert("Seu bloqueador ainda está ativo. Tente desabilitar por completo.");
  if(pg == "galeria"){
    janLarg = 620;
    janAlt = 440;
    largura = screen.width;
    altura = screen.height;
    xPos = (largura - janLarg) / 2;
    yPos = (altura - janAlt) / 2;
    self.focus();
    window.open("galeria.php?id="+id+"&tipo="+ops, ops,"width="+janLarg+",height="+janAlt+",top="+yPos+",left="+xPos);
	}
  void(0);
}

function bloqueadorPopUpAtivo(){
  var b;
  var j = window.open('', '', 'width=1,height=1,left=0,top=0,scrollbars=no');
  if(j){
    b = false;
    j.close();
	} else
    b = true;

  return b;
}

function abreGL(id){
  var janLarg = 620;
  var janAlt = 440;
  var largura = screen.width;
  var altura = screen.height;
  var xPos = (largura - janLarg) / 2;
  var yPos = (altura - janAlt) / 2;
  self.focus();
  window.open("galeria.php?id="+id+"&tipo=instalacoes","instalacoes","width="+janLarg+",height="+janAlt+",top="+yPos+",left="+xPos);
  void(0);
}
