var bMenuOpen		= false
var nTypeOpen		= 0
var bHide			= false

function getAbsoluteX (obj) 
{
   var x = 0;
   if (obj && typeof obj.offsetParent != "undefined") {
     while (obj && typeof obj.offsetLeft == "number") {
       x += obj.offsetLeft;
       obj = obj.offsetParent;
     }
   }
   return x;
}

function getAbsoluteY(obj)
{
   var y = 0;
   if (obj && typeof obj.offsetParent != "undefined") {
     while (obj && typeof obj.offsetTop == "number") {
       y += obj.offsetTop;
       obj = obj.offsetParent;
     }
   }
   return y;
}

var strAgent 	= navigator.userAgent;
var strPlatform = navigator.platform;

function getDD(nType,nCount,bShow)
{
	if(bShow == true) {
		if(nType == 1) {
			if(getObj('inputMediumSelect').checked) getObj('mediumSelect').style.visibility = 'hidden';
			if(getObj('inputExpressionSelect').checked) getObj('expressionSelect').style.visibility = 'hidden';
		}
		bMenuOpen = true
		nTypeOpen = nType
		window.onmousemove = getMouseY;	
		var nAddMacIeX  = 0 
		var nAddMacIeY  = 0
		if(strAgent.indexOf("MSIE") > 0 && strPlatform.indexOf("Mac") >= 0) {
			nAddMacIeX = -2
			nAddMacIeY = -109
		}
		if(getObj("myartoffer")) {
			var nTop = 20;
			var nLeft = 40;
		} else {
			var nTop = 72;
			var nLeft = 19;
		}
		var x = getAbsoluteX(getObj("DD" + nType + "_" + nCount + "_field")) + nAddMacIeX - 206;
		var y = getAbsoluteY(getObj("DD" + nType + "_" + nCount + "_field")) + nAddMacIeY - 121;
		var objDiv  = getObj("DivDD" + nType + "_" + nCount);
		if(objDiv) {
			objDiv.style.top = y - nTop;
			objDiv.style.left = x - nLeft;
			objDiv.style.visibility = "visible";
		}
	} else {		
		if(nType == 1) {
			if(getObj('inputMediumSelect').checked) getObj('mediumSelect').style.visibility = 'visible';
			if(getObj('inputExpressionSelect').checked) getObj('expressionSelect').style.visibility = 'visible';
		}
		bMenuOpen = false
		for(i=1;i<=nType;i++) {
			for(j=1;j<=nCount;j++) {
				if(obj = getObj("DivDD" + i + "_" + j)) obj.style.visibility = "hidden";
			}
		}	
	}
}

var y = 0

function getMouseY(e)
{
	if(e) y = e.clientY;
}

function setTrue()
{
	bHide 		  = true
}

function hideAll()
{
	if(bMenuOpen) {
		if(bHide) {
			bHide = false
			getDD(1,1,false)
			getDD(2,1,false)
		} else {
			setTimeout("setTrue()",500)
		}
		var i = 0
		var objHide = null
		if(!document.getElementsByName("DD_exp")[i])
		while(objHide = document.getElementsByName("DD_exp")[i]) {
			objHide.style.visibility = "hidden";
			i++;
		}
	}
}

function rollOver(nType,nCount,bExpand,nExpandnr,bMove)
{
	var i = 0
	var objHide = null
	while(objHide = document.getElementsByName("DD_exp")[i])
	{
		objHide.style.visibility = "hidden";
		i++;
	}
	var objTd = getObj("DD" + nType + "_" + nCount + "_src" + nExpandnr);
	if(bExpand == "true")
	{
		if(window.event) {
			y = window.event.clientY
		} else  {	
			window.onmousemove = getMouseY;
		}
		var x = 0;
		if(!(strAgent.indexOf("MSIE") > 0 && strPlatform.indexOf("Mac") >= 0)) objTd.className = "drop_down_select_over_expand";
		var objSecDiv = getObj("DD" + nType + "_" + nCount + "_exp" + nExpandnr);
		if(bMove) {
			var nScrollTop = 0
			var nScrollTop2 = 0
			var bScrollTop = true
			if((nScrollTop = document.body.scrollTop)) nScrollTop2 = document.body.scrollTop
			x = getAbsoluteX(objTd) - 185
			y = (y + nScrollTop2) - 116
			objSecDiv.style.top = y - 60
			objSecDiv.style.left = (x - 150);
		}
		objSecDiv.style.visibility = "visible";
	} else {
		if(!(strAgent.indexOf("MSIE") > 0 && strPlatform.indexOf("Mac") >= 0)) objTd.className = "drop_down_select_over";
	}
}

function rollOut(nType,nCount,bExpand,nExpandnr)
{
	if(bExpand == "true") 
	{
		if(!document.getElementsByName("DD_exp")[0]) getObj("DD" + nType + "_" + nCount + "_exp" + nExpandnr).style.visibility = "hidden";
		if(!(strAgent.indexOf("MSIE") > 0 && strPlatform.indexOf("Mac") >= 0)) getObj("DD" + nType + "_" + nCount + "_src" + nExpandnr).className = "drop_down_expand";
	}
	else
	{
		if(!(strAgent.indexOf("MSIE") > 0 && strPlatform.indexOf("Mac") >= 0)) getObj("DD" + nType + "_" + nCount + "_src" + nExpandnr).className = "drop_down_select";
	}
}

function rollOverSec(nType,nCount,nKey)
{
	if(!(strAgent.indexOf("MSIE") > 0 && strPlatform.indexOf("Mac") >= 0)) getObj("DD" + nType + "_" + nCount + "_td_sec" + nKey).className = "drop_down_select_over";
}

function rollOutSec(nType,nCount,nKey)
{
	if(!(strAgent.indexOf("MSIE") > 0 && strPlatform.indexOf("Mac") >= 0)) getObj("DD" + nType + "_" + nCount + "_td_sec" + nKey).className = "drop_down_select";
}

function selectItem(nType,nCount,nKey,strValue,nTablenr)
{
	if(nType == 1) 
	{
		getObj("motive" + nCount +"nr").value = nKey;
	}
	if(nType == 2) 
	{
		getObj("imageCategorienr").value = nKey;
	}
	if(nTablenr) getObj("DD" + nType +  "_" + nCount + "_exp" + nTablenr).style.visibility = "hidden";
	getObj("DD" + nType + "_" + nCount + "_field").style.position = "static";
	getObj("DD" + nType + "_" + nCount + "_field").style.visibility = "visible";
	getObj("DD" + nType + "_" + nCount + "_field").value = strValue;	
	if(getObj("formMotive") && nType == 1) 			getObj("formMotive").submit();
	if(getObj("formImageCategorie") && nType == 2) 	getObj("formImageCategorie").submit();
	hideAll()
	bMenuOpen = false
}
