/*
Ajax url-loading object
request queue built on top of it
*/
/* namespacing object */
var x_ajaxurlloader=new Object();
x_ajaxurlloader.READY_STATE_UNINITIALIZED=0;
x_ajaxurlloader.READY_STATE_LOADING=1;
x_ajaxurlloader.READY_STATE_LOADED=2;
x_ajaxurlloader.READY_STATE_INTERACTIVE=3;
x_ajaxurlloader.READY_STATE_COMPLETE=4;
/*--- content loader object for cross-browser requests ---*/
x_ajaxurlloader.ContentLoader=function(url,onload,onerror,method,params,contentType){
this.req=null;
this.onload=onload;
this.onerror=(onerror) ? onerror : this.defaultError;
this.loadXMLDoc(url,method,params,contentType);
this.url = url;
}
x_ajaxurlloader.ContentLoader.prototype.loadXMLDoc=function(url,method,params,contentType){
if (!method){
method="GET";
}
if (!contentType && method=="POST"){
contentType='application/x-www-form-urlencoded';
}
if (window.XMLHttpRequest){
this.req=new XMLHttpRequest();
} else if (window.ActiveXObject){
this.req=new ActiveXObject("Microsoft.XMLHTTP");
}
if (this.req){
try{
var loader=this;
this.req.onreadystatechange=function(){
x_ajaxurlloader.ContentLoader.onReadyState.call(loader);
}
this.req.open(method,url,true);
if (contentType){
this.req.setRequestHeader('Content-Type', contentType);
}
this.req.send(params);
}catch (err){
this.onerror.call(this);
}
}
}
x_ajaxurlloader.ContentLoader.onReadyState=function()
{
var req=this.req;
var ready=req.readyState;
if(ready==x_ajaxurlloader.READY_STATE_LOADING)
{
document.body.style.cursor = "progress";
}
else
{
document.body.style.cursor = "auto";
}
if (ready==x_ajaxurlloader.READY_STATE_COMPLETE)
{
var httpStatus=req.status;
if (httpStatus==200 || httpStatus==0)
{
this.onload.call(this);
}
else
{
this.onerror.call(this);
}
}
}
x_ajaxurlloader.ContentLoader.prototype.defaultError=function(){
var error_msg = "";
error_msg = "X_AjaxUrlLoader Error: Data Fetch"
+"\n\n--------------------------------------------"
+"\n\nreadyState:"+this.req.readyState
+"\n\n--------------------------------------------"
+"\nstatus: "+this.req.status
+"\nurl: "+this.url
+"\n\n--------------------------------------------"
+"\nheaders: "+this.req.getAllResponseHeaders()
+"\n\n--------------------------------------------"
;
alert(error_msg);
}/* A_Ajax 2Mpact functions */
var _loading_popup = true;
function bepaal_loading_popup(loading_popup)
{
if(loading_popup == null)
{
_loading_popup = true;
}
else
{
_loading_popup = loading_popup;
}
}
//Function Prepares calls xmlHttpRequest
function makeHttpRequest_x_ajax(detail_link, postdata, loading_popup)
{
bepaal_loading_popup(loading_popup);
if(_loading_popup)
{
x_ajax_start_loading();
}
x_ajax_debug_link = detail_link;
//controle op &
var regEx_amp = /\&\;/gi;
detail_link = detail_link.replace(regEx_amp,"&");
//Make sure we set the server side page
if(detail_link==null)
{
alert('X_Ajax Error: no server side code ('+detail_link+')');
return false;
}
//create reg exp so we do not grabbed cached material
var regEx = /(\s|:)/gi;
var strDT = "ts=" + new Date().toString().replace(regEx,"");
//add our post data to strDT
if (typeof postdata != 'undefined')
{
strDT += "&"+postdata;
}
//Make the request to the server
var loader1 = new x_ajaxurlloader.ContentLoader(detail_link,finishRequest_x_ajax_html,null,"POST",strDT); //Make request
return 1;
}
//Function takes html document
function finishRequest_x_ajax_html()
{
//var bx = window.clearTimeout(timerUpdate);
var strDoc = this.req.responseText; //Grab HTML
var input_voor_arr = '';
var start_idx = 0;
var resp_aantal = 0;
var response_arr_multiple = new Array();
var response_arr = new Array();
var response_status = '';
var huidige_div_tab = '';
var response_result = '';
var response_extra = '';
if(strDoc.length > 0) {
response_arr_multiple = strDoc.split('|#|')
var response_status_multiple = response_arr_multiple[0];
if(response_status_multiple == 'MULTIPLE') {
start_idx = 1;
resp_aantal = response_arr_multiple.length - 1; // laatste steeds divider !!
}
else {
start_idx = 0;
resp_aantal = 1;
response_arr_multiple[start_idx] = strDoc;
}
//0 niet, want is eerste resultaat
for(var i= start_idx; i < resp_aantal; i ++) {
input_voor_arr = response_arr_multiple[i];
//alert(input_voor_arr);
response_arr = input_voor_arr.split('|@|')
response_status = response_arr[0];
huidige_div_tab = response_arr[1];
response_result = response_arr[2];
response_extra = response_arr[3];
switch(response_status)
{
case 'SHOW':
x_ajax_print(huidige_div_tab,response_result);
break;
case 'RELOAD':
x_ajax_print_with_reload(huidige_div_tab,response_result);
break;
case 'REDIRECT':
x_ajax_redirect(response_extra);
break;
case 'DISPLAY':
x_ajax_display(huidige_div_tab);
break;
case 'APPEND':
x_ajax_append(huidige_div_tab, response_result, response_extra);
break;
case 'EVAL':
x_ajax_eval(response_result);
break;
case 'DO_NOTHING':
break;
default:
if(x_ajax_debug == true)
{
window.open(x_ajax_debug_link,'xajaxdebug');
}
else
{
alert('X_Ajax Error: Problem with data.');
}
}
}
if(_loading_popup)
{
x_ajax_stop_loading();
_loading_popup = true;
}
}
else
{
alert('X_Ajax Error: No data found. 404 ('+huidige_div_tab+')');
}
}
//Function prints html
function x_ajax_print(huidige_div_tab, content)
{
document.getElementById(huidige_div_tab).innerHTML = content;
}
//Function prints html & reloads
function x_ajax_print_with_reload(huidige_div_tab,response_result)
{
document.location.reload(true);
}
//Function prints html & redirects
function x_ajax_redirect(redirect_location)
{
var regEx_amp = /\&\;/gi;
redirect_location = redirect_location.replace(regEx_amp,"&");
document.location.href = redirect_location;
}
//Function displays div
function x_ajax_display(huidige_div_tab)
{
document.getElementById(huidige_div_tab).style.display = 'block';
}
//Function appends div to div
function x_ajax_append(parent_div, content, child_div)
{
var mydiv = document.createElement("div");
mydiv.setAttribute("id",child_div);
mydiv.innerHTML = content;
document.getElementById(parent_div).appendChild(mydiv);
}
//Function evaluates a javascript expression, statement or sequence of statements
function x_ajax_eval(js_code)
{
eval(js_code);
}
/**
* Post a form to a given URL through an AJAX request.
*
* The function is typically called like this:
*
* but you can also specify the form through other mechanisms
* such as document.getElementById("myForm").
*
* Be aware that all input elements with a name will be
* present in the post, including all submit buttons.
*
* @param {HTMLFormElement} form The form to post
* @param {String} url The URL to post it to
* @param {Boolean} loading_popup Wil je een 'Bezig met laden'-venstertje zien?
*/
function x_ajax_post_form(form, url, loading_popup)
{
var postStr = "";
var element;
var elValue;
// check for presence of FCKeditors
var hasFCK = (typeof FCKeditorAPI != "undefined");
var editor;
for (var i = 0; i < form.elements.length; i++)
{
element = form.elements[i];
// only elements with a name and if of type radio or checkbox only when checked
if (element.name && ((element.type != "radio" && element.type != "checkbox") || element.checked))
{
// this will work for everything but FCKeditors
elValue = element.value;
// check for linked FCK instance and if one use its content
if (hasFCK && element.type == "hidden")
{
editor = FCKeditorAPI.GetInstance(element.id);
if (typeof editor != "undefined") elValue = editor.GetXHTML(true);
}
postStr += element.name+"="+encodeURIComponent(elValue)+"&";
}
}
// remove last &
postStr = postStr.slice(0, -1);
makeHttpRequest_x_ajax(url, postStr, loading_popup);
}
/**
* Post a div as if it were a form to a given URL through an AJAX request.
*
* The function is typically called like this if you work with a button and know
* at which level it is nested inside the div (in this case directly as a child):
*
* but you can also specify the div through other mechanisms such as
* document.getElementById("myDiv") and call the function from outside the div.
*
* Be aware that all input elements with a name will be present in the post,
* including all submit buttons.
*
* @param {Node} div The div containing the elements to post
* @param {String} url The URL to post it to
* @param {Boolean} loading_popup Wil je een 'Bezig met laden'-venstertje zien?
*/
function x_ajax_post_div(div, url, loading_popup)
{
var postStr = "";
var tagname;
var element;
var elValue;
// check for presence of FCKeditors
var hasFCK = (typeof FCKeditorAPI != "undefined");
var editor;
var elements = div.getElementsByTagName("*");
for (var i = 0; i < elements.length; i++)
{
element = elements[i];
tagname = element.tagName.toLowerCase();
// only elements that would normally be submitted with a form
if (tagname == "input" || tagname == "select" || tagname == "button" || tagname == "textarea")
{
// only elements with a name and if of type radio or checkbox only when checked
if (element.name && ((element.type != "radio" && element.type != "checkbox") || element.checked))
{
// this will work for everything but FCKeditors
elValue = element.value;
// check for linked FCK instance and if one use its content
if (hasFCK && element.type == "hidden")
{
editor = FCKeditorAPI.GetInstance(element.id);
if (typeof editor != "undefined") elValue = editor.GetXHTML(true);
}
postStr += element.name+"="+encodeURIComponent(elValue)+"&";
}
}
}
// remove last &
postStr = postStr.slice(0, -1);
makeHttpRequest_x_ajax(url, postStr, loading_popup);
}
/**
* Toont de 'loading'-popup
*/
function x_ajax_start_loading()
{
var ajax_loading_area = document.getElementById('ajax_loading_area');
if(ajax_loading_area != null)
{
var scrollY = document.documentElement.scrollTop;
if(!scrollY)scrollY = document.body.scrollTop;
if(!scrollY)scrollY = window.pageYOffset;
if(!scrollY)scrollY = 0;
ajax_loading_area.style.top = scrollY+200 + "px";
ajax_loading_area.className = '';
}
}
/**
* Verbergt de 'loading'-popup
*/
function x_ajax_stop_loading()
{
var ajax_loading_area = document.getElementById('ajax_loading_area');
if(ajax_loading_area != null)
{
ajax_loading_area.className = 'hidden';
}
}
var x_ajax_debug;
x_ajax_debug = true;
var locaties_opties_f_form = 'undefined';
var locaties_opties_idx_arr = new Array();
var locaties_opties_submission_throttle_THROTTLE_PERIOD_FIRST = 100;
var locaties_opties_submission_throttle_THROTTLE_PERIOD_LATER = 250;
var locaties_opties_submission_throttle_THROTTLE_PERIOD = locaties_opties_submission_throttle_THROTTLE_PERIOD_FIRST;
var locaties_opties_submission_throttle_latestServerQuery = 'undefined';
var locaties_opties_submission_throttle_throttle_started = 0;
var locaties_opties_submission_throttle_f_form = 'undefined';
var locaties_opties_submission_throttle_f_veld_postcode = 'undefined';
var locaties_opties_submission_throttle_test_value = 'undefined';
var locaties_opties_submission_throttle_upd_parameters = new Array();
var locaties_opties_submission_throttle_upd_parameters_start_param = new Array();
function locatieopties_handle_postcode(type_opzoeking, locatieopties_taal, extra_param, upd_parameters_arr, upd_idx_arr, f_form, f_veld_postcode) {
if(locaties_opties_submission_throttle_throttle_started == 0) {
locaties_opties_submission_throttle_throttle_started = 1;
locaties_opties_submission_throttle_THROTTLE_PERIOD = locaties_opties_submission_throttle_THROTTLE_PERIOD_FIRST;
locaties_opties_submission_throttle_f_form = f_form;
locaties_opties_submission_throttle_f_veld_postcode = f_veld_postcode;
locaties_opties_submission_throttle_upd_parameters_start_param = upd_parameters_arr;
locatieopties_handle_postcode_loop(type_opzoeking, locatieopties_taal, extra_param, upd_idx_arr);
}
else {
locaties_opties_submission_throttle_THROTTLE_PERIOD = locaties_opties_submission_throttle_THROTTLE_PERIOD_LATER;
}
}
function locatieopties_handle_postcode_loop(type_opzoeking, locatieopties_taal, extra_param, upd_idx_arr) {
locaties_opties_submission_throttle_test_value = locatieopties_handle_postcode_query(upd_idx_arr);
//herophalen --> query stelt deze opnieuw in !!
upd_parameters_arr = locaties_opties_submission_throttle_upd_parameters;
if (locaties_opties_submission_throttle_test_value != locaties_opties_submission_throttle_latestServerQuery) {
var vars = {
queryType: locaties_opties_submission_throttle_f_veld_postcode,
queryText: escape(locaties_opties_submission_throttle_test_value)
}
//effectieve uitvoering
locatieopties_handle(type_opzoeking, locatieopties_taal, extra_param, upd_parameters_arr, upd_idx_arr);
locaties_opties_submission_throttle_latestServerQuery = locaties_opties_submission_throttle_test_value;
}
setTimeout("locatieopties_handle_postcode_loop('"+type_opzoeking+"', '"+locatieopties_taal+"', '"+extra_param+"', '"+ upd_idx_arr+"')", locaties_opties_submission_throttle_THROTTLE_PERIOD);
}
function locatieopties_handle_postcode_query(upd_idx_arr) {
var result = '';
var update_aan_arr = upd_idx_arr.split(',');
update_aan_arr_len = update_aan_arr.length;
//HERINSTELLEN BESTAANDE VALUES
for(var i= 0; i < update_aan_arr_len; i++) {
upd_str = update_aan_arr[i];
if(locaties_opties_submission_throttle_f_form.elements[upd_str].value) {
locaties_opties_submission_throttle_upd_parameters[i] = locaties_opties_submission_throttle_f_form.elements[upd_str].value;
}
else {
locaties_opties_submission_throttle_upd_parameters[i] = '0';
}
}
if(locaties_opties_submission_throttle_f_form.elements[locaties_opties_submission_throttle_f_veld_postcode].value) {
result = locaties_opties_submission_throttle_f_form.elements[locaties_opties_submission_throttle_f_veld_postcode].value;
}
return result
}
function locatieopties_handle(type_opzoeking, locatieopties_taal, extra_param, upd_parameters_arr, upd_idx_arr, f_form) {
locaties_opties_f_form = f_form;
var idx_arr = new Array();
var update_aan_arr = upd_idx_arr.split(',');
update_aan_arr_len = update_aan_arr.length;
for(var i= 0; i < update_aan_arr_len; i++) {
upd_str = update_aan_arr[i];
idx_arr[i] = upd_str;
}
locaties_opties_idx_arr = idx_arr;
update_aan_arr_len = upd_parameters_arr.length;
var upd_arr = new Array();
for(var i= 0; i < update_aan_arr_len; i++) {
upd_str = upd_parameters_arr[i];
upd_arr[i] = idx_arr[i] + '=' + upd_str;
}
var upd_arr_string = '';
upd_arr_string = upd_arr.join('&');
var upd_parameters = '';
if(upd_arr_string.length > 0) {
upd_parameters = '&' + upd_arr_string;
}
var new_u = new_url + '&type_opzoeking=' + type_opzoeking + '&locatieopties_taal=' + locatieopties_taal + upd_parameters + extra_param;
makeHttpRequest_x_ajax(new_u);
}
function locatieopties_reset_values(f_form, upd_idx_arr) {
//values legen
//nieuwe request opstarten
if(locaties_opties_f_form && locaties_opties_idx_arr.length > 0) {
update_aan_arr_len = locaties_opties_idx_arr.length;
for(var i= 0; i < update_aan_arr_len; i++) {
upd_str = locaties_opties_idx_arr[i];
if(locaties_opties_f_form.elements[upd_str].value) {
locaties_opties_f_form.elements[upd_str].value = '';
}
}
}
else {
if(f_form) {
var update_aan_arr = upd_idx_arr.split(',');
update_aan_arr_len = update_aan_arr.length;
for(var i= 0; i < update_aan_arr_len; i++) {
upd_str = update_aan_arr[i];
if(f_form.elements[upd_str].value) {
f_form.elements[upd_str].value = '';
}
}
}
}
}