Ext.ns('com.applicationserverprovider.com');

//the blank image
Ext.BLANK_IMAGE_URL = 'http://wilsonalvarez.com/ext-2.3.0/resources/images/default/s.gif';

Ext.onReady(function() {
			var member_id=-1;
			var member_idto=-1;					
var txtfrom = new Ext.form.ComboBox({
		fieldLabel:'From',
		renderTo:'divfrom',
		selectOnFocus :false,
		style:'border:thin solid #01BEBE;',
		store: new Ext.data.JsonStore({
			url:'addmsj.php',
			id:'storefrom',
			root: 'data',
			baseParams:{type:'load'},
			fields: ['member_id','name']
			}),
		displayField: 'name',
		name:'member_id_from',
		id:'txtfrom',
		hiddenName:'member_id',
		enableKeyEvents:true,
		mode: 'local',
		listeners:{
			select:function(combo,record,index){
			 member_id=record.get('member_id');
			 if(member_id!=-1){
			 Ext.getCmp('txtto').setDisabled(false);
			 	if(Ext.getCmp('txtto').getValue()==combo.getValue()){
						Ext.getCmp('txtto').setValue('');
						member_idto=-1;}
				}
			 else{
			 Ext.getCmp('txtto').setDisabled(true);
			 Ext.getCmp('txtto').setValue('');
			 combo.setValue('');
			 }
			 } ,
		focus  :function(combo){
			Ext.getCmp('txtfrom').getStore().load({params:{type:'loadall'}});
			},
		keyup:function(field,combo){
				Ext.getCmp('txtfrom').getStore().load({params:{type:'load',name:field.getValue()},
			callback: function(r,options,success){
				if(success == false) {
					//alert('nada');
				}
						}
					})

				}
				}
		
		});
var txtto = new Ext.form.ComboBox({
		fieldLabel:'To',
		renderTo:'divto',
		disabled:true,
		selectOnFocus :false,
		style:'border: thin solid #01BEBE;',
		store: new Ext.data.JsonStore({
			url:'addmsj.php',
			id:'storeto',
			root: 'data',
			baseParams:{type:'load'},
			fields: ['member_id','name']
			}),
		displayField: 'name',
		name:'member_id_to',
		id:'txtto',
		hiddenName:'member_id',
		enableKeyEvents:true,
		mode: 'local',
		listeners:{
			select:function(combo,record,index){
			 member_idto=record.get('member_id');
			
			 } ,
		focus  :function(combo){
		Ext.getCmp('txtto').getStore().load({params:{type:'loadall2',member_id:member_id}});
			},
		keyup:function(field,combo){
				Ext.getCmp('txtto').getStore().load({params:{type:'loadto',member_id:member_id,name:field.getValue()},
			callback: function(r,options,success){
				if(success == false) {
					//alert('nada');
				}
						}
					})

				}
				}
	});

	var btnsubmit = new Ext.Button({		 
		text:'Send',
		width:80,
		renderTo:'divbtn',
		handler:function(){
			if(member_id!=-1 && member_idto!=-1){
				
var myMask = new Ext.LoadMask(document.getElementById('form'), {msg:"submit data pleas wait..."});
							myMask.show();
					 var o = {
						 url:'addmsj.php'
						,method:'post'
						,success:function(){
						document.getElementById('divmsj').innerHTML="<ul style='display:inline;float:left'><li style='display:inline-block;float:left; padding:1px 5px 2px 0;'><img src='images/ok.gif'></li><li style='display:inline-block;list-style:none; line-height:25px'><div style='color:#00B0B0; padding-left: 3px;'>Successful send </div></li></ul>";
							myMask.hide();}
   						,failure: function(){
						document.getElementById('divmsj').innerHTML="<ul style='display:inline;float:left'><li style='display:inline-block;float:left; padding:1px 5px 2px 0;'><img src='images/falue.gif'></li><li style='display:inline-block;list-style:none; line-height:25px'><div style='color:#00B0B0; padding-left: 3px;'>send failed</div></li></ul>";
							myMask.hide();}
						,scope:this
						,params:{
							 type:'insert'
							 ,member_id_from:member_id
							,member_id_to:member_idto
							,note:document.getElementById('coments').value
						}
					};
					Ext.Ajax.request(o);
		}else
		Ext.Msg.show({
		   title:'Error...',
		   msg: '<d style=" color:#415EA0">You must enter the fields</d>',
		   animEl: 'coments',
		   minWidth :200,
		   icon: Ext.MessageBox.WARNING
		});


			
			}
							 });
	/*
	     var win = new Ext.Window({
            title: 'Yellow Pad',
            closable:true,
            width: 700,
			height:545,
            tools: [{
					id:'close',
			   		handler : function(){ 
					init=true;
					exit(); } //handler
			}],
            plain:true,
            layout: 'border',
			tbar: {
                    xtype: 'toolbar',
                    items: [
                        {
                            xtype: 'button',
                            text: 'MyButton'
                        },
                        {
                            xtype: 'tbseparator'
                        },
                        {
                            xtype: 'button',
                            text: 'MyButton'
                        }
                    ]
                },
                items: [
                    {
                        xtype: 'grid',
                        region: 'center',
                        border: false,
                        columns: [
                            {
                                xtype: 'gridcolumn',
                                dataIndex: 'string',
                                header: 'Column',
                                sortable: true,
                                width: 100
                            },
                            {
                                xtype: 'numbercolumn',
                                dataIndex: 'number',
                                header: 'Column',
                                sortable: true,
                                width: 100,
                                align: 'right'
                            },
                            {
                                xtype: 'datecolumn',
                                dataIndex: 'date',
                                header: 'Column',
                                sortable: true,
                                width: 100
                            },
                            {
                                xtype: 'booleancolumn',
                                dataIndex: 'bool',
                                header: 'Column',
                                sortable: true,
                                width: 100
                            }
                        ],
                        bbar: {
                            xtype: 'paging'
                        }
					}
				]
        });
		
		win.on('beforeshow',function(){
			if(screen.height<700){
				win.setPosition(50,50);	
			}
							});
		
		win.on('move',function(){
			if(win.getPosition(true)[1]<=0){
				win.setPosition(win.getPosition(true)[0],50);	
				}
							
							});
	var div = Ext.get('btnlogin');
	
	div.on('click', function(){
	
	//if(init==true){
		win.show(this);
		//}
	//else win2.show(this);
	});
	*/
	
	
}); // eo function onReady
