/////// ####################################################################################################
/////// WRITTEN BY TECHNICWEB - 09/05
/////// TESTED IN:
//////		- Internet Explorer 6.0
//////	Unsupported:
//////		- Mozilla
//////
//////	Unsupported browsers will render default HTML <select> controls.
////// #####################################################################################################

var v_dropdownlistmanager_prefix = "ddl";
var a_dropdownlistmanager_objects = new Array(); // used for storing a reference for each of the dropdowns rendered

function EstateWeb_Objects_DropDownListManager(){
	this.Name = ""; //Unique name of form field in the document
	this.MultiSelect = false; //Allow values to multiselect
	this.MultiSelectNoItemTemplate = "All Areas";
	this.MultiSelectSingularTemplate = "Area (%L)"; // %N  = number of items selected, %L = text of item selected
	this.MultiSelectMultipleTemplate = "Areas (%N)";
	this.DefaultSelectedIndex = -1; //When there are no selected items (multiselect), then this index will be checked by default e.g. All Areas.
	this.ControlContainer = ""; //Unique ID of container in which the control will be rendered
	this.ControlWidth = 200; //Width in pixels of the control
	this.ControlHeight = 19; //Height in pixels of the control
	this.ControlClass = ""; //Css Class for defining render styles
	this.ControlLabelClass = ""; //Allows custom positioning for the label in the control
	this.ControlArrowClass = ""; //Allows sutom position for the arrow in the control
	this.ControlGraphicWidth = 16;
	this.ControlGraphicHeight = 17;
	this.ControlGraphicURL = ""; //relative or absolute url of default or 'off' graphic
	this.ControlCheckboxURL = ""; //relative or absolute url of the checkbox 'off' state
	this.ControlCheckboxWidth = 15;
	this.OptionsContainerClass = ""; //Css Class for the options container
	this.OptionsContainerHeight = 50; //Height of options container before scrolling options
	this.OptionClass = "";
	this.OptionClass_Over = "";
	this.OptionLabelClass = "";
	this.OptionCheckboxClass = "";
	this.DataSource = new Array(); //Array datasource for databinding
	this.DataBind = __EstateWeb_Objects_DropDownListManager_DataBind;
}


function __EstateWeb_Objects_DropDownListManager_DataBind(){


	if (this.Name.length == 0){
		__EstateWeb_Objects_DropDownListManager_Error("No \'Name\' property defined\n\n");
		return;
	}
	
	if (this.ControlContainer.length == 0){
		__EstateWeb_Objects_DropDownListManager_Error("No Unique Container ID provided\n\nThis is usally the id of the container DIV in which the control will be rendered");
		return;
	}
	
	if (this.ControlGraphicURL.length == 0){
		__EstateWeb_Objects_DropDownListManager_Error("No Arrow graphic relative /absolute URL provided\n\nThis is required");
		return;
	}
	
	if (this.ControlCheckboxURL.length == 0 && this.MultiSelect == true){
		__EstateWeb_Objects_DropDownListManager_Error("No Checkbox graphic relative / absolute URL provided\n\nThis is required when specifying \'MultiSelect\'");
		return;
	}

	if (this.DataSource.length == 0){
		__EstateWeb_Objects_DropDownListManager_Error("No Datasource provided for \'"+this.Name+"\' control\n\nThis control requires a datasource to create options");
		return;
	}




	//Render control for IE only
	if (!EstateWeb_Browser_IsMozilla()){
			// Control Display
			var objControlDisplay = document.createElement("DIV");
			//append style
			objControlDisplay.setAttribute("id", v_dropdownlistmanager_prefix+"_"+this.Name+"_ControlContainer");
			objControlDisplay.style.width = this.ControlWidth+"px";
			objControlDisplay.style.height = this.ControlHeight+"px";
			objControlDisplay.className = this.ControlClass;
			//objControlDisplay.style.zindex = this.OptionsContainerZIndex;
			objControlDisplay.onmouseover = __EstateWeb_Objects_DropDownListManager_OnMouseOver;
			objControlDisplay.onmousedown = __EstateWeb_Objects_DropDownListManager_OnMouseDown;
			objControlDisplay.onmouseout = __EstateWeb_Objects_DropDownListManager_OnMouseOut;
			objControlDisplay.onmouseup = __EstateWeb_Objects_DropDownListManager_OnMouseUp;
			//
			
			//Control Label Container
			var objControlDisplayLabelContainer = document.createElement("DIV");
			//append style
			objControlDisplayLabelContainer.style.position = "absolute";
			//objControlDisplayLabelContainer.style.height = this.ControlHeight+"px";
			if (this.ControlLabelClass.length > 0 ){
				objControlDisplayLabelContainer.className = this.ControlLabelClass;
			}
			//
			
			//Control Label Text
			var objControlDisplayLabelContainerText = document.createElement("A");
			//append style
			objControlDisplayLabelContainerText.setAttribute("id", v_dropdownlistmanager_prefix+"_"+this.Name+"_txtLabel");
			objControlDisplayLabelContainerText.innerHTML = this.DataSource[0][0];//"Select...";
			//
			
			
			//add label to container
			objControlDisplayLabelContainer.appendChild(objControlDisplayLabelContainerText);
			
			//Control Arrow Graphic Container
			var objControlDisplayArrowContainer = document.createElement("DIV");
			objControlDisplayArrowContainer.style.position = "absolute";
			objControlDisplayArrowContainer.style.height = this.ControlHeight+"px";
			objControlDisplayArrowContainer.style.width = this.ControlGraphicWidth+"px";
			objControlDisplayArrowContainer.setAttribute("align", "right");
			if (this.ControlArrowClass.length > 0){
				objControlDisplayArrowContainer.className = this.ControlArrowClass;
			}
			
			//Control Arrow graphic
			var objControlDisplayArrowGraphic = document.createElement("IMG");
			objControlDisplayArrowGraphic.setAttribute("id", v_dropdownlistmanager_prefix+"_"+this.Name+"_ArrowGraphic");
			objControlDisplayArrowGraphic.setAttribute("src", this.ControlGraphicURL);
			objControlDisplayArrowGraphic.setAttribute("width", this.ControlGraphicWidth);
			objControlDisplayArrowGraphic.setAttribute("height", this.ControlGraphicHeight);
			
			//add graphic to container
			objControlDisplayArrowContainer.appendChild(objControlDisplayArrowGraphic);
			
			//add label contrainer to main control container
			objControlDisplay.appendChild(objControlDisplayLabelContainer);
			//add graphic container to main control container
			objControlDisplay.appendChild(objControlDisplayArrowContainer);
			
			//Options Container
			var objControlOptionsContainer = document.createElement("DIV");
			
			objControlOptionsContainer.setAttribute("id", v_dropdownlistmanager_prefix+"_"+this.Name+"_Options_Container");
			objControlOptionsContainer.style.width = this.ControlWidth+"px";
			objControlOptionsContainer.style.height = this.OptionsContainerHeight+"px";
			objControlOptionsContainer.style.overflow = "auto";
			objControlOptionsContainer.style.display = "none";
			objControlOptionsContainer.style.zindex = this.OptionsContainerZIndex;
			//alert(objControlOptionsContainer.style.zindex);
			objControlOptionsContainer.className = this.OptionsContainerClass;
			
			
			objControlOptionsContainer.onblur = __EstateWeb_Objects_DropDownListManager_HideOptions;
	}else{
		//Generate a generic dropdownlist
		var objSelect = document.createElement("select");
		objSelect.name = this.Name;
		objSelect.id = v_dropdownlistmanager_prefix +"_" + this.Name;
		EstateWeb_Document_GetObject(this.ControlContainer).appendChild(objSelect);
	}
	
	//Now iterate though the datasource creating options
	if ( this.DataSource.length ){
		for (var e=0;e < this.DataSource.length; e++){
			var item = this.DataSource[e];
			
			if (!EstateWeb_Browser_IsMozilla()){
				var objOption = document.createElement("DIV");
				objOption.setAttribute("id", v_dropdownlistmanager_prefix+"_"+this.Name+"_Options_Item"+e);
				objOption.className = this.OptionClass;
				
				if ( this.MultiSelect ){
				
					
					//create checkbox image control
					var objCheckbox = document.createElement("img");
					objCheckbox.setAttribute("id", v_dropdownlistmanager_prefix+"_"+this.Name+"_Options_Item"+e+"_CheckboxGraphic");
					objCheckbox.setAttribute("src", this.ControlCheckboxURL);
					objCheckbox.setAttribute("border",0);
					objCheckbox.setAttribute("align","absmiddle");
					objOption.appendChild(objCheckbox);
					
					//create label cell
					var objLabel = document.createElement("a");
					objLabel.setAttribute("id", v_dropdownlistmanager_prefix+"_"+this.Name+"_Options_Item"+e+"_Label");
					objLabel.className = this.OptionLabelClass;
					objLabel.innerHTML = item[0];
					objOption.appendChild(objLabel);
		
					//create value
					var objLabel = document.createElement("a");
					objLabel.setAttribute("id", v_dropdownlistmanager_prefix+"_"+this.Name+"_Options_Item"+e+"_Value");
					objLabel.innerHTML = item[1];
					objLabel.style.display = "none";
					objOption.appendChild(objLabel);			
					
					objOption.onclick = __EstateWeb_Objects_DropDownListManager_OnItemMouseClick;
					objOption.onmouseover = __EstateWeb_Objects_DropDownListManager_OnItemMouseOver;
					objOption.onmouseout = __EstateWeb_Objects_DropDownListManager_OnItemMouseOut;
				
				}else{
				
					objOption.onclick = __EstateWeb_Objects_DropDownListManager_OnItemMouseClick;
					objOption.onmouseover = __EstateWeb_Objects_DropDownListManager_OnItemMouseOver;
					objOption.onmouseout = __EstateWeb_Objects_DropDownListManager_OnItemMouseOut;
					
					var objOptionText = document.createElement("A");
					objOptionText.setAttribute("id", v_dropdownlistmanager_prefix+"_"+this.Name+"_Options_Item"+e+"_Label");
					objOptionText.innerHTML = item[0];
					
					var objOptionValue = document.createElement("A");
					objOptionValue.setAttribute("id", v_dropdownlistmanager_prefix+"_"+this.Name+"_Options_Item"+e+"_Value")
					objOptionValue.style.display = "none";
					objOptionValue.innerHTML = item[1];
					
					objOption.appendChild(objOptionText);
					objOption.appendChild(objOptionValue);
				
				}
				
				objControlOptionsContainer.appendChild(objOption);
			}else{
				//create options normally
				var objSelect = EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix +"_" + this.Name);
				objSelect.options[objSelect.options.length] = new Option(item[0],item[1]);
			
			}
			
		}
	}
	
	if (!EstateWeb_Browser_IsMozilla()){
		//Create form input control
		var objFormItem = document.createElement("INPUT");
		objFormItem.setAttribute("type", "hidden");
		objFormItem.setAttribute("id", v_dropdownlistmanager_prefix+"_"+this.Name+"_Result");
		objFormItem.setAttribute("name", this.Name);
	}
	
	
	
	
	//render control in specified container
	if ( EstateWeb_Document_IsObject(this.ControlContainer) ){
		
		if ( !EstateWeb_Browser_IsMozilla()){
	
			EstateWeb_Document_GetObject(this.ControlContainer).appendChild(objControlDisplay);
			EstateWeb_Document_GetObject(this.ControlContainer).appendChild(objControlOptionsContainer);
			EstateWeb_Document_GetObject(this.ControlContainer).appendChild(objFormItem);
			a_dropdownlistmanager_objects[a_dropdownlistmanager_objects.length] = new Array(this.Name, this);
			
			//if we are in multiselect mode, then select the default item (if set)
			if ( this.DefaultSelectedIndex >= 0 ){
				__EstateWeb_Objects_DropDownListManager_BuildFakeOption(v_dropdownlistmanager_prefix+"_"+this.Name+"_Options_Item"+this.DefaultSelectedIndex).Click();
			}
		}
		
	}else{
		alert("Dropdownlist Creator\n\nControl Container does\'t exist");
	}
}

function __EstateWeb_Objects_DropDownListManager_OnItemMouseClick(){
	if ( __EstateWeb_Objects_DropDownListManager_IsMultiSelect(this.id) ){
	
		//Get an reference to the object for this dropdownlist
		var oDropDownList = __EstateWeb_Objects_DropDownListManager_GetObjectReference(__EstateWeb_Objects_DropDownListManager_GetName(this.id));
	
		//toggle the checkbox graphic for the item
		var objCheckbox = EstateWeb_Document_GetObject(this.id+"_CheckboxGraphic");
		if ( objCheckbox.src.indexOf("_off.gif") > 0 ){
			objCheckbox.src = __EstateWeb_Objects_DropDownListManager_GetGraphicName( objCheckbox.src, "on");
		}else{
			objCheckbox.src = __EstateWeb_Objects_DropDownListManager_GetGraphicName( objCheckbox.src, "off");
		}
		
		
		//if the item that is selected is not the DefaultSelectedItem, then we must reset the DefaultSelectedItem
		if ( objCheckbox.src.indexOf("_on.gif") > 0 && this.id != v_dropdownlistmanager_prefix+"_"+__EstateWeb_Objects_DropDownListManager_GetName(this.id)+"_Options_Item"+oDropDownList.DefaultSelectedIndex ){
			var objCheckbox = EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+"_"+__EstateWeb_Objects_DropDownListManager_GetName(this.id)+"_Options_Item"+oDropDownList.DefaultSelectedIndex+"_CheckboxGraphic");
			if ( objCheckbox ){
				objCheckbox.src = __EstateWeb_Objects_DropDownListManager_GetGraphicName( objCheckbox.src, "off");		
			}
		}
		
		
		//loop through all the options
		var iItems = 0;
		var sValues = "";
		var objOptions = EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+'_'+__EstateWeb_Objects_DropDownListManager_GetName(this.id)+'_Options_Container').childNodes;
		var bFound = false;
		var objOptionLabel = EstateWeb_Document_GetObject(this.id).getElementsByTagName("a")[0].innerHTML;
		
		for (var e=0;e< objOptions.length;e++){
			var objOption = objOptions[e];
			var objCheckbox = EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+"_"+__EstateWeb_Objects_DropDownListManager_GetName(this.id)+"_Options_Item"+e+"_CheckboxGraphic");
			var objOptionValue = objOption.getElementsByTagName("a")[1].innerHTML;
			
			// if we reach the DefaultSelectedIndex, and its checked then we reset all the other options
			// we dont want to do this more than once, so indicate if we have reached this point	
			if (!bFound){
				if ( e == oDropDownList.DefaultSelectedIndex ){
					if ( EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+"_"+__EstateWeb_Objects_DropDownListManager_GetName(this.id)+"_Options_Item"+oDropDownList.DefaultSelectedIndex+"_CheckboxGraphic").src.indexOf("_on.gif") > 0 ){
						for ( var ee=0; ee < objOptions.length; ee++ ){
							if ( ee != oDropDownList.DefaultSelectedIndex ){
								var objOption2 = objOptions[ee];
								var objCheckbox2 = EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+"_"+__EstateWeb_Objects_DropDownListManager_GetName(this.id)+"_Options_Item"+ee+"_CheckboxGraphic");
								objCheckbox2.src = __EstateWeb_Objects_DropDownListManager_GetGraphicName( objCheckbox2.src, "off");
							}
						}
					}
				
					bFound = true;
		
				}
			
			}
			
			
			
			if ( objCheckbox.src.indexOf("_on.gif") > 0 ) { 
				if ( sValues.length > 0 ) { sValues += "," }
				sValues += objOptionValue;
				iItems++; 
			}
			
		}
		
		
		
		if ( iItems == 1 ){
			EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+"_"+__EstateWeb_Objects_DropDownListManager_GetName(this.id)+"_txtLabel").innerHTML = oDropDownList.MultiSelectSingularTemplate.replace("%N", iItems).replace("%L", objOptionLabel);
		}else if ( iItems > 1 ){
			EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+"_"+__EstateWeb_Objects_DropDownListManager_GetName(this.id)+"_txtLabel").innerHTML = oDropDownList.MultiSelectMultipleTemplate.replace("%N", iItems);
		}else{
			EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+"_"+__EstateWeb_Objects_DropDownListManager_GetName(this.id)+"_txtLabel").innerHTML = oDropDownList.MultiSelectNoItemTemplate;
		}
		
		EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+"_"+__EstateWeb_Objects_DropDownListManager_GetName(this.id)+"_Result").value = sValues;
	
	}else{
		__EstateWeb_Objects_DropDownListManager_OnItemMouseClick_Set(this.id)
		__EstateWeb_Objects_DropDownListManager_HideOptions(this.id);
	}
}

function __EstateWeb_Objects_DropDownListManager_OnItemMouseClick_Set(ID){
	EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+"_"+__EstateWeb_Objects_DropDownListManager_GetName(ID)+"_txtLabel").innerHTML = EstateWeb_Document_GetObject(ID+'_Label').innerHTML;
	EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+"_"+__EstateWeb_Objects_DropDownListManager_GetName(ID)+"_Result").value = EstateWeb_Document_GetObject(ID+'_Value').innerHTML;
}

function __EstateWeb_Objects_DropDownListManager_OnItemMouseOver(){
	EstateWeb_Document_GetObject(this.id).className =  __EstateWeb_Objects_DropDownListManager_GetClassName(EstateWeb_Document_GetObject(this.id).className, "over");
}

function __EstateWeb_Objects_DropDownListManager_OnItemMouseOut(){
	EstateWeb_Document_GetObject(this.id).className =  __EstateWeb_Objects_DropDownListManager_GetClassName(EstateWeb_Document_GetObject(this.id).className, "out");
}

function __EstateWeb_Objects_DropDownListManager_OnMouseOver(){
	var nURL = __EstateWeb_Objects_DropDownListManager_GetGraphicName( EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+"_"+__EstateWeb_Objects_DropDownListManager_GetName(this.id)+"_ArrowGraphic").src, "over");
	EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+"_"+__EstateWeb_Objects_DropDownListManager_GetName(this.id)+"_ArrowGraphic").src = nURL;
}
	
function __EstateWeb_Objects_DropDownListManager_OnMouseDown(){
	var nURL = __EstateWeb_Objects_DropDownListManager_GetGraphicName( EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+"_"+__EstateWeb_Objects_DropDownListManager_GetName(this.id)+"_ArrowGraphic").src, "down");
	EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+"_"+__EstateWeb_Objects_DropDownListManager_GetName(this.id)+"_ArrowGraphic").src = nURL;
}

function __EstateWeb_Objects_DropDownListManager_OnMouseOut(){
	var nURL = __EstateWeb_Objects_DropDownListManager_GetGraphicName( EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+"_"+__EstateWeb_Objects_DropDownListManager_GetName(this.id)+"_ArrowGraphic").src, "off");
	EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+"_"+__EstateWeb_Objects_DropDownListManager_GetName(this.id)+"_ArrowGraphic").src = nURL;
}

function __EstateWeb_Objects_DropDownListManager_OnMouseUp(){
	var nURL = __EstateWeb_Objects_DropDownListManager_GetGraphicName( EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+"_"+__EstateWeb_Objects_DropDownListManager_GetName(this.id)+"_ArrowGraphic").src, "off");
	EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+"_"+__EstateWeb_Objects_DropDownListManager_GetName(this.id)+"_ArrowGraphic").src = nURL;
	__EstateWeb_Objects_DropDownListManager_ToggleOptions(this.id);
}

function __EstateWeb_Objects_DropDownListManager_IsMultiSelect(id){
	//get a handle on container
	var objContainer = EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+'_'+__EstateWeb_Objects_DropDownListManager_GetName(id)+'_Options_Container').getElementsByTagName("img");
	if ( objContainer.length == 0 ){ return false } else { return true }
}

function __EstateWeb_Objects_DropDownListManager_GetName(id){
	var sname = id.substring(id.indexOf("_")+1);
	sname = sname.substring(0, sname.indexOf("_"));
	return sname;
}

function __EstateWeb_Objects_DropDownListManager_HideOptions(id){
	//alert(typeof this.id);
	if (typeof this.id == "undefined"){
		EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+'_'+__EstateWeb_Objects_DropDownListManager_GetName(id)+'_Options_Container').style.display = "none";
	}else{
		EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+'_'+__EstateWeb_Objects_DropDownListManager_GetName(this.id)+'_Options_Container').style.display = "none";
	}
	
}

function __EstateWeb_Objects_DropDownListManager_ToggleOptions(id){
	if ( EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+'_'+__EstateWeb_Objects_DropDownListManager_GetName(id)+'_Options_Container').style.display == "block"){
		__EstateWeb_Objects_DropDownListManager_HideOptions(id);
	}else{
		__EstateWeb_Objects_DropDownListManager_ShowOptions(id);
	}
}

function __EstateWeb_Objects_DropDownListManager_ShowOptions(id){
	EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+'_'+__EstateWeb_Objects_DropDownListManager_GetName(id)+'_Options_Container').style.display = "block";
	if (! EstateWeb_Browser_IsMozilla()){
		EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+'_'+__EstateWeb_Objects_DropDownListManager_GetName(id)+'_Options_Container').focus();
	}else{
		EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+'_'+__EstateWeb_Objects_DropDownListManager_GetName(id)+'_Options_Container').style.MozUserFocus = "normal";
	}
}

function __EstateWeb_Objects_DropDownListManager_GetGraphicName(url, newpart){
	var sextension = url.substring(url.lastIndexOf("."))
	var sname = url.substring(0, url.lastIndexOf("_"));
	return sname+"_"+newpart+sextension;
}

function __EstateWeb_Objects_DropDownListManager_GetObjectReference(name){
	for (var ii=0;ii< a_dropdownlistmanager_objects.length; ii++){
		if ( a_dropdownlistmanager_objects[ii][0] == name ){
			return a_dropdownlistmanager_objects[ii][1];
		}
	}
}

function __EstateWeb_Objects_DropDownListManager_GetClassName(className, newpart){
	return className.substring(0, className.lastIndexOf("_")) +"_"+ newpart;
}

function __EstateWeb_Objects_DropDownListManager_SelectItem_ByIndex(objManager, Index){
	//loop through each item until we reach the index required
	var items = EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+"_"+objManager.Name+"_Options_Container").getElementsByTagName("DIV");
	if ( Index <= items.length ){
		var item = items[Index];
		__EstateWeb_Objects_DropDownListManager_OnItemMouseClick_Set(item.id);
	}
}

function __EstateWeb_Objects_DropDownListManager_SelectItem_ByValue(objManager, Val){

	if (!EstateWeb_Browser_IsMozilla()){
		var items = EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+"_"+objManager.Name+"_Options_Container").getElementsByTagName("DIV");
		
		if ( Val.length > 0 ){
			if ( objManager.MultiSelect == true ){
				Val = unescape(Val).split(",");
				for (var i=0; i < Val.length; i++){
					for(var ii=0; ii < items.length; ii++){
						var option = items[ii];
						Val[i] = Val[i].replace("+"," ");
						var optionData = option.getElementsByTagName("A");
						if ( optionData[1].innerHTML.toUpperCase() == Val[i].toUpperCase() ){
							__EstateWeb_Objects_DropDownListManager_BuildFakeOption(option.id).Click();
						}
					}				
				}
			}else{
		
				for(var i=0; i < items.length; i++){
					var option = items[i];
					var optionData = option.getElementsByTagName("A");
					if ( optionData[1].innerHTML.toUpperCase() == Val.toUpperCase() ){
							__EstateWeb_Objects_DropDownListManager_SelectItem_ByIndex(objManager, i);
					}
				}
			}
		}
	}else{
		//just select the item in the select list that matches
		var objSelect = EstateWeb_Document_GetObject(v_dropdownlistmanager_prefix+"_"+objManager.Name);
		for (var i = 0 ;i< objSelect.options.length;i++){
			if (objSelect.options[i].value.toUpperCase() == Val.toUpperCase()){
				objSelect.selectedIndex = i;
				return;
			}
		}
	}
}

function __EstateWeb_Objects_DropDownListManager_BuildFakeOption(id){
	//allows mozilla browsers to have .click() events
	var obj = new Object();
	obj.id = id;
	obj.Click = __EstateWeb_Objects_DropDownListManager_OnItemMouseClick;
	return obj;
}

function __EstateWeb_Objects_DropDownListManager_Error(msg){
	var errorMsg = "EstateWeb - DropdownList Manager\n____________________________\n\n\An error has occured in this application, please see error description below.\n\n'"+msg+"\'";
	alert(errorMsg);
	return false;
}