

var menuopen=-1;
var menuurlprefix='';

function findObj(n) {
	var x;
	
	d=document;
	if(!(x=d[n])&&d.all) x=d.all[n];
	if(!x && d.getElementById) x=d.getElementById(n);
	return x;
}

function hidemenu(menuid) {
	menuobj=findObj("menu"+menuid)
	menuheadobj=findObj("menuhead"+menuid)

	if (menuobj)
		menuobj.style.visibility='hidden';
	menuheadobj.className='menuhead';

	menuopen=-1;
}

function showmenu(menuid) {
	menuobj=findObj("menu"+menuid);
	menuheadobj=findObj("menuhead"+menuid)

	var ns6=document.getElementById&&!document.all;

	if (menuobj)
	{
		dh=document.body.clientHeight;
		menupos=ns6?(menuheadobj.parentNode.pageY-this.pageYOffset):(menuheadobj.parentElement.offsetTop-document.body.scrollTop);
		menuheight=menuobj.clientHeight;
		if((menupos+menuheight>dh)&&(menupos>0))
		{
			menutop=dh-(menuheight+menupos)-2;
			if (menutop<-menupos) menutop=-menupos;
			menuobj.style.top=menutop;
		}
		else
		{
			menuobj.style.top=0;
		}

		menuobj.style.visibility='visible';

		//menuobj.filters.opacity=55;
		//menutobj.filters.opacity=55;

		menuheadobj.className='menuhead_opensub';
	} else {
		menuheadobj.className='menuhead_open';
	}

	menuopen=menuid;
}

function menuhead_rollon(e) {
	var ns6=document.getElementById&&!document.all;
	o=ns6? e.target : window.event.srcElement;

	openmenuid=o.id.substr(8);

	if(menuopen>=0) hidemenu(menuopen);

	showmenu(openmenuid);
}

function menu_rollon(e) {
	var ns6=document.getElementById&&!document.all;
	o=ns6? e.target : window.event.srcElement;
	if (o.id=="nothing")
		return;
	if (o.className == "menuopt") o.className = "menuopt_over";
}

function menu_rolloff(e) {
	var ns6=document.getElementById&&!document.all;
	o=ns6? e.target : window.event.srcElement;
	if (o.id=="nothing")
		return;
  	if (o.className.substring(0,7) == "menuopt") o.className = "menuopt";
}

function menu_mousedown(e) {
	var ns6=document.getElementById&&!document.all;
	o=ns6? e.target : window.event.srcElement;
	if (o.id=="nothing")
		return;
	if (o.className == "menuopt_over") o.className = "menuopt_click";
 	if (o.className == "menuhead_open") o.className = "menuhead_click";
 	if (o.className == "menuhead_opensub") o.className = "menuhead_clicksub";
}

function menu_mouseup(e) {
	var ns6=document.getElementById&&!document.all;
	o=ns6? e.target : window.event.srcElement;
	if (o.id=="nothing")
		return;
 	if (o.className == "menuopt_click") o.className = "menuopt_over";
 	if (o.className == "menuhead_click") o.className = "menuhead_open";
 	if (o.className == "menuhead_clicksub") o.className = "menuhead_opensub";
}

function menu_mouseclick(e) {
	var ns6=document.getElementById&&!document.all;
	o=ns6? e.target : window.event.srcElement;
	if (o.id=="nothing")
		return;
	if (o.className == "menuopt_over") {
		menusubid=o.id.split(".");
		menuid=menusubid[0];
		menuoptid=menusubid[1];
		t=menuoptions[menuid][menuoptid].split('|');
		newurl=t[1];
		if (newurl.substr(0,7)!='http://') newurl=menuurlprefix + newurl;
		if (newurl.substr(0,1)=="@")
			OnGoSubmit(newurl.substr(1,newurl.length));
		else if (newurl!="")
			window.location=newurl;
	} else if ((o.className == "menuhead_open")||(o.className == "menuhead_opensub")) {
		menuid=o.id.substr(8);
		t=menuoptions[menuid][0].split('|');
		newurl=t[1];
		if (newurl.substr(0,7)!='http://') newurl=menuurlprefix + newurl;
		if (newurl.substr(0,1)=="@")
			OnGoSubmit(newurl.substr(1,newurl.length));
		else if (newurl!="")
			window.location=newurl;
	}
}

function document_mouseover(e) {
	if(menuopen>=0) {
		var ns6=document.getElementById&&!document.all;
		o=ns6? e.target : window.event.srcElement;
		if (o.id=="nothing")
			return;
		menuobj=findObj("menu"+menuopen);
		if (menuobj)
		{
			if ((menuobj.style.visibility == "visible")&&(o.id.length==0))
				hidemenu(menuopen);
		}
		else
		{
			menuobj=findObj("menuhead"+menuopen);
			if ((menuobj.className == "menuhead_open")&&(o.id.length==0)) menuobj.className="menuhead";
		}
	}
}

function menu_build()
{
	for (x in menuoptions) {
		subopts=menuoptions[x].length;
		vpos=165+(x*17);
		if (subopts >=14)
		{
			for (var y=0; y < subopts; y++)
			{
				t=menuoptions[x][y].split('|');
				if(y==0)
				{
					document.write ('<span class="menuspan" style="position: absolute; top: ' + vpos + '">&nbsp;&nbsp;');
					document.writeln ('<span class="menuhead" id="menuhead'+x+'" unselectable="on">'+t[0]+'</span>');
					if(subopts>1) document.writeln ('<span id="menu'+x+'" class="menu"><table width="'+(2*t[2])+'" border="0" cellspacing="0" cellpadding="0">');
				}
				else
				{
					document.writeln ('<tr><td class="menuopt" id="'+x+'.'+y+'" unselectable="on">'+t[0]+'</td>');
					y++;
					if (y >= subopts)
						document.writeln ('<td class="menuopt" id="nothing" unselectable="on">&nbsp;</td></tr>');
					else
					{
						tt=menuoptions[x][y].split('|');
						document.writeln ('<td class="menuopt" id="'+x+'.'+y+'" unselectable="on">'+tt[0]+'</td></tr>');
					}
				}
			}
			if(subopts>1) document.writeln('</table></span>');
			document.write('</span>');
		}
		else
		{ 
			for (var y=0; y < subopts; y++) {
				t=menuoptions[x][y].split('|');
				if(y==0)
				{
					document.write ('<span class="menuspan" style="position: absolute; top: ' + vpos + '">&nbsp;&nbsp;');
					document.writeln ('<span class="menuhead" id="menuhead'+x+'" unselectable="on">'+t[0]+'</span>');
					if(subopts>1) document.writeln ('<span id="menu'+x+'" class="menu"><table width="'+t[2]+'" border="0" cellspacing="0" cellpadding="0">');
				}
				else
				{
					document.writeln ('<tr><td class="menuopt" id="'+x+'.'+y+'" unselectable="on">'+t[0]+'</td></tr>');
				}
			}
			if(subopts>1) document.writeln('</table></span>');
			document.write('</span>');
		}
	}
}

function menu_addevents() {
	for (x in menuoptions) {
		var mh=document.getElementById? document.getElementById('menuhead'+x): eval('document.all.menuhead'+x);
		mh.onmouseover = menuhead_rollon;
		mh.onmousedown = menu_mousedown;
		mh.onmouseup = menu_mouseup;
		mh.onclick = menu_mouseclick;
		if (menuoptions[x].length>1) {
			var m=document.getElementById? document.getElementById('menu'+x): eval('document.all.menu'+x);
			m.onmouseout = menu_rolloff;
			m.onmouseover = menu_rollon;
			m.onmousedown = menu_mousedown;
			m.onmouseup = menu_mouseup;
			m.onclick = menu_mouseclick;
		}
	}
	document.onmouseover=document_mouseover;
}

function OnGoResetSearch()
{
	this.document.SearchForm.Composer.selectedIndex=0;
	this.document.SearchForm.Category.selectedIndex=0;
	this.document.SearchForm.Genre.selectedIndex=0;
	this.document.SearchForm.Key.selectedIndex=0;
	this.document.SearchForm.SoloInstrument.selectedIndex=0;
	this.document.SearchForm.Timing.selectedIndex=0;
}

function OnGoSearch()
{
	if ((this.document.SearchForm.Composer.selectedIndex == 0)&&(this.document.SearchForm.Category.selectedIndex == 0)
			&&(this.document.SearchForm.Genre.selectedIndex == 0)&&(this.document.SearchForm.Key.selectedIndex == 0)
			&&(this.document.SearchForm.SoloInstrument.selectedIndex == 0)&&(this.document.SearchForm.Timing.selectedIndex == 0))
	{
		alert("Please enter your requirment for search.");
		return;
	}
	var Tmp="SystemLink_Summary";
	if (this.document.SearchForm.Composer.selectedIndex > 0)
		Tmp+="_O"+this.document.SearchForm.Composer.options[this.document.SearchForm.Composer.selectedIndex].value;
	if (this.document.SearchForm.Category.selectedIndex > 0)
		Tmp+="_C"+this.document.SearchForm.Category.options[this.document.SearchForm.Category.selectedIndex].value;
	if (this.document.SearchForm.Genre.selectedIndex > 0)
		Tmp+="_G"+this.document.SearchForm.Genre.options[this.document.SearchForm.Genre.selectedIndex].value;
	if (this.document.SearchForm.Key.selectedIndex > 0)
		Tmp+="_K"+this.document.SearchForm.Key.options[this.document.SearchForm.Key.selectedIndex].value;
	if (this.document.SearchForm.SoloInstrument.selectedIndex > 0)
		Tmp+="_S"+this.document.SearchForm.SoloInstrument.options[this.document.SearchForm.SoloInstrument.selectedIndex].value;
	if (this.document.SearchForm.Timing.selectedIndex > 0)
		Tmp+="_T"+this.document.SearchForm.Timing.options[this.document.SearchForm.Timing.selectedIndex].value;
	this.location=Tmp;
}

function OnGoSubmit(XType)
{
	this.document.Form1.action=""+XType;
	this.document.Form1.submit();
}