function sendAjaxRequest(submitButton, additionalMethod, messageDiv) { var ajaxUrl = submitButton.form.action; var queryString = getQueryString(submitButton.form); if (!messageDiv) { messageDiv = getMessageDiv(submitButton.form); } sendManualAjaxRequest(ajaxUrl, queryString, additionalMethod, messageDiv); return false; } function sendManualAjaxRequest(ajaxUrl, queryString, additionalMethod, messageDiv) { var sessionId = "4606F76DCF64345657731D1EDC6731AF"; if (ajaxUrl.indexOf(";jsessionid=") == -1) { ajaxUrl = ajaxUrl + ";jsessionid=" + sessionId; } try { var XMLHTTP = getAjaxRequestObject(ajaxUrl, "", true); if (XMLHTTP != null) { XMLHTTP.onreadystatechange = function alertAJAXResponse() { if (XMLHTTP.readyState == 4) { var response = XMLHTTP.responseText; if (response != null && response != "") { if (messageDiv != null) { messageDiv.innerHTML = response; } } if (additionalMethod) { additionalMethod = additionalMethod.replace(/\$message\$/,response); eval(additionalMethod); } } }; XMLHTTP.send(queryString); } } catch(e) { alert(e); } return false; } function getMessageDiv(form) { var messageDiv = null; for (var i = 0 ; i < form.childNodes.length ; i++) { var childNode = form.childNodes[i]; if (childNode.nodeName == "DIV" && childNode.getAttributeNode("title") && childNode.getAttributeNode("title").nodeValue == "messagediv") { messageDiv = childNode; break; } else if (childNode.childNodes && childNode.childNodes.length > 0) { messageDiv = getMessageDiv(childNode); if (messageDiv != null) { break; } } } return messageDiv; } function getQueryString(form) { var queryString = ""; for (var i = 0 ; i < form.elements.length ; i++) { var element = form.elements[i]; if (element.type) { if (element.type == "checkbox") { queryString = queryString + element.name + "=" + encodeURIComponent(element.checked) + "&"; } else if (element.type == "radio") { if (element.checked) { queryString = queryString + element.name + "=" + encodeURIComponent(element.value) + "&"; } } else { queryString = queryString + element.name + "=" + encodeURIComponent(element.value) + "&"; } } else { queryString = queryString + element.name + "=" + encodeURIComponent(element.value) + "&"; } } queryString = queryString + "×tamp=" + new Date().getTime(); return queryString; } function getAjaxRequestObjectTest(remoteFunction, successMessage, overwriteReadyState) { var XMLHTTP = null; if (window.XMLHttpRequest) { XMLHTTP = new XMLHttpRequest(); } else { if (window.ActiveXObject) { try { XMLHTTP = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } } if (XMLHTTP != null) { if (remoteFunction.indexOf("http://") == -1 && remoteFunction.indexOf("https://") == -1 && remoteFunction.indexOf(getContextPath()) == -1) { remoteFunction = getContextPath() + remoteFunction; } XMLHTTP.open("POST", remoteFunction); XMLHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); if (!overwriteReadyState) { XMLHTTP.onreadystatechange = function alertAJAXResponse() { if (XMLHTTP.readyState == 4 && successMessage) { alert(successMessage); } }; } } return XMLHTTP; }