

function ACPSelect ( divID, linkDiv, text ) {
	this.linkDiv = linkDiv;
	this.linkDiv.onmousedown = function ( e ) {
		e = e || window.event;
		e.cancelBubble = true;
	}

	this.id = ACPSelect.getUID();

	this.div = document.getElementById( divID );

	if (this.div.id != "lnkDiv") {
		this.div.innerHTML = "" +	
		   "<table cellspacing=0 cellpadding=0 border=0><tr>" +
			"<td><img src='/images/sb/boxleft.gif' width=23 height=27><br></td>" +
		   "<td background='/images/sb/boxback.gif' class='selectText' id='" + this.id + "textCell'><nobr>" +
			( text ? text : "" ) +
		   "</nobr></td>" +
			"<td id='" + this.id + "buttonCell'>" +
				"<img src='/images/sb/boxbutton.gif' width=21 height=27 id='" + this.id + "upImage'>" +
				"<img src='/images/sb/boxbuttondown.gif' width=21 height=27 id='" + this.id + "downImage' style='display:none;'>" +
			"</td>" +
			"<td><img src='/images/sb/boxright.gif' width=18 height=27></td>" +
		   "</tr></table>";
	}
	else {
		this.div.innerHTML = "" +	
		   "<table cellspacing=0 cellpadding=0 border=0><tr>" +
			"<td><img src='/images/sb/boxleft1.gif'><br></td>" +
		   "<td background='/images/sb/boxback1.gif' class='selectText' id='" + this.id + "textCell'><nobr>" +
			( text ? text : "" ) +
		   "</nobr></td>" +
			"<td id='" + this.id + "buttonCell'>" +
				"<img src='/images/sb/boxbutton1.gif' id='" + this.id + "upImage'>" +
				"<img src='/images/sb/boxbuttondown1.gif' id='" + this.id + "downImage' style='display:none;'>" +
			"</td>" +
			"<td><img src='/images/sb/boxright1.gif'></td>" +
		   "</tr></table>";
	}
	
	this.textCell = document.getElementById( this.id + "textCell" );
	this.buttonCell = document.getElementById( this.id + "buttonCell" );
	this.upImage = document.getElementById( this.id + "upImage" );
	this.downImage = document.getElementById( this.id + "downImage" );

	this.textCell.onmousedown = ACPSelect.forwardEvent( this, "open" );
	if ( document.all ) this.textCell.onselectstart = function () { return false; }

	this.buttonCell.style.cursor = "hand";
	this.buttonCell.onmousedown = ACPSelect.forwardEvent( this, "open" );
}


ACPSelect.prototype.oldMouseDown = null;


ACPSelect.prototype.size = function () {
	this.linkDiv.className = "selectLinksLoad";

	this.linkDiv.style.display = "block";
	var width = this.linkDiv.offsetWidth;
	var height = this.linkDiv.offsetHeight;
	this.linkDiv.style.display = "none";

	if ( height > 200 ) this.linkDiv.style.height = 200;

	if ( width - 26 > this.textCell.offsetWidth ) {
		this.textCell.style.width = width - 26;
		this.linkDiv.style.width = width;
	} else {
		this.linkDiv.style.width = this.textCell.offsetWidth + 26;
	}

	this.linkDiv.className = "selectLinks";
}


ACPSelect.prototype.open = function ( e ) {
	if ( ACPSelect.openInstance ) {
		if ( ACPSelect.openInstance == this ) return;
		ACPSelect.openInstance.close();
	}

	this.size();

	ACPSelect.openInstance = this;

	this.upImage.style.display = "none";
	this.downImage.style.display = "block";
	var curParent = this.div, top = 25, left = 18;
	while ( curParent && curParent.style.position != "absolute" ) {
		top += curParent.offsetTop;
		left += curParent.offsetLeft;
		curParent = curParent.offsetParent;
	}
	this.linkDiv.style.top = top;
	this.linkDiv.style.left = left;


	if ( document.all && navigator.userAgent.indexOf("MSIE 5.") == -1 ) this.linkDiv.filters[ 0 ].Apply();
	this.linkDiv.style.display = "block";
	if ( document.all && navigator.userAgent.indexOf("MSIE 5.") == -1 ) this.linkDiv.filters[ 0 ].Play();

	var instance = this;
	setTimeout( function () { }, 200 );

	this.oldMouseDown = document.body.onmousedown;
	document.body.onmousedown = ACPSelect.forwardEvent( this, "close" );
	e.cancelBubble = true;
}


ACPSelect.prototype.setText = function ( text ) {
	this.textCell.innerHTML = "<nobr>" + text + "</nobr>";
}


ACPSelect.prototype.close = function ( e ) {

	this.setButtonUp();

	this.linkDiv.style.display = "none";
	if ( this.oldMouseDown ) document.body.onmousedown = this.oldMouseDown;
	if ( ACPSelect.openInstance == this ) ACPSelect.openInstance = null;
}


ACPSelect.prototype.setButtonUp = function () {

	this.upImage.style.display = "block";

	this.downImage.style.display = "none";
}


ACPSelect.load = function () {
	return;
	var data;
	for ( var divID in ACPSelect.instances ) {
		ACPSelect.instances[ divID ].size();
	}
}


ACPSelect.instances = [];
ACPSelect.register = function ( divID, linkDivID, text ) {
	var linkDiv = document.getElementById( linkDivID );
	linkDiv.className = "selectLinksLoad";
	ACPSelect.instances[ divID ] = new ACPSelect( divID, linkDiv, text );
}


ACPSelect.forwardEvent = function ( instance, method ) {
	return function ( e ) {
		if ( !e ) e = window.event;
		instance[ method ]( e );
	}
}


ACPSelect.UID = 0;
ACPSelect.getUID = function () {
	return "ACPSelect" + ACPSelect.UID++;
}


ACPSelect.openInstance = null;


