var onloadFunctions = new Array( );

/* lettergrootehuidig */
var currentSize = 1;

/**
 * Onload functie gaat door onloadFunctions array om die functies uit te voeren.
 */
window.onload = function( )
{
	for(var myIndex = 0; myIndex < onloadFunctions.length; myIndex++ )
	{
		if(onloadFunctions[myIndex])
		{
			onloadFunctions[myIndex]( );
		}
	}
}

/*
 * Functie om een onloadfunctie toe te voegen aan de onloadFunctions array
 */
window.addOnloadFunction = function( func )
{
	onloadFunctions[onloadFunctions.length] = func;
}

function var_dump( theVar, depth, keyName )
{
	var result = "";
      	var tabs = "";
      	
      	if(typeof depth == 'undefined')
      	{
      		var depth = 0;
      	}
      	else
      	{
      		depth++;	
      	}
      	
      	for(var i = 0; i < depth; i++)
      	{
      		tabs += "\t";	
      	}
	
	switch (typeof(theVar))
	{
           case 'object':
			if(keyName)
			{
				result += "\n"+tabs+keyName+" : "+typeof(theVar);
			}
			else
			{
				result += "\n"+tabs+typeof(theVar);	
			}
			result += "\n"+tabs+"{";
			
			for( keyName in theVar )
			{
				result += var_dump( theVar[keyName], depth, keyName );
			}
			
			result += "\n"+tabs+"}";            	
           	break;
           default:
           
           	if(typeof(theVar) == 'string')
           	{
           		var type = " ("+typeof(theVar)+" "+theVar.length+")";
           	}
           	else
           	{
           		var type = "";	
           	}
           
           	if(keyName)	
           	{
           		result += "\n"+tabs+keyName+" : "+theVar+type;
           	}
           	else
           	{
           		result += "\n"+tabs+theVar+type;	
           	}
           	break;	
	}				
	
	return result;
}	       
			
function getPopupLayer()
{
    
    var popup = document.getElementById('popupLayer');
    
    if (!popup) 
    {
        popup = document.createElement('div');
        popup.id = 'popupLayer';
        popup.count = 0;
        document.body.insertBefore(popup,document.body.firstChild);
         
    } 
    
    if (popup.count == undefined) 
    {
        popup.count = 0;
    }
    
    return popup;
}			

function showPopupLayer()
{
	hideShowSelect('none');
	var popup = getPopupLayer();
	var message = popup.innerHTML;
	var message = "<div id='popupLayerClose'><a href='#' onClick='hidePopupLayer()'><img src='/images/melding_close.gif' alt='Sluit melding' /></a></div> <h1> Melding</h1> <br />" + message;
	popup.innerHTML = message;
	popup.style.display = 'block';	
}	

function hidePopupLayer()
{
	hideShowSelect('inline');
	
	//Lees flag uit om te bepalen of de applet wel zichtbnaar mag zijn
	if(showmap24Ligging == true)
	{
		showHideMap24('inline');
	}
	
	var popup = getPopupLayer();
	popup.style.display = 'none';	
}	

function hideShowSelect(waarde)
{
	var selectBoxen = document.getElementsByTagName('select');
	
	for(var i=0; i<selectBoxen.length; i++)
	{
		if(selectBoxen[i].id != "")
		{
			if(!document.getElementById(selectBoxen[i].id).disabled)
			{
				document.getElementById(selectBoxen[i].id).style.display = waarde;
			}
		}
	}
}

function showHideMap24(waarde)
{
	if(document.getElementById('map24div'))
	{
		document.getElementById('map24div').style.display = waarde;
		document.getElementById('map24poi').style.display = waarde;
	}
}

function handleSoapError()
{
	var Elm = document.getElementById("soaperror");
	if(Elm)
	{
		var popup = getPopupLayer();
		popup.innerHTML = Elm.innerHTML;
		showPopupLayer();
	}
}	

function mkPrint()
{
	var printLink = document.getElementsByTagName('a');
	
	for(var i=0; i<printLink.length; i++)
	{
		if(printLink[i].id)
		{
			if(printLink[i].id == 'printPage')
			{
				printLink[i].onclick = function()
				{
					print();
					return(false);
				} 
			}
		}
	}
}
var showmap24Ligging = true;

function changeLettergrootte()
{
	if(currentSize == 1)
	{
		var size = 2;
	}
	else
	{
		var size = 1;
	}

	var remoteLettergrootte = new lettergrootte();
	remoteLettergrootte.setsize(size);
	
	setLettergrootte(size);
}

function setDefaultLettergrootte()
{
	document.getElementById("lettergrootte").onclick = function()
	{
		changeLettergrootte();
	}
	
	var remoteLettergrootte = new lettergrootte();
	remoteLettergrootte.dispatcher.mode = 'sync';
 		
	currentSize = remoteLettergrootte.getsize();

	setLettergrootte(currentSize);
}

function setLettergrootte( size )
{
	for(var i=0; i<document.styleSheets.length; i++)
	{
		//Ander browsers
		if(document.styleSheets[i].media.mediaText != undefined)
		{
			var type = document.styleSheets[i].media.mediaText;
		}
		//IE
		else if(document.styleSheets[i].media != undefined)
		{
			var type = document.styleSheets[i].media;
		}
		else
		{
			var type = 'screen';
		}

		if(type == "screen")
		{
			var arrLoc = document.styleSheets[i].href.split("/");
			
			if(arrLoc[arrLoc.length-2] != size)
			{
				document.styleSheets[i].disabled = true;
			}
			else
			{
				document.styleSheets[i].disabled = false;
			}
		}
	}
	
	currentSize = size;
}

function getMelding( name )
{
	var remoteMelding = new melding();
	remoteMelding.dispatcher.mode = 'sync';
	return remoteMelding.getmelding( name );	
}

HTML_AJAX.Open = function(request) 
{
  	loading = getPopupLayer();
	
	//if(request.methodName == "getmelding")
	//{
		loading.innerHTML = 'Een ogenblik geduld aub<br/><br/><br/><br/><img src="/images/ajax_loading.gif" border="0" alt="Bezig met laden..." />';
//	}
//	else
//	{
//		loading.innerHTML = getMelding("INSCHRIJVENPOSTCODE");
//	}
	showPopupLayer();
	
    loading.count++;
    if (request.isAsync) 
    {
        request.loadingId = window.setTimeout(function() { loading.style.display = 'block'; },500);
    }
    else 
    {
        loading.style.display = 'block';
    }
}

HTML_AJAX.Load = function(request) 
{
    if (request.loadingId) 
    {
        window.clearTimeout(request.loadingId);
    }
    var loading = document.getElementById('popupLayer');
    loading.count--;

    if (loading.count == 0) 
    {
        //loading.style.display = 'none';
        hidePopupLayer();
    }
}

addOnloadFunction(setDefaultLettergrootte);
addOnloadFunction(handleSoapError);
addOnloadFunction(mkPrint);