/*
 * nbsp, WM | 2008-10-27 - Formular für Traveltalk-Kontakt-Seite CID = 60
 * 
 */

/*Ext.namespace('Ext.LotteryStore');*/
var lotteryForm;


function writeHiddenFieldUpload(){
	Ext.getCmp("uploadfilename").setValue(Ext.getCmp("uploadfile").getValue());
	return true;
}

 function doLotteryForm(){
 	
 
 /*****************************************************************/ 

/*
	var store = new Ext.data.SimpleStore({
        fields: ['PK', 'TITLE'],
        data : Ext.LotteryStore.subjects
    });
		
	var subject_combo = new Ext.form.ComboBox({
		width:333,
        store: store,
        typeAhead: true,
        mode: 'local',
		id: 'subjects',
		hiddenName: 'subject',
        forceSelection: true,
        triggerAction: 'all',
        emptyText:unescape('Bitte ausw%E4hlen'),
        selectOnFocus:true,        
		displayField:'TITLE',
		valueField:'PK',
		value: aVals['subject'],
		fieldLabel: '*'+'Betreff',
		labelSeparator: '', 		
 		labelStyle: 'width:210px;',
		ctCls: 'cb pad0',
		allowBlank: false,
		msgTarget: 'under',
		blankText: 'Pflichtfeld!'+' '+'Bitte Betreff angeben!'
		
		
    });
*/

	var UploadFileFieldHidden = new Ext.form.Hidden({
		name: 'uploadfilename',
		id: 'uploadfilename'
	});
	
	var UploadFileField = new Ext.form.TextField({
		name: 'uploadfile',
		id: 'uploadfile',
		allowBlank: true,
		inputType: 'file',
		hideLabel: true,
		cls: 'mb10',
		value: '',
		validator: writeHiddenFieldUpload,
		width: 300,
		listeners: {
			render: function() {
				Ext.getCmp('uploadfile').getEl().dom.setAttribute('size', 40);								
				Ext.getCmp('uploadfile').defaultAutoCreate.size = 40;				
				}
		}	
	});
		
		
		
 
  	lotteryForm = new Ext.FormPanel({
 		renderTo: 'lottery_div',
 		frame:true,
 		autoWidth: true,
 		labelWidth: 198,		
		/*url: 'master/custom/website/views/ajax/lottery/saveLottery.cfm',*/
		url: '/index.cfm?event=ajax.lottery.send',
 		items: [
		
		{
 			xtype: 'hidden',
 			id: 'lottery_id',
 			value: aVals['lottery_id']
 		},
		{
 			xtype: 'hidden',
 			id: 'lottery_fk',
 			value: aVals['lottery_fk']
 		},
		
		{
			width: 608,
			layout: 'form',
			border: false,
			items: [{
				html: '<h2>' + aVals['title'] + '</h2>',
				style: 'color:#999999;'				
			}]
		},
		{
			width: 608,
			layout: 'form',
			border: false,
			items: [{
				html: '<strong>' + aVals['description'] + '</strong>',
				style: 'color:#333333;font-family:Arial,Helvetica,sans-serif;font-size:12px;line-height:17px;'
				/*style: 'font-size: 12px;margin-right: 5px;'*/
			}]
		},
		/*
		{
 			xtype: 'textfield',
 			fieldLabel: 'Nickname',
 			labelSeparator: '',
 			id: 'nickname', 			
 			width: 333,
			value: aVals['nickname'],
 			labelStyle: 'width:210px;',
			ctCls: 'cb pad0',
 			allowBlank: false,
 			msgTarget: 'under',
 			blankText: 'Pflichtfeld!'+' '+'Bitte Nickname eingeben"'
 		},*/
		{
 			layout:'column',
            border:false,
            cls: 'pb10',
            items:[
			{
                width: 260,
                layout: 'form',
                labelWidth: 198,
                border:false,
                items:[
				{
		 			xtype: 'textfield',
		 			fieldLabel: 'Vorname',
		 			labelSeparator: '',
		 			id: 'firstnamea',
		 			width: 230,
		 			disabled: true,
					value: aVals['firstname'],
		 			labelStyle: 'width:210px;',
					ctCls: 'cb pad0',
		 			allowBlank: false,
		 			msgTarget: 'under',
		 			blankText: 'Pflichtfeld!'+' '+'Bitte Namen eingeben!'
		 		},
		 		{
		 			xtype: 'hidden',		 			
		 			id: 'firstname',
		 			width: 260,		 			
					value: aVals['firstname']		 			
		 		}]
            },{
                width: 260,
                layout: 'form',
                labelWidth: 198,
                border:false,
                items:[
				{
		 			xtype: 'textfield',
		 			fieldLabel: 'Nachname',
		 			labelSeparator: '',
		 			id: 'lastnamea',
		 			width: 230,
		 			disabled: true,
					value: aVals['lastname'],
		 			labelStyle: 'width:210px;',
					ctCls: 'cb pad0',
		 			allowBlank: false,
		 			msgTarget: 'under',
		 			blankText: 'Pflichtfeld!'+' '+'Bitte Nachnamen eingeben!'
		 		},
		 		{
		 			xtype: 'hidden',		 			
		 			id: 'lastname',
		 			width: 260,		 			
					value: aVals['lastname']		 			
		 		}]
            }]
 		},
 		
		
		{
 			layout:'column',
            border:false,			
			items:[
			/*
			{
				width: 608,
				layout: 'form',
				border: false,
				items: [{
					html: unescape('Ihre Telefonnummer f%FCr R%FCckfragen'),
					style: ''				
				}]
			},
			*/
			{
                width: 270,
                layout: 'form',
                labelWidth: 220,
                border:false,
                items:[{
	                xtype: 'textfield',
		 			fieldLabel: '*'+ unescape('Deine Telefonnummer f%FCr R%FCckfragen'),
		 			labelSeparator: '',
		 			id: 'phone1',
		 			width: 38,
		 			labelStyle: 'width:220px;',					
		 			allowBlank: false,
		 			msgTarget: 'qtip',
		 			blankText: 'Pflichtfeld!'+' '+unescape('Bitte L%E4ndervorwahl eingeben%21'),
					value: '0049'
	 			}]
            },{
                width: 68,
                layout: 'form',
                border:false,
                labelWidth: 5,
                items:[{
	 				xtype: 'textfield',
		 			fieldLabel: '-',
		 			labelSeparator: '',
//		 			labelStyle: '',
		 			id: 'phone2',
		 			width: 50,
		 			allowBlank: false,
		 			msgTarget: 'qtip',
		 			blankText: 'Pflichtfeld!'+' '+'Bitte Vorwahl eingeben!'
 				}]
            },{
                width: 185,
                layout: 'form',
                border:false,
                labelWidth: 5,
                items:[{
	 				xtype: 'textfield',
		 			fieldLabel: '-',
		 			labelSeparator: '',
		 			id: 'phone3',
		 			width: 142,
		 			allowBlank: false,
		 			msgTarget: 'qtip',
		 			blankText: 'Pflichtfeld!'+' '+'Bitte Rufnummer eingeben!'
 				}]
            }]
 		},
				
		/*subject_combo,*/
		{
 			xtype: 'textfield',
 			//style: 'margin-top:5px;',
 			fieldLabel: 'Betreff',
 			labelSeparator: '',
 			id: 'subjecta',
 			width: 490,
 			disabled: true,
 			labelStyle: 'width:210px;',
			ctCls: 'cb pad0 mb10',
 			allowBlank: false,
 			msgTarget: 'under',
 			blankText: 'Pflichtfeld!'+' '+'Bitte Betreff eingeben!',
			value: aVals['title'],
			readOnly: true,
			cls: 'grey'
			
 		},
 		{
 			xtype: 'hidden',		 			
 			id: 'subject',
 			width: 260,		 			
 			value: aVals['title']		
 		},
		
		{
			width: 608,
			layout: 'form',
			border: false,
			items: [{
				html: unescape("Datei anh%E4ngen%21") + '<!--&nbsp;<img src="/img/folder_icon.png" onclick="Ext.getCmp(\'fileupload\').show()"/>-->',
				style: 'color:#333333;font-family:Arial,Helvetica,sans-serif;font-size:12px;line-height:17px;'
				/*style: 'font-size: 12px;margin-right: 5px;'*/
			}]
		},
		
		
		/*UploadFileField, UploadFileFieldHidden,*/
		
		{
			width: 608,			
			layout: 'form',
			id: 'fileupload',
			/*style: 'display:none;',*/
			hidden: false,
			border: false,
			items: [
				UploadFileField, 
				UploadFileFieldHidden
			]
		},	
		
		{
 			xtype: 'textarea',
 			fieldLabel: 'Deine Nachricht (optional)',
 			labelSeparator: '',
 			id: 'message',
 			width: 608,
 			height: 100,
 			labelStyle: 'width:270px;',
			ctCls: 'cb pad0',
 			allowBlank: true,
 			msgTarget: 'under',
 			blankText: 'Pflichtfeld!'+' '+'Bitte Nachricht eingeben!'/*,
 			maxLength: 500*/
 		},
/*				
		{
			width: 608,
			layout: 'form',
			border: false,
			items: [{
				html: '<strong>Hinweis:</strong> ' + unescape("Sie erhalten automatisch eine Kopie Ihrer Anfrage per E-Mail. Wie sind bem%FCht%2C schnellstm%F6glich zu antworten. Ihre TravelTalk Redaktion."),
				style: 'color:#333333;font-family:Arial,Helvetica,sans-serif;font-size:12px;line-height:17px;margin-bottom:20px;'
			}]
		},
*/
		/*{
 			xtype: 'hidden',
 			id: 'captchacheckstring',
 			value: ''
 		}
		
		,{
			width: 306,
			layout: 'form',
			border: false,
			items: [{
				html: '<span class="fll">*' + 'Sicherheitscode</span> <span class="flr"><a href="javascript:void(0);" onclick="Ext.getCmp(\'captchaimg\').fireEvent(\'render\',Ext.getCmp(\'captchaimg\'))">Neuen Code anfordern</a></span>',
				style: 'font-size: 12px;margin-right: 5px;'
			}]
		},{
			xtype: 'panel',
			id: 'captchaimg',				
        	listeners: {
        		render: function(pThis){
        			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: '*'+'Bitte tragen Sie hier den Code ein!',
 			labelSeparator: '',
 			id: 'verificoderepeat',
 			width: 333,
 			labelStyle: 'width:210px;',
			ctCls: 'cb pad0',
 			allowBlank: false,
 			msgTarget: 'under',
 			blankText: 'Pflichtfeld!'+' '+'Bitte Sicherheits-Code eingeben!'
 		},*/
		
		{
			/*width: 214,*/
			layout: 'form',
			border: false,
			items: [{
				html: '<div class="line_dotted mt16"><!--leer--></div>' +
				'<div class="fll mt5">* Pflichtfelder</div>' +
				'<div class="mt10 flr">' +
				'	<a class="mr10" href="#" onclick="lotteryForm.doAbort(); return false;"><img alt="Abbrechen" onmouseout="src=\'/img/buttons/btn_abbrechen_01_77x21.gif\'" onmouseover="src=\'/img/buttons/btn_abbrechen_02_77x21.gif\'" src="/img/buttons/btn_abbrechen_01_77x21.gif"/></a>' +
				'	<a href="#" onclick="lotteryForm.doSubmit(); return false;"><img alt="Absenden" onmouseout="src=\'/img/buttons/btn_abschicken_01_80x21.gif\'" onmouseover="src=\'/img/buttons/btn_abschicken_02_80x21.gif\'" src="/img/buttons/btn_abschicken_01_80x21.gif"/></a>' +
				'</div>',
				style: 'font-size: 12px;margin-right: 5px;'
			}]
		}	
		
		
		],
		/*
 		buttons: [{
			text: 'Abbrechen'			
		},{
			text: 'Speichern',
			handler: function(){
				lotteryForm.doSubmit();
			}
		}],
		*/
		key: {
			key: [10, 13],
			fn: function(){
				lotteryForm.doSubmit();
			}
		},
		// Submit:
		doSubmit: function(){
			if (lotteryForm.validate()) {
				lotteryForm.getForm().submit({
						success: function (pForm, pAction){
							if(pAction){
								Ext.MessageBox.alert("Hinweis",aVals['success_text'],function(){lotteryForm.doAfterSucces();});
							}else{
								Ext.MessageBox.alert('Fehler','Fehler beim Speichern!');
							} 
						},
						failure: function(pForm, pAction){
							if(pAction.result){
								if(pAction.result.successnumber == 1){
									Ext.MessageBox.alert('Fehler','Fehler beim Speichern!'+'<br>'+'Bitte geben Sie den richtigen Sicherheitscode ein!');
								}
								
								if(pAction.result.successnumber == 2){
									Ext.MessageBox.alert('Fehler','Fehler beim Speichern!'+'<br>'+'Fehler beim versenden des Formulars!<br>'+unescape("Bitte versuchen Sie es sp%E4ter noch einmal%21"));
								}
								
								if(pAction.result.successnumber == 3){
									Ext.MessageBox.alert('Fehler','Fehler beim Speichern!'+'<br>'+ pAction.result.msg);
								}
							}else{
								Ext.MessageBox.alert('Fehler',unescape("F%FClle bitte alle Pflichtfelder aus%21"));
							}
						}
					}
				);
			}
		},
		
		// Abort:
		doAbort: function(){
			window.location.href = aVals['backlink_abort'];
		},
		doAfterSucces: function(){
			window.location.href = aVals['backlink_ok'];
		},
		
		// Validierung:
		validate: function(){
			return true;
		},
		showError: function(fieldName, Msg){
			Ext.MessageBox.alert('Fehler', Msg, function(){
				lotteryForm.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');
			}
		}
		*/
		,fileUpload: true
		
		
 	})
 }