function formatText(t,u,e,k,d,col,enlarge,chD){
	
	if(typeof(chD)=="undefined"){chD=""}
	
	if(u==1){t=checkForUrl(t)}
	if(e==1){t=checkForEMail(t,chD)}
	
	if(typeof(enlarge)=="undefined"){enlarge=0}
	if(enlarge==0){
		if(k==1){t=checkForKap(t)}
	}	
	else{
		if(k==1){t=checkForKapClear(t)}
	}

	if(k==1){t=checkForLexikon(t)}
	if(d==1){t=checkForDownload(t,col)}
	
	t=t.replace(/\r\n/g,"<br>")
	t=t.replace(/\[\[/g,"{{{{")
	t=t.replace(/\]\]/g,"}}}}")
	t2='<b>'
	t=t.replace(/\[/g,t2)
	t2='</b>'
	t=t.replace(/\]/g,t2)
	t=t.replace(/\{\{\{\{/g,"[")
	t=t.replace(/\}\}\}\}/g,"]")
	
	t=t.replace(/\{\{/g,"§§§§")
	t=t.replace(/\}\}/g,"§§§$")
	t2='<b><a style="font-size: 10pt">'
	t=t.replace(/\{/g,t2)
	t2='</a></b>'
	t=t.replace(/\}/g,t2)
	t=t.replace(/\§\§\§\§/g,"{")
	t=t.replace(/\§\§\§\$/g,"}")
	
	t=t.replace(/  /g," &nbsp;")
	
	return t
}

function checkForUrl(t){
	newT=""
	do{
		pos=t.search(/\{\+w\+/)
		if(pos>-1){
			tt=t.substr(pos)
			pos2=tt.search(/\}/)
			if(pos2>-1){
				tmpText=t.substr(pos+4,pos2-4)
				tText=tmpText.split("$")
				if(tText.length==2){
					newT+=t.substr(0,pos) + '<a onclick="goFormatWeb(\'' +  tText[1] + '\')" title="' + tText[1] + '" style="text-decoration:underline; cursor:pointer">' + tText[0] + '</a>'
					restText=t.substr(pos+pos2+1)
					t=t.substr(pos+pos2+1)
				}
				else if(tText.length==3){
					if(tText[2]=="window"){
						gefunden=0
						switch(tText[1]){
							case 'impressum':jumpTo="goImpressum()";gefunden=1;break
							case 'guestbook':jumpTo="goGuestbook()";gefunden=1;break
							case 'terminer':jumpTo="goTerminer()";gefunden=1;break
							case 'sitemap':jumpTo="goSitemap()";gefunden=1;break
							case 'jobs':jumpTo="goJobs()";gefunden=1;break
							case 'ausbildung':jumpTo="goAusbildung()";gefunden=1;break
						}
						if(gefunden==0){
							if(tText[1].substr(0,4)=="bild"){
								bildParam=tText[1].split(/\,/)
								jumpTo='goPicView(\'' + bildParam[1] + '\',\'\',\'\')'
								gefunden=1
							}
						}
						if(gefunden==1){
							newT+=t.substr(0,pos) + '<a onclick="' + jumpTo + '" style="text-decoration:underline; cursor:pointer">' + tText[0] + '</a>'
							restText=t.substr(pos+pos2+1)
							t=t.substr(pos+pos2+1)					
						}
						else{
							restText=t.substr(pos+1)
							break						
						}
					}
					else{
						restText=t.substr(pos+1)
						break					
					}
				}
				else{
					restText=t.substr(pos+1)
					break
				}
			}
			else{
				restText=t.substr(pos+1)
				break
			}
		}
	}while(pos>-1)
	if(newT!==""){t=newT + restText}
	t=checkForVC(t)
	return t
}

function checkForEMail(t,chD){
	newT=""
	do{
		pos=t.search(/\{\+e\+/)
		if(pos>-1){
			tt=t.substr(pos)
			pos2=tt.search(/\}/)
			if(pos2>-1){
				tmpText=t.substr(pos+4,pos2-4);tText=tmpText.split("$")
				if(tText.length>1){
					if(tText.length>2){
						tText[2]=tText[2].replace(/\'/g,"\\\'");tText[2]=tText[2].replace(/\"/g,"\\\"")
						eText=tText[2]
					}
					else{eText=""}
					newT+=t.substr(0,pos) + '<a onclick="goFormatMail(\'' +  tText[1] + '\',\'' + eText + '\',\'' + chD + '\')" title="' + tText[1] + '" style="text-decoration:underline; cursor:pointer">' + tText[0] + '</a>'
					restText=t.substr(pos+pos2+1)
					t=t.substr(pos+pos2+1)
				}
				else{restText=t.substr(pos+1);break}
			}
			else{restText=t.substr(pos+1);break}
		}
	}while(pos>-1)
	if(newT!==""){t=newT + restText}
	return t
}

function checkForKap(t){
	newT=""
	do{
		pos=t.search(/\{\+s\+/)
		if(pos>-1){
			tt=t.substr(pos)
			pos2=tt.search(/\}/)
			if(pos2>-1){
				tmpText=t.substr(pos+4,pos2-4)
				tText=tmpText.split("$")
				if(tText.length==2){
					newT+=t.substr(0,pos) + '<a onclick="goFormatKapitel(\'' +  tText[1] + '\')" title="Wechsel zu Seite ' + tText[1] + '" style="text-decoration:underline; cursor:pointer">' + tText[0] + '</a>'
					restText=t.substr(pos+pos2+1)
					t=t.substr(pos+pos2+1)
				}
				else{
					restText=t.substr(pos+1)
					break
				}
			}
			else{
				restText=t.substr(pos+1)
				break
			}
		}
	}while(pos>-1)
	if(newT!==""){t=newT + restText}
	
	return t
}

function checkForVC(t){
	newT=""
	do{
		pos=t.search(/\{\+v\+/)
		if(pos>-1){
			tt=t.substr(pos)
			pos2=tt.search(/\}/)
			if(pos2>-1){
				tmpText=t.substr(pos+4,pos2-4)
				tText=tmpText.split("$")
				if(tText.length==2){
					newT+=t.substr(0,pos) + '<a onclick="goFormatVC(\'' +  tText[1] + '\')" title="Visitenkarte ' + tText[1] + '" style="text-decoration:underline; cursor:pointer">' + tText[0] + '</a>'
					restText=t.substr(pos+pos2+1)
					t=t.substr(pos+pos2+1)
				}
				else{
					restText=t.substr(pos+1)
					break
				}
			}
			else{
				restText=t.substr(pos+1)
				break
			}
		}
	}while(pos>-1)
	if(newT!==""){t=newT + restText}
	return t
}

function checkForKapClear(t){
	newT=""
	do{
		pos=t.search(/\{\+s\+/)
		if(pos>-1){
			tt=t.substr(pos)
			pos2=tt.search(/\}/)
			if(pos2>-1){
				tmpText=t.substr(pos+4,pos2-4)
				tText=tmpText.split("$")
				if(tText.length==2){
					newT+=t.substr(0,pos) + tText[0]
					restText=t.substr(pos+pos2+1)
					t=t.substr(pos+pos2+1)
				}
				else{
					restText=t.substr(pos+1)
					break
				}
			}
			else{
				restText=t.substr(pos+1)
				break
			}
		}
	}while(pos>-1)
	if(newT!==""){t=newT + restText}
	return t
}

function checkForLexikon(t){
	newT=""
	do{
		pos=t.search(/\{\+l\+/)
		if(pos>-1){
			tt=t.substr(pos)
			pos2=tt.search(/\}/)
			if(pos2>-1){
				tmpText=t.substr(pos+4,pos2-4)
				tText=tmpText.split("$")
				if(tText.length==3){
					newT+=t.substr(0,pos) + '<a onclick="goFormatLexikon(\'' +  tText[1] + '\',\'' + tText[2] + '\')" title="Informationen zu ' + tText[0] + '" style="text-decoration:underline; cursor:pointer">' + tText[0] + '</a>'
					restText=t.substr(pos+pos2+1)
					t=t.substr(pos+pos2+1)
				}
				else{
					restText=t.substr(pos+1)
					break
				}
			}
			else{
				restText=t.substr(pos+1)
				break
			}
		}
	}while(pos>-1)
	if(newT!==""){t=newT + restText}
	return t
}

function checkForDownload(t,col){
	newT=""
	do{
		pos=t.search(/\{\+d\+/)
		if(pos>-1){
			tt=t.substr(pos)
			pos2=tt.search(/\}/)
			if(pos2>-1){
				tmpText=t.substr(pos+4,pos2-4)
				tText=tmpText.split("$")
				if(tText.length==2){
					newT+=t.substr(0,pos) + '<a onclick="goFormatWeb(\'' +  tText[1] + '\')" title="' + tText[1] + '" style="text-decoration:underline; cursor:pointer">' + tText[0] + '</a>'
					//newT+=t.substr(0,pos) + '<a href="' + tText[1] + '" title="' + tText[1] + '" style="text-decoration:underline; cursor:pointer; color:' + col + '">' + tText[0] + '</a>'
					restText=t.substr(pos+pos2+1)
					t=t.substr(pos+pos2+1)
				}
				else{
					restText=t.substr(pos+1)
					break
				}
			}
			else{
				restText=t.substr(pos+1)
				break
			}
		}
	}while(pos>-1)
	if(newT!==""){t=newT + restText}
	return t
}

function goFormatWeb(url){
	u=url.split("\#")
	if(u.length>1){
		w=u[1].split("\§")
		myWindowOpen(u[0],"","left=40px, top=40px, width=" + w[0] + "px, height=" + w[1] + "px")
	}
	else{
		myWindowOpen(url,"","")
	}
}

function goFormatMail(adr,text,chD){
	a=adr.replace("\@","qpßqp")
	myWindowOpen(chD + "email.php?emAd=" + a + "&t=" + text,"","left=40px, top=40px, width=300px, height=400px")
}
	
function goFormatKapitel(kap){
	s=kap.split(",")
	cursorAllWait()
	self.location='seite.php?p=' + s[0] + '&m=' + s[1] + '&s=' + s[2]
}

function goFormatVC(data){
	w=400;h=300
	winPos=windowPlace(w,h)
	window.open("visitenkarte.php?name=" + data,"","left=" + winPos[0] + "px, top=" + winPos[1] + "px, width=" + w + "px, height=" + h + "px, menubar=no, toolbar=no, status=no, titlebar=no")
	
}

function goFormatLexikon(letter,word){
	//closeAllWins()
	winLexikon=myWindowOpen("lexikon/lexikon.php?isChar=" + letter + "&suchwort=" + word,"","left=40px, top=40px, width=300px, height=400px")
}
	