function formatText(t,u,e,k,d,col){
	if(u==1){t=checkForUrl(t)}
	if(e==1){t=checkForEMail(t)}
	if(k==1){t=checkForKap(t)}
	if(d==1){t=checkForDownload(t,col)}
	var m = new RegExp(crlf,"g")
	t=t.replace(m,"<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,"}")		
	
	return t
}

function checkForUrl(t){
	var seekStr = new RegExp(/\{\+w\+/)
	newT=""
	do{
		pos=t.search(seekStr)
		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:hand">' + 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 checkForEMail(t){
	var seekStr = new RegExp(/\{\+e\+/)
	newT=""
	do{
		pos=t.search(seekStr)
		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 + ')" title="' + tText[1] + '" style="text-decoration:underline; cursor:hand">' + 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){
	var seekStr = new RegExp(/\{\+s\+/)
	newT=""
	do{
		pos=t.search(seekStr)
		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 Kapitel ' + tText[1] + '" style="text-decoration:underline; cursor:hand">' + 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){
	var seekStr = new RegExp(/\{\+d\+/)
	newT=""
	do{
		pos=t.search(seekStr)
		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 href="' + tText[1] + '" title="' + tText[1] + '" style="text-decoration:underline; cursor:hand; 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){
	window.open(url,"","")
}

function goFormatMail(adr,text){
	a=adr.replace("\@","qpßqp")
	window.open("email.php?emAd=" + a + "&t=" + text,"","left=40px, top=40px, width=300px, height=400px")
}
	
function goFormatKapitel(kap){
	s=kap.split(",")
	if(!s[0]){s[0]=0}else{s[0]--}
	if(!s[1]){s[1]=0}
	if(s[0]<1){s[0]=0};if(s[1]<1){s[1]=0}
	if(s[0]>(m_menuMainCount-1)){s[0]=(m_menuMainCount-1)};if(s[1]>m_menuSubCount){s[1]=m_menuSubCount}
	
	menuGoSite(s[0],s[1])
	return false
	
	mB=mbuts[mainPart][s[0]].split("\#")
	sB=mB[s[1]].split("\|")
	if(sB.length==2){
	
	}
	else{
		document.getElementById("bodyAll").style.cursor="wait"
		self.location='seite.php?p=' + mainPart + '&m=' + s[0] + '&s=' + s[1]
	}	
}

	
