/**
 * WARNING: in spite of the class name "nieuwsbrief" this functionality is called "Mailing" to the user
 */
	activity.nieuwsbrief = Class.create(activity.mailing, {
		initialize:function($super, container, controller){
			$super(container, controller);
			this.instID = 'activity.nieuwsbrief.' + parseInt(Math.random()*1000000);
			this.myCommand = 'persclubNieuwsbrief';
			// texts 
			this.previewTemplate = 'include/showTemplate.php?nieuwsbrief_id=';
//			this.uploadWarning = "Om bestanden te koppelen dient u de nieuwsbrief eerst op te slaan";
//			this.viewMailingText = "Nieuwsbrief bekijken";
//			this.nameOfMailingText = "Naam van de nieuwsbrief* : ";
//			this.descriptionOfMailingText = 'Optionele beschrijving van deze nieuwsbrief:<br/>';
//			this.dateSelectText = '<b>Selecteer een datum waarop de nieuwsbrief verzonden moet worden:</b><br/>';
//			this.dtToSendText = "<br/>Deze nieuwsbrief wordt verzonden op: <b>";
//			this.dtToSentText = "<br/>Deze nieuwsbrief is verzonden op: <b>"; 
//			this.selectListWarning = "Kies minimaal 1 lijst waar de nieuwsbrief naar verzonden zal worden:<br/>";
//			this.sendMailConfirmText = 'Weet u zeker dat u de nieuwsbrief wilt versturen?';
//			this.mailSentConfirmationText = "<blink>De nieuwsbrief is verzonden !</blink>";
			this.uploadWarning = "Om bestanden te koppelen dient u de mailing eerst op te slaan";
			this.viewMailingText = "Mailing bekijken";
			this.nameOfMailingText = "Naam van de mailing * : ";
			this.descriptionOfMailingText = 'Optionele beschrijving van deze mailing:<br/>';
			this.dateSelectText = '<b>Selecteer een datum waarop de mailing verzonden moet worden:</b><br/>';
			this.dtToSendText = "<br/>Deze mailing wordt verzonden op: <b>";
			this.dtToSentText = "<br/>Deze mailing is verzonden op: <b>"; 
			this.selectListWarning = "Kies minimaal 1 lijst waar de mailing naar verzonden zal worden:<br/>";
			this.sendMailConfirmText = 'Weet u zeker dat u de mailing wilt versturen?';
			this.mailSentConfirmationText = "<blink>De mailing is verzonden !</blink>";
			
						
		},
		
		draw : function(){
			unWaiter();
			unWaiter();

			this.container.update('');
			
			//add drawers:
			this.container.insert('<form name="'+this.instID + '_form" id="' +this.instID + '_form" action="/index.php" method="post" target="'+this.instID+'uploadIFrame" enctype="multipart/form-data">');
			var form = $(this.instID + '_form');
			
			var aContainer = this.addDrawer(form, 'Instellingen');
			this.drawSettings(aContainer);
			
			var aContainer = this.addDrawer(this.container, 'Email-lijst');
			this.getLists(aContainer, 'perclubBasket');
			this.getLists(aContainer, 'perclubPrivateBasket');
			
			var aContainer = this.addDrawer(this.container, 'Sjabloon');
			this.getTemplates(aContainer);

			
			var aContainer = this.addDrawer(form, 'Bericht', (function(){this.startTinyEditor('message1')}).bind(this) );
			this.getMessageProperties(aContainer, 1 );
			aContainer.insert('<textarea id="message1">' + recursivehtml_entity_decode(this.message1) + '</textarea>');
			
			var aContainer = this.addDrawer(this.container, 'Attachments');
			this.writeFileUploader(aContainer);

			var aContainer = this.addDrawer(this.container, 'Verzending');
			this.setMessageTiming(aContainer);
			
			this.container.insert("</form>");

			this.statusBar = new Element('div', {id:this.instID + "_status", className:'activityStatus'})
			this.container.insert(this.statusBar);

			var ieContainer = new Element('div', {className:'ieContainer'});
			this.container.insert(ieContainer);

			var storeBttn = new Element('input', {type:'button', className:'type-button', value:'Hoofdmenu', id:this.instID + '_cancel', style:'float:left;'});
			ieContainer.insert(storeBttn);
			storeBttn.observe('click', this.goBack.bind(this))

			var sendBttn = new Element('input', {type:'button',className:'type-button', id:this.instID + '_send', style:'float:right;', value:'Versturen'});
			sendBttn.disabled = true;
			ieContainer.insert(sendBttn);
			sendBttn.observe('click', this.sendMailing.bindAsEventListener(this));

			var sendTestBttn = new Element('input', {type:'button',className:'type-button',id:this.instID + '_sendTest', style:'float:right;', value:"Testbericht versturen"});
			sendTestBttn.disabled = true;
			ieContainer.insert(sendTestBttn);
			sendTestBttn.observe('click', this.sendTestMail.bind(this));

			var previewBttn = new Element('input', {type:'button',className:'type-button', id:this.instID + '_preview', style:'float:right;', value:this.viewMailingText} );
			previewBttn.disabled = true;
			ieContainer.insert(previewBttn);
			previewBttn.observe('click', (function(){
				if ($(this.instID + '_mailingURL1').getValue() !='' ){
					window.open($(this.instID + '_mailingURL1').getValue());
				}else{
					window.open(this.previewTemplate + this.id);
				}
			}).bind(this))

			var storeBttn = new Element('input', {type:'button',className:'type-button', id:this.instID + '_store',style:'float:right;', value:"Opslaan"});
			ieContainer.insert(storeBttn);
			storeBttn.observe('click', this.saveActivity.bind(this))
			this.container.insert('<iframe name="'+this.instID+'uploadIFrame" id="'+this.instID+'uploadIFrame" width="0" frameborder="0" height="0"></iframe>');
			if ($(this.instID + '_mailingURL1').getValue() !=''){
				this.hideTiny(); 
			}

			return ieContainer;
		},
		
		validateSave : function(checkForSend){
			if (!checkForSend) checkForSend=false;
			// check if all values are OK to save
			var ok = true;
			var okForSend = true;
			this.resetDrawerStatus();
			
			// check mailing-settings:
			if ( !$(this.instID + '_mailingName') || !$(this.instID + '_mailingName').getValue()){
				ok = false;
				okForSend = false;
				if ($(this.instID + '_mailingName')) $(this.instID + '_mailingName').setStyle('background-color:#ff9898;')
				this.setDrawerStatus('Instellingen', 'fatal');
			}else{
				this.setDrawerStatus('Instellingen', 'ok');
				if ($(this.instID + '_mailingName')) {
					$(this.instID + '_mailingName').setStyle('background-color:#98ff9f;');
					this.name = $(this.instID + '_mailingName').getValue();
				}
			}
			
			// check sendername:
			if ( !$(this.instID + '_senderName') || !$(this.instID + '_senderName').getValue()){
				ok = false;
				okForSend = false;
				if ($(this.instID + '_senderName')) $(this.instID + '_senderName').setStyle('background-color:#ff9898;')
				this.setDrawerStatus('Instellingen', 'fatal');
			}else{
				this.setDrawerStatus('Instellingen', 'ok');
				if ($(this.instID + '_senderName')) {
					$(this.instID + '_senderName').setStyle('background-color:#98ff9f;');
					this.senderName = $(this.instID + '_senderName').getValue();
				}
			}

			// check senderEmail:
			if ( !$(this.instID + '_senderEmail') || !$(this.instID + '_senderEmail').getValue()){
				ok = false;
				okForSend = false;
				if ($(this.instID + '_senderEmail')) $(this.instID + '_senderEmail').setStyle('background-color:#ff9898;')
				this.setDrawerStatus('Instellingen', 'fatal');
			}else{
				this.setDrawerStatus('Instellingen', 'ok');
				if ($(this.instID + '_senderEmail')) {
					$(this.instID + '_senderEmail').setStyle('background-color:#98ff9f;');
					this.senderEmail = $(this.instID + '_senderEmail').getValue();
				}
			}

			// check subject:
			if ( !$(this.instID + '_subject') || !$(this.instID + '_subject').getValue()){
				ok = false;
				okForSend = false;
				if ($(this.instID + '_subject')) $(this.instID + '_subject').setStyle('background-color:#ff9898;')
				this.setDrawerStatus('Instellingen', 'fatal');
			}else{
				this.setDrawerStatus('Instellingen', 'ok');
				if ($(this.instID + '_subject')) {
					$(this.instID + '_subject').setStyle('background-color:#98ff9f;');
					this.subject = $(this.instID + '_subject').getValue();
				}
			}

			// check list-selection:
			var selectedLists = []; 
			$$('.activityListSelect').each(
				function(input){
					if (input.checked) selectedLists.push(input.value);
				}
			)
			
			if (selectedLists.length < 1){
				this.setDrawerStatus('Email-lijst', 'error');
				okForSend = false;
			}else{
				this.setDrawerStatus('Email-lijst', 'ok');
			}

			// check template:
			if ($(this.instID + '_mailingURL1').getValue() != ''){
				this.setDrawerStatus('Sjabloon', 'ok');
			}else{
				var selectedTemplates = $$('.templateSelect').findAll(
						function(input){
							if (input.checked) {
								return input;
							}
						}
					)
	
				if (selectedTemplates.length < 1){
					okForSend = false;
					this.setDrawerStatus('Sjabloon', 'error');
				}else{
					this.setDrawerStatus('Sjabloon', 'ok');
				}
			}
			
			// check messages
			var ed = tinyMCE.get('message1');
			if (ed){
				try{
					tinyMCE.execCommand('mceCleanup');
					this['message1'] = ed.getContent();
				}catch(e){
					var ed = '';
				}
			}
			if ($(this.instID + '_mailingURL1') && $(this.instID + '_mailingURL1').getValue() == '') $(this.instID + '_mailingURL1').setStyle('background-color:#98ff9f;');
			if ( ($(this.instID + '_mailingURL1')) ){
				if ($(this.instID + '_mailingURL1').getValue() != '' ){
					this['mailingURL'] = $(this.instID + '_mailingURL1').getValue();
					if (this['mailingURL'].toString().indexOf('http://') == -1 &&  this['mailingURL'].toString().indexOf('https://') == -1){
						okForSend = false;
						this.setDrawerStatus('Bericht', 'fatal');
						$(this.instID + '_mailingURL1').setStyle('background-color:#ff9898;')
					}else{
						$(this.instID + '_mailingURL1').setStyle('background-color:#98ff9f;');
						this.setDrawerStatus('Bericht', 'ok');
					}
				}else{
					this['mailingURL'] = '';
				}
			}else{
				// check if at least message 1 has a value:
				if (this.message1.length < 1){
					okForSend = false;
					this.setDrawerStatus('Bericht', 'error');
				}else{
					this.setDrawerStatus('Bericht', 'ok');
				}
				this['mailingURL'] = '';
			}
			this['imageAlign1'] = $(this.instID + '_imageAlign1').getValue();

			this['title1'] = $(this.instID + '_mailingTitle1').getValue();
			this['titleImageAlign'] = $(this.instID + '_titleImageAlign').getValue();
			this['showTitle'] = $(this.instID + '_showTitle').getValue();

			var ed = tinyMCE.get(this.instID + '_description');
			if (ed){
				try{
					this.description = ed.getContent();
				}catch(e){
					var ed = '';
				}
			}else{
				this.description = $(this.instID + '_description').getValue();
			}
			this.setDrawerStatus('Verzending', 'ok');
			if (okForSend){
				$(this.instID + '_send').disabled = false;
				$(this.instID + '_sendTest').disabled = false;
				$(this.instID + '_preview').disabled = false;
				if ($(this.instID + '_landingPreview')) $(this.instID + '_landingPreview').disabled = false;
			}else{
				$(this.instID + '_send').disabled = true;
				$(this.instID + '_sendTest').disabled = true;
				$(this.instID + '_preview').disabled = true;
				if ($(this.instID + '_landingPreview')) $(this.instID + '_landingPreview').disabled = true;
			}
			
			if (checkForSend) return okForSend;
			return ok;
		},
		
		saveMailing : function(callBack){
			this.statusBar.update("Bezig met opslaan...");
			if (!callBack) callBack = this.handleSave.bind(this);
			var RPCObj = new rpc;
			RPCObj.debug = true;
			RPCObj.createCall(this.myCommand, '', this);
			RPCObj.setMethod('saveMailing');

			RPCObj.attachWaiter(function(){shader('', "Even geduld a.u.b, bezig met opslaan")}, this);
			RPCObj.attachUnWaiter(unShader, this);

			RPCObj.addArgument('mailingID', this.id);
			RPCObj.addArgument('name', encodeURIComponent(this.name));
			RPCObj.addArgument('titleImageAlign', this.titleImageAlign);
			RPCObj.addArgument('showTitle', this.showTitle);
			RPCObj.addArgument('senderName', this.senderName);
			RPCObj.addArgument('senderEmail', this.senderEmail);
			RPCObj.addArgument('subject', encodeURIComponent(this.subject));
			RPCObj.addArgument('description', '<![CDATA[' + encodeURIComponent(this.description) + " ]]>");
			RPCObj.addArgument('url1', encodeURIComponent(this['mailingURL'] ));
			RPCObj.addArgument('title1', encodeURIComponent(this['title1']));
		
			var ed = tinyMCE.get('message1');
			if (ed){
				RPCObj.addArgument('message1', '<![CDATA[' + encodeURIComponent(this['message1'])+ " ]]>");
			}
			RPCObj.addArgument('imageAlign1', this['imageAlign1']);
			
			if (this.sendDate) {
				var minutes = this.sendDate.date.getMinutes();
				if (minutes < 10){
					var minutes = '0' + minutes.toString();  
				}
				var date = this.sendDate.date.getFullYear() + "-" + (this.sendDate.date.getMonth()+1) + "-" + this.sendDate.date.getDate() + " " + this.sendDate.date.getHours() + ":" + minutes + ":00";
				RPCObj.addArgument('dtToSent', '<![CDATA[' + (date)+ " ]]>");
			}
			// add selected lists:
			var selectedLists = [];
			var selectedPrivateLists = []; 
			$$('.activityListSelect').each(
				function(input){
					if (input.checked){
						if (input.command == 'perclubPrivateBasket'){
							selectedPrivateLists.push(input.value);
						}else{
							selectedLists.push(input.value);
						}
					}
				}
			)
			if (selectedLists[0]) {
//				selectedLists = selectedLists[0].getValue();
				RPCObj.addArgument('basket_id', selectedLists.join(','));
			}else{
				RPCObj.addArgument('basket_id', '');
			}
			if (selectedPrivateLists[0]) {
//				selectedLists = selectedLists[0].getValue();
				RPCObj.addArgument('private_basket_id', selectedPrivateLists.join(','));
			}else{
				RPCObj.addArgument('private_basket_id', '');
			}
			
			// add selected template:
			var selectedTemplates = $$('.templateSelect').findAll(
				function(input){
					if (input.checked) return input;
				}
			)
			if (selectedTemplates[0]) {
				selectedTemplates = selectedTemplates[0].getValue();
				RPCObj.addArgument('template_id', selectedTemplates);
			}
				
			RPCObj.setCallback(callBack);
			RPCObj.call();			

		},
		
		handleSave : function(req){
			if (req.responseJSON.message){
				shader("", "Er is een fout opgetreden bij het verwerken van de mailing, de mailing is opgeslagen maar kan niet verzonden worden. <br/>Neem contact op met de helpdesk <br/>(errormelding: " + req.responseJSON.message + ")");
				return;
			}
			if (this.id == 0){
				this.id = req.responseJSON.mailingID;
			}
			this.id = req.responseJSON.mailingID;
			var hasFiles = false;
			if ( $(this.instID + '_hidden1').getValue()){
				hasFiles = true;	
			}
			if ( $(this.instID + '_titleFile').getValue()){
				hasFiles = true;	
			}
			if (hasFiles){
				this.statusBar.update("Bezig met uploaden bestanden .... ");
				this.handleUploads();
			}else{
				this.statusBar.update("Opgeslagen!");
			}
		},
		
		writeFileUploader:function(container){
			if ($('attachmentUploader')) $('attachmentUploader').remove();
			var div = new Element('div', {className:'uploader', id:'attachmentUploader'});
			container.insert(div);
			if (!this.id){
				var iframe = new Element('span').update(this.uploadWarning);
			}else{
				var iframe = new Element('iframe', {height:'75px', frameborder:'0',  border:'0', width:'100%', scrolling:'auto', src:'include/nieuwsbrief_attachments.php?id=' + this.id});
				iframe.setStyle("border:1px black solid;");
			}
			div.insert(iframe);
		},
		
		drawSettings : function(container){
			var div = new Element('div', {style:'padding:5px;'});
			container.insert(div);
			
			var input = new Element('input', {type:'text', id:this.instID + '_mailingName', className:'activityInput', value:this.name});
			div.insert(new Element('span', {className:'activityTitle'}).update(this.nameOfMailingText));
			div.insert(input);
			input.observe('change', this.updateTitle1.bindAsEventListener(this))
			
			div.insert('<br/>');
			
			var select = new Element('select', {id:this.instID + '_showTitle', className:'activityInput'});
			div.insert(new Element('span', {className:'activityTitle'}).update("Toon naam als titel in bericht: "));
			div.insert(select);
			
			var option = new Element('option', {value:'0'}).update("Nee");
			select.insert(option);
			if (this['showTitle'] == ''||this['showTitle'] == '0') option.selected = true;

			var option = new Element('option', {value:'1'}).update("Ja");
			select.insert(option);
			if (this['showTitle'] == '1') option.selected = true;


			div.insert('<br/>');
			
			var text = new Element('textarea', {id:this.instID + "_description", className:'activityInput'}).update(unescape(this.description));
			div.insert(new Element('span', {className:'activityTitle'}).update(this.descriptionOfMailingText));
			div.insert(text);
			
			div.insert('<br/>');

			var input = new Element('input', {type:'text', id:this.instID + '_senderName', className:'activityInput', value:this.senderName});
			div.insert(new Element('span', {className:'activityTitle'}).update("Afzender naam : "));
			div.insert(input);

			div.insert('<br/>');
			
			var input = new Element('input', {type:'text', id:this.instID + '_senderEmail', className:'activityInput', value:this.senderEmail});
			div.insert(new Element('span', {className:'activityTitle'}).update("Afzender adres : "));
			div.insert(input);
			div.insert('<div class="extraText"><span style="color:red;">Let op</span>: Indien u een Testbericht wil sturen, dan vult u hier het mailadres in van diegene waar het naar toe moet.</div>');
			div.insert('<br/>');

			var input = new Element('input', {type:'text', id:this.instID + '_subject', className:'activityInput', value:this.subject});
			div.insert(new Element('span', {className:'activityTitle'}).update("Email onderwerp : "));
			div.insert(input);
			
			div.insert('<br/>');
			
			
			var input = new Element('input', {type:'file', id:this.instID + '_titleFile', 'name':this.instID + '_titleFile', className:'activityInput'});
			div.insert(new Element('span', {className:'activityTitle'}).update("Afbeelding titel : "));
			div.insert(input);
		
			
			var defaultHTML = '<div class="extraText">Let op: JPG-Afbeeldingen van maximaal 300 x 300 pixels in formaat en niet groter dan 512Kb.</div>';
			if (this['hasImageOnTitle'] == 'true'){
				div.insert('<div class="extraText" id="extraText">U heeft reeds <a target="_blank" href="http://' + window.location.hostname +'/images/users/nieuwsbrief_title_images/'+this.id+'.jpg">deze afbeelding</a> geupload. <a href="http://' + window.location.hostname +'/include/removeNieuwsbriefTitleImage.php?mailingID='+this.id+'" target="'+this.instID+'uploadIFrame" onclick="$(\'extraText\').update(\'\')" >[afbeelding verwijderen]</a>');
				div.insert('<br/>Door een andere afbeelding te uploaden zult u de bestaande afbeelding overschrijven. <br/>Let op: JPG-Afbeeldingen van maximaal 300 x 300 pixels in formaat en niet groter dan 512Kb.</div>')
			}else{
				div.insert(defaultHTML)
			}
			input.observe('change', (function(e){
				var elem = e.element();
				var filename = elem.getValue();
				filename = filename.toLowerCase();
				var ext = filename.substring( filename.length-4, filename.length);
				if (ext != '.jpg' && ext != 'jpeg'){
					alert("Alleen bestanden van het type JPG zijn toegestaan");
					elem.value = '';
				}
			}).bindAsEventListener(this) )

			div.insert('<br/>');
			
			var select = new Element('select', {id:this.instID + '_titleImageAlign', className:'activityInput'});
			div.insert(new Element('span', {className:'activityTitle'}).update("Plaatsing titel-afbeelding : "));
			div.insert(select);
			
			var option = new Element('option', {value:'right'}).update("");
			select.insert(option);
			if (this['titleImageAlign'] == '') option.selected = true;

			var option = new Element('option', {value:'left'}).update("Links uitgelijnd");
			select.insert(option);
			if (this['titleImageAlign'] == 'left') option.selected = true;

			var option = new Element('option', {value:'right'}).update("Rechts uitgelijnd");
			select.insert(option);
			if (this['titleImageAlign'] == 'right') option.selected = true;			
			
		},		

		getMessageProperties : function(container, index){
			var aValue = this['title' + index];
			if (!aValue || aValue == 'undefined') aValue = '';

			var tmpContainer = new Element('div', {className:'messageProperties'});
			container.insert(tmpContainer);

			var row = new Element('div', {className:'messagePropertiesRow url'})
			tmpContainer.insert(row);
			var title = new Element('div', {className:'fieldTitle'}).update('URL van html-document:');
			row.insert(title);
			var input = new Element('input', {type:'text', id:this.instID + '_mailingURL'+index, className:'activityInput', value:this['url'+index]});
			row.insert(input);
			input.observe('change', (function(){
				if ($(this.instID + '_mailingURL'+index).getValue() !=''){
					$$('.mceEditor')[0].hide(); 
					$$('.messagePropertiesRow').each(
						function(elem){
							if (!elem.hasClassName('url')) elem.hide();
						}
					);
				}else{
					$$('.templateSelect').each( 
							function(e){
								e.disabled = false;
							} 
					)
					$$('.mceEditor')[0].show();
					$$('.messagePropertiesRow').each(
						function(elem){
							if (!elem.hasClassName('url')) elem.show();
						}
					);
				}
			}).bind(this));
			
			var row = new Element('div', {className:'messagePropertiesRow'})
			tmpContainer.insert(row);
			var title = new Element('div', {style:"font-weight:bold;"}).update('Of vul hieronder de teksten van de mailing in:');
			row.insert(title);
			row.insert('<br style="clear:both;"/>');
			
			var row = new Element('div', {className:'messagePropertiesRow'})
			tmpContainer.insert(row);
			var title = new Element('div', {className:'fieldTitle'}).update('Titel deel ' +index+':');
			row.insert(title);
			var input = new Element('input', {type:'text', id:this.instID + '_mailingTitle'+index, className:'activityInput', value:aValue});
			row.insert(input);

			var row = new Element('div', {className:'messagePropertiesRow'})
			tmpContainer.insert(row);

			var title = new Element('div', {className:'fieldTitle'}).update('Afbeelding deel ' +index+':');
			row.insert(title);
			
			var input = new Element('input', {type:'file', id:this.instID + '_hidden'+index, 'name':this.instID + '_hidden'+index, className:'activityInput'});
			row.insert(input);
			
			var defaultHTML = '<div class="extraText">Let op: JPG-Afbeeldingen van maximaal 300 x 300 pixels in formaat en niet groter dan 512Kb.</div>';
			if (this['hasImageOnIndex' + index] == 'true'){
				row.insert('<div class="extraText" id="extraText'+index+'">U heeft reeds <a target="_blank" href="http://' + window.location.hostname +'/images/users/nieuwsbrief_images/'+this.id+'/'+index+'.jpg">deze afbeelding</a> geupload. <a href="http://' + window.location.hostname +'/include/removeNieuwsbriefImage.php?mailingID='+this.id+'&index='+index+'" target="'+this.instID+'uploadIFrame" onclick="$(\'extraText'+index +'\').update(\'\')" >[afbeelding verwijderen]</a>');
				row.insert('<br/>Door een andere afbeelding te uploaden zult u de bestaande afbeelding overschrijven. <br/>Let op: JPG-Afbeeldingen van maximaal 300 x 300 pixels in formaat en niet groter dan 512Kb.</div>')
			}else{
				row.insert(defaultHTML)
			}
			input.observe('change', (function(e){
				var elem = e.element();
				var filename = elem.getValue();
				filename = filename.toLowerCase();
				var ext = filename.substring( filename.length-4, filename.length);
				if (ext != '.jpg' && ext != 'jpeg'){
					alert("Alleen bestanden van het type JPG zijn toegestaan");
					elem.value = '';
				}
			}).bindAsEventListener(this) )


			var row = new Element('div', {className:'messagePropertiesRow'})
			tmpContainer.insert(row);
			var title = new Element('div', {className:'fieldTitle'}).update('Plaatsing afbeelding deel ' +index+':');
			row.insert(title);
			var select = new Element('select', {id:this.instID + '_imageAlign'+index, className:'activityInput'});
			row.insert(select);
			
			var option = new Element('option', {value:'right'}).update("");
			select.insert(option);
			if (this['imageAlign'+index] == '') option.selected = true;

			var option = new Element('option', {value:'left'}).update("Links uitgelijnd");
			select.insert(option);
			if (this['imageAlign'+index] == 'left') option.selected = true;

			var option = new Element('option', {value:'right'}).update("Rechts uitgelijnd");
			select.insert(option);
			if (this['imageAlign'+index] == 'right') option.selected = true;
			
			if ($(this.instID + '_mailingURL'+index).getValue() !=''){
				$$('.messagePropertiesRow').each(
					function(elem){
						if (!elem.hasClassName('url')) elem.hide();
					}
				);
			}			
		}
	})
