/**
 *  Common.js 
 *
 *	© copyright 2005 - 2007 2G B.V. All rights reserved.
 *	The computer program(s) is the proprietary information of the original authors. 
 *	and provided under the relevant License Agreement containing restrictions 
 *	on use and disclosure. Use is subject to the License Agreement.
 *
 *  	No part of this package may be reproduced and/or published by print, 
 *	photoprint, microfilm, audiotape, electronically, mechanically or any other means, 
 *	or stored in an information retrieval system, without prior permission from 2G B.V. www.2g-it.nl.
 * 
 *	@original authors:  jgeuze
 */

/**
 * Holds a hardcoded hashmap of the head-categories.
 */
var aiHeadCategories = new Array();
aiHeadCategories['DAMES_MODE'] = 1;
aiHeadCategories['HEREN_MODE'] = 2;
aiHeadCategories['KINDER_MODE'] = 3;
aiHeadCategories['BABY_MODE'] = 4;
aiHeadCategories['KOOPJESHOEK'] = 5;
aiHeadCategories['ALLES_OVER_MERKEN'] = 6;

var g__asMainCategoryNames = new Array();
g__asMainCategoryNames['ALLES_OVER_MERKEN'] = 'alles_over_merken.php';
g__asMainCategoryNames['DAMES_MODE'] = 'damesmode.php';
g__asMainCategoryNames['HEREN_MODE'] = 'herenmode.php';
g__asMainCategoryNames['KINDER_MODE'] = 'kindermode.php';
g__asMainCategoryNames['BABY_MODE'] = 'babymode.php';
g__asMainCategoryNames['KOOPJESHOEK'] = 'koopjeshoek.php';
g__asMainCategoryNames['CONTACT'] = 'contact.php';

var g__firstDatafeedID = "";
 
/**
 * This method will load a new page into the main iframe, and update the belonging active tab.
 */
function loadPage(sSourceObject, sPage2Load)
{
	loadNewPage(sPage2Load);
	
	var oSourceObject = document.getElementById(sSourceObject);
	updateTabs(oSourceObject);
}//loadPage
function navigateToHome()
{
	if (g_PreviousActiveTab != null)
	{
		var aoPreviousTDs = g_PreviousActiveTab.getElementsByTagName("TD");
		updateTabElements(aoPreviousTDs);
	}
		
	var oTab2Activate = document.getElementById("tabHomepage");
	
	g_PreviousActiveTab = oTab2Activate;
	
	var aoTDs = oTab2Activate.getElementsByTagName("TD");
	updateTabElements(aoTDs);
	
	loadNewPage("homepage.php");
}
function loadNewPage(sPage2Load)
{
	sPage2Load = 'html/' + sPage2Load;
	var oIframe = document.getElementById("oMainController");
	oIframe.src = sPage2Load;
}//loadNewPage

/**
  * This method will update the tabs-list (contained at the top of the site) with the active tab.
  *
  * @param oTab2Activate:	The tab to activate (amongst others give it the proper class).
  */
var g_PreviousActiveTab = null;
function updateTabs(oTab2Activate)
{
	if (g_PreviousActiveTab != null)
	{
		var aoPreviousTDs = g_PreviousActiveTab.getElementsByTagName("TD");
		updateTabElements(aoPreviousTDs);
	}
	
	g_PreviousActiveTab = oTab2Activate;
	
	var aoTDs = oTab2Activate.getElementsByTagName("TD");
	updateTabElements(aoTDs);
}//updateTabs

/**
 * This is a helper method which wil update tab elements with specific classnames.
 * This method is used by the updateTabs method to add the styling.
 *
 * @param aoTabElements:	The html elements to update.
 */
function updateTabElements(aoTabElements)
{
	for (var iElementIndex = 0; iElementIndex < aoTabElements.length; iElementIndex++)
	{
		var oElement = aoTabElements[iElementIndex];
		
		//Nonactive tabs to Active
		if (oElement.className == "cls_NonActiveTabLeftCorner")
		{
			oElement.className = "cls_ActiveTabLeftCorner";
		}
		else if (oElement.className == "cls_NonActiveTab")
		{
			oElement.className = "cls_ActiveTab";
		}
		else if (oElement.className == "cls_NonActiveTabRightCorner")
		{
			oElement.className = "cls_ActiveTabRightCorner";
		}
		
		//Active tabs to Nonactive tabs.
		else if (oElement.className == "cls_ActiveTabLeftCorner")
		{
			oElement.className = "cls_NonActiveTabLeftCorner";
		}
		else if (oElement.className == "cls_ActiveTab")
		{
			oElement.className = "cls_NonActiveTab";
		}
		else if (oElement.className == "cls_ActiveTabRightCorner")
		{
			oElement.className = "cls_NonActiveTabRightCorner";
		}
		
		//Special to ActiveSpecial
		else if (oElement.className == "cls_SpecialTab")
		{
			oElement.className = "cls_ActiveSpecialTab";
		}
		
		//Active special tabs to special tabs.
		else if (oElement.className == "cls_ActiveSpecialTab")
		{
			oElement.className = "cls_SpecialTab";
		}
	}
}//updateTabElements

/**
 * This method is called when the keydown is pressed within the search, box.
 * we wan't to check if the ENTER key was pressed, and if that is the case we
 * will perform a search.
 *
 * @param oEvent:	The event object containing the keycode to test against.
 */
function keydown_performSearch(oEvent)
{
	var eKey = -1;
	if (typeof(oEvent) == "undefined")
	{
		//IE
		eKey = event.keyCode;
	}
	else
	{
		//Firefox...
		eKey = oEvent.keyCode;
	}
	//var eKey = event.keyCode;
	if (eKey == 13)
	{
		var oBrand = document.getElementById("txtSearchByBrand");
		g__sSelectedBrandsValue = oBrand.options[oBrand.selectedIndex].value;		
		g__sSearchString = getHTMLData(document.getElementById("txtSeachInput"));
		if (g__sSelectedBrandsValue == "" || g__sSelectedBrandsValue == "-1" || g__sSelectedBrandsValue == -1)
		{
			g__sSelectedBrandsValue = "zoeken";
		}
		if (g__sSearchString == "")
		{
			g__sSearchString = "zoeken";
		}
		//window.top.location = "http://www.merkkledingwinkels.nl/" + "?page=homepage.php&searchme=true&searchquery=" + g__sSearchString + "&searchbrand=" + g__sSelectedBrandsValue;
		//New version
		//http://www.merkkledingwinkels.nl/zoek_merken/zoeken/Adidas.html
		
		gotoSearchPage(g__sSearchString, g__sSelectedBrandsValue);
	}
}//keydown_performSearch

function firePerformSearch(oNothing)
{
	var oBrand = document.getElementById("txtSearchByBrand");
	g__sSelectedBrandsValue = oBrand.options[oBrand.selectedIndex].value;		
	g__sSearchString = getHTMLData(document.getElementById("txtSeachInput"));
	
	//window.top.location = "http://www.merkkledingwinkels.nl/" + "?page=homepage.php&searchme=true&searchquery=" + g__sSearchString + "&searchbrand=" + g__sSelectedBrandsValue;
	if (g__sSelectedBrandsValue == "" || g__sSelectedBrandsValue == "-1" || g__sSelectedBrandsValue == -1)
	{
		g__sSelectedBrandsValue = "zoeken";
	}
	if (g__sSearchString == "")
	{
		g__sSearchString = "zoeken";
	}
	//New version
	//http://www.merkkledingwinkels.nl/zoek_merken/zoeken/Adidas.html
	gotoSearchPage(g__sSearchString, g__sSelectedBrandsValue);
}//firePerformSearch

function gotoSearchPage(g__sSearchString, g__sSelectedBrandsValue)
{
	//#38;
	if (g__sSelectedBrandsValue.indexOf('#38;') != -1)
	{
		g__sSelectedBrandsValue = g__sSelectedBrandsValue.replace('#38;', '_AND_');
	}
	while (g__sSearchString.indexOf(' ') != -1)
	{
		g__sSearchString = g__sSearchString.replace(' ', '_SPACE_');
	}
	window.top.location = "http://www.merkkledingwinkels.nl/zoek_merken/" + g__sSearchString + "/" + g__sSelectedBrandsValue + ".html";
}//gotoSearchPage

function inputFormInputText_Enable(oSourceObject)
{
	oSourceObject.createTextRange().select();	
	oSourceObject.focus();
}
function getMainController()
{
	return document.getElementById("oMainController").contentWindow.document;
}

function LOG(sLogDescription, sGeneralDefinition, sOption1, sOption2)
{
	var xmlHttpRequest =  new XMLHttpRequest();
	
	//We are sending the request asynchronously because we don't do anything with the response and we don't want the user
	//to lose performance because of the log call.
	xmlHttpRequest.open('POST', 'http://www.merkkledingwinkels.nl/php/ControllerHandler.php', true);
	
	//setup a method to call when response is received from the server.
	xmlHttpRequest.onreadystatechange = function() 
	{
		if (xmlHttpRequest.readyState == 4) 
		{
			doneLogging(xmlHttpRequest);
		}
	}
	
	//set the request data.
	var sRequestData = "sAction2Perform=UPDATE_LOG_DATA"
						+"&sLogDescription=" + encodeURIComponent(sLogDescription)
						+"&sGeneralDefinition=" + encodeURIComponent(sGeneralDefinition)
						+"&sOption1=" + encodeURIComponent(sOption1)
						+"&sOption2=" + encodeURIComponent(sOption2);
	
	//now send the request.
	xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttpRequest.send(sRequestData);
}//LOG

function doneLogging(xmlResponse)
{
	//Do nothing for now.
}//doneLogging

/**
 * This method will perform a search with the given values.
 */
var g__sSelectedBrandsValue = null;
var g__sSearchString = null;
function performSearch(bFireCursor)
{
	if (bFireCursor == true)
	{
		var oBrand = document.getElementById("txtSearchByBrand");
		g__sSelectedBrandsValue = oBrand.options[oBrand.selectedIndex].value;		
		g__sSearchString = getHTMLData(document.getElementById("txtSeachInput"));
	}
	if (g__sSelectedBrandsValue == -1)
	{
		if (getURLParam("searchbrand") != "")
		{
			g__sSelectedBrandsValue = getURLParam("searchbrand");
		}
	}
	if (g__sSearchString == "")
	{
		if (getURLParam("searchquery") != "")
		{
			g__sSearchString = getURLParam("searchquery");
		}
	}
	
	LOG("Zoeken op datafeeds", g__sSearchString+ " - " + g__sSelectedBrandsValue, "", "");
	
	var sURL = getMainController().location.href;
	if (g__sSelectedBrandsValue == "" || g__sSelectedBrandsValue == "-1" || g__sSelectedBrandsValue == -1)
	{
		g__sSelectedBrandsValue = "zoeken";
	}
	if (g__sSearchString == "")
	{
		g__sSearchString = "zoeken";
	}

	//New version
	//http://www.merkkledingwinkels.nl/zoek_merken/zoeken/Adidas.html
	var sNewURL = "http://www.merkkledingwinkels.nl/zoek_merken/" + g__sSearchString + "/" + g__sSelectedBrandsValue + ".html";
	//	if (sURL.indexOf("homepage.php") == -1)
	//if (window.top.location.href != sNewURL)
	if (sURL.indexOf("homepage.php") == -1)
	{
		gotoSearchPage(g__sSearchString, g__sSelectedBrandsValue);
		updateTabs(document.getElementById("tabAllesOverMerken"));
	}
	else
	{
		if  (	
				g__sSearchString.length < 3
					&&	(g__sSelectedBrandsValue == "-1" || g__sSelectedBrandsValue == "")
			)
		{
			alert("Specificeer u zoek opdracht! (u dient minimaal 3 letters in te typen of u moet een merk kiezen!)");
			//give focus back to search box
			try	{	inputFormInputText_Enable(document.getElementById("txtSeachInput"));	}	catch (e)	{	/*ignore.*/ }
			return;
		}
		
		var oPanel = document.getElementById("divGeneralContent");
		if (oPanel == null)
		{
			oPanel = getMainController().getElementById("divGeneralContent");
		}
		//Fire search Query
		var xmlSearchCount = getSearchDataCount();
		if (typeof(xmlSearchCount) != "undefined" && xmlSearchCount != null)
		{
			var iSearchCount = 0;
			iSearchCount = parseInt(xmlSearchCount.selectSingleNode(".//counter/text()").nodeValue, 10);
			if (iSearchCount == 0)
			{
				//build nothing found ui.
				if (oPanel != null)
				{
					oPanel.innerHTML = buildSearchResponse(null, null);
					//give focus back to search box
					try	{	inputFormInputText_Enable(document.getElementById("txtSeachInput"));	}	catch (e)	{	/*ignore.*/ }
				}
			}
			else
			{
				g___search__iTotal = iSearchCount;
				if (typeof(bFireCursor) != "undefined")
				{
					setCursor(null);
				}
				var xmlSearchResponse = getSearchData();
				
				if (typeof(xmlSearchResponse) != "undefined" && xmlSearchResponse != null)
				{
					if (oPanel != null)
					{
						//build response ui.
						oPanel.innerHTML = buildSearchResponse(xmlSearchResponse, iSearchCount);
						if (oMainController.setHeight)
						{
							oMainController.setHeight();
						}
						
					}
				}
			}
		}
		
		// Reset the search fields.
		document.getElementById('txtSeachInput').value = '';
		document.getElementById("txtSearchByCategory").selectedIndex = 0;
		document.getElementById("txtSearchByBrand").selectedIndex = 0;
	}
}//performSearch

function setCursor(sType)
{
	if (typeof(g___search__iMinCursor) == "undefined")
	{
		g___search__iMinCursor = 0;
	}
	if (sType != null)
	{
		if (sType == "NEXT")
		{
			if (10 + g___search__iMinCursor > g___search__iTotal)
			{
				g___search__iMinCursor = 0;
			}
			else
			{
				g___search__iMinCursor += 10;
			}
		}
		else
		{
			if (g___search__iMinCursor >= 10)
			{
				g___search__iMinCursor -= 10;
			}
		}
	}
	//Update max cursor.
	if (10 + g___search__iMinCursor >= g___search__iTotal)
	{
		//Maximum is itotal.
		g___search__iMaxCursor = g___search__iTotal;
	}
	else
	{
		g___search__iMaxCursor = 10 + g___search__iMinCursor;
	}
}

function searchPrevious()
{
	setCursor("PREVIOUS");
	performSearch();
}//searchPrevious

function searchNext()
{
	setCursor("NEXT");
	performSearch();
}//searchNext

var g___search__iTotal = 0;
var g___search__iMaxCursor = 0;
var g___search__sHeadCategory = "";
var g___search__sSubCategory = "";
var g___search__sBrand = "";
var g___search__sSearchString = "";
var g_sHeadCategory = "";
var g_sSubCategory = "";
function getSearchDataCount()
{
	var xmlReturn = null;
	
	//Store search criteria globaly.
	g___search__sSearchString = g__sSearchString;
	
	if (typeof(g__sSearchString) != "undefined" && g__sSearchString != "" && g__sSearchString != null && g__sSearchString != "zoeken")
	{
		while (g___search__sSearchString.indexOf('_SPACE_') != -1)
		{
			g___search__sSearchString = g___search__sSearchString.replace('_SPACE_', ' ');
		}
		while (g__sSearchString.indexOf('_SPACE_') != -1)
		{
			g__sSearchString = g__sSearchString.replace('_SPACE_', ' ');
		}
		g___search__sSearchString += "*";
	}
	else
	{
		g___search__sSearchString = "";
	}
	var sXMLExtension = "";
	
	/*var sSelectedValue = oCategory.options[oCategory.selectedIndex].value;
	if (sSelectedValue != "-1" && sSelectedValue != "")
	{
		//Add categories to search.
		var sHeadCategory = oCategory.options[oCategory.selectedIndex].getAttribute("main_category");
		var sSubCategory = oCategory.options[oCategory.selectedIndex].getAttribute("sub_category");
		sXMLExtension += '<column><extendingtype>AND</extendingtype><id>fk_hoofdcategorie</id><value>' + sHeadCategory + '</value></column>';
		sXMLExtension += '<column><extendingtype>AND</extendingtype><id>fk_subcategorie</id><value>' + sSubCategory + '</value></column>';

		//Store search criteria globaly.
		g_sHeadCategory = sHeadCategory;
		g_sSubCategory = sSubCategory;
	}*/
	
	if (g__sSelectedBrandsValue != "-1" && g__sSelectedBrandsValue != "" && g__sSelectedBrandsValue != "zoeken")
	{
	
		if (g__sSelectedBrandsValue.indexOf('_AND_') != -1)
		{
			g__sSelectedBrandsValue = g__sSelectedBrandsValue.replace('_AND_', '#38;');
		}
		//Add brands to search.
		g___search__sSearchString += " %2B%22" + g__sSelectedBrandsValue + "%22";
		
		//Store search criteria globaly.
		g___search__sBrand = g__sSelectedBrandsValue;
	}
	
	//Send Count query.
	//create the cross-browser compatible htppRequest.
	var xmlHttpRequest =  new XMLHttpRequest();
	xmlHttpRequest.open('POST', 'http://www.merkkledingwinkels.nl/php/ControllerHandler.php', false);
	
	//set the request data.
	var sRequestData = "sAction2Perform=GET_COUNT_DATA_FOR_GSEARCH&sqlQueryID=SearchDatafeedsCount&sKeyWords=%2B" + g___search__sSearchString;
	
	/*if (sXMLExtension != "")
	{
		sXMLExtension = '<root>' + sXMLExtension + '</root>';
		sRequestData += "&sExtension=" + sXMLExtension;
	}*/
	
	//now send the request.
	xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttpRequest.send(sRequestData);
	
	xmlReturn = xmlHttpRequest.responseXML;
	
	return xmlReturn;
}//getSearchDataCount

function getSearchData()
{	
	var xmlReturn = null;
	
	/*if (typeof(g__sSearchString) != "undefined" && g__sSearchString != "" && g__sSearchString != null)
	{
		g___search__sSearchString += "*";
	}
	else
	{
		g___search__sSearchString = "";
	}
	var sXMLExtension = "";
	
	var sSelectedValue = oCategory.options[oCategory.selectedIndex].value;
	if (sSelectedValue != "-1" && sSelectedValue != "")
	{
		//Add categories to search.
		var sHeadCategory = oCategory.options[oCategory.selectedIndex].getAttribute("main_category");
		var sSubCategory = oCategory.options[oCategory.selectedIndex].getAttribute("sub_category");
		sXMLExtension += '<column><extendingtype>AND</extendingtype><id>fk_hoofdcategorie</id><value>' + sHeadCategory + '</value></column>';
		sXMLExtension += '<column><extendingtype>AND</extendingtype><id>fk_subcategorie</id><value>' + sSubCategory + '</value></column>';
	}
	
	if (g__sSelectedBrandsValue != "-1" && g__sSelectedBrandsValue != "")
	{
		//Add brands to search.
		g___search__sSearchString += " %2B%22" + g__sSelectedBrandsValue + "%22";
		
		//Store search criteria globaly.
		g___search__sBrand = g__sSelectedBrandsValue;
	}*/
	
	//Send search query
	//create the cross-browser compatible htppRequest.
	var xmlHttpRequest =  new XMLHttpRequest();
	xmlHttpRequest.open('POST', 'http://www.merkkledingwinkels.nl/php/ControllerHandler.php', false);
	
	//set the request data.
	var sRequestData = "sAction2Perform=GET_SEARCH_DATA_FOR_GSEARCH&sqlQueryID=SearchDatafeeds&sKeyWords=%2B" + g___search__sSearchString + "&iMinCursor=" + g___search__iMinCursor + "&iMaxCursor=10";

	//now send the request.
	xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttpRequest.send(sRequestData);
	
	xmlReturn = xmlHttpRequest.responseXML;
	
	return xmlReturn;
}//getSearchData

/**
 * This method will build a search response result html
 */
function buildSearchResponse(xmlSearchResponse, iSearchCount)
{
	var sHTML = '<div style="width:600px; height:100%; overflow:auto;">';
	
	if (xmlSearchResponse == null && iSearchCount == null)
	{
		//No result found,
		sHTML += '<table cellpadding="0" cellspacing="0" width="100%" height="100%" class="cls_SearchTable">'
					+'<tr><td><label>Er zijn geen zoek resultaten gevonden voor de opgegeven zoek criteria</label></td></tr></table>';
		
	}
	else
	{
		var sSearchString = '';
		
		if (g__sSearchString != '' && g__sSearchString != 'zoeken')
		{
			sSearchString += g__sSearchString + ' ';
		}
		if (g__sSelectedBrandsValue != '-1' && g__sSelectedBrandsValue != '' && g__sSelectedBrandsValue != 'zoeken')
		{
			sSearchString += g__sSelectedBrandsValue;
		}
		
		sHTML += '<table cellpadding="0" cellspacing="0" width="100%" height="100%" class="cls_SearchTable">';
		sHTML += '<tr><td colspan="2">&nbsp;&nbsp;</td></tr><tr><td colspan="2" align="left" valign="top" style="padding-bottom:4px;"><label>Resultaten <b>' + (1 + g___search__iMinCursor) + '</b> - <b>' + g___search__iMaxCursor + '</b> van circa <b>' + iSearchCount + '</b> voor <b>' + sSearchString + '</b></label></td></tr>';
		sHTML += '<tr><td align="left" valign="top"><input type="button" onclick="top.searchPrevious();" class="cls_Buttons" value="<< vorige"></input></td>'
						+'<td align="right" valign="top"><input type="button" onclick="top.searchNext();" class="cls_Buttons" value="volgende >>"></input></tr><tr><td colspan="2">&nbsp;&nbsp;</td></tr>';
		var anNodes = xmlSearchResponse.selectNodes(".//tuple");
		for (var iNode = 0; iNode < anNodes.length; iNode++)
		{
			var nSearchNode = anNodes[iNode];
			
			var sTitle = nSearchNode.selectSingleNode(".//description/text()").nodeValue;
			var sDescription = nSearchNode.selectSingleNode(".//tekst_for_search/text()").nodeValue;
			var sFoto = nSearchNode.selectSingleNode(".//foto/text()").nodeValue;
			var sURL = nSearchNode.selectSingleNode(".//url/text()").nodeValue;
			
			var sAllsDescription = sTitle + " " + sDescription;
			
			sHTML += '<tr class="cls_DatafeedsSearchResult" style="padding-bottom:4px;"><td colspan="2" align="left" valign="top"><a href="' + sURL + '" target="_blank" rel="nofollow" class="cls_Search_Title">' + sTitle + '</a></td></tr>'
					+ '<tr style="border-bottom: 10px solid white;">'
						+'<td align="left" style="border-bottom: 10px solid white;"><a href="' + sURL + '" target="_blank" rel="nofollow"><img height="110px" src="' + sFoto + '" border="0" alt="' + sAllsDescription + '" title="' + sAllsDescription + '"></a></td>'
						+'<td align="left" valign="top" style="border-bottom: 10px solid white;" ><a href="' + sURL + '" target="_blank" rel="nofollow" style="text-decoration: none;" class="cls_DatafeedsSearchResult">' + parseSearchText(sDescription, g___search__sSearchString) + '</a>&nbsp;&nbsp;<b><a href="' + sURL + '" target="_blank" rel="nofollow" class="cls_DatafeedsSearchResult">Meer info</a></b></td>'
					+'</tr>';
		}
		
		sHTML += '<tr><td colspan="2">&nbsp;&nbsp;</td></tr><tr><td colspan="2" align="left" valign="top" style="padding-bottom:4px;"><label>Resultaten <b>' + (1 + g___search__iMinCursor) + '</b> - <b>' + g___search__iMaxCursor + '</b> van circa <b>' + iSearchCount + '</b> voor <b>' + sSearchString + '</b></label></td></tr>';
		sHTML += '<tr><td align="left" valign="top"><input type="button" onclick="top.searchPrevious();" class="cls_Buttons" value="<< vorige"></input></td>'
						+'<td align="right" valign="top"><input type="button" onclick="top.searchNext();" class="cls_Buttons" value="volgende >>"></input></tr><tr><td colspan="2">&nbsp;&nbsp;</td></tr>';
		sHTML += '</table>';
		
	}
	
	/*
		g___search__sSearchString = "";
		g___search__sHeadCategory = "";
		g___search__sSubCategory = "";
		g___search__sBrand = "";
	*/
	
	sHTML += '</div>';
	
	return sHTML;
}//buildSearchResponse

/**
 * This method is fired when the keydown is pressed of the email-subscribe-input.
 * we will check if the enter key was pressed and if so we will call the subscribeEmail method.
 *
 * @param oEvent:	The event object containing the keycode to test against.
 */
function keydown_subscribeEmail(oEvent)
{
	var eKey = -1;
	if (typeof(oEvent) == "undefined")
	{
		//IE
		eKey = event.keyCode;
	}
	else
	{
		//Firefox...
		eKey = oEvent.keyCode;
	}
	//var eKey = event.keyCode;
	if (eKey == 13)
	{
		subscribeEmail();
	}
}//keydown_subscribeEmail

/**
 * This method will subscribe the given email to the subscribers list.
 */
function subscribeEmail()
{
	var oElement = document.getElementById("txtEmail");
	var sEmail = getHTMLData(oElement);
	
	if (sEmail != "" && isValidEmail(sEmail) == true)
	{
		//create the cross-browser compatible htppRequest.
		var xmlHttpRequest =  new XMLHttpRequest();
		xmlHttpRequest.open('POST', 'http://www.merkkledingwinkels.nl/php/ControllerHandler.php', false);
		
		//set the request data.
		var sRequestData = "sAction2Perform=SEND_SUBSCRIBE_MAIL";
						sRequestData += "&sEmail=" + sEmail;						
		
		//now send the request.
		xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttpRequest.send(sRequestData);
		
		alert("U bent aangemeld!");
		
		//Clean up the form.
		setHTMLData(oElement, "");
	}
	else
	{
		alert("U moet wel een (geldig) e-mail invoeren!");
	}
}//subscribeEmail

/**
 * This method returns the value of the HTML-element. In case of an input-field the 'value' 
 * property is returned. If it's a label the innerText property is returned.
 */
function getHTMLData(htmlElement)
{
    var sReturn = null;
    if (htmlElement != null)
    {
        var sTagName = htmlElement.tagName;
        if (sTagName != null)
        {
            sTagName = sTagName.toUpperCase();
            if (sTagName == "INPUT")
            {
                sReturn = htmlElement.value;
            }
            else if (sTagName == "LABEL")
            {
                sReturn = htmlElement.innerText;
            }
            else if (sTagName == "SELECT")
            {
                sReturn = htmlElement.value;
            }
            else
            {
                sReturn = htmlElement.innerText;
            }
        }
    }
	
	//replace chars.
	if (sReturn != null)
	{
		sReturn = replaceSpecialCharsFromUI(sReturn);
	}
	
    return sReturn;
}//getHTMLData

/**
 * This method sets the value of the HTML-element. In case of an input-field the 'value' 
 * property is set. If it's a label the innerText property is set.
 */
function setHTMLData(htmlElement, sValue)
{
	//replace chars.
	sValue = replaceSpecialCharsToUI(sValue);
	
    if (htmlElement != null)
    {
        var sTagName = htmlElement.tagName;
        if (sTagName != null)
        {
            sTagName = sTagName.toUpperCase();
            if (sTagName == "INPUT")
            {
                htmlElement.value = sValue;
            }
            else if (sTagName == "LABEL")
            {
                htmlElement.innerText = sValue;
            }
            else if (sTagName == "SELECT")
            {
                htmlElement.value = sValue;
            }
            else
            {
                htmlElement.innerText = sValue;
            }
        }
    }
}//setHTMLData

/**
 * This method will replace nice chars to the their numeric char value.
 */
function replaceSpecialCharsFromUI(sValue)
{
	//replace euro chars.
	while (sValue.indexOf("€") != -1) {sValue = sValue.replace("€", "#8364;")};
	//replace & chars.
	while (sValue.indexOf("&") != -1) {sValue = sValue.replace("&", "#38;")};

	return sValue;
}//replaceSpecialCharsFromUI

/**
 * This method will replace special chars to the "nice" char for the interface.
 */
function replaceSpecialCharsToUI(sValue)
{
	//replace euro chars.
	while (sValue.indexOf("#8364;") != -1) {sValue = sValue.replace("#8364;", "€")};
	//replace & chars.
	while (sValue.indexOf("#38;") != -1) {sValue = sValue.replace("#38;", "&")};

	return sValue;
}//replaceSpecialCharsToUI

function loadIndexData()
{
	
	var oPane = top.document.getElementById("divCategories");
	if (oPane != null && oPane.innerHTML == "")
	{
		var sHTML_CATEGORIES_OPTIONS = getUniqueCategoriesHTML("txtSearchByCategory", "Zoek op categorie", true);
		oPane.innerHTML = sHTML_CATEGORIES_OPTIONS;
		var oSelect = top.document.getElementById("txtSearchByCategory");
		if (oSelect != null)
		{
			oSelect.style.width = "160px";
		}
	}
	
	var sHTML_BRANDS_OPTIONS = getUniqueBrandsHTML("txtSearchByBrand", "Zoek op merk", true);
	oPane = top.document.getElementById("divBrands");
	if (oPane != null)
	{
		oPane.innerHTML = sHTML_BRANDS_OPTIONS;
		var oSelect = top.document.getElementById("txtSearchByBrand");
		if (oSelect != null)
		{
			oSelect.style.width = "105px";
		}
	}
}//loadIndexData

/**
 * This method will load page data for the given page id.
 *
 * @param sPageID:	The pageid to get the data for.
 */
function loadPageData(sPageID)
{
	//var sHTML_TOP_FIVE = getPaneHTML(sPageID, "TOP_FIVE");
	var sHTML_TOP_NIEUWS = getPaneHTML(sPageID, "TOP_NIEUWS");
	var sHTML_TOP_LINKS = getPaneHTML(sPageID, "TOP_LINKS");
	var sHTML_MERKEN_SHOPS = getPaneHTML(sPageID, "MERKEN_SHOP");
	var sHTML_OPRUIMING = getPaneHTML(sPageID, "OPRUIMING");
	var sHTML_PAGE_SPECIFIC_DATAFEEDS = getPaneHTML(sPageID, "PAGE_SPECIFIC_DATAFEEDS");

	var sHTML_CATEGORIES_OPTIONS = getUniqueCategoriesHTML();
	
	//var oPanel = document.getElementById("divTopFivePanel");
	//if (oPanel != null)
	//{
	//	oPanel.innerHTML = sHTML_TOP_FIVE;
	//}
	// Set the top five panel for this category.
	/*
	if (sPageID == "HOME_PAGE")
	{
		var sHTML_TOP_FIVE = getTopFiveHTML(-1);

		var oPanel = document.getElementById("divTopFivePanel");
		if (oPanel != null)
		{
			oPanel.innerHTML = sHTML_TOP_FIVE;
		}
	}
	*/
	oPanel = document.getElementById("divTopLinksPanel");
	if (oPanel != null)
	{
		oPanel.innerHTML = sHTML_TOP_LINKS;
	}
	oPanel = document.getElementById("divMerkenShopsPanel");
	if (oPanel != null)
	{
		oPanel.innerHTML = sHTML_MERKEN_SHOPS;
	}
	oPanel = document.getElementById("divTopNieuwsPanel");
	if (oPanel != null)
	{
		oPanel.innerHTML = sHTML_TOP_NIEUWS;
	}
	oPanel = document.getElementById("divOpruimingPanel");
	if (oPanel != null)
	{
		oPanel.innerHTML = sHTML_OPRUIMING;
	}
	oPanel = document.getElementById("divPageSpecificDataFeeds");
	if (oPanel != null)
	{
		oPanel.innerHTML = sHTML_PAGE_SPECIFIC_DATAFEEDS;
	}
	oPanel = document.getElementById("divCategories");
	if (oPanel != null)
	{
		oPanel.innerHTML = sHTML_CATEGORIES_OPTIONS;
	}
	
	if (sPageID == "ALLES_OVER_MERKEN")
	{
		var strSubcategory = getURLParam("subcategory");
		
		if(strSubcategory != "")
		{
			jumpToHardCodedLinks(strSubcategory);
		}
		else
		{
			jumpToHardCodedLinks('MERKEN_OVERZICHT');
			//getPageDetails(null, 'MERKEN_OVERZICHT', 'linked_title', 'title', null, null);
		}
		var sHTML_TOP_FIVE = getTopFiveHTML(-1);

		var oPanel = document.getElementById("divTopFivePanel");
		if (oPanel != null)
		{
			oPanel.innerHTML = sHTML_TOP_FIVE;
		}
	}
	else if (sPageID == "DAMES_MODE" || sPageID == "HEREN_MODE" || sPageID == "BABY_MODE" || sPageID == "KINDER_MODE" || sPageID == "KOOPJESHOEK")
	{
		var strSubcategory = getURLParam("subcategory").toLowerCase();
	
		if(strSubcategory != "")
		{
			getPageDetails(document.getElementById("txtDataFeed_" + strSubcategory), null, g__aiSubCategoryIDs[strSubcategory], aiHeadCategories[sPageID]);
		}
		else
		{
			var sFirstIndex = g__firstDatafeedID.substring(12).toLowerCase();
			getPageDetails(document.getElementById(g__firstDatafeedID), null, g__aiSubCategoryIDs[sFirstIndex], aiHeadCategories[sPageID]);
		}
	}
	
	
	/*if (sPageID == "HOME_PAGE")
	{
		loadIndexData();
	}*/
	
	setHeight();
	
	if (document.location.href.indexOf("searchme") != -1 || document.location.href.indexOf("zoek_merken") != -1)
	{
		//fire event onclick of the search button.
		var oControl = top.document.getElementById("btnSearch");
		if (oControl != null)
		{
			fireClickEvent(oControl);
		}
	}

	//getPageDetailsFromUrl(aoHeadCategories[sPageID]);
}//loadPageData

/**
 * This method will return html for a specific pane.
 *
 * @param sPageID:	The id of the page for the specific pane
 * @param sPane:	The name of the pane to generate html for.
 */
function getPaneHTML(sPageID, sPane)
{
	var sHTML = "";
	var xmlData = getPaneData(sPageID, sPane);
	
	if (sPane == "TOP_FIVE")
	{
		sHTML = '<table cellpadding="0" cellspacing="0" width="150px" class="clsBlueContent_DataContainer">';
					
					var anColumns = xmlData.selectNodes(".//tuple");
					for (var iDataColumn = 0; iDataColumn < anColumns.length; iDataColumn++)
					{
						var oDataColum = anColumns[iDataColumn];
						var nDescriptionNode = oDataColum.selectSingleNode(".//TopVijfBestVerkocht_Description/text()");
						var nUrlNode = oDataColum.selectSingleNode(".//TopVijfBestVerkocht_Url/text()");
						if (nDescriptionNode != null && nUrlNode != null)
						{
							var sDescription = nDescriptionNode.nodeValue;
							var sUrl = nUrlNode.nodeValue;
							sUrl = buildTopFiveURL(sUrl, sDescription)
							sHTML += '<tr>'
										+'<td colspan="3" class="cls_BlueContentData">' + sUrl + '</td>'
									+'</tr>';
						}
					}
				sHTML += '</table>';
	}
	else if (sPane == "TOP_LINKS")
	{
		sHTML = '<table cellpadding="0" cellspacing="0" width="150px" class="clsBlueContent_DataContainer">';
					
					var anColumns = xmlData.selectNodes(".//tuple");
					for (var iDataColumn = 0; iDataColumn < anColumns.length; iDataColumn++)
					{
						var oDataColum = anColumns[iDataColumn];
						var nDescriptionNode = oDataColum.selectSingleNode(".//TopShops_Description/text()");
						var nToevoegingNode = oDataColum.selectSingleNode(".//TopShops_Toevoeging/text()");
						var nUrlNode = oDataColum.selectSingleNode(".//TopShows_Link/text()");
						if (nDescriptionNode != null && nUrlNode != null)
						{
							var sDescription = nDescriptionNode.nodeValue;
							var sUrl = nUrlNode.nodeValue;
							buildAnyUrl(sUrl);
							sHTML += '<tr>'
										+'<td colspan="3" class="cls_BlueContentData"><a target="_blank" href="' + sUrl + '" rel="nofollow">' + sDescription;
										if (nToevoegingNode != null)
										{
											sHTML += '<font color="red"> ' + nToevoegingNode.nodeValue + '</font></a>';
										}
										else
										{
											sHTML += '</a>';
										}
										sHTML += '</td>'
									+'</tr>';
						}
					}
				sHTML += '</table>';
	}
	else if (sPane == "MERKEN_SHOP")
	{
		sHTML = '<table cellpadding="0" cellspacing="0" width="150px" class="clsBlueContent_DataContainer">';
					var temp_xmlData = getPaneData('LOGOS_MERKEN_SHOPS');
					var anColumns = temp_xmlData.selectNodes(".//tuple");
					for (var iDataColumn = 0; iDataColumn < anColumns.length; iDataColumn++)
					{
						/*sHTML += '<tr>'
									+'<td colspan="3" class="cls_BlueContentData_Logo">'
										+'<table cellpadding="0" cellspacing="0" ><tr>';
										
						var oFirstDataColum = anColumns[iDataColumn];
						var oSecondDataColum = anColumns[1 + iDataColumn];
						if (oFirstDataColum != null)
						{
							var nLogoUrlNode = oFirstDataColum.selectSingleNode(".//LogoURL/text()");
							var nLogoLinkNode = oFirstDataColum.selectSingleNode(".//LogoLink/text()");
							if (nLogoUrlNode != null && nLogoLinkNode != null)
							{
								var sFirstLogoURL = nLogoUrlNode.nodeValue;
								var sFirstLogoLink = nLogoLinkNode.nodeValue;
								sHTML += '<td><a target="_blank" href="' + sFirstLogoLink + '">'
											+'<img border="0" src="' + sFirstLogoURL + '" /></a></td>';
							}
						}
						if (oSecondDataColum != null)
						{
							var nLogoUrlNode = oSecondDataColum.selectSingleNode(".//LogoURL/text()");
							var nLogoLinkNode = oSecondDataColum.selectSingleNode(".//LogoLink/text()");
							if (nLogoUrlNode != null && nLogoLinkNode != null)
							{
								var sSecondLogoURL = nLogoUrlNode.nodeValue;
								var sSecondLogoLink = nLogoLinkNode.nodeValue;
								sHTML += '<td align="right"><a target="_blank" href="' + sSecondLogoLink + '">'
											+'<img border="0" src="' + sSecondLogoURL + '" /></a></td>';
							}
						}			
						sHTML +='</tr></table></td></tr>';
								
						iDataColumn++; //two logo's are handle per loop*/
						
						var oDataColum = anColumns[iDataColumn];
						var nLogoUrlNode = oDataColum.selectSingleNode(".//LogoURL/text()").nodeValue;
						var nLogoLinkNode = oDataColum.selectSingleNode(".//LogoLink/text()").nodeValue;
							
						sHTML += '<tr>';
							sHTML += '<td colspan="3" class="cls_BlueContentData_Logo" align="center">';
								sHTML += '<a target="_blank" href="' + nLogoLinkNode + ' "rel="nofollow"><img border="0" src="' + nLogoUrlNode + '" /></a>';
							sHTML += '</td>';
						sHTML += '</tr>';
					}
				sHTML += '</table>';
	}
	else if (sPane == "TOP_NIEUWS")
	{
		sHTML = '<table cellpadding="0" cellspacing="0" width="150px" class="clsBlueContent_DataContainer">';
					
					var anColumns = xmlData.selectNodes(".//tuple");
					for (var iDataColumn = 0; iDataColumn < anColumns.length; iDataColumn++)
					{
						var oDataColum = anColumns[iDataColumn];
						var nTitleNode = oDataColum.selectSingleNode(".//TopNieuws_Title/text()");
						var nUrlNode = oDataColum.selectSingleNode(".//TopNieuws_Link/text()");
						if (nTitleNode != null && nUrlNode != null)
						{
							var sTitle = nTitleNode.nodeValue;
							var sUrl = nUrlNode.nodeValue;
							sUrl = buildAnyUrl(sUrl);
							sHTML += '<tr>'
										//+'<td colspan="3" class="cls_BlueContentData"><a target="_blank" href="' + sUrl + '">' + sTitle + '</a></td>'
										+'<td colspan="3" class="cls_BlueContentData"><a href="http://www.merkkledingwinkels.nl/?page==alles_over_merken.php&subcategory=NIEUWS_OVERZICHT" target="_parent">' + sTitle + '</a></td>'
										//+'<td colspan="3" class="cls_BlueContentData cls_LinkCell" onclick="loadNewPage(\'alles_over_merken.php?subcategory=NIEUWS_OVERZICHT\');">' + sTitle + '</td>'
									+'</tr>';
						}
					}
				sHTML += '</table>';
	}
	else if (sPane == "OPRUIMING")
	{
		sHTML = '<table cellpadding="0" cellspacing="0" width="150px" class="clsBlueContent_DataContainer">';
					
					var anColumns = xmlData.selectNodes(".//tuple");
					for (var iDataColumn = 0; iDataColumn < anColumns.length; iDataColumn++)
					{
						var oDataColum = anColumns[iDataColumn];
						var nDescriptionNode = oDataColum.selectSingleNode(".//Opruiming_Description/text()");
						var nToevoegingNode = oDataColum.selectSingleNode(".//Opruiming_Toevoeging/text()");
						var nUrlNode = oDataColum.selectSingleNode(".//Opruiming_Url/text()");
						if (nUrlNode != null)
						{
							var sUrl = buildOpruimingURL(nUrlNode.nodeValue);
							sHTML += '<tr>'
										+'<td colspan="3" class="cls_YellowContentData">' + sUrl;
										if (nToevoegingNode != null)
										{
											sHTML += '<font color="red"> ' + nToevoegingNode.nodeValue + '</font>';
										}
										sHTML += '</td>'
									+'</tr>';
						}
					}
				sHTML += '</table>';
	}
	else if (sPageID != "HOME_PAGE" && sPane == "PAGE_SPECIFIC_DATAFEEDS") //Homepage doesn't have datafeeds for this pane.
	{
		sHTML = getPageSpecificDataFeedsPanel(sPageID, xmlData);
	}
	else if (sPageID == "HOME_PAGE" && sPane == "PAGE_SPECIFIC_DATAFEEDS")
	{
		sHTML = getPageSpecificDataFeedsPanelForHomePage(xmlData);
	}
	
	return sHTML;
}//getPaneHTML

function buildOpruimingURL(sURLHTML)
{
	var sReturn = sURLHTML;
	
	if (sURLHTML.toUpperCase().indexOf("<A HREF") == -1)
	{
		//No <a href tag found.
		sReturn = '<a href="' + sURLHTML + '" target="_blank">Opruiming! </a>';
	}
	
	return sReturn;
}//buildOpruimingURL

function buildTopFiveURL(sURLHTML, sDescription)
{
	var sReturn = sURLHTML;
	
	if (sURLHTML.toUpperCase().indexOf("<A HREF") == -1)
	{
		//No <a href tag found.
		sReturn = '<a href="' + sURLHTML + '" target="_blank">' + sDescription + '</a>';
	}
	
	return sReturn;
}//buildTopFiveURL

function buildAnyUrl(sURLHTML)
{
	var sReturn = sURLHTML;
	
	if (sURLHTML.toUpperCase().indexOf("HTTP://") == -1)
	{
		//No <a href tag found.
		sReturn = 'http://' + sURLHTML;
	}
	
	return sReturn;
}//buildAnyUrl

/**
 * This method will get the pane-data from the backend.
 * It will call the backend with the specified page id.
 *
 * @param sPageID:	The id of the page to get data for
 * @param sPane:	The name of the pane to get data for.
 */
var g_aoPaneDataStore = new Array();
function getPaneData(sPageID, sPane)
{
	if (typeof(g_aoPaneDataStore[sPageID]) == "undefined")
	{
		//Fetch data fresh from the backend
	
		//create the cross-browser compatible htppRequest.
		var xmlHttpRequest =  new XMLHttpRequest();
		xmlHttpRequest.open('POST', 'http://www.merkkledingwinkels.nl/php/ControllerHandler.php', false);
		
		//set the request data.
		var sCategoryID = '';
		if (g_iCurrentCategory != null)
		{
			sCategoryID = '&iCategoryID=' + g_iCurrentCategory;
		}
		var sRequestData = "sAction2Perform=GET_PAGE_DATA&PAGE_ID=" + sPageID + sCategoryID;
		
		//now send the request.
		xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttpRequest.send(sRequestData);
		
		xmlReturn = xmlHttpRequest.responseXML;
		g_aoPaneDataStore[sPageID] = xmlReturn;
	}
	else
	{
		xmlReturn = g_aoPaneDataStore[sPageID];
	}
	
	return xmlReturn;
}//getPaneData

/**
 * This method will get the data feeds data from the backend.
 * It will call the backend with the specified category id and parent category id.
 *
 * @param sCategoryID:		The id of the category to get data for
 * @param sParentCategoryID:	The parent-category-id of the category to get data for.
 */
var g_sCategoryID = null;
var g_sParentCategoryID = null;
var g_iUIDatafeedsCursor = 0;
var g_iUIDatafeedsMaxCursor = 0;
function getDatafeedsData(sCategoryID, sParentCategoryID, sType)
{
	if (sCategoryID == null && sParentCategoryID == null)
	{
		sCategoryID = g_sCategoryID;
		sParentCategoryID = g_sParentCategoryID;
	}
	else
	{
		g_sCategoryID = sCategoryID;
		g_sParentCategoryID = sParentCategoryID;
	}
	
	var sTempUniqueID = sCategoryID + "_" + sParentCategoryID + "_" + g_iDatafeedsCursor;
	
	if (typeof(sType) == "undefined")
	{
		sType = null;
	}
	setDatafeedsCursor(sType);
	
	
	//Always fetch data fresh from the backend

	//create the cross-browser compatible htppRequest.
	var xmlHttpRequest =  new XMLHttpRequest();
	xmlHttpRequest.open('POST', 'http://www.merkkledingwinkels.nl/php/ControllerHandler.php', false);
	
	//set the request data.
	var sRequestData = "sAction2Perform=GET_DATA_FEEDS&CATEGORY_ID=" + sCategoryID + "&PARENT_CATEGORY_ID=" + sParentCategoryID;
	sRequestData += '&iMinCursor= ' + g_iDatafeedsCursor + '&iMaxCursor=10';
	g_iUIDatafeedsCursor = 1 + g_iDatafeedsCursor;
	g_iUIDatafeedsMaxCursor = 9 + g_iUIDatafeedsCursor;
	if (g_iDatafeedTotal != 0 && g_iUIDatafeedsMaxCursor > g_iDatafeedTotal)
	{
		g_iUIDatafeedsMaxCursor = g_iDatafeedTotal;
	}
	
	//now send the request.
	xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttpRequest.send(sRequestData);
	
	xmlReturn = xmlHttpRequest.responseXML;
	g_aoPaneDataStore[sTempUniqueID] = xmlReturn;
	
	try
	{
		//get the total.
		var nTotal = xmlReturn.selectSingleNode(".//TOTAL/text()");
		if (nTotal != null && g_iDatafeedTotal == 0)
		{
			var sTotal = nTotal.nodeValue;
			g_iDatafeedTotal = parseInt(sTotal, 10);
			setDatafeedsCursor(sType);
		}
	}
	catch (eFailed) { /* ignore */ }
	
	// Set the top five panel for this category.
	var sHTML_TOP_FIVE = getTopFiveHTML(sCategoryID);

	var oPanel = document.getElementById("divTopFivePanel");
	if (oPanel != null)
	{
		oPanel.innerHTML = sHTML_TOP_FIVE;
	}
	
	return xmlReturn;
}//getDatafeedsData

function getTopFiveHTML(sCategoryID)
{
	//create the cross-browser compatible htppRequest.
	var xmlHttpRequest =  new XMLHttpRequest();
	xmlHttpRequest.open('POST', 'http://www.merkkledingwinkels.nl/php/ControllerHandler.php', false);
	
	//set the request data.
	var sRequestData = "sAction2Perform=GET_DATA&sqlQueryID=TOP_FIVE&iCategoryID=" + sCategoryID;
	
	//now send the request.
	xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttpRequest.send(sRequestData);
	
	xmlData = xmlHttpRequest.responseXML;
	
	// Create the HTML.
	sHTML = '<table cellpadding="0" cellspacing="0" width="150px" class="clsBlueContent_DataContainer">';
					
		var anColumns = xmlData.selectNodes(".//tuple");
		for (var iDataColumn = 0; iDataColumn < anColumns.length; iDataColumn++)
		{
			var oDataColum = anColumns[iDataColumn];
			var nDescriptionNode = oDataColum.selectSingleNode(".//TopVijfBestVerkocht_Description/text()");
			var nUrlNode = oDataColum.selectSingleNode(".//TopVijfBestVerkocht_Url/text()");
			if (nDescriptionNode != null && nUrlNode != null)
			{
				var sDescription = nDescriptionNode.nodeValue;
				var sUrl = nUrlNode.nodeValue;
				sUrl = buildTopFiveURL(sUrl, sDescription)
				sHTML += '<tr>'
							+'<td colspan="3" class="cls_BlueContentData">' + sUrl + '</td>'
						+'</tr>';
			}
		}
	sHTML += '</table>';
	
	return sHTML;
}//getTopFiveHTML

var g_iDatafeedsCursor = 0;
var g_iDatafeed_iMaxCursor = 0;
var g_iDatafeedTotal = 0;
function setDatafeedsCursor(sType)
{
	if (typeof(g_iDatafeedsCursor) == "undefined")
	{
		g_iDatafeedsCursor = 0;
	}
	if (sType != null)
	{
		if (sType == "NEXT")
		{
			if (10 + g_iDatafeedsCursor > g_iDatafeedTotal)
			{
				g_iDatafeedsCursor = 0;
			}
			else
			{
				g_iDatafeedsCursor += 10;
			}
		}
		else
		{
			if (g_iDatafeedsCursor >= 10)
			{
				g_iDatafeedsCursor -= 10;
			}
		}
	}
	//Update max cursor.
	if (10 + g_iDatafeedsCursor >= g_iDatafeedTotal)
	{
		//Maximum is itotal.
		g_iDatafeed_iMaxCursor = g_iDatafeedTotal;
	}
	else
	{
		g_iDatafeed_iMaxCursor = 10 + g_iDatafeedsCursor;
	}
}//setDatafeedsCursor

function getUniqueCategoriesHTML(sSelectID, sDummyOption, bFromHome)
{
	if (typeof(sSelectID) == "undefined")
	{
		sSelectID = "txtGeintereseerd";
	}
	if (typeof(sDummyOption) == "undefined")
	{
		sDummyOption = "Kies categorie";
	}
	var sHTML = '<select class="cls_Options" style="width:100%;" id="' + sSelectID + '"><option value="-1">' + sDummyOption + '</option>';
	
	var xmlCategories = getUniqueCategories(bFromHome);
	var anColumns = xmlCategories.selectNodes(".//tuple");
	for (var iDataColumn = 0; iDataColumn < anColumns.length; iDataColumn++)
	{
		var oDataColum = anColumns[iDataColumn];
		var nDescriptionNode = oDataColum.selectSingleNode(".//description/text()");
		var nMainCategory = oDataColum.selectSingleNode(".//main_category_id/text()");
		var nSubCategory = oDataColum.selectSingleNode(".//sub_category_id/text()");
		
		if (nDescriptionNode != null && nMainCategory != null && nSubCategory != null)
		{
			var sDescription = nDescriptionNode.nodeValue;
			var sMainCategory = nMainCategory.nodeValue;
			var sSubCategory = nSubCategory.nodeValue;
			sHTML += '<option value="' + sDescription + '" main_category="' + sMainCategory + '" sub_category="' + sSubCategory + '">' + sDescription + '</option>';
		}
	}

	sHTML += '</select>';
	
	return sHTML;
}//getUniqueCategoriesHTML

function getUniqueCategories(bFromHome)
{
	var sTempUniqueID = "__ALL_CATEGORIES";
	if (typeof(g_aoPaneDataStore[sTempUniqueID]) == "undefined")
	{
		//Fetch data fresh from the backend
	
		//create the cross-browser compatible htppRequest.
		var xmlHttpRequest =  new XMLHttpRequest();
		if (typeof(bFromHome) != "undefined" && bFromHome == true)
		{
			xmlHttpRequest.open('POST', 'php/ControllerHandler.php', false);
		}
		else
		{
			xmlHttpRequest.open('POST', '../php/ControllerHandler.php', false);
		}
		
		//set the request data.
		var sRequestData = "sAction2Perform=GET_DATA&sqlQueryID=GET_UNIQUE_CATEGORIES";
		
		//now send the request.
		xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttpRequest.send(sRequestData);
		
		xmlReturn = xmlHttpRequest.responseXML;
		g_aoPaneDataStore[sTempUniqueID] = xmlReturn;
	}
	else
	{
		xmlReturn = g_aoPaneDataStore[sTempUniqueID];
	}
	
	return xmlReturn;
}//getUniqueCategories

function getUniqueBrandsHTML(sSelectID, sDummyOption, bFromHome)
{
	if (typeof(sSelectID) == "undefined")
	{
		sSelectID = "txtBrands";
	}
	if (typeof(sDummyOption) == "undefined")
	{
		sDummyOption = "Kies merk";
	}
	var sHTML = '<select class="cls_Options" style="width:100%;" id="' + sSelectID + '"><option value="-1">' + sDummyOption + '</option>';
	
	var xmlBrands = getUniqueBrands(bFromHome);
	var anColumns = xmlBrands.selectNodes(".//tuple");
	for (var iDataColumn = 0; iDataColumn < anColumns.length; iDataColumn++)
	{
		var oDataColum = anColumns[iDataColumn];
		var nIDNode = oDataColum.selectSingleNode(".//id/text()");
		var nDescriptionNode = oDataColum.selectSingleNode(".//leverancier/text()");
		
		if (nIDNode != null && nDescriptionNode != null)
		{
			var sDescription = nDescriptionNode.nodeValue;
			var sID = nIDNode.nodeValue;
			sHTML += '<option value="' + sID + '">' + replaceSpecialCharsToUI(sDescription) + '</option>';
		}
	}

	sHTML += '</select>';
	
	return sHTML;
}//getUniqueBrandsHTML

function getUniqueBrands(bFromHome)
{
	var sTempUniqueID = "__ALL_BRANDS";
	if (typeof(g_aoPaneDataStore[sTempUniqueID]) == "undefined")
	{
		//Fetch data fresh from the backend
	
		//create the cross-browser compatible htppRequest.
		var xmlHttpRequest =  new XMLHttpRequest();
		if (typeof(bFromHome) != "undefined" && bFromHome == true)
		{
			xmlHttpRequest.open('POST', 'php/ControllerHandler.php', false);
		}
		else
		{
			xmlHttpRequest.open('POST', '../php/ControllerHandler.php', false);
		}
		
		//set the request data.
		var sRequestData = "sAction2Perform=GET_DATA&sqlQueryID=GET_UNIQUE_BRANDS_FOR_SEARCH";
		
		//now send the request.
		xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttpRequest.send(sRequestData);
		
		xmlReturn = xmlHttpRequest.responseXML;
		g_aoPaneDataStore[sTempUniqueID] = xmlReturn;
	}
	else
	{
		xmlReturn = g_aoPaneDataStore[sTempUniqueID];
	}
	
	return xmlReturn;
}//getUniqueBrands

function getUniqueLeveranciers()
{
	var sTempUniqueID = "__ALL_LEVERANCIERS";
	if (typeof(g_aoPaneDataStore[sTempUniqueID]) == "undefined")
	{
		//Fetch data fresh from the backend
	
		//create the cross-browser compatible htppRequest.
		var xmlHttpRequest =  new XMLHttpRequest();
		xmlHttpRequest.open('POST', '../php/ControllerHandler.php', false);
		
		//set the request data.
		var sRequestData = "sAction2Perform=GET_DATA&sqlQueryID=GET_UNIQUE_BRANDS";
		
		//now send the request.
		xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttpRequest.send(sRequestData);
		
		xmlReturn = xmlHttpRequest.responseXML;
		g_aoPaneDataStore[sTempUniqueID] = xmlReturn;
	}
	else
	{
		xmlReturn = g_aoPaneDataStore[sTempUniqueID];
	}
	
	return xmlReturn;
}//getUniqueLeveranciers

function getLeverancier(sLeverancierName, anLeveranciers)
{
	var sReturn = "";
	
	var anNodes = anLeveranciers.selectNodes(".//tuple");
	for (var iCount = 0; iCount < anNodes.length; iCount++)
	{
		if (anNodes[iCount].selectSingleNode(".//id/text()").nodeValue == sLeverancierName)
		{
			sReturn = anNodes[iCount].selectSingleNode(".//leverancier/text()").nodeValue;
			break;
		}
	}
	
	return sReturn;
}//getLeverancier

/**
 * This method will return a specific data-feeds panel html for the specified page.
 *
 * @param sPageID 	The page to get the feeds data-html for.
 * @param	xmlData	The xml containing the data to use.
 */
function getPageSpecificDataFeedsPanel(sPageID, xmlData)
{
	var sPageSpecificHeaderText;
	var sHTMLDataContent;
	
	//Build up the header text.
	if (sPageID == "ALLES_OVER_MERKEN" || sPageID == "KOOPJESHOEK")
	{
		sPageSpecificHeaderText = 'Merken';
	}
	else if (sPageID == "DAMES_MODE")
	{
		sPageSpecificHeaderText = 'Damesmode';
	}
	else if (sPageID == "HEREN_MODE")
	{
		sPageSpecificHeaderText = 'Herenmode';
	}
	else if (sPageID == "KINDER_MODE")
	{
		sPageSpecificHeaderText = 'Kindermode';
	}
	else if (sPageID == "BABY_MODE")
	{
		sPageSpecificHeaderText = 'Babymode';
	}
	else if (sPageID == "CONTACT")
	{
		sPageSpecificHeaderText = 'Contact';
	}
	
	//Build up the body text.
	
	//If the page is contact, merken, or koopjeshoek we have "hard-code" specific links.
	//for all other pages the categories are used to build up the body-text/links dynamically.
	if (sPageID == "CONTACT" || sPageID == "ALLES_OVER_MERKEN")
	{
		sHTMLDataContent = getHardCodedLinksForDataFeedsPanel(sPageID, xmlData);
	}
	else
	{
		var iCategoryTotalCount = 0;
		sHTMLDataContent = '<table cellpadding="0" cellspacing="0" width="150px" class="clsOrangeContent_DataContainer">';
		var bFirstElement = true;
		var anColumns = xmlData.selectNodes(".//tuple");
		for (var iDataColumn = 0; iDataColumn < anColumns.length; iDataColumn++)
		{
			var sID = "";
			var oDataColum = anColumns[iDataColumn];
			var nCategoryDescriptionNode = oDataColum.selectSingleNode(".//Category_Description/text()");
			var nCategoryIDNode = oDataColum.selectSingleNode(".//Category_ID/text()");
			var nCategoryParentNode = oDataColum.selectSingleNode(".//Category_Parent/text()");
			var nCountNode = oDataColum.selectSingleNode(".//Total/text()");
			if (nCategoryDescriptionNode != null && nCategoryIDNode != null && nCategoryParentNode != null)
			{
				var sCategoryDescription = nCategoryDescriptionNode.nodeValue;
				var sCategoryID = nCategoryIDNode.nodeValue;
				var sCategoryParent = nCategoryParentNode.nodeValue;
				var sCountForCategory = nCountNode.nodeValue;
				iCategoryTotalCount += parseInt(sCountForCategory, 10);
				
				sID = "txtDataFeed_" + sCategoryDescription;
				if (bFirstElement == true)
				{
					bFirstElement = false;					
					g__firstDatafeedID = sID;
				}
				sHTMLDataContent += '<tr>'
										+'<td id="' + sID + '" colspan="3" class="cls_OrangeContentData"><a href="http://www.merkkledingwinkels.nl/?page==' + g__asMainCategoryNames[sPageID] + '&subcategory=' + encodeURIComponent(sCategoryDescription) + '" target="_parent" style="Color: black;">' + sCategoryDescription + ' (' + sCountForCategory + ')</td>'
									+'</tr>';
			}
		}
		sHTMLDataContent += '</table>';
	}
	
	var sCategoryTotalCount = "";
	if (typeof(iCategoryTotalCount) != "undefined" && iCategoryTotalCount != null && iCategoryTotalCount != undefined)
	{
		sCategoryTotalCount = '(' + iCategoryTotalCount.toString() + ')';
	}
	
	//Append all text to one html-blob.
	var sContainerHTML = '<table cellpadding="0" cellspacing="0" width="150px">'
							+'<tr>'
								+'<td class="cls_OrangeContentLeftCorner"></td>'
								+'<td class="cls_OrangeContent">' + sPageSpecificHeaderText + '<font size="0.001em"><small> 	' + sCategoryTotalCount + '</small></font></td>'
								+'<td class="cls_OrangeContentRightCorner"></td>'
							+'</tr>'
							+'<tr>'
								+'<td colspan="3">'
									+'<div id="divLeftTopDatafeedsPanel">'
										+ sHTMLDataContent
									+'</div>'
								+'</td>'
							+'</tr>'
						+'</table>';
	
	return sContainerHTML;
}//getPageSpecificDataFeedsPanel

/**
 * This method will return the datafeeds content for the hardcode pages.
 *
 * @param sPageID	The hardcoded pageid to get the data for.
 */
function getHardCodedLinksForDataFeedsPanel(sPageID, xmlData)
{
	var sHTML = '';
	
	if (sPageID == "ALLES_OVER_MERKEN" || sPageID == "KOOPJESHOEK")
	{
		var iCountMerken = xmlData.selectSingleNode(".//CountMerken/text()").nodeValue;
		var iCountOpruimingMerken = xmlData.selectSingleNode(".//CountOpruimingMerken/text()").nodeValue;
		var iCountMerkenNieuws = xmlData.selectSingleNode(".//CountNieuwsLinks/text()").nodeValue;
		var iCountMerkenShops = xmlData.selectSingleNode(".//CountMerkenShops/text()").nodeValue;
		
		sHTML = '<table cellpadding="0" cellspacing="0" width="150px" class="clsOrangeContent_DataContainer">'
					+'<tr><td colspan="3" id="txtHardCodedPage_MERKEN_OVERZICHT" class="cls_OrangeContentData"><a href="http://www.merkkledingwinkels.nl/?page==alles_over_merken.php&subcategory=MERKEN_OVERZICHT" target="_parent" style="Color: black;">Merkenoverzicht (' + iCountMerken + ')</a></td></tr>'
					+'<tr><td colspan="3" id="txtHardCodedPage_NIEUWS_OVERZICHT" class="cls_OrangeContentData"><a href="http://www.merkkledingwinkels.nl/?page==alles_over_merken.php&subcategory=NIEUWS_OVERZICHT" target="_parent" style="Color: black;">Merken nieuws (' + iCountMerkenNieuws + ')</a></td></tr>'
					/*+'<tr><td colspan="3" id="txtHardCodedPage_MERKEN_SHOPS_OVERZICHT" class="cls_OrangeContentData" onclick="getPageDetails(this, \'MERKEN_SHOPS_OVERZICHT\', \'linked_title\', \'title\', null, null);">Merkenshops (' + iCountMerkenShops + ')</td></tr>'*/
					+'<tr><td colspan="3" id="txtHardCodedPage_MEEST_GESTELDE_VRAGEN" class="cls_OrangeContentData"><a href="http://www.merkkledingwinkels.nl/?page==alles_over_merken.php&subcategory=MEEST_GESTELDE_VRAGEN" target="_parent" style="Color: black;">Meest gestelde vragen</a></td></tr>'
					+'<tr><td colspan="3" id="txtHardCodedPage_TIPS_EN_TRICS" class="cls_OrangeContentData"><a href="http://www.merkkledingwinkels.nl/?page==alles_over_merken.php&subcategory=TIPS_EN_TRICS" target="_parent" style="Color: black;">Tips & Trics</a></td></tr>'
					+'</tr>'
				+'</table>';
	}
	else if (sPageID == "CONTACT")
	{
		sHTML = '<table cellpadding="0" cellspacing="0" width="150px" class="clsOrangeContent_DataContainer">'
					+'<tr><td colspan="3" class="cls_OrangeContentData" onclick="getPageDetails(this, \'EmailNieuwsbrief.php\');">E-mail nieuwsbrief</td></tr>'
					+'<tr><td colspan="3" class="cls_OrangeContentData" onclick="getPageDetails(this, \'TipDeWebmaster.php\');">Tip de webmaster</td></tr>'
					+'<tr><td colspan="3" class="cls_OrangeContentData" onclick="getPageDetails(this, \'Contactgegevens.php\');">Contactgegevens</td></tr>'
					+'<tr><td colspan="3" id="txtOpenedLink" class="cls_OrangeContentData_Clicked" onclick="getPageDetails(this, \'StelEeenVraag.php\');">Stel een vraag</td></tr>'
					+'<tr><td colspan="3" class="cls_OrangeContentData" onclick="getPageDetails(this, \'MEEST_GESTELDE_VRAGEN\',  \'title\', \'title\', \'description\', null);">Meest gestelde vragen</td></tr>'
					+'</tr>'
				+'</table>';
	}
	
	return sHTML;
}//getHardCodedLinksForDataFeedsPanel

/**
 * This method will jump to one of the hardcoded pages.
 *
 */
function jumpToHardCodedLinks(sLink)
{
	if (sLink.toUpperCase() == 'MERKEN_OVERZICHT')
	{
		getPageDetails(document.getElementById('txtHardCodedPage_' + sLink), 'MERKEN_OVERZICHT', 'linked_title', 'title', null, null);
	}
	else if (sLink.toUpperCase() == 'NIEUWS_OVERZICHT')
	{
		getPageDetails(document.getElementById('txtHardCodedPage_' + sLink), 'NIEUWS_OVERZICHT', 'link_title', 'title', 'description', null);
	}
	else if (sLink.toUpperCase() == 'MEEST_GESTELDE_VRAGEN')
	{
		getPageDetails(document.getElementById('txtHardCodedPage_' + sLink), 'MEEST_GESTELDE_VRAGEN', 'title', 'title', 'description', null);
	}
	else if (sLink.toUpperCase() == 'TIPS_EN_TRICS')
	{
		getPageDetails(document.getElementById('txtHardCodedPage_' + sLink), 'TIPS_EN_TRICS', 'title', 'description', 'description', null);
	}
}//jumpToHardCodedLinks

/**
 * This method will fetch pagedetails for a datafeeds link.
 * 
 * @param oSourceObject:	The source object clicked.
 */
var g_PreviousClickedDatafeedsLink = null;
var g_iCurrentCategory = null;
function getPageDetails (oSourceObject, sPage2Load, sTitle, sColumnSort, sDescription, sURL)
{
	if (sPage2Load != null)
	{
		LOG("Openen van pagina", sPage2Load, "", "");
	}
	else
	{
		var sCategoryID = sTitle;
		var sParentCategoryID = sColumnSort;
		
		var sCategoryDetails = sCategoryID;
		
		var xmlCategories = getUniqueCategories();
		var anColumns = xmlCategories.selectNodes(".//tuple");
		for (var iDataColumn = 0; iDataColumn < anColumns.length; iDataColumn++)
		{
			var oDataColum = anColumns[iDataColumn];
			var nDescriptionNode = oDataColum.selectSingleNode(".//description/text()");
			var nMainCategory = oDataColum.selectSingleNode(".//main_category_id/text()");
			var nSubCategory = oDataColum.selectSingleNode(".//sub_category_id/text()");
			
			if (nSubCategory.nodeValue == sCategoryID)
			{
				//we found the proper category.
				sCategoryDetails = nDescriptionNode.nodeValue;
			}
		}
		LOG("Openen van categorie", sCategoryDetails, "", "");
	}
	
	if (isNaN(parseInt(sTitle, 10)) == false)
	{
		g_iCurrentCategory = parseInt(sTitle, 10);
	}
	else
	{
		g_iCurrentCategory = null;
	}
	
	if (oSourceObject != null)
	{
		//See if this is the first time
		var oTestLink = document.getElementById("txtOpenedLink");
		if (g_PreviousClickedDatafeedsLink == null && oTestLink != null)
		{
			if (oTestLink.className == "cls_OrangeContentData_Clicked")
			{
				g_PreviousClickedDatafeedsLink = oTestLink;
			}
		}
		//Update style class of the td and update the previous td-clicked-classname
		if (g_PreviousClickedDatafeedsLink != null)
		{
			g_PreviousClickedDatafeedsLink.className = "cls_OrangeContentData";
		}
		if (oSourceObject == null)
		{
			oSourceObject = oTestLink;
		}
		oSourceObject.className = "cls_OrangeContentData_Clicked";
		g_PreviousClickedDatafeedsLink = oSourceObject;
	}
	if (typeof (sPage2Load) != "undefined" && sPage2Load != null)
	{
		//load specific page
		loadNewInnerPage(sPage2Load, sTitle, sColumnSort, sDescription, sURL);
	}
	else if (typeof (sPage2Load) != "undefined" && sPage2Load == null)
	{
		//reset cursors
		g_iDatafeedsCursor = 0;
		g_iDatafeed_iMaxCursor = 0;
		g_iDatafeedTotal = 0;
		buildGeneralPanelForDataFeeds(oSourceObject, sTitle, sColumnSort, null);
	}
	//Update main container with proper page or redirect to datafeeds-site.
	//TODO implement loading of datafeeds or subpage
	setHeight();
}//getPageDetails

/**
 * This method will parse the URL and set the iframe page if nessecary.
 *
 */
function getPageDetailsFromUrl(iHeadCategoryID)
{
	var strSubcatory = getURLParam("subcategory");
	
	if(strSubcatory != "")
	{
		getPageDetails(null, null, parseInt(strSubcatory, 10), iHeadCategoryID);
	}
}//parseUrl

function loadNewInnerPage(sPage2Load, sTitle, sColumnSort, sDescription, sURL, xmlData)
{
	var xmlData = getPaneData(sPage2Load);
	var sHTML = buildGeneralPanelForCustomContent(sColumnSort, sTitle, sDescription, sURL, xmlData);
	document.getElementById("divGeneralContent").innerHTML = sHTML;
}//loadNewInnerPage

function datafeedsPrevious(sCategoryID, sCategoryParent)
{
	buildGeneralPanelForDataFeeds(null, sCategoryID, sCategoryParent, "PREVIOUS");
}//datafeedsPrevious

function datafeedsNext(sCategoryID, sCategoryParent)
{
	buildGeneralPanelForDataFeeds(null, sCategoryID, sCategoryParent, "NEXT");
}//datafeedsNext

/**
 * This method will build up the general data feeds panel (center of the ui beneath the banner)
 * It will first fetch the data feeds for the specific sub-category. After that it will build up the ui
 * for each data feed.
 *
 * @param oSourceObject		The sourceobject calling the method.
 * @param sCategoryID		The category id.
 * @param sCategoryParent		The parent category id.
 */
function buildGeneralPanelForDataFeeds(oSourceObject, sCategoryID, sCategoryParent, sType)
{
	var xmlDataFeeds = getDatafeedsData(sCategoryID, sCategoryParent, sType);
	var sHTML = '';
	
	//Add cursor
	sHTML += buildDatafeedsCursor("UPPER", sCategoryID, sCategoryParent);
	
	var anLeveranciers = getUniqueLeveranciers();
	var anNodes = xmlDataFeeds.selectNodes(".//tuple");
	for (var iNode = 0; iNode < anNodes.length; iNode++)
	{
		try
		{
			var sLeverancierName = anNodes[iNode].selectSingleNode(".//fk_leverancier_id/text()").nodeValue;
			sLeverancierName = getLeverancier(sLeverancierName, anLeveranciers);
			var sPrice = anNodes[iNode].selectSingleNode(".//prijs/text()").nodeValue;
			var sSmallPrice = anNodes[iNode].selectSingleNode(".//prijs2/text()").nodeValue;
			var sTitle = anNodes[iNode].selectSingleNode(".//titel/text()").nodeValue;
			var sDescription = anNodes[iNode].selectSingleNode(".//omschrijving/text()").nodeValue;
			
			if (sTitle.length > 14)
			{
				sTitle = sTitle.substring(0, 17) + "...";
			}
			var sImageLocation = anNodes[iNode].selectSingleNode(".//foto/text()").nodeValue;
			var sUrlLocation = anNodes[iNode].selectSingleNode(".//url/text()").nodeValue;
			
			var sAdditionalFeatures = "&4dsid=5540&4dkn=merkkledingwinkelssite&4dadvn=" + sLeverancierName;
			sUrlLocation += sAdditionalFeatures;

			var sSpacer = "";
			if (sSmallPrice == "0" || sSmallPrice == sPrice || sSmallPrice == "" || sSmallPrice == null)
			{
				sSmallPrice = "";
			}
			else
			{
				sSmallPrice = "&#8364;" + formatPrice(sSmallPrice);
				sSpacer = "&nbsp;&nbsp;";
			}
			
			if (sPrice == "")
			{
				sPrice = "";
			}
			else
			{
				sPrice = "&#8364;" + formatPrice(sPrice);
			}
			var sLoggerData = sLeverancierName + " - " + sUrlLocation;
			var encodedImageURL = replaceAll(sImageLocation, '&amp;', '*en_teken*');
			encodedImageURL = replaceAll(encodedImageURL, '=', '*is_teken*');
			encodedImageURL = replaceAll(encodedImageURL, '?', '*vraag_teken*');
			encodedImageURL = encodeURIComponent(encodedImageURL);	
			
			sHTML += '<div id="Datafeeds_container" class="cls_Datafeeds_Container" onclick="openDatafeed(this, \'' + sLeverancierName + '\');" title="' + sDescription + '">'
						+'<div id="divImage" class="cls_Datafeed_background_image" title="' + sDescription + '"'
							+'style="background-image: url(\'../php/imageresizer.php?w=110&h=180&constrain=1&img=' + encodedImageURL + '\');background-repeat: no-repeat;"></div>'
						+'<div id="divDetails" class="cls_Datafeed_cls_ImageContainer">'
							+'<table cellpadding="0" cellspacing="0">'
								+'<tr>'
									+'<td class="cls_Datafeed_left_corner"></td>'
									+'<td class="cls_Datafeed_middle">'
										+'<div style="background-color:white;" class="cls_ContentDatafeeds">'
											+'<a onclick=\'LOG(\"Openen van datafeed\", \"' + sLoggerData + '\", \"\", \"\");\' href="' + sUrlLocation + '" target="_blank" rel="nofollow"><label>' + sTitle + '</label></a>'
											+'<br/>'
											+'<label><a onclick=\'cancelOnclick();LOG(\"Openen van datafeed\", \"' + sLoggerData + '\", \"\", \"\");\' href="' + sUrlLocation + '" target="_blank" rel="nofollow"><u>Meer info</u></a></label>'
											+'<div class="cls_Spacer_DataFeedsa"></div>'
											+'<a onclick=\'LOG(\"Openen van datafeed\", \"' + sLoggerData + '\", \"\", \"\");\' href="' + sUrlLocation + '" target="_blank" rel="nofollow"><label class="cls_Before_Price">' + sSmallPrice + '</label></a>'  
											+ sSpacer
											+'<a onclick=\'LOG(\"Openen van datafeed\", \"' + sLoggerData + '\", \"\", \"\");\' href="' + sUrlLocation + '" target="_blank" rel="nofollow"><label class="cls_After_Price">' + sPrice + '</label></a>'
										+'</div>'
										+'<div class="cls_Spacer_DataFeeds"><br/></div>'
									+'</td>'
									+'<td class="cls_Datafeed_right_corner"></td>'
								+'</tr>'
							+'</table>'
						+'</div>'
					+'</div>';
		}
		catch (eInvalidData)
		{
			//Ignore for now.
		}
	}
	
	sHTML += buildDatafeedsCursor("BOTTOM", sCategoryID, sCategoryParent);
	
	document.getElementById("divGeneralContent").innerHTML = sHTML;
}//buildGeneralPanelForDataFeeds

function formatPrice(sPrice)
{
	// Replace dots with commas.
	sPrice = sPrice.replace('.', ',');

	// Check if the price has two decimals.
	var iDecimalIndex = sPrice.indexOf(',');
	if (iDecimalIndex == -1)
	{
		sPrice += ',00';
	}
	else
	{
		var sDecimal = sPrice.substr(iDecimalIndex);
		if (sDecimal.length == 2)
		{
			sPrice += '0';
		}
	}
	
	return sPrice;
}//formatPrice

function replaceAll (sString, sOriginal, sDestination) 
{
	 //couldn't find a replaceAll function in the js API, so here it goes:
	 while (sString.indexOf(sOriginal) >= 0) 
	 {
		sString = sString.replace(sOriginal, sDestination);
	 }

	 return sString;
}//replaceAll

/**
 * This method will build up the general data feeds panel (center of the ui beneath the banner)
 * It will first fetch the data feeds for the specific sub-category. After that it will build up the ui
 * for each data feed.
 *
 * @param oSourceObject		The sourceobject calling the method.
 * @param sCategoryID		The category id.
 * @param sCategoryParent		The parent category id.
 */
function getPageSpecificDataFeedsPanelForHomePage(xmlDataFeeds)
{
	var sHTML = '';
	
	var anLeveranciers = getUniqueLeveranciers();
	var anNodes = xmlDataFeeds.selectNodes(".//tuple");
	for (var iNode = 0; iNode < anNodes.length; iNode++)
	{
		try
		{
			var sLeverancierName = anNodes[iNode].selectSingleNode(".//fk_leverancier_id/text()").nodeValue;
			sLeverancierName = getLeverancier(sLeverancierName, anLeveranciers);
			var sPrice = anNodes[iNode].selectSingleNode(".//prijs/text()").nodeValue;
			var sSmallPrice = anNodes[iNode].selectSingleNode(".//prijs2/text()").nodeValue;
			var sTitle = anNodes[iNode].selectSingleNode(".//titel/text()").nodeValue;
			var sDescription = anNodes[iNode].selectSingleNode(".//omschrijving/text()").nodeValue;
			if (sTitle.length > 14)
			{
				sTitle = sTitle.substring(0, 17) + "...";
			}
			var sImageLocation = anNodes[iNode].selectSingleNode(".//foto/text()").nodeValue;
			var sUrlLocation = anNodes[iNode].selectSingleNode(".//url/text()").nodeValue;
			
			var sAdditionalFeatures = "&4dsid=5540&4dkn=merkkledingwinkelssite&4dadvn=" + sLeverancierName;
			sUrlLocation += sAdditionalFeatures;

			var sSpacer = "";
			if (sSmallPrice == "0" || sSmallPrice == sPrice || sSmallPrice == "" || sSmallPrice == null)
			{
				sSmallPrice = "";
			}
			else
			{
				sSmallPrice = "&#8364;" + formatPrice(sSmallPrice);
				sSpacer = "&nbsp;&nbsp;";
			}

			if (sPrice == "")
			{
				sPrice = "";
			}
			else
			{
				sPrice = "&#8364;" + formatPrice(sPrice);
			}
			
			var encodedImageURL = replaceAll(sImageLocation, '&amp;', '*en_teken*');
			encodedImageURL = replaceAll(encodedImageURL, '=', '*is_teken*');
			encodedImageURL = replaceAll(encodedImageURL, '?', '*vraag_teken*');
			encodedImageURL = encodeURIComponent(encodedImageURL);
			var sLoggerData = sLeverancierName + " - " + sUrlLocation;
			
			sHTML += '<div id="Datafeeds_container" class="cls_Datafeeds_Container" onclick="openDatafeed(this, \'' + sLeverancierName + '\');" title="' + sDescription + '">'
						+'<div id="divImage" class="cls_Datafeed_background_image" title="' + sDescription + '"'
							+'style="background-image: url(\'../php/imageresizer.php?w=110&h=180&constrain=1&img=' + encodedImageURL + '\');background-repeat: no-repeat;"></div>'
						+'<div id="divDetails" class="cls_Datafeed_cls_ImageContainer">'
							+'<table cellpadding="0" cellspacing="0">'
								+'<tr>'
									+'<td class="cls_Datafeed_left_corner"></td>'
									+'<td class="cls_Datafeed_middle">'
										+'<div style="background-color:white;" class="cls_ContentDatafeeds">'
											+'<a onclick=\'LOG(\"Openen van datafeed\", \"' + sLoggerData + '\", \"\", \"\");\' href="' + sUrlLocation + '" target="_blank" rel="nofollow"><label>' + sTitle + '</label></a>'
											+'<br/>'
											+'<label><a onclick=\'cancelOnclick();LOG(\"Openen van datafeed\", \"' + sLoggerData + '\", \"\", \"\");\' href="' + sUrlLocation + '" target="_blank" rel="nofollow"><u>Meer info</u></a></label>'
											+'<div class="cls_Spacer_DataFeedsa"></div>'
											+'<a onclick=\'LOG(\"Openen van datafeed\", \"' + sLoggerData + '\", \"\", \"\");\' href="' + sUrlLocation + '" target="_blank" rel="nofollow"><label class="cls_Before_Price">' + sSmallPrice + '</label></a>'  
											+ sSpacer
											+'<a onclick=\'LOG(\"Openen van datafeed\", \"' + sLoggerData + '\", \"\", \"\");\' href="' + sUrlLocation + '" target="_blank" rel="nofollow"><label class="cls_After_Price">' + sPrice + '</label></a>'
										+'</div>'
										+'<div class="cls_Spacer_DataFeeds"><br/></div>'
									+'</td>'
									+'<td class="cls_Datafeed_right_corner"></td>'
								+'</tr>'
							+'</table>'
						+'</div>'
					+'</div>';
		}
		catch (eInvalidData)
		{
			//Ignore for now.
		}
	}
	
	document.getElementById("divGeneralContent").innerHTML = sHTML;
}//getPageSpecificDataFeedsPanelForHomePage

function buildDatafeedsCursor(sUP, sCategoryID, sCategoryParent)
{
	var sHTML = '';
	
	if (sUP == "UPPER")
	{
		sHTML += '<table cellpadding="0" cellspacing="0" width="100%" height="100%" class="cls_DatafeedsTable">';
			sHTML += '<tr><td colspan="2" align="left" valign="top" class="cls_Datafeeds_Previous"><label>Resultaten ' + g_iUIDatafeedsCursor + ' - ' + g_iUIDatafeedsMaxCursor + ' van circa ' + g_iDatafeedTotal + '</label></td></tr>';
			sHTML += '<tr><td align="left" valign="top"  class="cls_Datafeeds_Previous"><input type="button" onclick="datafeedsPrevious(' + sCategoryID + ',' + sCategoryParent + ');" class="cls_Buttons" value="<< vorige"></input></td>'
							+'<td align="right" valign="top" class="cls_Datafeeds_Next"><input type="button" onclick="datafeedsNext(' + sCategoryID + ',' + sCategoryParent + ');" class="cls_Buttons" value="volgende >>"></input></tr><tr><td colspan="2">&nbsp;&nbsp;</td></tr>';
		sHTML += '<tr><td colspan="2" valign="top">';	
	}
	else
	{
		sHTML += '</td></tr>';
			sHTML += '<tr><td colspan="2" align="left" valign="top" class="cls_Datafeeds_Previous"><label>Resultaten ' + g_iUIDatafeedsCursor + ' - ' + g_iUIDatafeedsMaxCursor + ' van circa ' + g_iDatafeedTotal + '</label></td></tr>';
			sHTML += '<tr><td align="left" valign="top" class="cls_Datafeeds_Previous"><input type="button" onclick="datafeedsPrevious(' + sCategoryID + ',' + sCategoryParent + ');" class="cls_Buttons" value="<< vorige"></input></td>'
							+'<td align="right" valign="top" class="cls_Datafeeds_Next"><input type="button" onclick="datafeedsNext(' + sCategoryID + ',' + sCategoryParent + ');" class="cls_Buttons" value="volgende >>"></input></tr><tr><td colspan="2">&nbsp;&nbsp;</td></tr>';
		sHTML += '</table>';
	}
	return sHTML;
}//buildDatafeedsCursor

var g_bBusyClicking = false;
function cancelOnclick()
{
	g_bBusyClicking = true;
}
function openDatafeed(oSource, sLeverancierName)
{
	if (g_bBusyClicking == false)
	{
		var sAdditionalFeatures = "&4dsid=5540&4dkn=merkkledingwinkelssite&4dadvn=" + sLeverancierName;
		var aHREFs = oSource.getElementsByTagName("A");
		var sURL = aHREFs[0].href;
		if (typeof(aHREFs[1]) != "undefined")
		{
			sURL = aHREFs[1].href;
		}
		if (sURL.indexOf("merkkledingwinkelsite") == -1)
		{
			sURL += sAdditionalFeatures;
		}
		window.open(sURL);
		
		LOG("Openen van datafeed", sLeverancierName + " - " + sURL, "", "");
	}
	else
	{
		g_bBusyClicking = false;
	}
}

/**
 * This method will build up the general panel (center of the ui beneath the banner)
 * with data. It will split the data based on the sort field (alphabeticaly), and give a header 
 * with a description above each group. Inside the group, the remaining links will be placed.
 *
 * @param sSortField			Name of the field to sort by.
 * @param sHeaderTitle		Name of the header column.
 * @param sDescriptionField	Name of the description column.
 * @param sUrlField			Name of the url column
 * @param xmlData			The xml data to use to build the pane.
 */
var caAlphabet = new Array();
caAlphabet[caAlphabet.length] = "A";caAlphabet[caAlphabet.length] = "B";caAlphabet[caAlphabet.length] = "C";caAlphabet[caAlphabet.length] = "D";caAlphabet[caAlphabet.length] = "E";caAlphabet[caAlphabet.length] = "F";caAlphabet[caAlphabet.length] = "G";caAlphabet[caAlphabet.length] = "H";caAlphabet[caAlphabet.length] = "I";caAlphabet[caAlphabet.length] = "J";caAlphabet[caAlphabet.length] = "K";caAlphabet[caAlphabet.length] = "L";caAlphabet[caAlphabet.length] = "M";caAlphabet[caAlphabet.length] = "N";caAlphabet[caAlphabet.length] = "O";caAlphabet[caAlphabet.length] = "P";caAlphabet[caAlphabet.length] = "Q";caAlphabet[caAlphabet.length] = "R";caAlphabet[caAlphabet.length] = "S";caAlphabet[caAlphabet.length] = "T";caAlphabet[caAlphabet.length] = "U";caAlphabet[caAlphabet.length] = "V";caAlphabet[caAlphabet.length] = "W";caAlphabet[caAlphabet.length] = "X";caAlphabet[caAlphabet.length] = "Y";caAlphabet[caAlphabet.length] = "Z";
function buildGeneralPanelForCustomContent(sSortField, sHeaderTitle, sDescriptionField, sUrlField, xmlData)
{
	var sHTML = '';
	
	var anNodes = xmlData.selectNodes(".//tuple");
	
	for (var iAlpha = 0; iAlpha < caAlphabet.length; iAlpha++)
	{
		var sGroupHTML = '<div class="cls_GeneralContent_Group">';
		
		//Group header (a,b,c, etc)
		var csLetter = caAlphabet[iAlpha];
		sGroupHTML += '<table cellpadding="0" cellspacing="0" bgcolor="#ebf3ce">'
						+'<tr>'
							+'<td class="cls_GeneralContent_Block_Header"><font color="#BBD536">-</font>' + csLetter + '</td>'
						+'</tr>';
		var bFound = false;
		for (var iNode = 0; iNode < anNodes.length; iNode++)
		{
			var nTemp = anNodes[iNode].selectSingleNode(".//" + sSortField + "/text()");
			if (nTemp != null)
			{
				var sString = nTemp.nodeValue;
				//Case insensitive comparison if the first-char of the sort-field is equal to the current letter in the alphabet.
				if (sString.substring(0, 1).toUpperCase() == csLetter)
				{
					//Within this alphabetic order build up html.
					bFound = true;
					
					//Get description and the url to append.
					var sTitle = anNodes[iNode].selectSingleNode(".//" + sHeaderTitle + "/text()").nodeValue;
					var sUrlDescription = null;
					
					if(sDescriptionField != null)
					{
						var sDescription = anNodes[iNode].selectSingleNode(".//" + sDescriptionField + "/text()").nodeValue;
						sUrlDescription = sDescription;
					}
					
					if(sUrlField != null)
					{			
						var sUrl = anNodes[iNode].selectSingleNode(".//" + sUrlField + "/text()").nodeValue;
						if (sUrl.indexOf("http") == -1)
						{
							sUrl = "http://" + sUrl;
						}
						
						if(sUrlDescription != null)
						{
							sUrlDescription = '<a target="_blank" href="' + sUrl + ' "rel="nofollow">' + sUrlDescription + '</a></td>';
						}
						else
						{	
							sUrlDescription = '<a target="_blank" href="' + sUrl + '" rel="nofollow">' + sUrl + '</a></td>';
						}
					}
					
					sGroupHTML += '<tr>'
									+'<td style="padding: 1px 3px 1px 3px"><b>' + sTitle + '</b></td>'
								 +'</tr>';
								
					if(sDescriptionField != null)
					{
						sGroupHTML += '<tr>'
									     +'<td style="padding: 1px 3px 1px 3px;">' + sUrlDescription + '</td>'
								     +'</tr>'
								     +'<tr>'
									     +'<td>&nbsp;</td>'
								     +'</tr>';
					}
					
					
				}
			}
		}
		if (bFound == true)
		{
			//Append this alphabet-group.
			sGroupHTML += '</table></div>';
			sHTML += sGroupHTML;
		}
	}
	
	return sHTML;
}//buildGeneralPanelForCustomContent

/**
 * This method will send the contact-form with the details to the server so a mail can be sent.
 */
function sendEmailForm()
{
	var sName = getHTMLData(document.getElementById("txtNaam"));
	var sQuestion = getHTMLData(document.getElementById("txtVraag"));
	var sSex = getHTMLData(document.getElementById("txtGeslacht"));
	var sEmail = getHTMLData(document.getElementById("txtAanvraagEmail"));
	var sCategory = getHTMLData(document.getElementById("txtGeintereseerd"));
	var sHow = getHTMLData(document.getElementById("txtArrived"));
	
	if (sEmail != "" && isValidEmail(sEmail) == true)
	{
		if (sName != "" && sQuestion != "" && sEmail != "")
		{
			//Disable send-button.
			document.getElementById("btnSend").disabled = true;
			//create the cross-browser compatible htppRequest.
			var xmlHttpRequest =  new XMLHttpRequest();
			xmlHttpRequest.open('POST', '../php/ControllerHandler.php', false);
			
			//set the request data.
			var sRequestData = "sAction2Perform=SEND_CONTACT_MAIL";
							sRequestData += "&sName=" + sName;
							sRequestData += "&sQuestion=" + sQuestion;
							sRequestData += "&sSex=" + sSex;
							sRequestData += "&sEmail=" + sEmail;
							sRequestData += "&sCategory=" + sCategory;
							sRequestData += "&sHow=" + sHow;
							
			
			//now send the request.
			xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xmlHttpRequest.send(sRequestData);
			
			alert("U aanvraag is verstuurd!");
			
			//Clean up the form.
			cleanUpEmailForm();
		}
		else
		{
			alert("Niet al de verplichte velden zijn ingevuld!");
		}
	}
	else
	{
		alert("Het email adres is ongeldig!");
	}
}//sendEmailForm


function isValidEmail(str) 
{
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

/**
 * This method will cleanup the email form.
 */
function cleanUpEmailForm()
{
	setHTMLData(document.getElementById("txtNaam"), "");
	setHTMLData(document.getElementById("txtVraag"), "");
	document.getElementById("txtGeslacht").selectedIndex = 0;
	setHTMLData(document.getElementById("txtAanvraagEmail"), "");
	document.getElementById("txtGeintereseerd").selectedIndex = 0;
	document.getElementById("txtArrived").selectedIndex = 0;
}//cleanUpEmailForm

// check for XPath implementation 
if( document.implementation.hasFeature("XPath", "3.0") ) 
{ 
	// prototying the XMLDocument 
	XMLDocument.prototype.selectNodes = function(cXPathString, xNode) 
	{ 
		if( !xNode ) { xNode = this; }
		var oNSResolver = this.createNSResolver(this.documentElement) 
		var aItems = this.evaluate(cXPathString, xNode, oNSResolver,
					 XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null) 
		var aResult = [];
		for( var i = 0; i < aItems.snapshotLength; i++) 
		{ 
			aResult[i] = aItems.snapshotItem(i);
		} 
		return aResult;
	} 

	// prototying the Element 
	Element.prototype.selectNodes = function(cXPathString) 
	{ 
		if(this.ownerDocument.selectNodes) 
		{ 
			return this.ownerDocument.selectNodes(cXPathString, this);
		} 
		else{throw "For XML Elements Only";} 
	}
}
 
// check for XPath implementation 
if( document.implementation.hasFeature("XPath", "3.0") ) 
{ 
	// prototying the XMLDocument 
	XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode) 
	{ 
		if( !xNode ) { xNode = this; }
		var xItems = this.selectNodes(cXPathString, xNode);
		if( xItems.length > 0 ) 
		{ 
			return xItems[0];
		} 
		else 
		{ 
			return null;
		} 
	} 

	// prototying the Element 
	Element.prototype.selectSingleNode = function(cXPathString) 
	{
		if(this.ownerDocument.selectSingleNode) 
		{ 
			return this.ownerDocument.selectSingleNode(cXPathString, this);
		} 
		else{throw "For XML Elements Only";} 
	} 
} 

//Adjust height of the main iframe
function setHeight(bFromSearch)
{
	var iBodyHeight = 0;
	iBodyHeight = (document.body.offsetHeight);
	
	var iHeaderHeight = 320;
	var iMaximumHeight = window.screen.availHeight - iHeaderHeight;
	var iNewHeight = iBodyHeight + 20;
	if (iNewHeight < iMaximumHeight)
	{
		iNewHeight = iMaximumHeight;
	}
	window.frameElement.style.height = iNewHeight + "px"
}//setHeight

function fireClickEvent(oControl)
{ 
    if (document.all) 
    {
		//IE
        oControl.fireEvent("onclick"); 
    } 
    else 
    { 
		//Firefox, etc.
        var clickEvent = window.document.createEvent("MouseEvent"); 
        clickEvent.initEvent("click", false, true); 
        oControl.dispatchEvent(clickEvent); 
    }
}//fireClickEvent

/**
 * This method will parse search text.
 *
 * @param  sText:	The text to parse.
 * @param  sKeywords:	The keywords to parse against.
 *
 * @return sParsedText:	Returns the parsed text.
 */
function parseSearchText (sText, sKeyWords)
{
	var sParsedText = sText;
	var sBEGIN_HTML = '<label class="cls_Search_Hilite">';
	var sEND_HTML = '</label>';
	
	//First, we need to remove single quotes and replace them with double quotes and we need to replace escape quotes with a single quote.
	while (sKeyWords.indexOf("'") != -1)
	{
		sKeyWords = sKeyWords.replace("'", '\"')
	}
	while (sKeyWords.indexOf('\"') != -1)
	{
		sKeyWords = sKeyWords.replace('\"', "'")
	}
	
	//Asteriks conversion.
	while (sKeyWords.indexOf("*") != -1)
	{
		//handle the asteriks part.
		var iEnd = sKeyWords.indexOf("*")
		//find the starting index (walk backwards till we run into a space or are at position 0.
		var iPosition = iEnd;
		var bFoundSpace = false;
		while (iPosition != 0 && bFoundSpace != true)
		{
			iPosition--;
			if (iPosition != 0)
			{
				if (sKeyWords.substring(iPosition - 1, iPosition) == " ")
				{
					bFoundSpace = true;
				}
			}
		}
		
		var sReplacementText = sKeyWords.substring(iPosition, iEnd);
		sParsedText = injectInString(sParsedText, sBEGIN_HTML, sEND_HTML, sReplacementText);
		//remove this from the sKeyWords string.
		var reKeyWord = '';
		var iEndOfString = sReplacementText.length;
		var iPosition = 0;
		while (iPosition != iEndOfString)
		{
			var cChar = sReplacementText.substring(iPosition, iPosition + 1);
			reKeyWord += '[' + cChar + ']';
			iPosition++;
			if (iPosition != iEndOfString)
			{
				reKeyWord += '+';
			}
		}
		//add the asterik.
		reKeyWord += '+[*]';
		var reRemoveKeyWord = new RegExp(reKeyWord, "gi");
		sKeyWords = sKeyWords.replace(reRemoveKeyWord, "");		
	}
	
	//Quote conversion.
	while (sKeyWords.indexOf("'") != - 1)
	{
		//handle the quotes part.
		var iStartQuote = sKeyWords.indexOf("'");
		var iEndQuote = sKeyWords.substring(iStartQuote + 1, sKeyWords.length).indexOf("'");
		if (iEndQuote == -1)
		{
			break;
		}
		var sReplacementText = sKeyWords.substring(iStartQuote + 1, iEndQuote + 1);
		var reKeyWordWithQuotes = "[']+";
		var iEndOfString = sReplacementText.length;
		var iPosition = 0;
		while (iPosition != iEndOfString)
		{
			var cChar = sReplacementText.substring(iPosition, iPosition + 1);
			if (cChar != " ")
			{
				reKeyWordWithQuotes += '[' + cChar + ']';
			}
			else
			{
				reKeyWordWithQuotes += '[\\s]';
			}
			iPosition++;
			if (iPosition != iEndOfString)
			{
				reKeyWordWithQuotes += '+';
			}
		}
		reKeyWordWithQuotes += "+[']";
		reKeyWordWithQuotes = new RegExp(reKeyWordWithQuotes, "gi");
		
		sParsedText = injectInString(sParsedText, sBEGIN_HTML, sEND_HTML, sReplacementText);
		
		sKeyWords = sKeyWords.replace(reKeyWordWithQuotes, "");
	}
	
	//Remaining conversions.
	if (sKeyWords.length > 0)
	{
		//Check if we match agains a text / number regular expresion.
		var bCheck = false;
		var reCheckForLetters = '[a-z]';
		reCheckForLetters = new RegExp(reCheckForLetters, "gi");
		var oResult = sKeyWords.match(reCheckForLetters);
		if (oResult != null)
		{
			bCheck = true;
		}
		var reCheckForNumbers = '[\\d]';
		reCheckForNumbers = new RegExp(reCheckForNumbers, "gi");
		var oResult = sKeyWords.match(reCheckForNumbers);
		if (oResult != null)
		{
			bCheck = true;
		}
		
		if (bCheck == true)
		{
			//we still have text remaining, handle that the normal way.
			//Next split the keywords into an array.
			var anKeyWords = sKeyWords.split(" ");
			var iNumberOfKeys = anKeyWords.length;
			while (iNumberOfKeys--)
			{
				var sCurrentKey = anKeyWords[iNumberOfKeys];
				if (sCurrentKey != "")
				{
					sParsedText = injectInString(sParsedText, sBEGIN_HTML, sEND_HTML, sCurrentKey);
				}
			}
		}
	}
	
	return sParsedText;
}//parseSearchText

/**
 * This method will inject a string before and after a specifc search strng within a string.
 *
 * @param sSourceString: The source string to search within.
 * @param sBeforeString: The string to append before the search text.
 * @param sAfterString:   The string to append after the search text.
 * @param sSearchString: The string to search for.
 *
 * @return sReturn:	Returns the injected string.
 */
function injectInString(sSourceString, sBeforeString, sAfterString, sSearchString)
{
	var sReturn = sSourceString;
	
	var iStringPosition = 0;
	var sTempString = "";
	var sTextAfter = "";
	var sOriginalSourceString = sSourceString;
	
	//Check if replacement of special chars' is neccessary.
	var sTempTest = sSourceString.substring(iStringPosition, sSourceString.length);
	if (sTempTest.toUpperCase().indexOf(sSearchString.toUpperCase()) == -1)
	{
		sSourceString = toNormalChars(sTempTest);
	}
	while (iStringPosition < sSourceString.length)
	{
		var sString2Use = sOriginalSourceString.substring(iStringPosition, sSourceString.length);
		var sString2Test = sSourceString.substring(iStringPosition, sSourceString.length);
		if (sString2Test.toUpperCase().indexOf(sSearchString.toUpperCase()) != -1)
		{
			var iStart = sString2Test.toUpperCase().indexOf(sSearchString.toUpperCase());
			var iEnd = iStart + sSearchString.length;
			var bSkip = false;
			var iCharBefore = sString2Test.substring(iStart - 1, iStart);
			if (iCharBefore != " ")
			{
				if (iCharBefore != "")
				{
					if (iCharBefore != ">")
					{
						bSkip = true;
					}
				}
			}
			var sReplacingText = sString2Use.substring(iStart, iEnd);
			var sParsedKey;
			if (bSkip == false)
			{
				sParsedKey = sBeforeString + sReplacingText + sAfterString;
			}
			else
			{
				sParsedKey = sReplacingText;
			}
			var sTextBefore = sString2Use.substring(0, iStart);
			sTempString += sTextBefore;
			sTempString += sParsedKey;
			sTextAfter = sString2Use.substring(iEnd, sString2Use.length);
			iStringPosition += iEnd;
		}
		else
		{
			iStringPosition = sOriginalSourceString.length;
		}
	}
	if (sTempString.length != 0)
	{
		sTempString += sTextAfter;
		sReturn = sTempString;
	}
	
	return sReturn;
}//injectInString

/**
 * This function will map a certain number of special characters to normal ones.
 */
function toNormalChars(sSourceString)
{
	var sReturn = sSourceString;
	
	//A-types to a or A
	while (sReturn.indexOf("à") != -1) {sReturn = sReturn.replace("à", "a")};
	while (sReturn.indexOf("á") != -1) {sReturn = sReturn.replace("á", "a")};
	while (sReturn.indexOf("â") != -1) {sReturn = sReturn.replace("â", "a")};
	while (sReturn.indexOf("ã") != -1) {sReturn = sReturn.replace("ã", "a")};
	while (sReturn.indexOf("ä") != -1) {sReturn = sReturn.replace("ä", "a")};
	while (sReturn.indexOf("À") != -1) {sReturn = sReturn.replace("À", "A")};
	while (sReturn.indexOf("Á") != -1) {sReturn = sReturn.replace("Á", "A")};
	while (sReturn.indexOf("Â") != -1) {sReturn = sReturn.replace("Â", "A")};
	while (sReturn.indexOf("Ã") != -1) {sReturn = sReturn.replace("Ã", "A")};
	while (sReturn.indexOf("Ä") != -1) {sReturn = sReturn.replace("Ä", "A")};
	
	//"E-types", to "e" or E
	while (sReturn.indexOf("ë") != -1) {sReturn = sReturn.replace("ë", "e")};
	while (sReturn.indexOf("é") != -1) {sReturn = sReturn.replace("é", "e")};
	while (sReturn.indexOf("è") != -1) {sReturn = sReturn.replace("è", "e")};
	while (sReturn.indexOf("ê") != -1) {sReturn = sReturn.replace("ê", "e")};
	while (sReturn.indexOf("Ë") != -1) {sReturn = sReturn.replace("Ë", "E")};
	while (sReturn.indexOf("È") != -1) {sReturn = sReturn.replace("È", "E")};
	while (sReturn.indexOf("É") != -1) {sReturn = sReturn.replace("É", "E")};
	while (sReturn.indexOf("Ê") != -1) {sReturn = sReturn.replace("Ê", "E")};
	
	//I-types to i or I
	while (sReturn.indexOf("ì") != -1) {sReturn = sReturn.replace("ì", "i")};
	while (sReturn.indexOf("í") != -1) {sReturn = sReturn.replace("í", "i")};
	while (sReturn.indexOf("î") != -1) {sReturn = sReturn.replace("î", "i")};
	while (sReturn.indexOf("ï") != -1) {sReturn = sReturn.replace("ï", "i")};
	while (sReturn.indexOf("Ì") != -1) {sReturn = sReturn.replace("Ì", "I")};
	while (sReturn.indexOf("Í") != -1) {sReturn = sReturn.replace("Í", "I")};
	while (sReturn.indexOf("Î") != -1) {sReturn = sReturn.replace("Î", "I")};
	while (sReturn.indexOf("Ï") != -1) {sReturn = sReturn.replace("Ï", "I")};
	
	//O-types to o or O
	while (sReturn.indexOf("ò") != -1) {sReturn = sReturn.replace("ò", "o")};
	while (sReturn.indexOf("ó") != -1) {sReturn = sReturn.replace("ó", "o")};
	while (sReturn.indexOf("ô") != -1) {sReturn = sReturn.replace("ô", "o")};
	while (sReturn.indexOf("õ") != -1) {sReturn = sReturn.replace("õ", "o")};
	while (sReturn.indexOf("ö") != -1) {sReturn = sReturn.replace("ö", "o")};
	while (sReturn.indexOf("Ò") != -1) {sReturn = sReturn.replace("Ò", "O")};
	while (sReturn.indexOf("Ó") != -1) {sReturn = sReturn.replace("Ó", "O")};
	while (sReturn.indexOf("Ô") != -1) {sReturn = sReturn.replace("Ô", "O")};
	while (sReturn.indexOf("Õ") != -1) {sReturn = sReturn.replace("Õ", "O")};
	while (sReturn.indexOf("Ö") != -1) {sReturn = sReturn.replace("Ö", "O")};
	
	//U-types to u or U
	while (sReturn.indexOf("ü") != -1) {sReturn = sReturn.replace("ü", "u")};
	while (sReturn.indexOf("ù") != -1) {sReturn = sReturn.replace("ù", "u")};
	while (sReturn.indexOf("ú") != -1) {sReturn = sReturn.replace("ú", "u")};
	while (sReturn.indexOf("û") != -1) {sReturn = sReturn.replace("û", "u")};
	while (sReturn.indexOf("Ü") != -1) {sReturn = sReturn.replace("Ü", "U")};
	while (sReturn.indexOf("Ù") != -1) {sReturn = sReturn.replace("Ù", "U")};
	while (sReturn.indexOf("Ú") != -1) {sReturn = sReturn.replace("Ú", "U")};
	while (sReturn.indexOf("Û") != -1) {sReturn = sReturn.replace("Û", "U")};
	
	return sReturn;
}//toNormalChars

/**
 * This method analyzes the URL and returns a parameter.
 *
 * @param strParamName	The name of the param to return.
 *
 * @returns The value of the parameter or an empty string if the parameter was not found.
 */
function getURLParam(strParamName)
{
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 )
  {
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
	{
      if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 )
	  {
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  
	if (document.location.href.indexOf("zoek_merken") != -1 && strParamName == "searchme")
	{
		return "true";
	}
	if (strReturn == "" && (strParamName == "searchbrand" || strParamName == "searchquery"))
	{
		if (document.location.href.indexOf("zoek_merken") != -1)
		{
			//http://www.merkkledingwinkels.nl/zoek_merken/zoeken/Adidas.html
			var sURL = document.location.href;
			var iIndex = sURL.indexOf("/zoek_merken/") + 13;
			sURL = sURL.substring(iIndex, sURL.length);
			if (strParamName == "searchbrand")
			{
				if (sURL.indexOf("/") != -1)
				{
					var sTemp = sURL.substring(sURL.indexOf("/") + 1, sURL.indexOf(".html"));
					if (sTemp != "zoeken")
					{
						strReturn = sTemp;
					}
				}
			}
			else
			{
				var sTemp = sURL.substring(0, sURL.indexOf("/"));
				if (sTemp != "zoeken")
				{
					strReturn = sTemp;
				}
			}
		}
	}
  
  return unescape(strReturn);
}//getURLParam