function show_dialog() {
	Effect.Appear('dialog', {duration: 1});
	Effect.Appear('dialoggray', {duration: 1, to: 0.6});
	$('html').style.overflow = 'hidden';
}
function hide_dialog() {
	Effect.Fade('dialog', {duration: 0.8});
	Effect.Fade('dialoggray', {duration: 0.8});
	$('html').style.overflow = 'auto';
} 

function show_dialog_route(route) {
	new Ajax.Updater(
		'dialog_route', 
		'site/route.php',
		{
			method: 'post',
			parameters: 'route='+route,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache'],
			evalScripts: true
		});
	
	Effect.Appear('dialog_route', {duration: 1});
	Effect.Appear('dialoggray', {duration: 1, to: 0.6});
	$('html').style.overflow = 'hidden';
}
function hide_dialog_route() {
	GUnload();
	gmap = -1;
	geocoder = null;
	Effect.Fade('dialog_route', {duration: 0.8});
	Effect.Fade('dialoggray', {duration: 0.8});
	$('html').style.overflow = 'auto';
}

function u(id, page, vars) {
	new Ajax.Updater(
		id, 
		page+'.php',
		{
			method: 'post',
			parameters: vars,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache'],
			evalScripts: true
		});
}

function show_voorstel_page(num){
	var totalPages = 4;
	
	for(var i = 0; i < totalPages+1; i++) {
		if($('pagination'+i)) {
			$('pagination'+i).className = '';
			Element.hide('cright'+i);
			Element.hide('page'+i);
		}
	}
	
	$('pagination'+num).scrollTop = 0; 
	$('pagination'+num).className = 'current';
	Element.show('cright'+num);
	Element.show('page'+num);
}

/* Google maps */
var gmap = -1;
var gdirs;
var geocoder;
var address;

function gmaps_show(_address) {
	address = _address;
	if (gmap == -1) {
		if (!GBrowserIsCompatible()) return;
		gmap = new GMap2(document.getElementById('gmaps'));
		geocoder = new GClientGeocoder();
		gmap.addControl(new GSmallMapControl());
		gmap.addControl(new GMapTypeControl());
		gmap.enableScrollWheelZoom();
		gmap.enableDoubleClickZoom();
		gmap.enableContinuousZoom();
		
		gdirs = new GDirections(gmap, $('directions'));
		GEvent.addListener(gdirs, "error", handleErrors);
		GEvent.addListener(gdirs, "load", hideErrors);
		
		geocoder.getLatLng(
			_address,
			function(point) {
				if (!point) {
					alert(_address + ' not found');
				} else {
					gmap.setCenter(point, 13);
					var marker = new GMarker(point);
					gmap.addOverlay(marker);
				}
			}
		);
	}
}

function tomorrow_gmaps_hide() {
	$('gmaps_container').style.display = 'none';
}

/* plan route */
function calculate_directions(start) {
	gdirs.load("from: "+start+" to: "+address);
}

function gmap_alert(s) {
	$('fouten').innerHTML = 'Er deed zich een probleem voor tijdens het zoeken van een route:<br/><br/>'+s;
	$('fouten').style.display = '';
	$('directions').style.display = 'none';
}

function hideErrors() {
	gmap.setMapType( G_NORMAL_MAP);
	$('fouten').style.display = 'none';
	$('directions').style.display = '';
}

function handleErrors(){
	if (gdirs.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		gmap_alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdirs.getStatus().code);
	else if (gdirs.getStatus().code == G_GEO_SERVER_ERROR)
		gmap_alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdirs.getStatus().code);
	else if (gdirs.getStatus().code == G_GEO_MISSING_QUERY)
		gmap_alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdirs.getStatus().code);
	else if (gdirs.getStatus().code == G_GEO_BAD_KEY)
		gmap_alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdirs.getStatus().code);
	else if (gdirs.getStatus().code == G_GEO_BAD_REQUEST)
		gmap_alert("A directions request could not be successfully parsed.\n Error code: " + gdirs.getStatus().code);
	else
		gmap_alert("An unknown error occurred.");
}

function show_case_page(num, tab)
{
	//var totalPages = 5;
	
	for (i=1;i<=6;i++)
	{
		if ($('pagination_'+tab+"_"+i)) {
			Element.hide('c'+tab+'_'+i);
			$('pagination_'+tab+"_"+i).className = ''; 
			Element.hide('cright'+tab+'_'+i);
		}

	}

	$('pagination_'+tab+"_"+num).className = 'current'; 
	Element.show('cright'+tab+'_'+num);
	Element.show('c'+tab+'_'+num);
}