function initReq() { // queue init if (document.getElementsByName('queueform').length) { tableRows = document.getElementsByTagName('tr'); for (rowNr = 0; rowNr < tableRows.length; rowNr++) { // let's make sure there isn't another nested table if (!tableRows[rowNr].getElementsByTagName('table').length) { // if row has a special tag then make whole row clickable if (tableRows[rowNr].id == "row_link") { // nothing ?! } else { // find cells tableCells = tableRows[rowNr].getElementsByTagName('td'); for (cellNr = 0; cellNr < tableCells.length; cellNr++) { // find anchors anchors = tableCells[cellNr].getElementsByTagName('a'); if (anchors.length == 1) { if (anchors[0].href) { // tableCells[cellNr].class = "td_value"; // tableCells[cellNr].onclick = function () { document.location = anchors[0].href }; } } } } } } } // ------------------------- // textarea hooks // ------------------------- textareas = document.getElementsByTagName('textarea'); for (taNr = 0; taNr < textareas.length; taNr++) { if (textareas[taNr].id) { if (textareas[taNr].scrollHeight > textareas[taNr].offsetHeight) ptrHeightRaise = setTimeout('_heightRaise(\'' + textareas[taNr].id + '\', 0)', 100); textareas[taNr].onfocus = function() { startHeightMonitor(this.id); } textareas[taNr].onblur = function() { stopHeightMonitor=1; } } } // ------------------------- // init input field hooks // ------------------------- tableCells = document.getElementsByClassName('td_value'); for (cellNr = 0; cellNr < tableCells.length; cellNr++) { myDivs = tableCells[cellNr].getElementsByTagName('div'); if (myDivs.length == 2 && myDivs[1].getElementsByTagName('input')) { myInput = myDivs[1].getElementsByTagName('input'); } else if (myDivs.length) { myInput = myDivs[0].getElementsByTagName('input'); } if (myDivs.length == 2 && myInput && myInput.length == 1) { if (myInput[0].type == 'checkbox') { if (myInput[0].checked) tableCells[cellNr].className = 'td_value_highlight'; tableCells[cellNr].onclick = function() { if (this.className == 'td_value') { this.className = 'td_value_highlight'; } else { this.className = 'td_value'; } myCheckbox = this.getElementsByTagName('input'); toggle_checkbox(myCheckbox[0]); // Enabled/disabled by content checking myDivs = this.getElementsByTagName('div'); if (myDivs[0].innerHTML == 'Enabled') { myDivs[0].innerHTML = 'Disabled'; } else if (myDivs[0].innerHTML == 'Disabled') { myDivs[0].innerHTML = 'Enabled'; } }; } else if (myInput[0].type == 'text') { tableCells[cellNr].onmouseover = function() { this.getElementsByTagName('input')[0].focus(); } tableCells[cellNr].onmouseout = function() { this.getElementsByTagName('input')[0].blur(); } } else if (myInput[0].type == 'select') { myInput[0].className = 'td_value_no_hover'; } } } // ------------------------- // init tabbed pages // ------------------------- // find tabSets tabSets = document.getElementsByClassName('tabs'); for (tabSetNr = 0; tabSetNr < tabSets.length; tabSetNr++) { myTabs = tabSets[tabSetNr].getElementsByTagName('TD'); for (tabNr = 0; tabNr < myTabs.length; tabNr++) { // divide space equally myTabs[tabNr].style.width = Math.round(100 / myTabs.length); // add hook if (myTabs[tabNr].className != 'disabled' && myTabs[tabNr].className != 'tab_blank') { myTabs[tabNr].onclick = function() { this.className = 'selected'; // reset tabs myTabs = this.parentNode.getElementsByTagName('TD'); for (tabNr = 0; tabNr < myTabs.length; tabNr++) { myTabs[tabNr].style.width = Math.round(100 / myTabs.length); if (myTabs[tabNr].className == 'selected') { myTabs[tabNr].className = 'tab_selected'; $(myTabs[tabNr].innerHTML).style.display = ''; } else if (myTabs[tabNr].className == 'tab_blank'){ // do nothing } else if (myTabs[tabNr].className == 'td_value_disabled') { myTabs[tabNr].className = 'tab_disabled'; $(myTabs[tabNr].innerHTML).style.display = 'none'; } else { myTabs[tabNr].className = 'tab'; $(myTabs[tabNr].innerHTML).style.display = 'none'; } } } } // reset class if (myTabs[tabNr].className == 'disabled' && document.getElementById(myTabs[tabNr].innerHTML)) { document.getElementById(myTabs[tabNr].innerHTML).style.display = 'none'; myTabs[tabNr].className = 'tab_disabled'; } else if (myTabs[tabNr].className != 'selected' && document.getElementById(myTabs[tabNr].innerHTML)) { document.getElementById(myTabs[tabNr].innerHTML).style.display = 'none'; myTabs[tabNr].className = 'tab'; } else if (document.getElementById(myTabs[tabNr].innerHTML)) { document.getElementById(myTabs[tabNr].innerHTML).style.display = ''; myTabs[tabNr].className = 'tab_selected'; } } } initSelectors(); } function initSelectors() { // ------------------------- // init selectors // ------------------------- // find tabSets selectors = document.getElementsByClassName('draft_selector'); for (selectorNr = 0; selectorNr < selectors.length; selectorNr++) { // selectors[selectorNr].id = "selector_" + selectorNr; fillHtmlObject('https://c-req.linxtelecom.com/Plugins/drafts/selector/' + selectors[selectorNr].id, 'https://c-req.linxtelecom.com/Plugins/drafts/Templates/selector.xsl', selectors[selectorNr].id); } // alert(result); } var iframeEnabled = 0; function adjustIframeSize() { // shamelessly copied from http://www.diplok.com/1ppl/html/article093.html // Must launched on the body onload event handler for IE // Use document.documentElement if you are in Compat mode myIframe = parent.document.getElementById(window.name); myIframeHeight = document.body.scrollHeight; myIframe.style.height = myIframeHeight + 5 + "px"; myIframe.style.width = document.body.scrollWidth + "px"; // since first time it runs from OnLoad when enabled // we can assign variable here iframeEnabled = 1; } function open_miniwindow(SITE, DOMAIN, FORMNAME, FORMELEMENT) { document.domain=DOMAIN; xclient = eval("document." + FORMNAME + "." + FORMELEMENT); if (xclient.value) { SITE = SITE + "pattern=" + xclient.value + "&response=" + DOMAIN + "," + FORMNAME + "." + FORMELEMENT; } else { SITE = SITE + "response=" + DOMAIN + "," + FORMNAME + "." + FORMELEMENT; } window2=open( SITE ,'SLAVE', 'toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,status=no,resizable=yes,width=700,height=550'); } function goto_ticket (ticket_id) { if (ticket_id[0] == '#') ticket_id = ticket_id.substring(1, ticket_id.length); if (!isNaN(ticket_id)) document.location='?' + ticket_id; } function check (object_id) { object_id.checked = true; } function validate_input_data() { // alert(document.COMMENT_FORM.MAIL_body); return true; } function toggle_checkbox(object_id) { if (typeof(object_id) != 'object') { object = document.getElementById(object_id); } else { object = object_id; } if (object.checked) { object.checked = 0; } else { object.checked = 1; } } function toggle_class(object_id, class_a, class_b) { object = document.getElementById(object_id); if (object.className == class_a) { object.className = class_b; } else { object.className = class_a; } } function toggle_img_src(object_id, img_a, img_b) { object = document.getElementById(object_id); if (object.src.match(img_a)) { object.src = img_b; } else { object.src = img_a; } } /*** DIV visibility routines ***/ var visibility = ''; function toggle_visibility_all (pic_a, pic_b) { var all_kids = document.getElementsByTagName('DIV'); var counter = 0; for (var i=0; i < all_kids.length; i++) { if (all_kids[i].className.substring(0,4) == 'mail') { counter++; if (counter == 1) continue; if (counter == 2) visibility = all_kids[i].style.visibility // alert(all_kids[i].style.visibility); toggle_visibility(all_kids[i].className, all_kids[i].id, 'mail_expand_' + all_kids[i].className.substring(5,12), pic_a, pic_b, visibility); } } } function toggle_visibility (object_class, object_id, pic_id, pic_a, pic_b, visibility) { kids = document.getElementsByTagName('DIV'); for (var i=0; i < kids.length; i++) { if (kids[i].className == object_class) { if (object_id && kids[i].id == object_id) { _toggle_object_visibility(kids[i], pic_id, pic_a, pic_b, visibility); } else if (!object_id && !kids[i].id) { _toggle_object_visibility(kids[i], pic_id, pic_a, pic_b, visibility); _hide_children_behind_parent(object_class, kids[i].style.visibility, kids[i].style.position); } } } } function _toggle_object_visibility (object, pic_id, pic_a, pic_b, visibility) { if (visibility == 'visible') object.style.visibility = 'visible'; else if (visibility == 'hidden') object.style.visibility = 'hidden'; if (object.style.visibility == 'hidden') { object.style.visibility = 'visible'; object.style.display = ''; object.style.position = 'relative'; document.getElementById(pic_id).src = pic_b; } else { object.style.visibility = 'hidden'; object.style.display = 'none'; object.style.position = 'fixed'; document.getElementById(pic_id).src = pic_a; } if (iframeEnabled) adjustIframeSize(); } function _hide_children_behind_parent (object_class, visibility, position) { if (visibility == "visible") return; kids = document.getElementsByTagName('DIV'); for (var i=0; i < kids.length; i++) { if (kids[i].className == object_class) { if (kids[i].id) { kids[i].style.visibility = visibility; kids[i].style.position = position; } } } } /*** onmouseover/out tr painting ***/ function toggle_bgcolor (el_id, color) { table_row = document.getElementById(el_id); if (!table_row) return; if (color) { table_row.style.old_toggled_backgroundColor = table_row.style.backgroundColor; table_row.style.backgroundColor = color; } else { table_row.style.backgroundColor = table_row.style.old_toggled_backgroundColor; } } function reset_select_box(el_id) { var i, j; var obj = document.getElementById(el_id); for (i = obj.length; i > 0; i--) { obj.options[i-1].selected = 0; } obj.options[0].selected = 1; return true; } /*** some fancy flashing ***/ var old_bg = ''; var flash_max_count = 5; function flash_bg(obj_id) { flash_count = 0; old_bg = document.getElementById(obj_id).style.background; flash_check = setTimeout('_flash_start(\'' + obj_id + '\', ' + flash_count + ')', 0); } function _flash_start(obj_id, flash_count) { document.getElementById(obj_id).style.background = 'red'; flash_check = setTimeout('_flash_end(\'' + obj_id + '\', ' + flash_count + ')', 500); } function _flash_end(obj_id, flash_count) { document.getElementById(obj_id).style.background = old_bg; flash_count++; if (flash_count < flash_max_count) flash_check = setTimeout('_flash_start(\'' + obj_id + '\', ' + flash_count + ')', 500); } /*** ***/ var stopHeightMonitor = 0; function startHeightMonitor(obj_id) { stopHeightMonitor = 0; ptrHeightMonitor = setTimeout('_heightMonitor(\'' + obj_id + '\')', 500); } function _heightMonitor(obj_id) { if (!stopHeightMonitor) { if ($(obj_id).scrollHeight > $(obj_id).offsetHeight) { ptrHeightRaise = setTimeout('_heightRaise(\'' + obj_id + '\', 0)', 100); } ptrHeightMonitor = setTimeout('_heightMonitor(\'' + obj_id + '\')', 100); } } function _heightRaise(obj_id, counter) { if (counter < 4) { $(obj_id).style.height = $(obj_id).scrollHeight + 4; ptrHeightRaise = setTimeout('_heightRaise(\'' + obj_id + '\', ' + ++counter + ')', 10); } } /*** validation helpers ***/ function check_for_object(obj_id) { if (!document.getElementById(obj_id)) { // alert('Element ' + obj_id + ' not found!'); return 0; } return 1; } function check_number(obj_id, message) { if (!check_for_object(obj_id)) return 1; if (!document.getElementById(obj_id).value || isNaN(document.getElementById(obj_id).value)) { flash_bg(obj_id); if (message) alert(message); else alert('Ootan numbrit!'); document.getElementById(obj_id).focus(); document.getElementById(obj_id).select(0, document.getElementById(obj_id).length); return 0; } return 1; } function check_positive_number(obj_id, message) { if (!check_for_object(obj_id)) return 1; if (!document.getElementById(obj_id).value || isNaN(document.getElementById(obj_id).value) || (document.getElementById(obj_id).value <= 0)) { if (message) alert(message); else alert('Ootan nullist suuremat numbrit!'); document.getElementById(obj_id).focus(); return 0; } return 1; } function check_string(obj_id, message) { if (!check_for_object(obj_id)) return 1; if (!document.getElementById(obj_id).value) { flash_bg(obj_id); if (message) alert(message); else alert('Ootan teksti!'); document.getElementById(obj_id).focus(); return 0; } return 1; } function check_for_change(obj_id, message) { if (!check_for_object(obj_id)) return 1; if (document.getElementById(obj_id).defaultValue == document.getElementById(obj_id).value) { flash_bg(obj_id); if (message) alert(message); else alert('No change!'); document.getElementById(obj_id).focus(); return 0; } return 1; } /*** form validation ***/ function validate_comment_form() { // wick answer = true; if (siw && siw.selectingSomething) answer = false; // end of wick if (!check_number('MAIL_client_id')) return false; if (!check_string('MAIL_subject', 'Subject missing!')) return false; // if (document.getElementById('MAIL_contenttype').value != 'text/html' // && !check_for_change('MAIL_body', 'Enter some text!')) return false; return true; } function validate_clientid_form() { if (!check_number('client_id')) return false; return true; } var http_request; // combined from: // http://www.captain.at/howto-ajax-permission-denied-xmlhttprequest.php // http://www.captain.at/howto-ajax-process-xml.php function createRequest(url, parameters, myResultParser, myDestination) { http_request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... // UniversalBrowserRead - needs the whole package to be signed, // can't be done with php scripts :( if (0 && netscape.security.PrivilegeManager.enablePrivilege) try { netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); } catch (e) { alert("Problems - '" + e + "'!"); return false; } http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); } } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { } } } if (!http_request) { alert('Cannot create XMLHTTP instance'); return false; } http_request.onreadystatechange = eval(myResultParser)(myDestination); try { http_request.open('GET', url + parameters, true); } catch (e) { alert ("Sry, problems - '" + e + "'!"); } try { http_request.send(null); } catch (e) {} } function alertContents(contentDestinationID) { if (http_request.readyState == 4) { if (http_request.status == 200) { alert(http_request.responseText); document.getElementById(contentDestinationID).innerHTML = http_request.responseText; } else { alert("Got status: " + http_request.status); } } } function pluginOpen(pluginName, param) { // plugin layer config // myPluginTopMargin = 20; myPluginLeftMargin = 20; pluginCloseWidth = 65; pluginCloseHeight = 20; myPluginZindex = 999; // find some setup values if (window.ActiveXObject) { // definitely MS IE :) myBrowserHeight = document.body.clientHeight; myBrowserWidth = document.body.clientWidth; } else { // hopefully mozilla myBrowserHeight = window.innerHeight; myBrowserWidth = window.innerWidth; } // plugin layer myPlugin = document.getElementById('pluginWindow'); myPlugin.style.left = myPluginLeftMargin; myPlugin.style.top = myPluginTopMargin; myPlugin.style.height = (myBrowserHeight - 2 * myPluginTopMargin); myPlugin.style.width = (myBrowserWidth - 3 * myPluginLeftMargin); myPlugin.style.visibility = 'visible'; myPlugin.style.zIndex = myPluginZindex; // small close button - should be independent myPluginClose = document.getElementById('pluginWindowClose'); myPluginClose.style.left = myBrowserWidth - (3 * myPluginLeftMargin) - pluginCloseWidth; myPluginClose.style.width = pluginCloseWidth; myPluginClose.style.height = pluginCloseHeight; // contents myContents = document.getElementById('pluginWindowContents'); myContents.src = "https://c-req.linxtelecom.com/Plugins/" + pluginName + "/" + param; myContents.style.height = myPlugin.style.height; myContents.style.width = myPlugin.style.width; _stopPluginWatcher = 0; pluginCheck = setTimeout('_pluginWatcher()', 500); return false; } function pluginClose() { myPlugin = document.getElementById('pluginWindow'); myContents = document.getElementById('pluginWindowContents'); myPlugin.style.visibility = 'hidden'; myContents.src = "about:blank"; _stopPluginWatcher = 1; } var _stopPluginWatcher = 1; function _pluginWatcher() { if (window.ActiveXObject) { // definitely MS IE :) myPluginResult = pluginWindowContents.document.getElementById('resultString'); } else { myContents = document.getElementById('pluginWindowContents'); myPluginResult = myContents.contentDocument.getElementById('resultString'); } if (myPluginResult && myPluginResult.innerHTML == 'Submit form.') { pluginClose(); commentFormSubmit(); } else if (myPluginResult && myPluginResult.innerHTML) { pluginClose(); eval(myPluginResult.innerHTML); } else if (!_stopPluginWatcher) { pluginCheck = setTimeout('_pluginWatcher()', 250); } } function commentFormSubmit() { if (validate_comment_form()) { document.COMMENT_FORM.submit(); } } /***************************************************************************************** * * Description: adds an extra field for attachments in comment section * Input: * Output: * Result: HTML element filled with extra file input field * ******************************************************************************************/ function addAttachmentField() { var myBr = document.createElement("br"); var myFileInputField = document.createElement("input"); var myFilesizeInputField= document.createElement("input"); myFileInputField.setAttribute("class", "MAIL_attach"); myFileInputField.setAttribute("id", "MAIL_attach_" + document.getElementsByClassName('MAIL_attach').length); myFileInputField.setAttribute("name", "MAIL_attach[]"); myFileInputField.setAttribute("type", "FILE"); myFilesizeInputField.setAttribute("name", "MAX_FILE_SIZE"); myFilesizeInputField.setAttribute("type", "HIDDEN"); myFilesizeInputField.setAttribute("value", "10000000"); var anchorInputField = document.getElementById("MAIL_attach_" + (document.getElementsByClassName('MAIL_attach').length - 1)); anchorInputField.parentNode.insertBefore(myFileInputField, anchorInputField.nextSibling); anchorInputField.parentNode.insertBefore(myFilesizeInputField, anchorInputField.nextSibling); anchorInputField.parentNode.insertBefore(myBr, anchorInputField.nextSibling); } /***************************************************************************************** * * Description: HTTPRequest for XML data from an URL * Input: string: URL string: parameters * Output: * Result: HTML element filled with data * ******************************************************************************************/ function getXML(xmlURL, parameters) { try { asyncMode.strlen; } catch (e) { asyncMode = 'true'; } var errFunc = function(t) { alert('Error ' + t.status + ' -- ' + t.statusText + "[xmlUrl:" + xmlURL + " ? " + parameters); } result = new Ajax.Request(xmlURL, {asynchronous:false, method:'get', postBody:parameters, onFailure: errFunc}); // FIXME: not sure if this is the correct way to extract results return result.transport.responseXML; } /***************************************************************************************** * * Description: HTTPRequest for Text data from an URL * Input: string: URL string: parameters * Output: * Result: HTML element filled with data * ******************************************************************************************/ function getText(textURL, parameters) { try { asyncMode.strlen; } catch (e) { asyncMode = 'true'; } var errFunc = function(t) { alert('Error ' + t.status + ' -- ' + t.statusText + "[textUrl:" + textURL + " ? " + parameters); } result = new Ajax.Request(textURL, {asynchronous:false, method:'get', postBody:parameters, onFailure: errFunc}); // FIXME: not sure if this is the correct way to extract results return result.transport.responseText; } /***************************************************************************************** * * http://wiki.script.aculo.us/scriptaculous/show/Ajax.Request * see http://wiki.script.aculo.us/scriptaculous/show/Ajax.Updater for Javascript evaluation and stright innerHTML fillings * Description: * Input: string: xml data URL * string: xsl template URL * string: destination element ID (must have innerHTML) * Output: * Result: HTML element filled with data * ******************************************************************************************/ function fillHtmlObject(xmlSrc, xslSrc, contentDestinationID, options) { // FIXME: is there any way to detect if we have undefined string? try { options['asyncMode'].strlen; } catch (e) { if (!options) options = { }; options['asyncMode'] = 'true'; } // success handler var handlerFunc = function(xml) { if (xslSrc) { // Houston, we have a template, let's apply it var xsl; if (typeof xslSrc == 'object') { // previously loaded template xsl = xslSrc; } else { // we have probably URL, lets try to load xsl = getXML(xslSrc); } // debug // alert("xmlSrc: " + xmlSrc + "\nxslSrc: " + xslSrc + "\nXML:" + xml.responseText); // if (xml.responseXML) { // xml filled by func:fillHtmlObject _applyStylesheet(xml.responseXML, xsl, $(contentDestinationID), options); } else { // previously loaded xml _applyStylesheet(xml, xsl, $(contentDestinationID), options); } } else { // no template - plain text input $(contentDestinationID).innerHTML = xml.responseText; } } var errFunc = function(t) { alert('Error ' + t.status + ' -- ' + t.statusText); } if (typeof xmlSrc == 'object') { handlerFunc(xmlSrc); } else { new Ajax.Request(xmlSrc, {asynchronous:options['asyncMode'], method:'get', postBody:options['xml'], onSuccess:handlerFunc, onFailure:errFunc}); } } /***************************************************************************************** * Adapted from: * http://www.soi.city.ac.uk/~sa386/epterm2/sqlxml/week9/The%20XSLT-JavaScript%20Interface%20In%20Gecko.htm * * Description: Applies XSLT stylesheet to XML data and inserts result into a HTML container * Input: XMLDocument: xml data * XMLDocument: xsl template * HTMLElement: destination element (must have innerHTML) * Output: * ******************************************************************************************/ function _applyStylesheet(xmlsrc, xslt, dst, options) { var xml; if (typeof dst != 'object') { alert("Destination doesn't exist!"); return false; } if (!xslt) { alert("Empty template?!"); return false; } if (typeof xmlsrc == 'object') { xml = xmlsrc; } else { xml = getXML(xmlsrc, options['xml']); } if (window.XSLTProcessor) { var xsltProcessor = new XSLTProcessor(); for (field in options['xsl']) { xsltProcessor.setParameter(null, field, options['xsl'][field]); } try { xsltProcessor.importStylesheet(xslt); } catch (e) { alert("Template error {"+xslt+"}!\n Error:\n---\n"+e+"\n---\n\n" + xsltProcessor); return false; } try { var xsltResult = xsltProcessor.transformToFragment(xml, document); } catch(e) { alert("Error applying template: " + e); return; } dst.innerHTML = ""; dst.appendChild(xsltResult); } else if (window.ActiveXObject) { var xsltIE = new ActiveXObject("Msxml2.XSLTemplate"); var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument"); xslDoc.load(xslt); xsltIE.stylesheet = xslDoc; var xmlDoc = new ActiveXObject("Msxml2.DOMDocument"); xmlDoc.load(xml); xslProcessor = xsltIE.createProcessor(); xslProcessor.input = xmlDoc; for (field in options['xsl']) { xslProcessor.addParameter(field, options['xsl'][field]); } xslProcessor.transform(); dst.innerHTML = xslProcessor.output; } }; /***************************************************************************************** * * Description: load
parameters into a string * Input: string: form ID * Output: string: element1=value1&element2=value2&elementX=valueX * ******************************************************************************************/ function fromGetParameters(formId) { var parameterString = ""; form = document.getElementById(formId); inputFields = form.getElementsByTagName('input'); selectFields = form.getElementsByTagName('select'); textareaFields = form.getElementsByTagName('textarea'); for (nr = 0; nr < inputFields.length; nr++) { parameterString += inputFields.item(nr).name + "=" + inputFields.item(nr).value + "&"; } for (nr = 0; nr < selectFields.length; nr++) { parameterString += selectFields.item(nr).name + "=" + selectFields.item(nr).value + "&"; } for (nr = 0; nr < textareaFields.length; nr++) { parameterString += textareaFields.item(nr).name + "=" + textareaFields.item(nr).value + "&"; } return parameterString; }; /***************************************************************************************** * * Description: general FORM submit * Input: string: form ID * function pointer: success handler function * Output: string: element1=value1&element2=value2&elementX=valueX * ******************************************************************************************/ Ajax.activeRequestCount_fixed = 0; // fixed: prototype.js BUG! var myGlobalHandlers = { onCreate: function(request, transport) { Ajax.activeRequestCount_fixed++; request.__start = true; $('submitbutton').disabled = 'true'; Element.show('systemBusy'); }, onComplete: function(request, transport) { if (request.__start) { Ajax.activeRequestCount_fixed--; request.__start = false; if (Ajax.activeRequestCount_fixed == 0) { $('submitbutton').disabled = ''; Element.hide('systemBusy'); } } }, onException: function(request, exception) { alert("Js Exception: " + exception); } }; Ajax.Responders.register(myGlobalHandlers); function _formSubmit(formId, postURL, handlerFunc, errFunc) { var parameters = fromGetParameters(formId); var myAjaxRequest = new Ajax.Request(postURL, {asynchronous:false, method:'post', postBody:parameters, onSuccess:handlerFunc, onFailure:errFunc}); } /***************************************************************************************** * * Description: submit function * Input: string: FORM Name string: xml data URL string: xsl data URL * Output: * Result: database update and refreshed data on the webpage * ******************************************************************************************/ function _prepareAndSubmit(srcFormName, dstURL, resultXsl, resultObjectID, parentSuccessHandler) { // prepare result handling var successHandler = function(t) { // FIXME: this needs some checks if ((t.responseText && t.responseXML.childNodes.item(0).childNodes.length) || (document.all && t.responseXML.childNodes.item(0).childNodes)) { // $('debug').innerHTML = "
POST:\n" + fromGetParameters(srcFormName) + "\nRESPONSE:\n" + t.responseText.replace(//g, '>') + "
"; // error|result handling parentSuccessHandler(t); } else if (t.responseText && t.responseText != "") { // for debugging purposes - if unknown output exists - show output $('debug').innerHTML = "debug: " + t.responseText; } else if (parentSuccessHandler) { // OBSOLETE! FIXME LATER $('debug').innerHTML = "
" + t.responseText.replace(//g, '>') + "
"; // execute handler we got from parent proccess parentSuccessHandler(t); } } var errorHandler = function(t) { alert('Submit error: ' + t.responseText + " ("+ dstURL +")"); } if (!srcFormName) { alert('Error: Form ID is not defined!'); return; } if (!dstURL) { alert('Error: Destination URL is not defined!'); return; } if (!resultXsl) { alert('Error: Result template is not defined!'); return; } if (!resultXsl) { alert('Error: Result destination object ID is not defined!'); return; } _formSubmit(srcFormName, dstURL, successHandler, errorHandler); } /***************************************************************************************** * * Description: submit function for uf Form * Input: integer: ticket ID * Output: * Result: database update and refreshed data on the webpage * ******************************************************************************************/ function postForm(formId, dstURL, resultObjectId) { var headerSuccess = function(t) { // selectedCache['xml'] = t.responseXML; if (resultObjectId) { // do nothing right now } else { alert("ERROR: No response!"); } } _prepareAndSubmit(formId, dstURL, 'NULL', resultObjectId, headerSuccess); } // ------------------------- // DEBUG fuctions // ------------------------- var MAX_DUMP_DEPTH = 1; function dumpObj(obj, name, indent, depth) { if (depth > MAX_DUMP_DEPTH) { return indent + name + ": \n"; } if (typeof obj == "object") { var child = null; var output = indent + name + "\n"; indent += "\t"; for (var item in obj) { try { child = obj[item]; } catch (e) { child = ""; } if (typeof child == "function") { } else if (typeof child == "object") { // output += dumpObj(child, item, indent, depth + 1); } else { output += indent + item + ": " + child + "\n"; } } return output; } else { return obj; } }