var oMatrixheight;

onload = function (){
	if(document.getElementById) {
		//kijk of object aanwezig is
		if(document.getElementById("wizard-matrix"))
		{
			// alleen als het knopje aamwezig is
			if(document.getElementById("toggle-matrix"))
			{
				var owizardMatrix=document.getElementById("wizard-matrix");
				//wat is inititiële hoogte van object
				oMatrixheight = parseInt((owizardMatrix.offsetHeight) + 15);
				//verberg object en zet hoogte op 0px
				owizardMatrix.style.display = "none";
				owizardMatrix.style.visibility='hidden';
				owizardMatrix.style.height='0px';
				document.getElementById("toggle-matrix").href="javascript:toggleMatrix();"
			}
		}
	}
}

function toggleMatrix() {
	if(document.getElementById) {
		var owizardMatrix=document.getElementById("wizard-matrix");
		//als object getoond wordt maak klein en verander tekst knop titel
		if(owizardMatrix.style.display == "block") {
			document.getElementById("toggle-matrix").innerHTML = "Toon het overzicht";
			setsmallheight();
		} 
		//als object niet getoond wordt maak groot en verander tekst knop titel
		else {
			owizardMatrix.style.display = "block";
			document.getElementById("toggle-matrix").innerHTML = "Verberg het overzicht";
			setlargeheight();
			owizardMatrix.style.visibility='visible';
		}
	}
}

function setsmallheight(){
	var owizardMatrix=document.getElementById("wizard-matrix")
	//wat is huidige hoogte van object
	var oheight=parseInt(owizardMatrix.style.height.substring(0,owizardMatrix.style.height.lastIndexOf('px')))
	//als hoogte groter is dan 1 maak kleiner
	if(oheight>1){
	  var posy = Math.ceil(oheight/2);
		if (posy >50) {posy =35}
 		owizardMatrix.style.height=(parseInt(oheight-posy))+'px';
		//herhaal functie om animatie effect te krijgen
		setTimeout("setsmallheight()",1);
		document.getElementById("toggle-matrix").href="#"
	}
	//als object kleiner is, verberg object
	else  {
	owizardMatrix.style.display = "none";
	document.getElementById("toggle-matrix").href="javascript:toggleMatrix();"
	}
}
function setlargeheight(){
var owizardMatrix=document.getElementById("wizard-matrix")
//wat is huidige hoogte van object
var oheight=parseInt(owizardMatrix.style.height.substring(0,owizardMatrix.style.height.lastIndexOf('px')))
	//als hoogte kleiner is dan inititiéle hoogte maak even groot
	if(oheight<oMatrixheight){
		var posy=Math.ceil((oMatrixheight-oheight)/2);
		if (posy >50) {posy =35}
		owizardMatrix.style.height=(parseInt(oheight+posy))+'px';
		//herhaal functie om animatie effect te krijgen
		setTimeout("setlargeheight()",1);
		document.getElementById("toggle-matrix").href="#"
	}
	else{
	document.getElementById("toggle-matrix").href="javascript:toggleMatrix();"
	}
}

function show_hide(object1,object2){
show = true;
var obj1 = document.getElementById(object1).getElementsByTagName("div");
var obj2 = document.getElementById(object2);
if (obj2.style.display == '')
	show = false;
for (i = 0; i < obj1.length; i++) {
	obj1[i].style.display = 'none'; 
} 
if (show == true)
	obj2.style.display = ''; 
} 

/*
Nice little piece of JavaScript code that works with a combination
of div elements
	 <div class="label">The label</div>
   <div class="content">The content</div>
	 
By clicking on the label the content is shown and hidden.

Adapted by Rob Hofker from code found at 
  http://www.quirksmode.org/index.html?/js/display.html	  
*/

/* function initShowHide
	 intilializes all label divs by adding the clickLabelDiv function to the
	 onclick event 
	 finaly it calls the function closeLabelDiv, hiding all but max divs
	 
	 NB use this function in the unload of the page */
function initShowHide(max) {
  var x = document.getElementsByTagName('div');
  for (var i=0;i<x.length;i++)
  {
    if (x[i].className == 'faqlabel')
    x[i].onclick = clickLabelDiv;
  }
  closeLabelDiv(max);
}

/* function closeLabelDiv
	 hides all content divs but skips all till max, those are left open
*/
function closeLabelDiv(max)
{
  var x = document.getElementsByTagName('div');
  var skip = 0;
  for (var i=0;i<x.length;i++)
  {
     if (x[i].className == 'content') {
      skip++;
      // Items till max are left open
      if (skip > max) x[i].style.display = 'none';
    }
  }
}

/* function clickLabelDiv
	 hides/shows the content div that belongs to the label div
*/
function clickLabelDiv(e)
{
  if (!e) e = window.event;
  if (e.target) var tg = e.target;
  else if (e.srcElement) var tg = e.srcElement;
  while (tg.nodeName != 'DIV') // Safari GRRRRRRRRRR
    tg = tg.parentNode;
  var nextSib = tg.nextSibling;
  while (nextSib.nodeType != 1)
    nextSib = nextSib.nextSibling;
  var nextSibStatus = (nextSib.style.display == 'none') ? 'block' : 'none';
  nextSib.style.display = nextSibStatus;	
}

/* function removeMask
	 removes the input mask if the value is equal to the input mask
*/
function removeMask( obj )
{
	if( obj.value == obj.getAttribute("mask") )
	{
		obj.value = "";
	}
	return( true );
}


/* function placeMask
	 places the input mask if the value is empty
*/
function placeMask( obj )
{
    var trimmedValue = obj.value.replace(/(^\s*)/g, "");	//strip whitespace at start
	trimmedValue = trimmedValue.replace(/(\s*$)/g, "");	//strip whitespace at end

	if(trimmedValue == "" )
	{
		obj.value = obj.getAttribute("mask");
	}
	return( true );
}

function CreatePopUp( url ) 
{
	//window.open( url, "popup", "width=580,height=600,scrollbars=no,status=no,resizable=no" );
	CreatePopUpWithSize (url, 580, 600);
}

function CreateBelMePopUp (url) {
	CreatePopUpWithSize (url, 580, 680);
}

function CreatePopUpWithSize (url, width, height) 
{
	window.open( url, "popup", "width=" + width + ",height=" + height + ",scrollbars=no,status=no,resizable=no" );
}

function printPage()
{
	print();
}

/* resizing iframes */
function doresize() {
	if (
		(xGetElementById('frmWizard')) &&
		(xGetElementById('frmWizard').style)
	) {
		var chromeHeight = xHeight('header');
		chromeHeight += xHeight('navigation');
		chromeHeight += xHeight('clickpath');
		chromeHeight += xHeight('footer');
		
		var divhoogte	= document.body.clientHeight - chromeHeight - 130;
		
		if (divhoogte <5) divhoogte = 5;
		xGetElementById('frmWizard').style.height = divhoogte  + 'px';		
	}
}

function tryResize() {
	//next resize iframe'
	if (xGetElementById('frmWizard') != null){
		// first temporarily detach event in IE, to prevent hanging
		if (window.attachEvent) {
			window.detachEvent("onresize", tryResize);
			doresize();
			window.attachEvent("onresize", tryResize);
		}
		else
		{
			doresize();
		}
	}
}

if (window.addEventListener) {
	//firefox
	window.addEventListener("load", tryResize, false);
	//window.addEventListener("load", hideprinter, false);
	window.addEventListener("resize", tryResize, false);
} else {
	if (window.attachEvent) {
		// ie
		window.attachEvent("onload", tryResize);
		//window.attachEvent("onload", hideprinter);
		window.attachEvent("onresize", tryResize);
	} else {
		// andere
		window.onload=tryResize;
		//window.onload=hideprinter;
		window.onresize=tryResize;
	}
}


var timer_id;
function scroll_iframe(frm,inc,dir) {
  if (timer_id) clearTimeout(timer_id);
  if (window.frames[frm]) {
    if (dir == "v") window.frames[frm].scrollBy(0, inc);
    else window.frames[frm].scrollBy(inc, 0);
    timer_id = setTimeout("scroll_iframe('" + frm + "'," + inc + ",'" + dir + "')", 20);
  }
}

function stopScroll() { if (timer_id) clearTimeout(timer_id); }

/* end resizing iframes */

/* cmsupdate */

function cmsUpdateMouseover( link )
{
	var row = link.parentNode.parentNode;
	for ( var i = 0; i < row.childNodes.length; i++ )
	{
		row.childNodes[i].firstChild.style.color = "Red";
	}
}

function cmsUpdateMouseOut( link )
{
	var row = link.parentNode.parentNode;
	for ( var i = 0; i < row.childNodes.length; i++ )
	{
		row.childNodes[i].firstChild.style.color = "Gray";
	}
}

/* end cmsupdate */

/* Keuzehulp */

/* keuzehulp.js */
 
if (document.getElementById && document.getElementsByTagName) {
 window.onload = initHideAll;
}
 
function initHideAll() {
 var kh = xGetElementsByClassName('keuzehulp');
 var dts = new Array();
 
 for (var j = 0; j < kh.length; j++) {
   dts = kh[j].getElementsByTagName('dt');
 
   for (var i = 0; i < dts.length; i++) {
    // now first toggle all off
  //  toggle( dts[i] );
    //add the toggle to the onclick
    dts[i].onclick = function() {
     toggle(this);
     return false;
    }
   }
 }
}
 
function toggle(l) {
 var dd = l.nextSibling;
  while (dd!= null && dd && dd.nodeType != 1)
 {
   dd = dd.nextSibling;
 }
 
  if(cssjs('check',dd,'hide'))
 {
   cssjs('remove',dd,'hide');
   l.style.backgroundImage = 'url(../images/keuzehulp/arrow-blue-up.gif)';
 }
 else
 {
   cssjs('add',dd,'hide');
  l.style.backgroundImage = 'url(../images/keuzehulp/arrow-blue-down.gif)';
 }
}
 
function cssjs(a,o,c1,c2)
{
  switch (a){
    case 'swap':
      o.className=!cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
    break;
    case 'add':
      if(!cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
    break;
    case 'remove':
      var rep=o.className.match(' '+c1)?' '+c1:c1;
      o.className=o.className.replace(rep,'');
    break;
    case 'check':
      return new RegExp('\\b'+c1+'\\b').test(o.className)
    break;
  }
}

/* end keuzehulp */
/* end cmsupdate */

/* click recording */
function recordClick(e)
{
	var posx = 0;
	var posy = 0;
	var wrapper = xGetElementById( 'wrapper' );
	// Wrapper is not defined.... Try wizardwrapper
	if ( wrapper == null )
	{
		wrapper = xGetElementById( 'wizardwrapper' );
	}
	// Wizardwrapper is not defined.... try popwrapper
	if ( wrapper == null )
	{
		wrapper = xGetElementById( 'popupwrapper' );
	}
	
	// Do not recordclick in popup wizards.
	/*
	if ( wrapper == null ) 
	{ 
		return; 
	}	
	*/

	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	
	{
		posx = e.pageX - wrapper.offsetLeft;
		posy = e.pageY - wrapper.offsetTop;
	}
	else if (e.clientX || e.clientY) 	
	{
		posx = e.clientX - wrapper.offsetLeft + wrapper.scrollLeft + document.documentElement.scrollLeft;
		posy = e.clientY + wrapper.scrollTop + document.documentElement.scrollTop;
		// no wrapper.offsetTop necessary.
	}
	
	var segment = '';
	var referrer = document.referrer;
	Unive.Site.Controlling.AjaxHandling.ClickManager.RecordClick(posx, posy, url, segment, referrer, recordClickCallBack );
}

// This method will be called after the method has been executed
// and the result has been sent to the client.

function recordClickCallBack(res)
{
}

// method for alert for premium action
// an 'alert' can not be used, because the styling cannot be changed
function showPremiumAlert( elm )
{

}

function SetTargetUrlForLandingPage(url)
{
var urlField = document.getElementById('hiddenurl');
urlField.value = url;
}

/*function added for styleguide functionality*/
function showcode (s){
	document.getElementById('overlaydiv').className = 'overlay';
	document.getElementById('htmlview').value = s;
	document.getElementById('codeview').className = 'showme';
	return false;
}

function PcToUrl()
{
var postcodeField = document.getElementById('homepagepcinput');
var postcode = postcodeField.value;
if ( postcode.length < 6 ) { return }
postcode = postcode.replace(' ','');
var zoekRegioKantoorLink = document.getElementById('zoekregiokantoorlink');
var newHref = "regionaal/zoekkantoor/" + postcode;
zoekRegioKantoorLink.href = newHref;
return true;
}

function FillSurAanvrAVvelden()
{
var ja = document.getElementById('container_ctl07_ctl02_rbl_0');
if ( ja.checked && UseProfile )
{
    document.getElementById('container_ctl08_ctl00_t').value = Initials;
    document.getElementById('container_ctl08_ctl02_t').value = Tussenvoeg;
    document.getElementById('container_ctl08_ctl04_t').value = LastName;
    document.getElementById('container_ctl09_ctl00_t').value = Postcode;
    document.getElementById('container_ctl09_ctl03_hn').value = Huisnummer;
    document.getElementById('container_ctl09_ctl03_hnp').value = HuisnummerToevoeging;
    document.getElementById('container_ctl10_t').value = BirthDate;
    document.getElementById('container_ctl17_t').value = EMail;
    document.getElementById('container_ctl15_t').value = Mobile;
    if ( Gender != null )
    {
        if ( Gender == "M" )
        {
            document.getElementById('container_ctl11_ctl02_rbl_0').checked = true;
        }
        else
        {
            document.getElementById('container_ctl11_ctl02_rbl_1').checked = true;
        }
    }
    
}
}

function ClearAVFields()
{
    document.getElementById('container_ctl07_ctl02_rbl_0').checked = false;
    document.getElementById('container_ctl08_ctl00_t').value = '';
    document.getElementById('container_ctl08_ctl02_t').value = '';
    document.getElementById('container_ctl08_ctl04_t').value = '';
    document.getElementById('container_ctl09_ctl00_t').value = '';
    document.getElementById('container_ctl09_ctl03_hn').value = '';
    document.getElementById('container_ctl09_ctl03_hnp').value = '';
    document.getElementById('container_ctl10_t').value = 'dd-mm-jjjj';
    document.getElementById('container_ctl17_t').value = '';
    document.getElementById('container_ctl15_t').value = '';
}

