
/*******************************************************************
* Fun??es Gen?ricas
*******************************************************************/
var isIE = (navigator.userAgent.toLowerCase().indexOf("msie") != -1);
var isNetscape = (navigator.userAgent.toLowerCase().indexOf("netscape") != -1);
var isMozilla = (navigator.userAgent.toLowerCase().indexOf("gecko") != -1);
var CHECK = "checkbox";
var CHECK_1 = "checkbox_1";
var TEXT = "text";
var COMBO = "combo";
var SPAN = "span";
var HIDDEN = "hidden";
var avisouCapsLock = false;
var imagem = "<table border='0' cellpadding='0' cellspacing='0' width='100%' style='margin-top: 10px'><tr><td align='center' valign='center'><img src='../images/loading.gif'></td></tr></table>";

function buscarConfigDefault(cde_ide){
	var link = "../action/configDefaultsAction.do?acao=buscaConfigDefault";
	var xml = "<?xml version='1.0' encoding='UTF-8'?>\n";
	xml += "<ConfigDefaultVO>";
	xml += "<cde_ide>" + cde_ide + "</cde_ide>";
	xml += "</ConfigDefaultVO>";
	
	return executarXML(xml,link);
}

function textCounter(field, maxlimit) {
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
}

function fContar(entradaObj,salidaObj,caracteres) {
  //var entradaObj=getObject(entrada);
  //var salidaObj=getObject(salida);
  var longitud=caracteres - entradaObj.value.length;
  if(longitud <= 0) {
    longitud=0;
    entradaObj.value=entradaObj.value.substr(0,caracteres);
  }
  salidaObj.innerHTML = longitud;
}

function formatMoney(obj,dec,comma) {
  var f = '';
  var tot = 0;
  var cver = '';
  var ccal = '';
  var re = /,/gi;
  var rep = /\./gi;
  var pos = 0;
  var cint = '';
  var cdec = '';

  if (comma == undefined) comma = true;

  if (dec == undefined) {
    dec = 2
  }

  cver = obj;
  cver = parseFloat(cver);

  if(!isNaN(cver)) {
    cver = cver.toString();
    cver = cver.replace(rep,',');
    pos = cver.search(',');
    cver = cver.replace(re,'.');
    if (pos == -1 || pos == 0) {
      cint = cver;
      cdec = ""
      for (i = 1; i <= dec; i++) {
        cdec += '0';
      }
    } else {
      cint = cver.substr(0, pos);
      cdec = cver.substr(pos + 1, dec);
      while (cdec.length < dec) {
        cdec += '0';
      }
    }
    if (comma) {
      cver = commaSplit(cint + "," + cdec);
    } else {
      cver = cint + "," + cdec;
    }
    obj = cver;
  } else {
    if (obj!='') {
      alert('Valor Inv?lido. Digite apenas valores num?ricos')
      obj = '0,00'
    }
  }

  if (obj == ''){
    var aux = ",";
    obj = '0';
    for (var i = 1; i <= dec; i++) {
      obj += aux + '0';
      aux = '';
    }
  }

  return obj;
}

function abrir_popup_x(acao, params) {
  if (acao == "CONTRATOS"){
	  var largura_ie = 750;
	  var altura_ie = 330;
	  var largura_mozilla = 752;
	  var altura_mozilla = 330;
  }	 else if (acao == "CONTRATOSGRUPOSESCALONADOS"){
	  var largura_ie = 750;
	  var altura_ie = 330;
	  var largura_mozilla = 752;
	  var altura_mozilla = 330;
  }  else if (acao == "EMPRESA" || acao == "CLIENTE") {
	  var largura_ie = 650;
	  var altura_ie = 330;
	  var largura_mozilla = 655;
	  var altura_mozilla = 330;
  }  else if (acao == "MYEMPRESA") {
	  var largura_ie = 650;
	  var altura_ie = 330;
	  var largura_mozilla = 655;
	  var altura_mozilla = 330;
  }  else if (acao == "CONTATOS") {
	  var largura_ie = 750;
	  var altura_ie = 330;
	  var largura_mozilla = 752;
	  var altura_mozilla = 330;
  }  else if (acao == "EMAILPAGADORES") {
	  var largura_ie = 650;
	  var altura_ie = 330;
	  var largura_mozilla = 652;
	  var altura_mozilla = 330;
  }  else if (acao == "EMPRESAPAGADORA") {
	  var largura_ie = 650;
	  var altura_ie = 330;
	  var largura_mozilla = 652;
	  var altura_mozilla = 330;
  }  else if (acao == "FIN_LANCAMENTOS2") {
	  var largura_ie = 650;
	  var altura_ie = 330;
	  var largura_mozilla = 652;
	  var altura_mozilla = 330;
  } else if (acao == "NOVO_CLASS_FIN_DEBITO"){   
  	  var largura_ie = 650;
	  var altura_ie = 340;
	  var largura_mozilla = 655;
	  var altura_mozilla = 340;
  }  else if (acao == "CONSULTIVO") {
	  var largura_ie = 650;
	  var altura_ie = 340;
	  var largura_mozilla = 652;
	  var altura_mozilla = 340;
  }  else if (acao == "CONSULTIVO") {
	  var largura_ie = 650;
	  var altura_ie = 340;
	  var largura_mozilla = 652;
	  var altura_mozilla = 340;
  } else if (acao == "FIN_NOTAS") {
	  var largura_ie = 650;
	  var altura_ie = 340;
	  var largura_mozilla = 652;
	  var altura_mozilla = 340;
  } else if (acao == "PASTAS_LOCAL") {
	  var largura_ie = 460;
	  var altura_ie = 360;
	  var largura_mozilla = 440;
	  var altura_mozilla = 360;
  } else if (acao == "COMARCA") {
	  var largura_ie = 480;
	  var altura_ie = 360;
	  var largura_mozilla = 480;
	  var altura_mozilla = 360;
  } else if (acao == "TEXTO_PADRAO") {
	  var largura_ie = 600;
	  var altura_ie = 330;
	  var largura_mozilla = 600;
	  var altura_mozilla = 330;
  }else {
	  var largura_ie = 460;
	  var altura_ie = 330;
	  var largura_mozilla = 440;
	  var altura_mozilla = 330;
  }
  
  var params_aux = "";

  if (params != null) {
    params_aux = params;
  }

  if (acao == "PROCESSO") {
    abre('../action/popupXAction.do?jsp=' + acao + params_aux,'',690,418,1,1);
  } else {
    if (!isIE) {
      abre('../action/popupXAction.do?jsp=' + acao + params_aux,'',largura_mozilla,altura_mozilla,1,1);
    } else {
      abre('../action/popupXAction.do?jsp=' + acao + params_aux,'',largura_ie,altura_ie,1,1);
    }
  }
}

function spreadCheckVazio(spread) {
  var ret = "";
  for (i=0;i<=spread.process.maxRows-1;i++) {
    ret += "0;";
  }
  return ret;
}

function spreadCheckVazioAux(spread) {
  var ret = "";
  for (i=0;i<=spread.process.maxRows-1;i++) {
    ret += " ;";
  }
  return ret;
}

function spreadCheckVazioFixed(oSpread, col) {
  var csv = "";
  var campo = null;
  var valor = "";

  for (var i=0;i<oSpread.process.maxRows;i++) {
    with (oSpread.body.rows[i]) {
      var type = cells[col-1].childNodes[0].getAttribute("tipo");
      var value = cells[col-1].childNodes[0].getAttribute("value");
      if (type.toUpperCase() == 'CHECK') {
        if (!isIE) {
          csv += "0;";
        } else {
          csv += "0;";
        }
      }
    }
  }

  return csv;
}

function spreadValidDuplicate(spread,tipo,nome_form,coluna) {
  var campo = spreadCsv(spread,tipo,nome_form,coluna);
  var arr_campo = campo.split(";");
  var ret = true;

  for (i=0;i<=arr_campo.length-1;i++) {
    for (j=0;j<=arr_campo.length-1;j++) {
      if (i != j) {
        if (arr_campo[i] == arr_campo[j]) {
          ret = false;
          break;
        }
      }
    }
  }
  return ret;
}

function spreadValidate(nom_spread,tipo,nom_form,coluna) {
  var validar = true;
  var campo = null;

  if (tipo == COMBO) {
    campo = document.getElementsByTagName("select");
  } else if (tipo == SPAN) {
    campo = document.getElementsByTagName("div");
  } else {
    campo = document.getElementsByTagName("input");
  }

  var valor = "";

  for (var i=0;i<=campo.length-1;i++) {
    if (tipo == COMBO) {
      var name = campo[i].getAttribute("name");
      if (name.indexOf(nom_spread + "_" + coluna) != -1) {
        value = eval("document." + nom_form + "." + name + ".value");
        if (value == "") {
          return false;
        }
      }
    } else if ((tipo == TEXT) ||
             (tipo == HIDDEN)) {
      if (campo[i].getAttribute("type") == tipo) {
        var name = campo[i].getAttribute("id");
        if (name.indexOf(nom_spread + "_" + coluna) != -1) {
          value = eval("document." + nom_form + "." + name + ".value");
          if (value == "") {
            return false;
          }
        }
      }
    } else if (tipo == SPAN) {
      var name = campo[i].id;
      if (name.indexOf(nom_spread + "_" + coluna) != -1) {
        var valor = document.getElementById(name).innerHTML;
        if (valor == "") {
          return false;
        }
      }
    }
  }
  return validar;
}

function spreadCsv(nom_spread,tipo,nom_form,coluna) {
  var csv = "";
  var campo = null;

  if (tipo == COMBO) {
    campo = document.getElementsByTagName("select");
  } else if (tipo == SPAN) {
    campo = document.getElementsByTagName("div");
  } else {
    campo = document.getElementsByTagName("input");
  }

  var valor = "";

  for (var i=0;i<=campo.length-1;i++) {
    if (tipo == COMBO) {
      var name = campo[i].getAttribute("name");
      if (name.indexOf(nom_spread + "_" + coluna) != -1) {
        value = eval("document." + nom_form + "." + name + ".value");
        if (value != "") {
          csv += value + ";";
        }
      }
    } else if ((tipo == TEXT) ||
               (tipo == HIDDEN)) {
      if (campo[i].getAttribute("type") == tipo) {
        var name = campo[i].getAttribute("id");
        if (name.indexOf(nom_spread + "_" + coluna) != -1) {
          value = eval("document." + nom_form + "." + name + ".value");
          if (value != "") {
            csv += value + ";";
          }
        }
      }
    } else if (tipo == CHECK) {
      if (campo[i].getAttribute("type") == tipo) {
        var name = campo[i].getAttribute("name");
        if (name.indexOf(nom_spread + "_" + coluna) != -1) {
          var check = campo[i].getAttribute("checked");
          var value = campo[i].getAttribute("value");
          if (!isIE) {
            if (check != null && value != "") {
              csv += value + ";";
            } else {
              csv += "0;";
            }
          } else {
            if (check && value != "") {
              csv += value + ";";
            } else {
              csv += "0;";
            }
          }
        }
      }
    } else if (tipo == SPAN) {
      var name = campo[i].id;
      if (name.indexOf(nom_spread + "_" + coluna) != -1) {
        var valor = document.getElementById(name).innerHTML;
        if (valor != "") {
          csv += document.getElementById(name).innerHTML + ";";
        }
      }
    } else if (tipo == CHECK_1) {
      aux = CHECK;
      if (campo[i].getAttribute("type") == aux) {
        var name = campo[i].getAttribute("name");
        if (name.indexOf(nom_spread + "_" + coluna) != -1) {
          var check = campo[i].getAttribute("checked");
          var value = campo[i].getAttribute("value");
          if (!isIE) {
            if (check != null) {
              csv += "1;";
            } else {
              csv += "0;";
            }
          } else {
            if (check) {
              csv += "1;";
            } else {
              csv += "0;";
            }
          }
        }
      }
    }
  }
  return csv;
}


function spreadCsv2(nom_spread,tipo,nom_form,coluna) {
  var csv = "";
  var campo = null;

  if (tipo == COMBO) {
    campo = document.getElementsByTagName("select");
  } else if (tipo == SPAN) {
    campo = document.getElementsByTagName("div");
  } else {
    campo = document.getElementsByTagName("input");
  }

  var valor = "";

  for (var i=0;i<=campo.length-1;i++) {
    if (tipo == COMBO) {
      var name = campo[i].getAttribute("name");
      if (name.indexOf(nom_spread + "_" + coluna) != -1) {
        value = eval("document." + nom_form + "." + name + ".value");
        if (value != "") {
          csv += value + ";";
        }
      }
    } else if ((tipo == TEXT) ||
               (tipo == HIDDEN)) {
      if (campo[i].getAttribute("type") == tipo) {
        var name = campo[i].getAttribute("id");
        if (name.indexOf(nom_spread + "_" + coluna) != -1) {
          value = eval("document." + nom_form + "." + name + ".value");
          if (value != "") {
            csv += value + ";";
          }
        }
      }
    } else if (tipo == CHECK) {
      if (campo[i].getAttribute("type") == tipo) {
        var name = campo[i].getAttribute("name");
        if (name.indexOf(nom_spread + "_" + coluna) != -1) {
          var check = campo[i].getAttribute("checked");
          var value = campo[i].getAttribute("value");
          if (!isIE) {
            if (check != null && value != "") {
              csv += value + ";";
            } else {
              csv += "100;";
            }
          } else {
            if (check && value != "") {
              csv += value + ";";
            } else {
              csv += "100;";
            }
          }
        }
      }
    } else if (tipo == SPAN) {
      var name = campo[i].id;
      if (name.indexOf(nom_spread + "_" + coluna) != -1) {
        var valor = document.getElementById(name).innerHTML;
        if (valor != "") {
          csv += document.getElementById(name).innerHTML + ";";
        }
      }
    } else if (tipo == CHECK_1) {
      aux = CHECK;
      if (campo[i].getAttribute("type") == aux) {
        var name = campo[i].getAttribute("name");
        if (name.indexOf(nom_spread + "_" + coluna) != -1) {
          var check = campo[i].getAttribute("checked");
          var value = campo[i].getAttribute("value");
          if (!isIE) {
            if (check != null) {
              csv += "1;";
            } else {
              csv += "0;";
            }
          } else {
            if (check) {
              csv += "1;";
            } else {
              csv += "0;";
            }
          }
        }
      }
    }
  }
  return csv;
}

function spreadCsvVazios(nom_spread,tipo,nom_form,coluna) {
  var csv = "";
  var campo = null;

  if (tipo == COMBO) {
    campo = document.getElementsByTagName("select");
  } else if (tipo == SPAN) {
    campo = document.getElementsByTagName("div");
  } else {
    campo = document.getElementsByTagName("input");
  }

  var valor = "";

  for (var i=0;i<=campo.length-1;i++) {
    if (tipo == COMBO) {
      var name = campo[i].getAttribute("name");
      if (name.indexOf(nom_spread + "_" + coluna) != -1) {
        value = eval("document." + nom_form + "." + name + ".value");
        if (value != "") {
          csv += value + ";";
        } else {
          csv += " ;";
        }
      }
    } else if ((tipo == TEXT) ||
               (tipo == HIDDEN)) {
      if (campo[i].getAttribute("type") == tipo) {
        var name = campo[i].getAttribute("id");
        if (name.indexOf(nom_spread + "_" + coluna) != -1) {
          value = eval("document." + nom_form + "." + name + ".value");
          if (value != "") {
            csv += value + ";";
          } else {
            csv += " ;";
          }
        }
      }
    } else if (tipo == CHECK) {
      if (campo[i].getAttribute("type") == tipo) {
        var name = campo[i].getAttribute("name");
        if (name.indexOf(nom_spread + "_" + coluna) != -1) {
          var check = campo[i].getAttribute("checked");
          var value = campo[i].getAttribute("value");
          if (!isIE) {
            if (check != null) {
              csv += value + ";";
            } else {
              csv += "0;";
            }
          } else {
            if (check) {
              csv += value + ";";
            } else {
              csv += "0;";
            }
          }
        }
      }
    } else if (tipo == SPAN) {
      var name = campo[i].id;
      if (name.indexOf(nom_spread + "_" + coluna) != -1) {
        var valor = document.getElementById(name).innerHTML;
        if (valor != "") {
          csv += document.getElementById(name).innerHTML + ";";
        } else {
          csv += " ;";
        }
      }
    } else if (tipo == CHECK_1) {
      aux = CHECK;
      if (campo[i].getAttribute("type") == aux) {
        var name = campo[i].getAttribute("name");
        if (name.indexOf(nom_spread + "_" + coluna) != -1) {
          var check = campo[i].getAttribute("checked");
          var value = campo[i].getAttribute("value");
          if (!isIE) {
            if (check != null) {
              csv += "1;";
            } else {
              csv += "0;";
            }
          } else {
            if (check) {
              csv += "1;";
            } else {
              csv += "0;";
            }
          }
        }
      }
    }
  }
  return csv;
}

function pesqPopUpGenerica(acao,pesquisa,campo,campo_ide,nome_form) {
  var link = "../action/popUpAction.do?xml=1";
  var xml;

  xml  = "<?xml version='1.0' encoding='UTF-8'?>\n";
  xml += "<Popup>\n";
  xml += "<TipoAcao>" + acao + "</TipoAcao>\n";
  xml += "<Campo>" + campo + "</Campo>\n";
  xml += "<CampoIde>" + campo_ide + "</CampoIde>\n";
  xml += "<Pesquisa>" + pesquisa + "</Pesquisa>\n";
  xml += "<NomeForm>" + nome_form + "</NomeForm>\n";
  xml += "</Popup>\n";
  var retorno = executarXML(xml, link);

  eval(retorno);
}

function pesqPopUpX(pesquisa) {
  var link = "../action/popupXAction.do";
  var xml;

  xml  = "<?xml version='1.0' encoding='UTF-8'?>\n";
  xml += "<Popup>\n";
  xml += "<Pesquisa>" + pesquisa + "</Pesquisa>\n";
  xml += "</Popup>\n";
  var retorno = executarXML(xml, link);

  eval(retorno);
}

function abrir_popup_generico(acao,formulario,campo_ide,campo_valor,flag_honorario,flag_hidden_ide,flag_campo,flg_pesquisa,pesquisa) {
  var flag_honorario_aux = "";
  var flag_hidden_ide_aux = "";
  var flag_campo_aux = "";
  var largura_ie = 460;
  var altura_ie = 320;
  var largura_mozilla = 440;
  var altura_mozilla = 310;
  var flg_pesquisa_aux = "";
  var pesquisa_aux = "";

  if (flag_honorario != null) {
    if (flag_honorario == "1") {
      flag_honorario_aux = "&flag=1";
    }
  }

  if (flag_hidden_ide != null) {
    if (flag_hidden_ide == "1") {
      flag_hidden_ide_aux = "&hidden_ide=1";
    }
  }

  if (flag_campo != null) {
    if (flag_campo == "1") {
      flag_campo_aux = "&campo=1"
    }
  }

  if (flg_pesquisa != null) {
    if (flg_pesquisa == "1") {
      flg_pesquisa_aux = "&flg_pesquisa=1";
    }
  }

  if (pesquisa != null) {
    pesquisa_aux = "&pesquisa=" + pesquisa;
  }

  var pesquisa = "";

  if (!isIE) {
    abre('../action/popUpAction.do?acao=' + acao + '&formulario=' +
		formulario + '&campo_ide=' +
		campo_ide + '&campo_valor=' +
		campo_valor +
		flag_honorario_aux +
		flag_hidden_ide_aux +
		flag_campo_aux +
		flg_pesquisa_aux +
		pesquisa_aux,'',largura_mozilla,altura_mozilla,1,1);
  } else {
    abre('../action/popUpAction.do?acao=' + acao + '&formulario=' +
		formulario + '&campo_ide=' +
		campo_ide + '&campo_valor=' +
		campo_valor +
		flag_honorario_aux +
		flag_hidden_ide_aux +
		flag_campo_aux +
		flg_pesquisa_aux +
		pesquisa_aux,'',largura_ie,altura_ie,1,1);
  }
}

function refresh() {
  window.location.reload();
}

function select_check(obj) {
  if (!obj.hasAttribute("checked")) {
    obj.setAttribute("checked","true");
  } else {
    obj.removeAttribute("checked");
  }
}

function criaArray(n){
	this.length = n;
    for (var i = 0; i <= n; i++){
		this[i] = 0;
    }
    return this;
}

function trIn(o) {
//	o.style.background-color = '#ccffdd';
}

function trOut(o) {
//	o.bgcolor = '';
}

function loading(e) {
	var buttons = document.getElementsByTagName("input");
	try {
		if (e == 1) {
			document.body.style.cursor = "wait";
			document.getElementById("msg").style.cursor = "wait"
		} else {
			document.body.style.cursor = "";
			document.getElementById("msg").style.cursor = "pointer"
		}
	} catch(ex) {}

	for (var i = 0; i < buttons.length; i++) {
		var button = buttons[i];
		if (e == 1) {
			button.style.cursor = "wait";
		} else {
			if (button.type == 'button' || button.type == 'submit') {
				button.style.cursor = "pointer";
			} else {
				button.style.cursor = "";
			}
		}
	}
}

function executarXML(xml,link) {
  var retorno = "";
  if (isNetscape || isMozilla) {
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("POST",link, false);
  } else if (isIE) {
    xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
    xmlHttp.Open("POST",link, false);
  }

  xmlHttp.send(xml);
  retorno = xmlHttp.responseText;
  return retorno;
}

function executarXMLAssin( xml, link, funcao ){
	var retorno = "";
	var xmlHttp = null;
  	if( !isIE ){
  		xmlHttp = new XMLHttpRequest();
  		xmlHttp.open( "POST",link, true );
  	}
  	else{
  		//xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
  		xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
  		xmlHttp.open( "POST",link, true );
  	}

	xmlHttp.onreadystatechange = function(){
		if( xmlHttp.readyState == 4 ){
			if( xmlHttp.status == 200 ){
				eval(funcao);
				eval(xmlHttp.responseText);
			}
		}
	}
		
	xmlHttp.send( xml );
	
	return retorno;
}



function abre(url,janela,larg,alt,scroll) {
	nTop  = (screen.height / 2) - (alt  / 2)
	nLeft = (screen.width  / 2) - (larg / 2)

	window.open(url,janela,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+scroll+",resizable=no,copyhistory=no,width="+larg+",height="+alt+",top="+nTop+",left="+nLeft);
}

function maxLength(e,nmax) {
  if(e.value.length>=nmax) {
    e.value=e.value.substr(0,nmax - 1);
  }
}

function fNumberBco(str) {
  re = /^\$|\./g;
  str = str.replace(re, "");

  re = /\,/g;
  return str.replace(re, ".");
}

function tirarEspacoBlank(str) {
  re = /\&nbsp;/g;
  return str.replace(re, "");
}

function fNumberBcoInv(str) {
  re = /^\$|\./g;
  str = str.replace(re, ",");

  return str;
}

function fJava(str) {
  re = /"/g;
  str = str.replace(re, '\"');
  re = /'/g;
  return str.replace(re, "\'");
}

function fHtml(str) {
  re = /&/g;
  str = str.replace(re, '&amp;');
  re = /</g;
  str = str.replace(re, '&lt;');0
  re = />/g;
  str = str.replace(re, "&gt;");
  re = /'/g;
  str = str.replace(re, "''");
  re = /"/g;
  return str.replace(re, "&quot;");
}

function fJsHtml(str) {
  re = /&amp;/g;
  str = str.replace(re, '&');
  re = /&lt;/g;
  str = str.replace(re, '<');
  re = /&gt;/g;
  str = str.replace(re, ">");
  re = /&quot;/g;
  return str.replace(re, '"');
}

function selecionacombo(nCombo,nIndex)
{
  var n = nCombo.length;
  for(var i=0;i<n;i++){
    if(nCombo.options[i].value == nIndex){
      nCombo.options[i].selected = true;
    } else {
      nCombo.options[i].selected = false;
    }
  }
}

function vHora(campo){
	hora = campo.value;

	if (hora != '')
	{
		var hor = parseInt(hora.substring(0,2),10);
		var min = parseInt(hora.substring(3,5),10);

		if (hor <= 23 && min <= 59){
			if (hora.substring(2,3)==":"){
				return true;
			}else{
				window.alert('Hora inválida, por favor entre com o formato (hh:mm) !');
				campo.value = '';
				campo.focus();
				return false;
			}
		}else{
			window.alert('Hora inválida, por favor entre com o formato (hh:mm) !');
			campo.value = '';
			campo.focus();
			return false;
		}
	}

	return true;
}

function vData(campo){
	var data = campo.value;
	if (data != ""){
		aux1 = 0
		aux2 = 0
		while (data.indexOf("/",aux1) != -1)
		{
			aux1 = data.indexOf("/",aux1) + 1;
			aux2++;
		}

		if (aux2 > 2)
		{
			window.alert('Data inválida, por favor entre com o formato (dd/mm/aaaa) !');
			campo.focus();
			campo.value = '';
			return false;
		}

		var dia = parseInt(data.substring(0,2),10);
		var mes = parseInt(data.substring(3,5),10);
		var ano = parseInt(data.substring(6,10),10);
		if (data.substring(0,1)=='0' && data.substring(1,2) != '0' ||
			data.substring(0,1)!='0'){
			if (data.substring(2,3)=="/"){
				if (data.substring(3,4)=='0' && data.substring(4,5)!='0' ||
					data.substring(3,4)!='0'){
					if (data.substring(5,6)=="/"){
						if (data.substring(6,7)== '0' ||
							data.substring(6,7)=='' && data.substring(7,8)!='0'){
							window.alert('Data inválida, por favor entre com o formato (dd/mm/aaaa) !');
							campo.focus();
							campo.value = '';
							return false;
						}
					}else{
						window.alert('Use "/" ( barra ) como separador de data !');
						campo.focus();
						campo.value = '';
						return false;
					}
				}else{
					window.alert('Data inválida, por favor entre com o formato (dd/mm/aaaa) !');
					campo.focus();
					campo.value = '';
					return false;
				}
			}else{
				window.alert('Use "/" ( barra ) como separador de data !');
				campo.focus();
				campo.value = '';
				return false;
			}
		}else{
			window.alert('Data inválida, por favor entre com o formato (dd/mm/aaaa) !');
			campo.focus();
			campo.value = '';
			return false;
		}
		if (ano < 1900 || ano > 2100){
			window.alert('Ano fora do intervalo permitido !');
			campo.focus();
			campo.value = '';
			return false;
		}
		if (mes == 2){
			if (dia > 0 && dia <= 29){
				if (dia == 29){
					if ((ano % 4) != 0){
						window.alert('Este ano não é bissexto !');
						campo.focus();
						campo.value = '';
						return false;
					}
				}
			}else{
				window.alert('O dia é inválido para o mês de fevereiro !');
				campo.focus();
				campo.value = '';
				return false;
			}
		}
		if (mes > 12){
			window.alert('Mès inválido !');
			campo.focus();
			campo.value = '';
			return false;
		}
		if ((mes == 4)||(mes == 6)||(mes == 9)||(mes == 11)){
			if ((dia < 1 ) || (dia > 30)){
				window.alert('Este mês não tem mais de 30 dias !');
				campo.focus();
				campo.value = '';
				return false;
			}
		}else{
			if ((dia < 1) || (dia > 31)){
				window.alert('O mês não pode ter mais de 31 dias !');
				campo.focus();
				campo.value = '';
				return false;
			}
		}
	}
	return true;
}

function fDataBco(data)
{
	return data.substring(6,10) + "-" +
		   data.substring(3,5)+ "-" +
		   data.substring(0,2)
}

function comparaData(dtmenor,dtmaior){
	if (parseInt((dtmenor.substring(6,10) +
		dtmenor.substring(3,5)+
		dtmenor.substring(0,2)),10) >
		parseInt((dtmaior.substring(6,10) +
		dtmaior.substring(3,5)+
		dtmaior.substring(0,2)),10)){
		return false;
	}
	return true;
}

function spreadCsvCheckValue(oSpread, col_check, col_value) {
  var csv = "";
  var campo = null;
  var valor = "";

  for (var i=0;i<oSpread.process.maxRows;i++) {
    with (oSpread.body.rows[i]) {
      var type = cells[col_check-1].childNodes[0].getAttribute("tipo");
      var value = cells[col_check-1].childNodes[0].getAttribute("value");
      if (type.toUpperCase() == 'CHECK') {
        if (!isIE) {
          if (cells[col_check-1].childNodes[0].getAttribute("checked") != null) {
            csv += oSpread.getValue(col_value,i+1) + " ;";
          }
        } else {
          if (cells[col_check-1].childNodes[0].checked) {
            csv += oSpread.getValue(col_value,i+1) + " ;";
          }
        }
      }
    }
  }

  return csv;
}

function spreadCsvFixedOk(oSpread, col, hidden) {
  var csv = "";
  var campo = null;
  var valor = "";

  for (var i=0;i<oSpread.process.maxRows;i++) {
    if (hidden) {
      with (oSpread.hidden.rows[i]) {
        //csv += (fJava(cells[col-1].childNodes[0].value) == "" ? " " : fJava(cells[col-1].childNodes[0].value)) + ";";
      }
    } else {
      with (oSpread.body.rows[i]) {
        var type = cells[col-1].childNodes[0].getAttribute("tipo");
        var value = cells[col-1].childNodes[0].getAttribute("value");
        if (type.toUpperCase() == 'LABEL') {
          //csv += (fJava(cells[col-1].childNodes[0].innerHTML) == "" ? " " : fJava(cells[col-1].childNodes[0].innerHTML)) + ';';
        } else if (type.toUpperCase() == 'CHECK') {
          if (!isIE) {
            if (cells[col-1].childNodes[0].getAttribute("checked") != null) {
              //csv += value + "1;";
            } else {
              //csv += "0;";
            }
          } else {
            if (cells[col-1].childNodes[0].checked) {
              csv += "1;";
            } else {
              csv += "0;";
            }
          }
        } else {
          //csv += (fJava(cells[col-1].childNodes[0].value) == "" ? " " : fJava(cells[col-1].childNodes[0].value)) + ';';
        }
      }
    }
  }

  return csv;
}


function mySpreadCsvFixed(oSpread, col,tok) {
  var csv = "";
  for (var i=0;i<oSpread.process.maxRows;i++) {
  	with (oSpread.body.rows[i]) {
  		var value = cells[col-1].childNodes[0].getAttribute("value");
  		if (value != "") {
  			csv += value + tok;
  		}
    }
  }
  return csv;
}

function spreadCsvFixed(oSpread, col, hidden) {
  var csv = "";
  var campo = null;
  var valor = "";

  for (var i=0;i<oSpread.process.maxRows;i++) {
    if (hidden) {
      with (oSpread.hidden.rows[i]) {
        csv += (fJava(cells[col-1].childNodes[0].value) == "" ? " " : fJava(cells[col-1].childNodes[0].value)) + ";";
      }
    } else {
      with (oSpread.body.rows[i]) {
        var type = cells[col-1].childNodes[0].getAttribute("tipo");
        var value = cells[col-1].childNodes[0].getAttribute("value");
        if (type.toUpperCase() == 'LABEL') {
          csv += (fJava(cells[col-1].childNodes[0].innerHTML) == "" ? " " : fJava(cells[col-1].childNodes[0].innerHTML)) + ';';
        } else if (type.toUpperCase() == 'CHECK') {
          if (!isIE) {
            if (cells[col-1].childNodes[0].checked != 0) {
				//alert(csv += value);
              csv += value + " ;";
            } else {
              csv += "0;";
            }
          } else {
            if (cells[col-1].childNodes[0].checked) {
              csv += value + " ;";
            } else {
              csv += "0;";
            }
          }
        } else {
          csv += (fJava(cells[col-1].childNodes[0].value) == "" ? " " : fJava(cells[col-1].childNodes[0].value)) + ';';
        }
      }
    }
  }

  return csv;
}






function spreadCsvFixed(oSpread, col, hidden) {
  var csv = "";
  var campo = null;
  var valor = "";

  for (var i=0;i<oSpread.process.maxRows;i++) {
    if (hidden) {
      with (oSpread.hidden.rows[i]) {
        csv += (fJava(cells[col-1].childNodes[0].value) == "" ? " " : fJava(cells[col-1].childNodes[0].value)) + ";";
      }
    } else {
      with (oSpread.body.rows[i]) {
        var type = cells[col-1].childNodes[0].getAttribute("tipo");
        var value = cells[col-1].childNodes[0].getAttribute("value");
        if (type.toUpperCase() == 'LABEL') {
          csv += (fJava(cells[col-1].childNodes[0].innerHTML) == "" ? " " : fJava(cells[col-1].childNodes[0].innerHTML)) + ';';
        } else if (type.toUpperCase() == 'CHECK') {
          if (!isIE) {
            if (cells[col-1].childNodes[0].checked != 0) {
				//alert(csv += value);
              csv += value + " ;";
            } else {
              csv += "0;";
            }
          } else {
            if (cells[col-1].childNodes[0].checked) {
              csv += value + " ;";
            } else {
              csv += "0;";
            }
          }
        } else {
          csv += (fJava(cells[col-1].childNodes[0].value) == "" ? " " : fJava(cells[col-1].childNodes[0].value)) + ';';
        }
      }
    }
  }

  return csv;
}










function spreadCsvFixedEx(oSpread, col, hidden) {
  var csv = "";
  var campo = null;
  var valor = "";

  for (var i=0;i<oSpread.process.maxRows;i++) {
    if (hidden) {
      with (oSpread.hidden.rows[i]) {
        csv += (fJava(cells[col-1].childNodes[0].value) == "" ? "0" : fJava(cells[col-1].childNodes[0].value)) + ";";
      }
    } else {
      with (oSpread.body.rows[i]) {
        var type = cells[col-1].childNodes[0].getAttribute("tipo");
        var value = cells[col-1].childNodes[0].getAttribute("value");
        if (type.toUpperCase() == 'LABEL') {
          csv += (fJava(cells[col-1].childNodes[0].innerHTML) == "" ? "0" : fJava(cells[col-1].childNodes[0].innerHTML)) + ';';
        } else if (type.toUpperCase() == 'CHECK') {
          if (!isIE) {
            if (cells[col-1].childNodes[0].getAttribute("checked") != null) {
              csv += value + "0;";
            } else {
              csv += "0;";
            }
          } else {
            if (cells[col-1].childNodes[0].checked) {
              csv += value + "0;";
            } else {
              csv += "0;";
            }
          }
        } else {
          csv += (fJava(cells[col-1].childNodes[0].value) == "" ? "0" : fJava(cells[col-1].childNodes[0].value)) + ';';
        }
      }
    }
  }

  return csv;
}

function spreadCsvFixedBlankEx(oSpread, col, hidden) {
  var csv = "";
  var campo = null;
  var valor = "";

  for (var i=0;i<oSpread.process.maxRows;i++) {
    if (hidden) {
      with (oSpread.hidden.rows[i]) {
        csv += fJava(cells[col-1].childNodes[0].value) == "" ? "0;" : "0;";
      }
    } else {
      with (oSpread.body.rows[i]) {
        var type = cells[col-1].childNodes[0].getAttribute("tipo");
        var value = cells[col-1].childNodes[0].getAttribute("value");
        if (type.toUpperCase() == 'LABEL') {
          csv += fJava(cells[col-1].childNodes[0].innerHTML) == "" ? "0;" : "0;";
        } else if (type.toUpperCase() == 'CHECK') {
          if (!isIE) {
            if (cells[col-1].childNodes[0].getAttribute("checked") != null) {
              csv += "0;";
            } else {
              csv += "0;";
            }
          } else {
            if (cells[col-1].childNodes[0].checked) {
              csv += "0;";
            } else {
              csv += "0;";
            }
          }
        } else {
          csv += fJava(cells[col-1].childNodes[0].value) == "" ? "0;" : "0;";
        }
      }
    }
  }

  return csv;
}


function onload() {
  var aux = true;
  try {
    window.focus();
  } catch(e) {}

  try {
    document.forms[0][0].focus();
  } catch(e) {}
}

function spreadCsvHiddenFixed(oSpread, col) {
  var csv = "";
  var campo = null;
  var valor = "";

  for (var i=0;i<oSpread.process.maxRows;i++) {
    with (oSpread.hidden.rows[i]) {
      csv += (fJava(cells[col-1].childNodes[0].value) == "" ? "0" : fJava(cells[col-1].childNodes[0].value)) + ";";
    }
  }
  return csv;
}

function spreadCsvHiddenBlankFixed(oSpread, col) {
  var csv = "";
  var campo = null;
  var valor = "";

  for (var i=0;i<oSpread.process.maxRows;i++) {
    with (oSpread.hidden.rows[i]) {
      csv += fJava(cells[col-1].childNodes[0].value) == "" ? "0;" : "0;";
    }
  }
  return csv;
}

function spreadCsvCheckFixed(oSpread, col) {
  var csv = "";
  var campo = null;
  var valor = "";

  for (var i=0;i<oSpread.process.maxRows;i++) {
    with (oSpread.body.rows[i]) {
      var type = cells[col-1].childNodes[0].getAttribute("tipo");
      var value = cells[col-1].childNodes[0].getAttribute("value");
      if (type.toUpperCase() == 'CHECK') {
        if (!isIE) {
          if (cells[col-1].childNodes[0].getAttribute("checked") != null) {
            csv += "1;";
          } else {
            csv += "0;";
          }
        } else {
          if (cells[col-1].childNodes[0].checked) {
            csv += "1;";
          } else {
            csv += "0;";
          }
        }
      }
    }
  }

  return csv;
}


setTimeout("onload()",10);

function fMinutesToHours(m){
	var hora = 0;
	var minuto = 0;
	var ret = "";
	var ponto = 0;
	if(isNaN(m)){
		return '00:00';
	} else {
		if (m < 60)	{
			hora = 0;
			minuto = m;
		} else {
			hora = m / 60;
			if (hora.toString().indexOf('.') < 0){
				ponto = hora.toString().length;
			} else {
				ponto = hora.toString().indexOf('.');
			}
			hora = hora.toString().substring(0,ponto);
			minuto = m - (hora * 60);
		}
		ret  = hora < 10 ? '0' + hora : hora;
		ret += ":";
		ret += minuto < 10 ? '0' + minuto : minuto;
		return ret;
	}
}

function fHoursToMinutes(h){
	var hora = 0;
	var minuto = 0;
	var ret = "";
	var ponto = 0;
	if (h.toString().indexOf(":") < 0){
		ret = h * 60;
	} else {
		ponto = h.toString().indexOf(':');
		hora = h.toString().substring(0,ponto) * 60;
		minuto = h.toString().substring(ponto + 1,h.toString().length);
		ret = parseInt(hora) + parseInt(minuto);
	}
	return ret;
}

function checkCapsLock( e ) {
	if (!avisouCapsLock){
		avisouCapsLock = true;
		var myKeyCode=0;
		var myShiftKey=false;
		var myMsg='A tecla Caps Lock está ativada.\n\nPara evitar que a senha seja digitada incorretamente,\nvocê deve desativá-la.';

		// Internet Explorer 4+
		if ( document.all ) {
			myKeyCode=e.keyCode;
			myShiftKey=e.shiftKey;

		// Netscape 4
		} else if ( document.layers ) {
			myKeyCode=e.which;
			myShiftKey=( myKeyCode == 16 ) ? true : false;

		// Netscape 6
		} else if ( document.getElementById ) {
			myKeyCode=e.which;
			myShiftKey=( myKeyCode == 16 ) ? true : false;

		}

		// Upper case letters are seen without depressing the Shift key, therefore Caps Lock is on
		if ( ( myKeyCode >= 65 && myKeyCode <= 90 ) && !myShiftKey ) {
			alert( myMsg );

		// Lower case letters are seen while depressing the Shift key, therefore Caps Lock is on
		} else if ( ( myKeyCode >= 97 && myKeyCode <= 122 ) && myShiftKey ) {
			alert( myMsg );

		}
	}
}
