function valEntNumero() { return !isNaN(String.fromCharCode(event.keyCode)) || valNavegacao(event.keyCode); } function valPasteNumero() { return !isNaN(window.clipboardData.getData("Text")); } function valNavegacao(keyCode) { switch(keyCode) { case 46 : case 8: case 37: case 38: case 39: case 40: return true; } return false; } function exibirCalendario(objeto) { var oObjAtual = document.getElementById(objeto + "_tab"); oObjAtual.style.display = "block"; } function sumirCalendario(objeto) { var oObjDiv = window.document.getElementById(objeto + "_tab"); oObjDiv.style.display = "none"; } function sumirData(objeto) { var oObj = window.document.getElementById(objeto); oObj.value = ""; sumirCalendario(objeto); } function iniciar(objeto) { exibirCalendario(objeto); var oData; var sData; if(window.document.getElementById(objeto + "_hid").value == "") { oData = new Date(); sData = oData.getDate() + "/" + (oData.getMonth() + 1) + "/" + oData.getFullYear(); } else { sData = window.document.getElementById(objeto + "_hid").value; } var aData = sData.split("/"); oData = new Date(); oData.setFullYear(aData[2]); oData.setMonth(aData[1] - 1); oData.setDate(aData[0]); window.document.getElementById(objeto + "_ddlMes").value = oData.getMonth(); window.document.getElementById(objeto + "_txtAno").value = oData.getFullYear(); window.document.getElementById(objeto + "_hid").value = oData.getDate() + "/" + (oData.getMonth() + 1) + "/" + oData.getFullYear(); estruturarCalendario(objeto, sData); } function estruturarCalendario(objeto, data) { //Estabelece as datas inicial e final. var aData = data.split("/"); var dDate = new Date(parseInt(aData[2]), parseInt(aData[1] - 1), parseInt(aData[0]), 0, 0, 0, 0); var aDataSel = data.split("/"); var dDateSel = new Date(parseInt(aDataSel[2]), parseInt(aDataSel[1] - 1), parseInt(aDataSel[0]), 0, 0, 0, 0); dDateSel.setHours(01,00,00,00); var dDataInicio = new Date(dDate.getFullYear(), dDate.getMonth(), 1, 0, 0, 0, 0); dDataInicio.setHours(01,00,00,00); var dDataFim = new Date(dDate.getFullYear(), dDate.getMonth(), 1, 0, 0, 0, 0); dDataFim.setHours(01,00,00,00); var iContador = 0; var oTable, oTr, oTd; oTable = document.createElement("table"); dDataFim.setMonth(dDataFim.getMonth() + 1); dDataFim.setDate(dDataFim.getDate() - 1); while(dDataInicio.getDay() != 0) dDataInicio.setDate(dDataInicio.getDate() - 1); while(dDataFim.getDay() != 6) dDataFim.setDate(dDataFim.getDate() + 1); montarCabecalho(oTable); while(dDataInicio <= dDataFim) { if(iContador % 7 == 0) { oTr = document.createElement("tr"); oTable.appendChild(oTr); } oTd = document.createElement("td"); oTd.align = "center"; if(dDataInicio.getDay() == 0 || dDataInicio.getDay() == 6) oTd.bgColor = "#E4E4E4"; if(dDateSel.toString() == dDataInicio.toString()) oTd.bgColor = "#B4B4B4"; oTd.style.cursor = "pointer"; oTd.setAttribute("onclick", "selecionarData('" + objeto + "'," + dDataInicio.getDate() + ", " + (dDataInicio.getMonth() + 1) + ", " + dDataInicio.getFullYear() + ")"); oTd.innerHTML = dDataInicio.getDate(); oTr.appendChild(oTd); dDataInicio.setDate(dDataInicio.getDate() + 1); iContador ++; } window.document.getElementById(objeto + "_cln").innerHTML = "" + oTable.innerHTML + "
"; } function montarCabecalho(tabela) { var arrDiaSemana = new Array("dom", "seg", "ter", "qua", "qui", "sex", "sab"); var oTr = document.createElement("tr"); var oTd; tabela.appendChild(oTr); for(i = 0; i < arrDiaSemana.length; i++) { oTd = document.createElement("td"); oTd.align = "center"; oTd.innerHTML = "" + arrDiaSemana[i] + ""; oTr.appendChild(oTd); } } function mudarData(objeto) { var minhaData = window.document.getElementById(objeto + "_hid").value; var aData = minhaData.split("/"); var oData = new Date(parseInt(aData[2]), parseInt(aData[1] - 1), parseInt(aData[0]), 0, 0, 0, 0); var sData; oData.setMonth(parseInt(window.document.getElementById(objeto + "_ddlMes").value)); oData.setFullYear(parseInt(window.document.getElementById(objeto + "_txtAno").value)); sData = oData.getDate() + "/" + (oData.getMonth() + 1) + "/" + oData.getFullYear(); estruturarCalendario(objeto, sData); } function avancarData(objeto) { var minhaData = window.document.getElementById(objeto + "_hid").value; var aData = minhaData.split("/"); var oData = new Date(parseInt(aData[2]), parseInt(aData[1] - 1), parseInt(aData[0]), 0, 0, 0, 0); var sData; oData.setMonth(parseInt(window.document.getElementById(objeto + "_ddlMes").value) + 1); if(oData.getMonth() == 0) oData.setFullYear(parseInt(window.document.getElementById(objeto + "_txtAno").value) + 1); else oData.setFullYear(parseInt(window.document.getElementById(objeto + "_txtAno").value)); window.document.getElementById(objeto + "_ddlMes").value = oData.getMonth(); window.document.getElementById(objeto + "_txtAno").value = oData.getFullYear(); sData = oData.getDate() + "/" + (oData.getMonth() + 1) + "/" + oData.getFullYear(); estruturarCalendario(objeto, sData); } function recuarData(objeto) { var minhaData = window.document.getElementById(objeto + "_hid").value; var aData = minhaData.split("/"); var oData = new Date(parseInt(aData[2]), parseInt(aData[1] - 1), parseInt(aData[0]), 0, 0, 0, 0); var sData; oData.setMonth(parseInt(window.document.getElementById(objeto + "_ddlMes").value) - 1); if(oData.getMonth() == 11) oData.setFullYear(parseInt(window.document.getElementById(objeto + "_txtAno").value) - 1); else oData.setFullYear(parseInt(window.document.getElementById(objeto + "_txtAno").value)); window.document.getElementById(objeto + "_ddlMes").value = oData.getMonth(); window.document.getElementById(objeto + "_txtAno").value = oData.getFullYear(); sData = oData.getDate() + "/" + (oData.getMonth() + 1) + "/" + oData.getFullYear(); estruturarCalendario(objeto, sData); } function selecionarData(objeto, dia, mes, ano) { var minhaData = dia + "/" + mes + "/" + ano; estruturarCalendario(objeto, minhaData); var dData = new Date(parseInt(ano), parseInt(mes) - 1, parseInt(dia), 0, 0, 0, 0); window.document.getElementById(objeto + "_ddlMes").value = dData.getMonth(); window.document.getElementById(objeto + "_txtAno").value = dData.getFullYear(); window.document.getElementById(objeto).value = minhaData; window.document.getElementById(objeto + "_hid").value = minhaData; }