  var activeTab = '';
// ---------Handle document clickEvents--------
  addEvent(document, 'click', checkClick);

  var contentClass = 'containercontentholder';
  var mainContentHolder = 'containerholder';

  function checkClick(e)
  {
    e?evt=e:evt=event;

    elem = evt.target?evt.target:evt.srcElement;
    var test = getSetting('trigger', elem);

    if (test && test == 'maxMin')
    {
      maxMin(elem,evt);
      return;
    }
  }

  // --------------------------------------------

  function projectPublished(projectUuid, collectionUuid, actionSuccess, actionFailed)
  {
    var callbackParams = new Array();
    callbackParams[0] = escape(actionSuccess);
    callbackParams[1] = escape(actionFailed);
    request_addUrl('remote/project_published.php?pu=' + projectUuid + '&collectionUuid=' + collectionUuid);
    request_retrieve('projectPublishedCallBack', callbackParams);
    //remoteRequest('remote/project_published.php', 'pu=' + projectUuid + '&collectionUuid=' + collectionUuid, 'projectPublishedCallBack(\'' + escape(actionSuccess) + '\', \'' + escape(actionFailed) + '\')', 'GET');
  }

  function projectPublishedCallBack(num, target, req_count, actionSuccess, actionFailed)
  {
    if (req_count != request_counter)
      return;
    if (xmlReqs[num].readyState != 4)
      return;

    if (xmlReqs[num].status != 200)
      return;

    var result = xmlReqs[num].responseText;
    var action = '';

    try
    {
      if (result == 1)
        action = unescape(actionSuccess);
      else
        action = unescape(actionFailed);

      eval(action);
    }
    catch (e)
    {
      // do nothing !!
    }
  }

  function loadCmsContent(cmsUrl, part, targetId, fromHistory)
  {
    if (targetId == null || targetId == '')
      var targetId = 'information_content'

    if (targetElem = document.getElementById(targetId))
    {
      targetElem.style.cursor = 'wait';
      var reqUrl = 'remote/loadCmsContent.php?url=' + cmsUrl + '&part=' + part;
      request_addUrl(reqUrl);
      request_retrieve('placeLoadedCmsContent', [targetId, cmsUrl, part, fromHistory]); // request_retrieve expects an array as second paramater

      if (!targetElem.backbuttonid)
      {
        targetElem.backbuttonid = findBackButton(targetId);

        var backButton = null;
        if (backButton = document.getElementById(targetElem.backbuttonid))
          backButton.setAttribute('targetid', targetId);
      }
    }
  }

  function placeLoadedCmsContent(num, target, req_count, targetId, cmsUrl, part, fromHistory)
  {
    if (req_count!= request_counter)
      return;

    if (xmlReqs[num].readyState != 4)
      return;

    if (xmlReqs[num].status != 200)
      return;

    var targetDiv = null;
    if (targetDiv = document.getElementById(targetId))
    {
      if (fromHistory == 'undefined' || fromHistory == undefined) // last one for IE
      {
        // create the history property if not pressent
        if (!targetDiv.history)
          targetDiv.history = new Array()

        // set previous page in history
        var newIndex = targetDiv.history.length;

        if (newIndex == 0) // first one so store the whole content (we don't know the url)
        {
          // no url and part so store the content !!
          targetDiv.history[newIndex] = targetDiv.innerHTML;
        }
        else // one of the following pages so, store only the url / part info
        {
          var contentData             = new Object;
          contentData.url             = targetDiv.currentUrl;
          contentData.part            = targetDiv.currentPart;
          targetDiv.history[newIndex] = contentData;
        }

        // prevent history to be bigger than 10 pages
        // remove oldest (first) entry when history bigger then 10 pages
        if (targetDiv.history.length > 10)
          targetDiv.history.shift();

        // store the new url and part in the div element
        targetDiv.currentUrl  = cmsUrl;
        targetDiv.currentPart = part;
      }

      // set the new content
      targetDiv.innerHTML    = xmlReqs[num].responseText;
      targetDiv.style.cursor = 'default';

      // show back button
      if (targetDiv.backbuttonid)
      {
        var backButton = null;
        if (backButton = document.getElementById(targetDiv.backbuttonid))
        {
          backButton.style.display = 'block';
          backButton.style.visibility = 'visible';
          backButton.setAttribute('targetid', targetId);
        }
      }
    }
  }

  function loadPrevContent(elem)
  {
    var targetId = '';

    if (typeof(elem) != "object")
      elem = document.getElementById(elem);

    if (elem && elem.getAttribute)
      targetId = elem.getAttribute('targetId');

    if (targetId != '')
    {
      if (targetDiv = document.getElementById(targetId))
      {
        // check if there is history
        if (targetDiv.history && targetDiv.history.length > 0)
        {
          var prevContent =  targetDiv.history.pop();

          if (typeof(prevContent) == "object") // url / part info
          {
            loadCmsContent(prevContent.url, prevContent.part, targetId, true)
          }
          else if (typeof(prevContent) == "string") // first page content
          {
            // first one
            targetDiv.innerHTML = prevContent;
          }

          // hide back button
          if (targetDiv.history.length == 0)
          {
            var backButton = null;
            if (backButton = document.getElementById(targetDiv.backbuttonid))
              backButton.style.display = 'none';

          }
        }
      }
    }
  }

  function findBackButton(targetId)
  {
    var targetDiv = null;

    if (targetDiv = document.getElementById(targetId))
    {
      var contentHolder        = targetDiv.parentNode;
      var footerholder         = getChildByClass(contentHolder, 'div', 'footerholder');
      var buttonholder         = getChildByClass(footerholder, 'div', 'buttonholder');
      var backbuttonholder     = getChildByClass(buttonholder, 'div', 'backButton');

      if (!backbuttonholder)
        var backbuttonholder   = createCmsBackButton(buttonholder);

      if (!backbuttonholder)
      {
        var backButtonLinkholder = getChildByClass(buttonholder, 'div', 'buttonstart');
        var backButtonLinks      = backbuttonholder.getElementsByTagName('a');
        var backButtonLink       = backButtonLinks[0];

        backButtonLink.setAttribute('targetid', targetId);
      }
    }

    return backbuttonholder.id;
  }

  function createCmsBackButton(buttonHolder)
  {
    // create the nodes
    var dateObj = new Date();
    var id = dateObj.valueOf();

    var bacButDiv = document.createElement('div');
    bacButDiv.setAttribute('style', 'display:block;');
    bacButDiv.setAttribute('style', 'visibility: hidden;');
    bacButDiv.setAttribute('id', id);

    var bacButStartDiv = document.createElement('div');

    var bacButLink = document.createElement('a');
    bacButLink.setAttribute('targetid', 'information_content');

    var bacButLinkText = document.createTextNode('Terug');

    var bacButCloserDiv = document.createElement('div');

    var bacButBut = document.createElement('input');
    bacButBut.setAttribute('type', 'submit');
    bacButBut.setAttribute('class', 'hidesubmitbutton');

    // link nodes togetter
    bacButLink.appendChild(bacButLinkText); // text in link
    bacButStartDiv.appendChild(bacButLink); // link in start div
    bacButDiv.appendChild(bacButStartDiv); // startdiv in holder
    bacButCloserDiv.appendChild(bacButBut); // button in closer div
    bacButDiv.appendChild(bacButCloserDiv); // closerdiv in holder

    // append the new button (holder) to the button holder
    buttonHolder.insertBefore(bacButDiv, buttonHolder.firstChild);

    // append styles to new nodes
    // when classes are set with setAttribute, they are not used in IE (7)
    addClass(bacButDiv, 'backButton');
    addClass(bacButStartDiv, 'buttonstart');
    addClass(bacButCloserDiv, 'buttoncloser');
    addClass(bacButBut, 'hidesubmitbutton');

    // add the action to the link
    bacButLink.href = 'javascript:loadPrevContent(\''+id+'\');';
    //bacButLink.onClick = 'loadPrevContent(this);';

    return bacButDiv;
  }

  function toggleFormElement(activeTab, holderDiv, activeId)
  {
    if (typeof(activeTab) == 'string')
      activeTab = document.getElementById(activeTab);

    if (typeof(activeTab) != 'object')
      return;

    if (holder = document.getElementById(holderDiv))
    {

      if (menu = document.getElementById('mainmenu'))
      {
        tabs = menu.getElementsByTagName('a');

        if (tabs.length > 0)
        {
          for (i = 0; i < tabs.length; i++)
          {
            if (tabs[i].className)
              tabs[i].className = 'itemNor';

          }

          activeTab.className = 'itemAct';
        }
      }

      var blocks = getElementsByClassName(holder, 'div', 'tab content');

      if (blocks.length > 0)
      {
        for (i = 0; i < blocks.length; i++)
        {
          blocks[i].style.display = ((blocks[i].id==activeId) ? 'block' : 'none');
        }
      }

      sizeLightBox();
    }
  }

  function toggleOrderMenu(activeItem,holderDiv)
  {
    if (holder = document.getElementById(holderDiv))
    {
      tabs = holder.getElementsByTagName('a');

      if (tabs.length>0)
      {
        for (i=0; i<tabs.length; i++)
        {
          removeClass(tabs[i], 'active');
        }

        addClass(activeItem, 'active');
      }
    }
  }

  function placeContent(url, divId, dynUrl, executeFunctions)
  {
    if (!dynUrl)
      dynUrl = null;

    request_init(divId, dynUrl, executeFunctions);
    request_addUrl(url);
    request_retrieve();
  }

  function changeDisplayPersistentElements(displayMode)
  {
    var persistentElements = new Array('object','select');

    for (var j = 0; j < persistentElements.length; j++)
    {
      if (objects = document.getElementsByTagName(persistentElements[j]))
      {
        for (var i=0; i<objects.length; i++)
        {
          objects[i].style.visibility = displayMode;
        }
      }
    }
  }

  function maxMin(elem,e)
  {
    var mainHolder = getParentByClass(elem, mainContentHolder);

    if (mainHolder)
      var holderToClose = getChildByClass(mainHolder,'div',contentClass);

    if (holderToClose)
    {
      var display = holderToClose.style.display;

      if (hasClass(elem, 'icon-expand-white') || hasClass(elem, 'icon-shrink-white'))
      {
        var open = 'icon-expand-white';
        var close = 'icon-shrink-white';
      }
      else
      {
        var open = 'icon-expand-black';
        var close = 'icon-shrink-black';
      }

      if (display == 'none')
      {
        holderToClose.style.display = 'block';
        removeClass(elem, open)
        addClass(elem, close)
      }
      else
      {
        holderToClose.style.display = 'none';
        removeClass(elem, close)
        addClass(elem, open)
      }
    }
  }

  function getCssStyle(elem,style)
  {
    if (elem.style && elem.style[style])
    {
      return elem.style[style];
    }
    else
    {
      if (elem.currentStyle && elem.currentStyle[style])
        return elem.currentStyle[style];
      else if (window.getComputedStyle && (value=window.getComputedStyle(elem,null)[style]))
        return value;

    }
    return false;
  }

  function changeDisplay(show, hide, delay)
  {
    if (delay && !isNaN(delay))
    {
      var timer = window.setTimeout("changeDisplay('"+ show +"', '"+ hide +"')", delay);
      return;
    }

    if (show != '')
    {
      var showDivs = show.split(',');

      for (var i = 0; i < showDivs.length; i++)
      {
        if (document.getElementById(showDivs[i]))
          document.getElementById(showDivs[i]).style.display = 'block';

      }
    }
    if (hide != '')
    {
      var hideDivs = hide.split(',');

      for (var i = 0; i < hideDivs.length; i++)
      {
        if (document.getElementById(hideDivs[i]))
          document.getElementById(hideDivs[i]).style.display = 'none';

      }
    }
  }

  function toggleDisplay(elem)
  {
    var display = ((getCssStyle(elem,'display')=='none') ? 'block' : 'none');
    elem.style.display = display;
  }


  /**
  * Function that opens cms content in a lightbox
  *
  * @param string url
  * @param string lightBoxType
  * @param string lightBoxColor
  * @return void
  */
  function openLightBoxUrl(url, lightBoxType, lightBoxColor)
  {
    if (!url)
      return false;

    url = 'content/blocks/static/text.php?url=' + url + '&dt=true&dst=true';

    openLightBox(url, lightBoxType, lightBoxColor);
  }

  /**
  * Function that opens a secured page in a lightbox
  *
  * @param string url
  * @param string lightBoxColor
  * @return void
  */
  function openSecuredLightBoxUrl(url, lightBoxColor)
  {
    if (!url)
      return false;

    url = 'security-lightbox.php?url=' + url + '&dt=true&dst=true';

    openLightBox(url, 'login', lightBoxColor);
  }

  /**
  * Function that opens the comparison calculator
  *
  * @param string lightBoxColor
  * @return void
  */
  function openComparisonCalculator(lightBoxColor)
  {
    var url = 'content/blocks/dynamic/comparison_calculator.php';

    openLightBox(url, 'medium', lightBoxColor, null, 'initCalculator()');
  }

  function redirectMyLivy()
  {
    window.top.location.href = 'mylivy.php';
  }

  function doAction(action, projectScenario, actionValues, openContainers, openLightbox)
  {
     postFrame = frames['form_frame'];

    if (openContainers != null)
     openContainers = '&oc=' + openContainers;

    if (openLightbox != null)
     openLightbox = '&olb=' + openLightbox;

    var url = '';
    var baseHref = window.top.document.getElementsByTagName('base');

    if (baseHref && baseHref[0] && baseHref[0].href)
      url = baseHref[0].href;

    if (postFrame != null)
       postFrame.location = url+'scripts/mylivy_actions.php?ac=' + action + '&ps=' + projectScenario + '&av=' + actionValues + openContainers + openLightbox;
  }

  function getFile(projectUuid, fileUuid, fileType, errorContainerId, storageType, collectionUuid)
  {
    postFrame = frames['form_frame'];

    if (postFrame != null)
      postFrame.location.href = 'includes/functions/getFile.php?pu='+projectUuid+'&fileUuid='+fileUuid+'&fileType='+fileType+'&errorContainerId='+errorContainerId+'&storage='+storageType+'&col_uuid='+collectionUuid;

  }

  // Built for the image slider download link
  function getMediaUuid(projectUuid)
  {
    var divs = document.getElementById('thumbs');
    divs = divs.getElementsByTagName('div');

    for (var i = 0; i < divs.length; i++)
    {
      if (divs[i].className=='item current')
      {
        mediaUuid = divs[i].getElementsByTagName('img')[0].id;
        return mediaUuid;
      }
    }

    return '';
  }

  function getSetting(attribute, elem)
  {
    var setting = '';

    if (elem &&  elem.getAttribute)
      setting = elem.getAttribute(attribute);

    if (setting == null)
      setting = '';

    return setting;
  }


  var checkMaxLength = function (e)
  {
    e?evt=e:evt=event;
    var objToCheck = evt.target?evt.target:evt.srcElement;
    var maxLength  = parseInt(objToCheck.getAttribute('maxLength'));
    var counterDiv = document.getElementById(objToCheck.counterID);
    newLinePreg  = new RegExp("\n", "g");
    nrOfNewlines = (objToCheck.value.match(newLinePreg)) ? objToCheck.value.match(newLinePreg).length : 0;

    if (objToCheck.value.length > maxLength - nrOfNewlines)
    {
      objToCheck.value = objToCheck.value.substr(0, maxLength - nrOfNewlines);
      return false;
    }

    totalLength = objToCheck.value.length + nrOfNewlines;
    counterDiv.innerHTML = '<div class="text_counter">'+ totalLength +'/'+maxLength+'</div>';
  }

  function initMaxLength(objToCheck, counterID)
  {
    var maxLength = parseInt(objToCheck.getAttribute('maxLength'));
    var counterDiv = document.getElementById(counterID);
    objToCheck.counterID = counterID;

    if (!objToCheck.init) // set extra events to check the length !!!
    {
      addEvent(objToCheck, 'keyup', checkMaxLength);
      addEvent(objToCheck, 'change', checkMaxLength);
      addEvent(objToCheck, 'blur', checkMaxLength);
      objToCheck.init = true;
    }

    newLinePreg  = new RegExp("\n", "g");
    nrOfNewlines = (objToCheck.value.match(newLinePreg)) ? objToCheck.value.match(newLinePreg).length : 0;
    totalLength  = objToCheck.value.length + nrOfNewlines;
    counterDiv.innerHTML = '<div class="text_counter">'+ totalLength +'/'+maxLength+'</div>';
  }

  function scrollToTop()
  {
    scroll(0,0);
  }

  function addLijstVanZakenItem(itemID,listID)
  {
    d = document.getElementById('tpl_' + itemID);

    if (d)
    {
      rowStr = d.value;
      setNode(listID, rowStr);

      if (document.getElementById(itemID))
      {
        var name = ucFirst(document.getElementById(itemID).value);

        if (name.length > 0)
        {
          if (isUsed(listID,name))
          {
            alert(sequenceError);
          }
          else
          {
            elem = document.createElement('div');
            str = sequenceRow[listID].replace(/\[name]/g,name);
            name = name.replace(/\./g,"|");
            str = str.replace(/\[attributeName]/g,name);
            str = str.replace(/\%num%/g,'row' + uniqueNum);
            uniqueNum = uniqueNum + 1;
            elem.innerHTML = str;
            document.getElementById(listID).appendChild(elem);
            setUsed(listID,name);
            document.getElementById(itemID).value = '';
          }
        }
        document.getElementById(itemID).focus();
      }
    }
  }

  function setInvalidOrMissingDataError(id)
  {
    setFormError(id,'Enkele gegevens ontbreken of zijn onjuist ingevuld.');
  }

  function setFormError(id,error)
  {
    if (elem = document.getElementById(id))
    {
      elem.innerHTML = error;
      var parent = getParentByClass(elem, 'form-error');

      if (parent)
        parent.style.display = 'block';

      scrollToTop();
    }
  }

  function reloadWindow()
  {
    window.document.location.href = window.document.location.href;
  }

  function loadImage(imageName,imageSrc)
  {
    if (!imageSrc)
      imageSrc = document.images[imageName].src;

    var now = new Date();
    if (document.images)
      document.images[imageName].src = imageSrc + '?' + now.getTime();

  }

  var result_projects = new Array();
  var result_total = 0;
  var result_page = 1;

  function clearSearchFormResultContainers()
  {
    if (elems = document.getElementById('search_result'))
    {
      elems = elems.childNodes;

      for (var i = 0; i < elems.length; i++)
      {
        if (elems[i].tagName == 'DIV')
          elems[i].innerHTML = '';

      }
    }
    else
    {
      show('debug', 'element with id=search_result not found !!!');
    }
  }

  function showSearchFilter()
  {
    document.getElementById('searchFormPlacePreview').value = 'false';
    document.getElementById('searchFormPreviewType').value = '';
    changeDisplay('search_filter', 'search_preview_holder');
  }

  function setSearchFormResultPage(pageId, previewType)
  {
    if (elem = document.getElementById('searchFormPageId'))
      elem.value = pageId;

    if (previewType != null)
    {
      document.getElementById('searchFormPlacePreview').value = 'true';
      document.getElementById('searchFormPreviewType').value = previewType;
    }
    else
    {
      document.getElementById('searchFormPlacePreview').value = 'false';
      document.getElementById('searchFormPreviewType').value = '';
    }

    if (validator.submit('searchObjects'))
    {
      document.forms['searchObjects'].submit();
      document.getElementById('search_opacity_layer').style.display = 'block';
    }
  }

  function setSearchFormOrderButtons(sourceElem)
  {
    if (elems = document.getElementById('sortbar'))
    {
      elems = elems.childNodes;

      for (var i = 0; i < elems.length; i++)
      {
        if (elems[i].tagName == 'A')
        {
          if (elems[i].id == 'selected' && (elems[i].innerHTML != sourceElem.innerHTML))
            elems[i].className = 'up-down';

          elems[i].id = '';
        }
      }
    }

    sourceElem.id = "selected";
  }

  function setSearchFormResultSortOrder(sortOrder, sourceElem)
  {
    switch (sourceElem.className)
    {
      case 'up-down':
        sourceElem.className = 'up';
        sortType = 'asc';
        break;
      case 'up':
        sourceElem.className = 'down';
        sortType = 'desc';
        break;
      case 'down':
        sourceElem.className = 'up';
        sortType = 'asc';
        break;
      default:
        sourceElem.className = 'up-down';
        sortType = 'asc';
        break;
    }

    if (elem = document.getElementById('searchFormSortOrderField'))
      elem.value = sortOrder;

    if (elem2 = document.getElementById('searchFormSortOrderType'))
      elem2.value = sortType;

    setSearchFormOrderButtons(sourceElem);

    setSearchFormResultPage(1);
  }

  function placePreview(offeringUuid, offeringCollectionUuid)
  {
    preview = document.getElementById('search_preview');
    left = document.getElementById('previewLeft');
    right = document.getElementById('previewRight');

    preview.innerHTML = '';
    left.innerHTML = '&nbsp;';
    right.innerHTML = '&nbsp;';

    var i = 0;
    var key = 0;

    for (i = 0; i < result_projects.length; i++)
    {
      if (offeringUuid == result_projects[i]['uuid'])
        key = i;

    }

    if (key == 0)
    {
      if (result_page != 1)
        left.innerHTML = '<a href="javascript:void(0);" onclick="setSearchFormResultPage(result_page-1, \'last\');">Vorige woning</a>';

      if (result_projects.length > 1)
        right.innerHTML = '<a href="javascript:void(0);" onclick="placePreview(\''+ result_projects[key+1]['uuid'] +'\', \''+result_projects[key+1]['col_uuid']+'\');">Volgende woning</a>';

    }
    else if (key == (result_projects.length-1))
    {
      left.innerHTML = '<a href="javascript:void(0);" onclick="placePreview(\''+ result_projects[key-1]['uuid'] +'\', \''+result_projects[key-1]['col_uuid']+'\');">Vorige woning</a>';

      if ((result_total/9) > result_page)
        right.innerHTML = '<a href="javascript:void(0);" onclick="setSearchFormResultPage(result_page+1, \'first\');">Volgende woning</a>';

    }
    else
    {
      left.innerHTML = '<a href="javascript:void(0);" onclick="placePreview(\''+ result_projects[key-1]['uuid'] +'\', \''+result_projects[key-1]['col_uuid']+'\');">Vorige woning</a>';
      right.innerHTML = '<a href="javascript:void(0);" onclick="placePreview(\''+ result_projects[key+1]['uuid'] +'\', \''+result_projects[key+1]['col_uuid']+'\');">Volgende woning</a>';
    }

    changeDisplay('search_preview_holder', 'search_filter');

    var url = '';
    var baseHref = document.getElementsByTagName('base');

    if (baseHref && baseHref[0] && baseHref[0].href)
      url = baseHref[0].href;

    request_init('search_preview', null, 'fireNumberedScriptsForDivs(\'videoholder\');size_column_content(\'search_preview\');');
    request_addUrl(url+'templates/template_preview.php?ou=' + offeringUuid + '&ocu=' + offeringCollectionUuid + '&url=livy_pv');
    request_retrieve('request_placeContent');
  }

  function placeContainers(params)
  {
    var url = '';
    var baseHref = document.getElementsByTagName('base');

    if (baseHref && baseHref[0] && baseHref[0].href)
      url = baseHref[0].href;

    urls = new Array();
    var i = 0;

    for (i = 0; i < params.length; i++)
    {
      if (params[i]['col_uuid'] && params[i]['ssl'] && params[i]['target_id'] != '' && params[i]['uuid'] != '' && params[i]['col_uuid'] != '' && params[i]['dlm'] != '' && params[i]['ssl'] != '')
        request_addUrl(url + 'content/cachescripts/search_result_container.php?uuid=' + params[i]['uuid'] + '&col_uuid=' + params[i]['col_uuid'] + '&dlm=' + params[i]['dlm'] + '&ssl=' + params[i]['ssl'], params[i]['target_id'], null, 'GET');
      else if (params[i]['target_id'] != '' && params[i]['uuid'] != '' && params[i]['dlm'] != '')
        request_addUrl(url + 'content/cachescripts/home_project_container.php?uuid=' + params[i]['uuid'] + '&dlm=' + params[i]['dlm'], params[i]['target_id'], null, 'GET');
      else if (params[i]['target_id'] != '' && params[i]['uuid'] != '' && params[i]['dlm'] != '')
        request_addUrl(url + 'content/cachescripts/home_project_container.php?uuid=' + params[i]['uuid'] + '&dlm=' + params[i]['dlm'], params[i]['target_id']);

    }

    request_retrieve('request_placeContent');
  }

  /**
  * @desc   dynamic load javascript
  * @param  sring path (url) to javascript file
  * @return boolean if load action was succesfull
  * returns also true if script was already loaded !!
  **/
  function loadJsFile(path)
  {
    var headTags = document.getElementsByTagName("head");
    var headTag  = null;

    if(headTags && headTags[0])
      headTag = headTags[0];

    if(!headTag)
      return false;

    // check if the script is not already included yet !!
    var scriptTags = headTag.getElementsByTagName("script");

    if(scriptTags && scriptTags.length > 0)
    {
      var index = 0;
      for(index in scriptTags)
      {
        if(scriptTags[index].src && scriptTags[index].src.indexOf(path) >= 0)
          return true;
      }
    }

    // add the script to the document
    var script = document.createElement("script");
    script.src = path;
    script.type = "text/javascript";
    headTag.appendChild(script);
    return true;
  }

  //
  // --------------------------------- callback functions -------------------------------- //
  // -- the following functions are called from a validation function in the validator -- //
  //

  // this function is called by validator.validation_higher_lower_then() function
  function set_select_to_a_value_higer_lower_then(request)
  {
    var pageValidation = request.pageValidation;
    var checkEl        = request.checkEl;
    var otherEl        = request.otherEl;
    var checkElValue   = request.checkElValue;
    var otherElValue   = request.otherElValue;
    var higherLower    = request.higherLower;
    var valid          = request.valid;

    // this function will only change select boxes of the type 'select-multiple'
    if (validator.getElementType(otherEl) == 'select-multiple');
    {
      // value of the checked elem should be higher or lower then the other elem
      // when we come here this is not the case, so set the other elem to a lower / higher value
      var nrOfOptions   = otherEl.options.length;
      var changedSelect = false
      var changeObject  = new Object();

      if (higherLower == 'higher')
      {
        // element should have a higher value than the otherEl, so set the otherEl to a lower value than the value of the element
        for (elemindex = nrOfOptions-1; elemindex >=0; elemindex--)
        {
          otherEl.options[elemindex].selected = false;

          if (!changedSelect)
          {
            var curSelValue = otherEl.options[elemindex].value;
            curSelValue  = string_to_int(curSelValue);

            if (curSelValue < checkElValue)
            {
              otherEl.options[elemindex].selected = true;
              changedSelect = true;
            }
          }
        }

        if (!changedSelect)
          otherEl.options[0].selected = true;
      }
      else
      {
        // element should have a lower value than the otherEl, so set the otherEl to a higher value than the value of the element
        for (elemindex = 0; elemindex < nrOfOptions; elemindex++)
        {
          otherEl.options[elemindex].selected = false;

          if (!changedSelect)
          {
            var curSelValue = otherEl.options[elemindex].value;
            curSelValue = string_to_int(curSelValue);

            if (curSelValue > checkElValue)
            {
              otherEl.options[elemindex].selected = true;
              changedSelect = true;
            }
          }
        }
        if (!changedSelect)
          otherEl.options[nrOfOptions-1].selected = true;
      }
    }
    // make the new value visable in the selectbox
    multiselectReInit(otherEl.id);
    return true;
  }

  // the following function is called from te validator.validation_call function in the validator
  function fillDependentSelect(request)
  {
    var selectToSet    = null;
    var requestURL     = '';
    var pageValidation = request.pageValidation;
    var calledFrom     = request.calledFrom;
    var xtraParameters = request.xtraParameters;

    // todo : set attribute which indicates if this action has to be executed on page initialization
    // don't do this action when the page (form) is initialized, validated or any action not triggerd by a change!!!
    //if (isInitForm || pageValidation || validationCalledOnChange === false) return;
    if (isInitForm || pageValidation) return;

    if (xtraParameters.length > 0 && xtraParameters.split)
    {
      xtraParametersArr = xtraParameters.split(',');

      if (xtraParametersArr[0])
        selectToSet = xtraParametersArr[0];
      if (xtraParametersArr[1])
        requestURL  = xtraParametersArr[1];

    }

    if (checkEl = document.getElementById(calledFrom))
      checkElValue = validator.getValue(checkEl);

    // empty the selectbox
    if (select = document.getElementById(selectToSet))
    {
      select.innerHTML = '';
      multiselectReInit(selectToSet);
    }

    // when the field contains something do the call
    if (checkElValue.length > 0)
    {
      var url = requestURL + "&query=" + escape(checkElValue);
      request_init(selectToSet, null, '');
      request_addUrl(url, selectToSet);
      request_retrieve('fillDependentSelectCallBack');
    }
  }

  // this function is the callback for the fillDependentSelect ajax call (above)
  function fillDependentSelectCallBack(num,target,req_count)
  {
    if (req_count!= request_counter)
      return;

    if (xmlReqs[num].readyState != 4)
      return;

    if (xmlReqs[num].status != 200)
      return;

    if (targetElem = document.getElementById(target))
    {
      targetElem.options.length  = 0;
      var optionsString = xmlReqs[num].responseText;
      var optionsArray  = optionsString.split('|');
      var optindex      = 0;

      for (optindex in optionsArray)
      {
        $values = optionsArray[optindex].split('#');

        if ($values[0] && $values[1])
        {
          var optionName = new Option($values[1], $values[0], false, false)
          targetElem.options[targetElem.options.length] = optionName;
        }
      }
      multiselectReInit(targetElem.id);
    }
  }

  // the following function is called from te validator.validation_call function in the validator
  function setOptionsDepentSelect(request)
  {
    var selectToSet    = null;
    var pageValidation = request.pageValidation;
    var calledFrom     = request.calledFrom;
    var xtraParameters = request.xtraParameters;

    if (isInitForm || pageValidation) return;

    if (xtraParameters.length > 0 && xtraParameters.split)
    {
      xtraParametersArr = xtraParameters.split(',');

      if (xtraParametersArr[0])
        selectToSet = xtraParametersArr[0];
      if (xtraParametersArr[1])
        optionsObject = xtraParametersArr[1];

    }

    if (checkEl = document.getElementById(calledFrom))
      checkElValue = validator.getValue(checkEl);
    else
      return;

    if (targetElem = document.getElementById(selectToSet))
    {
      // first determine which options should be filled
      var filWith = new Array();
      // check how many values there are

      if (checkElValue == '' || (checkElValue[0] && checkElValue[1]))
      {
        // two or no values
        for (options in window[optionsObject])
          filWith[filWith.length] = options;
      }
      else
      {
        // one value
        filWith[0] = checkElValue;
      }
      // check which options where selected
      var prevCheckedOptions = new String('');

      if (targetElem.options)
      {
        for (curOption in targetElem.options)
        {
          if (targetElem.options[curOption] && targetElem.options[curOption].value && targetElem.options[curOption].selected === true)
            prevCheckedOptions += targetElem.options[curOption].value + ',';

        }
      }
      // clear the options in the selectbox
      targetElem.options.length  = 0;
      // fill the selectbox with new options
      for (optionIndex in filWith)
      {
        optionsArray = window[optionsObject][filWith[optionIndex]];
        for (optindex in optionsArray)
        {
          var text  = new String(optionsArray[optindex]);
          text = text.replace(/^[a-z]{1}/, text.charAt(0).toUpperCase());
          var value = optionsArray[optindex];
          if (text && value)
          {
            var prevSelected = false;

            if (prevCheckedOptions.indexOf(value + ',') != -1)
              prevSelected = true;

            var optionName = new Option(text, value, false, prevSelected)
            targetElem.options[targetElem.options.length] = optionName;
          }
        }
      }
      multiselectReInit(targetElem.id);
    }
  }

  function writeFlashObject(location, divId,  width, height)
  {
    document.getElementById(divId).innerHTML = '<object id=\"bl'+divId+'\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" width=\"'+width+'\" height=\"'+height+'\" >'
                                              +'<param name=\"movie\" value=\"' + location + '\" />'
                                              +'<param name=\"quality\" value=\"high\" />'
                                              +'<param name=\"wmode\" value=\"transparent\" />'
                                              +'<embed src=\"' + location + '\" quality=\"high\" wmode=\"transparent\" width=\"'+width+'\" height=\"'+height+'\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />'
                                              +'</object>';
    document.getElementById(divId).style.display = 'block';
  }

  function fireNumberedScriptsForDivs(divName)
  {
    var i=1;
    while (document.getElementById(divName+i))
    {
      eval(document.getElementById(divName+i).innerHTML);
      i++;
    }
  }
