/*
 * Ext JS Library 1.1.1
 * Copyright(c) 2006-2007, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://www.extjs.com/license
 */

Ext.onReady(function()
{
	
	var window_login = function()
	{
	    var dialog;
	    return {
	        init : function()
	        {
	             this.showDialog();
	        },
	       
	        showDialog : function(){
	            if(!dialog){ // lazy initialize the dialog and only create it once
	                dialog = new Ext.BasicDialog("hello-dlg", { 
	                        autoTabs:false,
	                        width:466,
	                        height:300,
	                        shadow:true,
	                        minWidth:300,
	                        minHeight:250,
	                        proxyDrag: false,
	                        closable: false,
	                        collapsible: false,
	                        draggable:false,
	                        resizable: false,
	                        autoScroll:false
	                });
	            }
	            dialog.show();
	        }
	    };
	}();
	window_login.init();

	var Tabs = 
	{
	    init : function()
	    {
	        // basic tabs 1, built from existing content
	        var tabs = new Ext.TabPanel('tabs1');
	        tabs.addTab('logintab', LOCALIZATION['connection']);
	        tabs.addTab('passtab', LOCALIZATION['lostpassword']);
	        tabs.addTab('notetab', LOCALIZATION['note']);
	        tabs.activate('logintab');
	    
    	}
	}

	Tabs.init();
	
    Ext.QuickTips.init();

    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';

    var login = new Ext.form.Form({
        labelWidth: 100, // label settings here cascade unless overridden
        url:'/onclick/onclick_ajax/login.ajax.php?action=login'
    });
    
    login.add(
        new Ext.form.TextField({
            fieldLabel: LOCALIZATION['username'],
            name: 'username',
            width:275,
            allowBlank:false,
            value:''
        }),

        new Ext.form.TextField({
            fieldLabel: LOCALIZATION['password'],
            name: 'password',
            inputType: 'password',
            width:275,
            allowBlank:false,
            value:''
        })

    );
	
    login.on('actioncomplete', function(fs, a){
    		Ext.Msg.hide();
    		top.main_app.load_module( 'sitechoser' );
    	}
    );
    
    login.on('actionfailed', function(fs, a){
    		Ext.Msg.hide();
    		Ext.Msg.alert(LOCALIZATION['message'], LOCALIZATION['incorectlogin'] );
    	}
    );
    
	
    login.addButton(
    		{
				icon:'/onclick/onclick_media/icons/server_go.png',
				text:LOCALIZATION['connection'],
				cls:"x-btn-text-icon"
			}

    		, function(){
    		if ( login.isValid() )
    		{
    			Ext.Msg.wait( LOCALIZATION['senddata'] + '...', LOCALIZATION['connection'] + '...');
    			login.submit();
    		}
    		else
    			Ext.Msg.alert(LOCALIZATION['message'], LOCALIZATION['emptyvalue'] );
    	}
    
    
    );
    
      login.addButton(
    		{
				icon:'/onclick/onclick_media/icons/delete.png',
				text:LOCALIZATION['cancel'],
				cls:"x-btn-text-icon"
			}

    		, function()
    		{
    			login.reset();
    		}
    
    
    );
    
    login.render('login');
    
    // Lost password
     var lost = new Ext.form.Form({
        labelWidth: 100, // label settings here cascade unless overridden
        url:'/onclick/onclick_ajax/login.ajax.php?action=lost'
    });
    
    lost.add(
        new Ext.form.TextField({
            fieldLabel: LOCALIZATION['email'],
            name: 'email',
            width:275,
            allowBlank:false,
            vtype:'email'
        })
    );
	
    lost.on('actioncomplete', function(fs, a){
    		Ext.Msg.hide();
    		if( typeof( a.result.message ) != "undefined" )
    			Ext.Msg.alert(LOCALIZATION['message'], a.result.message );
    	}
    );
    
    lost.on('actionfailed', function(fs, a){
    		Ext.Msg.hide();
    		 
    		if( typeof( a.result.message ) != "undefined" )
    			Ext.Msg.alert( LOCALIZATION['message'] , a.result.message );
    		else
    			Ext.Msg.alert(LOCALIZATION['message'], LOCALIZATION['noemailaccountfound'] );
    	}
    );
    
	
    lost.addButton(
    	{
			icon:'/onclick/onclick_media/icons/server_go.png',
			text:LOCALIZATION['send'],
			cls:"x-btn-text-icon"
		}
    	, function(){
    		if ( lost.isValid() )
    		{
    			Ext.Msg.wait( LOCALIZATION['senddata'] + '...', LOCALIZATION['connection'] + '...');
    			lost.submit();
    		}
    		else
    			Ext.Msg.alert(LOCALIZATION['message'], LOCALIZATION['emptyvalue'] );
    	}
    );
    
        lost.addButton(
    		{
				icon:'/onclick/onclick_media/icons/delete.png',
				text:LOCALIZATION['cancel'],
				cls:"x-btn-text-icon"
			}

    		, function()
    		{
    			lost.reset();
    		}
    
    
    );
    lost.render('lost');

});