/////////////////////////////////////////// BASIC FUNCTIONS, DON'T EDIT ///////////////////////////////////////////

// Starts loading these functions on loading the page:
window.addEvent('domready', function() {

	initCustomFunctions();

});




/////////////////////////////////////////// EDIT CUSTOM JAVASCRIPT BELOW THIS LINE ///////////////////////////////////////////

// Add all your custom function which need to be initialized to this function:
function initCustomFunctions() {
	//agentSelection();	
}

/////////////////////////////////////////// DEVELOPMENT FUNCTIONS ///////////////////////////////////////////

// AJAX call:
function ajaxCall(actie){
	var test = location.href.split('?');
	
	if(test.length<=1){
		var url =  location.href+'?type=105';
	}else{
		var url =  location.href+'&type=105';
	}	
	
	var myRequest = new Request(
	{
			method: 'post', 
			url: url,
			onSuccess: function(txt) {
			
			}
		}).send('actie='+actie+'');
} 

function addAgentToFavourites(id) {
		
	var test = location.href.split('?');
	var url  = test.length<=1 ? location.href+'?type=107' : location.href+'&type=107';
	
	url = url.replace(/&type=106/, '');
	url = url.replace(/lightbox.html/, '');
	

	var myRequest = new Request({
			method: 'post', 
			url: url,
			onSuccess: function(html) {
									
				parent.location.reload();
				
			}
		}).send('action=addAgentToFavourites&agentId='+id);
	
}

// Executes a function when clicked on an agent in a lightbox (this function gets called from a body onload):

function agentSelection() {
	var arr_agents = $$('div.agent');
	
	if (arr_agents.length == 0) return;
	
	//console.log(arr_agents);
	
	arr_agents.each(function(el_agent) {
		
		var int_agentId = el_agent.id.substring(5).toInt();
		
		el_agent.addEvents({
			'click': function(){ 
				addAgentToFavourites(int_agentId); 
			},
			'mouseenter': function() { 
				el_agent.addClass('mouseover'); 
			},
			'mouseleave': function() { 
				el_agent.removeClass('mouseover'); 
			}
		});		
	});
}