 /*
	FEEDBACK
*/
var feedbackWrapper;
function feedback(){
	if(!feedbackWrapper){
		var html = '';
		var language = document.getElementsByTagName('html')[0].getAttribute('lang');

		feedbackWrapper = document.createElement('div');
		feedbackWrapper.className = 'feedbackWrapper';
		feedbackWrapper.style.height = '0px';
		feedbackWrapper.style.width = '0px';
		document.getElementsByTagName('body')[0].appendChild(feedbackWrapper);
		
		
		// position of wrapper
		var xPos = document.body.clientWidth;
			xPos = parseInt((xPos / 2) - 300);
		feedbackWrapper.style.left = xPos + 'px';

		html += '<h2>Feedback <a href="javascript:closeFeedBack()"><img src="/data/closePopup.gif" /></a></h2>';
		html += '<iframe src="/feedback.cfm?language=' + language + '" frameborder="0"></iframe>';
		
		feedbackWrapper.innerHTML = html;
		
		feedback();
	}else{
		
		var height = feedbackWrapper.style.height;
			height = parseInt(height.replace('px', ''));
			height = height + 8;
		var width = feedbackWrapper.style.width;
			width = parseInt(width.replace('px', ''));
			width = width + 12;
		
		feedbackWrapper.style.height =  height + 'px';
		feedbackWrapper.style.width =  width + 'px';
		
		if(height < 400){
			setTimeout('feedback()', 0);
		}
		
	}
	
	return false;
	
}


function closeFeedBack(){
	document.getElementsByTagName('body')[0].removeChild(feedbackWrapper);
	feedbackWrapper = null;
}
/*
	// FEEDBACK
*/  /*
  findPos
*/
function findPos(obj){
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}  /*
	getElementsByClassName
*/
document.getElementsByClassName = function (needle){
    var s = [document.documentElement || document.body], i = 0, r = [], l = 0, e;
    var re = new RegExp('(^|\\s)' + needle + '(\\s|$)');

    do{
        e = s[i];

        while (e){
            if (e.nodeType == 1){
                if (e.className && re.test(e.className)) r[l++] = e;

                s[i++] = e.firstChild;
            }

            e = e.nextSibling;
        }
    }
	
    while (i--);

    return r;
} /*
  handleBodyLoad
*/
function handleBodyLoad(){
  markLinks();
  initZoom();
  initTab();
  zebraTables();
  
  highlightQuery();

  /*searchAsYouType = new searchAsYouType();
  searchAsYouType.initHandler('qGlobal');
  searchAsYouType.initHandler('q-0');*/
 
  initColScroller();
  initAnalyzer();

 
  if(document.getElementById('feedbackLink')) document.getElementById('feedbackLink').onclick = feedback;
  if(document.getElementById('mailThisPageLink'))document.getElementById('mailThisPageLink').onclick = mailThisPage;
}  /*
 init thumbnails
*/
function initThumbnails(){
	var thumbnails = document.getElementsByTagName('img');
	var thumbnail;
	
	for(var i = 0; i < thumbnails.length; i++)	{
		thumbnail = thumbnails[i];
		
		if(thumbnail.className.toLowerCase() == 'thumbnail'){
			
			thumbnail.parentNode.setAttribute('naturalWidth', thumbnail.width);
			thumbnail.parentNode.setAttribute('naturalHeight', thumbnail.height);
			
			// resize image
			if(thumbnail.width > thumbnail.height){
				thumbnail.style.width = '90px';
			}else{
				thumbnail.style.height = '60px';
			}
			
			// create popup
			thumbnail.parentNode.onclick = function(){
				var iWidth = this.getAttribute('naturalWidth');
				var iHeight = this.getAttribute('naturalHeight');
				
				createPopup(this.getAttribute('href'), 'thumbnail', sDefaultFeatures, iWidth, iHeight);
				
				return false;
			}
		}
	}
	
	thumbnails = null;
	thumbnail = null;
}  /*
	MAIL THIS PAGE
*/
var mailThisPageWrapper;
function mailThisPage(){
	if(!mailThisPageWrapper){
		var html = '';
		var language = document.getElementsByTagName('html')[0].getAttribute('lang');
		
		mailThisPageWrapper = document.createElement('div');
		mailThisPageWrapper.className = 'mailThisPageWrapper';
		mailThisPageWrapper.style.height = '0px';
		mailThisPageWrapper.style.width = '0px';
		document.getElementsByTagName('body')[0].appendChild(mailThisPageWrapper);
		
		
		// position of wrapper
		var xPos = document.body.clientWidth;
			xPos = parseInt((xPos / 2) - 200);
		mailThisPageWrapper.style.left = xPos + 'px';

		html += '<h2>Mail this page <a href="javascript:closeMailThisPage()"><img src="/data/closePopup.gif" /></a></h2>';
		html += '<iframe src="/mailThisPage.cfm?language=' + language + '" frameborder="0"></iframe>';
		
		mailThisPageWrapper.innerHTML = html;
		
		mailThisPage();
	}else{
		
		var height = mailThisPageWrapper.style.height;
			height = parseInt(height.replace('px', ''));
			height = height + 9;
		var width = mailThisPageWrapper.style.width;
			width = parseInt(width.replace('px', ''));
			width = width + 12;
		
		mailThisPageWrapper.style.height =  height + 'px';
		mailThisPageWrapper.style.width =  width + 'px';
		
		if(height < 300){
			setTimeout('mailThisPage()', 0);
		}
		
	}
	
	return false;
	
}


function closeMailThisPage(){
	document.getElementsByTagName('body')[0].removeChild(mailThisPageWrapper);
	mailThisPageWrapper = null;
}
/*
	// MAIL THIS PAGE
*/ /*
 mark links
*/
function markLinks(){
	var links = document.getElementsByTagName('a');
	var link, href, mark;

	for(var i = 0; i < links.length; i++){
		link = links[i];
		
			
		switch(link.getAttribute('rel')){
			case 'ext': case 'external':
				link.className += ' external';
				link.target = '_blank';
				
				
				if(link.getElementsByTagName('img').length == 0){
					href = link.getAttribute('href').toLowerCase();
					href = href.substring((href.length - 4), (href.length));

					switch(href){
						case '.pdf':
							link.className += ' pdf';
							mark = document.createElement('img');
							mark.src = '/data/link-icons/pdf.png';
							link.insertBefore(mark , (link.firstChild));
							break;
						
						case '.xls':
							link.className += ' xls';
							mark = document.createElement('img');
							mark.src = '/data/link-icons/xls.png';
							link.insertBefore(mark , (link.firstChild));
							break;
							
						case '.doc':
							link.className += ' pdf';
							mark = document.createElement('img');
							mark.src = '/data/link-icons/doc.png';
							link.insertBefore(mark , (link.firstChild));
							break;
							
						case '.ppt':
							link.className += ' pdf';
							mark = document.createElement('img');
							mark.src = '/data/link-icons/ppt.png';
							link.insertBefore(mark , (link.firstChild));
							break;
							
						default:
							mark = document.createElement('img');
							mark.src = '/data/link-icons/external.png';
							link.appendChild(mark);
							break;
				}
			}
		}
	}
	
	links = document.getElementById('content').getElementsByTagName('a');
	
	for(var i = 0; i < links.length; i++){
		if(links[i].getAttribute('href')){
			href = document.createElement('span');
				href.className = 'print';
				href.appendChild((document.createTextNode(' [' + links[i].href + ']')));
			
			links[i].appendChild(href);
		}
	}
	
	mark = null;
	href = null;
	link = null;
	links = null;
}
 var aPopups = new Array();
var aModalPopups = new Array();

window.onfocus = function()
{
	if(aModalPopups.length != 0)
	{
		aModalPopups[0].focus();
	}
}


var sDefaultFeatures = 'channelmode=0, fullscreen=0, location=0, menubar=0, resizable=0, scrollbars=0, status=0, titlebar=0, toolbar=0';

// create popup
function createPopup(URL, name, features, width, height)
{
	var left	= (screen.availWidth - width) / 2;
	var top		= (screen.availHeight - height) / 2;
	
	return window.open(URL, name, features + ', width=' + width + ', height=' + height + ', left=' + left + ', top=' + top);
	
	left = null;
	top = null;
} function handleAnalyzerChange() {
	var image = document.getElementById('analyzerImage');
	var documentItemID = document.getElementById('analyzerDocumentItemID').value;
	
	document.getElementById('analyzerImageWrapper').style.display = 'block';
	
	image.style.display = 'none';
	
	if ((getYearList() != '') && (getCategoryList() != '')) {
		image.src='/postoffice/financialCommunication.cfc?method=getAnalyzerResultsGraphic&documentItemID=' + documentItemID + '&years='+  getYearList() + '&categories='+getCategoryList();
		image.style.display = 'block';
	} else {
		image.style.display = 'none';
	}
}

function getYearList() {
	var currentYearList = '';
	var checkboxYearList = document.getElementById('years').getElementsByTagName('input');

	for (var i=0; i < checkboxYearList.length; i++) {
		if (checkboxYearList[i].checked) {
			if (currentYearList != '') {
				currentYearList += ',';
			} 
			/*currentYearList += checkboxYearList[i].id.replace('year-','');*/
                        currentYearList += (i+1);
		}
	}
	
	return currentYearList;
}

function getCategoryList() {
	var currentCategoryList = '';
	var checkboxCategoryList = document.getElementById('categories').getElementsByTagName('input');

	for (var i=0; i < checkboxCategoryList.length; i++) {
		if (checkboxCategoryList[i].checked) {
			if (currentCategoryList != '') {
				currentCategoryList += ','
			} 
			currentCategoryList += checkboxCategoryList[i].id.replace('category-','');
		}
	}
	
	return currentCategoryList;
}

function initAnalyzer(){
	if(!document.getElementById('analyzer')) return;
	
	var inputs = document.getElementById('analyzer').getElementsByTagName('input');
	
	for(var i = 0; i < inputs.length; i++){
		if(inputs[i].type.toLowerCase() == 'checkbox'){
			inputs[i].onchange = handleAnalyzerChange;
		}
	}
}
 function initColScroller(){
	if(!document.getElementById('colScroller')) return;
	
	var table = document.getElementById('colScroller');
	var numCols = table.rows[0].cells.length;
	
	for(var i = 5; i < numCols; i++){
		hideCol(table, i);
	}
	
	table.setAttribute('previousCol', null);
	table.setAttribute('nextCol', 5);
	table.setAttribute('cols', numCols - 1);
	
	var caption = document.createElement('caption');
	var captionHTML = '';
		captionHTML += '<div>';
			captionHTML += '<a href="javascript:showPreviousCol(document.getElementById(\'colScroller\'), 4);" class="previous">«</a>';
			captionHTML += '<a href="javascript:showNextCol(document.getElementById(\'colScroller\'), 4);" class="next">»</a>';
		captionHTML += '</div>';
		
	caption.innerHTML = captionHTML;
	table.insertBefore(caption, (table.getElementsByTagName('thead')[0]))
}

function showPreviousCol(table, maxColumns){
	var previousCol = parseInt(table.getAttribute('previousCol'));
	if(isNaN(previousCol)) return;
	
	var cols = parseInt(table.getAttribute('cols'));
	
	showCol(table, previousCol);
	hideCol(table, (previousCol + parseInt(maxColumns)));
	
	if(previousCol > 1){
		table.setAttribute('previousCol', previousCol - 1);
		table.setAttribute('nextCol', previousCol + maxColumns)
	}else{
		table.setAttribute('previousCol', null);
		table.setAttribute('nextCol', previousCol + maxColumns)
	}
}

function showNextCol(table, maxColumns){
	var nextCol = parseInt(table.getAttribute('nextCol'));
	if(isNaN(nextCol)) return;
	
	var cols = parseInt(table.getAttribute('cols'));
	
	showCol(table, nextCol);
	hideCol(table, (nextCol - parseInt(maxColumns)));
	
	if(nextCol < cols){
		table.setAttribute('nextCol', nextCol + 1);
		table.setAttribute('previousCol', nextCol - maxColumns);
	}else{
		table.setAttribute('previousCol', nextCol - maxColumns);
		table.setAttribute('nextCol', null);
	}
}

function showCol(table, colNumber){
	var rows = table.rows;
	
	for(var i = 0; i < rows.length; i++){
		if(document.all){
			rows[i].cells[colNumber].style.display = '';
		}else{
			rows[i].cells[colNumber].style.display = 'table-cell';
		}
	}
}

function hideCol(table, colNumber){
	var rows = table.rows;
	
	for(var i = 0; i < rows.length; i++){
		rows[i].cells[colNumber].style.display = 'none';
	}
}
 // getcookie
function getCookie(sName){
	var aCookie = document.cookie.split("; ");
	
	for (var i=0; i < aCookie.length; i++){
		var aCrumb = aCookie[i].split("=");
		if (sName == aCrumb[0]){
			return unescape(aCrumb[1]);
		}
	}
	
	return null;
}
 /*
  econostoAndERIKS
*/
var econostoAndERIKSWrapper;
function showEconostoAndERIKS(){
	var wrapper = econostoAndERIKSWrapper;
	
	if(!wrapper){
		wrapper = document.createElement('div');
		wrapper.id = 'econostoAndERIKSWrapper';
		
		wrapper.innerHTML = '<iframe frameborder="0" src="/econostoAndERIKS/index.cfm"></iframe>';
		
		document.body.appendChild(wrapper);
		
		econostoAndERIKSWrapper = wrapper;
	}
	
	if(document.all) wrapper.style.height = document.body.offsetHeight + 'px';
	wrapper.style.display = 'block';
	document.getElementById('site').style.display = 'none';
}

function hideEconostoAndERIKS(){
	econostoAndERIKSWrapper.style.display = 'none';
	document.getElementById('site').style.display = 'block';
} /*
  search as you type
*/	
function searchAsYouType(){
	
}

searchAsYouType.prototype.initHandler = function(id){
	if(!document.getElementById(id)) return;
	
	var input = document.getElementById(id);
	input.setAttribute('autocomplete', 'off');
	input.onkeyup = searchAsYouType.handleInputKeyUp;
}

searchAsYouType.prototype.getContainer = function(){
	var container;
	
	if(document.getElementById('searchAsYouTypeContainer')){
		container = document.getElementById('searchAsYouTypeContainer');
		
		while(container.firstChild) container.removeChild(container.firstChild);
	}else{
		container = document.createElement('div');
		container.id = 'searchAsYouTypeContainer';
		document.body.appendChild(container);
	}
	
	var pos = findPos(searchAsYouType.input);
	var x = pos[0];
	var y = pos[1] + searchAsYouType.input.offsetHeight;
	var width = searchAsYouType.input.offsetWidth;
	if(width < 300) width = 300;
	
	container.style.display = 'block';
	container.style.top = y + 'px';
	container.style.left = x + 'px';
	container.style.width = width + 'px';
	container.className = searchAsYouType.input.id;
	
	document.body.onclick = function(){
		document.getElementById('searchAsYouTypeContainer').style.display = 'none';
		document.body.onclick = null;
	}
		
	return container;
}

searchAsYouType.prototype.handleInputKeyUp = function(){
	
	if(!searchAsYouType.HTTPRequest){
		searchAsYouType.input = this;
		searchAsYouType.HTTPRequest = new XMLHttpRequest();
		
		searchAsYouType.HTTPRequest.onreadystatechange = searchAsYouType.handleResults;
		
		searchAsYouType.HTTPRequest.open('GET', '/postoffice/search.cfc?method=search&q='+this.value, true);
		searchAsYouType.HTTPRequest.send('');				
	}
	
}

searchAsYouType.prototype.handleResults = function(){
	if(searchAsYouType.HTTPRequest.readyState == 4){
		
		searchAsYouType.results = eval(searchAsYouType.HTTPRequest.responseText);
		searchAsYouType.HTTPRequest = null;
		
		var a, strong, em;
		var container = searchAsYouType.getContainer();
		if(searchAsYouType.results.length == 0) container.style.display = 'none';

		
		for(var i = 0; i < searchAsYouType.results.length; i++){
			
			var a = document.createElement('a');
			var strong = document.createElement('strong');
			var em = document.createElement('em');
			
			a.href = searchAsYouType.results[i][1];
			a.onclick = function(){
				document.cookie = 'q=' + searchAsYouType.input.value + '; path=/';
			}
			
			strong.appendChild(document.createTextNode(searchAsYouType.results[i][0].replace(/<b>/gi,'').replace(/<\/b>/gi,'')));
			a.appendChild(strong);
			
			em.appendChild(document.createTextNode(searchAsYouType.results[i][1]));
			a.appendChild(em);
			
			container.appendChild(a);
			

		}
	}
} /*
  search highlighting
*/
var words;
function highlightQuery() {
	notAllowed = ["home/search/"];	
	for (var i=0; i < notAllowed.length; i++) {
		if (window.location.href.indexOf(notAllowed[i])>=0) {
			return;
		}
	}	

	// google	
	var startIndex = document.referrer.indexOf('&q='); 
	if (startIndex < 0) {
		startIndex = document.referrer.indexOf('?q='); 
	}
	
	// yahoo
	if(startIndex < 0){
		startIndex = document.referrer.indexOf('&p=');
		
		if(startIndex < 0){
			startIndex = document.referrer.indexOf('?p=');
		}
	}
	
	var endIndex = -1;
	if (startIndex >= 0) {
		endIndex = document.referrer.substr(startIndex+3).indexOf('&') + startIndex  +3; 
		
		if (endIndex < (startIndex+3)) {
			endIndex = document.referrer.length;
		}
	}

	var query = '';
	if ((startIndex>0 ) && (endIndex>0) && (startIndex+3 < endIndex)) {
		query = document.referrer.substring(startIndex+3, endIndex);
	}else{
		if( (getCookie('q')) && ((getCookie('q')).length > 0)){
			query = getCookie('q');
			document.cookie = 'q=; path=/';
		}
	}
        
	if(query != ''){
		words = query.toLowerCase().split('+');
		
		for (var i = 0; i < words.length; i++) {
			highlightLeave(document.getElementsByTagName('body')[0], i);
		}
	}
}


function highlightLeave(X, n) {
	var currentNode='';
	if (X.childNodes.length > 0) {
		while((currentNode=='') || (currentNode.nextSibling)) {
			
			if (currentNode=="") {
				currentNode = X.firstChild; 
			} else {
				currentNode = currentNode.nextSibling;
			}
					
			if (currentNode.nodeType != 3) {
				highlightLeave(currentNode, n);
			} else {
				nodeValue = currentNode.nodeValue;
				while (nodeValue.toLowerCase().indexOf(words[n]) >= 0) {
					var startIndex = nodeValue.toLowerCase().indexOf(words[n]);
					var endIndex = nodeValue.toLowerCase().indexOf(words[n]) + words[n].length;
					

					var preText = document.createTextNode(nodeValue.substring(0, startIndex));
					var highlightText = document.createTextNode(nodeValue.substring(startIndex,endIndex));
					var highlightContainer = document.createElement('span');
					highlightContainer.className = 'searchHighlight' + ((n%10)+1);
					highlightContainer.appendChild(highlightText);
					currentNode.parentNode.insertBefore(preText,currentNode);
					currentNode.parentNode.insertBefore(highlightContainer,currentNode);
					nodeValue = nodeValue.substr(endIndex);
					currentNode.nodeValue = nodeValue; 
				}
			}

		}
	}

} function switchkaart(nr) {
	var americaKaart = document.getElementById('NorthAmericaImg');

	americaKaart.src = '/eriksusa/img/company/us region/kaartAmerica'+nr+'.png';
}

function switchkaarttotaal() {
	var americaKaart = document.getElementById('NorthAmericaImg');
	americaKaart.src = '/eriksusa/img/company/us region/kaartAmericatotaal.png';
}

function showAddress(show) {
	var americaDiv1 = document.getElementsByClassName('americaMidwest')[0];
	var americaDiv2 = document.getElementsByClassName('americaWest')[0];
	var americaDiv3 = document.getElementsByClassName('americaWestAnaheim')[0];
	var americaDiv4 = document.getElementsByClassName('americaEast')[0];


	if(show == 1){
		americaDiv1.style.display = 'block';
		americaDiv2.style.display = 'none';
		americaDiv3.style.display = 'none';
		americaDiv4.style.display = 'none';
	}
	if(show == 2){
		americaDiv1.style.display = 'none';
		americaDiv2.style.display = 'block';
		americaDiv3.style.display = 'none';
		americaDiv4.style.display = 'none';
	}
	if(show == 3){
		americaDiv1.style.display = 'none';
		americaDiv2.style.display = 'none';
		americaDiv3.style.display = 'block';
		americaDiv4.style.display = 'none';
	}
	if(show == 4){
		americaDiv1.style.display = 'none';
		americaDiv2.style.display = 'none';
		americaDiv3.style.display = 'none';
		americaDiv4.style.display = 'block';
	}

}  /*
 tabbed navigation
*/
function initTab(){
	var hash = window.location.hash;
	
	if(hash.indexOf('#tab') == -1){
		var startTab = document.getElementsByClassName('startTab')[0];
		if(startTab){
			var tabID = startTab.id.replace('di', '');
			window.open('#tab-' + tabID, '_self');
			initTab();
			return;
		}
	}
	
	var tabID = hash.replace('#tab-', ''); 
	
	var tabNavigation = document.getElementsByClassName('tabnavigation')[0];
	
	if(tabNavigation && tabNavigation.nodeName.toLowerCase() != 'p'){
		var links = tabNavigation.getElementsByTagName('a');
		for(var i = 0; i < links.length; i++){
			if(links[i].href.indexOf('showTab(' + tabID + ')') == -1){
				links[i].parentNode.className = '';
			}else{
				links[i].parentNode.className = 'active';
			}
		}
		
		var tabs = document.getElementsByClassName('isTab');
		for(var i = 0; i < tabs.length; i++){
			tabs[i].className = tabs[i].className.replace('showTab', '');
		}
		
		var tab = document.getElementById('di'+tabID);
			tab.className += ' showTab';
		
		// check for and stop media players
		var mediaObjects = document.getElementsByTagName('object');
		var mediaEmbeds = document.getElementsByTagName('embed');
		
		for(var i = 0; i < mediaObjects.length; i++){
			try{mediaObjects[i].stop()}catch(e){};
		}
		
		for(var i = 0; i < mediaEmbeds.length; i++){
			try{mediaEmbeds[i].stop()}catch(e){};
		}
	}
	
	hash = null;
	tabNavigation = null;
	tabs = null;
	tab = null;
	mediaObjects = null;
	mediaEmbeds = null;
	
}

function showTab(tabID){
	window.open('#tab-' + tabID, '_self');
	initTab();
} /*
	zebra tables
*/
function zebraTables(){

	var rows = document.getElementsByTagName('tr');

	for(var i = 0; i< rows.length; i++){

		if((i % 2) == 0){

			rows[i].className += ' odd';

		}else{

			rows[i].className += ' even';

		}
	}
} // zoomlinks
function initZoom(){
	var zoom = getCookie('zoom');
	
	if(zoom == null){
		document.getElementsByTagName('body')[0].className += ' normal';
	}else{
		document.getElementsByTagName('body')[0].className += ' ' + zoom;
	}
}

function zoom(factor){
	var className = document.getElementsByTagName('body')[0].className;
	className = className.replace(' big', '');
	className = className.replace('big', '');
	className = className.replace(' normal', '');
	className = className.replace('normal', '');
	className = className.replace(' small', '');
	className = className.replace('small', '');
	className += ' ' + factor;
	
	document.cookie = 'zoom=' + factor + '; path=/';
	document.getElementsByTagName('body')[0].className = className;
}


