var main_sub_navi_open = '';
var berater_info_open = false;
var berater_info_over = false;
var search_id_selected = '';

function do_main_sub_menu(menuname)
{

	// if submenu already open close it (clearing menuname does it)
	if(menuname == main_sub_navi_open)
	{
		menuname = '';
	}

	// close current submenu if necessary
	if(main_sub_navi_open.length && menuname != main_sub_navi_open)
	{
		if($('main_sub_navi_' + main_sub_navi_open))
		{
			Element.hide($('main_sub_navi_' + main_sub_navi_open));
			if($('main_navi_' + main_sub_navi_open).hasClassName('submenuactive')) $('main_navi_' + main_sub_navi_open).toggleClassName('submenuactive');
			main_sub_navi_open = '';
		}
	}

	// set position of new submenu and open it
	if(menuname && menuname.length && $('main_sub_navi_' + menuname))
	{
			// get position info
			var xoffset = $('main_navi_' + menuname).positionedOffset();
			var leftpx = xoffset[0] + 'px';
			var toppx = (xoffset[1] + $('main_navi_' + menuname).getHeight()) + 'px';
			// set position of submenu
			$('main_sub_navi_' + menuname).setStyle({ left: leftpx, top: toppx });
			// show submenu
			Element.show($('main_sub_navi_' + menuname));
			// store menuname as main_sub_navi_open
			main_sub_navi_open = menuname;
			// set corresponding menu as active (keep highlighting)
			if(!$('main_navi_' + menuname).hasClassName('submenuactive')) $('main_navi_' + menuname).toggleClassName('submenuactive');
	}
}


function show_berater_info()
{
	if(!berater_info_open)
	{
		new Effect.Move('berater_info',{ x: 0, y: 168, mode: 'absolute', duration: 0.2});
		berater_info_open = true;
	}

}

function hide_berater_info()
{
	if(berater_info_open && !berater_info_over)
	{
		new Effect.Move('berater_info',{ x: 0, y: 200, mode: 'absolute', duration: 0.2});
		berater_info_open = false;
	}

}

function set_search_cat(id)
{
	$('search_category').value = id;
	var new_search_id = 'search_cat_' + id;
	if($(search_id_selected)) $(search_id_selected).removeClassName('sel');
	if($(new_search_id) && !$(new_search_id).hasClassName('sel')) $(new_search_id).addClassName('sel');
	search_id_selected = new_search_id;
}



function publication_category_display(id) {
	var el = document.getElementById(id);

	if (el.style.display == 'none')
		el.style.display = 'block';
	else
		el.style.display = 'none';
}

function publication_order(id) {

    var xmlhttp = null;

    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else
	if (window.ActiveXObject) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

	if (xmlhttp) {
    	xmlhttp.open('GET', '/app/ajax/publication_order.php?publication_id='+id, true);
    	xmlhttp.onreadystatechange = function() {
    	    if(xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					var response = eval('(' + xmlhttp.responseText + ')');
					if (response.success) {
    	        		if (confirm(response.result + '\n\nMöchten Sie nun zum Bestellformular wechseln?'))
							window.location = '/bestellformular.php';
					} else {
    	        		alert('Fehler: ' + response.error);
					}
				} else {
    	        	alert('Status: ' + xmlhttp.status);
				}
			}
    	}
    	xmlhttp.send(null);
	}
}

function b7_iFrameHeight(iframeId) {
	var h = 0;
	if ( !document.all ) {
		iframeElement = document.getElementById(iframeId);
		iframeDocument = iframeElement.contentDocument;
		h = iframeDocument.height;
		iframeElement.style.height = (h + 60) + 'px';
	} else if( document.all ) {
		iframeElement = document.all(iframeId);
		iframeDocument = document.frames(iframeId).document;
		h = iframeDocument.body.scrollHeight;
		iframeElement.style.height = (h + 20) + 'px';
	}
}


function rpfile(file_id) {
	if(file_id)
	{
		var content = 'protectedfilebox.php?file_id=' +file_id;
		Shadowbox.open({
			content: content,
			player: 'iframe',
			title: 'Datei anfordern',
			options : {
				animate: true,
				displayCopyright: false,
				displayNav: false
			},
			height:     320,
			width:      500
		});
		return false;
	}
}


function login(file, target_page) {
	var content = '/loginbox.php';
	if (file != undefined && file != '') {
		content += '?file=' + file;
	}
	else if (target_page != undefined && target_page != '') {
		content += '?target_page=' + target_page;
	}
	Shadowbox.open({
        content: content,
        player: 'iframe',
        title: 'Login',
        options : {
        	animate: true,
        	displayCopyright: false,
        	displayNav: false
        },
        height:     280,
        width:      350
    });
    return false;
}

