// functions for loading products from the "wijnvinder" in the list_content div

var Wijnvinder = new Object();

Wijnvinder['createDisplayArea'] = function(areaName) {
  if(! areaName) {
    return 0;
  }
  // configuration. change as needed
  var possibleAreas = ['list_content', 'product_content'];
  
  // remove previously created display areas
  for(var i = 0; i < possibleAreas.length ; i++) {
    var areaId = possibleAreas[i];
    if(document.getElementById(areaId)) {
      var areaToRemove = document.getElementById(areaId);
      areaToRemove.parentNode.removeChild(areaToRemove);
    };
  };


  var displayArea = document.createElement('DIV');
  displayArea.setAttribute('id', areaName);

  var topBlocks = document.getElementById('contenttopblocks');
  
  if(topBlocks) {
    topBlocks.parentNode.insertBefore(displayArea, topBlocks);
  } else {
    document.getElementById('main').appendChild(displayArea);
  }
  
  if(! document.getElementById('anchorforstartproductlist')){ 
    var anchor = document.createElement('A');
    anchor.setAttribute('name', 'startproductlist');
    anchor.setAttribute('id', 'anchorforstartproductlist');
    displayArea.parentNode.insertBefore(anchor, displayArea);
  };
  return displayArea;
};

Wijnvinder['displayObject'] = null;

Wijnvinder['showWaitMessage'] = function() {
  var objectToDisplayMessageIn = Wijnvinder['displayObject'];
  if(objectToDisplayMessageIn) {
      objectToDisplayMessageIn.innerHTML = "<h1><br />Een ogenblik geduld alsjeblieft ...<br /></h1><h2>Je wijnen worden opgehaald<br /><br /><br /></h2>";
  };
  return true;
};

Wijnvinder['showResults'] = function(returnedData) {
  var objectToDisplayMessageIn = Wijnvinder['displayObject'];
  if(objectToDisplayMessageIn) {
      objectToDisplayMessageIn.innerHTML = returnedData;
	    tagListeners.assignListenersToElementsBelow(objectToDisplayMessageIn);
  };
};

function getDataFromURL(urlWanted) {
  //alert('functie wordt aangeroepen');
  var contentDivName = 'list_content';
  if(urlWanted.match(/Product\/View/)) {
    contentDivName = 'product_content';
  };
  var displayObject = Wijnvinder['createDisplayArea'](contentDivName);
  Wijnvinder['displayObject'] = displayObject;
  ECubeAjax['assignHandlerToState']('READY_STATE_INCOMPLETE', Wijnvinder['showWaitMessage']);
  ECubeAjax['assignHandlerToState']('READY_STATE_COMPLETE', Wijnvinder['showResults']);
  location.href="#startproductlist";
  ECubeAjax['sendRequest'](urlWanted+'?ProductsOnly=yes&GetWijnvinderData=yes');
};




