/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* Geral: */ function trim(str) { return str.replace(/^\s+|\s+$/g, ''); } function submit(form) { form.submit(); } function setIdAndSubmit(idElement, idValue, form) { idElement.value = idValue; form.submit(); } function setIdWithOptionAndSubmit(idElement, idValue, optionElement, optionValue, form) { idElement.value = idValue; optionElement.value = optionValue; form.submit(); } function setValueAndSubmit(element, value, form, menu1, menu2, menu3, quickFinderValue, event) { if (quickFinderValue == null) { if (menu1 != null) { menu1.style.display = 'none'; } if (menu2 != null) { menu2.style.display = 'none'; } if (menu3 != null) { menu3.style.display = 'none'; } element.value = value; form.submit(); } else { if (event.keyCode == '13') { var quickFinder = document.createElement('input'); quickFinder.type = 'hidden'; quickFinder.name = 'quick_finder_parameter'; quickFinder.value = quickFinderValue; form.appendChild(quickFinder); element.value = value; form.submit(); } } } function submitOnEnterUp(event, form) { if (event.keyCode == '13') { form.submit(); } } function confirmDeactivation(element, form, message) { var ok = confirm(message); if (ok) { element.value = 2; form.submit(); } } function confirmDestruction(element, form, message) { var ok = confirm(message); if (ok) { element.value = 3; form.submit(); } } function confirmCreationOfNote(component, form) { if (trim(component.value) != '') { var ok = confirm('Deseja realmente salvar o texto?'); if (ok) { form.submit(); } } else { alert('Favor informar o texto da nota.'); component.value = ''; component.focus(); } } /* Adição e remoção de linhas em formulários com opções de múltiplos valores: */ function setTextComponentValue(textComponent) { var hasInnerText = (document.getElementsByTagName("body")[0].innerText != undefined) ? true : false; if (!hasInnerText) { textComponent.textContent = textComponent.value.toUpperCase(); } else { textComponent.innerText = textComponent.value.toUpperCase(); } } function showDivComponent(divComponent, textComponent, value) { if (textComponent != null && value != 'OUTRO' || value == null) { divComponent.style.display = 'none'; } else { divComponent.style.display = 'block'; textComponent.value = ''; textComponent.focus(); } } function addRow(idTable, textComponent, value, name, extraValue) { var newValue = null; var textComponentOk = true; if (value != 'OUTRO') { newValue = value; } else { if (trim(textComponent.value) != '') { newValue = trim(textComponent.value); textComponent.value = ''; } else { alert('Favor informar o valor desejado.'); textComponentOk = false; } textComponent.value = ''; textComponent.focus(); } if (textComponentOk && newValue != null) { var hasInnerText = (document.getElementsByTagName("body")[0].innerText != undefined) ? true : false; newValue = (newValue + (extraValue != null ? " (" + extraValue + ")" : "")); var table = document.getElementById(idTable); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var element0 = document.createElement('input'); element0.type = 'hidden'; if (value != 'OUTRO') { element0.name = name; } else { element0.name = 'OUTRO_' + name; } element0.value = newValue; row.appendChild(element0); row.className = 'tr_background'; var cell0 = row.insertCell(0); var element1 = document.createElement("center"); var element2 = document.createElement("input"); element2.type = "checkbox"; element1.appendChild(element2); cell0.appendChild(element1); var cell1 = row.insertCell(1); var element3 = document.createElement("center"); cell1.appendChild(element3); if (!hasInnerText) { element3.textContent = '-'; } else { element3.innerText = '-'; } var cell2 = row.insertCell(2); if (!hasInnerText) { cell2.textContent = newValue.toUpperCase(); } else { cell2.innerText = newValue.toUpperCase(); } var cell3 = row.insertCell(3); if (value == 'OUTRO') { var element4 = document.createElement("div"); element4.style.width = '11px'; element4.style.height = '11px'; element4.style.left = '50%'; element4.style.marginLeft = '-5px'; element4.style.position = 'relative'; element4.style.backgroundImage = 'url(img/icones/prontuario/ok.png)'; cell3.appendChild(element4); } } } function deleteRow(table) { try { table = document.getElementById(table); var rowCount = table.rows.length; for (var i = 1; i < rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0].childNodes[0]; if (null != chkbox && true == chkbox.checked) { table.deleteRow(i); rowCount--; i--; } } } catch (e) { alert(e); } } function deleteRows(table) { table = document.getElementById(table); var rowCount = table.rows.length; for (var i = 1; i < rowCount; i++) { table.deleteRow(i); rowCount--; i--; } } function deleteRowsAndPrepareButtons(table, addButton, removeButton, disable) { addButton.disabled = disable; removeButton.disabled = disable; deleteRows(table); } /* Habilitação/desabilitação de campos com IDs similares: */ function setElementsEnabledByName(elementsByName, enable) { for (var i = 0; i < elementsByName.length; i++) { elementsByName[i].disabled = !enable; } } /* Exibição/inibição de campo de texto: */ function setTextFieldVisible(textField, visible) { visible ? textField.style.visibility = 'visible' : textField.style.visibility = 'hidden'; textField.getElementsByTagName('input')[0].value = ''; } /* Usuários: */ function showDivLogin(divLoginElement, divPasswordElement, salvarElement, loginElement, confirmLoginElement) { divLoginElement.style.display = 'inline'; loginElement.value = ''; confirmLoginElement.value = ''; if (divPasswordElement !== null) { divPasswordElement.style.display = 'none'; alert('Quando o novo e-mail (login) for salvo, uma nova senha será enviada para o mesmo. Sua conta será desconectada do sistema em seguida.'); } if (salvarElement !== null) { salvarElement.style.display = 'inline'; alert('Quando o novo e-mail (login) for salvo, uma nova senha será enviada para o mesmo.'); } } function hideDivLogin(divLoginElement, divPasswordElement, salvarElement, passwordElement, passwordElementValue, confirmPasswordElement) { divLoginElement.style.display = 'none'; if (divPasswordElement !== null) { divPasswordElement.style.display = 'inline'; passwordElement.value = passwordElementValue; confirmPasswordElement.value = ''; } if (salvarElement !== null) { salvarElement.style.display = 'none'; } } function confirmEmailDispatch(element, form) { var ok = confirm('Tem certeza que deseja reenviar uma nova senha para a conta em questão?'); if (ok) { element.value = 7; form.submit(); } } /* Pacientes: */ function mask(src, mask) { var i = src.value.length; var output = mask.substring(0, 1); var text = mask.substring(i) if (text.substring(0, 1) != output) { src.value += text.substring(0, 1); } } /* Exames: */ function sum(component, max, oneDecimalDigit) { var value; if (oneDecimalDigit == null) { value = parseFloat(component.value) + 1; } else { if (oneDecimalDigit == true) { value = parseFloat(component.value) + 0.1; value = value.toFixed(1); } else { value = parseFloat(component.value) + 0.01; value = value.toFixed(2); } } if (max != null) { if (value <= max) { component.value = value; } } else { component.value = value; } } function subtract(component, min, oneDecimalDigit) { var value; if (oneDecimalDigit == null) { value = parseFloat(component.value) - 1; } else { if (oneDecimalDigit == true) { value = parseFloat(component.value) - 0.1; value = value.toFixed(1); } else { value = parseFloat(component.value) - 0.01; value = value.toFixed(2); } } if (min != null) { if (value >= min) { component.value = value; } } else { component.value = value; } } function openPopup(page, element, value) { if (element != null) { element.value = value; } var w = 800; var h = 600; var sw = screen.width; var sh = screen.height; var l = sw / 2 - w / 2; var t = sh / 2 - h / 2; window.open('paginas/' + page + '.jsp', null, 'top=' + t + ', left=' + l + ', width=' + w + ', height=' + h + ', status=yes, toolbar=no, menubar=no, location=no, scrollbars=yes'); }