
function absolute_pos_top (el) {
	return el.offsetParent?el.offsetTop+absolute_pos_top(el.offsetParent):el.offsetTop;
}
function absolute_pos_left (el) {
	return el.offsetParent?el.offsetLeft+absolute_pos_left(el.offsetParent):el.offsetLeft;
}

var that;
var cheight;
var hideflag=false;
var outer;
var navlist;
var navback;
var hidden;
var id;

function init(flag) {
	
	if (flag && document.all) EditorInit();
//	outer   = document.getElementById('outside');
	navlist = document.getElementById('inside');	
	navback = document.getElementById('frm');
	hidden  = document.getElementById('invisible');
	that=null;
	var tohide = new Array('hotel', 'catering', 'restaurant', 'pics', 'approach', 'congresses', 'trips', 'services', 'conditions');
	for (var el=0; el<tohide.length; el++) {
		if (hidden)
			hidden.appendChild(document.getElementById(tohide[el]));
	}

}


function bottom_fields(n) {

	if(n == 'congresses' || n == 'trips' || n == 'services' || n == 'conditions') return true;

	return false;
	
}

function mk_id(n) {
	n = n.replace(/\&amp;/g,'');
	return n.replace(/[\s\-]/g,'');
}

function show_nav(el, newid) {
	
	if (newid != undefined)
		id = newid;

	hideflag=false;
	var start = 0;
	var speed = 3;
//	var id = mk_id(el.innerHTML);
	if (bottom_fields(id)) {
		speed *= 2;
//		navlist.style.verticalAlign='bottom';
	} else {
//		navlist.scrollTop = 0;
//		navlist.style.verticalAlign='top';
	}

	var list = document.getElementById(id);
	if (list==null) {
		if (that!=null) {
			hideflag=true;
			fade_out(navlist, 9999);
		}
		return null;
	}
	var finalheight = list.style.height.substring(0,list.style.height.length-2);
	
	if (navlist) {
	
		if (that==el) {
			if (navlist.style.height==finalheight +"px") return null;
			start = parseInt(navlist.style.height.substring(0,navlist.style.height.length-2));
		}
		else if (that!=null) {
			hideflag=true;
			fade_out(navlist, 9999);
		}
		else {
		   navlist.style.height=0+'px';
		}


		that = el;
	
		var top = 0;
		if (bottom_fields(id)) {
			top = absolute_pos_top(that) - parseInt(navlist.style.height) +5;
		} else {
			top = absolute_pos_top(that) +12 ;
		}
		var left = absolute_pos_left(that)-10;
		
		that.className = 'menu_hover';
		navlist.style.left = left +'px';
		navlist.style.top    = top +'px';
		navlist.style.width = list.style.width;
	//	navback.style.width=navlist.style.width;
	//	navback.style.height=navlist.style.height;
	//	navback.style.top=navlist.style.top;
	//	navback.style.left=navlist.style.left;
		hidden.appendChild(navlist.firstChild);
		navlist.appendChild(list);
		navlist.scrollTop=0;
		navlist.style.display = 'block';
	//	navback.style.display='block';
		fade_in(navlist, start, speed, finalheight, 0);
	//	outer.style.display='block';

	}

}

function stop_hide_nav() {
	hideflag=false;
	show_nav(that);
}

function hide_nav() {
	hideflag=true;
	window.setTimeout(function(){if(hideflag)fade_out(navlist, 3);}, 500);
}

function fade_out(el, speed) {
	speed=Math.max(1,speed);
	cheight = Math.max(0, cheight-speed);

	if (cheight)
		el.style.height = cheight+'px';
	
	if (that) {
	
		if (bottom_fields(mk_id(that.innerHTML))) {
			var top = absolute_pos_top(that) - parseInt(navlist.style.height) +5;
			navlist.style.top = top +'px'
			navlist.scrollTop = 100;
		}
	
	//	navback.style.height=el.style.height;
		if (cheight>0) window.setTimeout(function(){if(hideflag)fade_out(el, speed);}, 1);
		else {
			el.style.display='none';
	//		outer.style.display='none'
	//		navback.style.display='none';
			that.className='menu_normal';
			hideflag=false;
			//that=null;
		}

	}

}


function fade_in(el, strt, speed, finalheight, c) {
	
	cheight = Math.min(strt+speed*c , finalheight);
	el.style.height = cheight +'px';

	if (bottom_fields(id)) {
		var top = absolute_pos_top(that) - parseInt(navlist.style.height) +5;
		navlist.style.top = top +'px'
		navlist.scrollTop = 100;
	}
//	navback.style.height=el.style.height;
	if (cheight<finalheight) {
		c=c+1;
		window.setTimeout(function(){fade_in(el, strt, speed, finalheight, c);}, 1);
	}

}


var rex   = /(\d+)(\.(\d*))?/;

function refreshLine(id1, id2, id3, sum, totalsum, e) {

	var key;
	
	if (e && e.which)
		key = e.which;
	else if (window.event)
		key = window.event.keyCode;

	// Nicht nach Tab, Shift und Pfeiltasten
	if (key != 9 && key != 16 && (key < 37 || key > 40)) {

		var preis = parseFloat(document.getElementById(id2).value);
		if (isNaN(preis)) preis=0;
		document.getElementById(id2).value = preis;

		var anz   = parseInt(document.getElementById(id1).value);
		if (isNaN(anz))   anz=0;
		// Nicht nach Backspace, Remove und Zahlen
		if (key != 8 && key != 46 && (key < 48 || key > 59) && (key < 96 || key > 105))
			document.getElementById(id1).value = anz;
		
		var s0   = Math.round(100*(preis * anz))/100;
		rex.exec(s0.toString());
		
		var s1    = RegExp.$1;
		var s2    = RegExp.$3;
		while (s2.length<2) s2 += '0';
		document.getElementById(id3).value =  s1 +','+ s2;
		refreshCalc(sum, totalsum);

	}

}

function refreshCalc(id1, id2) {
	var sums = document.getElementsByName(id1);
	var sum=0;
	var tmp=0;
	for (var i=0; i<sums.length; i++) {
		tmp = parseFloat(sums[i].value.replace(/,/,'.'));
		sum += tmp;
	}
	
	var s0 = Math.round(sum*100)/100;
	rex.exec(s0.toString());
	
	var s1    = RegExp.$1;
	var s2    = RegExp.$3;
	while (s2.length<2) s2 += '0';
	document.getElementById(id2).value =  s1 +','+ s2;
}


