var arrAllComboBoxes = new Array();
var pOldDComboBoxOnloadHandler = null;
var pOldDComboBoxResizeHandler = null;
pOldDComboBoxOnloadHandler = window.onload;
pOldDComboBoxResizeHandler = window.onresize;
onload = DComboBoxOnloadHandler;
onresize = DComboBoxResizeHandler;
function NewWindow(mypage, myname, w, h, scroll, menu)
{
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable';
    if (menu == 1)
    {
        winprops = winprops + ',menubar=yes,toolbar=yes,statusbar=yes,location=yes,personalbar=yes';
    }
    win = window.open(mypage, myname, winprops);
    if (parseInt(navigator.appVersion) >= 4)
    {
        win.window.focus();
    }
}
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, dp_bg_color, dp_btn_path, dp_link)
{
	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 style='background: #"+dp_bg_color+";'>";

	strBuild += "<input type='text' value='" + StartValue;
	strBuild += "' name='" + BaseName + "' id='" + BaseName + "' "
	if (!(document.layers))
		strBuild += "style='height: 21px; width: " + (PixelWidth - 14) + "px; font: 7pt Verdana; position: relative; color: #555753;" + AdditionalStyle + "' ";
	strBuild += Other + " />"
	strBuild += "</td><td style='background: #"+dp_bg_color+";'>"
	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='"+dp_btn_path+"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++ )
		{
   if(dp_link == 1)
   {
			   strBuild += "<tr><td onclick='ChangeValue(event,this,\"" + BaseName + "\",\"" + DCValues[cnt] + "\", \"" + DCOptions[cnt] + "\")' "
   }
   else
   {
			   strBuild += "<tr><td onclick='ChangeValue2(event,this,\"" + BaseName + "\",\"" + DCValues[cnt] + "\", \"" + DCOptions[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, dp_bg_color, dp_btn_path, dp_link)
{
	if (!(BaseName)) BaseName = "DefaultDComboBoxName";
	document.write(BuildDCBox(BaseName,StartValue,Options,PixelWidth,Other,AdditionalStyle, Values, dp_bg_color, dp_btn_path, dp_link));
	setTimeout("ComboInit('" + BaseName + "');", 22);
	arrAllComboBoxes.push(BaseName);
}
function ChangeColor(evnt, elem, strColor)
{
	xBackground(elem, strColor);
}
function ChangeValue(evnt, elem, strParentElemName, strValue, strName)
{
	var objA = xGetElementById(strParentElemName);
	objA.value = strValue;
	var objB = xGetElementById(strParentElemName + "DcboBox");
	//xDisappearTo(objB,"n",1000);
	xHide(objB);
	if (!(document.layers))
		objB.IsVisible = false;
	tmp = strValue.substring(0,4);
	if (strValue != 0)
	{
		if(tmp == "new_")
		{
			strValue = strValue.replace(/new_/gi,'');
   objA.value = strValue;
			NewWindow(strValue, "New_Page", 700, 500, "yes", "no");
		}
		else
		{
			location.href = strValue;
		}
	}
 objA.value = strName;
 if (objA && (objA.onchange)) objA.onchange();
}
/*
function ChangeValue2(evnt, elem, strParentElemName, strValue, strName)
{
	var objA = xGetElementById(strParentElemName);
	objA.value = strValue;
	var objB = xGetElementById(strParentElemName + "DcboBox");
	xHide(objB);
	if (!(document.layers))
		objB.IsVisible = false;
 //objA.value = strName;
 if (objA && (objA.onchange)) objA.onchange();
}
*/
function ChangeValue2(evnt, elem, strParentElemName, strValue, strName)
{
	var objA = xGetElementById(strParentElemName);
	//objA.value = strValue;
	objA.value = strName;
	var objB = xGetElementById(strParentElemName + "DcboBox");
	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;
	}
}
