function CreateMenu(sDir)
{
    var tmp;
    var tmp2;
	var sAlign;
	var sDir;
	
	if (sDir=="rtl") {sAlign="right";}
	else {sAlign="left";}
	
    menuDiv=document.getElementById("dropmenu");
    tmp2="<table border='0' cellspacing='0' cellpadding='1' width='100%'>";
    tmp2+="<tr><td height='5'></td></tr>";
    //tmp2+="<tr>";
    for (var i=1;i<=NumOfMenus;i++)
    {
        tmp=eval("dropmenu"+i);
        tmp=tmp[0].split(";");
        tmp2+="<tr><td class='MenuLink' onmouseover='ShowChilds(dropmenu"+i+",this,\"" +  sAlign + "\")' onmouseout='changeColor(this)' style='padding-right: 10px;padding-left: 10px;'>";
        if (tmp[1]!="")
        {
            tmp2+="<a href='"+tmp[1]+"' class='Link'>"+tmp[0]+"</a>";
        }
        else
        {
            tmp2+=tmp[0];
        }
        tmp2+="</td></tr>";
		tmp2+="<tr id='sub_" + tmp[2] + "' class='hide_element'><td id='sub_" + tmp[2] + "_td'></td></tr>"
        tmp2+="<tr><td height='5'></td></tr>";
        //if (i<NumOfMenus) { tmp2+="<td>|</td>"; }
    }
    tmp2+="</table>";
    menuDiv.innerHTML=tmp2
}

function getEY(oElement) {
    var iReturnValue = 0;
    while( oElement != null ) {
        iReturnValue += oElement.offsetTop;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}
function getEX(oElement) {
    var iReturnValue = 0;
    while( oElement != null ) {
        iReturnValue += oElement.offsetLeft;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}
var t;
var dropMenuDiv = document.createElement('span');
dropMenuDiv.style.display="none";
dropMenuDiv.style.position="absolute";
dropMenuDiv.style.backgroundColor="white";
dropMenuDiv.style.textAlign="center";
dropMenuDiv.style.border="1px solid #CCCCCC";
dropMenuDiv.style.width="120px";
dropMenuDiv.onmouseout=function() { HideChilds(1); }
dropMenuDiv.onmouseover=function() { clearTimeout(t); }

function changeColor(x)
{
    if (x.style.backgroundColor=="")
    {
        x.style.backgroundColor="#7B84B7";
        //x.style.color="black";
    }
    else
    {
        x.style.backgroundColor="";
        //x.style.color="black";
    }
}

function ShowChilds(menuId,x, sAlign)
{
    HideChilds(0);
	changeColor(x)
    dropMenuDiv.innerHTML="";
    var tmp;
    if (menuId.length>1)
    {
        for (var i=1;i<menuId.length;i++)
        {
            tmp=menuId[i].split(";");
            //dropMenuDiv.innerHTML+="<a href='"+tmp[1]+"'><div class='MenuLink' style='border-bottom: 1px solid #AEAEAE;width: 95%;text-align: " + sAlign + ";padding-right: 5px;cursor: hand;' class='text' onmouseover='changeColor(this);' onmouseout='changeColor(this);'>"+tmp[0]+"</div></a>"
            dropMenuDiv.innerHTML+="<a href='"+tmp[1]+"'><div class='MenuLink' style='border-bottom: 1px solid #AEAEAE;width: 100%;text-align: " + sAlign + ";padding-right: 1px;cursor: hand;' onmouseover='changeColor(this);' onmouseout='changeColor(this);'>"+tmp[0]+"</div></a>"
        }
        dropMenuDiv.style.top=eval(getEY(x))+"px";
        dropMenuDiv.style.left=eval(getEX(x)-x.offsetWidth+65)+"px";
        dropMenuDiv.style.display="block";
        document.body.appendChild(dropMenuDiv);
    }
    else
    {
        dropMenuDiv.style.display="none";
    }
}
function HideChilds(x)
{
    if (x==1)
    {
        t=setTimeout("dropMenuDiv.style.display='none'",150);
    }
    else
    {
        clearTimeout(t);
    }
}