//hides all the select menus that overlap the given layer
function HideOverlappingSelects(oLayer) {
//if this is IE, hide selects that overlap the progress bar
	if ((document.all || (Browser.OS == OS_MAC && Browser.UserAgent == BROWSER_GECKO)) && oLayer) {
		var i;
		var arrSelects = document.getElementsByTagName('SELECT');
		var arrSelectsIgnore = oLayer.getElementsByTagName('SELECT');
		
		//prevents selects inside the div from being hidden
		for (i=0; i<arrSelectsIgnore.length; i++) {
			arrSelectsIgnore[i].overlap_ignore = true;
		}		

		for (i=0; i<arrSelects.length; i++) {
			//if the select overlaps the progress bar, and is visible, hide it and mark it
			if (DoesOverlap(oLayer, arrSelects[i]) && !arrSelects[i].overlap_ignore) {
				if (IsObjectVisible(arrSelects[i])) {
					arrSelects[i].style.visibility = 'hidden';
					arrSelects[i].overlap_hidden = true; //set expando value
					arrSelects[i].overlap_hidden_layer = oLayer.id;
					
					if (Browser.OS == OS_MAC && Browser.UserAgent == BROWSER_GECKO) {
						arrSelects[i].style.display = 'none';
					} else {
						CreateTempSelectDiv(arrSelects[i]);
					}
					
				}
			}
		}
	}
}

//shows the selects hidden by calling HideOverlappingSelects with the same layer
function ShowOverlappingSelects(oLayer) {
	if ((document.all || (Browser.OS == OS_MAC && Browser.UserAgent == BROWSER_GECKO)) && oLayer) {
		var arrSelects = document.getElementsByTagName('SELECT');
		var arrSelectsIgnore = oLayer.getElementsByTagName('SELECT');
		
		for (var i=0; i<arrSelects.length; i++) {
			if (arrSelects[i].overlap_hidden) { //read expando value
				if (arrSelects[i].overlap_hidden_layer == oLayer.id) {
					arrSelects[i].style.visibility = 'visible';
					if (Browser.OS == OS_MAC && Browser.UserAgent == BROWSER_GECKO) {
						arrSelects[i].style.display = 'block';
					}  else {
						RemoveTempSelectDiv(arrSelects[i]);
					}
				} 
			}
		}
		
		//prevents selects inside the div from being hidden
		for (i=0; i<arrSelectsIgnore.length; i++) {
			arrSelectsIgnore[i].overlap_ignore = false;
		}		
	}
}

//creates a div that looks just like the select object
function CreateTempSelectDiv(oSelect) {
	var oCoords = new ObjCoordinates(oSelect);
	var oTempDiv = document.createElement('<div id="' + oSelect.name + '_tempDiv" style="position:absolute; left:0px; top:0px; width:0px; height:0px; z-index:1"></div>');
	oTempDiv.style.width = oCoords.Width;
	oTempDiv.style.height = oCoords.Height;
	oTempDiv.style.top = oCoords.Top;
	oTempDiv.style.left = oCoords.Left;
	oTempDiv.style.border = "2px inset";
	oTempDiv.style.paddingLeft = "3px";
	oTempDiv.style.paddingTop = "0px";
	oTempDiv.style.fontFamily = 'Arial';

	if (oSelect.style.fontSize == '') {
		oTempDiv.style.fontSize = '11px';
	} else {
		oTempDiv.style.fontSize = parseInt(oSelect.style.fontSize) - 1;
	}

	oTempDiv.style.overflowY = 'scroll';
	
	if (oSelect.className == '') {
		oTempDiv.style.backgroundColor = "#FFFFFF";
	}

	if (oSelect.multiple) {
		oTempDiv.className = oSelect.className;
		oTempDiv.disabled = true;
		
		oTempDiv.style.overflowX = 'auto';
		oTempDiv.style.height = oCoords.Height;
		oTempDiv.style.width = oCoords.Width;
		for (var i=0; i<oSelect.options.length; i++) {
			oTempDiv.innerHTML += oSelect.options[i].text + '<br>';
			if (i >= 5) {
				break;
			}
		}
	} else {
		
		if (oSelect.selectedIndex >= 0) {
			oTempDiv.innerHTML = oSelect.options[oSelect.selectedIndex].innerHTML;
		}
	}
	document.body.appendChild(oTempDiv);
}

//removes the cooresponding "fake select" div
function RemoveTempSelectDiv(oSelect) {
	var oTemp = document.getElementById(oSelect.name + '_tempDiv');
	if (oTemp) {
		oTemp.removeNode(true);
	}
}

//wrapper object which makes it easy to access the coordinates of an HTML element
function ObjCoordinates(oObj) {
	if (!oObj) {
		return false;
	}
	
	this.Obj = oObj;
	
	this.Left = GetIeX(oObj);
	this.Top = GetIeY(oObj);
	this.Right = this.Left + parseInt(oObj.offsetWidth);
	this.Bottom = this.Top + parseInt(oObj.offsetHeight);
	
	this.Height = this.Bottom - this.Top;
	this.Width = this.Right - this.Left;
}

function GetName(oObj) {
	if (!oObj.id || oObj.id == '') {
		return oObj.name;
	} else {
		return oObj.id;
	}
}

function DoesOverlap(oObj, oCompareObj) {
	var cdObj = new ObjCoordinates(oObj);
	var cdCompareObj = new ObjCoordinates(oCompareObj);
	
	if (cdCompareObj.Left > cdObj.Left && cdCompareObj.Left < cdObj.Right) {
		if (cdCompareObj.Top > cdObj.Top && cdCompareObj.Top < cdObj.Bottom) {
			return true;
		} else if (cdCompareObj.Bottom > cdObj.Top && cdCompareObj.Bottom < cdObj.Bottom) {
			return true;
		}
	} else if (cdCompareObj.Right > cdObj.Left && cdCompareObj.Right < cdObj.Right) {
		if (cdCompareObj.Top > cdObj.Top && cdCompareObj.Top < cdObj.Bottom) {
			return true;
		} else if (cdCompareObj.Bottom > cdObj.Top && cdCompareObj.Bottom < cdObj.Bottom) {
			return true;
		}
	}
	
	return false;
}

function GetIeX(element) {
    var xPos = GetOffsetLeft(element);
    var tempElement = GetOffsetParent(element);
	
    while (tempElement != null) {
        xPos += GetOffsetLeft(tempElement);
		
		if (tempElement.tagName != "BODY") { 
			xPos -= tempElement.scrollLeft;
			
		}
		
        tempElement = GetOffsetParent(tempElement);
    }
	
    return xPos;
}

function GetIeY(element) {
    var yPos = GetOffsetTop(element);
    var tempElement = GetOffsetParent(element);

    while (tempElement != null) {
        yPos += GetOffsetTop(tempElement);

		if (tempElement.tagName != "BODY") {
			yPos -= tempElement.scrollTop;
		}
        tempElement = GetOffsetParent(tempElement);
    }
    return yPos;
}

//returns an object given its name as a string
function FindObj(n, d) {
  var p,i,x;  
  if (!d) d=document; 
  if ((p=n.indexOf("?"))>0 && parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; 
	n=n.substring(0,p);
  }
  if (!(x=d[n])&&d.all) x=d.all[n]; 
  for (i=0; !x && i < d.forms.length; i++) x=d.forms[i][n];
  for(i=0; !x && d.layers && i<d.layers.length; i++) x=FindObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); 
  return x;
}

//this function returns the position of an image
//coordinate should be supplied as 'x' or 'y'
function GetObjPositionLC(sName, sCoordinate, bScrollCoords){
	var oObj;

	if (typeof(sName) == "string") {
		oObj = FindObj(sName);
	} else if (typeof(sName) == "object") {
		oObj = sName;
	}

	if (document.layers) { //netscape
		return eval("theImage." + sCoordinate);
	} else { //DOM
		if (sCoordinate == 'x'){
			return GetIeX(oObj, bScrollCoords);
		} else {
			return GetIeY(oObj, bScrollCoords);
		}
	}
}

//given an object, returns the parent div tag (search tip layer)
function GetParentDiv(oObj, sAttributeName, sAttributeValue) {
	var oTemp = oObj;
	while (oTemp.parentNode) {
		if (oTemp.tagName == 'DIV') {
			if (sAttributeName && sAttributeValue) {
				if (GetAttributeEx(oTemp, sAttributeName) == sAttributeValue) {
					return oTemp;
				}
			} else {
				return oTemp;
			}
		} 
			
		oTemp = oTemp.parentNode;
	}
}

//given an object, returns the parent div tag (search tip layer)
function GetOffsetParent(oObj) {
	var oTemp = null;

	if (document.all) {
		oTemp = oObj.offsetParent;
	} else {
		if (oObj.offsetParent != oObj.parentNode && oObj.parentNode.tagName == "DIV") {
			oTemp = oObj.parentNode;
		} else {
			oTemp = oObj.offsetParent;
		}
	}

	if (oTemp != oObj) {
		return oTemp;
	} else {
		return null;
	}
}

//given an object, returns the parent div tag (search tip layer)
function GetOffsetTop(oObj) {
	if (document.all) {
		return oObj.offsetTop;
	} else {
		var oOffsetParent = GetOffsetParent(oObj);
		
		if (!oOffsetParent) {
			return 0;
		} else if (oOffsetParent.tagName == "DIV") {
			//if (oOffsetParent.style.overflow == "scroll") {
				//return (oObj.offsetTop - oOffsetParent.offsetTop) + 3;	
			//} else {
				return oObj.offsetTop - oOffsetParent.offsetTop;
			//}
		} else {
			return oObj.offsetTop;	
		}
	}
}

//given an object, returns the parent div tag (search tip layer)
function GetOffsetLeft(oObj) {
	if (document.all) {
		return oObj.offsetLeft;
	} else {
		var oOffsetParent = GetOffsetParent(oObj);
		
		if (!oOffsetParent) {
			return 0;
		} else if (oOffsetParent.tagName == "DIV") {
			//if (oOffsetParent.style.overflow == "scroll") {
				//return (oObj.offsetTop - oOffsetParent.offsetLeft) + 3;	
			//} else {
				return oObj.offsetLeft - oOffsetParent.offsetLeft;
			//}
		} else {
			return oObj.offsetLeft;	
		}
	}
}