Wtf.crm.newActivityGrid = function(config){
     Wtf.crm.newActivityGrid.superclass.constructor.call(this, config);
     this.addEvents= {
        "refreshActivityhomegrid": true
     }
}
Wtf.extend(Wtf.crm.newActivityGrid, Wtf.Panel,{
    onRender : function(config) {
        Wtf.crm.newActivityGrid.superclass.onRender.call(this,config);
        this.getField();
        this.add(new Wtf.Panel({
            border: false,
            layout:'fit',
            autoSroll:true,
            tbar:[{
                    text: 'New Task',id: this.id + 'newtaskacc',iconCls:'pwnd newcal caltb',tooltip:'Click to add New Task',
                    handler: this.onNewClick,scope: this
                },'-',{
                    text: 'New Event',id: this.id + 'neweventacc',iconCls: 'pwnd newcal caltb',tooltip:'Click to add New Event',
                    handler:this.onNewEventClick,scope:this
                },'-',{
                    text: 'Edit',id: this.id + 'editTaskEvent',disabled :true,iconCls:'pwnd RevisionList',tooltip:'Click to edit Task',
                    handler:this.onEditTaskEventClick,scope:this
                }],
            items:[this.opActgrid]

        }));
        //this.opActgrid.on("rowdblclick",this.opActgriddblClick,this);
        this.sm2.on('selectionchange', this.rowSelectionHandler, this);
        this.on("refreshActivityhomegrid",function(){
          //this.opActaccds.reload();
        });
        
    },
    getField:function(){
         this.opActdataReader = new Wtf.data.JsonReader({
            root: "data",
            fields: [{name: 'taskid'},
                    {name: 'subject'}, 
                    {name: 'name'}, 
                    {name: 'relatedto'},
                    {name: 'task/event'},
                    {name: 'assignedto'}],
           totalProperty: 'totalCount'
        });
       
        this.sm2 = new Wtf.grid.CheckboxSelectionModel({width:25});
         
//        this.opActaccds = new Wtf.data.Store({         
//            reader: this.opActdataReader,
//            url: 'activities.jsp?type=get&id='+this.leadid,
//            method : 'GET'
//        });
        this.opActaccds = new Wtf.data.SimpleStore({
        fields: ['subject','name','relatedto','task/event','assignedto'],
            data : [["Arrange Venue","Meeting","Training","Training","Alex Joseph"],
                    ["Contact TPO","Placement","Placement","Annual Placement","Colin Payne"],
                    ["Training assignment","Study","Training","Training","John Tranter"]
            ]
        });
        
        this.opActacccm= new Wtf.grid.ColumnModel(
          [ new Wtf.grid.RowNumberer(),
            this.sm2,
              {
                 header: "Subject",
                 autoWidth : true,
                 sortable: true,
                 dataIndex:'subject'
              },{
                 header: "Name",
                 autoWidth : true,
                 sortable: true,
                 dataIndex:'name'
              },{
                 header :"Related To",
              autoSize : true,
                 sortable: true,
                 dataIndex:'relatedto'
              },{
                 header :"Task/Event",
              autoSize : true,
                 sortable: true,
                 dataIndex:'task/event'
              },{
                 header :"Assigned to",
              autoSize : true,
                 sortable: true,
                 dataIndex:'assignedto'
              }
          ]);

       this.opActgrid = new Wtf.grid.GridPanel({                            
            store: this.opActaccds,
            title:'Open Activity',
            cm: this.opActacccm,                           
            sm : this.sm2,
            border : false,
            loadMask : true,
            viewConfig: {
                forceFit:true
            }
       });
//       this.opActaccds.load( {params: {
//                        start:0,
//                        limit:15
//                    }});
    },
   opActgriddblClick:function(grid,rowno){
        var taskid = grid.getSelectionModel().getSelected().data["taskid"];
        var flag = grid.getSelectionModel().getSelected().data["task/event"]=="task"?1:0;
        Wtf.Ajax.request({
               url:'activities.jsp',
               params:{
                    type:'gettaskevent',
                    flag: flag,
                    taskeventid:taskid
               },
               scope: this,
               success: function(result, req){ 
                   var taskeventInfo = eval("(" + result.responseText.trim() + ")");
                   if(flag==1){
                          var isExits = Wtf.getCmp('NewActivity'+this.id+taskid);
                          if(!isExits){
                              var convert = new Wtf.crm.newActivity({
                                                title:taskeventInfo[0].name,
                                                id:'NewActivity'+this.id+taskid,
                                                taskParentId:this.leadid,
                                                taskOwnerid:this.ownerid,
                                                type:'display',
                                                homeTabId:this.id,
                                                info: taskeventInfo,
                                                parentid:this.parentid,
                                                closable:true,
                                                layout:'fit'
                                             })
                              Wtf.getCmp(this.parentid).add(convert); 
                              Wtf.getCmp(this.parentid).activate(convert);
                              Wtf.getCmp(this.parentid).doLayout();
                              convert.showSystemInfo();
                          }else{
                            Wtf.getCmp(this.parentid).activate(isExits);
                              Wtf.getCmp(this.parentid).doLayout();
                           }
                   }else{
                      var isExits = Wtf.getCmp('NewEventActivity'+this.id+taskid);
                      if(!isExits){
                           var convert = new Wtf.crm.newEventActivity({
                                            title:taskeventInfo[0].name,
                                            id:'NewEventActivity'+this.id+taskid,
                                            taskParentId:this.leadid,
                                             type:'display',
                                             homeTabId:this.id,
                                             parentid:this.parentid,
                                             taskOwnerid:this.ownerid,
                                             info: taskeventInfo,
                                            closable:true,
                                            layout:'fit'
                                         });
                           Wtf.getCmp(this.parentid).add(convert); 
                           Wtf.getCmp(this.parentid).activate(convert);
                           Wtf.getCmp(this.parentid).doLayout();
                           convert.showSystemInfo();
                       }else{
                           Wtf.getCmp(this.parentid).activate(isExits);
                           Wtf.getCmp(this.parentid).doLayout();
                       }
                   }
               }
        });
        
   },
   rowSelectionHandler:function(){
      var selected = this.sm2.getSelections();
      if(selected.length==1){
          Wtf.getCmp(this.id + 'editTaskEvent').enable();
      }else{
          Wtf.getCmp(this.id + 'editTaskEvent').disable();
      }  
   },
   onNewClick:function(){
        var isExits = Wtf.getCmp('NewActivity'+this.id);
            if(!isExits){
           var convert = new Wtf.crm.newActivity({
                            title:'New Task',
                            parentid:this.parentid,
                            id:'NewActivity'+this.id,
                            homeTabId:this.id,
                            taskParentId:this.leadid,
                            closable:true,
                            layout:'fit'
                         })
           Wtf.getCmp(this.parentid).add(convert); 
           Wtf.getCmp(this.parentid).activate(convert);
           Wtf.getCmp(this.parentid).doLayout();
           }else{
            Wtf.getCmp(this.parentid).activate(isExits);
              Wtf.getCmp(this.parentid).doLayout();
           }
   },
   onNewEventClick:function(){
          var isExits = Wtf.getCmp('NewEventActivity'+this.id);
          if(!isExits){
           var convert = new Wtf.crm.newEventActivity({
                            title:'New Event',
                            parentid:this.parentid,
                            id:'NewEventActivity'+this.id,
                            homeTabId:this.id,
                            taskParentId:this.leadid,
                            closable:true,
                            layout:'fit'
                         });
           Wtf.getCmp(this.parentid).add(convert); 
           Wtf.getCmp(this.parentid).activate(convert);
             Wtf.getCmp(this.parentid).doLayout();
           }else{
            Wtf.getCmp(this.parentid).activate(isExits);
              Wtf.getCmp(this.parentid).doLayout();
           }
   },
   onEditTaskEventClick:function(){
       //this.opActgriddblClick(this.opActgrid);
   }
})


Wtf.crm.newEventActivity = function(config){
     Wtf.crm.newEventActivity.superclass.constructor.call(this, config);
}
Wtf.extend(Wtf.crm.newEventActivity, Wtf.Panel, {
    onRender : function(config) {
        Wtf.crm.newEventActivity.superclass.onRender.call(this,config);
        this.formField();
        this.add(new Wtf.Panel({
            activeTab: 0,
            id: "crmLeadnewEventActivity" + this.id,
            border: false,
            autoScroll:true,
            cls:'mainTabPanel',
            layout:'fit',
            items: [{
                       border:false,
                        layout:'border',
                       //autoScroll:true,
                        items:[{
                             autoScroll:true,
                            region:'center',
                            bodyStyle:'padding:8px 8px 8px 8px',
                            border: false,
                            layout:'column',
                            items:[this.calenderDetail, this.additionalInfo,this.DescriptionInfo,this.Recurrence,this.reminder,this.systemInfo]
                        }]
                    }],
            tbar:this.getTbar()
        }));
        this.alldayevent.on('select',this.alldayeventChange,this);
         if(this.type&&this.type=='display'){
            this.setValues();
            this.systemInfo.hide();
        }else{
            this.systemInfo.hide();
        }
    },
    alldayeventChange:function(combobox){
        if(combobox.getValue()==0){
           this.eventtime.disable();
        }else if(combobox.getValue()==1){
           this.eventtime.enable();
        }
    },
    getTbar:function(){
        return ([this.saveButt=new Wtf.Action({
                    id: 'But1' + this.id,
                    text: 'Save',
                    scope:this,
                    iconCls: 'pwnd saveicon caltb',
                    handler: this.onSaveClick
                }),'-',this.cancelButt = new Wtf.Action({
                    id: 'Cancel' + this.id,
                    text: 'Cancel',
                    scope:this,
                    iconCls: 'pwnd closeicon caltb',
                    handler: this.onCancleClick
                })]);
    },
     setValues:function(){
      
    
        this.eventdate.setValue(this.info[0].eventdate);
        this.alldayevent.setValue(this.info[0].allday);
        this.eventtime.setValue(this.info[0].eventtime);
        this.relatedto.setValue(this.info[0].relatedto);
        this.name.setValue(this.info[0].name);
        this.privateyn.setValue(this.info[0].private);
        this.location.setValue(this.info[0].location);
        this.description.setValue(this.info[0].description);
        this.recurringevents.setValue(this.info[0].recurringevent);
        this.reminderCheckbox.setValue(this.info[0].reminder);
        if(this.info[0].allday==0){
            this.eventtime.disable();
        }
    },
     getJsonObject:function(ColumnList, ContentList){
        var jsonobj = "{data:[{";
        for(i=0; i < ColumnList.length; i++)
        {
            jsonobj +=  ColumnList[i] +":'" + ContentList[i] + "',";
        }
        jsonobj = jsonobj.substring(0,jsonobj.length-1) + "}]}";
        return jsonobj;
    },
    onSaveClick:function(){
       var ColumnList = new Array('assifneto','subject','eventdate','alldayevent','time','relatedto','name','private','location','showtimeas','description','recurringevent','reminder','taskParentId');
       var ContentList = new Array(this.assignedto.getValue(),this.subject.getValue(),this.eventdate.getValue(),this.alldayevent.getValue(),
                                    this.eventtime.getValue(),this.relatedto.getValue(),this.name.getValue(),this.privateyn.getValue(),this.location.getValue(),
                                this.showtime.getValue(),this.description.getValue(),this.recurringevents.getValue(),this.reminderCheckbox.getValue(),this.taskParentId);
     
      if(this.assignedto.getValue()!="" && this.subject.getValue()!=""){
          this.saveButt.disable();
          if(this.type&&this.type=='display'){
            ColumnList.push('taskid');
            ContentList.push(this.info[0].taskid);
            var jsonObj = this.getJsonObject(ColumnList,ContentList);
            Wtf.Ajax.request({
               url:'activities.jsp',
               params:{
                    type:'saveevent',
                    data:jsonObj
               },
               scope: this,
               success: function(result, req){
                  this.removeTab();
                  var home=Wtf.getCmp(this.homeTabId);
                  if(home)
                        home.fireEvent("refreshActivityhomegrid");
                  Wtf.MessageBox.show({
                        //title: 'ERROR',
                        msg: 'Event saved successfully',
                        buttons: Wtf.MessageBox.OK,
                        animEl: 'ok'
                    });
                    this.saveButt.enable();
               }

           });
          }else{
              var jsonObj = this.getJsonObject(ColumnList,ContentList);
              Wtf.Ajax.request({
                   url:'activities.jsp',
                   params:{
                        type:'event',
                        data:jsonObj
                   },
                   scope: this,
                   success: function(result, req){ 
                      this.removeTab();
                      var home=Wtf.getCmp(this.homeTabId);
                      if(home)
                            home.fireEvent("refreshActivityhomegrid");
                      Wtf.MessageBox.show({
                            //title: 'ERROR',
                            msg: 'Event created successfully',
                            buttons: Wtf.MessageBox.OK,
                            animEl: 'ok'
                        });
                      this.saveButt.enable();  
                   }

               });
           }
       }else{
             Wtf.MessageBox.show({
                        title: 'ERROR',
                        msg: 'Please enter required field!',
                        buttons: Wtf.MessageBox.OK,
                        animEl: 'ok',
                        icon: Wtf.MessageBox.ERROR
                    });
       }
     
        
    },
    onCancleClick:function(){
        this.removeTab();
    },
    removeTab:function(){
        var tab = Wtf.getCmp(this.parentid);
        if(tab)
            tab.remove(this); 
    },
    showSystemInfo:function(){
            var createdby = this.info[0].createdby;
            var editedby = this.info[0].editedby;
            var leadCreationDate=Date.parseDate(this.info[0].creationdate,"Y-m-d H:i:s.0").format("d/m/Y");
            var leadmodificationdate=Date.parseDate(this.info[0].timestamp,"Y-m-d H:i:s.0").format("d/m/Y");
            this.systemInfoTpl.overwrite(Wtf.getCmp("Created By_"+this.id).el.dom.firstChild, eval({"datetime":createdby+', '+leadCreationDate,"title":'Created By :'})); 
            this.systemInfoTpl.overwrite(Wtf.getCmp("Lead Owner_"+this.id).el.dom.firstChild, eval({"datetime":editedby+', '+leadmodificationdate,"title":'Last Edited By :'})); 
    },
     systemInfoTpl : new Wtf.XTemplate(
         '<tpl for=".">'
            +'<div style = "font-size:11px;color:black;height:100%;overflow:auto;">'
                +'<table style ="font-size:12px">'
                    +'<tr>'
                        +'<td align = "left" width="100">'
                        +'<div>{title} </div>'
                    +'</td>'
                    +'<td align = "left" width="280">'
                        +'<div> {datetime}</div>'
                    +'</td>'
                +'</tr>'
              +'</table>'
            +'</div>'
        +'</tpl>'
     ),
   
    formField:function(){
        var contactReader = new Wtf.data.Record.create([
            {name: 'ownerid', type: 'string'},
            {name: 'ownername', type: 'string'}
        ]);

        this.viewStoreAssignTo = new Wtf.data.SimpleStore({
            fields: ['viewid','view'],
          data : [[0,"Rachel Aniston"],
                  [1,"Michelle Bond"],
                  [2,"Thomas Demello"],
                  [3,'Johan Rellinda'],
                    [4,'--None--']]
        });
        //viewStoreAssignTo.load();
//        viewStoreAssignTo.on("load",function(){
//             if(this.type&&this.type=='display'){
//                   this.assignedto.setValue(this.taskOwnerid);
//             }
//        },this);
        var comboReader = new Wtf.data.Record.create([
            {name: 'id', type: 'string'},
            {name: 'name', type: 'string'}
        ]);

        this.viewStoreSubject = new Wtf.data.SimpleStore({
            fields: ['id','name'],
              data : [[0,"Call"],
                      [1,"Send letter"],
                      [2,"Send Quote"],
                      [3,'Other']]
        });
//        viewStoreSubject.load();
//         viewStoreSubject.on("load",function(){
//             if(this.type&&this.type=='display'){
//                      this.subject.setValue(this.info[0].subject);
//             }
//        },this);
        this.viewStoreYesNo = new Wtf.data.SimpleStore({
              fields: ['viewid','view'],
              data : [[0,"Yes"],
                      [1,"No"]]
        });
        
        this.viewTime = new Wtf.data.SimpleStore({
           fields: ['id','name'],
              data : [[0,"Busy"],
                      [1,"Out of Office"],
                      [2,"Free"]]
        });
        //viewTime.load();
//        viewTime.on("load",function(){
//             if(this.type&&this.type=='display'){
//                     this.showtime.setValue(this.info[0].showas);
//             }
//        },this);
        this.calenderDetail = new Wtf.form.FieldSet({
          title:"Calendar Details",
          columnWidth:1,
          bodyStyle:'padding:8px 8px 8px 8px',
          layout:"column",
          border:false,
          height:220,
          items:[{
             columnWidth : .5,
             layout : "form",
           //  bodyStyle:'padding:8px 8px 8px 8px',
              border:false,
              //lableWidth: 120,
              items:[this.assignedto = new Wtf.form.ComboBox({
                         fieldLabel: 'Assigned To',
                         store: this.viewStoreAssignTo,
                         displayField: 'view',
                         valueField: 'viewid',
                         anchor:'100%',
                         selectOnFocus:true,
                         triggerAction: 'all',
                         editable: false,
                         mode: 'local'
                     }),this.subject=new Wtf.form.ComboBox({
                         fieldLabel: 'Subject',
                          store: this.viewStoreSubject,
                         displayField: 'name',
                         valueField: 'id',
                         anchor:'100%',
                         selectOnFocus:true,
                         triggerAction: 'all',
                         editable: false,
                         mode: 'local'
                     }),this.name=new Wtf.form.TextField({
                         fieldLabel: 'Event Name',
                         width:'70%'
                     }),this.eventdate = new Wtf.form.DateField({
                         fieldLabel: 'Event Date',
                         width:'70%'
                     }),this.alldayevent=new Wtf.form.ComboBox({
                         fieldLabel: 'All Day Event',
                          store: this.viewStoreYesNo,
                         displayField: 'view',
                         valueField: 'viewid',
                         anchor:'100%',
                         selectOnFocus:true,
                         triggerAction: 'all',
                         editable: false,
                         mode: 'local'
                     }),this.eventtime = new Wtf.form.TimeField({
                         fieldLabel: 'eventTime',
                         increment:5,
                         width:'70%'
                     })
              ]
             },{
             columnWidth : .5,
             layout : "form",
           //  bodyStyle:'padding:8px 8px 8px 8px',
              border:false,
              //lableWidth: 120,
              items:[this.relatedto = new Wtf.form.TextField({
                         fieldLabel: 'Related To',
                         width:'70%'
                     }),this.privateyn=new Wtf.form.ComboBox({
                         fieldLabel: 'Private',
                          store: this.viewStoreYesNo,
                         displayField: 'view',
                         valueField: 'viewid',
                         anchor:'100%',
                         selectOnFocus:true,
                         triggerAction: 'all',
                         editable: false,
                         mode: 'local'
                     })
              ]
            }]                
      });
      this.additionalInfo = new Wtf.form.FieldSet({
          title:"Other Information",
          columnWidth:1,
          bodyStyle:'padding:8px 8px 8px 8px',
          layout:"column",
          border:false,
          height:100,
          items:[{
             columnWidth : 1,
             layout : "form",
           //  bodyStyle:'padding:8px 8px 8px 8px',
              border:false,
              //lableWidth: 120,
              items:[this.location=new Wtf.form.TextField({
                         fieldLabel: 'Location',
                         width:'70%'
                     }),this.showtime = new Wtf.form.ComboBox({
                         fieldLabel: 'Show Time As',
                         store: this.viewTime,
                         displayField: 'name',
                         valueField:'id',
                         anchor:'100%',
                         selectOnFocus:true,
                         triggerAction: 'all',
                         editable: false,
                         mode: 'local'
                     })
              ]
             }]
      });
       this.DescriptionInfo = new Wtf.form.FieldSet({
          title:"Description Information",
          columnWidth:1,
          bodyStyle:'padding:8px 8px 8px 8px',
          layout:"column",
          border:false,
          height:100,
          items:[{
             columnWidth : 1,
             layout : "form",
           //  bodyStyle:'padding:8px 8px 8px 8px',
              border:false,
              //lableWidth: 120,
              items:[this.description=new Wtf.form.TextArea({
                        fieldLabel:'Description',
                         anchor:'100%',
                          width:'70%'
                     })
              ]
             }]
      });
      this.Recurrence = new Wtf.form.FieldSet({
          title:"Recurrence",
          columnWidth:1,
          bodyStyle:'padding:8px 8px 8px 8px',
          layout:"column",
          border:false,
          height:80,
          items:[{
             columnWidth : 1,
             layout : "form",
           //  bodyStyle:'padding:8px 8px 8px 8px',
              border:false,
              lableWidth: 120,
              items:[this.recurringevents = new Wtf.form.ComboBox({
                         fieldLabel: 'Create recurring series of events',
                          store: this.viewStoreYesNo,
                         displayField: 'view',
                         valueField:'viewid',
                         anchor:'100%',
                         selectOnFocus:true,
                         triggerAction: 'all',
                         editable: false,
                         mode: 'local'
                     })
              ]
             }]
      });
       this.reminder = new Wtf.form.FieldSet({
          title:"Reminder",
          columnWidth:1,
          bodyStyle:'padding:8px 8px 8px 8px',
          layout:"column",
          border:false,
          height:80,
          items:[{
             columnWidth : 1,
             layout : "form",
           //  bodyStyle:'padding:8px 8px 8px 8px',
              border:false,
              //lableWidth: 120,
              items:[this.reminderCheckbox = new Wtf.form.ComboBox({
                         fieldLabel: 'Reminder',
                          store: this.viewStoreYesNo,
                         displayField: 'view',
                         valueField:'viewid',
                         anchor:'100%',
                         selectOnFocus:true,
                         triggerAction: 'all',
                         editable: false,
                         mode: 'local'
                     })
              ]
             }]
      });
      this.systemInfo = new Wtf.form.FieldSet({
                        title: 'System Information',
                        border: false,
                        height:50,
                        columnWidth:1,
                        layout:'column',
                        items: [{
                            columnWidth:0.5,
                            border: false,
                            layout:'form',
                            bodyStyle:'padding:8px 8px 8px 8px',
                            labelWidth:120,
                            items: [{
                                        xtype:'panel',
                                        border:false,
                                        paging:false,
                                        width:'100%',
                                        id:'Created By_'+this.id,
                                        autoLoad : false
                                    }]
                        },{
                            columnWidth:0.5,
                            border: false,
                            layout:'form',
                            bodyStyle:'padding:8px 8px 8px 8px',
                            labelWidth:120,
                            items: [{
                                        xtype:'panel',
                                        border:false,
                                        paging:false,
                                        width:'100%',
                                        id:'Lead Owner_'+this.id,
                                        autoLoad : false
                                    }]
                        }]
                    });
    }
    
})




Wtf.crm.newActivity = function(config){
     Wtf.crm.newActivity.superclass.constructor.call(this, config);
}
Wtf.extend(Wtf.crm.newActivity, Wtf.Panel, {
    onRender : function(config) {
        Wtf.crm.newActivity.superclass.onRender.call(this,config);
        this.formField();
        this.add(new Wtf.Panel({
            activeTab: 0,
            id: "crmLeadnewActivity" + this.id,
            border: false,
            autoScroll:true,
            cls:'mainTabPanel',
            layout:'fit',
            items: [{
                       border:false,
                        layout:'border',
                       //autoScroll:true,
                        items:[{
                             autoScroll:true,
                            region:'center',
                            bodyStyle:'padding:8px 8px 8px 8px',
                            border: false,
                            layout:'column',
                            items:[this.convertLead, this.additionalInfo,this.reminder,this.systemInfo]
                        }]
                    }],
            tbar:this.getTbar()
        }));
        if(this.type&&this.type=='display'){
            this.setValues();
        }else{
            this.systemInfo.hide();
        }
    },
    setValues:function(){
    
       //this.subject.setValue(this.info[0].subject);
       this.duedate.setValue(this.info[0].duedate);
       this.comments.setValue(this.info[0].comments);
       this.relatedto.setValue(this.info[0].relatedto);
       this.name.setValue(this.info[0].name);
       //this.status.setValue(this.info[0].status);
       //this.priority.setValue(this.info[0].priority);
       this.notification.setValue(this.info[0].notification);
      this.remindercheck.setValue(this.info[0].reminder);
    },
    getTbar:function(){
        return ([this.saveButt = new Wtf.Action({
                    id: 'But1' + this.id,
                    text: 'Save',
                    scope:this,
                    iconCls: 'pwnd saveicon caltb',
                    handler: this.onSaveClick
                }),'-', this.cancelButt = new Wtf.Action({
                    id: 'But2' + this.id,
                    text: 'Cancel',
                    scope:this,
                    iconCls: 'pwnd closeicon caltb',
                    handler: this.onCancleClick
                })]);
    },
    onSaveClick:function(){
       var ColumnList = new Array('assifneto','subject','duedate','comments','relatedto','name','status','priority','notification','reminder','taskParentId');
       var ContentList = new Array(this.assignedto.getValue(),this.subject.getValue(),this.duedate.getValue(),this.comments.getValue(),
                                    this.relatedto.getValue(),this.name.getValue(),this.status.getValue(),this.priority.getValue(),this.notification.getValue(),
                                this.remindercheck.getValue(),this.taskParentId);
     
      if(this.assignedto.getValue()!="" && this.subject.getValue()!=""){
          this.saveButt.disable();
          if(this.type&&this.type=='display'){
            ColumnList.push('taskid');
            ContentList.push(this.info[0].taskid);
            var jsonObj = this.getJsonObject(ColumnList,ContentList);
            Wtf.Ajax.request({
               url:'activities.jsp',
               params:{
                    type:'savetask',
                    data:jsonObj
               },
               scope: this,
               success: function(result, req){
                  this.removeTab();
                  var home=Wtf.getCmp(this.homeTabId);
                  if(home)
                        home.fireEvent("refreshActivityhomegrid");
                  Wtf.MessageBox.show({
                        //title: 'ERROR',
                        msg: 'Task saved successfully',
                        buttons: Wtf.MessageBox.OK,
                        animEl: 'ok'
                    });
                    this.saveButt.enable();
               }

           });
          }else{
              var jsonObj = this.getJsonObject(ColumnList,ContentList);
              Wtf.Ajax.request({
                   url:'activities.jsp',
                   params:{
                        type:'task',
                        data:jsonObj
                   },
                   scope: this,
                   success: function(result, req){ 
                      this.removeTab();
                      var home=Wtf.getCmp(this.homeTabId);
                      if(home)
                        home.fireEvent("refreshActivityhomegrid"); 
                      Wtf.MessageBox.show({
                            //title: 'ERROR',
                            msg: 'Task created successfully',
                            buttons: Wtf.MessageBox.OK,
                            animEl: 'ok'
                        });
                        this.saveButt.enable();
                   }

               });
           }
       }else{
             Wtf.MessageBox.show({
                        title: 'ERROR',
                        msg: 'Please enter required field!',
                        buttons: Wtf.MessageBox.OK,
                        animEl: 'ok',
                        icon: Wtf.MessageBox.ERROR
                    });
       }
         
    },
    getJsonObject:function(ColumnList, ContentList){
        var jsonobj = "{data:[{";
        for(i=0; i < ColumnList.length; i++)
        {
            jsonobj +=  ColumnList[i] +":'" + ContentList[i] + "',";
        }
        jsonobj = jsonobj.substring(0,jsonobj.length-1) + "}]}";
        return jsonobj;
    },
    showSystemInfo:function(){
            var createdby = this.info[0].createdby;
            var editedby = this.info[0].editedby;
            var leadCreationDate=Date.parseDate(this.info[0].creationdate,"Y-m-d H:i:s.0").format("d/m/Y");
            var leadmodificationdate=Date.parseDate(this.info[0].timestamp,"Y-m-d H:i:s.0").format("d/m/Y");
            this.systemInfoTpl.overwrite(Wtf.getCmp("Created By_"+this.id).el.dom.firstChild, eval({"datetime":createdby+', '+leadCreationDate,"title":'Created By :'})); 
            this.systemInfoTpl.overwrite(Wtf.getCmp("Lead Owner_"+this.id).el.dom.firstChild, eval({"datetime":editedby+', '+leadmodificationdate,"title":'Last Edited By :'})); 
    },
     systemInfoTpl : new Wtf.XTemplate(
         '<tpl for=".">'
            +'<div style = "font-size:11px;color:black;height:100%;overflow:auto;">'
                +'<table style ="font-size:12px">'
                    +'<tr>'
                        +'<td align = "left" width="150">'
                        +'<div>{title} </div>'
                    +'</td>'
                    +'<td align = "left" width="280">'
                        +'<div> {datetime}</div>'
                    +'</td>'
                +'</tr>'
              +'</table>'
            +'</div>'
        +'</tpl>'
     ),
    onCancleClick:function(){
        this.removeTab();
    },
    removeTab:function(){
        var tab = Wtf.getCmp(this.parentid);
        if(tab)
            tab.remove(this); 
    },
    formField:function(){
        var contactReader = new Wtf.data.Record.create([
            {name: 'ownerid', type: 'string'},
            {name: 'ownername', type: 'string'}
        ]);

        this.viewStoreAssignTo = new Wtf.data.SimpleStore({
            fields: ['ownerid','ownername'],
          data : [[0,"Rachel Aniston"],
                  [1,"Michelle Bond"],
                  [2,"Thomas Demello"],
                  [3,'Johan Rellinda'],
                    [4,'--None--']]
        });
//        viewStoreAssignTo.load();
//         viewStoreAssignTo.on("load",function(){
//             if(this.type&&this.type=='display'){
//                   this.assignedto.setValue(this.taskOwnerid);
//             }
//        },this);
        var comboReader = new Wtf.data.Record.create([
            {name: 'id', type: 'string'},
            {name: 'name', type: 'string'}
        ]);

        this.viewStoreSubject = new Wtf.data.SimpleStore({
            fields: ['id','name'],
              data : [[0,"Call"],
                      [1,"Send letter"],
                      [2,"Send Quote"],
                      [3,'Other']]
        });
//        viewStoreSubject.load();
//        viewStoreSubject.on('load',function(){
//            if(this.type&&this.type=='display'){
//                this.subject.setValue(this.info[0].subject);
//            }
//        },this);
        this.viewStatus = new Wtf.data.SimpleStore({
            
        fields: ['id','name'],
              data :[[0,"Not Started"],
                      [1,"In Progress"],
                      [2,"Completed"],
                      [3,'Waiting on Someone else'],
                      [4,'Deferred']]
        });
//        viewStatus.load();
//        viewStatus.on("load",function(){
//            if(this.type&&this.type=='display'){
//                this.status.setValue(this.info[0].status);
//            }
//        },this)
        this.viewPriority = new Wtf.data.SimpleStore({
            fields: ['id','name'],
              data : [[0,"High"],
                      [1,"Low"],
                      [2,"Normal"]]
        });
//        viewPriority.load();
//        viewPriority.on("load",function(){
//            if(this.type&&this.type=='display'){
//                this.priority.setValue(this.info[0].priority);
//            }
//      
//        },this)
        this.viewStoreYesNo = new Wtf.data.SimpleStore({
              fields: ['viewid','view'],
              data : [[0,"Yes"],
                      [1,"No"]]
        });
        
        this.convertLead = new Wtf.form.FieldSet({
          title:"Task Information",
          columnWidth:1,
          bodyStyle:'padding:8px 8px 8px 8px',
          layout:"column",
          border:false,
          height:220,
          items:[{
             columnWidth : .5,
             layout : "form",
           //  bodyStyle:'padding:8px 8px 8px 8px',
              border:false,
              lableWidth: 120,
              items:[this.assignedto=new Wtf.form.ComboBox({
                         fieldLabel: 'Assigned To',
                         store: this.viewStoreAssignTo,
                         displayField: 'ownername',
                         valueField: 'ownerid',
                         anchor:'100%',
                         selectOnFocus:true,
                         triggerAction: 'all',
                         editable: false,
                         mode: 'local'
                     }),this.subject=new Wtf.form.ComboBox({
                         fieldLabel: 'Subject',
                         id:this.id+'comboBox2',
                          store: this.viewStoreSubject,
                         displayField: 'name',
                         valueField:'id',
                         anchor:'100%',
                         selectOnFocus:true,
                         triggerAction: 'all',
                         editable: false,
                         mode: 'local'
                     }),this.name=new Wtf.form.TextField({
                         fieldLabel: 'Name',
                         width:'70%'
                     }),this.duedate=new Wtf.form.DateField({
                         fieldLabel: 'Due Date',
                         width:'70%'
                     })
              ]
             },{
             columnWidth : .5,
             layout : "form",
           //  bodyStyle:'padding:8px 8px 8px 8px',
              border:false,
              //lableWidth: 120,
              items:[this.relatedto=new Wtf.form.TextField({
                         fieldLabel: 'Related To',
                         width:'70%'
                     }),this.comments=new Wtf.form.TextArea({
                         fieldLabel: 'Comments',
                         width:'70%'
                     })
              ]
            }]                
      });
      this.additionalInfo = new Wtf.form.FieldSet({
          title:"Additional Information",
          columnWidth:1,
          bodyStyle:'padding:8px 8px 8px 8px',
          layout:"column",
          border:false,
          height:120,
          items:[{
             columnWidth : 1,
             layout : "form",
           //  bodyStyle:'padding:8px 8px 8px 8px',
              border:false,
              //lableWidth: 120,
              items:[this.status=new Wtf.form.ComboBox({
                         fieldLabel: 'Status',
                         store: this.viewStatus,
                         displayField: 'name',
                         valueField:'id',
                         anchor:'100%',
                         selectOnFocus:true,
                         triggerAction: 'all',
                         editable: false,
                         mode: 'local'
                     }),this.priority=new Wtf.form.ComboBox({
                         fieldLabel: 'Priority',
                         store: this.viewPriority,
                         displayField: 'name',
                         valueField:'id',
                         anchor:'100%',
                         selectOnFocus:true,
                         triggerAction: 'all',
                         editable: false,
                         mode: 'local'
                     }),this.notification=new Wtf.form.Checkbox({
                       labelSeparator:'',
                       hideLabel:true,
                       boxLabel:'Send Notification Email'
                    })
              ]
             }]
      });
       this.reminder = new Wtf.form.FieldSet({
          title:"Reminder",
          columnWidth:1,
          bodyStyle:'padding:8px 8px 8px 8px',
          layout:"column",
          border:false,
          height:70,
          items:[{
             columnWidth : 1,
             layout : "form",
             border:false,
             items:[this.remindercheck=new Wtf.form.Checkbox({
                         fieldLabel: 'Reminder'
                     })
              ]
             }]
      });
       this.systemInfo = new Wtf.form.FieldSet({
                        title: 'System Information',
                        border: false,
                        height:50,
                        columnWidth:1,
                        layout:'column',
                        items: [{
                            columnWidth:0.5,
                            border: false,
                            layout:'form',
                            bodyStyle:'padding:8px 8px 8px 8px',
                            labelWidth:120,
                            items: [{
                                        xtype:'panel',
                                        border:false,
                                        paging:false,
                                        width:'100%',
                                        id:'Created By_'+this.id,
                                        autoLoad : false
                                    }]
                        },{
                            columnWidth:0.5,
                            border: false,
                            layout:'form',
                            bodyStyle:'padding:8px 8px 8px 8px',
                            labelWidth:120,
                            items: [{
                                        xtype:'panel',
                                        border:false,
                                        paging:false,
                                        width:'100%',
                                        id:'Lead Owner_'+this.id,
                                        autoLoad : false
                                    }]
                        }]
                    });
    }    
     
})