/* helpbox errorbox START */
/*$.ajax({
url:'http://fast.fonts.com/jsapi/354f55ad-cf82-485c-b3cc-ed42ee2d0762.js',
type:'HEAD',
error: function(){
// Datei wurde nicht gefunden, und nun?
},
success: function(){
// Datei vorhanden, weiter im Text
alert('yes');
}
});
*/
var imgFolder = '/fileadmin/bod_libs/images/img_helpbox/';
var arrPageSizes;

$(document).ready(function() {
	arrPageSizes = ___getPageSize();
	if($('div.lightbox').length == 0) {
		$('body')
			.append('<div class="lightbox"><\/div>')
			.append('<div class="helpbox"><div class="close"><\/div><div class="content"><\/div><\/div>')
			.append('<div class="messagebox"><div class="top"><div class="close"><\/div><\/div><div class="middle"><div class="content"><\/div><\/div><div class="bottom"><\/div><\/div>')
			.append('<div class="errorbox"><img alt="" src="'+imgFolder+'box_top.gif" class="top"><div class="close"><\/div><div class="content"><\/div><img alt="" src="'+imgFolder+'box_bottom.gif" class="bottom"><\/div>')
			.append('<div class="addbox"><div class="top"><div class="close"><\/div><\/div><div class="middle"><div class="content"><\/div><\/div><div class="bottom"><\/div><\/div>');
	}
	$(".lightbox").height(arrPageSizes[1]);
}); 


function ___getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};

function boxFadeIn(box) {
	box.css({
		display: 'none',
		visibility: 'hidden'
	});
	
	var boxImages = box.find('img');
	var imagesLoaded = 0;
	for(var i=0; i < boxImages.length; i++) {
		boxImages[i].onload = function() {
			imagesLoaded++;
			if(imagesLoaded == boxImages.length) window.setTimeout(function() {
				doBoxFadeIn(box);
			}, 50);
		}
	}
	if(boxImages.length == 0) doBoxFadeIn(box);
}

function doBoxFadeIn(box) {
	var topPx = ($(window).height() / 2) - box.height() / 2;
	if($.browser.msie) topPx += $('body').scrollTop();
		
	box.css({
			top: topPx,
			visibility: 'visible',
			display: 'none'
		});
	
	if(box.find('div.top div.corner, div.bottom div.corner').length != 0) {
		var widthPx = box.outerWidth();
		if(widthPx > 750){
			widthPx = 750;
		}
		box.css({
				marginLeft: -(widthPx / 2),
				width: widthPx
			})
		   .find('div.top,div.bottom').css('width', (widthPx - 8)).find('div.middle').css('width', (widthPx));
	}
	
	
	box.fadeIn();
}

function showHelp2( idnum ){
	$.get('fileadmin/bod_libs/ajax/getHelp.ajax.php', "id="+idnum ,function(data){
		$(".helpbox .content").html(data)
		boxFadeIn($('.helpbox'));

	}, {cache: false});
	//$(".helpbox").fadeIn();
	//$(".lightbox").fadeIn();
	
	// lightbox
	arrPageSizes = ___getPageSize();
	$(".lightbox").css({
			display: 'block', 
			opacity: 0
		})
		.height(arrPageSizes[1])
		.animate({
				opacity:0.8
			}, 500 )
		.click(function() {
			hideHelp();
		});
	
	$(".helpbox .close").click(function() {
		hideHelp();
	});
	
	return false;
}

function showAdd( idnum ){
	$.get('fileadmin/bod_libs/ajax/getAdd.ajax.php', "id="+idnum ,function(data){
		$(".addbox .content").html(data);
		boxFadeIn($('.addbox'));
	}, { cache: false });
	//
	//$(".addbox").fadeIn();
	//$(".lightbox").fadeIn();
	arrPageSizes = ___getPageSize();
	$(".lightbox").css({display: 'block', opacity: 0} );
	$(".lightbox").height(arrPageSizes[1]);
	$(".lightbox").animate({opacity:0.8}, 500 );
	
	$(".addbox .close").click(function() {
		hideAdd();
	});
	$(".lightbox").click(function() {
		hideAdd();
	});
	
	return false;
}
function showHelp3( idnum ){
	$.get('fileadmin/bod_libs/ajax/getHelp_test.ajax.php', "id="+idnum ,function(data){$(".helpbox .content").html(data);}, {cache: false});
	$(".helpbox").fadeIn();
	arrPageSizes = ___getPageSize();
	$(".lightbox").height(arrPageSizes[1]);
	$(".lightbox").fadeIn();
	
	$(".helpbox .close").click(function() {
		hideHelp();
	});
	$(".lightbox").click(function() {
		hideHelp();
	});
	
	return false;
}

function showHelp(title, message) {
	$(".helpbox .content").html('<h4>'+title+'</h4>'+'<p>'+message+'</p>');
	
	boxFadeIn($('.helpbox'));
	//$(".helpbox").fadeIn();
	//$(".lightbox").fadeIn();
	
	$(".lightbox").css({display: 'block', opacity: 0} );
	arrPageSizes = ___getPageSize();
	$(".lightbox").height(arrPageSizes[1]);
	$(".lightbox").animate({opacity:0.8}, 500 );
	
	$(".helpbox .close").click(function() {
		hideHelp();
	});
	$(".lightbox").click(function() {
		hideHelp();
	});
	
	return false;
}

function hideHelp() {
	$(".helpbox").fadeOut('fast');
	$(".lightbox").fadeOut('fast');
}

function hideAdd() {
	$(".addbox").fadeOut('fast');
	$(".lightbox").fadeOut('fast');
}

function showError(message) {
	$(".errorbox .content").html(message);
	
	boxFadeIn($(".errorbox"));
	
	//$(".errorbox").fadeIn();
	//$(".lightbox").fadeIn();
	
	$(".lightbox").css({display: 'block', opacity: 0} );
	arrPageSizes = ___getPageSize();
	$(".lightbox").height(arrPageSizes[1]);
	$(".lightbox").animate({opacity:0.8}, 500 );

	$(".errorbox .close").click(hideError);
	$(".lightbox").click(hideError);
	
	$('select').css({position: 'relative', left: '-2000px'});
	window.scrollTo(0,0);
	
	return false;
}

function hideError() {
	$(".errorbox").fadeOut('fast');
	$(".lightbox").fadeOut('fast');
	$('select').css({position: 'relative', left: '0'});
}

function showMessage(title, message) {
	title = title ? title : null;
	var head_title;
	
	if(title)
		head_title = '<h4>'+title+'</h4>';
	else
		head_title = '';
		
	$(".messagebox .middle .content").html(head_title+'<p>'+message+'</p>');
	//var window_height		= window.innerHeight ? Math.round(window.innerHeight/2) : Math.round(document.documentElement.clientHeight/2);
	//var window_height		= window.innerHeight ? Math.round(window.innerHeight/2) : Math.round(document.body.clientHeight/2);
	//var messagebox_height	= Math.round($(".messagebox").height()/2);
	//var margin_top			= window_height-messagebox_height;
	
	//$(".messagebox").css('margin-top', margin_top+'px');
	//$(".messagebox").fadeIn();
	boxFadeIn($(".messagebox"));
	
	$(".lightbox").css({display: 'block', opacity: 0} );
	arrPageSizes = ___getPageSize();
	$(".lightbox").height(arrPageSizes[1]);
	$(".lightbox").animate({opacity:0.8}, 500 );
	
	$(".messagebox .top .close").click(function() {
		hideMessage();
	});
	$(".lightbox").click(function() {
		hideMessage();
	});
	
	return false;
}

function hideMessage() {
	$(".messagebox").fadeOut('fast');
	$(".lightbox").fadeOut('fast');
}


/*	$(document).ready(function() {
		$('button').click(function() {
			showHelp('Hilfe!', '<h5>So bekommen Sie Hilfe</h5><p>Hier gibt es Hilfe</p>');
		})
		
	})*/
	
	
	
/* helpbox ENDE */

/* HELLO START */

    function loadHtml(url, target) {
        if (window.XMLHttpRequest) {
            req = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            req = new ActiveXObject("Microsoft.XMLHTTP");
        }
        if (req != undefined) {
            req.onreadystatechange = function() {loadHtmlDone(url, target);};
            req.open("GET", url, true);
            req.send("");
        }
    }
  /*  function loadHtmlDone(url, target) {
        if (req.readyState == 4) { // only If req Is "loaded"
            if (req.status == 200) { // only If "OK"
               document.getElementById(target).innerHTML = req.responseText;
				
            } else {
                document.getElementById(target).innerHTML="err:\n"+ req.status + "\n" +req.statusText;
            }
        }
    }*/
    function loadHtmlDone(url, target) {
		var strResponseText;
		var arrText;
		var strLog;
		var strHello;
        if (req.readyState == 4) { // only If req Is "loaded"
            if (req.status == 200) { // only If "OK"
			//alert(req.responseText);
				stringResponseText = req.responseText;
				arrText = stringResponseText.split('&trenner&');
				strLog = arrText[1];
				strHello = arrText[0];
				document.getElementById(target).innerHTML = strHello;
				document.getElementById('Login').innerHTML = strLog;				
            } else {
				stringResponseText = req.responseText;
				arrText = stringResponseText.split('&trenner&');
				strLog = arrText[1];
				document.getElementById('Login').innerHTML = strLog;
                document.getElementById(target).innerHTML="err:\n"+ req.status + "\n" +req.statusText;
            }
        }
    }	

/* HELLO ENDE */
			

// till kahle 03.10.06
function forceProtocol( wantedProtocol )
{
  if (document.location.protocol != wantedProtocol )
  {
    // for JS 1.0 browsers:
    if (document.location.replace == null)
      document.location.replace = document.location.assign
    document.location.href = wantedProtocol + "//" + document.location.hostname + document.location.pathname + document.location.search;
  }
}

/* bookmarks start */
$(document).ready(function(){
    $(".bookmarksbox").hide();
    $(".bookmark").hover(
    	function() {
    		$(".bookmarksbox").fadeIn("fast");
    	},
    	function() {
    		$(".bookmarksbox").fadeOut("fast");
    	}
    );
    $(".bookmarksbox").hover(
    	function() {
    		$(".bookmarksbox").fadeIn("fast");
    	},
    	function() {
    		$(".bookmarksbox").fadeOut("fast");
    	}
    );
});
/* bookmarks ende */
/* guided tour start */
function PopUp(w,h,ziel) {

  h = h - 20;var x=0, y=0, parameter="";

  if (w < screen.availWidth || h < screen.availHeight) {

    x = (screen.availWidth - w - 12) / 2;

    y = (screen.availHeight - h - 104) / 2;

    if (window.opera) y = 0; // Opera positioniert unter den Symbolleisten

    if (x<0 || y<0) {x=0;y=0;}

    else parameter = "width=" + w + ",height=" + h + ",";

  }

  parameter += "left=" + x + ",top=" + y;

  parameter += ",menubar=no,location=no,toolbar=no,status=no";

  parameter += ",resizable=no,scrollbars=no";

  var Fenster = window.open(ziel,"PopUp",parameter);

  if (Fenster) Fenster.focus();

  return !Fenster;

}
/* guided tour ende */
