
//var m=new Array(%jsmenu%);

var last_id=0;
var sel_td=new Array(null);
var timer;
var menus=new Array();
var divs=new Array();

function MakeMenus() {	
	var mid, lnk, css, subm, text, tar;
	var spnum=0;
	var ch;
	var str;
	var i=0, j;

	while (i<m.length) {
		var lastmid="!";
		str='';
		for (; i<m.length; i++) {
			mid=lnk=css=subm=text='';
			spnum = 0;
			for (j=0; j<m[i].length; j++) {
				ch = m[i].charAt(j);
				if (ch<'0'||ch>'9') break;
				mid+=ch;
			}
			if (mid!=lastmid&&lastmid!="!")
				break;
			lastmid=mid;
			
			switch (m[i].charAt(j)) {
				case '#': lnk=''; tar=' target="_blank"'; break;
				case '|': lnk=''; tar=''; break;
				case '~': lnk='?folder='; tar=''; break;
			}
			for (j++; j<m[i].length; j++) {
				ch = m[i].charAt(j);
				if (ch==' ') { 
					if (++spnum==3) break;
					continue; 
				}
				switch (spnum) { 
					case 0: lnk+=ch; break;
					case 1: css+=ch; break;
					case 2: subm+=ch; break;
				}
			}
			text='&nbsp;'+m[i].substr(j+1)+'&nbsp;';
			css = css ? ' class="'+css+'" ' : '';
			lnk = lnk ? ' href="'+lnk+'" ' : '';
			if (subm=="") subm="'!'";
			str+='<tr><td onmouseover="MouseOver(this,'+subm+')" onmouseout="MouseOut(this);" class="s1"><a'+lnk+tar+css+'>'+text+'</a></td></tr>';
		}
		str = '<TABLE cellpadding="0" cellspacing="0"">'+str+'</TABLE>';
		menus[lastmid] = str;
	}
}
MakeMenus();

function elementXY(element) {
	this.x=0;
	this.y=0;
	if (element.x&&element.y) {
		this.x=element.x;
		this.y=element.y;
	}
	else 
		while (element) {
			this.x+=element.offsetLeft;
			this.y+=element.offsetTop;
			element=element.offsetParent;
		}
}

function MouseOver(sender, subid) {
	clearTimeout(timer);

	var div=sender, id=0;
	while (div.parentNode) {
			if (div.parentNode==menudivs) {
				for (var i=0; i<divs.length; i++) {
					if (divs[i]==div) id=i+1;
				}
				break;
			}
		div=div.parentNode;
	}

	if (id!=0) {
		if (id>last_id&&sel_td[last_id]!=null)
			sel_td[last_id].className='s3';
		if (id<last_id)
			sel_td[id].className='s1';
		sender.className='s2';

		sel_td[id] = sender;
		last_id = id;
	}

	for (var i=divs.length-1; i>=id; i--) {
		menudivs.removeChild(divs.pop());
	}

	if (subid=="!") return;

	Pos=new elementXY(sender);
	if (id==0) {
		Pos.x--;
		Pos.y+=sender.offsetHeight+10;
	} else {
		Pos.x+=sender.offsetWidth;
		Pos.y--;
	}

	div=document.createElement("div");
	div.style.position='absolute';
	div.style.visibility = 'visible';
	div.style.left = Pos.x+"px";
	div.style.top = Pos.y+"px";
	div.innerHTML = menus[subid];

	menudivs.appendChild(div);
	divs.push(div);
}

function DestroyMenu() {
	if (divs.length) {
		menudivs.removeChild(divs.pop());
		timer=setTimeout('DestroyMenu();',150);
	}
	else {
		if (sel_td[0]!=null)
			sel_td[0].className='s1';
		timer=null;
	}
}

function MouseOut(sender) {
	timer=setTimeout("DestroyMenu();",300);
	if (sel_td[last_id])
		sel_td[last_id].className='s1';
}

var stype = "google";

function search_popup() {
	window.open('search.php?search='+stype+'&text='+document.form2.text.value); 
}

function enter_submit(form) {
	key = event.keyCode ? event.keyCode : event.which ? event.which :event.charCode;
	enter = key==13 || key==10;
	if (enter) form.submit();
	return !enter;
}

function popup(href) {
	var winwidth=670,winheight=500,winleft=(screen.width-winwidth)/2,wintop=(screen.height-winheight)/2;
	window.open(href, 'popup', 'width='+winwidth+', height='+winheight+', menubar=no, scrollbars=no, toolbar=no, location=no, resizable=no, top='+wintop+', left='+winleft);
}

function popup2(href) {
//	var winwidth=670,winheight=500,winleft=(screen.width-winwidth)/2,wintop=(screen.height-winheight)/2;
	window.open(href, 'popup', 'menubar=no, scrollbars=no, toolbar=no, location=no, resizable=yes');
}

// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
// you may copy these functions but please keep the copyright notice as well
function pageWidth() {return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;} 
function pageHeight() {return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;} 
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;} 
function posTop() {return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;} function posRight() {return posLeft()+pageWidth();} function posBottom() {return posTop()+pageHeight();}
function initWindow(width,height)
{
    pageWidth(width);
    pageHeight(height);
    posLeft((screen.width-width)/2);
    posTop((screen.height-height)/2);
}
