window.addEvent('domready', function() {
	showreactie_toggle();
	wachtwoord_toggle();
	applyEllipses();
});


function GotoPrintPage(id)
{
	window.open('/Print.aspx?id='+ id, '', 'width=700px, resizable=true, scrollbars=yes');
}

function GotoMailPage(id)
{
	window.open('/layouts/MailPagina.aspx?pagid='+ id, '', 'width=550px, height=400px');
}

function ShowHideNieuwsOverzichtItems(pWeek, pDay)
{
	  
	  /*alert('ShowHideNieuwsOverzichtItems');*/
	  
	  var dayId = 'day_' + pWeek + '_' + pDay;
    
    $$('#week_' + pWeek + ' div.dayGroup').each(function(el)
    {
        el.style.display = (el.id == dayId) ? '' : 'none';
    });
    
	// onderstaande zorgt dat bij wisselen van dag binnen een uitgeklapte week, de container direct de juiste hoogte krijgt
	if ($$('#week_' + pWeek + ' div.dayGroup') &&
	    $$('#week_' + pWeek + ' div.dayGroup')[0] &&
	    $$('#week_' + pWeek + ' div.dayGroup')[0].parentNode &&
	    $$('#week_' + pWeek + ' div.dayGroup')[0].parentNode.getStyle &&
	    $$('#week_' + pWeek + ' div.dayGroup')[0].parentNode.getStyle('visibility') == 'visible') 
	{
		$$('#week_' + pWeek + ' div.dayGroup')[0].parentNode.setStyle('height', 'auto');
	}
	
    for (var d=2; d<7; d++)
    {
    	  var el = $('day_click_' + pWeek + '_' + d);
        if (el) el.className = (d == pDay) ? 'dot_active' : 'dot_inactive';
    }
}


function VindEenBaan()
{
	var zs = document.getElementById("jobfinder_job").value;
	var afstand = document.getElementById("jobfinder_afstand").value;
	var city = document.getElementById("jobfinder_city").value;
	
	if (city == 'Plaatsnaam')
	    city = '';
	
	if (zs == 'Zoekterm of referent')
	    zs = '';
	    
	//window.open('http://ag.careercast.com/careers/jobsearch/results?kAndEntire= '+zs+';radius='+afstand+';city='+city+';sortBy=relevance;pageSize=20');
	window.location='http://ag.careers.adicio.com/careers/jobsearch/results?kAndEntire= '+zs+';radius='+afstand+';city='+city+';sortBy=relevance;pageSize=20';
	return false;
}

function OpenReactieDiv(idTitle, idFormulier)
{
	document.getElementById(idTitle).style.display = 'block';
	document.getElementById(idFormulier).style.display = 'block';
}

function showreactie_toggle() {
	if (!($('showreactie'))) { return; }
	$('showreactie').addEvent('click', function(){
		$('showreactiecollapsible').effect('height',{
			duration: 500
		}).start($('showreactiecollapsible').scrollHeight);
		$('reactiecollapsible').effect('height',{
			duration: 500
		}).start($('reactiecollapsible').scrollHeight);
	});
}

function wachtwoord_toggle()
{
    if(!($('lnkWachtwoordvergetn'))) {return; }
    	$('lnkWachtwoordvergetn').addEvent('click', function(){
		$('wachtwoordvergetencollapsibled').effect('height',{
			duration: 500
		}).start($('wachtwoordvergetencollapsibled').scrollHeight);
		$('a').effect('height',{
			duration: 500
		}).start($('wachtwoordvergetencollapsibled').scrollHeight);
	});
}

function applyEllipses()
{
    var tags = new Array('span');
    for (t=0; t<tags.length; t++) {
        var el = document.getElementsByTagName(tags[t]);
        for (i=0; i<el.length; i++) {
            if (el[i].className.indexOf('ellipsisSpan') != -1) {
                autoEllipseText(el[i], el[i].className);
            }
        }
    }
}
/************************************************************************************
 * De autoEllipseText method kapt de text als het groter is dan de gegeven breedte 
 * en voegt op het einde de '...'
 * Er wordt verwacht dat de gegeven element de volgende style heeft:
 *  style="white-space:nowrap;"
 ************************************************************************************/
function autoEllipseText(element, className)
{
   var width = (className == 'ellipsisSpanA') ? 280 : 300;
   if(element.offsetWidth> width)
   {
      var text = element.innerHTML;
      var i = 1;
      element.innerHTML = '';
      
      while(element.offsetWidth <(width) && i <text.length)
      {
         element.innerHTML = text.substr(0,i) + '...';
         i++; 
      }            
   }
}

function getZoekResultaten(varType, ctrlInput)
{    
    var url = "/Zoeken.aspx?search=" + $(ctrlInput).value;
	if (varType != '') url += "&type=" + varType;
	document.forms[0].onsubmit = function() { return false; }
	document.forms[0].action = url;
	document.location = url;
}

function opEnterZoek(e, dit) 
{
	var keynum;
	if (window.event) // IE
	{
	    keynum = e.keyCode
	}
	else if (e.which) // Netscape/Firefox/Opera
	{
	    keynum = e.which
	}
	
	if(keynum == 13)
	{
		window.onunload = function() {
			if(actie!="") document.location.href=actie
		}
		
		waarde = dit.value;
		actie='/Zoeken.aspx?search=' + dit.value;
				
		document.location.href = actie;
				
		//getZoekResultaten('', 'top_search_field');
		//window.event.cancelBubble = true;	
	}
}