// Form Separator
Ext.form.separator = Ext.extend(Ext.BoxComponent, { autoEl:{ tag:'div', html:'' }, height:10  });
Ext.reg('separator', Ext.form.separator);	


// Form Tooltip
Ext.form.hint = Ext.extend(Ext.BoxComponent, { text: '', style:'height:18px; margin:0 0 3px 0; padding:4px 0 0 0; text-align:left;',
	initComponent: function(){
		var qtitle=this.title?' ext:qtitle="'+this.title+'"':'';
		Ext.apply(this, { autoEl:{ tag:'div', html:'<img src="img/icons/info.png" alt="'+this.text+'" ext:qtip="'+this.text+'" '+qtitle+' />' } });
		Ext.form.hint.superclass.initComponent.apply(this, arguments);
	}, onRender: function(){ Ext.form.hint.superclass.onRender.apply(this, arguments); }
});			
Ext.reg('hint', Ext.form.hint);	


// preconfigured combo
Ext.form.myCombo = Ext.extend(Ext.form.ComboBox, { triggerAction: 'all', mode:'local', editable:false, emptyText:'Please select' });
Ext.reg('myCombo', Ext.form.myCombo);	


// preconfigured form
Ext.myForm = Ext.extend(Ext.FormPanel, { autoHeight:true, frame:true, defaultType:'myCombo', defaults:{ width: 218 }, style:'margin-bottom:5px;'  });




// summary box 
Ext.SumBox = Ext.extend(Ext.ToolTip, { 
	initComponent: function(){
		Ext.apply(this, { 
			frame:true, autoHide:false, dismissDelay: 0, header: true, width: 260, shim:false, targetXY:'', floating:false, cls:'sumbox',
			tools:[ {id:'close', handler: function(e,t,p){ removeElement(p.name); p.getEl().slideOut('t',{useDisplay:true}); }}]
		});
		Ext.SumBox.superclass.initComponent.apply(this, arguments);
	} 
	,onRender: function(){ 
		Ext.SumBox.superclass.onRender.apply(this, arguments); 
	},
	slide: function(){
		this.removeClass('x-hide-display');
		this.getEl().slideIn('t',{useDisplay:true});
	}
});


// adding a numeric vtype
Ext.apply(Ext.form.VTypes, { 
	'numericMask' : /\d+/,
	'numericText' : 'Please enter only numbers in this field',
	'numeric': function(v) { 
		var numericRe = /\d+/; return numericRe.test(v); 
	}
});


// adding a numeric vtype
Ext.apply(Ext.form.VTypes, { 
	'cardDateMask' : /\d{0,4}/,
	'cardDate': function(v) { 
		var m=parseInt(v.substr(0,2),10); var y=parseInt(v.substr(2,2),10);
		var thisM=parseInt(new Date().getUTCMonth().toString(),10)+1;
		var thisY=parseInt(new Date().getUTCFullYear().toString().substr(2),10);
		return ((y>thisY)&&(m<=12&&m>=1))||((y==thisY)&&(m>=thisM));
	}			
});

// adding a credit card vtype validation
Ext.apply(Ext.form.VTypes, { 'cardMask' : /\d+/, 'cardText' : 'Card number fails validity test', 
	'card': function(v) { 
		if (Ext.getCmp('card_type').getValue()=='laser' || !Ext.getCmp('card_type').getValue()) return true;
		var i, sum=0, weight;
		for (i=0; i<v.length-1; i++){ weight=v.substr(v.length-(i+2),1)*(2-(i%2)); sum+=((weight<10)?weight:(weight-9)); }
		return (parseInt(v.substr(v.length-1)) == ((10-sum%10)%10)); 
	}			
});
			

