var tmp_css;
var myErrors = "";
window.onerror = function(e, f, l) {
	
	// store errors in array - for debugging
	myErrors += "\n" + '[' + f + ' ('+ l +')] ' + e;
	// but do not report them to the browserss debugger
	return true; 
}

String.prototype.substitute = function(was, becomes) {
  return this.split(was).join(becomes);
}

function getQueryString(key) {
}

function getFlashMovieObject(movieName) {
	if (window.document[movieName]) {
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1) {
		if (document.embeds && document.embeds[movieName])
			return document.embeds[movieName]; 
	} else {
		// (usually: if (navigator.appName.indexOf("Microsoft Internet")!=-1)
		return document.getElementById(movieName);
	}
}

var __pp = {
	
	showTabs: 		1,
	myUrl:			'https://mijn.residentie.net/portalplugin/',
	contentDiv:		'body',
	tabAlias: 		'residentienet',
	portal: 		undefined,

	/*
	pim_url: 		'http://office.webclusive.com/pim',
	loket_url:		'http://office.webclusive.com/loket',
	pim_base_url: 	'http://office.webclusive.com/',
	*/
	
	pim_url: 		'http://mijn.residentie.net/pim',
	loket_url:		'http://mijn.residentie.net/loket',
	pim_base_url: 	'http://mijn.residentie.net/',
	
	Credentials:	{},
	gateway:		undefined,
	managment:		Boolean,
	display_portal:	Boolean,
	tmp:			{},
	userInfo:		false,
	serviceList:	{},
	display_name:	"",
	pp_action_done: false,
	loadingImage: 	'',
	_debug_msgs: 	new Array(),
	
	portals: { 	sport: 				'Sport',
				politiek:			'Politiek',
				onderwijs:			'Onderwijs',
				huwelijk:			'Huwelijk',
				ondernemer:			'Ondernemers',
				omroep:				'Omroep',
				gezondheidwelzijn:	'Gezondheid en Welzijn',
				residentienet:		'Algemene',
				wmoportaal:			'Wet Maatschappelijke Ondersteuning', 
				cultuur:			'Cultuur' },

	debug: function(msg) {
		this._debug_msgs.push(msg);
	},

	_action_result: function() {},
	_qsv: function(key) {
        //returns value of key
        var valueStr;
        var searchStr;
        key=(key+"=");
        var fullQString=window.location.search.substring(1);
        var fullQLengthInt=fullQString.length;
        var keyLengthInt=key.length;
        var keyPosInt=fullQString.indexOf(key);
        if(!(keyPosInt==-1))
        {
                var startLengthInt=(keyPosInt+keyLengthInt);
                searchStr=fullQString.substring(startLengthInt);
                andPosInt=searchStr.indexOf("&");
                if(andPosInt==-1)
                {
                        valueStr=searchStr;
                }else{
                        valueStr=searchStr.substring(0, (andPosInt));
                }
        }else{
                valueStr = 'not set';
        }
        return(valueStr);

	},
	
	_addScript: function(href) {
	
		var newScript 	= document.createElement('script');
		newScript.type 	= "text/javascript";
		newScript.src 	= href;		
		document.getElementsByTagName("head")[0].appendChild(newScript);
	
	},
	
	_addCSS: function(href) {
	
		if (document.createStyleSheet) {
		
			
			return document.createStyleSheet(href);
		
		} else {

			var styles = "@import url(' "+href+" ');";	
			var newSS=document.createElement('link');	
			newSS.rel='stylesheet';	
			newSS.href='data:text/css,'+escape(styles);
			//alert(newSS.href);
			return document.getElementsByTagName("head")[0].appendChild(newSS);
		}
	
	},

	_html: function(c, root, doc, responseText, source_url) {
		//alert(responseText);
		
		responseText = responseText.split("\n").join(" ");		
			
		responseText = responseText.replace(/<h3>\s*Plaatje bijwerken.*?<\/form>/i, '');
		
		var body = responseText.match(/<body[^>]*>(.*)<\/body>/);

		$(this.contentDiv).innerHTML = '<div id="pp_content">' + body[1] + '</div>';

		var forms = $(this.contentDiv).getElementsByTagName('form');

		for(i = 0; i<forms.length; i++) {
			forms[i].onsubmit = function() {
				
				// get the currect url from /somewhere/ - probably store it somewhere
				// in the request and then retrieve. But remember: you can have multiple
				// requests pending!!
				__pp.call(source_url, Form.serialize(this), true);
				return false;

			}
		}
		
		var aTags = $(this.contentDiv).getElementsByTagName('a');
		
		for( var i = 0; i<aTags.length; i++) {
//			alert(aTags[i].href);
		}
	},

	_ChangeDetails: function(c) {

		var children 	= c.toHash();
		var toReplace 	= $('pp_change_form');
		var newNode		= document.createElement('DIV');
		
		var msg = '';
		if (children.ok == 0) {

			var msg = '';

			for(var i = 0; i< c.length;i++) {
				if (c[i].childNodes[0].tagName == 'error') {
					for(var e = 0; e < c[i].childNodes.length; e++) {
						msg += c[i].childNodes[e].firstChild.nodeValue + "<br />";
					}
				}
			}

			$('pp_area_messages').innerHTML = msg;

		} else {

			$('pp_area_messages').innerHTML = 'Uw gegevens zijn bijgewerkt<br />';

		}

		$('pp_a_change_sub_title').innerHTML = '';
		$('pp_change_form').b_submit.disabled 	= false;
		$('pp_change_form').b_submit.className	= 'pp_inp_submit';

	},

	_SetPassword: function(c) {

		var children 	= c.toHash();
		var toReplace 	= $('pp_set_pass_form');
		var newNode		= document.createElement('DIV');
		
		var msg = '';
		if (children.ok == 0) {

			var msg = '';

			for(var i = 0; i< c.length;i++) {
				if (c[i].childNodes[0].tagName == 'error') {
					for(var e = 0; e < c[i].childNodes.length; e++) {
						msg += c[i].childNodes[e].firstChild.nodeValue + "<br />";
					}
				}
			}

			$('pp_area_messages').innerHTML = msg;
			$('pp_set_pass_form').b_submit.disabled 	= false;
			$('pp_set_pass_form').b_submit.className	= 'pp_inp_submit';

		} else {

			// update HTML
			$('pp_a_set_pass').innerHTML 			= 'Wachtwoord bijgewerkt.';
			$('pp_a_set_pass_subtitle').innerHTML 	= '&nbsp;';
			
			var html = '<p>Uw wachtwoord is bijgewerkt.</p>';

			newNode.innerHTML = html;
			toReplace.parentNode.replaceChild(newNode, toReplace);
		}
	},
	_SendActivationCode: function(c) {
		var children 	= c.toHash();
		var toReplace 	= $('pp_forgot_pass_form');
		var newNode		= document.createElement('DIV');
		
		var msg = '';
		if (children.ok == 0) {

			var msg = '';

			for(var i = 0; i< c.length;i++) {
				if (c[i].childNodes[0].tagName == 'error') {
					for(var e = 0; e < c[i].childNodes.length; e++) {
						msg += c[i].childNodes[e].firstChild.nodeValue + "<br />";
					}
				}
			}

			$('pp_area_messages').innerHTML = msg;
			$('pp_forgot_pass_form').b_submit.disabled 	= false;
			$('pp_forgot_pass_form').b_submit.className	= 'pp_inp_submit';

		} else {

			// update HTML
			$('pp_a_forgot_pass').innerHTML 			= 'Wachtwoord vergeten';
			$('pp_a_forgot_pass_subtitle').innerHTML 	= 'stap 2 van 3';
			
			var html = '<p>Er is een e-mail verzonden naar uw email adres met verdere instructies.</p>';

			newNode.innerHTML = html;
			toReplace.parentNode.replaceChild(newNode, toReplace);
		}
		
	},
	_CreateUser: function(c) {

		var children = c.toHash();

		if (children.ok == 0) {

			var msg = '';

			for(var i = 0; i< c.length;i++) {
				if (c[i].childNodes[0].tagName == 'error') {
					for(var e = 0; e < c[i].childNodes.length; e++) {
						msg += c[i].childNodes[e].firstChild.nodeValue + "<br />";
					}
				}
			}

			$('pp_a_reg_sub_title').innerHTML 	= 'stap 1 van 3';
			$('pp_area_messages').innerHTML 	= msg;
			$('pp_reg_form').b_submit.disabled 	= false;
			$('pp_reg_form').b_submit.className	= 'pp_inp_submit';

		} else {

			// update HTML
			$('pp_a_reg_title').innerHTML 		= 'Registratie geslaagd! Welkom ' + this.tmp.RegCache.firstname;
			$('pp_a_reg_sub_title').innerHTML 	= 'stap 2 van 3';
			
			var toReplace 	= $('pp_reg_form');
			var newNode		= document.createElement('DIV');
			
			var html = '<p style="margin-top: 0px">Er is een bevestigings e-mail verzonden naar het door u opgegeven email adres. Leest u deze ';
			html += 'e-mail en volg de instructies nauwkeurig op zodat u uw account officieel kan activeren.</p>';

			html += '<p>Nadat uw account is geactiveerd kunt u zich inschrijven voor faciliteiten van de diverse portalen</p>';

			html += '<p class="pp_light"><a onclick="window.print();" href="#">Wij raden u aan deze pagina te printen zodat u de gegevens niet kunt vergeten</a></p>';
			html += '<table class="pp_light">';
			html += '<tr><th>Uw gebruikersnaam</th><td>' + this.tmp.RegCache.username + '</td></tr>';
			html += '<tr><th>Uw e-mailadres</th><td>' + this.tmp.RegCache.email + '</td></tr>';
			html += '</table>';

			//html += '<p>Wanneer u uw wachtwoord vergeet kunt u deze opvragen met de optie "wachtwoord vergeten".</p>';

			newNode.innerHTML = html;
			toReplace.parentNode.replaceChild(newNode, toReplace);

			this.tmp.RegCache = {};
		}
	},

	_something: function(c) {
		alert($H(c).inspect());
	},
	_result: function(c) {
		alert($H(c).inspect());
	},
	_logoutResult: function(c) {
		/*var html = '';
			html += '<a href="#" class="pp_menu_option" return false onclick="__pp.cnt_WhatIsIt();">Wat is het?</a><br />';
			html += '<a href="#" class="pp_menu_option" return false onclick="__pp.cnt_TheServices();">De diensten!</a><br />';
			html += '<a href="#" class="pp_menu_option" return false onclick="__pp.cnt_Register();">Registreer uzelf!</a><br /><br />';
			html += this._getLoginFormHTML();*/

		var html = '';
		html += '<div class="pp_area" id="pp_feedback_form_area">';
		html += '<div class="pp_area_title"><span id="pp_a_feedback_title">Uitgelogd</span></div>';
		html += '<div class="pp_area_sub_title"><span id="pp_a_feedback_sub_title">&nbsp;</span></div>';
		html += '<div class="pp_area_content">';
		html += '<div id="pp_area_messages"></div>';

		html += '<p>U bent uitgelogd uit Mijn Residentie.Net</p>';

		html += '</div>';
		html += '</div>';
		
		$(this.contentDiv).innerHTML = html;
	},
	_Subscribe: function(c) {
		this.setMessage("Succesvol ingeschreven");
		//if (confirm('U bent nog niet aangemeld voor dit tabblad, wilt u dat nu doen?'))
		this.call_loket({});
	},
	_loketResult: function(c, root, doc, content, source_url) {

		for(var i = 0; i<c.length;i++) {
			if (c[i].tagName == 'dal:user') {

				var uInfo = c[i].attributes.toHash();

				if (uInfo['dal:display_name']) {
					this.display_name = uInfo['dal:display_name'];
				};

			} else {
				//try {
					var method = '_'+c[i].tagName;
					method = method.substitute('-', '_');
					this[method](c[i].childNodes, c[i], doc, content, source_url);
				//} catch (e) { alert(e + ": " + method); };
			}
		};

	},
	_portals: function(c) {

		var name = c[0].firstChild.firstChild.firstChild.childNodes[0].firstChild['data'];

		var html = '<span class="pp_text">Welkom, <span class="pp_username">' + this.display_name + '</span></span><br/>';

		html += '<form method="post" style="margin:0;padding:0;" onsubmit="__pp.showServices(); return false;">';
		html += '<li><a href="#" onclick="__pp.showServices();">mijn.residentie.net</a></li>';
		html += '<input type="hidden" value="1" name="b_submit"/>';
		html += '</form>';
		html += "<li><span id='pp_loginstatus'><a href='' onclick='__pp.logout(); return false;' id='pp_logout'>Uitloggen</a></span></li>";
		
		$('pp_print').innerHTML = html;
		
		// starting at the second node; first nodes are title and link
		var str 	= "";
		var myAlias	= null;

		for (i=0;i<c[0].firstChild.firstChild.firstChild.childNodes.length;i++) {

			// shortcut
			var myRoot 		 = c[0].firstChild.firstChild.firstChild.childNodes[i];

			if (myRoot.tagName == "alias") {

				myAlias = myRoot.firstChild.nodeValue;
				this.serviceList[myAlias] = {};

			} else if (myRoot.tagName == "item") {

				var desc = null;
				var short_desc;
				var show_in_pp = false;
				try {
					var desc 		= myRoot.childNodes[2].firstChild['data'];
					var short_desc 	= myRoot.childNodes[3].firstChild['data'];
					var show_in_pp	= myRoot.childNodes[4].firstChild['data'] == 'true' ? true : false;
				} catch (e) {};

				if (show_in_pp) {
					if (desc == 'null' || desc == '') 				desc = '';
					if (short_desc == 'null' || short_desc == '') 	short_desc = 'Geen beschrijving opgegeven';

					var infoObj = {
						url: 			myRoot.childNodes[0].firstChild['data'],
						title: 			myRoot.childNodes[1].firstChild['data'],
						subscription:	myRoot.attributes['subscription'].firstChild['data'],
						favorite:		myRoot.attributes['favorite'].firstChild['data'],
						subscribe_to:	(myRoot.attributes['subscribe_to'] == undefined) 
											? "" 
											: myRoot.attributes['subscribe_to'].firstChild['data'],
						description:	desc,
						short_description:	short_desc,
						myRoot:			myRoot
					}

					var sid = (infoObj.subscription != false && infoObj.subscription != 'false')
									? infoObj.subscription
									: infoObj.subscribe_to;

					this.serviceList[myAlias][sid + ""] = infoObj;
				};
			};
		}

		var showServiceList = false;
		var content		 	= {};

		if (!this.pp_action_done && this._qsv('pp_action') == 'activated') {
			this.pp_action_done = true;
			showServiceList = true;

			content.title 		= 'Meld je aan voor verschillende faciliteiten';
			content.sub_title 	= 'stap 3 van 3';
			content.finish		= 'Afronden';
			content.foot		= 'Door een faciliteit aan te vinken kunt u zich aanmelden voor de desbetreffende faciliteit van een portaal. ';
			content.foot		+= 'Kies boven de lijst voor de faciliteiten uit andere portalen';

		} else if (!this.pp_action_done && this._qsv('pp_action') == 'setpass') {

			this.pp_action_done = true;

			this.cnt_SetPassword();

		} else if (this.tmp.showService != undefined && this.tmp.showService) {

			showServiceList = true;

			if (this.tmp.showService == 'unsubscribe') {

				content.title 		= 'Afmelden voor&nbsp;' + this.tabAlias + '&nbsp;portaal&nbsp;faciliteiten';
				content.sub_title 	= '&nbsp;';
				content.foot		= 'Meld je af voor faciliteiten door op de vinkjes te klikken';

			} else {

				//content.title 		= 'Alle diensten';
				content.title 		= 'Faciliteiten&nbsp;portaal&nbsp;' + this.tabAlias ;
				content.sub_title 	= '&nbsp; ';

				content.foot		= 'Door een faciliteit aan te vinken kunt u zich aanmelden voor de desbetreffende faciliteit van een portaal. ';
				content.foot		+= 'Kies boven de lijst voor de faciliteit uit andere portalen';
			}

		};
		if (showServiceList) {

			var html = '';

			if (this.tmp.showService == 'my_rnet') {
				
				html += '<div class="pp_myrnet_header">';
				html += '<div id="pp_myrnet_welcome">Welkom ' + this.display_name + '!</div>';
				//html += '<div id="pp_myrnet_todata"><a onclick="__pp.cnt_EditProfile()" href="#">mijn gegevens</a></div>';
				html += '</div>';
				
				/** The news stuff */

				// disable showing news for now
				if (false) {
					// this should probably come from somewhere, .. 
					var articles = [
						{ img: 		this.myUrl + '/img/sport.jpg',
						  content: 	'Alles over de kwali- ficatie beachsoccer op het sportportaal.',
						  link:		'http://sport.residentie.net/',
						  color: 	'F79D10'
						  },
						{ img: 		this.myUrl + '/img/health.jpg',
						  content: 	'Gezondheid en Welzijn',
						  link:		'http://www.gezondheidenwelzijndenhaag.nl/',
						  color: 	'03c3c4'
						  },
						{ img: 		this.myUrl + '/img/school.jpg',
						  content: 	'Een tal van nieuwe faciliteiten binnen het onderwijs portaal.',
						  link:		'http://onderwijs.residentie.net/',
						  color: 	'E9609B'
						  },
						{ img: 		this.myUrl + '/img/ondernemers.jpg',
						  content: 	'Ondernemers',
						  link:		'http://ondernemers.residentie.net/',
						  color: 	'018c85'
						  },
						{ img: 		this.myUrl + '/img/politiek.jpg',
						  content: 	'Politiek',
						  link:		'http://politiek.residentie.net/',
						  color: 	'0033bb'
						  },
						{ img: 		this.myUrl + '/img/wedding.jpg',
						  content: 	'Binnenkort trouwen? Ga snel naar het huwelijksportaal.',
						  link:		'http://huwelijk.residentie.net/',
						  color: 	'F7103B'
						  },
						{ img: 		this.myUrl + '/img/omroep.jpg',
						  content: 	'Omroep',
						  link:		'http://omroep.residentie.net/',
						  color: 	'b08332'
						  }
					];

					html += '<div class="pp_area" id="pp_news_area">';
					html += '<div class="pp_area_title"><span id="pp_a_news_title">Nieuws!</span></div>';
					html += '<div class="pp_area_sub_title"><span id="pp_a_news_sub_title">&nbsp;</span></div>';
					html += '<div class="pp_area_content">';

					var takenArticles = {};

					for(var j = 0; j < 3; j++) {

						var i = Math.floor(Math.random()*articles.length);
						while(takenArticles[i] != undefined) {
							i = Math.floor(Math.random()*articles.length);
						}
						takenArticles[i] = i;

						var link = articles[i].link;

						html += '<div class="pp_article">';
						html += '<div class="pp_article_img"><a href="'+link+'"><img src="'+articles[i].img+'" alt="" /></a></div>';
						html += '<div style="background-color: #'+articles[i].color+'" class="pp_article_content"><a href="'+link+'">'+articles[i].content+'</a></div>';
						html += '</div>';

					}

					html += '</div>';
					html += '</div>';
					html += '<br />';

				}
				/* ---- */
			};

			html += '<div class="pp_area" id="pp_serv_area">';
			html += '<div class="pp_area_title"><span id="pp_a_serv_title">' + content.title + '</span></div>';
			html += '<div class="pp_area_sub_title"><span id="pp_a_serv_sub_title">' + content.sub_title + '<span></div>';
			
			/*this.showTabs = 1;*/
			
			if (this.showTabs) {
				html += '<div id="pp_manage_services" class="pp_services">';

				// tabs worden neergezet, .. doe hier dus iets mee. Bijvoorbeeld niet tonen, ofzo
				for (var pa in this.portals) {
					var style = pa == this.tabAlias ? 'color: black; background-color: white' : '';
					html += '<div style="'+style+'" class="pp_service" id="pp_service_' + pa + '"><span onclick="__pp.changeActivePortal(this, \''+pa+'\')">' 
					html += this.portals[pa] + '</span></div>';
				}
				html += '</div>';
				html += '<br style="clear: both" />';
			};

			html += '<div class="pp_area_content">';
			html += '<div id="pp_area_messages"></div>';
			var thisAlias = this.tabAlias;

			var foundService = false;
			for(var s in this.serviceList[thisAlias]) {
				foundService = true;
				
				var info = this.serviceList[thisAlias][s];
				var sid = (info.subscription != false && info.subscription != 'false')
								? info.subscription
								: info.subscribe_to;

				var act = this.pim_base_url + "loket/" + thisAlias + "/portal_plugin";

				html += '<div class="pp_service_entry">';

				if (this.tmp.showService == 'my_rnet') {

					if (info.favorite == "true") {
						// html += '<img src="/img/check_on.jpg" width="26" height="13" alt="[x]" />';
						html += '<span class="pp_on_container"><img src="'+this.myUrl+'/img/check_on_trans.gif" width="26" height="13" alt="[x]" /></span>';
					} else {

						html += '<form style="display: inline" onsubmit="return __pp.setServiceLoading(\'' + act + '\', ' + sid + ', this)">';
						html += '<input type="hidden" value="'+ info.subscription +'" name="subscription" />';
						html += '<input type="hidden" value="'+ info.subscribe_to +'" name="subscribe_to" />';
						html += '<input type="hidden" value="make_fav" name="action" />';
						html += '<input style="width: 26px; height: 13px" class="pp_submit_on" src="'+this.myUrl+'/img/check_off.jpg" type="image" value="Aan" name="do_submit" />';
						html += '</form>';
					}

				} else if (this.tmp.showService == 'unsubscribe') {

					if (info.favorite == "false") {
						html += '<img src="'+this.myUrl+'/img/shim.gif" width="26" height="13" alt="[x]" />';
					} else {

						html += '<form style="display: inline" onsubmit="return __pp.setServiceLoading(\'' + act + '\', ' + sid + ', this)">';
						html += '<input type="hidden" value="'+ info.subscription +'" name="subscription" />';
						html += '<input type="hidden" value="'+ info.subscribe_to +'" name="subscribe_to" />';
						html += '<input type="hidden" value="unmake_fav" name="action" />';
						//html += '<input style="width: 26px; height: 13px" class="pp_submit_on" src="/img/check_on.jpg" type="image" value="Aan" name="do_submit" />';
						html += '<span class="pp_on_container"><input style="width: 26px; height: 13px" class="pp_submit_on" src="'+this.myUrl+'/img/check_on_trans.gif" type="image" value="Aan" name="do_submit" /></span>';
						html += '</form>';
					}
				} else {

					html += '<form style="display: inline" onsubmit="return __pp.setServiceLoading(\'' + act + '\', ' + sid + ', this, false)">';
					html += '<input type="hidden" value="'+ info.subscription +'" name="subscription" />';
					html += '<input type="hidden" value="'+ info.subscribe_to +'" name="subscribe_to" />';
					if (info.favorite == "true") {
						html += '<input type="hidden" value="unmake_fav" name="action" />';
						//html += '<input style="width: 26px; height: 13px" class="pp_submit_off" src="/img/check_on.jpg" type="image" value="Uit" name="do_submit" />';
						html += '<span class="pp_on_container"><input style="width: 26px; height: 13px" class="pp_submit_on" src="'+this.myUrl+'/img/check_on_trans.gif" type="image" value="Uit" name="do_submit" /></span>';
					} else {
						html += '<input type="hidden" value="make_fav" name="action" />';
						html += '<input style="width: 26px; height: 13px" class="pp_submit_off" src="'+this.myUrl+'/img/check_off.jpg" type="image" value="Aan" name="do_submit" />';
					};
					html += '</form>';
				}

				
				
				//wanneer 'info.title' gelijk is aan iets van nieuwsbrief dan dient geen link te worden weergegeven.
						
				var str = info.title;
				var reg = /nieuwsbrief/i;
				if (reg.test(str)){ 
					html += '<span class="pp_service_link" id="pp_s_title_' + sid + '" target="_blank">' + info.title.toUpperCase() + '</span>';
					
					if (info.short_description) {
						html += ' - <span class="pp_service_link">' +  info.short_description +'</span>';
					};
				}else { 
					html += '<a href="'+ info.url +'" class="pp_service_link" id="pp_s_title_' + sid + '" target="_blank">'+ info.title +'</a>';
				
					if (info.short_description) {
						/*
						html += ' - <span class="pp_service_description">' + '<a onclick="return !__pp.showServiceDetails('+sid+', \''+thisAlias+'\');" href="'+ info.url +'" class="pp_service_link" id="pp_s_title_' + sid + '" target="_blank">'+ info.short_description +'</a></span>';
						*/
						html += ' - <span class="pp_service_description">' + '<a href="'+ info.url +'" class="pp_service_link" id="pp_s_title_' + sid + '" target="_blank">'+ info.short_description +'</a></span>';
					};
				}
				
  				/*
  				
				//oude mannier om de links weer te geven 
  				
				html += '<a href="'+ info.url +'" class="pp_service_link" id="pp_s_title_' + sid + '" target="_blank">'+ info.title +'</a>';

				if (info.short_description) {
					html += ' - <span class="pp_service_description">' + '<a onclick="return !__pp.showServiceDetails('+sid+', \''+thisAlias+'\');" href="'+ info.url +'" class="pp_service_link" id="pp_s_title_' + sid + '" target="_blank">'+ info.short_description +'</a></span>';
				};
				
				*/
	
				html += '</div>';
			}
			if (!foundService) {
				html += '<div class="pp_light">Dit portaal heeft helaas (nog) geen faciliteiten.</div>';
			} else {

				//html += '<br /><img src="'+this.myUrl+'/img/service_legenda.gif" />';
				//html += '<br /><b>Legenda:</b>';
				
				html += '<br /><br /><p><span class="pp_on_container"><input style="width: 26px; height: 13px" class="pp_submit_on" src="'+this.myUrl+'/img/check_on_trans.gif" type="image" value="Aan" name="do_submit" /></span>= Aangemeld';
				html += '&nbsp;&nbsp;<input style="width: 26px; height: 13px" class="pp_submit_off" src="'+this.myUrl+'/img/check_off.jpg" type="image" value="Aan" name="do_submit" />= niet aangemeld</p>';
				
				html += '<div class="pp_area_footer">';
				if (content.foot) {
					html +=  content.foot + '<br />';
				}
			
				html += '<div class="pp_button_container"><br />';

				if (content.finish) {
					html += ''
					html += '<form method="post" action="" onsubmit="__pp.finishSubscribe(); return false">';
					html += '<input type="submit" class="pp_inp_submit" name="pp_finish" value="' +content.finish+ '" />';
					html += '</form>';
				};


	

				html += '<div class="pp_help_button"><a href="mailto:helpdesk@residentie.net?subject=Mijn%20Residentie.Net"><span>help</span></a></div>';
				if (this.tmp.showService == 'my_rnet') {
					html += '<div class="pp_service_checkout"><a onclick="__pp.cnt_EditProfile()" href="#">mijn gegevens</a>&nbsp;<a href="#" onclick="__pp.unsubscribeServices(); return false;"><u>Afmelden faciliteiten</u></a></div>';
				} else if (this.tmp.showService == 'unsubscribe') {
					html += '<div class="pp_service_checkout"><a onclick="__pp.cnt_EditProfile()" href="#">mijn gegevens</a>&nbsp;<a href="#" onclick="__pp.showServices(); return false;">Terug naar mijn profiel</a></div>';
				}

				html += '</div>';
				html += '</div>';

			}
			

			html += '</div>';
			html += '</div>';
			html += '</div>';
			html += '</div>';

			html += '<div id="pp_service_details_container"></div>';

			$(this.contentDiv).innerHTML = '<div id="pp_content">' + html + '</div>';

		}

		return;

		//alert(this.display_portal + " ; " + name);
		//if (this.display_portal) {
		
			for (key in tot) {
				for(var i =0; i<tot[key].length;i++) {
					//$(this.contentDiv).innerHTML += tot[key][i].title + "<br />";							

					var info = tot[key][i];

					if (this.managment) {

						var act = this.pim_base_url + "loket/" + this.tabAlias + "/portal_plugin";

						var html =  '<form style="display: inline" onsubmit="__pp.call(\''+act+'\', Form.serialize(this), true); return false;" class="pp_form_subscribe">';

						html += '<input type="hidden" value="'+ info.subscription +'" name="subscription" />';
						html += '<input type="hidden" value="'+ info.subscribe_to +'" name="subscribe_to" />';
						if (info.favorite == "true") { 	
							html += '<input type="hidden" value="unmake_fav" name="action" />';
							html += '<input class="pp_submit_off" type="submit" value="Uit" name="do_submit" />';				
						} else {
							html += '<input type="hidden" value="make_fav" name="action" />';
							html += '<input class="pp_submit_on" type="submit" value="Aan" name="do_submit" />';
						};
						html += '</form>';

						$('pp_print').innerHTML += html;
					}

					if ((info.favorite == "true") || (this.managment == true)) {
						$('pp_print').innerHTML += " <a href='"+ info.url +"' class='pp_service_link' target='_blank'>"+ info.title +"</a><br />";
					}

				}

			}
		//}
		
		if (this.managment == true) {				
			$('pp_print').innerHTML += "<br /><button id='pp_toggle_manage_off' class='pp_toggle_manage' onclick='__pp.workAround();'>Annuleer beheer faciliteiten</button>";
		} else {
			
			$('pp_print').innerHTML += "<br /><button id='pp_toggle_manage_on' class='pp_toggle_manage' onclick='__pp.workAround();'>Beheer faciliteiten</button>";
		}

		$('pp_print').innerHTML += "<br /><br /><a class='pp_menu_option' onclick='__pp.call(this.href, {}); return false;' href='"+this.pim_base_url+"pim/settings.html' target='_blank'>Uw persoonlijke instellingen</a><br />";
		//if (this.Credentials.username != undefined) {
			$('pp_print').innerHTML += "<br /><span id='pp_loginstatus'>U bent ingelogd als: "+this.Credentials.username+"<br /><a href='#' onclick='__pp.logout(); return false;' id='pp_logout'>Uitloggen</a></a>";
		//}
		
	},
	changeActivePortal: function(sp, alias) {
		$('pp_service_details_container').innerHTML = '';

		this.pp_action_done = false;

		var active = document.getElementsByClassName('pp_service');
		for(var i = 0;i < active.length;i++) {

			//active[i].style.color 			= 'white';
			//active[i].firstChild.onclick = function() { return false; };
			active[i].firstChild.style.cursor = 'wait';
		}

		var body = document.getElementsByTagName('body')[0];
		body.style.cursor = 'wait';

		$('pp_service_' + alias).style.color = 'white';
		$('pp_service_' + alias).style.backgroundColor = '#565555';

		if (this.tabAlias != alias) {
			this.tabAlias = alias;
			this.call_loket({});
		}
		//sp.parentNode.className = 'sp_service_active';

		// empty currently showing services list
		// fetch new one for the new alias (unless of course alias = current alias!)
	},
	_checkLoginResult: function(c) {

		c = c.toHash();

		if (c['status'] == 1) {

			this.userInfo = {
				username: 	c.username,
				first_name: c.firstname,
				last_name: 	c.lastname,
				email: 		c.email
			};

			if (this.tmp.pimAction != undefined) switch(this.tmp.pimAction) {
				case 'editProfile':
					this.cnt_EditProfile();
					return;
			}

			if (this.tmp.loginAttempt == true) {
				this.tmp.showService = 'my_rnet';
			}
			this.call_loket({	sessionid: this.Credentials.sessionid,
					   			serviceid: this.Credentials.serviceid});
			
		} else {
			//this.setMessage('U bent niet ingelogd.');
			
			$('pp_print').innerHTML = this._getLoginFormHTML()
			$('pp_print').innerHTML += "<li><a href='#' id='pp_reg_link' class='pp_menu_option' onclick='__pp.cnt_Register();'>Registreren? Klik hier!</a></li>";
			$('pp_print').innerHTML += '<li><a href="#" id="pp_forgot_pass" class="pp_menu_option" onclick="__pp.cnt_ForgotPass();">Wachtwoord vergeten?</a></li>';
			$('pp_print').innerHTML += "<li><a href='#' id='pp_whatis' class='pp_menu_option' onclick='__pp.cnt_Help();'>Wat is mijn residentie.net?</a></li>";

			//alert("Er is een fout opgetreden bij het inloggen, controleer uw naam en wachtwoord.");

			if (this.tmp.loginAttempt == true) {

				var html = '';
				html += '<div class="pp_area" id="pp_feedback_form_area">';
				html += '<div class="pp_area_title"><span id="pp_a_feedback_title">Ongeldige gebruikersnaam/wachtwoord</span></div>';
				html += '<div class="pp_area_sub_title"><span id="pp_a_feedback_sub_title">&nbsp;</span></div>';
				html += '<div class="pp_area_content">';
				html += '<div id="pp_area_messages"></div>';

				html += '<p style="margin-top: 0px">U heeft niet de correcte inloggegevens ingevuld. Bent u uw wachtwoord vergeten? Klik dan ';
				html += 'op de <a onclick="__pp.cnt_ForgotPass();" href="#">wachtwoord vergeten</a> link.</p>';

				html += '</div>';
				html += '</div>';

				$(this.contentDiv).innerHTML = html;
			}
		};

		this.tmp.loginAttempt = false;
	},
	
	_getLoginFormHTML: function() {
		var html = '';
		html += '<form method="post" id="pp_login_fields">';
			html += '<div><label  for="__ppName">Login</label>';
			html += '<input type="text" class="formInput" id="__ppName" name="__ppName" /></div>';

			html += '<div><label  for="__ppPass">Password</label>';
			html += '<input type="password" class="formInput" id="__ppPass" name="__ppPass" /></div>';

			html += '<div><input class="formButton" type="submit" value=" " id="__ppSubmitLogin" onclick="__pp.doLogin();return false;" /></div>';
		html += '</form>';
		return html;
	},
	_redirect_form: function(c, root) {
		//alert("Want to redirect: " + $H(c[0].attributes.value).inspect());

		//alert(""+this.sessionid);
		
		var info = root.attributes.toHash();

		//alert(c.getLength());
		for(i=0;i<c.getLength();i++) {
			var attrs = c.item(i).attributes.toHash();
			info[attrs.name] = attrs.value;
		}
		
		this.Credentials.sessionid = info.sessionid;
		this.Credentials.serviceid = info.serviceid;
		this.sessionid = info.sessionid;
		//alert(""+this.sessionid);

		var callObj = {
			sessionid: info.sessionid,
			serviceid: info.serviceid
		};
		
		if (this.Credentials.username != undefined && this.Credentials.password != undefined) {
			callObj.username = this.Credentials.username;
			callObj.password = this.Credentials.password;
		}

		this.call_pim(callObj);
	},

	notifyHttpResult: function(key) {

		var body = document.getElementsByTagName('body')[0];
		body.style.cursor = 'auto';

		this.setMessage('');
		
		//if (this.gateway) {
			var source_url	= this.gateway.GetVariable('/:source_url_' + key);
			var content 	= this.gateway.GetVariable('/:res_' + key);
		//}

		//zorg voor later aan de flash kant
		var parser 	= new XMLParser();
		var doc 	= null;
		var ok		= true;

		// Flash always returns String values, ... yeck
		if (content == 'undefined') {
			ok = false;
		} else try {
			parser.parse(content);
			doc = parser.doc;
		} catch (e) { 
			this.setError(e);
			//alert(e + " ::: " + content); 
			ok = false; 
		};


		if (ok) {
			var root 		= doc.getDocumentElement();
			var children 	= root.getChildNodes()// #.toHash();
			var rootName	= root.getTagName();

			rootName = rootName.substitute('-', '_');

			if (this['_' + rootName] == undefined) {
				this.setError("Sorry, no handler for: " + rootName);
			} else {
				this['_' + rootName](children, root, doc, content, source_url);
			}
		} else {
			// Handle errors
			// alert('Yeck! - bad error!');
		}
		
		// fetch the http result back from the flash player object
		// and handle more like the normal AJAX
	},
	
	call_loket: function(params) {

		/*this.call(this.pim_base_url + 'loket/rnet/portal_plugin');
		this.call(this.pim_base_url + 'loket/ow/portal_plugin');
		this.call(this.pim_base_url + 'loket/ondernemers/portal_plugin');*/
		this.call(this.pim_base_url + 'loket/' + this.tabAlias  + '/portal_plugin', params);
		return 
	},

	call_pim: function(params) {
		return this.call(this.pim_base_url + 'pim/portal_plugin', params);
	},
	
	call_content: function(file) {
		this.call(this.myUrl + '/content/' + file + '.html', {});
		return;
	},

	setError: function(msg) {
		return false; // disabled
		return this.setMessage('<span style="background-color: red">' + msg + '</span>');
	},
	setMessage: function(msg) {
		try {
			$('__ppInfo').innerHTML = msg;
			if (msg == '') {
				$('__ppInfo').style.display = 'none';
			} else {
				$('__ppInfo').style.display = 'block';
				$('__ppInfo').style.marginBottom = '9px';
				$('__ppInfo').style.borderBottom = '1px solid #BABABA';
			}
		} catch (e) {};
	},

 	call: function(url, params, noConvert) {

		this.debug('Calling: ' + url);
		this.setMessage('Bezig... ');
 		// Mimick AJAX through a flash gateway - allowing remote http requests
 		// using the 'remote policy' implemtation. XmlHttpRequest doesn't have
 		// this and requires settings in the user's browser to make it work.

		if (!noConvert) {
			params = $H(params).toQueryString();
		}

 		this.gateway.SetVariable('/:gateway.post_data', params);
		this.gateway.SetVariable('/:gateway.doRequest', url);
 
 	},
 	checkInitialLogin: function() {
 	
 		// ask loket: is user logged in
		__pp.call_loket({});
		// if not - ask pim and if pim says yes ask loket again
		// with some info about 
		// - DO THAT

		// catch result in the result handler
		// then -
			// - if user is logged in: display list of services
			// - if user is not logged in: display login fields
			//   with doc.write calls
	 	
 	
 	},
 	
 	init: function(tab, showTabs) {
 	
		this.showTabs = showTabs;
		var r = '';

		// add stylesheets
		/*this._addCSS(this.myUrl + 'style/pp-generic.css' + r);*/
	//	this._addCSS(this.myUrl + '/style/pp-generic.css');
		this._addCSS('https://mijn.residentie.net/portalplugin/style/pp-generic.css');


	//	this._addCSS(this.myUrl + 'style/pp-' + tab + '.css' + r);

		// add extra javascript files
		this._addScript(this.myUrl + 'js/prototype.js' + r);
		this._addScript(this.myUrl + 'js/xmlp.js' + r);



//		var html = '<div class="boxmenu" id="pp_login">';
		var html = '<style>#flash { height:10px; overflow:hidden; } </style><h3>MIJN RESIDENTIE.NET</h3>';
//		html += '<div class="boxMenuContent">';

		this.tabAlias = tab;
		this.managment = false;
		
		var width = 1;
		var height = 1;
		html += '<div id="flash"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+width+'" height="'+height+'" id="pp_gateway" align="middle">';
		html += '<param name="allowScriptAccess" value="always" />';
		html += '<param name="movie" value="' + this.myUrl  + 'gateway.swf" />';
		html += '<param name="flashvars" value="myLocation='+document.location.href+'" />';
		html += '<param name="quality" value="high" />';
		html += '<param name="wmode" value="Transparent" />';
		html += '<param name="bgcolor" value="#BABABA" />';
		html += '<embed flashvars="myLocation='+document.location.href+'" src="'+ this.myUrl  +'gateway.swf?myLocation='+document.location.href+'" wmode="Transparent" quality="high" bgcolor="#BABABA" width="'+width+'" swliveconnect="true" height="'+height+'" name="pp_gateway" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		html += '</object></div>';
	
		html += '<div id="__ppInfo"><div><p class="pp_text">Mijn Residentie.Net wordt geladen.</span></div></div>';
		html += '<ul><div id="pp_print">';

			/*
			html += '<a href="#" class="pp_menu_option" onclick="__pp.cnt_WhatIsIt();return false;">Wat is het?</a><br />';
			html += '<a href="#" class="pp_menu_option" onclick="__pp.cnt_TheServices();return false;">De diensten!</a><br />';
			html += '<a href="#" class="pp_menu_option" onclick="__pp.cnt_Register();return false;">Registreer uzelf!</a><br /><br />';
			*/
			
		html += '</div></ul>';

	//	html += '</div>';
//		html += '</div>';

		document.write(html);
		var me = this;
		setTimeout(function() {
			me._init();
		}, 1000);
	},

	_init: function() {

		if (!DetectFlashVer(7,0,0)) {
			$('pp_print').innerHTML = '<span style="text-transform: none">U heeft geen Flash Player geinstalleerd. Om Mijn Residentie.Net te gebruiken heeft u deze nodig. Bezoek <a style="text-decoration: underline" href="http://www.adobe.com/go/gntray_dl_getflashplayer">adobe.com</a> om deze te installeren.<br /><br />Of gebruik onze andere omgeving zonder flash op <a style="text-decoration: underline" href="http://mijn.residentie.net/pim">mijn.residentie.net</a></span>';
			return false;
		}


		this.loadingImage = '<span class="pp_loading_container"><img width="60" height="15" style="border: none" src="' + this.myUrl + 'img/loading.gif" alt="Verwerken" /></span>';

		this.setMessage('Bezig.');
		setTimeout(function() {
			
			__pp.gateway = getFlashMovieObject('pp_gateway');	
			__pp.checkInitialLogin();
			
		}, 2000); // give it some time to load swf


		setInterval(function() {
			__pp.call_pim({});
		}, 60000*5);
		
		if (this._qsv('pp_action') == 'activated') {
			var me = this;
			setTimeout(function() {

				var html = '';
				html += '<div class="pp_area" id="pp_reg_form_area">';
				html += '<div class="pp_area_title"><span id="pp_text">Bezig met laden</span></div>';
				html += '<div class="pp_area_sub_title"><span id="pp_a_reg_sub_title">'+me.loadingImage+'<span></div>';
				html += '<div class="pp_area_content">';
				html += '<div id="pp_area_messages"></div>';
				html += '&nbsp;';
				html += '</div>';
				html += '</div>';

				$(me.contentDiv).innerHTML = html;

			}, 10);
		};
	},

	doLogin: function() {
		//var gateway = getFlashMovieObject('pp_gateway');

		this.tmp.loginAttempt = true;
		this.Credentials.username = $F('__ppName');
		this.Credentials.password = $F('__ppPass');

		this.call_loket({});
	},
	logout: function() {
		this.call_loket({logout: 'true'});
		this.call_pim({logout: 'true'});
		
		//__pp.init(this.tabAlias);
	// toegevoegd door pascal, in IE moest er gerefreshed worden om te zien dat je was uitgelogd 	
	window.location.replace(window.location.href);		
		
	},
	
	subscribe: function(b) {
		b.innerHTML = 'Uit';
		b.onclick = function() {
			__pp.unsubscribe(b);	
		}
		this.setMessage("U heeft zich ingeschreven voor deze dienst");
	},
	
	unsubscribe: function(b) {
		b.innerHTML = 'Aan';
		b.onclick = function() {
			__pp.subscribe(b);	
		}
		this.setMessage("U heeft zich uitgeschreven voor deze dienst");
	},
	cnt_Disclaimer: function() {
		this.call_content('disclaimer');
	},
	cnt_Help: function() {
		this.call_content('help');
	},
	
	cnt_ServiceExplain: function() {
		this.call_content('explain');
	},
	
	cnt_WhatIsIt: function() {
		this.call_content('uitleg');
	},
	
	cnt_TheServices: function() {
		this.call_content('services');
	},

	hf: function(name, value) {
		return '<input type="hidden" name="' + name + '" value="'+value+'" />';
	},
	makeRow: function(id, label, type, value) {
		if (value == undefined) value = '';
		var h = '<tr><th><label for="pp_row_' + id + '">' + label + '</label></th>';
		h += '<td><input class="pp_inp_'+ (type == undefined ? 'text' : type) + '" value="'+ value +'" type="' + (type == undefined ? 'text' : type) + '" name="'+ id +'" id="pp_row_' + id + '" /></td></tr>';
		return h;
	},
	
	cnt_SetPassword: function() {

		var html = '';
		html += '<div class="pp_area" id="pp_set_pass_area">';
		html += '<div class="pp_area_title"><span id="pp_a_set_pass">Wachtwoord vergeten</span></div>';
		html += '<div class="pp_area_sub_title"><span id="pp_a_set_pass_subtitle">stap 3 van 3</span></div>';
		html += '<div class="pp_area_content">';
		html += '<div id="pp_area_messages"></div>';
		html += '<form method="post" id="pp_set_pass_form" action="' + this.pim_url + '/portal_plugin">';
		html += this.hf('cmd:action', 'setPassword');
		html += '<table id="pp_table">';
		html += this.makeRow('password', 'Wachtwoord', 'password');
		html += this.makeRow('password2', 'Herhaal wachtwoord', 'password');
		html += '</table>';
		html += '<br /><br /><input type="submit" class="pp_inp_submit" name="b_submit" value="Ga verder" />';
		html += '<div class="pp_help_button"><a href="mailto:helpdesk@residentie.net?subject=Mijn%20Residentie.Net"><span>help</span></a></div>';
		html += '</form>';

		html += '</div>';
		html += '</div>';

		$(this.contentDiv).innerHTML = '<div id="pp_content">' + html + '</div>';

		this._setupFormSubmit('pp_set_pass_form', function(f) {

			var myMsg = '';
			
			if (f.password.value.length <= 5) {
				myMsg += 'Uw nieuwe wachwoord dient minimaal 5 karakters lang te zijn.<br />';
			} else if (f.password.value != f.password2.value) {
				myMsg += 'De ingevoerde wachtwoorden komen niet overeen.<br />';
			}

			if (myMsg != '') {
				$('pp_area_messages').innerHTML = myMsg + "<br />";
				return false;
			}

			f.b_submit.disabled = true;
			f.b_submit.className = 'pp_inp_submit_disabled';
			
			$('pp_area_messages').innerHTML = '';

			return true;
		});
	},
	cnt_ForgotPass: function() {

		var html = '';
		html += '<div class="pp_area" id="pp_forgot_pass_area">';
		html += '<div class="pp_area_title"><span id="pp_a_forgot_pass">Wachtwoord vergeten</span></div>';
		html += '<div class="pp_area_sub_title"><span id="pp_a_forgot_pass_subtitle">stap 1 van 3</span></div>';
		html += '<div class="pp_area_content">';
		html += '<div id="pp_area_messages"></div>';
		html += '<form method="post" id="pp_forgot_pass_form" action="' + this.pim_url + '/portal_plugin">';
		html += this.hf('cmd:action', 'sendActivationCode');
		html += this.hf('template', 'forgotpassword');
		html += '<table id="pp_table">';
		html += this.makeRow('email', 'gebruikersnaam', 'text');
		html += '</table>';
		html += '<br /><input type="submit" class="pp_inp_submit" name="b_submit" value="Ga verder" />';
		html += '<div class="pp_help_button"><a href="mailto:helpdesk@residentie.net?subject=Mijn%20Residentie.Net"><span>help</span></a></div>';
		html += '</form>';

		html += '</div>';
		html += '</div>';

		$(this.contentDiv).innerHTML = '<div id="pp_content">' + html + '</div>';

		this._setupFormSubmit('pp_forgot_pass_form', function(f) {

			var myMsg = '';

			if (f.email.value == '') {
				myMsg += "Geen gebruikersnaam opgegeven<br />";
			} else if (f.email.value.indexOf('@residentie.net') < 1) {
				f.email.value += '@residentie.net';
			};

			if (myMsg != '') {
				$('pp_area_messages').innerHTML = myMsg + "<br />";
				return false;
			}

			f.b_submit.disabled = true;
			f.b_submit.className = 'pp_inp_submit_disabled';
			
			$('pp_area_messages').innerHTML = '';

			return true;
		});
	},

	cnt_EditProfile: function() {

		if (!this.userInfo) {

			this.tmp.pimAction = 'editProfile';
			this.call_pim({});

			return false;
		}

		this.tmp.pimAction = undefined;
	
		var hf = this.hf;
		var makeRow = this.makeRow;

		var html = '';
		html += '<div class="pp_area" id="pp_change_form_area">';
		html += '<div class="pp_area_title"><span id="pp_a_change_title">Mijn gegevens</span></div>';
		html += '<div class="pp_area_sub_title"><span id="pp_a_change_sub_title">&nbsp;</span></div>';
		html += '<div class="pp_area_content">';
		html += '<div id="pp_area_messages"></div>';
		html += '<form method="post" id="pp_change_form" action="' + this.pim_url + '/portal_plugin">';
		html += hf('cmd:action', 'changeDetails');
		html += hf('change_source', document.location.href.replace(/^(.*?)[#?].*/, '$1'));
		html += '<table id="pp_table" cellpadding="2">';
		html += makeRow('first_name', 'voornaam', 'text', this.userInfo.first_name);
		html += makeRow('last_name', 'achternaam', 'text', this.userInfo.last_name);
		html += makeRow('email', 'email adres', 'text', this.userInfo.email);
		html += '</table>';
		html += '<br /><br />';
		html += '<input type="submit" class="pp_inp_submit" name="b_submit" value="Bewaar" />';
		html += '<div class="pp_help_button"><a href="mailto:helpdesk@residentie.net?subject=Mijn%20Residentie.Net"><span>help</span></a></div>';
		html += '<div style="bottom: 13px" class="pp_service_checkout"><a href="#" onclick="__pp.showServices(); return false;"><u>Terug naar mijn residentie.net</u></a></div';
		html += '</form>';

		html += '</div>';
		html += '</div>';

		$(this.contentDiv).innerHTML = html;

		this._setupFormSubmit('pp_change_form', function(f) {

			var myMsg = '';

			if (f.email.value == '') {
				myMsg += "Geen email adres opgegeven<br />";
			} else if (f.email.value.indexOf('@') == -1) {
				myMsg += "U heeft geen geldig e-mailadres opgegeven<br />";
			}
			if (f.first_name == '') {
				myMsg += "U heeft geen voornaam opgegeven<br />";
			}
			if (f.last_name == '') {
				myMsg += "U heeft geen achternaam opgegeven<br />";
			}

			if (myMsg != '') {
				$('pp_area_messages').innerHTML = myMsg + "<br />";
				return false;
			}

			f.b_submit.disabled = true;
			f.b_submit.className = 'pp_inp_submit_disabled';
			
			$('pp_area_messages').innerHTML = '';

			$('pp_a_change_sub_title').innerHTML = __pp.loadingImage;

			return true;
		});

	},

	cnt_Register: function() {

		var hf = this.hf;
		var makeRow = this.makeRow;

		var html = '';
		html += '<div class="pp_reg_intro"><h3>WELKOM OP MIJN RESIDENTIE.NET</h3><strong>Uw persoonlijke weg langs alle faciliteiten van Gemeente Den Haag</strong><br />Op deze pagina kunt u zich aanmelden voor Mijn.Residentie.net. Met het door u aan te maken profiel kunt u zich gaan aanmelden voor allerlei handige en informatieve faciliteiten op de verschillende portalen. Veel succes met uw Mijn.Residentie.net profiel.</div>';
		html += '<div class="pp_area" id="pp_reg_form_area">';
		html += '<div class="pp_area_title"><span id="pp_a_reg_title">Meld u hier aan</span></div>';
		html += '<div class="pp_area_sub_title"><span id="pp_a_reg_sub_title">stap 1 van 3</span></div>';
		html += '<div class="pp_area_content">';
		html += '<div id="pp_area_messages"></div>';
		html += '<form method="post" id="pp_reg_form" action="' + this.pim_url + '/portal_plugin">';
		html += hf('cmd:action', 'createUser');
		html += hf('reg_source', document.location.href.replace(/^(.*?)[#?].*/, '$1'));
		html += '<table id="pp_table">';
		html += makeRow('username', 'gebruikersnaam', 'text');
		html += makeRow('first_name', 'voornaam', 'text');
		html += makeRow('last_name', 'achternaam', 'text');
		html += makeRow('email', 'email adres', 'text');
		html += makeRow('password', 'wachtwoord', 'password');
		html += makeRow('password_repeat', 'bevestig wachtwoord', 'password');
		html += '</table>';
		html += '<input type="checkbox" id="pp_reg_agree" value="1" name="agree" /> ';
		//html += "<label id='pp_reg_agree'>Ik ben het eens met de </label><a href='#' onclick='__pp.cnt_Disclaimer();'>Algemene Voorwaarden</a>";
		html += "<label id='pp_reg_agree'>Ik ben het eens met de hieronder weergegeven algemene voorwaarden";	
		html += '<p>De website www.Residentie.net is een samenwerkingsverband tussen de gemeente Den Haag en andere partijen. Alle betrokken streven ernaar om correcte en actuele informatie te geven maar kunnen niet garanderen dat de informatie juist is op het moment waarop zij wordt ontvangen, of dat de informatie na verloop van tijd nog steeds juist is. Daarom kunnen aan de informatie op deze pagina\'s geen rechten worden ontleend en aanvaardt de gemeente geen aansprakelijkheid voor schade als gevolg van onjuistheden en/of gedateerde informatie.</p>';
		html += '<br /><br /><input type="submit" class="pp_inp_submit" name="b_submit" value="Ga verder" />';
		html += '<div class="pp_help_button"><a href="mailto:helpdesk@residentie.net?subject=Mijn%20Residentie.Net"><span>help</span></a></div>';
		html += '</form>';


//	html += '<label id="pp_reg_agree">Ik ben het eens met de </label><a target="_blank" href="http://www.residentie.net/dislaimer">algemene voorwaarden</a>.';






		html += '</div>';
		html += '</div>';

		$(this.contentDiv).innerHTML = '<div id="pp_content">' + html + '</div>';

		this._setupFormSubmit('pp_reg_form', function(f) {

			var myMsg = '';

			if (f.username.value == '') {
				myMsg += "Geen gebruikersnaam opgegeven<br />";
			} else if (f.username.value.indexOf('@residentie.net') < 1) {
				f.username.value += '@residentie.net';
			};

			if (f.password.value.length < 5) {
				myMsg += "U heeft geen (geldig) wachtwoord opgegeven<br />";
			} else if (f.password.value != f.password_repeat.value) {
				myMsg += "De wachtwoorden komen niet overeen<br />";
			}
			if (f.email.value.indexOf('@') == -1) {
				myMsg += "U heeft geen geldig e-mailadres opgegeven<br />";
			}
			if (f.agree.checked == false) {
				myMsg += "U bent niet akkoord gegaan met de algemene voorwaarden<br />";
			}

			if (myMsg != '') {
				$('pp_area_messages').innerHTML = myMsg + "<br />";
				return false;
			}

			f.b_submit.disabled = true;
			f.b_submit.className = 'pp_inp_submit_disabled';
			
			__pp.tmp.RegCache = {
				username: 	f.username.value,
				firstname: 	f.first_name.value,
				email:		f.email.value
			};

			$('pp_area_messages').innerHTML = '';

			$('pp_a_reg_sub_title').innerHTML = __pp.loadingImage;

			return true;
		});
	},
	
	finishSubscribe: function() {
		this.showServices();

		return false;
		$('pp_a_serv_title').innerHTML = 'Registratie compleet';
		$('pp_a_serv_sub_title').innerHTML = '&nbsp;';
		$('pp_serv_area').innerHTML = 'Hier wordt aan gewerkt.';
	},

	showServiceDetails: function(serv, alias) {
		var info = this.serviceList[alias][serv];

		var html = '';
		html += '<div class="pp_bordered_area">';
		html += '<h3>' + info.title + '</h3>';
		html += '<p class="pp_light">' + info.short_description + '</p>';
		html += '<p>' + info.description + '</p>';
		html += '<p style="align: right"><a href="'+info.url+'">Ga naar deze dienst</a></p>';
		html += '</div>';

		$('pp_service_details_container').innerHTML = html;

		return true;
	},
	setServiceLoading: function(act, sub, frm, pp_done) {

		if (pp_done != undefined) {
			this.pp_action_done = pp_done;
		}

		try {
			frm.subscription.focus();
		} catch (e) {};

		$('pp_s_title_' + sub).innerHTML = this.loadingImage;
		__pp.call(act, Form.serialize(frm), true);

		return false;

	},
	unsubscribeServices: function() {

		this.tmp.showService = 'unsubscribe';
		this.call_loket({});

	},
	showServices: function() {

		this.tmp.showService = 'my_rnet';
		this.call_loket({});
	},

	// sets up a form for AJAX submit to the PIM side
	_setupFormSubmit: function(frm, cb) {

		setTimeout(function() {
			$(frm).onsubmit = function() {

				if (cb == undefined || cb(this)) {
					__pp.call(this.action, Form.serialize(this), true);
				}
				
				return false;
			}
		}, 500); // wait some time to make sure the form exists in the DOM

	},
	
	workAround: function() {
		this.managment = !this.managment;
		this.call_loket({});
	}
};

// Flash Player Version Detection - Rev 1.5
// Detect Client Browser type
// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;			
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
			var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}
