/*
 * init javascript by CCI IT GROEP
 * http://www.cci-itgroep.nl/
 * Copyright (c) 2009 CCI IT GROEP
 */

/*== HideEmptyImages ==*/
function HideEmptyImages()
{	
	var regex_1 = new RegExp("(shownoimg)\.gif$");
	
	for (var i=0; i < document.images.length; i++)
	{
		if (regex_1.test(document.images[i].src))
		{
			document.images[i].style.display = "none";
		}
	}
}

/*== getQuery ==*/
var query = window.location.search.substring(1);
var vars = query.split("&");
var varArray = {};

function getQueryVariable(variable)
{
	for (var i=0;i<vars.length;i++)
	{
		var pair = vars[i].split("=");
		if (pair[0] == variable)
		{
		  return pair[1];
		}
	} 
}
function loadVariables()
{
	for (var i=0;i<vars.length;i++)
	{
		var pair = vars[i].split("=");
		varArray[pair[0].toString()] = pair[1];
	}
}
/*== ==*/

/*== createCrumbPath (getQueryVariable nodig!) ==*/
function createCrumbPath(containerId,defaultPageId)
{
	// Check available location info
	if (themeId && themeName && crumbPath_themeIds && crumbPath_themeNames && pageId && pageName && $("#"+containerId).length)
	{
		// Define arrays to hold themeId's and themeNames
		var themeIds = [];
		var themeNames = [];
		
		// Trim and put themeId's and themeNames in seperate arrays
		crumbPath_themeIds = crumbPath_themeIds.replace(/^~/,"");
		crumbPath_themeIds = crumbPath_themeIds.replace(/~$/,"");
		crumbPath_themeNames = crumbPath_themeNames.replace(/^~/,"");
		crumbPath_themeNames = crumbPath_themeNames.replace(/~$/,"");
		
		var themeIdsSplit = crumbPath_themeIds.split(/~/g);
		var themeNamesSplit = crumbPath_themeNames.split(/~/g);
		
		// Loop through all theme's and put the information in their arrays
		for (var i = 0; i < themeIdsSplit.length; i++)
		{
			if (!themeNamesSplit[i].match(/#/) && !themeNamesSplit[i].toLowerCase().match(/formulieronderdelen/))
			{
				themeIds.push(themeIdsSplit[i]);
				themeNames.push(themeNamesSplit[i]);
			}
		}
		
		// Build the HTML to be put in the element with the id 'containerId' if the page is not the homepage itself
		var crumbPathHTML = "";
		
		var pageIdIsDefaultPageId = false;
		var pageIdIsFormsetId = false;
		
		if (pageId == "1132")
		{
			pageIdIsDefaultPageId = true;
			
			crumbPathHTML = '<a class="page-home" href="/cms/publish/content/showpage.asp?pageid='+defaultPageId+'">Home</a>';
		}
		else
		{
			crumbPathHTML = '<a class="default" href="/cms/publish/content/showpage.asp?pageid='+defaultPageId+'">Home</a>';
		}
		
		// Loop through all information in the themeIds and themeNames array
		var pageNameLowerCase = pageName.toLowerCase();
		
		if (pageNameLowerCase.match(/footer$/))
		{
			pageIdIsFormsetId = true;
		}
		
		for (var j = 0; j < themeIds.length; j++)
		{
			var themeNameIsPageName = false;
			
			var extraClass = ' class="theme"';
			
			if (j == 0 && j == (themeIds.length - 1))
			{
				extraClass = ' class="theme theme-first-last"';
				
				if (themeNames[j].toLowerCase() == pageNameLowerCase)
				{
					themeNameIsPageName = true;
				}
			}
			else if (j == 0)
			{
				extraClass = ' class="theme theme-first"';
			}
			else if (j == (themeIds.length - 1))
			{
				extraClass = ' class="theme theme-last"';
				
				if (themeNames[j].toLowerCase() == pageNameLowerCase)
				{
					themeNameIsPageName = true;
				}
			}
			
			if (!themeNameIsPageName)
			{
				crumbPathHTML += '<a'+extraClass+' href="/cms/publish/content/showpage.asp?themeid='+themeIds[j]+'">'+themeNames[j]+'</a>';
			}
		}
		
		// Add the current page information to the crumbpath if the pageId is not the same as the default pageId
		if (!pageIdIsDefaultPageId)
		{
			if (!pageIdIsFormsetId)
			{
				crumbPathHTML += '<a class="page" href="/cms/publish/content/showpage.asp?pageid='+pageId+'">'+pageName+'</a>';
			}
			else
			{
				crumbPathHTML += '<a class="page" href="/cms/publish/emailservice/membershipform.asp?formset_id='+getQueryVariable("formset_id")+'">Aanmelden / Wijzigen</a>';
			}
		}
		
		// Put the crumbpath html in the element with the id 'containerId'
		$("#"+containerId).html(crumbPathHTML);
	}
}
/*== ==*/

/*== [DEPRECATED] Kruimelpad script (Vanaf Updater 9 SP3 en hoger)  indien lager, dit script uitcommentariseren==*/
/*== PROTOTYPES rev en replaceLast nodig!! ==*/
/*== CSS classes first en last nodig!! ==*/
/*== Img crumb_path_sep.gif nodig!! ==*/
function createCrumbPathAt(id)
{
	if (document.getElementById(id) && crumbPath_themeNames && crumbPath_themeIds && themeName && pageName && pageId)
	{
		crumbPath_themeNames = crumbPath_themeNames.replace(/[ ][(]NIET VERWIJDEREN[)]/g,"");
		pageName = pageName.replace(/[ ][(]NIET VERWIJDEREN[)]/g,"");
		themeName = themeName.replace(/[ ][(]NIET VERWIJDEREN[)]/g,"");
		
		crumbPath_themeNames = crumbPath_themeNames.replace(/\* Modules/g,"");
		pageName = pageName.replace(/\* Modules/g,"");
		themeName = themeName.replace(/\* Modules/g,"");
		
		crumbPath_themeNames = crumbPath_themeNames.replace(/^~/,"");
		crumbPath_themeNames = crumbPath_themeNames.replace(/~$/,"");
		
		crumbPath_themeIds = crumbPath_themeIds.replace(/^~/,"");
		crumbPath_themeIds = crumbPath_themeIds.replace(/~$/,"");
		
		var printableNavigation = '';
		var objectToPlaceCrumbpath = document.getElementById(id);
		
		var crumbPath_themeIds_Array = crumbPath_themeIds.replace(/^~/,"");
		crumbPath_themeIds_Array = crumbPath_themeIds.replace(/~$/,"");
		crumbPath_themeIds_Array = crumbPath_themeIds.split(/~/);
		
		var crumbPath_themeNames_Array = crumbPath_themeNames.replace(/^~/,"");
		crumbPath_themeNames_Array = crumbPath_themeNames.replace(/~$/,"");
		crumbPath_themeNames_Array = crumbPath_themeNames.split(/~/);
		
		for (var i=0; i<crumbPath_themeIds_Array.length; i++)
		{
			if (crumbPath_themeIds_Array[i] == "")
			{
				crumbPath_themeNames_Array = crumbPath_themeNames_Array.splice(i,1);
				crumbPath_themeIds_Array = crumbPath_themeIds_Array.splice(i,1);
			}
			if (crumbPath_themeNames_Array[i-1] && crumbPath_themeNames_Array[i])
			{
				if (crumbPath_themeNames_Array[i-1] == crumbPath_themeNames_Array[i])
				{
					crumbPath_themeNames_Array = crumbPath_themeNames_Array.splice(i,1);
					crumbPath_themeIds_Array = crumbPath_themeIds_Array.splice(i,1);
				}
			}
			if (crumbPath_themeNames_Array[i])
			{
				if (crumbPath_themeNames_Array[i] == "")
				{
					crumbPath_themeNames_Array = crumbPath_themeNames_Array.splice(i,1);
					crumbPath_themeIds_Array = crumbPath_themeIds_Array.splice(i,1);
				}
				else if (crumbPath_themeNames_Array[i].match(/#/) || crumbPath_themeNames_Array[i].match(/Home/))
				{
					crumbPath_themeNames_Array = crumbPath_themeNames_Array.splice(i,1);
					crumbPath_themeIds_Array = crumbPath_themeIds_Array.splice(i,1);
				}
			}
		}
		
		printableNavigation += '<a class="first" href="/">Home</a>';
		
		for (var j=0; j<crumbPath_themeNames_Array.length; j++)
		{
			if (j == 0)
			{
				//crumbPath_themeNames_Array[j] = crumbPath_themeNames_Array[j].replace(/NEW/,"CaseWare");
				
				// Voeg alle (sub) thema's toe aan een verzameling met links, evt. opbouw kan hier worden gewijzigd
				printableNavigation += '<a href="/cms/publish/content/showpage.asp?themeid='+crumbPath_themeIds_Array[j]+'">'+crumbPath_themeNames_Array[j]+'</a>';
			}
			else if (j == crumbPath_themeNames_Array.length-1)
			{
				if (pageName == themeName && themeId == crumbPath_themeIds_Array[crumbPath_themeIds_Array.length-1])
				{
					// Voeg alle (sub) thema's toe aan een verzameling met links, evt. opbouw kan hier worden gewijzigd
					printableNavigation += '<a class="last" href="/cms/publish/content/showpage.asp?themeid='+crumbPath_themeIds_Array[j]+'">'+crumbPath_themeNames_Array[j]+'</a>';
				}
				else
				{
					// Voeg alle (sub) thema's toe aan een verzameling met links, evt. opbouw kan hier worden gewijzigd
					printableNavigation += '<a href="/cms/publish/content/showpage.asp?themeid='+crumbPath_themeIds_Array[j]+'">'+crumbPath_themeNames_Array[j]+'</a>';
				}
			}
			else
			{
				// Voeg alle (sub) thema's toe aan een verzameling met links, evt. opbouw kan hier worden gewijzigd
				printableNavigation += '<a href="/cms/publish/content/showpage.asp?themeid='+crumbPath_themeIds_Array[j]+'">'+crumbPath_themeNames_Array[j]+'</a>';
			}
			
		}
		
		if (pageName.toLowerCase().match(themeName.toLowerCase()) && themeId == crumbPath_themeIds_Array[crumbPath_themeIds_Array.length-1])
		{
			// Als het themeId waar we op ons bevinden gelijk is aan het laatste themeId in het kruimelpad en de naam van de pagina gelijk is aan het thema naam, hoeft er geen pagina link toegevoegd te worden
			printableNavigation = replaceLast(printableNavigation,'<a ','<a class="last" ');
		}
		else
		{
			// Hier wordt de paginatitel als laatste link toegevoegd, evt. opbouw kan hier worden gewijzigd
			printableNavigation += '<a class="last" href="/cms/publish/content/showpage.asp?pageid='+pageId+'"><strong>'+pageName+'</strong></a>';
		}
		
		// Plaats het samengestelde kruimelpad in het element met het opgegeven ID
		objectToPlaceCrumbpath.innerHTML = printableNavigation;
	}
}
/*== ==*/
/*== openClose ==*/
function openClose(elementLink, elementLinkCurrentClassName, elementToOpen, elementToOpenCurrentClassName)
{
	if (elementLink && elementToOpen)
	{
		if (elementLink.className.match(/active/) && elementToOpen.className.match(/active/))
		{
			elementLink.className = elementLinkCurrentClassName;
			elementToOpen.className = elementToOpenCurrentClassName;
		}
		else
		{
			elementLink.className = elementLinkCurrentClassName + ' active';
			elementToOpen.className = elementToOpenCurrentClassName + ' active';
		}
	}
}
/*== ==*/

/*- http://support.microsoft.com/kb/278469 -*/
/* In de onload van de iframe:  */
function adjustIFrameSize(iframeId)
{
	var iframeElementByIdForStyling = document.getElementById(iframeId);
	var iframeElement = window.frames[iframeId];
	
	if (navigator.appVersion.match(/MSIE/))
	{
		iframeElementByIdForStyling.style.height = iframeElement.document.body.scrollHeight + 13 + 'px';
	}
	else
	{
		iframeElementByIdForStyling.style.height = iframeElement.document.getElementsByTagName('html')[0].scrollHeight + 100 + 'px';
	}
}
/*== ==*/

/*== Parent Anchoring ==*/
function setParentAnchorPoints(elementId)
{
	if (parent.setAnchorPointsFromIframe && document.getElementById(elementId))
	{
		parent.setAnchorPointsFromIframe(document.getElementById(elementId).innerHTML);
	}
}
function bringParentToAnchor()
{
	var anchorValue;
	var url = window.location.href;
	var parentUrl = parent.window.location.href;
	var strippedUrl = url.toString().split("#");
	var strippedParentUrl = parentUrl.toString().split("#");
	if (strippedUrl.length > 1)
	{
		anchorvalue = strippedUrl[1];
		parent.window.location.href = strippedParentUrl[0] + "#"+anchorvalue;
		/*var parentLoc = parent.location.href.split("#");
		parentLoc = parentLoc[0];
		parent.location.href = parentLoc[0] + "#" + anchorvalue;*/
	}
}
/*== ==*/

/*==Body onload (jQuery) ==*/
$(document).ready(function()
{
	HideEmptyImages();
	createCrumbPath("crumb_path_wrapper", "1132");
});
/*== ==*/

/*== Body onload ==
window.onload = function(e)
{
	HideEmptyImages();
}
/*== ==*/

