var xmlreqs = new Array(); var xmlreqCount = 0; var ajaxWaitingElement; var ajaxWaitType = 'prefix'; function ajax_do (element, functie, params, object, waitingAnimation, doUrchinTracker) { if(waitingAnimation) { if(waitingAnimation == true) { startWaiting(element); } else { startWaiting(waitingAnimation, true); } } else { startWaiting(); } var query = 'object=' + object + '&element=' + element + '&functie=' + functie + '&' + params; var url = "/_BWF/ajax/ajax.php"; doXmlHttpRequest(url, query, doUrchinTracker, element); } function ajax_do_ssl (element, functie, params, object, waitingAnimation, doUrchinTracker) { if(waitingAnimation) { if(waitingAnimation == true) { startWaiting(element); } else { startWaiting(waitingAnimation, true); } } else { startWaiting(); } var query = 'object=' + object + '&element=' + element + '&functie=' + functie + '&' + params; var url = "/_BWF/ajax/ajax.php"; doXmlHttpRequest(url, query, doUrchinTracker, element); } /* Do an actual ajax request (used by ajax_do) functions manages an array of xmlHtpp objects, which is needed when multiple ajax requests overlap the xmlHtpp objects in array are recycled after they have returned their ajax data (so size of array will be max simultanious ajax calls since page refresh) */ function doXmlHttpRequest(url, query, doUrchinTracker, element) { var pos = -1; for (var i=0; i<xmlreqs.length; i++) { if (xmlreqs[i].freed == 1) { pos = i; break; } } if (pos == -1) { pos = xmlreqs.length; xmlreqs[pos] = new createXMLHttpRequest(1); } if (xmlreqs[pos].xmlhttp) { xmlreqs[pos].freed = 0; if(doUrchinTracker) { xmlreqs[pos].doUrchinTracker = true; } else { delete xmlreqs[pos].doUrchinTracker; } if(element) { xmlreqs[pos].element = element; } xmlreqs[pos].xmlhttp.open("POST", url, true); xmlreqs[pos].xmlhttp.onreadystatechange = function() {handleStateChange(pos)}; xmlreqs[pos].xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlreqs[pos].xmlhttp.send(query); xmlreqCount++; } } /* create an ajax data socket dependent on browser (used by doXmlHttpRequest) */ function createXMLHttpRequest(freed) { this.freed = freed; this.xmlhttp = false; try{ /* Opera 8.0+, Firefox, Safari */ this.xmlhttp = new XMLHttpRequest(); } catch (e){ /* Internet Explorer Browsers */ try{ this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ /* Ajax is not supported */ alert("Your browser does not support Ajax"); return false; } } } } /* this function is called when the ajax call returns */ function handleStateChange(pos) { if(xmlreqs[pos].freed == 0 && xmlreqs[pos].xmlhttp.readyState == 4 && xmlreqs[pos].xmlhttp.status == 200) { finishWaiting(); eval(xmlreqs[pos].xmlhttp.responseText); if(xmlreqs[pos].doUrchinTracker) { var tracker = location.pathname+location.search+"_ajax" + (location.hash).replace(/\//g,'_').replace(/#/,'_'); tracker = tracker; _gaq.push(['_trackPageview', tracker]); } xmlreqs[pos].freed = 1; if(xmlreqs[pos].element) { var div = document.getElementById(xmlreqs[pos].element); var x = div.getElementsByTagName("script"); for(var i=0;i<x.length;i++) { eval(x[i].text); } } } } function startWaiting(waitingElement, waitingElementSeperate){ document.body.className = 'waitAjax'; if(waitingElement) { var innerHTMLResult = "<p style='text-align: center;'><br/><img src='../_BWF/images/loadingAnimation.gif' alt='loading'></p>"; if(ajaxWaitType == "prefix") { innerHTMLResult += "<br/><br/>" + document.getElementById(waitingElement).innerHTML; } document.getElementById(waitingElement).innerHTML = innerHTMLResult; } if(waitingElementSeperate) { ajaxWaitingElement = waitingElement; } } function finishWaiting(){ document.body.className = 'readyAjax'; if(ajaxWaitingElement && ajaxWaitingElement != '') { document.getElementById(ajaxWaitingElement).innerHTML = ""; ajaxWaitingElement = null; } } /* will parse part after hash in URL. no input required (for ajax deeplink/bookmark support) */ function parseHashURL() { return processHashString(); } /* will parse a string (assumed to be part after hash of a URL) and execute the command (e.g. for ajax back button and deeplink/bookmark support). */ function processHashString(string) { var data = explodeHashString(string); if(data) { doHashString(data); return true; } return false; } /* will parse a string and return an array with keys as variablenames and values as values (.e.g. URL with #/x/1/y/2 will return as array(x => 1, y => 2). * in case no string is passed as parameter, it will take it from the URL behind the # */ function explodeHashString(string) { if(!string) { string = location.hash.slice(1); } if(string && string != '') { var data = []; var stringArray = string.split('/'); for(var i=1;i < stringArray.length;i=i+2) { var key = stringArray[i]; var value = stringArray[i+1]; data[key] = value; } return data; } return false; } /* based on input a string is added after the current URL with hash */ function addHistoryEntry(p1, p2, p3, p4) { if(window.dhtmlHistory) { var string = '/'+encodeURIComponent(decodeURIComponent(p1)); if(p2) { string = string + '/'+encodeURIComponent(decodeURIComponent(p2)); } if(p3) { string = string + '/'+encodeURIComponent(decodeURIComponent(p3)); } if(p4) { string = string + '/'+encodeURIComponent(decodeURIComponent(p4)); } dhtmlHistory.add(string); } } /* only if RSH is included window.dhtmlHistory exists */ if(window.dhtmlHistory) { /* what will be defined here is what is executed in case back button is pressed, string will be the string defined in addHistoryEntry (that what is behind hash in URL) */ var rshListener = function(string, historyData) { processHashString(string); }; window.dhtmlHistory.create({ toJSON: function(o) { return $.toJSON(o); }, fromJSON: function(s) { return $.evalJSON(s); } }); window.onload = function(){ window.dhtmlHistory.initialize(); window.dhtmlHistory.addListener(rshListener); }; }
