function loadaktion(aktion)
{
	parent.mainframe.location.href='web.php?action=' + aktion;
}

function loadcmd(page)
{
	document.location.href='web.php?cmd=' + page;
}

function loadaktion2(aktion)
{
	document.location.href='web.php?action=' + aktion;
}

function goto_anker(anker)
{
	document.location.href='#' + anker;
}

function return_confirm(cont,page)
{
	var cont = cont;
	var returnpath = page + '&action=clear';
	if(confirm(cont))
	{
		show_content(returnpath);
	}
	else
	{
		return "";
	}	
}

function bookmark_page(url,title)
{
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		window.external.AddFavorite(url,title);
	}
	else
	{
		alert('Not available for this Browser');
	}
}

function show_thumbnail(a,b,c)
{
	var pfad = "uploads/annoucements_pix/" + a;
	document.getElementById("thumbnail").src=pfad;
	document.getElementById("thumbnail").width=b;
	document.getElementById("thumbnail").height=c;
}

function showpopup(page)
{
	document.location.href=page;
}

function loadaktion3(aktion)
{
	document.location.href='action.php?page=' + aktion;
}

function loadcontent(cmd,typ)
{
	parent.document.location.href=typ + 'content.inc.php?page=' + cmd;
}

function show_content(cmd)
{
	document.location.href='content.inc.php?page=' + cmd;
}

function loadpage(cmd)
{
	parent.mainframe.location.href='content.inc.php?page=' + cmd;
}

function loadNavi(id)
{
	location.href='navigation.inc.php?navi=' + id;
}

function showpage(id)
{
	document.location.href='web.php?page=' + id;
}

function showurl_blank(url)
{
	win = window.open(url);
	win.focus;
}

function editor_hideDiv(id)
{
   document.getElementById(id).style.visibility = "hidden";
   document.getElementById(id).style.display = "none";
}

function Content_hideDiv(id)
{
   document.getElementById(id).style.visibility = "hidden";
}

function time_close_div(id)
{
	parent.document.getElementById(id).style.visibility = "hidden";
}

function gen_popup(page,id,w,h,sb,typ)
{
	myleft=(screen.width)?(screen.width-w)/2:100;
	mytop=(screen.height)?(screen.height-h)/2:100;
	settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=" + sb + ",location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes";
	win=window.open(typ + 'popups/' + page + '.php?dat=' + id,'Popup',settings);
	win.focus();
}

function xxl_Pic(dat,repl)
{
	var w = 650;
	var h = 450;
    // Dateiname ermitteln (added by EDV Wambsganss)
    var regex = /\/([0-9]*\.[a-z]{3}$)/i;
	var datei = regex.exec(dat);
	//var datei = dat.replace(repl,"");
	myleft=(screen.width)?(screen.width-w)/2:100;
	mytop=(screen.height)?(screen.height-h)/2:100;
	settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes";
	win=window.open('popups/show_pic.php?dat=' + datei[1],'XXLPic',settings);
	win.focus();
}

function gen_searchform(dat)
{
	var w=550;
	var h=400;
	myleft=(screen.width)?(screen.width-w)/2:100;
	mytop=(screen.height)?(screen.height-h)/2:100;
	settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes";
	win=window.open('searchform.php?query=' + dat,'SearchForm',settings);
	win.focus();
}

function print_page(id,dat,cat)
{
	var w = 600;
	var h = 500;
	myleft=(screen.width)?(screen.width-w)/2:100;
	mytop=(screen.height)?(screen.height-h)/2:100;
	settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes";
	win=window.open('print_page.php?dat=' + id + '&s=' + dat + '&sk=' + cat,'PrintPage',settings);
	win.focus();
}

function lastvalue(field)
{
	fieldlastvalue = field.value;
}

function countLines(CharsinLine,input_field,output_field,output_field2)
{
	var strAllText = input_field.value;
	var arrLines = strAllText.split("\r\n");
	for(var i = 0; i < arrLines.length; i++)
	{
		if(arrLines[i].length > CharsinLine)
		{
			output_field.value = fieldlastvalue + '\r\n';
		}
	}
	output_field2.value = arrLines.length + 1;
}

function showLines(max,text,outputfield,outputfield2,max_lines,msg)
{
	var lineCounter = 2;
	text = text.value;
	text = "" + text;
	var temp = "";
	var chcount = 0; 
	for (var i = 0; i < text.length; i++) // for each character ... 
	{   
		var ch = text.substring(i, i+1); // first character
		var ch2 = text.substring(i+1, i+2); // next character
		if (ch == '\n') // if character is a hard return
		{  
			temp += ch;
			chcount = 1;
			lineCounter++;
		}
		else
		{
			if (chcount == max) // line has max chacters on this line
			{
				temp += '\n' + ch; // go to next line
				chcount = 1; // reset chcount
				lineCounter++;
			}
			else  // Not a newline or max characters ...
			{
				temp += ch;
				chcount++; // so add 1 to chcount
			}
		}
	}
	var zeilen = temp.split('\n');
	if(zeilen.length >= max_lines)
    {
         alert(msg);
	}
	else
	{
		//return (temp); // sends value of temp back
		outputfield.value = temp;
		outputfield2.value = lineCounter;
	}
}

function ShowHide(id)
{
	obj = document.getElementsByTagName("div");
    if(obj[id].style.visibility == 'visible')
	{
    	obj[id].style.visibility = 'hidden';
    }
    else
	{
    	obj[id].style.visibility = 'visible';
    }
}

function Banner_Add(id)
{
	if(id == 1)
	{
		document.getElementById("banner_url").style.visibility = 'hidden';
		document.getElementById("quellcode").style.visibility = 'hidden';
		document.getElementById("banner_upload").style.visibility = 'visible';
		document.getElementById("submit_button").style.visibility = 'visible';
		document.getElementById("qcinfo").style.visibility = 'hidden';
		document.getElementById("zielurl").style.visibility = 'visible';
	}
	if(id == 2)
	{
		document.getElementById("banner_url").style.visibility = 'visible';
		document.getElementById("quellcode").style.visibility = 'hidden';
		document.getElementById("banner_upload").style.visibility = 'hidden';
		document.getElementById("submit_button").style.visibility = 'visible';
		document.getElementById("qcinfo").style.visibility = 'hidden';
		document.getElementById("zielurl").style.visibility = 'visible';
	}
	if(id == 3)
	{
		document.getElementById("banner_url").style.visibility = 'hidden';
		document.getElementById("quellcode").style.visibility = 'visible';
		document.getElementById("banner_upload").style.visibility = 'hidden';
		document.getElementById("submit_button").style.visibility = 'visible';
		document.getElementById("qcinfo").style.visibility = 'visible';
		document.getElementById("zielurl").style.visibility = 'hidden';
	}
	if(id == '')
	{
		document.getElementById("banner_url").style.visibility = 'hidden';
		document.getElementById("quellcode").style.visibility = 'hidden';
		document.getElementById("banner_upload").style.visibility = 'hidden';
		document.getElementById("submit_button").style.visibility = 'hidden';
		document.getElementById("qcinfo").style.visibility = 'hidden';
		document.getElementById("zielurl").style.visibility = 'hidden';
	}
}

function Banner_Add2(id)
{
	if(id == 1)
	{
		document.getElementById("banner_url").style.visibility = 'hidden';
		document.getElementById("quellcode").style.visibility = 'hidden';
		document.getElementById("banner_upload").style.visibility = 'visible';
		document.getElementById("submit_button").style.visibility = 'visible';
		document.getElementById("qcinfo").style.visibility = 'visible';
		document.getElementById("zielurl").style.visibility = 'visible';
	}
	if(id == 2)
	{
		document.getElementById("banner_url").style.visibility = 'visible';
		document.getElementById("quellcode").style.visibility = 'hidden';
		document.getElementById("banner_upload").style.visibility = 'hidden';
		document.getElementById("submit_button").style.visibility = 'visible';
		document.getElementById("qcinfo").style.visibility = 'visible';
		document.getElementById("zielurl").style.visibility = 'visible';
	}
	if(id == 3)
	{
		document.getElementById("banner_url").style.visibility = 'hidden';
		document.getElementById("quellcode").style.visibility = 'visible';
		document.getElementById("banner_upload").style.visibility = 'hidden';
		document.getElementById("submit_button").style.visibility = 'visible';
		document.getElementById("qcinfo").style.visibility = 'visible';
		document.getElementById("zielurl").style.visibility = 'hidden';
	}
	if(id == '')
	{
		document.getElementById("banner_url").style.visibility = 'hidden';
		document.getElementById("quellcode").style.visibility = 'hidden';
		document.getElementById("banner_upload").style.visibility = 'hidden';
		document.getElementById("submit_button").style.visibility = 'hidden';
		document.getElementById("qcinfo").style.visibility = 'visible';
		document.getElementById("zielurl").style.visibility = 'hidden';
	}
}

/*===============================*/
/* onMouseOver Menü */
function getX(elm)
{
	x = elm.offsetLeft;
	if(!elm.offsetParent) return x;
	else return (x+getX (elm.offsetParent));
}

function changePos(elm1,elm2,elm3)
{
	var x = getX(document.getElementById(elm1));
	/*document.getElementById(elm2).style.left=x;*/
}

function hide_menu_all(mall)
{
	for(var i=1;i<=mall;i++)
	{
		hide_menu(i);
	}
}
   
function hide_menu(submenu)
{
	document.getElementById(submenu).style.visibility = 'hidden';
}
   
function menu(submenu,mall)
{
	/*hide_menu_all(mall);*/
	document.getElementById(submenu).style.visibility = 'visible';
}
/*===============================*/

function window_move_to()
{
	var x = (screen.width / 2) - (document.body.clientWidth / 2);
	var y = (screen.height / 2) - (document.body.clientHeight / 2);
	window.moveTo(x, y);
}

function resizeToContent()
{
	var isMSIE = (navigator.appName == "Microsoft Internet Explorer");
	var isOpera = (navigator.userAgent.indexOf("Opera") != -1);

	if (isOpera)
		return;

	if (isMSIE) {
		try { window.resizeTo(10, 10); } catch (e) {}

		var elm = document.body;
		var width = elm.offsetWidth;
		var height = elm.offsetHeight;
		var dx = (elm.scrollWidth - width) + 4;
		var dy = elm.scrollHeight - height;
		
		try { window.resizeBy(dx, dy); } catch (e) {}
		window_move_to();
	} else {
		window.scrollBy(1000, 1000);
		if (window.scrollX > 0 || window.scrollY > 0) {
			window.resizeBy(window.innerWidth * 2, window.innerHeight * 2);
			/*window.sizeToContent();*/
			window.scrollTo(0, 0);
			var x = parseInt(screen.width / 2.0) - (window.outerWidth / 2.0);
			var y = parseInt(screen.height / 2.0) - (window.outerHeight / 2.0);
			window.moveTo(x, y);
		}
	}
};

var oldContent="";
function CheckLen(Target,ml)
{
	var maxlength    =    ml;    //die maximale Zeichenlänge
    var CharsLeft    =    0;        //verbleibende Zeichen
    var breakLines    =    0;        //anzahl Zeilenumbrüche
    var theChar        =    "";        //zu testendes Zeichen
    StrLen=Target.value.length;
    if (StrLen==1&&Target.value.substring(0,1)==" ")
    {
        Target.value="";
        StrLen=0;
    }

    if (StrLen>maxlength)
    {
        Target.value=Target.value.substring(0,maxlength);
        CharsLeft=0;
    }
    else
    {
        CharsLeft=maxlength-StrLen;
    }
    for(var i=0; i<StrLen; i++)
    {
        theChar = Target.value.substring(i,i+1);
        if(theChar == "\n")
        {
            breakLines++;
        }
    }
    if(breakLines>9)        //mehr als 10 Umbrüche
    {
        Target.value = oldContent;
    }
    else if(oldContent!=Target.value)
    {
        oldContent  = Target.value;
    }
    document.Formname.Anzahl.value=CharsLeft;
    document.Formname.Brl.value=breakLines;
}

function pm_getvalue(formular,feld,wert) { 
opener.document.formular.feld.value=wert; 
} 

var B_Type = new crossBrowserType();
function crossBrowserType()
{
	this.IE = false;
	this.NS4 = false;
	this.NS6 = false;
	this.id = "";

	if (document.all) {this.IE = true; this.id = "IE";}
	else if (document.getElementById) {this.NS6 = true; this.id = "NS6";}
	else if (document.layers) {this.NS4 = true; this.id = "NS4";}
}

var crossMouseX, crossMouseY;
if (B_Type.NS4) document.captureEvents(Event.MOUSEMOVE);

function crossMousePosition(e)
{
	if (B_Type.IE) {
		crossMouseX=event.x + document.body.scrollLeft; 
		crossMouseY=event.y + document.body.scrollTop;
	}
	else {crossMouseX=e.pageX; crossMouseY=e.pageY;}
}

function crossGetObject(id)
{
	var obj = null;
	if (B_Type.IE) obj=document.all[id];
	else if (B_Type.NS6) obj=document.getElementById(id);
	else if (B_Type.NS4) obj=document.layers[id];
	return obj;
}

function crossWrite(obj, text)
{
		
	if (B_Type.IE) obj.innerHTML = text;
	else if (B_Type.NS6) obj.innerHTML = text;
	else if (B_Type.NS4)
	{
		obj.document.open();
		obj.document.write(text);
		obj.document.close();
	}
}

function crossInnerWindowWidth()
{
	var val;
	if (B_Type.IE) val=document.body.clientWidth;
	else if (B_Type.NS6) val=window.innerWidth;
	else if (B_Type.NS4) val=window.innerWidth;
	return val;
}

function crossOuterWindowWidth()
{
	var val;
	if (B_Type.IE) val=document.body.offsetWidth;
	else if (B_Type.NS6) val=window.outerWidth;
	else if (B_Type.NS4) val=window.outerWidth;
	return val;
}

function crossInnerWindowHeight()
{
	var val;
	if (B_Type.IE) val=document.body.clientHeight;
	else if (B_Type.NS6) val=window.innerHeight;
	else if (B_Type.NS4) val=window.innerHeight;
	return val;
}

function crossGetScroll(achse)
{
	var val;
	if (!achse || achse == "y")
	{
		if (B_Type.IE) val=document.body.scrollTop;
		else if (B_Type.NS6) val=window.pageYOffset;
		else if (B_Type.NS4) val=window.pageYOffset;
	}
	else
	{
		if (B_Type.IE) val=document.body.scrollLeft;
		else if (B_Type.NS6) val=window.pageXOffset;
		else if (B_Type.NS4) val=window.pageXOffset;
	}
	return val;
}

function crossSetScroll(x, y)
{
	window.scrollTo(x, y);
}

function crossMoveTo(obj, x, y)
{
	if (B_Type.IE) {obj.style.pixelLeft=x; obj.style.pixelTop=y;}
	else if (B_Type.NS4) {obj.left=x; obj.top=y;}
	else if (B_Type.NS6) {obj.style.left=x+"px"; obj.style.top=y+"px";}
}

function crossGetPositionX(obj)
{
	if (B_Type.IE) return obj.style.pixelLeft;
	else if (B_Type.NS4) return obj.left;
	else if (B_Type.NS6) return parseInt(obj.style.left);
}
function crossGetPositionY(obj)
{
	if (B_Type.IE) return obj.style.pixelTop;
	else if (B_Type.NS4) return obj.top;
	else if (B_Type.NS6) return parseInt(obj.style.top);
}

function crossShowObject(obj)
{
	if (B_Type.IE || B_Type.NS6) {obj.style.visibility="visible";}
	else if (B_Type.NS4) {obj.visibility="show";}
}

function crossHideObject(obj)
{
	if (B_Type.IE || B_Type.NS6) {obj.style.visibility="hidden";}
	else if (B_Type.NS4) {obj.visibility="hide";}
}

function crossBackgroundColor(color, obj)
{
	if (typeof obj == "undefined") {document.bgColor=color; return;}
	if (B_Type.IE || B_Type.NS6) {obj.style.backgroundColor=color;}
	else if (B_Type.NS4) {obj.document.bgColor=color;}
}

function crossBackgroundImage(obj, img)
{
	if (B_Type.IE || B_Type.NS6) {obj.style.backgroundImage="url(" + img + ")";}
	else if (B_Type.NS4) {obj.background.src = img;}
}

var TTBack = "#FFFFFF";
var TTText = "#000000";
var TTBreite = 200;
var TT2Breite = 400;
var TTBorder = 1;
var TTFont = "Arial";
var TTDir = 0;
var TTVDir = 0;
var TTChangeVDir = 65;
var TTSpace = 10;
var TTShow = false;
var TT = null;
var b_Breite;
var b_Dir, b_VDir;

function setTT(id, breite, bgcolor)
{
	document.onmousemove = cursorMove;
	if (breite && breite>20) b_Breite = breite;
	if (bgcolor) TTBack = bgcolor;
	TT = crossGetObject(id);
	if (TT == null)
	{
		alert("keine Unterstützung für ToolTip-Infos");
		showTT = noTT; hideTT = noTT;
	}
	TTShow = false;
}
function noTT() {}

function showTT(msg, dir, breite, bgcolor)
{
	var b_Back;
	var relWidth, relHeight;

	if (TT == null) return;
	if (breite && breite>20) b_Breite = breite;
	else b_Breite=TTBreite;
	if (bgcolor) b_Back=bgcolor;
	else b_Back=TTBack;
	msg = '<table width=' + b_Breite + ' border=0 cellpadding=' + TTBorder + ' cellspacing=0 bgcolor=\"' + TTText + '\"><tr><td><table width=100% border=0 cellpadding=2 cellspacing=0 bgcolor=\"' + b_Back + '\"><tr><td id=tooltip>' + msg + '</td></tr></table></td></tr></table>';
	if (!dir) b_Dir = TTDir;
	else b_Dir = dir;
	relWidth = crossInnerWindowWidth() + crossGetScroll("x");
	relHeight = crossInnerWindowHeight() + crossGetScroll("y");
	if (crossMouseX + b_Breite + TTSpace > relWidth) 
		{b_Dir = 1;}
	else if (crossMouseX < b_Breite + TTSpace) b_Dir = 0;
	b_VDir = TTVDir;
	if (crossMouseY + TTChangeVDir > relHeight) b_VDir = 1;
	else if (crossMouseY - TTChangeVDir < 0) b_VDir = 0;
	crossWrite(TT, msg);
	TTShow = true;
	crossShowObject(TT);
}

function showTT_big(msg, dir, breite, bgcolor)
{
	var b_Back;
	var relWidth, relHeight;

	if (TT == null) return;
	if (breite && breite>20) b_Breite = breite;
	else b_Breite=TT2Breite;
	if (bgcolor) b_Back=bgcolor;
	else b_Back=TTBack;
	msg = '<table width=' + b_Breite + ' border=0 cellpadding=' + TTBorder + ' cellspacing=0 bgcolor=\"' + TTText + '\"><tr><td><table width=100% border=0 cellpadding=2 cellspacing=0 bgcolor=\"' + b_Back + '\"><tr><td id=tooltip>' + msg + '</td></tr></table></td></tr></table>';
	if (!dir) b_Dir = TTDir;
	else b_Dir = dir;
	relWidth = crossInnerWindowWidth() + crossGetScroll("x");
	relHeight = crossInnerWindowHeight() + crossGetScroll("y");
	if (crossMouseX + b_Breite + TTSpace > relWidth) 
		{b_Dir = 1;}
	else if (crossMouseX < b_Breite + TTSpace) b_Dir = 0;
	b_VDir = TTVDir;
	if (crossMouseY + TTChangeVDir > relHeight) b_VDir = 1;
	else if (crossMouseY - TTChangeVDir < 0) b_VDir = 0;
	crossWrite(TT, msg);
	TTShow = true;
	crossShowObject(TT);
}

function hideTT()
{
	if (TT == null) return;
	crossHideObject(TT);
	TTShow=false;
	crossMoveTo(TT, -200, 0);
}

function hideTT_big()
{
	if (TT == null) return;
	crossHideObject(TT);
	TTShow=false;
	crossMoveTo(TT, -400, 0);
}

function cursorMove(e)
{
	var posX, posY;
	
	crossMousePosition(e);

	if (TTShow)
	{
		if (b_Dir==0)
		{
			posX = crossMouseX + TTSpace; 
			if (b_VDir==0) {posY = crossMouseY + TTSpace;}
			else {posY = crossMouseY - TTChangeVDir;}
		}
		else
		{
			posX = crossMouseX-b_Breite-TTSpace;
			if (b_VDir==0) {posY = crossMouseY + TTSpace;}
			else {posY = crossMouseY - TTChangeVDir;}
		}
		crossMoveTo(TT, posX, posY)
	}
}
