// DivComboBox.js
// Copywrite 2005 Martin Krolik (martin@krolik.net)
// All rights reserved.  
var arrAllComboBoxes = new Array();
var pOldDComboBoxOnloadHandler = null;
var pOldDComboBoxResizeHandler = null;
pOldDComboBoxOnloadHandler = window.onload;
pOldDComboBoxResizeHandler = window.onresize;
onload = DComboBoxOnloadHandler;
onresize = DComboBoxResizeHandler;
function ComboInit(BaseName)
{
	var objA, objB, xOffset, yOffset;
	xOffset = 0;
	yOffset = 21;
	if (navigator.appName.indexOf("Mozilla")>=0) xOffset = -1;
	objB = xGetElementById(BaseName + "DcboBox");
	if (!(document.layers))
	{
		objA = xGetElementById(BaseName);

		xMoveTo(objB, xPageX(objA) + xOffset, xPageY(objA) + yOffset );	
	} else {

		objA = xGetElementById(BaseName) + "DcboBoxDDImgB";
		// objB = xGetElementById(BaseName + "DcboBoxDDImg");

		xMoveTo(objB, xPageX(objA) - (200-18), xPageY(objA) + 400 );	
	}
	//xClip(objB , 0, xWidth(objB), xHeight(objB), xWidth(objB) - 23);
	//xShow(objB);
}
function AllComboInit()
{
  for (var i = 0; i < arrAllComboBoxes.length; i++)
    {
      ComboInit(arrAllComboBoxes[i]);
    }
}
function DComboBoxOnloadHandler()
{
  if (pOldDComboBoxOnloadHandler) pOldDComboBoxOnloadHandler();
  AllComboInit();
}
function DComboBoxResizeHandler()
{
  if (pOldDComboBoxResizeHandler) pOldDComboBoxResizeHandler();
  AllComboInit();

}
function UnSelectAnyOptions(selectElement)
{
	void(0);
}
function AddSelection(Name,Value)
{
	void(0);
}
function RemoveSelection(Name)
{
	void(0);
}
function BuildDCBox(BaseName, StartValue, Options, PixelWidth, Other, AdditionalStyle, TextValues)
{
	var DCOptions;
	var DCValues;
	if (!(PixelWidth)) PixelWidth = 200;
	if (!(StartValue)) StartValue = "";
	if ((typeof Options) == "string")  { DCOptions = Options.split(",") } else { DCOptions = Options }
	if (TextValues != null)
	{
		if ((typeof TextValues) == "string")  { DCValues = TextValues.split(",") } else { DCValues = TextValues }
	} else {
		DCValues = new Array(DCOptions.length - 1);
		for (var cnt = 0; cnt < DCOptions.length; cnt++ )
		{
			DCValues[cnt] = DCOptions[cnt].toString() ;
		}
	}
	var strBuild = "";
	//if (document.layers)
	//	strBuild += "<table border=0><tr><td align=center>";
	strBuild += "<table border=0 cellpadding=0 cellspacing=0><tr><td>";
	strBuild += "<input type='text' value='" + StartValue;
	strBuild += "' name='" + BaseName + "' id='" + BaseName + "' "
	if (!(document.layers))
		strBuild += "style='top: 1px; width: " + (PixelWidth - 14) + "px; font: serif; position: relative; " + AdditionalStyle + "' ";
	strBuild += Other + " />"
	strBuild += "</td><td>"
	if (document.layers)
	{
		strBuild += "<a href='javascript:void(0);' onclick='ToggleDropDown(\"" + BaseName + "DcboBox\")'>"
		strBuild += "<span ";
		strBuild += " name='" + BaseName + "DcboBoxDDImgB' id='" + BaseName + "DcboBoxDDImgB' ";
		strBuild += ">";
	}
	strBuild += "<img src='/DComboBox/DropDownButton.gif' border='0' onclick='ToggleDropDown(\"" + BaseName + "DcboBox\")' ";
	strBuild += " name='" + BaseName + "DcboBoxDDImg' id='" + BaseName + "DcboBoxDDImg' ";
	strBuild += " style='position: relative; left: -2px;'>";
	if (document.layers)
	{
		strBuild += "</span>";
		strBuild += "</a>";
	}
	strBuild += "</td></tr></table>"
	//if (document.layers)
	//	strBuild += "</td></tr><tr><td align=center>- Or Select -</td></tr><tr><td align=center>";
	strBuild += "<div name='" + BaseName + "DcboBox' id='" + BaseName + "DcboBox' ";
	if (!(document.layers))
	{
		strBuild += "style='width: " + PixelWidth + "px; position: absolute; visibility: hidden; background-color: #ffffff; border-style: solid; border-width: 1px; overflow: auto; max-height: 200px; cursor: default; z-index: 50000; " + AdditionalStyle + "' ";
	} else {
		strBuild += "style='position: absolute; left: 100px; top: 100px; ' ";
	}
	strBuild += "><table width='100%' border='0' cellpadding='0' cellspacing='0' bgcolor='#FFFFFF'>" ;
	if ((DCOptions) && (DCOptions.length))
	{
		for (var cnt = 0; cnt < DCOptions.length; cnt++ )
		{
			strBuild += "<tr><td onclick='ChangeValue(event,this,\"" + BaseName + "\",\"" + DCValues[cnt] + "\")' "
			if (!(document.layers))
				strBuild += "onmouseover='ChangeColor(event,this,\"#cccccc\")' onmouseout='ChangeColor(event,this,\"#ffffff\")' UNSELECTABLE='ON' STYLE='-moz-user-select: none;' ";
			strBuild += ">" ;
			if (document.layers)
				strBuild += "<a href='javascript:void(0);' onclick='ChangeValue(event,this,\"" + BaseName + "\",\"" + DCOptions[cnt] + "\")'>"
			strBuild += DCOptions[cnt];
			if (document.layers)
				strBuild += "</a>"
			strBuild += "</td></tr>";
		}
	}
	strBuild += "</table></div>";
	if (document.layers)
		strBuild += "</td></tr></table>";
	return (strBuild);

}
function WriteDCBox(BaseName, StartValue, Options, PixelWidth, Other, AdditionalStyle, Values)
{
	if (!(BaseName)) BaseName = "DefaultDComboBoxName";
	document.write(BuildDCBox(BaseName,StartValue,Options,PixelWidth,Other,AdditionalStyle, Values));
	setTimeout("ComboInit('" + BaseName + "');", 22);
	arrAllComboBoxes.push(BaseName);
}
function ChangeColor(evnt, elem, strColor)
{
	xBackground(elem, strColor);
}
function ChangeValue(evnt, elem, strParentElemName, strValue)
{
	var objA = xGetElementById(strParentElemName);
	objA.value = strValue;
	var objB = xGetElementById(strParentElemName + "DcboBox");
	//xDisappearTo(objB,"n",1000);
	xHide(objB);
	if (!(document.layers))
		objB.IsVisible = false;
	if (objA && (objA.onchange)) objA.onchange();
}
function ToggleDropDown(strElem)
{
	if (document.layers)
	{
		alert(strElem);
		xShow(strElem);
		alert(xPageY(strElem + "DDImg") );
		xMoveTo(strElem, xLeft(strElem + "DDImgB"),  xTop(strElem + "DDImgB") );
		alert("DD");
		return; 

	}
	var el = xGetElementById(strElem);
	if (xDef(el.IsVisible))
	{
		if (el.IsVisible)
		{
			xHide(el);
			//xDisappearTo(el,"n",1000);

			el.IsVisible = false;
		} else {
			xShow(el);
			//xAppearFrom(el,"n",1000);
			el.IsVisible = true;
		}
	} else {
		xShow(el);
		//xAppearFrom(el,"n",1000);
		el.IsVisible = true;
	}
}
