/* News verschicken*/
var recommendForm;
var aVals;

function doRecommend(pk,dr){
	nCid = getVarFromUrlScope('cid');
	
	cVals = new Ext.data.JsonStore({
		url: '/index.cfm?event=recommend.show&cid='+ nCid +'&rec_pk=' + pk + '&rec_dr=' + dr,
		autoLoad: true,
		root: 'data',
		totalProperty: 'totalcount',
		fields: ['pk','title','description','name','email'],
		listeners: {
			load: showRecommendPopup
		}});
}


function recommendContent(){
	
	var myProfileGeneralLabelStyle = 'width:210px;';


	if(bFieldsDisabled == 0){	
		recommendForm = new Ext.FormPanel({
			renderTo: 'recommend_div',
	 		id: 'frm_recommend',
	 		frame:true,
	 		autoWidth: true,
	 		labelWidth: 198,

			url: '/index.cfm?event=ajax.showarticle.recommendation.send',
			items: [
			
				{
					xtype: 'hidden',
					id: 'rec_pk',
					value: aVals.pk
				},
				{
					xtype: 'hidden',
					id: 'cid',
					value: aLocation["cid"]
				},
				{
					xtype: 'hidden',
					id: 'rec_dr',
					value: aVals.dr
				},
				{
					xtype: 'hidden',
					id: 'rec_month',
					value: aVals.month
				},
				{
					xtype: 'hidden',
					id: 'rec_year',
					value: aVals.year
				},
				{
					xtype: 'hidden',
					id: 'rec_p',
					value: aVals.p
				},
				{
					xtype: 'hidden',
					id: 'dspevent',
					value: aVals.dspevent
				},
				{
					xtype: 'hidden',
					id: 'lastevent',
					value: aLocation['lastevent']
				},
				
				{
					width: 608,
					layout: 'form',
					border: false,
					items: [{
						html: '<h2>' + getLanguageText('recommendation.form.header_'+ aVals['typename']) + '</h2>',
						style: 'color:#999999;'				
					}]
				},

				{
					width: 608,
					layout: 'form',
					border: false,
					items: [{
						html: '<strong>'+ aVals.title +'</strong>',
						style: 'color:#333333;font-family:Arial,Helvetica,sans-serif;font-size:12px;line-height:17px;padding-bottom:16px;'				
					}]
				},

				
				{
					xtype: 'textfield',
					fieldLabel: getLanguageText('recommendation.form.email.label') + '*',
					labelSeparator: '',
					id: 'email',
					vtype: 'email',
					width: 333,
					validationEvent: 'blur',
					value: aVals.email,
					labelStyle: 'width:210px;',
					ctCls: 'cb pad0',
					allowBlank: false,
					msgTarget: 'under',
					blankText: getLanguageText('recommendation.form.email.error')
									
				},

				
				{
					xtype: 'textfield',
					fieldLabel: getLanguageText('recommendation.form.names.label') + '*',
					labelSeparator: '',
					id: 'name',
					width: 333,
					value: aVals.name,
					labelStyle: 'width:210px;',
					ctCls: 'cb pad0',
					allowBlank: false,
					msgTarget: 'under',
					blankText: getLanguageText('recommendation.form.names.error')
					
				},
				
	
				
			
				{
					xtype: 'textfield',
					fieldLabel: getLanguageText('recommendation.form.emailto.label') + '*',
					labelSeparator: '',
					id: 'emailto',
					vtype: 'email',
					width: 333,
					validationEvent: 'blur',
					
					labelStyle: 'width:210px;',
					ctCls: 'cb pad0',
					allowBlank: false,
					msgTarget: 'under',
					blankText: getLanguageText('recommendation.form.emailto.error')
									
				},
				

				
				{
					xtype: 'textarea',
					fieldLabel: getLanguageText('recommendation.form.message.label') + '*',
					labelSeparator: '',
					id: 'message',
					width: 608,
					height: 100,
					labelStyle: 'width:210px;',
					ctCls: 'cb pad0',
					allowBlank: false,
					msgTarget: 'under',
					blankText: getLanguageText('recommendation.form.message.error')
	
				},
				

	
		
				{
	 			xtype: 'hidden',
	 			id: 'captchacheckstring',
	 			value: ''
		 		}
				

				
				,{
					width: 306,
					layout: 'form',
					border: false,
					items: [{
						html: '<span><span class="fll">' + getLanguageText('recommendation.form.securitycode') + '</span> <span class="flr"><a href="javascript:void(0);" onclick="Ext.getCmp(\'captchaimg\').fireEvent(\'render\',Ext.getCmp(\'captchaimg\'))">' + getLanguageText('recommendation.form.getsecuritycode') + '</a></span></span>',
						style: 'font-size: 12px;margin-right: 5px;'
					}]
				},{
					xtype: 'panel',
					id: 'captchaimg',				
		        	listeners: {
		        		render: function(pThis){
							if(!(aVals['pkglobalusers'] > 0)) {
								
			        			Ext.Ajax.request({
			        				url: '/index.cfm?event=ajax.getContactFormCaptcha&random=' + Math.random(),
			        				success: function(pR,pO){
			        					var cData = Ext.decode(pR.responseText);
			        					var cTpl = new Ext.XTemplate(
			        						'<img src="/captchaimages/{img}" width="302" height="50" border="0" alt="Captcha" style="margin-bottom:14px;" />'
			        					);
			        					cTpl.overwrite(pThis.body,cData);							
			        					Ext.getCmp('captchacheckstring').setValue(cData.captchacheckstring);
			        				}					
			        			});	
							}
		        		}
		        	}
				},
				
				{
		 			xtype: 'textfield',
		 			style: 'margin-top:5px;',
		 			fieldLabel: getLanguageText('recommendation.form.insertcode'),
		 			labelSeparator: '',
		 			id: 'verificoderepeat',
		 			width: 333,
		 			labelStyle: 'width:210px;',
					ctCls: 'cb pad0',
		 			allowBlank: false,
		 			msgTarget: 'under',
		 			blankText: getLanguageText('recommendation.form.captcha.error')
		 		},
			
		 		
				{
					
					layout: 'form',
					border: false,
					items: [{
						html: '<div class="line_dotted mt16"><!--leer--></div>'
		            		+ '<span class="fll small mt10">' + getLanguageText('recommendation.form.mandatoryfield')+ '</span><div align="right" class="pt8 flr ma-buttonbox clearfix">'
							+ '	<a class="ma-button v1 wrp form-a" href="#" onclick="recommendForm.doAbort(); return false;"><span class="size">'+getLanguageText('defaults.cancel')+'</span></a>  '
							+ '	<a  class="ma-button v1 form-b" href="#" onclick="recommendForm.doSubmit(); return false;"><span class="size">'+getLanguageText('defaults.send')+'</span></a> '
							+ '</div>',
						style: 'font-size: 12px;margin-right: 5px;'				
					}]						
				}
 		
			
			],
		
			key: {
				key: [10, 13],
				fn: function(){
					recommendForm.doSubmit();
				}
			},
			// Submit:
			doSubmit: function(){
				if (recommendForm.validate()) {
					recommendForm.getForm().submit({
						
							success: function (pForm, pAction){
								if(pAction){
									recommendForm.getForm().reset();
									Ext.MessageBox.alert("Gut zu wissen!",aVals['success_text'],function(){recommendForm.doAbort();});								
								}else{
									Ext.MessageBox.alert('Fehler','Fehler beim Verschicken!');
								} 
							},
							failure: function(pForm, pAction){
								if(pAction.result){
									if(pAction.result.successnumber == 1){
										Ext.MessageBox.alert('Fehler','Fehler beim Verschicken!'+'<br>'+'Bitte korrekten Sicherheitscode eingeben!');
									}
									
									if(pAction.result.successnumber == 2){
										Ext.MessageBox.alert('Fehler','Fehler beim Verschicken!'+'<br>'+'');
									}
								}else{
									Ext.MessageBox.alert('Fehler','Fehler beim Verschicken!'+'<br>'+ unescape("Bitte alle Pflichtfelder ausf%FCllen%21"));
								}
							}						
						}
					);
				}
			},
			// Abort:
			doAbort: function(){
				//recommendForm.getForm().reset();
				//fpRecommendDataFormPopup.close();
				
				if(aLocation['lastevent'] == 'showarticle'){
					//lastevent gibts bei ct nicht! 
					window.location.href = '/index.cfm?event='+ aLocation['lastevent'] + '&cid=' + aLocation['cid'] + '&pk=' + aVals.pk;
					//jetzt scho! window.location.href = '/index.cfm?cid=' + aLocation['cid'] + '&pk=' + aVals.pk;
				}
				else if(aLocation['lastevent'] == 'shownews'){
	        			window.location.href = '/index.cfm?cid=' + aLocation['cid'] + '&pk=' + aVals.pk;
				}
				else if(aVals.dspevent == 'bloglist'){
					window.location.href = '/index.cfm?event='+ aLocation['lastevent'] + '&cid=' + aLocation['cid'] + '&month=' + aVals.month + '&year=' + aVals.year + '&p=' + aVals.p;
				}
				else if(aVals.dspevent == 'joblist'){
					window.location.href = '/';					
				}else{
					window.location.href = '/index.cfm?event='+ aLocation['lastevent'] + '&cid=' + aLocation['cid'] + '&pk=' + aVals.pk + '&month=' + aVals.month + '&year=' + aVals.year + '&p=' + aVals.p;
				}

			},
			
			
			// Validierung:
			validate: function(){
				return true;
			},
			showError: function(fieldName, Msg){
				Ext.MessageBox.alert('Fehler', Msg, function(){
					contactForm.getForm().findField(fieldName).focus();
				});
			}	

			})
		
	}else{
		
		recommendForm = new Ext.FormPanel({
			renderTo: 'recommend_div',
	 		id: 'frm_recommend',
			frame:true,
	 		autoWidth: true,
	 		labelWidth: 198,
			/*
			renderTo: 'recommend_div',
			defaults: {width: 530 },       
		    labelWidth: 225,
		    layoutConfig: {labelSeparator: ''},
			bodyStyle:'background-color:transparent;border:0px none;',
			style: 'margin-top: 10px;',			
					
			id: 'frm_recommend',	
			*/
			url: '/index.cfm?event=ajax.showarticle.recommendation.send',
			items: [
			
					
					{
						xtype: 'hidden',
						id: 'rec_pk',
						value: aVals.pk
					},
					{
						xtype: 'hidden',
						id: 'cid',
						value: aLocation["cid"]
					},
					{
						xtype: 'hidden',
						id: 'rec_dr',
						value: aVals.dr
					},
					{
						xtype: 'hidden',
						id: 'rec_month',
						value: aVals.month
					},
					{
						xtype: 'hidden',
						id: 'rec_year',
						value: aVals.year
					},
					{
						xtype: 'hidden',
						id: 'rec_p',
						value: aVals.p
					},
					{
						xtype: 'hidden',
						id: 'dspevent',
						value: aVals.dspevent
					},
					{
						xtype: 'hidden',
						id: 'lastevent',
						value: aLocation['lastevent']
					},
					
					{
						width: 608,
						layout: 'form',
						border: false,
						items: [{
							html: '<h2>' + getLanguageText('recommendation.form.header_'+ aVals['typename']) + '</h2>',
							style: 'color:#999999;'				
						}]
					},

					{
						width: 608,
						layout: 'form',
						border: false,
						items: [{
							html: '<strong>'+ aVals.title +'</strong>',
							style: 'color:#333333;font-family:Arial,Helvetica,sans-serif;font-size:12px;line-height:17px;padding-bottom:16px;'				
						}]
					},

					
					{
						xtype: 'textfield',
						fieldLabel: getLanguageText('recommendation.form.email.label') + '*',
						labelSeparator: '',
						id: 'email',
						vtype: 'email',
						width: 333,
						validationEvent: 'blur',
						value: aVals.email,
						labelStyle: 'width:210px;',
						ctCls: 'cb pad0',
						allowBlank: false,
						msgTarget: 'under',
						blankText: getLanguageText('recommendation.form.email.error')
										
					},

					
					{
						xtype: 'textfield',
						fieldLabel: getLanguageText('recommendation.form.names.label') + '*',
						labelSeparator: '',
						id: 'name',
						width: 333,
						value: aVals.name,
						labelStyle: 'width:210px;',
						ctCls: 'cb pad0',
						allowBlank: false,
						msgTarget: 'under',
						blankText: getLanguageText('recommendation.form.names.error')
						
					},
					
		
					
				
					{
						xtype: 'textfield',
						fieldLabel: getLanguageText('recommendation.form.emailto.label') + '*',
						labelSeparator: '',
						id: 'emailto',
						vtype: 'email',
						width: 333,
						validationEvent: 'blur',
						
						labelStyle: 'width:210px;',
						ctCls: 'cb pad0',
						allowBlank: false,
						msgTarget: 'under',
						blankText: getLanguageText('recommendation.form.emailto.error')
										
					},
					

					
					{
						xtype: 'textarea',
						fieldLabel: getLanguageText('recommendation.form.message.label') + '*',
						labelSeparator: '',
						id: 'message',
						width: 608,
						height: 100,
						labelStyle: 'width:210px;',
						ctCls: 'cb pad0',
						allowBlank: false,
						msgTarget: 'under',
						blankText: getLanguageText('recommendation.form.message.error')
		
					},
					

		/*
			
					{
		 			xtype: 'hidden',
		 			id: 'captchacheckstring',
		 			value: ''
			 		}
					

					
					,{
						width: 306,
						layout: 'form',
						border: false,
						items: [{
							html: '<span><span class="fll">' + getLanguageText('recommendation.form.securitycode') + '</span> <span class="flr"><a href="javascript:void(0);" onclick="Ext.getCmp(\'captchaimg\').fireEvent(\'render\',Ext.getCmp(\'captchaimg\'))">' + getLanguageText('recommendation.form.getsecuritycode') + '</a></span></span>',
							style: 'font-size: 12px;margin-right: 5px;'
						}]
					},{
						xtype: 'panel',
						id: 'captchaimg',				
			        	listeners: {
			        		render: function(pThis){
								if(!(aVals['pkglobalusers'] > 0)) {
									
				        			Ext.Ajax.request({
				        				url: '/index.cfm?event=ajax.getContactFormCaptcha&random=' + Math.random(),
				        				success: function(pR,pO){
				        					var cData = Ext.decode(pR.responseText);
				        					var cTpl = new Ext.XTemplate(
				        						'<img src="/captchaimages/{img}" width="302" height="50" border="0" alt="Captcha" style="margin-bottom:14px;" />'
				        					);
				        					cTpl.overwrite(pThis.body,cData);							
				        					Ext.getCmp('captchacheckstring').setValue(cData.captchacheckstring);
				        				}					
				        			});	
								}
			        		}
			        	}
					},
					
					{
			 			xtype: 'textfield',
			 			style: 'margin-top:5px;',
			 			fieldLabel: getLanguageText('recommendation.form.insertcode'),
			 			labelSeparator: '',
			 			id: 'verificoderepeat',
			 			width: 333,
			 			labelStyle: 'width:210px;',
						ctCls: 'cb pad0',
			 			allowBlank: false,
			 			msgTarget: 'under',
			 			blankText: getLanguageText('recommendation.form.captcha.error')
			 		},
				
			 	*/	
					{
						
						layout: 'form',
						border: false,
						items: [{
							html: '<div class="line_dotted mt16"><!--leer--></div>'
			            		+ '<span class="fll small mt10">' + getLanguageText('recommendation.form.mandatoryfield')+ '</span><div align="right" class="pt8 flr ma-buttonbox clearfix">'
								+ '	<a class="ma-button v1 wrp form-a" href="#" onclick="recommendForm.doAbort(); return false;"><span class="size">'+getLanguageText('defaults.cancel')+'</span></a>  '
								+ '	<a  class="ma-button v1 form-b" href="#" onclick="recommendForm.doSubmit(); return false;"><span class="size">'+getLanguageText('defaults.send')+'</span></a> '
								+ '</div>',
							style: 'font-size: 12px;margin-right: 5px;'				
						}]						
					}
			 	
			],
		
			key: {
				key: [10, 13],
				fn: function(){
					recommendForm.doSubmit();
				}
			},
			// Submit:
			doSubmit: function(){
				if (recommendForm.validate()) {
					recommendForm.getForm().submit({
						
							success: function (pForm, pAction){
								if(pAction){
									recommendForm.getForm().reset();
									Ext.MessageBox.alert("Gut zu wissen!",aVals['success_text'],function(){recommendForm.doAbort();});								
								}else{
									Ext.MessageBox.alert('Fehler','Fehler beim Verschicken!');
								} 
							},
							failure: function(pForm, pAction){
								if(pAction.result){
									if(pAction.result.successnumber == 1){
										Ext.MessageBox.alert('Fehler','Fehler beim Verschicken!'+'<br>'+'Bitte korrekten Sicherheitscode eingeben!');
									}
									
									if(pAction.result.successnumber == 2){
										Ext.MessageBox.alert('Fehler','Fehler beim Verschicken!'+'<br>'+'');
									}
								}else{
									Ext.MessageBox.alert('Fehler','Fehler beim Verschicken!'+'<br>'+ unescape("Bitte alle Pflichtfelder ausf%FCllen%21"));
								}
							}						
						}
					);
				}
			},
			// Abort:
			doAbort: function(){
				//recommendForm.getForm().reset();
				//fpRecommendDataFormPopup.close();

				if(aLocation['lastevent'] == 'showarticle'){
					//lastevent gibts bei ct nicht! 
					window.location.href = '/index.cfm?event='+ aLocation['lastevent'] + '&cid=' + aLocation['cid'] + '&pk=' + aVals.pk;
					//jetzt scho! window.location.href = '/index.cfm?cid=' + aLocation['cid'] + '&pk=' + aVals.pk;
				}
				else if(aLocation['lastevent'] == 'shownews'){
	        			window.location.href = '/index.cfm?cid=' + aLocation['cid'] + '&pk=' + aVals.pk;
				}
				else if(aVals.dspevent == 'bloglist'){
					window.location.href = '/index.cfm?event='+ aLocation['lastevent'] + '&cid=' + aLocation['cid'] + '&month=' + aVals.month + '&year=' + aVals.year + '&p=' + aVals.p;
				}
				else if(aVals.dspevent == 'joblist'){
					window.location.href = '/';					
				}else{
					window.location.href = '/index.cfm?event='+ aLocation['lastevent'] + '&cid=' + aLocation['cid'] + '&pk=' + aVals.pk + '&month=' + aVals.month + '&year=' + aVals.year + '&p=' + aVals.p;
				}
			},
			
			
			// Validierung:
			validate: function(){
				return true;
			},
			showError: function(fieldName, Msg){
				Ext.MessageBox.alert('Fehler', Msg, function(){
					recommendForm.getForm().findField(fieldName).focus();
				});
			}
			
			/* 
			 ,listeners: {
				render: function(pThis){
					dmy = pThis.getEl().child('.x-panel-btns');
					dmy.removeClass('x-panel-btns-center');
					dmy.addClass('x-panel-btns-right');
				}
			}
			*/
			})
	}
	
	
	
	
		
}
	
	
	
	
