// Written by Ahmad Azarinurazie (aien@pixl8.co.uk) for IIA.
// Created on 12th of May 2009
// This script will automatically adjust all SELECT width for preside form in IE

var IEAutoWidth = {
	width: 0,
	init: function(obj) {
		obj.onmouseover = function() {
			if (IEAutoWidth.width == 0) IEAutoWidth.width = this.offsetWidth | this.style.width;
			this.style.position	= "absolute";
			this.style.width	= "auto";
		};
		obj.onblur = function() {
			if (IEAutoWidth.width != 0) {
				this.style.width = IEAutoWidth.width + "px";
				IEAutoWidth.width = 0;
			}
			this.style.position	= "static";
		};
	}
}

if (typeof(AEvent) == 'undefined') {
	AEvent = {
		add: function(obj, type, fn) {
			if (obj.addEventListener) obj.addEventListener( type, fn, false );
			else if (obj.attachEvent) {
				obj["e"+type+fn] = fn;
				obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
				obj.attachEvent( "on"+type, obj[type+fn] );
			}
		}
	}
}

if (navigator.appName == "Microsoft Internet Explorer") {
	AEvent.add(window, "load", function() {
		var oSelect = document.getElementsByTagName("SELECT");
		
		var isPresideFormElement = function(obj) {
			while (obj.parentNode && obj.parentNode.id != "layers-wrapper") {
				obj = obj.parentNode;
				if (obj.id == "presideform") return true;
			}
			
			return false;
		}
		
		for (var i=0; i<oSelect.length; i+=1) if (isPresideFormElement(oSelect[i])) IEAutoWidth.init(oSelect[i]);
	});
}