// $Id: cms.js 7335 2008-06-24 10:50:12Z jss $

	function set_focus () {
		if (document.forms[0]) {
			for (j = 0; j < document.forms.length; j++) {
				for (i = 0; i < document.forms[j].length; i++) {
					if (document.forms[j][i].name == 'username') {
						document.forms[j][i].focus();
						break;
					}
				}
			}
		}
	}

	function unload() {
		if (document.input_changes && document.forms[document.input_name]) {
			if (confirm("Save changes?")) {
				for (i = 0; i < document.forms[document.input_name].length; i++) {
					if (document.forms[document.input_name][i].type == 'submit') {
						document.forms[document.input_name][i].click();
						break;
					}
				}
			}
		}
	}


	function init() {
		set_focus();
	}



	var pop_window = null;

	function popup(url, w, h) { 
		var winl = 0;
		var wint = 0;
		w = w + 50;
		h = h + 50;
		if (screen) {
			var winl = (screen.width - w) / 2;
			var wint = (screen.height - h) / 2;
		}
		winprops = 'height='+h+', width='+w+', top='+wint+', left='+winl+', scrollbars=0';

		if (pop_window && !pop_window.closed && pop_window.location) {
			pop_window.close();
		}
		pop_window = window.open(url, "member", winprops);
	}

	function popup_scroll(url, w, h) {

		var winl = 0;
		var wint = 0;
		w = w + 50;
		h = h + 50;
		if (screen) {
			var winl = (screen.width - w) / 2;
			var wint = (screen.height - h) / 2;
		}
		winprops = 'height='+h+', width='+w+', top='+wint+', left='+winl+', scrollbars=1';

		if (pop_window && !pop_window.closed && pop_window.location) {
			pop_window.close();
		}
		pop_window = window.open(url, "member", winprops);
	}


	function box_lists_add (form_obj, left, right) {
		box_lists_change(form_obj, left, right);
		box_lists_update(form_obj, left, right);
	}

	function box_lists_remove (form_obj, left, right) {
		box_lists_change(form_obj, right, left);
		box_lists_update(form_obj, left, right);
	}


	function box_lists_update (form_obj, left, right) {
		form_obj[left + '_' + right].value = '';

		for (i = 0; i < form_obj[right].length; i++) {
			if (i == form_obj[right].length - 1)
				form_obj[left + '_' + right].value = form_obj[left + '_' + right].value + form_obj[right][i].value;
			else
				form_obj[left + '_' + right].value = form_obj[left + '_' + right].value + form_obj[right][i].value + ',';
		}
		document.changed = true;
	}

	function box_lists_change (form_obj, left, right) {
		var
			opt_value, opt_text;

		for (;form_obj[left].selectedIndex > -1;) {
			opt_value = form_obj[left][form_obj[left].selectedIndex].value;
			opt_text = form_obj[left][form_obj[left].selectedIndex].text;
			form_obj[left][form_obj[left].selectedIndex] = null;
			form_obj[right][(form_obj[right].length)] = new Option(opt_text, opt_value);
		}
	}

	function box_expand (form_obj, area) {
		if (document.getElementById(area)) {
			if (form_obj.checked)
				document.getElementById(area).style.display = 'none';
			else
				document.getElementById(area).style.display = 'block';
		}
	}

	function box_expand_radio (form_obj, area) {
		if (document.getElementById(area)) {
			if (form_obj.value == 0)
				document.getElementById(area).style.display = 'none';
			else
				document.getElementById(area).style.display = 'block';
		}
	}

	function box_expand_flip (form_obj, area) {
		if (document.getElementById(area)) {
			if (!form_obj.checked)
				document.getElementById(area).style.display = 'none';
			else
				document.getElementById(area).style.display = 'block';
		}
	}

	var faq_current = '';

	function faq_expand (area) {
		if (document.getElementById(area)) {
			if (document.getElementById(area).style.display == 'block') {
				document.getElementById(area).style.display = 'none';
				faq_current = '';
			}
			else {
				document.getElementById(area).style.display = 'block';
				if ( (faq_current != area) && (faq_current != '') )
					faq_expand(faq_current)
				faq_current = area;
			}
		}
	}

	// mutually excludes one ore more form fields
	function mutualExclude() { // argument list = names of mutually exclusive fields (onchange trigger is the first in list)
		var fields = arguments;

		var disabled = true;

		if (!document.forms[0][fields[0]].value || document.forms[0][fields[0]].value == "0") {
			disabled = false;
		}

		for(i=1; i<arguments.length; i++) {
			document.forms[0][fields[i]].disabled = disabled;
		}

	}

	function inputFocus(ele, txt) {
		if (ele.value == txt) {
			ele.value = "";
		}
	}

	function inputBlur(ele, txt) {
		if (ele.value == "") {
			ele.value = txt;
		}
	}

	function template_forms_multi (form_obj, area, val) {
		if (document.getElementById(area)) {
			if (form_obj.value == val)
				document.getElementById(area).style.display = 'none';
			else
				document.getElementById(area).style.display = 'block';
		}
	}

	function printpage () {
		if (window.print) {
			window.print();
		}
	}



	var info_last_id = 0;

	function ish (id) {
		id = 'i' + id;
		ihi();
		if (document.getElementById(id)) {
            //document.getElementById(id).style.visibility = 'visible';
			document.getElementById(id).style.display = 'inline';
			info_last_id = id;
		}
	}

	function ihi () {
		if (document.getElementById(info_last_id)) {
            //document.getElementById(info_last_id).style.visibility = 'hidden';
			document.getElementById(info_last_id).style.display = 'none';
			info_last_id = 0;
		}
	}

	function ajust_div_height(left_div, right_div) {
        if (left_div.offsetHeight < right_div.offsetHeight) {
            left_div.setStyle('height', (right_div.offsetHeight - 10));
        }
        else {
            right_div.setStyle('height', (left_div.offsetHeight - 10));
        }
    }  


    
     
function showInfoDiv(el, number, area, tables, status, last_date, description, price) {
	if (!el.toolTip) {
		el.toolTip = new Element('div', {
			'class': 'market-tip',
			'styles': {
				'position': 'absolute',
				'top': '0',
				'left': '0',
				'visibility': 'hidden',
				'background': '#ffffff',
				'border': '1px solid #000',
				'padding': '2px'
			}
		}).inject(document.body);
		el.wrapper = new Element('div').inject(el.toolTip);
		if (number != '') {
			new Element('div', {'class': 'market-line'}).inject(el.wrapper).setHTML('Nummer: <strong>' + number + '</strong>');
		}
		if (area != '') {
			new Element('div', {'class': 'market-line'}).inject(el.wrapper).setHTML('Størrelse: <strong>' + area + '</strong>');
		}
		if (tables != '') {
			new Element('div', {'class': 'market-line'}).inject(el.wrapper).setHTML('Bord: <strong>' + tables + '</strong>');
		}
		new Element('div', {'class': 'market-line'}).inject(el.wrapper).setHTML('Status: <strong>' + status + '</strong>');
		if (last_date != '') {
			new Element('div', {'class': 'market-line'}).inject(el.wrapper).setHTML('Udløber: <strong>' + last_date + '</strong>');
		}
		if (description != '') {
			new Element('div', {'class': 'market-line'}).inject(el.wrapper).setHTML(description);
		}
		if (price != '') {
			new Element('div', {'class': 'market-line'}).inject(el.wrapper).setHTML('Pris: <strong>' + price + ' dkk incl. moms</strong>');
		}
	}
	
/*	var pos = el.getPosition();
	el.toolTip.setStyles({
		'left': pos.x + 16,
		'top': pos.y + 16
	});*/
/*	el.addEvent('mousemove', function(event) {
		var win = {'x': window.getWidth(), 'y': window.getHeight()};
		var scroll = {'x': window.getScrollLeft(), 'y': window.getScrollTop()};
		var tip = {'x': el.toolTip.offsetWidth, 'y': el.toolTip.offsetHeight};
		var page = {'x': event.pageX, 'y': event.pageY }
		var prop = {'x': 'left', 'y': 'top'};
		for (var z in prop){
			var pos = page[z] + 16;
			if ((pos + tip[z] - scroll[z]) > win[z]) pos = page[z] - 16 - tip[z];
			el.toolTip.setStyle(prop[z], pos);
		};
		if (el.toolTip.getStyle('visibility') == 'hidden') {
			el.toolTip.setStyle('visibility', 'visible');
		}
	});*/
}
function moveInfoDiv(event, el) {
	if (el.toolTip) {
		var win = {'x': window.getWidth(), 'y': window.getHeight()};
		var scroll = {'x': window.getScrollLeft(), 'y': window.getScrollTop()};
		var tip = {'x': el.toolTip.offsetWidth, 'y': el.toolTip.offsetHeight};
		if (event.pageX) {
			var page = {'x': event.pageX, 'y': event.pageY }
		} 
		else if (event.clientX) {
			var page = {'x': (event.clientX + document.documentElement.scrollLeft + el.scrollLeft), 'y': (event.clientY + document.documentElement.scrollTop + el.scrollTop) }
		}
//		var page = {'x': event.pageX, 'y': event.pageY }
		var prop = {'x': 'left', 'y': 'top'};
		for (var z in prop){
			var pos = page[z] + 16;
			if ((pos + tip[z] - scroll[z]) > win[z]) pos = page[z] - 16 - tip[z];
			el.toolTip.setStyle(prop[z], pos);
		};
		if (el.toolTip.getStyle('visibility') == 'hidden') {
			el.toolTip.setStyle('visibility', 'visible');
		}
	}
}
function hideInfoDiv(el) {
	if (el.toolTip) {
		el.toolTip.setStyle('visibility', 'hidden');
	//	el.removeEvents('mousemove');
	}
}    