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 checkdate(month, day, year){

  var intDay = parseInt(day, 10);
  var intMonth = parseInt(month, 10);
  var intYear = parseInt(year, 10);
  var checkYear = year != null && year != undefined;
  var arrMeses = new Array("Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro");
  var error = "";

  if (intMonth>12 || intMonth<1) {
    error += "  - Mês fora do intervalo esperado (Jan a Dez)\n";
  }

  if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intDay > 31 || intDay < 1)) {
    error += "  - Dia fora do intervalo esperado para o mes \""+arrMeses[intMonth-1]+"\"\n";
  } else if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intDay > 30 || intDay < 1)) {
    error += "  - Dia fora do intervalo esperado para o mes \""+arrMeses[intMonth-1]+"\"\n";
  } else if (intMonth == 2) {
    if (intDay < 1) {
      error += "  - Dia fora do intervalo esperado para o mes \""+arrMeses[intMonth-1]+"\"\n";
    } else if(checkYear) {
      if(LeapYear(intYear) == true) {
        if (intDay > 29) {
          error += "  - Dia fora do intervalo esperado para o mes e ano esperado "+arrMeses[intMonth-1]+"/"+intYear+"\n";
        }
      } else {
        if (intDay > 28) {
          error += "  - Dia fora do intervalo esperado para o mes e ano esperado "+arrMeses[intMonth-1]+"/"+intYear+"\n";
        }
      }
		} else {
      if (intDay > 29) {
        error += "  - Dia fora do intervalo esperado para o mes \""+arrMeses[intMonth-1]+"\"\n";
      }
		}
  }

  return error;

}

function LeapYear(intYear) {
  return ((intYear % 100 == 0 && intYear % 400 == 0) || (intYear % 4 == 0));
}
