document.observe("dom:loaded", function() {
	var sHash = document.location.hash;

	if ($('recent_list'))
	{
		$('recent_list').hide();
		$('recent_open').show();

		if (sHash == "#recent") {
			openRecentList();
			$('recent_open').onclick = closeRecentList;
		}
		else
		{
			$('recent_open').onclick = openRecentList;
		}
	}

	if ($$('.tabcontent') && $$('.tabcontent').length > 0)
	{
		if (sHash == "#t2") openTab('t2');
		else if (sHash == "#t3") openTab('t3');
		else if (sHash == "#t4") openTab('t4');
		else openTab('t1');

		$$('.tab').each(function(e) {
			if (e.down().href && e.down().rel)
			{
				e.down().observe("click", function() {
					openTab(this.rel);
					this.href = "javascript:void(0);";
				});
			}
		});
	}

	if ($$('.faqitem') && $$('.faqitem').length > 0)
	{
		$$('.faqlink').each(function(e) {
			e.observe("click", function() {
				toggleFaq(this.rel);
				this.href = "javascript:void(0);";
			});
		});
	}

	if ($('pop') && $('pop').visible())
	{
		$('pop').hide();
	}
});

function openRecentList()
{
	$('recent_open').down().src = $('recent_open').down().src.replace('darr', 'uarr');
	$('recent_open').href = '#';
	$('recent_list').show();
	$('recent_open').onclick = closeRecentList;
	return false;
}

function trim(value) {
  value = value.replace(/^\s+/,'');
  value = value.replace(/\s+$/,'');
  return value;
}

function closeRecentList()
{
	$('recent_open').down().src = $('recent_open').down().src.replace('uarr', 'darr');
	$('recent_open').href = '#recent';
	$('recent_list').hide();
	$('recent_open').onclick = openRecentList;
	return false;
}

function closeTabs()
{
	$$('.tabcontent').each(function(el) {
		el.hide();
		$$('.' + el.id)[0].removeClassName('current');
	});
}

function openTab(sTabId)
{
	closeTabs();
	$(sTabId).show();
	$$('.' + sTabId)[0].addClassName('current');

	window.scrollTo(0, 0);
}

function closeFaqs()
{
	$$('.faqitem').each(function(el) {
		el.hide();
	});
}

function toggleFaq(sFaqId)
{
	if ($(sFaqId).visible())
	{
//		closeFaqs();
		$(sFaqId).hide();
	}
	else
	{
//		closeFaqs();
		$(sFaqId).show();
	}
}

var highlighterCoverElement = "";
function loadHighlighters(sElId)
{
	if ($('hlOverlay').visible()) $('hlOverlay').hide();
	if ($('hlPopup').visible())   $('hlPopup').hide();
	if ($('hlShadow').visible())  $('hlShadow').hide();

	highlighterCoverElement = $(sElId);
	var aLinks = $(sElId).getElementsByTagName('A');
	for (var i = 0; i<aLinks.length; i++)
	{
		var oLink = aLinks[i];

		oLink.onclick = function()
		{
			var sImage = this.firstChild.src.substring(this.firstChild.src.indexOf('?') + 5, this.firstChild.src.length);
			showHighlighter(this.href, this.rel, sImage, this.firstChild.className.split("x"));
			return false;
		};
	}
}

function showHighlighter(sBrandUrl, sExternalUrl, sImage, aImageSize)
{
	if ($('hlOverlay').visible()) $('hlOverlay').hide();
	if ($('hlPopup').visible())   $('hlPopup').hide();
	if ($('hlShadow').visible())  $('hlShadow').hide();

	var iOverlayX = 0;
	var iOverlayY = 0;
/*@cc_on
	iOverlayX = -3;
	iOverlayY = -1;
@*/

	var oOverlay = $('hlOverlay');
	oOverlay.style.position = 'absolute';
	oOverlay.clonePosition(highlighterCoverElement, {
		'setLeft': true,
		'setTop': true,
		'setWidth': true,
		'setHeight': true,
		'offsetTop': iOverlayY,
		'offsetLeft': iOverlayX
	});

	oOverlay.setOpacity(0.8);
	oOverlay.show();

	var oPopup = $('hlPopup');
	oPopup.innerHTML = "";

	var oCloseLink = document.createElement('A');
	oCloseLink.id = 'hlClose';
	oCloseLink.href = "#";
	oCloseLink.innerHTML = 'X';
	oPopup.appendChild(oCloseLink);

	oPopup.innerHTML += '<br style="clear: right" />';

	var oBrandLink = document.createElement('A');
	oBrandLink.href = sBrandUrl;
	oBrandLink.innerHTML = '<img src="/images/upload/brands/' + sImage + '" alt="" width="' + aImageSize[0] + '" height="' + aImageSize[1] + '" />';
	oPopup.appendChild(oBrandLink);

	var iPopupWidth = aImageSize[0];

	if (sExternalUrl != '')
	{
		oPopup.innerHTML += '<br /><br />';

		var oExternalLink = document.createElement('A');
		oExternalLink.id = 'hlExternal';
		oExternalLink.target = '_blank';

		if (sExternalUrl.indexOf('://') < 1)
		{
			oExternalLink.href = 'http://' + sExternalUrl;
			oExternalLink.innerHTML = sExternalUrl;
		}
		else
		{
			oExternalLink.href = sExternalUrl;
			oExternalLink.innerHTML = sExternalUrl.substring(sExternalUrl.indexOf('://') + 3, sExternalUrl.length);
		}

		oPopup.appendChild(oExternalLink);
	}

	oPopup.style.position = 'absolute';
	oPopup.clonePosition(highlighterCoverElement, {
		'setLeft': true,
		'setTop': true,
		'setWidth': false,
		'setHeight': false,
		'offsetLeft': 120,
		'offsetTop': 180
	});
	oPopup.show();

	if (sExternalUrl != '')
	{
		if (oExternalLink.offsetWidth > iPopupWidth)
		{
			iPopupWidth = oExternalLink.offsetWidth;
		}
	}

	oPopup.style.width = iPopupWidth + 'px';

	var oShadow = $('hlShadow');
	oShadow.setOpacity(0.5);
	oShadow.style.position = 'absolute';
	oShadow.style.backgroundColor = '#000000';
	oShadow.clonePosition(oPopup, {
		'setLeft': true,
		'setTop': true,
		'setWidth': true,
		'setHeight': true,
		'offsetLeft': 10,
		'offsetTop': 10
	});
	oShadow.show();

	Event.observe('hlClose', 'click', function() {
		if ($('hlOverlay').visible()) $('hlOverlay').hide();
		if ($('hlPopup').visible())   $('hlPopup').hide();
		if ($('hlShadow').visible())  $('hlShadow').hide();
	});
}

function popDiv(sId)
{
	if ($(sId).visible())
	{
		$(sId).hide();
	}
	else
	{
		$(sId).show();
	}
}

function showRow(sId)
{
	$$('.' + sId).each(function (oEl) {
		if (oEl.style.display == 'none')
		{
			oEl.style.display = '';
		}
		else
		{
			oEl.style.display = 'none';
		}
	});
}

function showOrderButton()
{
//	alert(document.body.offsetHeight);

	if(document.body.offsetHeight > 1000)
	{
		document.getElementById('extra_orderbutton').style.display = "block";
	}
}

var aEnterButtonMaps = new Array();
function mapEnterToButton(sTextFieldId, sButtonId)
{
	oField = document.getElementById(sTextFieldId);
	oBtn   = document.getElementById(sButtonId);

	if (!oField || !oBtn) return;

	aEnterButtonMaps[sTextFieldId] = sButtonId;

	oField.onkeypress = checkForEnterKey;
}


function checkForEnterKey(e)
{
	if (!e) var e = window.event;

	var iKeyCode = e.keyCode;

	if (iKeyCode == 13)
	{
		var sButton = aEnterButtonMaps[this.id];
		var oButton = document.getElementById(sButton);

		if (oButton.onclick)
		{
			oButton.onclick();
			return false;
		}
		else
		{
			if (oButton.type.toLowerCase() == "reset")
			{
				this.form.reset();
				return false;
			}
			else if (oButton.type.toLowerCase() == "submit")
			{
				this.form.submit();
				return false;
			}
		}
	}
}

var k_push_vars = {
     "display_after": 1,
	"view_percentage": 100,
	"popup_font_color": "#000000",
	"popup_background": "#ACBFDA",
	"header": "Je reactie is belangrijk voor ons!",
	"question": "Zou je een korte reactie (1 minuut) willen geven?",
	"footer": "Bedankt voor het helpen om onze website te verbeteren",
	"remind": "",
	"remind_font_color": "#000000",	
	"yes": "Ja",
	"no": "Nee",
	"text_direction": "ltr",
	"images_dir": "http://cf.kampyle.com/",
	"yes_background": "#76AC78",
	"no_background": "#8D9B86",
	"site_code": 6883223
}


function showParticulier()
{
	document.getElementById('cust_company').style.display = 'none';
	document.getElementById('btn_particulier').className  =	'cust_particulier_active';
	document.getElementById('btn_business').className	  =	'cust_business_inactive';
	document.getElementById('cust_company').value	  	  =	'N';
}

function showBusiness()
{
	document.getElementById('cust_company').style.display 	  = '';
	document.getElementById('btn_particulier').className	  =	'cust_particulier_inactive';
	document.getElementById('btn_business').className	  	  =	'cust_business_active';
	document.getElementById('cust_company').value	  	 	  =	'Y';
}

function clearField(field_id,label)
{
	if(trim(document.getElementById(field_id).value) == label)
	{
		document.getElementById(field_id).value = '';
	}
}

function populateField(field_id,value)
{
	if(trim(document.getElementById(field_id).value) == '')
	{
		document.getElementById(field_id).value = value;
	}
}
 var mouseX;
 var mouseY;
function catchMouseMove(e)
{
	mouseX = Event.pointerX(e);
	mouseY = Event.pointerY(e);
	
}

function rolloverRating()
{
	document.getElementById('rating_rate').style.width = '0px';
	starsXs = findPosX(document.getElementById('rating_stars'));
	starsXe = starsXs+232;

	starsYs = findPosY(document.getElementById('rating_stars'));
	starsYe = starsYs+23;
	
//	alert(mouseX +" > "+ starsXs +" | "+ mouseX +" < "+ starsXe +" | "+ mouseY +" > "+ starsYs +" | "+ mouseY +" < "+ starsYe)
	
	if(mouseX >= starsXs && mouseX <= starsXe && mouseY >= starsYs && mouseY <= starsYe)
	{
//		alert(((mouseX - starsXs)%23));
		iExtra = 0;
		if((mouseX - starsXs) < 231)
		{
			if(((mouseX - starsXs)%23) > 0)
			{
				iExtra = (mouseX - starsXs)%23;
				iExtra = 23-iExtra;
			}
		}
		document.getElementById('rating_rollover').style.width =  ((mouseX - starsXs)+iExtra)+'px';
	}
	
}

function setRate()
{
	document.getElementById('rating_rollover').style.width = '0px';
	var val = document.getElementById('rating').value;
	
	nWidth = val * 23;
	nWidth += 23;
	
	document.getElementById('rating_rate').style.width = nWidth+'px';
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
	curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	var printstring = '';
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (obj.y)
	curtop += obj.y;
	window.status = printstring;
	return curtop;
}