﻿//============================================================================================//
function AjustarLayout() {
  /*
  var divEsq = document.getElementById('divEsq');
  var divCen = document.getElementById('divCen');
  var divDir = document.getElementById('divDir');
  divEsq.removeAttribute('style');
  divCen.removeAttribute('style');
  divDir.removeAttribute('style');
  var maiorAltura = divEsq.clientHeight;
  if (maiorAltura < divCen.clientHeight) {
    maiorAltura = divCen.clientHeight;
  }
  if (maiorAltura < divDir.clientHeight) {
    maiorAltura = divDir.clientHeight;
  }
  divEsq.setAttribute('style', 'height: ' + (maiorAltura - 8) + 'px;');
  divCen.setAttribute('style', 'height: ' + (maiorAltura - 8) + 'px;');
  divDir.setAttribute('style', 'height: ' + (maiorAltura - 8) + 'px;');
  */
}
//============================================================================================//
function IrPara(pProtocolo, pArquivo) {
  document.location.href = pProtocolo + '://' + window.location.host + '/' + pArquivo;
}
//============================================================================================//
//DivRepeaterBanSobreposto
function MM_showHideLayers() { //v9.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
  if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
  obj.visibility=v; }
}
function xolayer(){
  MM_showHideLayers('DivRepeaterBanSobreposto','','hide')
}
function Trim(str) { return str.replace(/^\s+|\s+$/g, ""); }
function VerificaDiv() {
  if (Trim(document.getElementById('DivRepeaterBanSobreposto').innerHTML) == "") {
    MM_showHideLayers('DivRepeaterBanSobreposto', '', 'hide')
  } else {
    MM_showHideLayers('DivRepeaterBanSobreposto', '', 'show')
  }
}
//============================================================================================//
function AbrirJanela(pProtocolo, pArquivo, pParametros) {
  var width = 0;
  var height = 0;
  var caracteristicas = '';
  var janela = 'jPlusnetWebStore';
  if (pArquivo == 'WFPagConBolCobreBemX.aspx') {
    width = 677;
    height = 450;
    caracteristicas = ', scrollbars=yes, resizable=yes';
  }
  if (pArquivo == 'WFPagConCarSenff.aspx') {
    width = 617;
    height = 450;
    caracteristicas = ', scrollbars=yes, resizable=yes';
  }
  if (pArquivo == 'WFPagConCarKomerciComprovante.aspx') {
    width = 280;
    height = 440;
  }
  if ((width > 0) && (height > 0)) {
    var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;
    window.open(
      pProtocolo + '://' + window.location.host + '/' + pArquivo + pParametros,
      janela,
      'width=' + width + ', height=' + height + ', left=' + left + ', top=' + top + caracteristicas
    );
  }
}
//============================================================================================//
function ControlarQuantidade(p_Campo, p_PerFracao, p_FatQuantidade, p_LimMaximo) {
  var ExpRegInteiro = /^\d+$/;
  var ExpRegReal = /^((\d+|\d{1,3})(\,\d*)?|\,\d+)$/;
  p_Campo.value = StrLRTrim(p_Campo.value);
  if (p_Campo.value != '') {
    //p_PerFracao
    if (p_PerFracao) {
      if (!ExpRegReal.test(p_Campo.value)) {
        alert('ATENÇÃO!\n\n' +
              'Este produto aceita apenas quantidades com valores numéricos inteiros ou fracionários.');
        p_Campo.focus();
        p_Campo.select();
        return false;
      }
    } else {
      if (!ExpRegInteiro.test(p_Campo.value)) {
        alert('ATENÇÃO!\n\n' +
              'Este produto aceita apenas quantidades com valores numéricos inteiros.');
        p_Campo.focus();
        p_Campo.select();
        return false;
      }
    }
    //p_FatQuantidade
    if ((p_FatQuantidade > 0)) {
      aux = p_Campo.value.replace(",", ".") / p_FatQuantidade;
      aux = aux.toFixed(2);
      if (aux != parseInt(aux)) {
        aux = (p_FatQuantidade * (parseInt(aux) + 1)).toFixed(2);
        aux = aux.replace(".", ",")
        p_Campo.value = aux;
        alert("A quantidade será ajustada para " + p_Campo.value + "\nconforme a embalagem.");
        p_Campo.focus();
        p_Campo.select();
        return false;
      }
    };
    //p_LimMaximo
    if ((parseFloat(p_Campo.value) > p_LimMaximo) && (p_LimMaximo > 0)) {
      alert('ATENÇÃO!\n\n' +
          'Este produto possui um limite máximo por pedido de: ' + p_LimMaximo + '\n');
      p_Campo.focus();
      p_Campo.select();
      return false;
    };
  };
};
//============================================================================================//
function StrLRTrim(p_Str) {
  var strTrim = new String(p_Str);

  while (strTrim.substr(0, 1) == ' ') strTrim = strTrim.substr(1, strTrim.length - 1);
  while (strTrim.substr(strTrim.length - 1, 1) == ' ') strTrim = strTrim.substr(0, strTrim.length - 1);
  return strTrim
};
//============================================================================================//
function correios() {
  var newWin = window.open("AWFXXXCep.aspx", "newWin", "toolbar=no,status=no,menubar=no,scrollbars=no,width=360,height=390,hotkeys=no,location=no,resizable=no,screenX=10,screenY=30,status=no,top=30,left=10");
}
//============================================================================================//
function checar_caps_lock(ev) {
  var e = ev || window.event;
  codigo_tecla = e.keyCode?e.keyCode:e.which;
  tecla_shift = e.shiftKey?e.shiftKey:((codigo_tecla == 16)?true:false);
  if(((codigo_tecla >= 65 && codigo_tecla <= 90) && !tecla_shift) || ((codigo_tecla >= 97 && codigo_tecla <= 122) && tecla_shift)) {
    document.getElementById('aviso_caps_lock').style.visibility = 'visible';
  }
  else {
    document.getElementById('aviso_caps_lock').style.visibility = 'hidden';
  }
}

