var pisrendered=false;
var simple = new Ext.form.Form({
        labelAlign: 'top',
        waitMsgTarget:true
    });
    simple.add(
        new Ext.form.TextField({
            fieldLabel: 'Benutzername oder E-Mail',
            name: 'un' ,
            allowBlank:false,
            blankText:'Pflichtfeld',
            width:"200",
            listeners:{
				'specialkey':specialKey,
				scope:this
			}
        }),

        new Ext.form.TextField({
            fieldLabel: 'Passwort',
            name: 'pa',
            inputType:'password',
            allowBlank:false ,
            blankText:'Pflichtfeld',
            width:"200",
            listeners:{
				'specialkey':specialKey,
				scope:this
			}
        }) ,
        new Ext.form.Checkbox({
            fieldLabel:"Eingeloggt bleiben",
            boxLabel: 'Login auf diesem Computer merken',
            name: 'staylogged',
            checked:'checked'
        })
    );


    function specialKey( field, e ) {
        if ( e.getKey() == e.RETURN || e.getKey() == e.ENTER ) {
        	simple.submit({url:'/dologin.php', waitMsg:'Bitte warten'})
        }
    }

    simple.addButton({
        text: 'Login',
        handler: function(){
            simple.submit({url:'/dologin.php', waitMsg:'Bitte warten'});
        }
    });

     simple.on("actioncomplete", function(form,action) {
        window.location.replace(action.result.redir);
     });
     simple.on("actionfailed", function(form,action) {
        Ext.MessageBox.alert("Fehler", action.result.errorMessage);
        simple.reset();
     });



    var reg = new Ext.form.Form({
        labelAlign: 'top',
        waitMsgTarget:true
    });

    var rds = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '/livesearch.php?ct=city'
        }),
        reader: new Ext.data.XmlReader({
            totalRecords: 'results',
            record: 'row'
        }, [
            {name: 'name'},
            {name: 'zusatz'},
            {name: 'id'}
        ])
    });

     // Custom rendering Template
    var rresultTpl = new Ext.Template(
        '<div class="livesearch-item">',
            '<p><b>{name}</b> {zusatz}',
        '</div>'
    );


    reg.add(
        new Ext.form.TextField({
            fieldLabel: 'Gewünschter Benutzername',
            name: 'un' ,
            minLength:3,
            maxLength:64,
            allowBlank:false,
            blankText:'Pflichtfeld',
            width:"200"
        }),
        new Ext.form.TextField({
            fieldLabel: 'E-Mail',
            name: 'email' ,
            vtype:'email',
            allowBlank:false,
            blankText:'Pflichtfeld',
            invalidText:'Bitte eine korrekte E-Mail-Adresse eingeben' ,
            width:"200"
        }),

        new Ext.form.TextField({
            fieldLabel: 'Passwort',
            name: 'pa',
            minLength:5,
            maxLength:24,
            inputType:'password',
            allowBlank:false ,
            width:"200"
        }),
        new Ext.form.TextField({
            fieldLabel: 'Passwort wiederholen',
            name: 'pa_wdh',
            minLength:5,
            maxLength:24,
            inputType:'password',
            allowBlank:false ,
            blankText:'Pflichtfeld',
            width:"200"
        }),
        new Ext.form.TextField({
            fieldLabel: 'Deine PLZ',
            name: 'plz',
            minLength:4,
            maxLength:5,
            allowBlank:false ,
            blankText:'Pflichtfeld',
            width:"200"
        })

        /*
        new Ext.form.ComboBox({
        fieldLabel:"Deine Stadt",
        store: rds,
        queryDelay:200,
        displayField:'name',
        valueField:'id',
        typeAhead: false,
        minChars:3,
        loadingText: 'Suche...',
        width: 200,
        hiddenName:'id',
        allowBlank:false,
        pageSize:0,
        grow:true,
        forceSelection:true,
        hideTrigger:true,
        tpl: rresultTpl

        }),
        */

    );
    reg.column({width:90, hideLabels: false},
    	new Ext.form.Radio({
            fieldLabel:'Geschlecht',
    		boxLabel: 'männlich',
    		inputValue: 'm',
    		name: 'sex',
    		checked: false
    	})
    );
    reg.column({width:120, hideLabels: false},
    	new Ext.form.Radio({
    		boxLabel: 'weiblich',
            labelSeparator:'',
    		inputValue: 'f',
    		name: 'sex',
    		checked: false
    	})
    );
    reg.end();

   
    reg.addButton({
        text: 'Jetzt registrieren!',
        handler: function(){
            reg.submit({url:'/doregister.php', waitMsg:'Bitte warten',params:{validcheck:"1"}});
        }
    });

     reg.on("actioncomplete", function(form,action) {
        Ext.MessageBox.alert("Vielen Dank", action.result.msg);
        reg.reset();
     });
     reg.on("actionfailed", function(form,action) {
        if (action.result.errorMessage!=null) Ext.MessageBox.alert("Fehler", action.result.errorMessage);
        //document.getElementById('cityId').value= action.result.cityId;
        //document.getElementById('cityname').value= action.result.cityname;
     });



    var pwd = new Ext.form.Form({
        labelAlign: 'top',
        waitMsgTarget:true
    });
    pwd.add(
        new Ext.form.TextField({
            fieldLabel: 'E-Mail',
            name: 'email' ,
            allowBlank:false,
            width:"200"
        })
    );

    pwd.addButton({
        text: 'Zugangsdaten anfordern',
        handler: function(){
            pwd.submit({url:'/dolostpwd.php', waitMsg:'Bitte warten'});
        }
    });

     pwd.on("actioncomplete", function(form,action) {
        Ext.MessageBox.alert("Zugangsdaten verschickt", action.result.msg);

     });
     pwd.on("actionfailed", function(form,action) {
        Ext.MessageBox.alert("Fehler", action.result.errorMessage);
        pwd.reset();
     });

 function srenderpwd() {
    if (pisrendered) return;
    pisrendered=true;

    pwd.render('lpwd');
 }


var additionalInit=function(){
    simple.render('lgin');
    if (typeof(reg)!='undefined') reg.render('regst');
};

