//toframe();
//var base="file://D:/Daten/WWW/praxis-pfiff/pages";
//if(location.href.substr(0,4) == 'http') base="http://www.cowedis.de/kunden/praxis-pfiff/htmdocs";

var InitFlag = false;
var dirsep = '\\';
if(document.URL.substr(0,4) == 'http') dirsep = '/';
//var topUrl = top.location.href.substr(0, top.location.href.lastIndexOf('/') + 1);
var topUrl = base;
//alert(topUrl + " " + topUrl.length);
var colorOff = "#006";
var colorOver = "#009";
var colorOn  = "RGB(163,137,41)";
var lineOff = "none";
var lineOn  = "1px solid RGB(200,10,5)";
var backgroundColorOff = "";
var backgroundColorOn  = "";

var MenuNames = new Array();
var mCount;
var MenuStatus;
function init()
{
//alert("InitFlag: " + InitFlag);
	if(InitFlag) return;
	var linkList = new Array();
	linkList = document.getElementsByTagName('a');
	j = 0;
	for(i=0; i<linkList.length; i++)
	{
		linkBasename = linkList[i].getAttribute('href');
		if(linkBasename.indexOf(topUrl) >= 0) linkBasename = linkBasename.substr(topUrl.length);
		linkBasename = linkBasename.substr(0, linkBasename.indexOf('.'));
//		alert(linkBasename);
		if(linkBasename.indexOf('/index') > 0) linkBasename = linkBasename.substr(0, linkBasename.indexOf('/index'));
		if(linkBasename.lastIndexOf('/') > 0) linkBasename = linkBasename.substr(linkBasename.lastIndexOf('/') + 1);
		if(document.getElementById(linkBasename))
		{
			MenuNames[j] = document.getElementById(linkBasename).id;
			j++;
//			alert(j + " " + linkBasename + " " + MenuNames[j] );
		}
	}
	mCount = j;
//alert(self.name + " j=" + j + " MenuNames[0]=" + MenuNames[0]);
//			alert(j + " " + linkBasename + " " + MenuNames[j] );
	document.getElementById(MenuNames[0]).style.color = colorOn;
	document.getElementById(MenuNames[0]).style.borderBottom = lineOn;
	document.getElementById(MenuNames[0]).style.backgroundColor = backgroundColorOn;
	InitFlag = true;
}

function ShowButton(alnk,evt)
{
	init();
	lnk = alnk.getAttribute('href');
	if(evt==0)
	{
		for(i=0; i < mCount; i++)
		if (lnk.indexOf(MenuNames[i])>0)
		{
			if(MenuStatus==i)
			{
				document.getElementById(MenuNames[i]).style.color = colorOn;
				document.getElementById(MenuNames[i]).style.backgroundColor = backgroundColorOn;
			}
			else
			{
				document.getElementById(MenuNames[i]).style.color = colorOff;
				document.getElementById(MenuNames[i]).style.backgroundColor = backgroundColorOff;
			}
		}
	}
	else
	{
		for(i=0;i<mCount;i++)
		if (lnk.indexOf(MenuNames[i])>0)
		{
			if(MenuStatus==i)
			{
				document.getElementById(MenuNames[i]).style.color = colorOn;
				document.getElementById(MenuNames[i]).style.backgroundColor = backgroundColorOn;
			}
			else
			{
				document.getElementById(MenuNames[i]).style.color = colorOver;
				document.getElementById(MenuNames[i]).style.backgroundColor = backgroundColorOn;
			}
		}
	}
}

function ChangeButton(url)
{
	init();

//alert(url);
	btn = url.substr(url.lastIndexOf(dirsep)+1);
	btn = btn.substr(0, btn.lastIndexOf('.'));
//alert(btn);
	for(i=0;i<mCount;i++)
	if(btn.indexOf(MenuNames[i])>=0)
	{
		document.getElementById(MenuNames[i]).style.color = colorOn;
		if(self.name == "SubSelect")
		{
			document.getElementById(MenuNames[i]).style.borderBottom = lineOff;
		}
		else
		{
			document.getElementById(MenuNames[i]).style.borderBottom = lineOn;
			//alert(line_height);
//			alert(MenuNames[i]);
		}
		document.getElementById(MenuNames[i]).style.backgroundColor = backgroundColorOn;
		
		MenuStatus=i;
	}else{
		document.getElementById(MenuNames[i]).style.color = colorOff;
		document.getElementById(MenuNames[i]).style.borderBottom = lineOff;
		document.getElementById(MenuNames[i]).style.backgroundColor = backgroundColorOff;
	}
}

var color_out = '#ffffff';
var color_over = '#88aadd';
var color_default = '#000033';
var color_selected = '#cc0000';
var selected_index = 0;
function changeCell(cell)
{
	row=cell.parentNode;
	for(i=0;i<row.cells.length;i++)
	{
		if(i==selected_index)
		{
			row.children.tags('TD')[i].children.tags('A')[0].style.color = color_selected;
		}else{
			row.children.tags('TD')[i].children.tags('A')[0].style.color = color_default;
		}
	}
}

function mClick(cell)
{
      selected_index=cell.cellIndex;
	  changeCell(cell);
      cell.children.tags('A')[0].click();
}

function mOver(cell)
{
	  cell.style.cursor = 'hand';
      cell.style.backgroundColor = color_over;
}

function mOut(cell)
{
   if (!cell.contains(event.toElement))
   {
	  cell.style.cursor = 'default';
      cell.style.backgroundColor = color_out;
   }
}

function setSubMenu(mName)
{
if (location.href.indexOf("select.htm")>=0)
{
	var ie = document.all ? 1 : 0
	for(i=0;i<mCount;i++)
	if(mName==SubMenuNames[i])
	{
if(ie){eval("document.all."+mName+".style").color=color_selected;}
    else{eval("document."+mName+".color='"+color_selected+"'");}
	}else{
if(ie){eval("document.all."+SubMenuNames[i]+".style").color=color_default;}
    else{eval("document."+SubMenuNames[i]+".color='"+color_default+"'");}
	}
}else{
parent.SubSelect.setSubMenu(mName);
}
}


