
$=function(e){return document.getElementById(e)};

var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
	try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } 
	catch (e) {
		try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } 
		catch (E) { xmlhttp = false; }
	}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try { xmlhttp = new XMLHttpRequest(); } 
	catch (e) { xmlhttp=false; }
}
if (!xmlhttp && window.createRequest) {
	try { xmlhttp = window.createRequest(); } 
	catch (e) { xmlhttp=false; }
}

set_document = function(link)
{
	$('text').innerHTML = '<div style="text-align:center; padding:250px 0px 200px 0px; font-size:13px; color:rgb(150,150,150); font-weight:bold">' + '<img src="ims/loading.gif" />' + '</div>';

	xmlhttp.open("GET", "get_page.php?page=" + link,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			$('text').innerHTML = xmlhttp.responseText;
			text_init();
		}
	}
	xmlhttp.send(null)
}

animation = {
	timeout:false,
	vals:[],
	eff_linear: function(i){return (Math.sin((i-0.5)*Math.PI)+1)/2;},
//	eff_linear: function(i){return (i>=0.5 ? 1 : 0);},
	ontick:function(){
		drop = new Array();
		for(i in animation.vals){
			var val = animation.vals[i];
			val.step++;
			val.e[val.v] = (val.eff(val.step/val.steps)*(val.end-val.begin)+val.begin) + val.type;

			if(val.step == val.steps){
				if(val.onend) val.onend();
				drop.push(i);
			}
		}
		if(drop.length > 0) {
			while(i = drop.pop()){
				animation.vals.splice(i,1);
			}
		}
		if(animation.vals.length == 0){
			animation.timeout = false;
		} else {
			animation.timeout = window.setTimeout(animation.ontick, 20);
		}
	},
	set:function(e, v, begin, end, type, eff, steps, onend){
		animation.vals.push({e:e, v:v, begin:begin, end:end, type:type, steps:steps, step:0, eff:eff, onend:onend});
		if(animation.timeout == false){
			animation.timeout = window.setTimeout(animation.ontick, 50);
		}
	}
}

menu_opens = [];
menu_anim_open = function(e){
	if(e.className == 'menuitem'){
		e.className = 'menuitemactive';
		menu_opens.push(e);
	}
	var next = e.nextSibling;
	if(next && next.className == 'mi_sub'){
		if(next.style.display == 'none'){
			next.style.display = 'block';
			var h = menuitems_getsize(next);
			animation.set(next.style, 'height', 0, h, 'px', animation.eff_linear, Math.round(10), function(){
				next.style.height = '';
			});
//			menu_opens.push(next);
			return h;
		}
	}
	return 0;
}

menu_open = function(e){
	if(e.className == 'menuitem'){
		e.className = 'menuitemactive';
		menu_opens.push(e);
	}
	var next = e.nextSibling;
	if(next && next.className == 'mi_sub' && next.style.display == 'none'){
		next.style.display = 'block';
		next.style.height = '';
//		menu_opens.push(next);
	}
}

menu_anim_close = function(e){
	if(e.nextSibling && e.nextSibling.className == 'mi_sub' && e.nextSibling.style.display != 'none'){
		var h = e.nextSibling.clientHeight;
		animation.set(e.nextSibling.style, 'height', h, 0, 'px', animation.eff_linear, Math.round(10), function(){ e.nextSibling.style.display = 'none'; });
	}
	if(e.className == 'menuitemactive'){
		e.className = 'menuitem';
	}
}

menu_close = function(e){
	if (e.nextSibling && e.nextSibling.className == 'mi_sub' && e.nextSibling.style.display != 'none'){
		e.nextSibling.style.display = 'none';
		e.nextSibling.style.height = '0px';
	}
	if(e.className == 'menuitemactive'){
		e.className = 'menuitem';
	}
}


menu_click = function(e)
{
	var link = e.firstChild.href.toString();
	var pos = link.indexOf('?a&');
	if(pos != -1){
		link = link.substr(0,pos+1) + link.substr(pos+3);	
	}
	menu_open_url(link);
	
	link = link.substr(link.lastIndexOf('=')+1);
	window.scrollTo(0,0);
	set_document(link);
	return false;
}




/*

menu_click = function(e)
{
	//alert('opens:' + menu_opens.length);

	var link = e.firstChild.href;
	link = link.substr(link.lastIndexOf('=')+1);
	set_document(link);

	if(e.className == 'menuitem' || e.className == 'menuitemactive'){
		while(o = menu_opens.pop()){
			if(o == e.parentNode.previousSibling){
//alert('OPUSH: '+o.innerHTML);
				menu_opens.push(o);
				break;
			}
			menu_user_close(o);
		}

		while(1){
			menu_user_open(e);
			if(e.firstChild.href.indexOf('?a&') == -1)
				break;
			if(e.nextSibling && e.nextSibling.className == 'mi_sub'){
				e = e.nextSibling.firstChild;
				if(e.id == 'submenu_bh'){
					e = e.nextSibling;
				}
			} else {
				break;
			}
		}
	}
	return false;
}
*/
menu_open_url = function(url)
{
	var menu = $('menubox');
	var links = menu.getElementsByTagName('a');
	for(i=0; i<links.length; i++){
		if(links[i].href.toString() == url){
			menu_open_to(links[i]);
			return true;
		}
	}
	menu_open_to(menu);
	return false;
}

menu_open_to = function(e) {
	e = e.parentNode;
	path = [];

	if(e.className == 'menuitem') {
		path.push(e);
		while(e = e.parentNode.previousSibling){
			if(e.className != 'menuitem'){
				break;
			}
			path.push(e);
		}
	} else {
	//	e = e.parentNode.previousSibling;
	}

	var open;

	if(menu_opens.length > 0) {
		while(open = menu_opens.pop()){
			if(open == e){ menu_opens.push(open); break; }
			menu_user_close(open);
		}
	}

	while(node = path.pop()){
		menu_user_open(node);
	}
}

menuitems_getsize = function(e)
{
	if(e.hasChildNodes())
	{
		var children = e.childNodes;
		var counter = 0;
		for (var i = 0; i < children.length; i++) 
			if(children[i].className == 'menuitem')
				counter++;
		if(e.parentNode.className == 'mi_sub')
			return counter*21;
		return 23 + counter*21;
	}
	return 0;
}

onLinkClick = function(){
	url = this.toString();
	page_pos = url.lastIndexOf('=');
	if(page_pos != -1){
		link = url.substr(page_pos + 1);
	} else{
		link = '';
	}
	window.scrollTo(0,0);
	set_document(link);
	

	menu_open_url(this);
	return false;
}

text_init = function(){
	var tpage = '';
	var tpagei = document.location.toString().indexOf('?');
	if(!tpagei) tpagei = document.location.toString().indexOf('/');
	if(tpagei){
		tpage = window.location.toString().slice(0,tpagei);
	}
	var links = document.getElementsByTagName('a');
	for(i=0;i<links.length;i++){
		if(!links[i].onClick 
		&&  links[i].href.toString().indexOf('page=') != -1
		&&  links[i].parentNode.className != 'menuitem'
		&&  links[i].parentNode.className != 'menuitemactive'
		&&  links[i].parentNode.className != 'menubox'
		&&  links[i].toString().indexOf(tpage) == 0){
			links[i].onclick = onLinkClick;
		}
	}
}

menu_user_open = menu_open;
menu_user_close = menu_close;
menu_init = function(){
	pos = window.location.toString().lastIndexOf('&');
	if(pos == -1){
		menu_open_url(window.location.toString());
	} else {
		posl = window.location.toString().indexOf('?');
		menu_open_url(window.location.toString().slice(0,posl+1) + window.location.toString().slice(pos+1));
	}

	text_init();

	var d = new Date();
	var t = d.getTime();
	for(i=0;i<10;i++){
		$('speed').style.width=i;
	}
	d = new Date();
	if((d.getTime() - t) <= 1){
		menu_user_open = menu_anim_open;
		menu_user_close = menu_anim_close;
	}
}

h2_open = function(e){ e.nextSibling.style.display = e.nextSibling.style.display == 'none' ? 'block' : 'none'; }
slct_onchange = function(e){
	if(e.selectedIndex){
		$('s1').disabled = $('s2').disabled = $('s3').disabled = true;
		$('s1').style.backgroundColor = $('s2').style.backgroundColor = $('s3').style.backgroundColor = 'rgb(200,200,200)';
	} else {
		$('s1').disabled = $('s2').disabled = $('s3').disabled = false;
		$('s1').style.backgroundColor = $('s2').style.backgroundColor = $('s3').style.backgroundColor = 'white';
	}
}

