Ext.namespace('NGMP.dialog');

NGMP.dialog.SystemInitializationDialog = function(A) {
	
	this.progressBar = new Ext.ProgressBar({
		border:false,
		height:20,
		region:'south'
	});

	this.welcomePanel = new Ext.Panel({
		border:false,
		autoLoad:{
			url:'install.php?step=1',
			callback:function() {
				var installLanguage = Ext.get('installLanguage');
				if (installLanguage) {
					installLanguage.on('change', function(A,B) {
						Ext.Ajax.request({
							url:'ngmp.php',
							params:{
								func:'setLang',
								lang: installLanguage.getValue()
							},
							success:function(){
								document.location.reload();
							},
							scope:this
						});
					},this);
				}
			}
		},
		buttons:[{
			text:LANG_next2,
			handler: function() {
				this.progressBar.updateProgress(0.4, LANG_license_agreement);
				this.centerPanel.getLayout().setActiveItem(this.licensePanel);
				this.centerPanel.doLayout();
			},
			scope:this
		}]
	});

	this.licensePanel = new Ext.Panel({
		border:false,
		autoLoad:{
			url:'install.php?step=1.1'
		},
		buttons:[{
			text:LANG_no_i_disagree,
			handler:function() {
				this.close();
			},
			scope:this
		},{
			text:LANG_yes_i_have_read_and_agreed,
			handler: function() {
				this.progressBar.updateProgress(0.6, LANG_registration);
				this.centerPanel.getLayout().setActiveItem(this.registrationPanel);
				this.centerPanel.doLayout();
			},
			scope:this
		}]

	});


	this.btnUpload = new NGMP.form.BrowseButton({
		style:'margin-left:10px;',
		text:LANG_upload_license_file
	});

	this.formLicenseUpload = new Ext.FormPanel({
		border:false,	
		region:'south',
		fileUpload:true,
		enctype:'multipart/form-data',
		items:[this.btnUpload]
	});

	this.registrationIntroPanel = new Ext.Panel({
		border:false,
		region:'center',
		autoLoad:{
			url:'install.php?step=2'
		},
		height:400
	});

	this.registrationPanel = new Ext.Panel({
		buttonAlign:'right',
		layout:'border',
		border:false,
		items:[this.registrationIntroPanel,this.formLicenseUpload],
		buttons:[{
			text:LANG_next2,
			handler:function() {
				if (this.btnUpload.inputFileEl.dom.value) {
					this.formLicenseUpload.form.submit({
						url:'install.php?step=2&upload=true',
						method:'post',
						success:function(A,B) {
							this.progressBar.updateProgress(0.8, LANG_domain+' ' + LANG_initialization);
							this.centerPanel.getLayout().setActiveItem(this.domainInitPanel);
							this.centerPanel.doLayout();
						},
						failure:function(A,B) {
							Ext.Msg.alert('safasdf');
						},
						scope:this
					});
				} else {
					Ext.Msg.alert(LANG_alert,LANG_please_select_your_license_file);
				}
			},
			scope:this
		}]
	});

	this.domainIntroPanel = new Ext.Panel({
		border:false,
		region:'center',
		autoLoad:{
			url:'install.php?step=3'
		}
	});

	this.domainNameField = new Ext.form.TextField({
		fieldLabel:LANG_domain_name,
		name:'name',
		allowBlank:false,
		vtype:'domainname'
	});
	this.domainInitForm = new Ext.form.FormPanel({
		border:false,	
		region:'south',
		url:'install.php',
		baseParams:{
			step:'3'
		},
		items:[this.domainNameField]
	});

	this.domainInitPanel = new Ext.Panel({
		layout:'border',
		border:false,
		items:[this.domainIntroPanel, this.domainInitForm],
		buttons:[{
			text:LANG_next2,
			handler:function() {
				this.domainInitForm.form.submit({
					url:'install.php?step=3&save=true',
					method:'post',
					success:function() {
						this.progressBar.updateProgress(1, LANG_done);
						this.centerPanel.getLayout().setActiveItem(this.congratulationPanel);
						this.centerPanel.doLayout();
					},
					failure:function() {
					},
					scope:this
				});
			},
			scope:this
		}]
	});

	this.congratulationPanel = new Ext.Panel({
		border:false,	
		autoLoad:{
			url:'install.php?step=4'
		},
		buttons:[{
			text:LANG_done,
			handler:function() {
				Ext.Ajax.request({
					url:'install.php?step=4&save=true'
				});
				this.close();
			},
			scope:this
		}]
	});

	this.centerPanel = new Ext.Panel({
		region:'center',
		layout:'card',
		activeItem:0,
		items:[this.welcomePanel, this.licensePanel,this.registrationPanel, this.domainInitPanel, this.congratulationPanel]
	});
	NGMP.dialog.SystemInitializationDialog.superclass.constructor.call(this,{
		title:LANG_system_initialization,
		modal:true,
		layout:'border',
		minWidth:300,
		minHeight:300,
		height:590,
		width:570,
		border:false,
		items:[this.centerPanel,this.progressBar]
	});
};

Ext.extend(NGMP.dialog.SystemInitializationDialog, Ext.Window, {
	show:function() {
		NGMP.dialog.SystemInitializationDialog.superclass.show.call(this);
		this.progressBar.updateProgress(0.2, LANG_welcome);
	}
});

NGMP.dialog.LoginDialog = function(A) {
	Ext.apply(this, A);

	this.languageField = new Ext.form.ComboBox({
		fieldLabel:LANG_language,
		hiddenName:'lang',
		value:'',
		store: new NGMP.data.JsonStore({
			url:'ngmp.php',
			baseParams:{
				func:'getLanguages'
			},
			root:'results',
			id:'id',
			fields:['id', 'text']
		}),
		displayField:'text',
		valueField:'id',
		mode:'local',
		triggerAction:'all',
		editable:false,
		selectOnFocus:true,
		forceSelection:true,
		allowBlank:false,
		listWidth: 170
	});

	this.languageField.on('select', function(A,B,C) {
		Ext.Ajax.request({
			url:'ngmp.php',
			params:{
				func:'setLang',
				lang: this.languageField.getValue()
			},
			success:function() {
				document.location.reload();
			},
			scope:this
		});
	},this);
	
	this.username = new Ext.form.TextField({
		id:'loginUsername',
		fieldLabel:LANG_username,
		msgTarget:'under',
		name:'username',
		invalidText: LANG_please_enter_your_username,
		allowBlank:false,
		width:175,
		value: Ext.state.Manager.get('username','')
	});
	this.password = new Ext.form.TextField({
		id:'loginPassword',
		fieldLabel:LANG_password,
		msgTarget:'under',
		name:'password',
		width:175,
		inputType:'password',
		allowBlank:false
	});
	this.password.on('specialkey', function(A,B){
		if (B.getKey() == 13) {
			this.doLogin();
		}
	},this);
	this.formPanel = new Ext.FormPanel({
		labelWidth:75,
		url:'ngmp.php',
		defaults: {
			width:180
		},
		buttonAlign:'right',
		bodyStyle:'padding:5px',
		items:[
			new NGMP.plugins.LogoComponent(),
			this.languageField,
			this.username,
			this.password
		],
		buttons:[{
			id:'ok',
			text:LANG_login,
			handler:this.doLogin,
			scope:this
		},this.btnSignUp = new Ext.Button({
			text:LANG_sign_up,
			handler: function() {
				delete this.signUpDialog;
				this.signUpDialog = new NGMP.dialog.SignUpDialog();
				this.signUpDialog.show();
			},
			scope:this
		})]
	});
	NGMP.dialog.LoginDialog.superclass.constructor.call(this, {
		layout:'fit',
		modal:true,
		height:300,
		width:300,
		resizable:false,
		closeAction:'hide',
		title:LANG_login,
		closable:false,
		iconCls:'login-icon-cls',
		shadow: true,
		left:407,
		bodyBorder:false,
		focus:function() {
			Ext.get('loginUsername').focus();
		},
		items:[
			this.formPanel
		],
		bbar: new Ext.StatusBar({
			text: "<a target='_blank' href='http://www.prevantage.com'>"+LANG_powered_by + "</a>",
			items:[{
				text: LANG_version_no
			}]
		})
	});
};
Ext.extend(NGMP.dialog.LoginDialog, Ext.Window, {
	callbacks: new Array(),
	addCallback:function(B,A) {
		this.callbacks.push({callback:B,scope:A});
	},
	doLogin: function() {
		if (this.formPanel.getForm().isValid()) {
			this.password.suspendEvents();
			this.originalPassword = this.password.getValue();
			this.password.setValue(sha256_digest(this.originalPassword));
			this.password.resumeEvents();
			this.formPanel.getForm().submit({
				url:'ngmp.php',
				params:{
					func:'login'
				},
				waitMsg:LANG_logging_in,
				success: function(A,B) {
					NGMP.preferences.settings = B.result.preferences;
					for (var C=0;C<this.callbacks.length;C++){
						if (this.callbacks[C].callback) {
							var D = this.callbacks[C].scope ? this.callbacks[C].scope:this;
							this.callbacks[C].callback.call(D);
						}
					}

					this.callbacks = [];
					this.hide();
				},
				failure: function (A,B) {
					if (B.result) {
						this.password.reset();
						Ext.Msg.alert(LANG_error, B.result.feedback, function() {
							this.username.selectText();
						},this);
					}
				},
				scope:this
			});
		}
	},
    show:function(){
	    NGMP.dialog.LoginDialog.superclass.show.call(this);
		this.languageField.store.reload({
			callback:function() {
				this.languageField.setValue(LANG_lang_id);
			},
			scope:this
		});
        this.formPanel.form.reset();

		//check installed
		Ext.Ajax.request({
			url:'install.php?step=100',
			success:function(A,B){
				var J = Ext.decode(A.responseText);
				if (J.failure) {
					this.systemInitializationDialog = new NGMP.dialog.SystemInitializationDialog();
					this.systemInitializationDialog.show();
				}
			},
			scope:this
		});
	}
});

NGMP.loginDialog = new NGMP.dialog.LoginDialog();


Ext.namespace("NGMP.dialog.UploadDialog");
NGMP.dialog.UploadDialog.BrowseButton=Ext.extend(Ext.Button,{
    input_name:"file",
	input_file:null,
	original_handler:null,
	original_scope:null,
	initComponent:function(){
        NGMP.dialog.UploadDialog.BrowseButton.superclass.initComponent.call(this);
        this.original_handler=this.handler||null;
        this.original_scope=this.scope||window;
        this.handler=null;
        this.scope=null;
    },
    onRender:function(B,A){
        NGMP.dialog.UploadDialog.BrowseButton.superclass.onRender.call(this,B,A);
        this.createInputFile();
    },
    createInputFile:function(){
        var C=this.el.child(".x-btn-center");
        C.position("relative");
        this.input_file=Ext.DomHelper.append(C,{
            tag:"input",
			type:"file",
			size:1,
			name:this.input_name||Ext.id(this.el),
			style:"position: absolute; display: block; border: none; cursor: pointer"
        },true);
        var B=C.getBox();
        this.input_file.setStyle("font-size",(B.width*0.5)+"px");
        var D=this.input_file.getBox();
        var A={
            x:3,y:3
        };
        if(Ext.isIE){
            A={
                x:0,y:3
            };
            
        }
        this.input_file.setLeft(B.width-D.width+A.x+"px");
        this.input_file.setTop(B.height-D.height+A.y+"px");
        this.input_file.setOpacity(0);
        if(this.handleMouseEvents){
            this.input_file.on("mouseover",this.onMouseOver,this);
            this.input_file.on("mousedown",this.onMouseDown,this);
        }
        if(this.tooltip){
            if(typeof this.tooltip=="object"){
                Ext.QuickTips.register(Ext.apply({
                    target:this.input_file
                }
                ,this.tooltip));
            }
            else{
                this.input_file.dom[this.tooltipType]=this.tooltip;
            }
            
        }
        this.input_file.on("change",this.onInputFileChange,this);
        this.input_file.on("click",function(E){
            E.stopPropagation();
        });
    },
	detachInputFile:function(B){
        var A=this.input_file;
        B=B||false;
        if(typeof this.tooltip=="object"){
            Ext.QuickTips.unregister(this.input_file);
        }
        else{
            this.input_file.dom[this.tooltipType]=null;
        }
        this.input_file.removeAllListeners();
        this.input_file=null;
        if(!B){
            this.createInputFile();
        }
        return A;
    },
    getInputFile:function(){
        return this.input_file;
    },
    disable:function(){
        NGMP.dialog.UploadDialog.BrowseButton.superclass.disable.call(this);
        this.input_file.dom.disabled=true;
    },
    enable:function(){
        NGMP.dialog.UploadDialog.BrowseButton.superclass.enable.call(this);
        this.input_file.dom.disabled=false;
    },
    destroy:function(){
        var A=this.detachInputFile(true);
        A.remove();
        A=null;
        NGMP.dialog.UploadDialog.BrowseButton.superclass.destroy.call(this);
    },
    onInputFileChange:function(){
        if(this.original_handler){
            this.original_handler.call(this.original_scope,this);
        }
    }
});
NGMP.dialog.UploadDialog.TBBrowseButton=Ext.extend(NGMP.dialog.UploadDialog.BrowseButton,{
    hideParent:true,onDestroy:function(){
        NGMP.dialog.UploadDialog.TBBrowseButton.superclass.onDestroy.call(this);
        if(this.container){
            this.container.remove();
        }
    }
});
NGMP.dialog.UploadDialog.FileRecord=Ext.data.Record.create([
	{name:"filename"},
	{name:"state",type:"int"},
	{name:"note"},
	{name:"input_element"}
]);
NGMP.dialog.UploadDialog.FileRecord.STATE_QUEUE=0;
NGMP.dialog.UploadDialog.FileRecord.STATE_FINISHED=1;
NGMP.dialog.UploadDialog.FileRecord.STATE_FAILED=2;
NGMP.dialog.UploadDialog.FileRecord.STATE_PROCESSING=3;
NGMP.dialog.UploadDialog.Dialog=function(A){
    var B={
        border:false,
		width:450,
		height:300,
		minWidth:450,
		minHeight:300,
		plain:true,
		constrainHeader:true,
		draggable:true,
		closable:true,
		maximizable:false,
		minimizable:false,
		resizable:true,
		autoDestroy:true,
		closeAction:"hide",
		plugins:[new NGMP.plugins.IconMenu({
            
        })],
		title:LANG_file_uploading_dialog,
		cls:"ext-ngmp-uploaddialog-dialog",
		url:"",base_params:{
            
        },
        permitted_extensions:[],
		reset_on_hide:true,
		allow_close_on_upload:false,
		upload_autostart:false,
		post_var_name:"file"
    };
    A=Ext.applyIf(A||{ },B);
    A.layout="absolute";
    NGMP.dialog.UploadDialog.Dialog.superclass.constructor.call(this,A);
};
Ext.extend(NGMP.dialog.UploadDialog.Dialog,Ext.Window,{
    fsa:null,
	state_tpl:null,
	form:null,
	grid_panel:null,
	progress_bar:null,
	is_uploading:false,
	initial_queued_count:0,
	upload_frame:null,
	initComponent:function(){
        NGMP.dialog.UploadDialog.Dialog.superclass.initComponent.call(this);
        var A={
            created:{
                "window-render":[{
                    action:[this.createForm,this.createProgressBar,this.createGrid],state:"rendering"
                }
                ],destroy:[{
                    action:this.flushEventQueue,state:"destroyed"
                }
                ]
            }
            ,rendering:{
                "grid-render":[{
                    action:[this.fillToolbar,this.updateToolbar],state:"ready"
                }
                ],destroy:[{
                    action:this.flushEventQueue,state:"destroyed"
                }
                ]
            }
            ,ready:{
                "file-selected":[{
                    predicate:[this.fireFileTestEvent,this.isPermittedFile],action:this.addFileToUploadQueue,state:"adding-file"
                }
                ,{
                    
                }
                ],"grid-selection-change":[{
                    action:this.updateToolbar
                }
                ],"remove-files":[{
                    action:[this.removeFiles,this.fireFileRemoveEvent]
                }
                ],"reset-queue":[{
                    action:[this.resetQueue,this.fireResetQueueEvent]
                }
                ],"start-upload":[{
                    predicate:this.hasUnuploadedFiles,action:[this.setUploadingFlag,this.saveInitialQueuedCount,this.updateToolbar,this.updateProgressBar,this.prepareNextUploadTask,this.fireUploadStartEvent],state:"uploading"
                }
                ,{
                    
                }
                ],"stop-upload":[{
                    
                }
                ],hide:[{
                    predicate:[this.isNotEmptyQueue,this.getResetOnHide],action:[this.resetQueue,this.fireResetQueueEvent]
                }
                ,{
                    
                }
                ],destroy:[{
                    action:this.flushEventQueue,state:"destroyed"
                }
                ]
            }
            ,"adding-file":{
                "file-added":[{
                    predicate:this.isUploading,action:[this.incInitialQueuedCount,this.updateProgressBar,this.fireFileAddEvent],state:"uploading"
                }
                ,{
                    predicate:this.getUploadAutostart,action:[this.startUpload,this.fireFileAddEvent],state:"ready"
                }
                ,{
                    action:[this.updateToolbar,this.fireFileAddEvent],state:"ready"
                }
                ]
            }
            ,uploading:{
                "file-selected":[{
                    predicate:[this.fireFileTestEvent,this.isPermittedFile],action:this.addFileToUploadQueue,state:"adding-file"
                }
                ,{
                    
                }
                ],"grid-selection-change":[{
                    
                }
                ],"start-upload":[{
                    
                }
                ],"stop-upload":[{
                    predicate:this.hasUnuploadedFiles,
					action:[this.resetUploadingFlag,
					this.abortUpload,this.updateToolbar,
					this.updateProgressBar,this.fireUploadStopEvent],state:"ready"
                }
                ,{
                    action:[this.resetUploadingFlag,
					this.abortUpload,
					this.updateToolbar,
					this.updateProgressBar,
					this.fireUploadStopEvent,
					this.fireUploadCompleteEvent],
					state:"ready"
                }
                ],"file-upload-start":[{
                    action:[this.uploadFile,
					this.findUploadFrame,
					this.fireFileUploadStartEvent]
                }
                ],"file-upload-success":[{
                    predicate:this.hasUnuploadedFiles,
					action:[this.resetUploadFrame,this.updateRecordState,
					this.updateProgressBar,
					this.prepareNextUploadTask,
					this.fireUploadSuccessEvent]
                }
                ,{
                    action:[this.resetUploadFrame,
					this.resetUploadingFlag,
					this.updateRecordState,
					this.updateToolbar,
					this.updateProgressBar,
					this.fireUploadSuccessEvent,
					this.fireUploadCompleteEvent],
					state:"ready"
                }
                ],"file-upload-error":[{
                    predicate:this.hasUnuploadedFiles,
					action:[this.resetUploadFrame,
					this.updateRecordState,
					this.updateProgressBar,
					this.prepareNextUploadTask,
					this.fireUploadErrorEvent]
                }
                ,{
                    action:[this.resetUploadFrame,
					this.resetUploadingFlag,
					this.updateRecordState,
					this.updateToolbar,
					this.updateProgressBar,
					this.fireUploadErrorEvent,
					this.fireUploadCompleteEvent],
					state:"ready"
                }
                ],"file-upload-failed":[{
                    predicate:this.hasUnuploadedFiles,
					action:[this.resetUploadFrame,
					this.updateRecordState,
					this.updateProgressBar,
					this.prepareNextUploadTask,
					this.fireUploadFailedEvent]
                }
                ,{
                    action:[this.resetUploadFrame,
					this.resetUploadingFlag,
					this.updateRecordState,
					this.updateToolbar,
					this.updateProgressBar,
					this.fireUploadFailedEvent,
					this.fireUploadCompleteEvent],
					state:"ready"
                }
                ],hide:[{
                    predicate:this.getResetOnHide,
					action:[this.stopUpload,this.repostHide]
                }
                ,{
                    
                }
                ],destroy:[{
                    predicate:this.hasUnuploadedFiles,
					action:[this.resetUploadingFlag,
					this.abortUpload,this.fireUploadStopEvent,
					this.flushEventQueue],state:"destroyed"
                }
                ,{
                    action:[this.resetUploadingFlag,
					this.abortUpload,this.fireUploadStopEvent,
					this.fireUploadCompleteEvent,this.flushEventQueue],state:"destroyed"
                }
                ]
            }
            ,destroyed:{
                
            }
            
        }
        ;
        this.fsa=new NGMP.utils.FSA("created",A,this);
        this.addEvents({
            filetest:true,
			fileadd:true,
			fileremove:true,
			resetqueue:true,
			uploadsuccess:true,
			uploaderror:true,
			uploadfailed:true,
			uploadstart:true,
			uploadstop:true,
			uploadcomplete:true,
			fileuploadstart:true
        });
        this.on("render",this.onWindowRender,this);
        this.on("beforehide",this.onWindowBeforeHide,this);
        this.on("hide",this.onWindowHide,this);
        this.on("destroy",this.onWindowDestroy,this);
        this.state_tpl=new Ext.Template("<div class='ext-ngmp-uploaddialog-state ext-ngmp-uploaddialog-state-{state}'>&#160;</div>").compile();
    }
    ,createForm:function(){
        this.form=Ext.DomHelper.append(this.body,{
            tag:"form",
			method:"post",
			action:this.url,
			style:"position: absolute;left: -100px;top: -100px; width: 100px;height: 100px"
        });
    }
    ,createProgressBar:function(){
        this.progress_bar=this.add(new Ext.ProgressBar({
            x:0,
			y:0,
			anchor:"0",
			value:0,
			text:LANG_upload_progress_waiting
        }));
    }
    ,createGrid:function(){
        var B=new Ext.data.Store({
            proxy:new Ext.data.MemoryProxy([]),reader:new Ext.data.JsonReader({
                
            }
            ,NGMP.dialog.UploadDialog.FileRecord),sortInfo:{
                field:"state",
				direction:"DESC"
            }
            ,pruneModifiedRecords:true
        }
        );
        var A=new Ext.grid.ColumnModel([{
            header:LANG_upload_state_col_title,
			width:70,
			resizable:false,
			dataIndex:"state",
			sortable:true,
			renderer:this.renderStateCell.createDelegate(this)
        }
        ,{
            header:LANG_upload_filename_col_title,
			width:230,
			dataIndex:"filename",
			sortable:true,
			renderer:this.renderFilenameCell.createDelegate(this)
        }
        ,{
            header:LANG_upload_note_col_title,
			width:150,
			dataIndex:"note",
			sortable:true,
			renderer:this.renderNoteCell.createDelegate(this)
        }
        ]);
        this.grid_panel=new NGMP.grid.GridPanel({
            ds:B,cm:A,
			x:0,
			y:22,
			anchor:"0 -22",
			border:true,viewConfig:{
                autoFill:true,forceFit:true
            }
            ,bbar:new Ext.Toolbar()
        });
        this.grid_panel.on("render",this.onGridRender,this);
        this.add(this.grid_panel);
        this.grid_panel.getSelectionModel().on("selectionchange",this.onGridSelectionChange,this);
    }
    ,fillToolbar:function(){
        var A=this.grid_panel.getBottomToolbar();
        A.x_buttons={
            
        }
        ;
        A.x_buttons.add=A.addItem(new NGMP.dialog.UploadDialog.TBBrowseButton({
            input_name:this.post_var_name,
			text:LANG_upload_btn_add,
			tooltip:LANG_upload_btn_add_tip,
			iconCls:"ext-ngmp-uploaddialog-addbtn",
			handler:this.onAddButtonFileSelected,
			scope:this
        }
        ));
        A.x_buttons.remove=A.addButton({
            text:LANG_upload_btn_remove,
			tooltip:LANG_upload_btn_remove_tip,
			iconCls:"ext-ngmp-uploaddialog-removebtn",
			handler:this.onRemoveButtonClick,scope:this
        });
        A.x_buttons.reset=A.addButton({
            text:LANG_upload_btn_reset,
			tooltip:LANG_upload_btn_reset_tip,
			iconCls:"ext-ngmp-uploaddialog-resetbtn",
			handler:this.onResetButtonClick,
			scope:this
        });
        A.add("-");
        A.x_buttons.upload=A.addButton({
            text:LANG_upload_btn_start,
			tooltip:LANG_upload_btn_start_tip,
			iconCls:"ext-ngmp-uploaddialog-uploadstartbtn",
			handler:this.onUploadButtonClick,
			scope:this
        });
        A.add("-");
        A.x_buttons.indicator=A.addItem(new Ext.Toolbar.Item(Ext.DomHelper.append(A.getEl(),{
            tag:"div",
			cls:"ext-ngmp-uploaddialog-indicator-stoped",
			html:"&#160"
        }
        )));
        A.add("->");
        A.x_buttons.close=A.addButton({
            text:LANG_upload_btn_close,
			tooltip:LANG_upload_btn_close_tip,
			handler:this.onCloseButtonClick,
			scope:this
        });
    }
    ,renderStateCell:function(F,A,B,D,E,C){
        return this.state_tpl.apply({
            state:F
        });
    }
    ,renderFilenameCell:function(H,A,C,E,G,D){
        var B=this.grid_panel.getView();
        var F=function(){
            try{
                Ext.fly(B.getCell(E,G)).child(".x-grid3-cell-inner").dom.qtip=H;
            }
            catch(I){
                
            }
            
        } ;
        F.defer(1000);
        return H;
    }
    ,renderNoteCell:function(H,A,C,E,G,D){
        var B=this.grid_panel.getView();
        var F=function(){
            try{
                Ext.fly(B.getCell(E,G)).child(".x-grid3-cell-inner").dom.qtip=H;
            }
            catch(I){
                
            }
            
        } ;
        F.defer(1000);
        return H;
    }
    ,getFileExtension:function(B){
        var A=null;
        var C=B.split(".");
        if(C.length> 1){
            A=C.pop();
        }
        return A;
    }
    ,isPermittedFileType:function(B){
        var A=true;
        if(this.permitted_extensions.length> 0){
            A=this.permitted_extensions.indexOf(this.getFileExtension(B))!=-1;
        }
        return A;
    }
    ,isPermittedFile:function(C){
        var A=false;
        var B=C.getInputFile().dom.value;
        if(this.isPermittedFileType(B)){
            A=true;
        }
        else{
            Ext.Msg.alert(LANG_error,
				String.format(LANG_upload_err_file_type_not_permitted, B,
						this.permitted_extensions.join(LANG_upload_permitted_extensions_join_str)));
            A=false;
        }
        return A;
    }
    ,fireFileTestEvent:function(A){
        return this.fireEvent("filetest",this,A.getInputFile().dom.value)!==false;
    }
    ,addFileToUploadQueue:function(C){
        var A=C.detachInputFile();
        A.appendTo(this.form);
        A.setStyle("width","100px");
        A.dom.disabled=true;
        var B=this.grid_panel.getStore();
        B.add(new NGMP.dialog.UploadDialog.FileRecord({
            state:NGMP.dialog.UploadDialog.FileRecord.STATE_QUEUE,
			filename:A.dom.value,
			note:LANG_upload_note_queued_to_upload,input_element:A
        }));
        this.fsa.postEvent("file-added",A.dom.value);
    }
    ,fireFileAddEvent:function(A){
        this.fireEvent("fileadd",this,A);
    }
    ,updateProgressBar:function(){
        if(this.is_uploading){
            var B=this.getQueuedCount(true);
            var A=1-B/this.initial_queued_count;
            this.progress_bar.updateProgress(A,String.format(LANG_upload_progress_uploading,
				this.initial_queued_count-B,
				this.initial_queued_count));
        }
        else{
            this.progress_bar.updateProgress(0,LANG_upload_progress_waiting);
        }
        
    }
    ,updateToolbar:function(){
        var A=this.grid_panel.getBottomToolbar();
        if(this.is_uploading){
            A.x_buttons.remove.disable();
            A.x_buttons.reset.disable();
            A.x_buttons.upload.enable();
            if(!this.getAllowCloseOnUpload()){
                A.x_buttons.close.disable();
            }
            Ext.fly(A.x_buttons.indicator.getEl()).replaceClass("ext-ngmp-uploaddialog-indicator-stoped","ext-ngmp-uploaddialog-indicator-processing");
            A.x_buttons.upload.setIconClass("ext-ngmp-uploaddialog-uploadstopbtn");
            A.x_buttons.upload.setText(LANG_upload_btn_stop);
            A.x_buttons.upload.getEl().child(A.x_buttons.upload.buttonSelector).dom[A.x_buttons.upload.tooltipType]=LANG_upload_btn_stop_tip;
        }
        else{
            A.x_buttons.remove.enable();
            A.x_buttons.reset.enable();
            A.x_buttons.close.enable();
            Ext.fly(A.x_buttons.indicator.getEl()).replaceClass("ext-ngmp-uploaddialog-indicator-processing","ext-ngmp-uploaddialog-indicator-stoped");
            A.x_buttons.upload.setIconClass("ext-ngmp-uploaddialog-uploadstartbtn");
            A.x_buttons.upload.setText(LANG_upload_btn_start);
            A.x_buttons.upload.getEl().child(A.x_buttons.upload.buttonSelector).dom[A.x_buttons.upload.tooltipType]=LANG_upload_btn_start_tip;
            if(this.getQueuedCount()> 0){
                A.x_buttons.upload.enable();
            }
            else{
                A.x_buttons.upload.disable();
            }
            if(this.grid_panel.getSelectionModel().hasSelection()){
                A.x_buttons.remove.enable();
            }
            else{
                A.x_buttons.remove.disable();
            }
            if(this.grid_panel.getStore().getCount()> 0){
                A.x_buttons.reset.enable();
            }
            else{
                A.x_buttons.reset.disable();
            }
            
        }
        
    }
    ,saveInitialQueuedCount:function(){
        this.initial_queued_count=this.getQueuedCount();
    }
    ,incInitialQueuedCount:function(){
        this.initial_queued_count++;
    }
    ,setUploadingFlag:function(){
        this.is_uploading=true;
    }
    ,resetUploadingFlag:function(){
        this.is_uploading=false;
    }
    ,prepareNextUploadTask:function(){
        var B=this.grid_panel.getStore();
        var A=null;
        B.each(function(C){
            if(!A&&C.get("state")==NGMP.dialog.UploadDialog.FileRecord.STATE_QUEUE){
                A=C;
            }
            else{
                C.get("input_element").dom.disabled=true;
            }
            
        });
        A.get("input_element").dom.disabled=false;
        A.set("state",NGMP.dialog.UploadDialog.FileRecord.STATE_PROCESSING);
        A.set("note",LANG_upload_note_processing);
        A.commit();
        this.fsa.postEvent("file-upload-start",A);
    }
    ,fireUploadStartEvent:function(){
        this.fireEvent("uploadstart",this);
    }
    ,removeFiles:function(E){
        var B=this.grid_panel.getStore();
        for(var C=0,A=E.length;C<A;C++){
            var D=E[C];
            D.get("input_element").remove();
            B.remove(D);
        }
        
    }
    ,fireFileRemoveEvent:function(C){
        for(var B=0,A=C.length; B< A; B++){
            this.fireEvent("fileremove",this,C[B].get("filename"));
        }
        
    }
    ,resetQueue:function(){
        var A=this.grid_panel.getStore();
        A.each(function(B){
            B.get("input_element").remove();
        });
        A.removeAll();
    }
    ,fireResetQueueEvent:function(){
        this.fireEvent("resetqueue",this);
    }
    ,uploadFile:function(A){
        Ext.Ajax.request({
            url:this.url,
			params:this.base_params||this.baseParams||this.params,
			method:"POST",
			form:this.form,
			isUpload:true,
			success:this.onAjaxSuccess,
			failure:this.onAjaxFailure,
			scope:this,
			record:A
        });
    }
    ,fireFileUploadStartEvent:function(A){
        this.fireEvent("fileuploadstart",this,A.get("filename"));
    }
    ,updateRecordState:function(A){
        if("success" in A.response&&A.response.success){
            A.record.set("state",NGMP.dialog.UploadDialog.FileRecord.STATE_FINISHED);
            A.record.set("note",A.response.message||A.response.error||LANG_upload_note_success);
        }
        else{
            A.record.set("state",NGMP.dialog.UploadDialog.FileRecord.STATE_FAILED);
            A.record.set("note",A.response.message||A.response.error||LANG_upload_note_error);
        }
        A.record.commit();
    }
    ,fireUploadSuccessEvent:function(A){
        this.fireEvent("uploadsuccess",this,A.record.get("filename"),A.response);
    }
    ,fireUploadErrorEvent:function(A){
        this.fireEvent("uploaderror",this,A.record.get("filename"),A.response);
    }
    ,fireUploadFailedEvent:function(A){
        this.fireEvent("uploadfailed",this,A.record.get("filename"));
    }
    ,fireUploadCompleteEvent:function(){
        this.fireEvent("uploadcomplete",this);
    }
    ,findUploadFrame:function(){
        this.upload_frame=Ext.getBody().child("iframe.x-hidden:last");
    }
    ,resetUploadFrame:function(){
        this.upload_frame=null;
    }
    ,removeUploadFrame:function(){
        if(this.upload_frame){
            this.upload_frame.removeAllListeners();
            this.upload_frame.dom.src="about:blank";
            this.upload_frame.remove();
        }
        this.upload_frame=null;
    }
    ,abortUpload:function(){
        this.removeUploadFrame();
        var B=this.grid_panel.getStore();
        var A=null;
        B.each(function(C){
            if(C.get("state")==NGMP.dialog.UploadDialog.FileRecord.STATE_PROCESSING){
                A=C;
                return false;
            }
            
        });
        A.set("state",NGMP.dialogP.UploadDialog.FileRecord.STATE_FAILED);
        A.set("note",LANG_upload_note_aborted);
        A.commit();
    }
    ,fireUploadStopEvent:function(){
        this.fireEvent("uploadstop",this);
    }
    ,repostHide:function(){
        this.fsa.postEvent("hide");
    }
    ,flushEventQueue:function(){
        this.fsa.flushEventQueue();
    }
    ,onWindowRender:function(){
        this.fsa.postEvent("window-render");
    }
    ,onWindowBeforeHide:function(){
        return this.isUploading()?this.getAllowCloseOnUpload():true;
    }
    ,onWindowHide:function(){
        this.fsa.postEvent("hide");
    }
    ,onWindowDestroy:function(){
        this.fsa.postEvent("destroy");
    }
    ,onGridRender:function(){
        this.fsa.postEvent("grid-render");
    }
    ,onGridSelectionChange:function(){
        this.fsa.postEvent("grid-selection-change");
    }
    ,onAddButtonFileSelected:function(A){
        this.fsa.postEvent("file-selected",A);
    }
    ,onUploadButtonClick:function(){
        if(this.is_uploading){
            this.fsa.postEvent("stop-upload");
        }
        else{
            this.fsa.postEvent("start-upload");
        }
        
    }
    ,onRemoveButtonClick:function(){
        var A=this.grid_panel.getSelectionModel().getSelections();
        this.fsa.postEvent("remove-files",A);
    }
    ,onResetButtonClick:function(){
        this.fsa.postEvent("reset-queue");
    }
    ,onCloseButtonClick:function(){
        this[this.closeAction].call(this);
    }
    ,onAjaxSuccess:function(C,D){
        var A={
            success:false,error:LANG_upload_note_error
        }
        ;
        try{
            var B=C.responseText;
            var E=B.match(/^<pre>((?:.|\n)*)<\/pre>$/i);
            if(E){
                B=E[1];
            }
            A=Ext.util.JSON.decode(B);
        }
        catch(G){
            
        }
        var F={
            record:D.record,response:A
        };
        if("success" in A&&A.success){
            this.fsa.postEvent("file-upload-success",F);
        }
        else{
			if (A.failure) {
				Ext.Msg.alert(LANG_error, A.feedback);
			}
            this.fsa.postEvent("file-upload-error",F);
        }
        
    }
    ,onAjaxFailure:function(A,B){
        var C={
            record:B.record,response:{
                success:false,error:LANG_upload_note_upload_failed
            }
        };
        this.fsa.postEvent("file-upload-failed",C);
    }
    ,startUpload:function(){
        this.fsa.postEvent("start-upload");
    }
    ,stopUpload:function(){
        this.fsa.postEvent("stop-upload");
    }
    ,getUrl:function(){
        return this.url;
    }
    ,setUrl:function(A){
        this.url=A;
    }
    ,getBaseParams:function(){
        return this.base_params;
    }
    ,setBaseParams:function(A){
        this.base_params=A;
    }
    ,getUploadAutostart:function(){
        return this.upload_autostart;
    }
    ,setUploadAutostart:function(A){
        this.upload_autostart=A;
    }
    ,getAllowCloseOnUpload:function(){
        return this.allow_close_on_upload;
    }
    ,setAllowCloseOnUpload:function(A){
        this.allow_close_on_upload;
    }
    ,getResetOnHide:function(){
        return this.reset_on_hide;
    }
    ,setResetOnHide:function(A){
        this.reset_on_hide=A;
    }
    ,getPermittedExtensions:function(){
        return this.permitted_extensions;
    }
    ,setPermittedExtensions:function(A){
        this.permitted_extensions=A;
    }
    ,isUploading:function(){
        return this.is_uploading;
    }
    ,isNotEmptyQueue:function(){
        return this.grid_panel.getStore().getCount()>0;
    }
    ,getQueuedCount:function(B){
        var C=0;
        var A=this.grid_panel.getStore();
        A.each(function(D){
            if(D.get("state")==NGMP.dialog.UploadDialog.FileRecord.STATE_QUEUE){
                C++;
            }
            if(B&&D.get("state")==NGMP.dialog.UploadDialog.FileRecord.STATE_PROCESSING){
                C++;
            }
            
        });
        return C;
    }
    ,hasUnuploadedFiles:function(){
        return this.getQueuedCount()> 0;
    }
    
});

NGMP.dialog.SelectGroups= function(A) {
	Ext.apply(this, A);

	this.store = new NGMP.data.JsonStore({
		url: 'ngmp.php',
		root:'results',
		totalProperty:'total',
		id:'gid',
		fields:['gid','name'],
		remoteSort: true,
		baseParams:{
			func:'getGroups'
		}
	});
	this.grid = new NGMP.grid.GridPanel({
		paging:true,
		border:false,
		store:this.store,
		view: new Ext.grid.GridView({
			autoFill:true,
			forceFit:true
		}),
		columns:[
			{header: LANG_name, dataIndex:'name', css:'white-space:normal;',sortable:true}
		],
		sm: new Ext.grid.RowSelectionModel()
	});
	NGMP.dialog.SelectGroups.superclass.constructor.call(this, {
		layout:'fit',
		modal:false,
		height:400,
		width:600,
		closeAction:'hide',
		title:LANG_select_groups,
		items:[this.grid],
		buttons:[{
			text:LANG_ok,
			handler: function() {
				this.callHandler(true);
			},
			scope:this
		},{
			text:LANG_add,
			handler: function() {
				this.callHandler(false);
				this.hide();
			},
			scope:this
		},{
			text:LANG_close,
			handler: function() {
				this.hide();
			},
			scope:this
		}],
		keys:[{
			key:Ext.EventObject.ENTER,
			fn:function() {
				this.callHandler(true);
			},
			scope:this
		}]
	});
};
Ext.extend(NGMP.dialog.SelectGroups, Ext.Window, {
	show:function() {
		this.store.reload();
		NGMP.dialog.SelectGroups.superclass.show.call(this);
	},
	callHandler:function(A) {
		if (this.handler) {
			if (!this.scope) {
				this.scope = this;
			}
			var B = this.handler.createDelegate(this.scope, [this.grid]);
			B.call();
		}
		if (A) {
			this.hide();
		}
	}
});

NGMP.dialog.SelectUsers= function(A) {
	Ext.apply(this, A);

	this.store = new NGMP.data.JsonStore({
		url: 'ngmp.php',
		root:'results',
		totalProperty:'total',
		id:'uid',
		fields:['uid','fullname'],
		remoteSort: true,
		baseParams:{
			func:'getUsers'
		}
	});
	this.grid = new NGMP.grid.GridPanel({
		paging:true,
		border:false,
		store:this.store,
		view: new Ext.grid.GridView({
			autoFill:true,
			forceFit:true
		}),
		columns:[
			{header: LANG_name, dataIndex:'fullname', css:'white-space:normal;',sortable:true}
		],
		sm: new Ext.grid.RowSelectionModel()
	});
	NGMP.dialog.SelectUsers.superclass.constructor.call(this, {
		layout:'fit',
		modal:false,
		height:400,
		width:600,
		closeAction:'hide',
		title:LANG_select_users,
		items:[this.grid],
		buttons:[{
			text:LANG_ok,
			handler:function() {
				this.callHandler(true);
			},
			scope:this
		},{
			text:LANG_add,
			handler: function() {
				this.callHandler(false);
			},
			scope:this
		},{
			text:LANG_close,
			handler: function() {
				this.hide();
			},
			scope:this
		}]
	});
};
Ext.extend(NGMP.dialog.SelectUsers, Ext.Window, {
	show:function() {
		this.store.reload();
		NGMP.dialog.SelectUsers.superclass.show.call(this);
	},
	callHandler:function(A) {
		if (this.handler) {
			if (!this.scope) {
				this.scope = this;
			}
			var B = this.handler.createDelegate(this.scope,[this.grid]);
			B.call();
		}
		if (A) {
			this.hide();
		}
	}
});


NGMP.dialog.LinksDialog=function(A){
	Ext.apply(this,A);
	this.store=new NGMP.data.JsonStore({
		url:'ngmp.php',
		root:"results",
		totalProperty:"total",
		fields:["icon","link_type","name","type","url","mtime","id","module"],
		remoteSort:true,
		baseParams:{
			task:"links"
		}
	});
	
	this.SearchField=new Ext.app.SearchField({store:this.store,width:320});

	this.grid = new NGMP.grid.GridPanel({
		paging:true,
		store:this.store,
		view:new Ext.grid.GridView({
			autoFill:true,
			forceFit:true
		}),
		columns:[{
			header:"",
			width:28,
			dataIndex:"icon",
			renderer:this.IconRenderer
		},{
			header:LANG_name,
			dataIndex:"name",
			css:"white-space:normal;",
		 	sortable:true
	    },{
			header:LANG_type,
			dataIndex:"type",
			sortable:true
		},{
			header:LANG_mtime,
			dataIndex:"mtime",
			sortable:true
		}],
		sm:new Ext.grid.RowSelectionModel(),
		tbar:[LANG_search+": "," ",this.SearchField]
	});
	NGMP.dialog.LinksDialog.superclass.constructor.call(this,{
		layout:"fit",
		modal:false,
		minWidth:300,
		minHeight:300,
		height:400,
		width:600,
		plain:true,
		closeAction:"hide",
		title:LANG_link_items,
		items:this.grid,
		buttons:[{
			id:"ok",
			text:LANG_ok,
			handler:function(){
				this.linkItems();
			},
			scope:this
		},{
			id:"close",
			text:LANG_close,
			handler:function(){
				this.hide();
			},
			scope:this
		}]
   });
};

Ext.extend(NGMP.dialog.LinksDialog,Ext.Window,{
	IconRenderer:function(C,A,B){
		return'<div class="go-link-icon-'+B.data.link_type+' "></div>';
	},
	setLinkRecords:function(B){
		this.fromLinks=[];
		for(var A=0; A<B.length;A++){
			this.fromLinks.push({link_id:B[A].data.link_id,link_type:B[A].data.link_type});
		}
	},
	setSingleLink:function(A,B){
		this.fromLinks=[{link_id:A,link_type:B}];
	},
	show:function(){
		NGMP.dialog.LinksDialog.superclass.show.call(this);
		this.SearchField.focus.defer(100,this.SearchField,[true]);
	},
	linkItems:function() {
		var A=this.grid.getSelectionModel();
		var C=A.getSelections();
		var B=[];
		for(var D=0; D<C.length;D++){
			B.push({link_id:C[D].data.id,link_type:C[D].data.link_type});
		}
		var E=new Ext.data.Connection();
		E.request({
			url:BaseHref+"action.php",
			params:{
				task:"link",fromLinks:Ext.encode(this.fromLinks),
				toLinks:Ext.encode(B)
	   		},
			callback:function(G,H,F){
				if(!H){
					Ext.MessageBox.alert(LANG_error,F.result.errors);
				} else {
					if(this.linksStore){
						this.linksStore.reload();
					}
					this.hide();
				}
		   },
		   scope:this
	   });
	}
});


NGMP.dialog.AddressWindow=function(A){
    this.addEvents({
        ok:true
    });
    this.contactsStore=A;
    this.sm=new Ext.grid.RowSelectionModel({
        singleSelect:false
    });
    this.cm=new Ext.grid.ColumnModel([{
        header:"Name",dataIndex:"name",width:200,sortable:true
    }
    ,{
        header:"Email",dataIndex:"email",width:200,sortable:true
    }
    ,{
        header:"Address",dataIndex:"street",width:200,sortable:true
    }
    ,{
        header:"City/Town",dataIndex:"city",width:150,sortable:true
    }
    ,{
        header:"County",dataIndex:"state",width:150,sortable:true
    }
    ,{
        header:"Telephone",dataIndex:"work",width:100,sortable:true
    }
    ]);
    this.addressGrid=new Ext.grid.GridPanel({
        id:"gridAddresses",region:"center",deferredRender:true,monitorResize:true,store:this.contactsStore,cm:this.cm,view:new Ext.grid.GridView({
            autoFill:false,forceFit:false,emptyText:"There are no contacts to display"
        }
        ),sm:this.sm,frame:false,border:false,split:false
    });
    this.addressGrid.on("rowdblclick",function(C,E,D){
        var B=A.getAt(E).get("email");
        if(this.toField.getValue().length>0&&!this.toField.getValue().endsWith(";")){
            B=";"+B;
        }
        this.toField.setValue(this.toField.getValue()+B);
    }
    ,this);
    this.toButton=new Ext.Button({
        id:"buttonTo",minWidth:50,handler:function(){
            var C=this.addressGrid.getSelectionModel().getSelections();
            var B=this.toField.getValue();
            if(B.endsWith(";")){
                B=B.substring(0,B.Length-1);
            }
            for(i=0;i<C.length;i++){
                if(B.length> 0){
                    B+=";";
                }
                B+=C[i].get("email");
            }
            this.toField.setValue(B);
        }
        ,scope:this,text:LANG_to+":"
    });
    this.toField=new Ext.form.TextField({
        id:"textfieldTo",hideLabel:true,name:"to",value:"",width:300,anchor:"100%"
    });
    this.addressFields=new Ext.Panel({
        id:"panelAddressFields",region:"south",baseCls:"x-plain",height:35,minHeight:35,maxHeight:35,split:false,border:false,layout:"table",layoutConfig:{
            columns:2
        }
        ,items:[{
            id:"panelToButton",baseCls:"x-plain",bodyStyle:"padding: 5px;",width:70,border:false,items:this.toButton
        }
        ,{
            id:"panelToField",baseCls:"x-plain",bodyStyle:"padding: 5px;",layout:"fit",border:false,items:this.toField
        }
        ]
    });
    NGMP.dialog.AddressWindow.superclass.constructor.call(this,{
        id:"windowAddressWindow",title:"Contacts",bodyBorder:false,width:400,height:300,minWidth:300,stateful:false,minHeight:200,layout:"border",modal:true,iconCls:"contacts-icon-cls",plain:true,buttonAlign:"right",maximizable:false,resizable:false,plugins:[new NGMP.plugins.IconMenu({
            
        }
        )],buttons:[{
            id:"buttonOKAddressWindow",text:"OK",handler:function(){
                this.fireEvent("ok",this,this.toField.getValue());
                this.hide();
            }
            ,scope:this
        }
        ,{
            id:"buttonCancelAddressWindow",text:"Cancel",handler:function(){
                this.hide();
            }
            ,scope:this
        }
        ],items:[this.addressGrid,this.addressFields]
    });
};
Ext.extend(NGMP.dialog.AddressWindow,Ext.Window,{
    afterShow:function(){
        NGMP.dialog.AddressWindow.superclass.afterShow.call(this);
        this.addressGrid.getSelectionModel().selectFirstRow();
    }
    ,show:function(A){
        NGMP.dialog.AddressWindow.superclass.show.call(this);
        this.toButton.setText(A.type+":");
        this.toField.setValue(A.value);
    }
    
});

NGMP.dialog.SignUpDialog = function(A) {
	this.config = A || {};

	this.formUserNameField = new Ext.form.TextField({
		fieldLabel:LANG_username,
		allowBlank:false,
		name:'username',
		validateValue:function(value) {
			var domainNameField = Ext.getCmp('domain');
			var _mail = value + '@' + domainNameField.lastSelectionText;
			if (!validateEmail(_mail)) {
				this.markInvalid(LANG_invalid_email);
				return false;
			}
			Ext.Ajax.request({
				url:'ngmp.php',
				params:{
					func:'checkAccountExists',
					account:_mail
				},
				success:function(A,B){
					var C = Ext.decode(A.responseText);
					if (C.exists === true) {
						this.markInvalid(LANG_account_exists);
						return false;
					}
				},
				scope:this
			});
			this.markInvalid('');
			delete domainNameField;
			delete _mail;
			return true;
		},
		scope:this
	});
	this.formDomainField = new Ext.form.ComboBox({
		hideLabel:false,
		labelSeparator:'@',
		width:220,
		hiddenName:'domain_id',
		id:'domain',
		value:null,
		style:'margin-left:4px;',
		store: new NGMP.data.JsonStore({
			url:'ngmp.php',
			baseParams:{
				func:'getSignupDomains'
			},
			root:'results',
			id:'id',
			fields:['id', 'name']
		}),
		displayField:'name',
		valueField:'id',
		mode:'local',
		triggerAction:'all',
		editable:false,
		selectOnFocus:true,
		forceSelection:true,
		allowBlank:false
	});


	this.formPasswordField = new NGMP.form.PasswordField({
		fieldLabel:LANG_password,
		id:'signupPassword',
		allowBlank:false,
		name:'password'
	});
	this.formPasswordField2 = new NGMP.form.PasswordField({
		fieldLabel:LANG_verify_password,
		inputType:'password',
		name:'password2',
		allowBlank:false,
		validateValue: function(value) {
		//	console.log('password2='+value+' password1='+Ext.getCmp('signupPassword').value);
			if (value != Ext.getCmp('signupPassword').getValue()) {
				this.markInvalid(LANG_password_missmatch);
				return false;
			} else {
				this.markInvalid('');
				return true;
			}
		},
		scope:this
	});

	this.formFirstNameField = new Ext.form.TextField({
		fieldLabel:LANG_name,
		name:'first_name',
		maxLength:20,
		allowBlank:false,
		width:80
	});

	this.formMiddleNameField = new Ext.form.TextField({
		fieldLabel:'',
		labelSeparator:'',
		hideLabel:true,
		name:'middle_name',
		maxLength:20,
		allowBlank:true,
		width:50,
		style:'margin-left: 3px;'
	});

	this.formLastNameField = new Ext.form.TextField({
		fieldLabel:'',
		labelSeparator:'',
		hideLabel:true,
		width:100,
		name:'last_name',
		maxLength:80,
		allowBlank:false,
		style:'margin-left:3px;'
	});

	this.formSexMale = new Ext.form.Radio({
		name:'sex',
		fieldLabel:LANG_sex,
		labelSeparator:':',
		boxLabel:LANG_male,
		checked:true,
		inputValue:'M',
		dataIndex:'sexM',
		width:75,
		height:20
	});
	this.formSexFemale = new Ext.form.Radio({
		name:'sex',
		boxLabel:LANG_female,
		labelSeparator:null,
		hideLabel:true,
		inputValue:'F',
		dataIndex:'sexF',
		width:75,
		height:20
	});

	this.formBirthday = new Ext.form.DateField({
		fieldLabel:LANG_birthday,
		name:'birthday',
		width:200
	});

	this.formStreetAddress = new Ext.form.TextField({
		fieldLabel:LANG_street_address,
		name:'street_address',
		width:400
	});

	this.formZipCode = new Ext.form.TextField({
		fieldLabel:LANG_zip_code,
		name:'zip_code',
		width:100
	});

	this.formCity = new Ext.form.TextField({
		fieldLabel:LANG_city,
		name:'city',
		width:100
	});

	this.formState = new Ext.form.TextField({
		fieldLabel:LANG_state,
		name:'state',
		width:100
	});

	this.formCountry = new Ext.form.TextField({
		fieldLabel:LANG_country,
		name:'country',
		width:100
	});

	this.formEmail = new Ext.form.TextField({
		fieldLabel:LANG_email,
		name:'email',
		width:200
	});
	this.formEmail2 = new Ext.form.TextField({
		fieldLabel:LANG_email+'2',
		name:'email2',
		width:200
	});
	this.formEmail3 = new Ext.form.TextField({
		fieldLabel:LANG_email+'3',
		name:'email3',
		width:200
	});
	this.formIM = new Ext.form.TextField({
		fieldLabel:LANG_im,
		name:'im',
		width:200
	});
	this.formIM2 = new Ext.form.TextField({
		fieldLabel:LANG_im+'2',
		name:'im2',
		width:200
	});
	this.formIM3 = new Ext.form.TextField({
		fieldLabel:LANG_im+'3',
		name:'im3',
		width:200
	});
	this.formPhone = new Ext.form.TextField({
		fieldLabel:LANG_phone,
		name:'phone',
		width:200
	});

	this.formFax = new Ext.form.TextField({
		fieldLabel:LANG_fax,
		name:'fax',
		width:200
	});
	this.formMobile = new Ext.form.TextField({
		fieldLabel:LANG_mobile,
		name:'mobile',
		width:200
	});
	this.formPhoneWork = new Ext.form.TextField({
		fieldLabel:LANG_phone_work,
		name:'phone_work',
		width:200
	});
	this.formMobileWork = new Ext.form.TextField({
		fieldLabel:LANG_mobile_work,
		name:'mobile_work',
		width:200
	});
	this.formFaxWork = new Ext.form.TextField({
		fieldLabel:LANG_fax_work,
		name:'fax_work',
		width:200
	});
	this.formCompany = new Ext.form.TextField({
		fieldLabel:LANG_company,
		name:'company',
		width:200
	});
	this.formDepartment = new Ext.form.TextField({
		fieldLabel:LANG_department,
		name:'department',
		width:200
	});
	this.formFunction = new Ext.form.TextField({
		fieldLabel:LANG_work_function,
		name:'work_function',
		width:200
	});

	this.basicFieldset = {
		xtype:'fieldset',
		title:LANG_basic,
		autoHeight:true,
		border:true,
		collapsed:false,
		defaults:{border:false,layout:'table'},
		items:[{
			defaults:{border:false, layout:'form'},
		 	items:[{
				items:[this.formUserNameField]
			 },{
				labelWidth:5,
				width:240,	
				style:'margin-left:2px;',	
				items:[this.formDomainField]
			 }]
		},{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formPasswordField]
			},{
				labelWidth:88,
				style:'margin-left:2px',	
				items:[this.formPasswordField2]
			}]
		}]
	};

	switch (NGMP.preferences.settings.lang) {
		case 'zh_cn':
			this.titleFieldset = {
				defaults:{border:false, layout:'form'},
				items:[{
					items:[new Ext.form.TextField({
						fieldLabel:LANG_contact_title,
						name:'initials',
						labelSeparator:':',
						width:30,
						maxLength:1
					})]
				},{
					items:[new Ext.form.TextField({
						fieldLabel:'',
						name:'title',
						labelSeparator:null,
						hideLabel:true,
						maxLength:20,
						width:126,
						style:'margin-left:3px;'
					})]
				}]
			};
			break;
		default:
			//en_us
			this.titleFieldset = {
				defaults:{border:false, layout:'form'},
				items:[{
					items:[new Ext.form.TextField({
						fieldLabel:LANG_contact_title,
						name:'title',
						labelSeparator:':',
						width:126,
						maxLength:20
					})]
				},{
					items:[new Ext.form.TextField({
						fieldLabel:'',
						name:'initials',
						labelSeparator:null,
						hideLabel:true,
						maxLength:1,
						width:30,
						style:'margin-left:3px;'
					})]
				}]
			};
			break;
	}

	this.personalFieldset = {
		xtype:'fieldset',
		title:LANG_personal_details,
		autoHeight:true,
		border:true,
		collapsed:false,
		defaults:{border:false,layout:'table'},
		items:[{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formFirstNameField]	
			},{
				items:[this.formMiddleNameField]
			},{
				items:[this.formLastNameField]
			}]
		},{	
			defaults:{border:false,layout:'form'},
			items:[{
				items:[this.formSexMale]
			},{
				items:[this.formSexFemale]
			}]
		},this.titleFieldset,
		{
			defaults:{border:false,layout:'form'},
			items:[{
				items:[this.formBirthday]
			}]
		}]
	};

	this.addressFieldset = {
		xtype:'fieldset',
		title:LANG_address,
		autoHeight:true,
		border:true,
		collapsed:true,
		collapsible:true,
		defaults:{border:false,layout:'table'},
		items:[{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formStreetAddress]
			}]
		},{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formZipCode]
			}]
		},{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formCity]
			}]
		},{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formState]
			}]
		},{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formCountry]
			}]
		}]
	};

	this.contactFieldset = {
		xtype:'fieldset',
		title:LANG_contact,
		autoHeight:true,
		border:true,
		collapsed:true,
		collapsible:true,
		defaults:{border:false,layout:'table'},
		items:[{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formEmail]
			}]
		},{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formEmail2]
			}]
		},{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formEmail3]
			}]
		},{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formIM]
			}]
		},{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formIM2]
			}]
		},{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formIM3]
			}]
		},{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formPhone]
			}]
		},{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formFax]
			}]
		},{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formMobile]
			}]
		},{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formPhoneWork]
			}]
		},{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formFaxWork]
			}]
		},{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formMobileWork]
			}]
		}]

	};

	this.workFieldset = {
		xtype:'fieldset',
		title:LANG_work,
		autoHeight:true,
		border:true,
		collapsed:true,
		collapsible:true,
		defaults:{border:false,layout:'table'},
		items:[{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formCompany]
			}]
		},{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formDepartment]
			}]
		},{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formFunction]
			}]
		}]
	};

	this.formPanel = new Ext.form.FormPanel({
		url:'ngmp.php',
		baseParams:{
			func:'signup'
		},
		bodyStyle:'padding: 5px 5px 5px 5px',
		items:[this.basicFieldset, this.personalFieldset,this.addressFieldset, this.contactFieldset, this.workFieldset],
		waitMsgtarget:true
	});

	NGMP.dialog.SignUpDialog.superclass.constructor.call(this, {
		width: 600,
		height:500,
		items:[this.formPanel],
		autoScroll:true,
		buttons:[{
			text:LANG_ok,
			handler:function() {
				this.formPanel.form.submit({
					params:{
						domain: this.formDomainField.lastSelectionText
					},
					success:function() {
						this.close();
					},
					failure:function(A,B) {
						Ext.Msg.alert(LANG_error, B.result.feedback);
					},
					scope:this
				});
			},
			scope:this
		}]
	});
};

Ext.extend(NGMP.dialog.SignUpDialog, Ext.Window, {
	show:function() {
		this.formDomainField.store.load({
			callback:function() {
				this.formPanel.load();
			},
			scope:this
		});
		NGMP.dialog.SignUpDialog.superclass.show.call(this);
	}
});
