


function setAfmetingen(width){

    var arAfmetingen = afmetingen();
    var objContentWidth = parseInt(width);

    var x_win = arAfmetingen[0];
    var y_win = arAfmetingen[1];
    var x = arAfmetingen[2];
    var y = arAfmetingen[3];

    var y_content = y_win * 0.9;
    var y_top = y_win * 0.05;
    var x_content = x_win * 0.9;
    var x_left = (x_win - objContentWidth) / 2;

    if(x_left < 0){x_left = 0};

    arNewAfmetingen = new Array(x,x_left,x_win,y,y_content,y_top,y_win);
    return arNewAfmetingen;
}


function afmetingen(){

    var x;
    var y;
    var x_win;
    var y_win;

    if (window.innerHeight && window.scrollMaxY) {
        x = document.body.scrollWidth;
        y = window.innerHeight + window.scrollMaxY;
    }else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        x = document.body.scrollWidth;
        y = document.body.scrollHeight;
    }else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        x = document.body.offsetWidth;
        y = document.body.offsetHeight;
    }

    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        x_win = window.innerWidth;
        y_win = window.innerHeight;
    }else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        x_win = document.documentElement.clientWidth;
        y_win = document.documentElement.clientHeight;
    }else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        x_win = document.body.clientWidth;
        y_win = document.body.clientHeight;
    }

    if(y < y_win){
        y = y_win;
    }

    arAfmetingen = new Array(x_win,y_win,x,y);
    return arAfmetingen;

}

function bs2_popup_instance( uid, param ){
	this.param = param;
	this.uid = uid;

	this.sourceDiv = null;
}

function bs2_popup(){

	window.popup = this;

	this.isObject = true;

	this.open = false;
	this.position = 0;

	this.stack = new Array();

	function show( uid, param, sourceDiv, site ){

		// add new popup and show it

		//start loading
		Ajax.StaticHandler.DoShow( Ajax.GetObject('div_loading_img') );
		if( Ajax.GetObject('popup_iframe') )
			Ajax.StaticHandler.DoShow( Ajax.GetObject('popup_iframe') );


		// arrange the popup-stack
		var currentPopup = new bs2_popup_instance( uid, param );
		if( sourceDiv )
			currentPopup.sourceDiv = Ajax.GetObject( sourceDiv );

		this.stack.splice( this.position + 1 );
		this.position = this.stack.push( currentPopup ) - 1;


		// div pop-up aanroepen, dmv doShow( pop-up)
		var victim = document.getElementById('popup');
		var victim2 = document.getElementById('popup_inhoud');
		//var victim3 = document.getElementById('popup_close');

		if( this.open == false ){
			victim.innerHTML = '&nbsp;';
			victim2.innerHTML = '&nbsp;';
		}

		this.open = true;

		/* functie frank */

		var arAfmetingen =	setAfmetingen(600);

		victim.style.width = arAfmetingen[0] + "px";
	    victim.style.height = arAfmetingen[3] + "px";
	    //victim.style.top = arAfmetingen[5] + "px";
	    //victim.style.left = arAfmetingen[1] + "px";

		Ajax.StaticHandler.DoShow( victim);
		Ajax.StaticHandler.DoShow( victim2);
		//Ajax.StaticHandler.DoShow( victim3);

		// posten


		this.getContent( currentPopup, site );

	}

	function getContent( popup, site ){

		//document.currentanchor = window.location.hash
		window.location.hash = "#";

		if( popup.sourceDiv ){
			Ajax.GetObject('popup_inhoud').innerHTML = popup.sourceDiv.innerHTML;
			window.popup.shown();
			return;
		}

		var Request = Ajax.GetAjaxRequest();
		Request.Prio = 1;
		Request.AddPostValue( 'show_popup', 'afzender' );
	    Request.AddPostValue( popup.uid, 'popup_id' );
	    Request.AddPostValue( popup.param, 'popup_param' );
		Request.AddPostValue( 'ajax_show_popup', 'functie' );
		Request.AddPostValue( site, 'site' );
		Request.SuccessHandler.HTMLTo( 'popup_inhoud' );
		Request.SuccessHandler.Call( window.popup.shown );
		Request.SuccessHandler.JSEvalTags( null );
		Request.Send();

	}


	function shown(){

		Ajax.StaticHandler.DoHide( Ajax.GetObject('div_loading_img') );
		window.popup.refreshButtons();

	}

	function hide(){

		Ajax.StaticHandler.DoHide( Ajax.GetObject( 'popup' ) );
		Ajax.StaticHandler.DoHide( Ajax.GetObject( 'popup_inhoud' ) );
		if( Ajax.GetObject('popup_iframe') )
			Ajax.StaticHandler.DoHide( Ajax.GetObject('popup_iframe') );
		//Ajax.StaticHandler.DoHide( Ajax.GetObject( 'popup_close' ) );

		this.open = false;

	}


	function escape( e ){


		if( !window.popup.open )
			return;

		if( !e )
			e = Event;

		if( e.which == 27 )
			window.popup.hide();

	}

	function previous(){

		if( this.position <= 0 )
			return;

		Ajax.StaticHandler.DoShow( Ajax.GetObject('div_loading_img') );

		this.position--;
		this.getContent( this.stack[this.position] );

	}

	function next(){

		if( this.position >= this.stack.length - 1 )
			return;

		Ajax.StaticHandler.DoShow( Ajax.GetObject('div_loading_img') );

		this.position++;
		this.getContent( this.stack[this.position] );

	}

	function refreshButtons(){

		var previous = Ajax.GetObject( 'popup_previous' );
		var next = Ajax.GetObject( 'popup_next' );


		if( this.position > 0 )
			previous.src = '/images/bestel/previous.gif';
			//Ajax.StaticHandler.DoEnable( previous );
		else
			previous.src = '/images/bestel/previous_disabled.gif';
			//Ajax.StaticHandler.DoDisable( previous );

		if( this.position < this.stack.length - 1 )
			next.src = '/images/bestel/next.gif';
			//Ajax.StaticHandler.DoEnable( next );
		else
			next.src = '/images/bestel/next_disabled.gif';
			//Ajax.StaticHandler.DoDisable( next );

	}

	this.previous = previous;
	this.next = next;

	this.show = show;
	this.shown = shown;
	this.hide = hide;
	this.escape = escape;
	this.getContent = getContent;
	this.refreshButtons = refreshButtons;


	Ajax.implementEvent( window, 'keydown', window.popup.escape );

	/*
	if( window.addEventListener ){
		window.addEventListener( 'keydown', window.popup.escape, true );
	}else{
		window.attachEvent( 'onkeydown', window.popup.escape );
	}
	*/

}




function show_bs2_popup( popup_id, param, sourceDiv ){



	if( !window.popup || !window.popup.isObject ){ // hack, maar IE heeft anders de DIV als window.popup
		window.popup = new bs2_popup();

	}


	window.popup.show( popup_id, param, sourceDiv, 'BS' );

}

function show_as_popup( popup_id, param, sourceDiv ){

	if( !window.popup || !window.popup.isObject ){ // hack, maar IE heeft anders de DIV als window.popup
		window.popup = new bs2_popup();

	}

	window.popup.show( popup_id, param, sourceDiv, 'AS' );

}

function popupEscape( e ){


	if( !window.popup.open )
		return;

	if( !e )
		e = Event;

	if( e.which == 27 )
		window.popup.hide();

}






function show_cs_popup( functie ){

	window.location.hash = "#";

	// div pop-up aanroepen, dmv doShow( pop-up)
	var popup = document.getElementById('popup');
	var victim2 = document.getElementById('popup_inhoud');
	//var victim3 = document.getElementById('popup_close');


	var arAfmetingen =	setAfmetingen(600);

	popup.style.width = arAfmetingen[0] + "px";
    popup.style.height = arAfmetingen[3] + "px";
    //victim.style.top = arAfmetingen[5] + "px";
    //victim.style.left = arAfmetingen[1] + "px";





	Ajax.StaticHandler.DoShow( popup);
	Ajax.StaticHandler.DoShow( victim2);

	if( Ajax.GetObject('popup_iframe') )
		Ajax.StaticHandler.DoShow( Ajax.GetObject('popup_iframe') );
	//Ajax.StaticHandler.DoShow( victim3);


	// content ophalen

	var Request = Ajax.GetAjaxRequest();

	Request.AddPostValue( 'show_popup', 'afzender' );
	Request.AddPostValue( 'content', 'get' );
	Request.AddPostValue( '1', 'ajax' );
	Request.AddPostValue( '1', 'popup' );
	Request.AddPostValue( 'nieuw_faq', 'hide_faq' );
	Request.AddPostValue( functie, 'functie' );
	Request.AddPostValue( functie, 'popup_id' );

	Request.SuccessHandler.HTMLTo( 'popup_inhoud' );
	Request.SuccessHandler.JSEvalTags( null );

	Request.Send();


}

function hide_popup(){


	if( window.popup && window.popup.isObject ){
		window.popup.hide();
		return;
	}


	Ajax.StaticHandler.DoHide( Ajax.GetObject( 'popup' ) );
	Ajax.StaticHandler.DoHide( Ajax.GetObject( 'popup_inhoud' ) );

	if( Ajax.GetObject('popup_iframe') )
		Ajax.StaticHandler.DoHide( Ajax.GetObject('popup_iframe') );
	//Ajax.StaticHandler.DoHide( Ajax.GetObject( 'popup_close' ) );

	window.popup_open = false;

	/*
	var Request = Ajax.GetAjaxRequest();
	Request.AddPostValue( 'hide_popup', 'afzender' );

	var victim = document.getElementById('popup');
	var victim2 = document.getElementById('popup_inhoud');
	var victim3 = document.getElementById('popup_close');
	//var victim3 = document.getElementById('popup_');

	Request.SuccessHandler.DoHide( victim);
	Request.SuccessHandler.DoHide( victim2);
	Request.SuccessHandler.DoHide( victim3);

	//Request.Send();
	*/

}

function adjust_infotag_size( div, arMouse, debug, min, max ){


	var marginFromCursor = 20;

	if(debug == true){
		//alert("min = "+min+", max = "+max);
	}

	if(min && min != 0){
		var minWidth = min;
	}else{
		var minWidth = 150;
	}

	if(max && max != 0){
		var maxWidth = max;
	}else{
		var maxWidth = 200;
	}

	/*

	DEZE CODE IS NIET BROWSER PROOF

	var rightSpace = window.innerWidth - arMouse[0] - marginFromCursor;
	var leftSpace = arMouse[0] - marginFromCursor;
	var bottomSpace = window.innerHeight - arMouse[1] - marginFromCursor;
	var topSpace = arMouse[1] - marginFromCursor;
	*/

	// DEZE WEL...

	if( window.innerWidth!=undefined ){

		var rightSpace = window.innerWidth - arMouse[0] - marginFromCursor;
		var leftSpace = arMouse[0] - marginFromCursor;
		var bottomSpace = window.innerHeight - arMouse[1] - marginFromCursor;
		var topSpace = arMouse[1] - marginFromCursor;

	}else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {

        var rightSpace = document.documentElement.clientWidth - arMouse[0] - marginFromCursor;
		var leftSpace = arMouse[0] - marginFromCursor;
		var bottomSpace = document.documentElement.clientHeight - arMouse[1] - marginFromCursor;
		var topSpace = arMouse[1] - marginFromCursor;

    }else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {

        var rightSpace = document.body.clientWidth - arMouse[0] - marginFromCursor;
		var leftSpace = arMouse[0] - marginFromCursor;
		var bottomSpace = document.body.clientHeight - arMouse[1] - marginFromCursor;
		var topSpace = arMouse[1] - marginFromCursor;

    }



	// div.clientHeight;
	// div.clientWidth
	// window.innerWidth
	// window.outerHeight

	// richting bepalen
	if( rightSpace >= minWidth ){
		// rechts uitlijnen
		div.style.left = (arMouse[0] + marginFromCursor)+"px";
		div.style.width = ( rightSpace > maxWidth ? maxWidth : rightSpace ) + "px";
	}else if( leftSpace >= minWidth ){
		// naar links
		var divWidth = ( leftSpace > maxWidth ? maxWidth : leftSpace );
		div.style.width = divWidth + "px";
		div.style.left = ( arMouse[0] - divWidth - marginFromCursor)+"px";
	}else{
		// pas niet
		div.style.left = 0 + "px";
		div.style.width = maxWidth + "px";

	}


	if( bottomSpace >= div.clientHeight ){
		// past eronder
		div.style.top = (arMouse[1] + marginFromCursor)+"px";
	}else if( topSpace >= div.clientHeight ){
		// past erboven
		div.style.top = (arMouse[1] - marginFromCursor - div.clientHeight )+"px";
	}else{
		// past nergens
		div.style.top = 0+"px";
	}

	/*if(debug == true){
		// 2010-05-10 George. In de CS wordt de info-popup links onderin weergegeven, dat lijk er op dat het relative wordt gepositioneerd. (is niet zo gedefineerd, maar wordt misschien geerfd ergens vandaan)
		div.style.position = 'absolute';
	}*/

}

function add_infotag_to( element, html, debug, min, max ){

	if(debug){
		//alert('kass');
		//return;
	}


	element = Ajax.GetObject( element );

	element.onmouseover = function( e ){



		if (!e) var e = window.event;

		var arMouse = getMousePos( e );


		if( Ajax.GetObject( element.id + '_infotag' ) ){

			//div.style.top = (arMouse[1]+20)+"px";
			//div.style.left = (arMouse[0]+10)+"px";
			adjust_infotag_size( div, arMouse );
			return;
		}

		//alert( arMouse[0] + ":" + arMouse[1] );

		if( Ajax.GetObject( element.id + '_infotag' ) )
			return;

		var div = document.createElement( 'DIV' );
		div.className = "infotag";
		div.id = element.id + '_infotag';

		//div.style.top = (arMouse[1]+20) + "px";
		//div.style.left = (arMouse[0]+10) + "px";

		div.innerHTML = html;
		document.body.appendChild( div );

		adjust_infotag_size( div, arMouse, debug, min, max );


	}
	element.onmouseout = function (e ){


		if (!e) var e = window.event;

		if( Ajax.GetObject( element.id + '_infotag' ) ){
			var div = Ajax.GetObject( element.id + '_infotag' );
			var parent = div.parentNode;
			parent.removeChild( div );
		}


	}



}


function getMousePos( e ){

	var posx = 0;
	var posy = 0;

	if (!e) var e = window.event;

	if (e.pageX || e.pageY){

		posx = e.pageX;
		posy = e.pageY;

	}else if (e.clientX || e.clientY){

		posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;

	}

	ar_mouse = new Array(posx,posy);
	return ar_mouse;
}
