
/***********************************
FOR CHECK COLUMN ON GRID 
************************************/
Ext.grid.CheckColumn = function(config){
	Ext.apply(this, config);
		if(!this.id){
		this.id = Ext.id();
		}
		this.renderer = this.renderer.createDelegate(this);
	};
	
	Ext.grid.CheckColumn.prototype ={
		init : function(grid){
		this.grid = grid;
		this.grid.on('render', function(){
		var view = this.grid.getView();
		view.mainBody.on('mousedown', this.onMouseDown, this);
		}, this);
	},
	
	onMouseDown : function(e, t){
		if(t.className && t.className.indexOf('x-grid3-cc-'+this.id) != -1){
		e.stopEvent();
		var index = this.grid.getView().findRowIndex(t);
		var record = this.grid.store.getAt(index);
		record.set(this.dataIndex, !record.data[this.dataIndex]);
		}
	},
	
	renderer : function(v, p, record){
		p.css += ' x-grid3-check-col-td';
		return '<div class="x-grid3-check-col'+(v?'-on':'')+' x-grid3-cc-'+this.id+'"> </div>';
		}
};

/**************************************************
FOR VALIDATE DATE RANGE AND PASSWORD 

* ================ Date Range Verification =======================

 var dr = new Ext.FormPanel({
      labelWidth: 125,
      frame: true,
      title: 'Date Range',
	  bodyStyle:'padding:5px 5px 0',
	  width: 350,
      defaults: {width: 175},
      defaultType: 'datefield',
      items: [{
        fieldLabel: 'Start Date',
        name: 'startdt',
        id: 'startdt',
        vtype: 'daterange',
        endDateField: 'enddt' // id of the end date field
      },{
        fieldLabel: 'End Date',
        name: 'enddt',
        id: 'enddt',
        vtype: 'daterange',
        startDateField: 'startdt' // id of the start date field
      }]
    });
    
 
     * ================  Password Verification =======================
 
        
    var pwd = new Ext.FormPanel({
      labelWidth: 125,
      frame: true,
      title: 'Password Verification',
      bodyStyle:'padding:5px 5px 0',
      width: 350,
      defaults: {
        width: 175,
        inputType: 'password'
      },
      defaultType: 'textfield',
      items: [{
        fieldLabel: 'Password',
        name: 'pass',
        id: 'pass'
      },{
        fieldLabel: 'Confirm Password',
        name: 'pass-cfrm',
        vtype: 'password',
        initialPassField: 'pass' // id of the initial password field
      }]
    });
    
****************************************************/
// Add the additional 'advanced' VTypes
Ext.apply(Ext.form.VTypes, {
  daterange: function(val, field) {
    var date = field.parseDate(val);
    
    // We need to force the picker to update values to recaluate the disabled dates display
    var dispUpd = function(picker) {
      var ad = picker.activeDate;
      picker.activeDate = null;
      picker.update(ad);
    };
    
    if (field.startDateField) {
      var sd = Ext.getCmp(field.startDateField);
      sd.maxValue = date;
      if (sd.menu && sd.menu.picker) {
        sd.menu.picker.maxDate = date;
        dispUpd(sd.menu.picker);
      }
    } else if (field.endDateField) {
      var ed = Ext.getCmp(field.endDateField);
      ed.minValue = date;
      if (ed.menu && ed.menu.picker) {
        ed.menu.picker.minDate = date;
        dispUpd(ed.menu.picker);
      }
    }
    /* Always return true since we're only using this vtype
     * to set the min/max allowed values (these are tested
     * for after the vtype test)
     */
    return true;
  },
  
  password: function(val, field) {
    if (field.initialPassField) {
      var pwd = Ext.getCmp(field.initialPassField);
      return (val == pwd.getValue());
    }
    return true;
  },
  
  passwordText: 'Passwords do not match',
  
  email:function(val, field) {
  	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(val))
		return true;
	else 
		return false;
  },
  emailText:'Email address not valid',
  
  emailconfirm:function(val, field) {
  	if(field.initialEmailField) {
  		var email = Ext.getCmp(field.initialEmailField);
  		return (val==email.getValue());
  	}
  	return true;
  },
  emailconfirmText:'Email do not match',
  
  minValue:function(val, field) {
  	if(field.minVotes)
  		return (val >= field.minVotes);
  	else
  		return fals;
  },
  minValueText:'YOUR VOTES DID NOT MEET THE REQUIRED MINIMUM'
  
});


