function adjustHeight(){
	var wrapperH=Ext.get('content_wrapper');
	var screenH=Ext.getBody();
	if ( (screenH.getHeight()-206) > wrapperH.getHeight() ){
		Ext.get('footer_wrapper').applyStyles('position:absolute; bottom:-5px; width: 100%;');
		Ext.getBody().applyStyles('margin:0; padding: 0; overflow: hidden;');
	}
}

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


//*** PROTOTYPE OVERWRITING *********************************************************************************
Ext.form.Field.prototype.msgTarget = 'side';

Ext.form.XmlErrorReader = function(){ Ext.form.XmlErrorReader.superclass.constructor.call(this, { record : 'field', success: '@success' }, ['id', 'msg' ] ); };
Ext.extend(Ext.form.XmlErrorReader, Ext.data.XmlReader);

// prevent from submitting emptyText value
Ext.form.Action.Submit.prototype.run = Ext.form.Action.Submit.prototype.run.createInterceptor(function() {
	this.form.items.each(function(item) {
		if (item.el.getValue() == item.emptyText) item.el.dom.value = '';
	});
});
Ext.form.Action.Submit.prototype.run = Ext.form.Action.Submit.prototype.run.createSequence(function() {
	this.form.items.each(function(item) {
		if (item.el.getValue() == '' && item.emptyText) item.el.dom.value = item.emptyText;
	});
 });
 

// enabling keyup, keypress and other events on text fields
Ext.override(Ext.form.Field, {
    fireKey : function(e){ if(((Ext.isIE && e.type == 'keydown') || e.type == 'keypress' ) && e.isSpecialKey()) this.fireEvent('specialkey', this, e); else this.fireEvent(e.type, this, e); },
    initEvents : function() {
        this.el.on("focus", this.onFocus,  this);
        this.el.on("blur", this.onBlur,  this);
        this.el.on("keydown", this.fireKey, this);
        this.el.on("keypress", this.fireKey, this);
        this.el.on("keyup", this.fireKey, this);
        this.originalValue = this.getValue(); // reference to original value for reset
    }
});

Ext.override(Ext.form.TextField, { // vtype=email validation problem for opera
	filterKeys : function(e){
		var k = e.getKey();
		if(e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1)) return;
		var c = e.getCharCode(), cc = String.fromCharCode(c);
		if(!Ext.isGecko && e.isSpecialKey() && !cc) return;
		if(!this.maskRe.test(cc)) e.stopEvent();
	}
});

//*** Additional Form Validation Types **********************************************************************
Ext.apply(Ext.form.VTypes, { 
	// numeric vtype validation
	numericMask: /\d+/,
	numericText: 'Please enter numbers only', 
	numeric: function(v){ return /^\d+$/.test(v) },
	
	// phone vtype validation
	phoneMask: /\d+/,
	phoneText: 'Please enter a valid Irish mobile number<br>10 digits only, starting with 08', 
	phone: function(v){
		return /^\d{10}$/.test(v)&&(v.substr(0,2)=='08') 
	},

	// credit card expiry date vtype validation
	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));
	},

	// credit card vtype validation
	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)); 
	}
});



// ajax popup window
Ext.Popup = Ext.extend(Ext.Window, {
	width: 700, height:600,
	listeners:{ beforeshow: function(w){w.center()} },
	   
	initComponent: function(conf){
		Ext.apply(this, { 
			constrain: true, resizable: false, layout: 'fit', modal:true, plain:true, bodyStyle:'padding:10px;',
			buttonAlign:'center', closeAction:'hide', autoScroll:true,
			buttons: [ { text: 'Close', scope:this, handler: this.hideWin } ]
		});
		Ext.Popup.superclass.initComponent.call(this);
	},
	hideWin: function(){ this.hide() },
	onRender: function(){ Ext.Popup.superclass.onRender.apply(this, arguments); }		
});

