var quoteRange; //globale Variable für die Zitierfunktion
var linkRange; //globale Variable für die Linkfunktion
var max_com = 15; //die Anzahl der abzurufenden Kommentare
var currentPage = 1;
var linkMode = 'URL';
var previewActive = false;

function createInterface(){
	//die messagebox erzeugen
	var code = top.document.createDocumentFragment();
	var glassdiv = top.document.createElement('div');	//das div zum Ausblenden
	glassdiv.setAttribute('id','glass');
	glassdiv.setAttribute('style','position:fixed; top:0px; left:0px; width:100%; height:100%; background-color:#000; -moz-opacity:0.5; -khtml-opacity:0.5; opacity:0.5; filter:alpha(opacity=50); z-index:10; display:none;');
	code.appendChild(glassdiv);
	var msgbox = top.document.createElement('div');   //das warning box div
	msgbox.setAttribute('id','warning_box');
	msgbox.setAttribute('style','display:none;border:1px #FFCF07 solid;width:500px;height:auto;position:fixed;top:30%;left:46%;margin-left:-200px;z-index:11;background-color:#FFF;text-align:center;font-family: Verdana, Arial, Helvetica, sans-serif;font-size:10pt;-moz-border-radius:15px;-khtml-border-radius:15px;-webkit-border-radius:15px;border-radius:15px;-webkit-box-shadow:rgb(0,0,0) 1px 1px 8px;');
	var msgbox2 = top.document.createElement('div');   //für den Rahmen
	msgbox2.setAttribute('style','height:100%;border:13px solid #FFF0B7;padding-top: 40px;padding-right: 30px;padding-bottom: 20px;padding-left: 30px;-moz-border-radius:15px;-khtml-border-radius:15px;-webkit-border-radius:15px;border-radius:15px;');
	var floatCont = top.document.createElement('div');
	floatCont.setAttribute('style','margin:auto;');
	var right = top.document.createElement('div');
	right.setAttribute('style','float:left;width:339px;');
	var left = top.document.createElement('div');
	left.setAttribute('style','float:left;width:75px;');	
	var bild = top.document.createElement('img');
	bild.setAttribute('src','Informationen/Kolumne/images/warning.png');
	left.appendChild(bild);
	var msgboxtext = top.document.createElement('div');		//das div für den text
	msgboxtext.setAttribute('id','warning_box_msg');
	var txt = top.document.createTextNode('-warning-');		//den standardtext
	msgboxtext.appendChild(txt);
	right.appendChild(msgboxtext);
	var br = top.document.createElement('br');	//zeilenumbruch
	right.appendChild(br);
	var okbutton = top.document.createElement('input');		//den OK button
	okbutton.setAttribute('type','button');
	okbutton.setAttribute('name','OK');
	okbutton.setAttribute('value','OK');
	okbutton.setAttribute('onclick','document.getElementById("warning_box").style.display = "none";document.getElementById("glass").style.display = "none";');
	okbutton.setAttribute('style','margin-top:30px; width:50px;color: #5A5A5A;font: 11px Verdana, Arial, Helvetica, sans-serif;background: #FFF9D7;border: 1px solid #FFCF07;padding:5px;font-weight:bold;-moz-border-radius:3px;-khtml-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;');
	var clearBr = top.document.createElement('br');
	clearBr.setAttribute('style','clear:both');
	floatCont.appendChild(left);
	floatCont.appendChild(right);
	floatCont.appendChild(clearBr);
	msgbox2.appendChild(floatCont);
	msgbox.appendChild(msgbox2);
	code.appendChild(msgbox);
	right.appendChild(okbutton);  //wenn das früher gemacht wird, gibts einen Fehler im IE
	top.document.body.appendChild(code);	//das jetzt ins top einfügen*/
	//msgbox ende
	//activity
	var act = top.document.createElement('div');
	act.setAttribute('id','activityContainer');
	act.setAttribute('style','position:fixed;bottom:0px;left:46%;z-index:100;font: 11px Verdana, Arial, Helvetica, sans-serif; color: #5A5A5A; padding:2px 5px 2px 5px; background-color:#EEEEEE; border-left:2px solid #BBBBBB; border-top:2px solid #BBBBBB; border-right:2px solid #BBBBBB; -moz-border-radius-topright:5px; -moz-border-radius-topleft:5px; -khtml-border-radius-topright:5px; -khtml-border-radius-topleft:5px; -webkit-border-top-left-radius:5px; -webkit-border-top-right-radius:5px;-webkit-box-shadow:rgb(180,180,180) 0px 0px 4px;');
	var act2 = top.document.createElement('div');
	act2.setAttribute('id','activity');
	act2.setAttribute('style','float:left;margin-right:5px;margin-top:3px;');
	act.appendChild(act2);
	var act3 = top.document.createElement('div');
	act3.setAttribute('style','float:left;');
	var actLink = top.document.createElement('a');
	actLink.setAttribute('onclick','document.getElementById(\'activityContainer\').style.visibility = \'hidden\';');
	actLink.setAttribute('style','cursor:pointer;padding:0px;');
	actLink.setAttribute('title','Ausblenden');
	var crossImg = top.document.createElement('img');
	crossImg.setAttribute('src','Informationen/Kolumne/images/cross.gif');
	crossImg.setAttribute('style','border:none;');
	actLink.appendChild(crossImg);
	act3.appendChild(actLink);
	act.appendChild(act3);
	top.document.body.appendChild(act);
	//activity ende
	//die Zitatfunktion
	var box = top.document.createElement('div');
	box.setAttribute('style','position:fixed;left:50%;top:20%;width:500px;margin-left:-250px;border:13px solid #FFF0B7;z-index:11;background-color:#FFF;border:1px #FFCF07 solid;padding:20px;display:none;border-radius:10px;-moz-border-radius:10px;-khtml-border-radius:10px;-webkit-border-radius:10px;font: 11px Verdana, Arial, Helvetica, sans-serif;-webkit-box-shadow:rgb(0,0,0) 1px 1px 8px;');
	box.setAttribute('id','quoteFunction');
	var heading = top.document.createElement('p');
	heading.setAttribute('style','font-weight:bold;font-size:18pt;color:gray;margin-top:0px;');
	headingText = top.document.createTextNode('Zitat einfügen');
	heading.appendChild(headingText);
	box.appendChild(heading);
	var hinweis = top.document.createTextNode('Hier kannst du das Zitat entsprechend anpassen.');
	var paragraph = top.document.createElement('p');
	paragraph.appendChild(hinweis);
	box.appendChild(paragraph);	
	var nameInput = top.document.createElement('input');
	nameInput.setAttribute('type','text');
	nameInput.setAttribute('id','quoteName');
	nameInput.setAttribute('style','width:350px;color: #5A5A5A;background: #FFFFFF;padding: 3px 5px;border: 1px solid #FFCF07;border-radius:3px;-moz-border-radius:3px;-khtml-border-radius:3px;-webkit-border-radius:3px;font: 11px Verdana, Arial, Helvetica, sans-serif; background-image:url(Informationen/Kolumne/images/optional.gif);background-position:right center;background-repeat:no-repeat;');
	var quoteInput = top.document.createElement('textarea');
	quoteInput.setAttribute('style','width:350px;height:150px;color: #5A5A5A;background: #FFFFFF;padding: 3px 5px;border: 1px solid #FFCF07;border-radius:3px;-moz-border-radius:3px;-khtml-border-radius:3px;-webkit-border-radius:3px;font: 11px Verdana, Arial, Helvetica, sans-serif;');
	quoteInput.setAttribute('id','quoteText');
	var table = top.document.createElement('table');
	table.setAttribute('style','margin:auto;border-collapse:separate;border-spacing:5px;');
	var tr1 = top.document.createElement('tr');
	var tr2 = top.document.createElement('tr');
	var tr3 = top.document.createElement('tr');
	var tr1td1 = top.document.createElement('td');
	tr1td1.setAttribute('style','vertical-align:middle;');
	var tr1td2 = top.document.createElement('td');
	var tr2td1 = top.document.createElement('td');
	tr2td1.setAttribute('style','vertical-align:middle;');
	var tr2td2 = top.document.createElement('td');
	var tr3td1 = top.document.createElement('td');
	var tr3td2 = top.document.createElement('td');
	tr1td2.appendChild(nameInput);
	tr2td2.appendChild(quoteInput);
	nameText = top.document.createTextNode('Name:');
	quoteText = top.document.createTextNode('Zitat:');
	tr1td1.appendChild(nameText);
	tr2td1.appendChild(quoteText);
	var quoteOk = top.document.createElement('input');
	quoteOk.setAttribute('type','button');
	quoteOk.setAttribute('value','OK');
	quoteOk.setAttribute('onclick','top.frames[0].addQuoteText(document.getElementById("quoteName").value,document.getElementById("quoteText").value);');	
	quoteOk.setAttribute('style','color: #5A5A5A;background: #FFF9D7;border: 1px solid #FFCF07;padding: 5px;border-radius:3px;-moz-border-radius:3px;-khtml-border-radius:3px;-webkit-border-radius:3px;font: 11px Verdana, Arial, Helvetica, sans-serif;font-weight: bold;');
	var quoteCancel = top.document.createElement('input');
	quoteCancel.setAttribute('type','button');
	quoteCancel.setAttribute('value','Abbrechen');
	quoteCancel.setAttribute('onclick','top.frames[0].cancelQuote();');	
	quoteCancel.setAttribute('style','color: #5A5A5A;background: #FFF9D7;border: 1px solid #FFCF07;padding: 5px;border-radius:3px;-moz-border-radius:3px;-khtml-border-radius:3px;-webkit-border-radius:3px;font: 11px Verdana, Arial, Helvetica, sans-serif;font-weight: bold;');	
	var leerzeichen = top.document.createTextNode(' ');
	tr3td2.appendChild(quoteOk);
	tr3td2.appendChild(leerzeichen);
	tr3td2.appendChild(quoteCancel);
	tr1.appendChild(tr1td1);
	tr1.appendChild(tr1td2);
	tr2.appendChild(tr2td1);
	tr2.appendChild(tr2td2);
	tr3.appendChild(tr3td1);
	tr3.appendChild(tr3td2);
	table.appendChild(tr1);
	table.appendChild(tr2);
	table.appendChild(tr3);
	box.appendChild(table);
	top.document.body.appendChild(box); 
	//Zitatfunktion ende
	//Linkfunktion Anfang
	box = top.document.createElement('div');
	box.setAttribute('style','position:fixed;left:50%;top:20%;width:500px;margin-left:-250px;border:13px solid #FFF0B7;z-index:12;background-color:#FFF;border:1px #FFCF07 solid;padding:20px;display:none;border-radius:10px;-moz-border-radius:10px;-khtml-border-radius:10px;-webkit-border-radius:10px;font: 11px Verdana, Arial, Helvetica, sans-serif;-webkit-box-shadow:rgb(0,0,0) 1px 1px 8px;');
	box.setAttribute('id','linkFunction');
	heading = top.document.createElement('p');
	heading.setAttribute('style','font-weight:bold;font-size:18pt;color:gray;margin-top:0px;');
	headingText = top.document.createTextNode('Link einfügen');
	heading.appendChild(headingText);
	box.appendChild(heading);
	hinweis = top.document.createTextNode('Hier kannst du den Link entsprechend anpassen.');
	paragraph = top.document.createElement('p');
	paragraph.appendChild(hinweis);
	box.appendChild(paragraph);	
	nameInput = top.document.createElement('textarea');
	nameInput.setAttribute('id','linkName');
	nameInput.setAttribute('style','width:350px; height:39px; color: #5A5A5A;background: #FFFFFF;padding: 3px 5px;border: 1px solid #FFCF07;border-radius:3px;-moz-border-radius:3px;-khtml-border-radius:3px;-webkit-border-radius:3px;font: 11px Verdana, Arial, Helvetica, sans-serif; background-image:url(Informationen/Kolumne/images/optional2.gif);background-position:right center;background-repeat:no-repeat;');
	nameInput.setAttribute('onkeyup','top.frames[0].linkVorschau();');
	quoteInput = top.document.createElement('input');
	quoteInput.setAttribute('type','text');
	quoteInput.setAttribute('style','width:350px;color: #5A5A5A;background: #FFFFFF;padding: 3px 5px;border: 1px solid #FFCF07;border-radius:3px;-moz-border-radius:3px;-khtml-border-radius:3px;-webkit-border-radius:3px;font: 11px Verdana, Arial, Helvetica, sans-serif;');
	quoteInput.setAttribute('id','linkPfad');
	quoteInput.setAttribute('onkeyup','top.frames[0].linkVorschau();');
	tab1 = top.document.createElement('a');
	tab1.setAttribute('style','padding:4px 5px 4px 5px;background-color:#F3F3F3; border:1px solid #F3F3F3 ;margin-left:20px;display:inline;color:#5A5A5A;-moz-border-radius-topleft:3px;-khtml-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;border-radius-topleft:3px;-moz-border-radius-topright:3px;-khtml-border-radius-topright:3px;-webkit-border-top-right-radius:3px;border-radius-topright:3px;');
	tab1.setAttribute('href','javascript:top.frames[0].changeLinkMode("URL");');
	tab1.setAttribute('title','Web-Link');
	tab1.setAttribute('id','tab1');
	tab1text = top.document.createTextNode('URL');
	tab1.appendChild(tab1text);
	box.appendChild(tab1);
	tab2 = top.document.createElement('a');
	tab2.setAttribute('style','border:1px solid #F3F3F3;padding:4px 5px 4px 5px;background-color:#FFFFFF;margin-left:3px;display:inline;color:#5A5A5A;-moz-border-radius-topleft:3px;-khtml-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;border-radius-topleft:3px;-moz-border-radius-topright:3px;-khtml-border-radius-topright:3px;-webkit-border-top-right-radius:3px;border-radius-topright:3px;');
	tab2.setAttribute('href','javascript:top.frames[0].changeLinkMode("mail");');
	tab2.setAttribute('title','E-Mail Link');
	tab2.setAttribute('id','tab2');
	tab2text = top.document.createTextNode('E-Mail Link');
	tab2.appendChild(tab2text);	
	box.appendChild(tab2);
	table = top.document.createElement('table');
	table.setAttribute('style','margin:auto;border-collapse:separate;border-spacing:5px;background-color:#F3F3F3;margin-top:4px;-moz-border-radius:3px;-khtml-border-radius:3px; -webkit-border-radius:3px; border-radius:3px;');
	tr1 = top.document.createElement('tr');
	tr2 = top.document.createElement('tr');
	tr3 = top.document.createElement('tr');
	tr1td1 = top.document.createElement('td');
	tr1td1.setAttribute('style','vertical-align:middle;');
	tr1td2 = top.document.createElement('td');
	tr2td1 = top.document.createElement('td');
	tr2td1.setAttribute('style','vertical-align:middle;');
	tr2td1.setAttribute('id','addressId');
	tr2td2 = top.document.createElement('td');
	tr3td1 = top.document.createElement('td');
	tr3td2 = top.document.createElement('td');
	tr1td2.appendChild(nameInput);
	tr2td2.appendChild(quoteInput);
	nameText = top.document.createTextNode('Angezeigter Text:');
	quoteText = top.document.createTextNode('Linkaddresse:');
	tr1td1.appendChild(nameText);
	tr2td1.appendChild(quoteText);
	quoteOk = top.document.createElement('input');
	quoteOk.setAttribute('type','button');
	quoteOk.setAttribute('value','OK');
	quoteOk.setAttribute('onclick','top.frames[0].addLinkText(document.getElementById("linkName").value,document.getElementById("linkPfad").value);');	
	quoteOk.setAttribute('style','color: #5A5A5A;background: #FFF9D7;border: 1px solid #FFCF07;padding: 5px;border-radius:3px;-moz-border-radius:3px;-khtml-border-radius:3px;-webkit-border-radius:3px;font: 11px Verdana, Arial, Helvetica, sans-serif;font-weight: bold;');
	quoteCancel = top.document.createElement('input');
	quoteCancel.setAttribute('type','button');
	quoteCancel.setAttribute('value','Abbrechen');
	quoteCancel.setAttribute('onclick','top.frames[0].cancelLink();');	
	quoteCancel.setAttribute('style','color: #5A5A5A;background: #FFF9D7;border: 1px solid #FFCF07;padding: 5px;border-radius:3px;-moz-border-radius:3px;-khtml-border-radius:3px;-webkit-border-radius:3px;font: 11px Verdana, Arial, Helvetica, sans-serif;font-weight: bold;');	
	leerzeichen = top.document.createTextNode(' ');
	tr3td2.appendChild(quoteOk);
	tr3td2.appendChild(leerzeichen);
	tr3td2.appendChild(quoteCancel);
	tr1.appendChild(tr1td1);
	tr1.appendChild(tr1td2);
	tr2.appendChild(tr2td1);
	tr2.appendChild(tr2td2);
	tr3.appendChild(tr3td1);
	tr3.appendChild(tr3td2);
	table.appendChild(tr1);
	table.appendChild(tr2);
	table.appendChild(tr3);
	box.appendChild(table);
	var linkPrev = top.document.createElement('div');
	linkPrev.setAttribute('id','linkPrev');
	linkPrev.setAttribute('style','padding:5px;');
	box.appendChild(linkPrev);
	top.document.body.appendChild(box); 	
	//Linkfunktion Ende
}

var req3 = null;

try{
	req3 = new XMLHttpRequest();
}
catch (ms){
	try{
		req3 = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (nonms){
		try{
			req3 = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (failed){
			req3 = null;
		}
	}  
}

if (req3 == null){
	  showWarning("AJAX Fehler");
}

var req2 = null;

try{
	req2 = new XMLHttpRequest();
}
catch (ms){
	try{
		req2 = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (nonms){
		try{
			req2 = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (failed){
			req2 = null;
		}
	}  
}

if (req2 == null){
	  showWarning("Fehler beim Laden der Kommentare: Error creating request object!");
}	

var req4 = null;
try{
	req4 = new XMLHttpRequest();
}
catch (ms){
	try{
		req4 = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (nonms){
		try{
			req4 = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (failed){
			req4 = null;
		}
	}  
}
if (req4 == null){
	  showWarning("Fehler beim Laden der Kommentare: Error creating request object!");
}

var req5 = null;
try{
	req5 = new XMLHttpRequest();
}
catch (ms){
	try{
		req5 = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (nonms){
		try{
			req5 = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (failed){
			req5 = null;
		}
	}  
}
if (req5 == null){
	  showWarning("Fehler beim Laden der Kommentare: Error creating request object!");
}

function more(){
	var menge = prompt("Wieviele Kommentare sollen maximal angezeigt werden?",max_com);
	if(menge != null){
		max_com = menge;
		getComments();
	}
}

function getComments(){
      if((req2.readyState == 0 || req2.readyState == 4)&&(req5.readyState == 0 || req5.readyState == 4)){  
	  	  setStatus("Bitte warten, Kommentare werden geladen!");
		  var postdata = "amount="+max_com+"&page="+currentPage;
		  req2.open("POST","get.php",true);
		  req2.onreadystatechange = function(){
			  if(req2.readyState == 4){
				  if(req2.status == 200){
					  document.getElementById("kommentare").innerHTML = "";
					  document.getElementById("kommentare").innerHTML = req2.responseText;	
					  req5.open("POST","termine.php",true);
						  req5.onreadystatechange = function(){
						  if(req5.readyState == 4){
							  if(req5.status == 200){
								  eval(req5.responseText);
								  setFrameHeight();
								  setStatus("Fertig.");		
							  }else{
									setStatus("Beim Abrufen der Kommentare ist ein Fehler aufgetreten!");					
									showWarning("Fehler: Status="+req5.status);  
							  }
						  }else{
								return false;  
						  }
					  }
					  req5.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		  			  req5.send(null);
				  }else{
						setStatus("Beim Abrufen der Kommentare ist ein Fehler aufgetreten!");					
						showWarning("Fehler: Status="+req2.status);  
				  }
			  }else{
					return false;  
			  }
		  }
		  req2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		  req2.send(postdata);
	  }
}

function vorschau(showMessages){
      if((document.getElementById('formName').value != '') && (document.getElementById('textfeld').value != '')){
		  if(document.getElementById('formName').value.indexOf('[') == -1 && document.getElementById('formName').value.indexOf(']') == -1){
		  if(showMessages) setStatus("Bitte warten, Vorschau wird erzeugt!");
		  var req = null;
		  try{
			  req = new XMLHttpRequest();
		  }
		  catch (ms){
			  try{
				  req = new ActiveXObject("Msxml2.XMLHTTP");
			  } 
			  catch (nonms){
				  try{
					  req = new ActiveXObject("Microsoft.XMLHTTP");
				  } 
				  catch (failed){
					  req = null;
				  }
			  }  
		  }
		  if (req == null){
				if(showMessages) showWarning("Fehler: Error creating request object!");
		  }
		  postdata = 'name='+encodeURIComponent(document.getElementById('formName').value)+'&text='+encodeURIComponent(document.getElementById('textfeld').value);
		  req.open("POST", 'preview.php', true);
		  req.onreadystatechange = function(){
		  if(req.readyState == 4){
				if(req.status!=200) {
					if(showMessages) showWarning("Fehler:"+req.status); 
				}else{
					document.getElementById('vorschauDiv').innerHTML = req.responseText;
					setFrameHeight();
					if(showMessages) setStatus("Vorschau wurde erstellt!");  
				}
			}else{
				return false; 
			}
		  }
		  req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		  req.send(postdata);
		}else{
			if(showMessages) showWarning("Dein Name darf keine eckigen Klammern enthalten!");		
		}
	}else{	
		if(showMessages) showWarning("Bitte beide Felder ausfüllen!");
	}
}

function senden(){
	if((document.getElementById('formName').value != '') && (document.getElementById('textfeld').value != '')){
	 // FGS und Konsorten 
	 t = document.getElementById('formName').value.toUpperCase();  
	 t1 = document.getElementById('textfeld').value.toUpperCase();
	 if(t.indexOf('FGS')==-1 && t.indexOf('SERG')==-1 && t1.indexOf('WEBMAST')==-1) {
		if(document.getElementById('formName').value.indexOf('[') == -1 && document.getElementById('formName').value.indexOf(']') == -1){
		  document.getElementById("submit").disabled = true;
		  document.getElementById("submit").style.color = "#DDDDDD";
		  document.getElementById("preview").disabled = true;
		  document.getElementById("preview").style.color = "#DDDDDD";	  
		  setStatus("Bitte warten, Kommentar wird gesendet");
		  var req = null;
	  
		  try{
			  req = new XMLHttpRequest();
		  }
		  catch (ms){
			  try{
				  req = new ActiveXObject("Msxml2.XMLHTTP");
			  } 
			  catch (nonms){
				  try{
					  req = new ActiveXObject("Microsoft.XMLHTTP");
				  } 
				  catch (failed){
					  req = null;
				  }
			  }  
		  }
		  if (req == null){
				showWarning("Fehler beim Senden des Kommentares: Error creating request object!");
		  }
		  postdata = 'name='+encodeURIComponent(document.getElementById('formName').value)+'&text='+encodeURIComponent(document.getElementById('textfeld').value);
		  req.open("POST", 'enter.php', true);
		  req.onreadystatechange = function(){
		  if(req.readyState == 4){
				if(req.status!=200) {
					showWarning("Fehler:"+req.status); 
				}else{    
					if(req.responseText=="OK"){
						  setStatus("Dein Kommentar wurde erfolgreich eingetragen!");  
						  getComments();
					}else{
						  setStatus("Beim Eintragen ist ein Fehler aufgetreten.");   
						  document.getElementById("submit").disabled = false;
						  document.getElementById("submit").style.color = "#5A5A5A";
						  document.getElementById("preview").disabled = false;
						  document.getElementById("preview").style.color = "#5A5A5A";					  
					}
				}
			}else{
				return false; 
			}
		  }
		  req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		  req.send(postdata);
		}else{
			showWarning("Dein Name darf keine eckigen Klammern enthalten!");		
		}
	 // else für fgs und sergai
	 }else{
	   showWarning('Bitte den Knopf EINTRAGEN mindestens 10s lang drücken!');  
	 }
	}else{
		showWarning('Bitte beide Felder ausfüllen!');
	}
}

function add_smile(type){
	feld.replaceSelection('%'+type+'%',true);
	updatePreview();
}

function format(type){
	feld.tagSelection('['+type+']','[/'+type+']',true);
	updatePreview();
}

// Internet Explorer Version größer 7?
function ieio() {
	if(navigator.appVersion.indexOf('MSIE') > -1) {
	  // die ersten 6 Zeichen aus dem Msie-String herausschneiden
	  // an welcher Stelle tritt MSIE auf? 
	  h = navigator.appVersion.indexOf('MSIE'); 
	  // die ersten 7 Zeichen ermitteln,
	  // beim Sechsten beginnt die Versionsnummer
	  hStr = navigator.appVersion.substr(h,7);  
	  // und jetzt das Sechste und Siebente in eine Zahl
	  // umwandeln und testen
	  // alert(hStr); 
	  h = parseInt(hStr.substr(5,2)); 
	  if(h > 7) {
	    return true;
	  }   
	  else {
	    return false;
	  }    	  
	}	
}


function hyperlink(evt){
	if(!evt.ctrlKey){
		// if(navigator.appVersion.indexOf('MSIE') > -1 && navigator.appVersion.indexOf('MSIE 8.0') == -1){
		if(ieio() == false) {
			alert('Diese Funktion wird von deinem Browser nicht unterstützt.'); 
			return;
		}
		linkRange = feld.saveSelection();
		if(feld.getSelectionLength() == 0){
			showLinkInput('','');
		}else{
			if(false == feld.isURL(feld.getSelectedText()) && false == feld.isMail(feld.getSelectedText())){
				showLinkInput(feld.getSelectedText(),'');
			}else{
				if(feld.isURL(feld.getSelectedText())){
					changeLinkMode('URL');
					showLinkInput('',feld.trim(feld.getSelectedText()));					
				}else{
					changeLinkMode('mail');
					showLinkInput('',feld.trim(feld.getSelectedText()));
				}
			}
		}
	}else{
		feld.focus();
		format('a');	
	}
}

function zitat(){
	// if(navigator.appVersion.indexOf('MSIE') > -1 && navigator.appVersion.indexOf('MSIE 8.0') == -1){
	if(ieio() == false) {
		alert('Diese Funktion wird von deinem Browser nicht unterstützt.'); 
		return;
	}
	quoteRange = feld.saveSelection();
	if(feld.getSelectionLength() == 0){
		showQuote('','');
	}else{
		showQuote('',feld.getSelectedText());
	}
}

function del(id){
	  if(true == window.confirm("Wirklich löschen?")){
		  var postdata = "id="+id;
		  req3.open("POST","delete.php",true);
		  req3.onreadystatechange = function(){
			  if(req3.readyState == 4){
				  if(req3.status == 200){
						if(req3.responseText == "OK"){
							getComments();
						}else{
							showWarning("Fehler beim Löschen: "+req3.responseText);	
						}
				  }else{
						showWarning("Fehler:"+req3.status);  
				  }
			  }else{
					return false;  
			  }
		  }
		  req3.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		  req3.send(postdata);  
	  }
}

function showWarning(msg){
	top.document.getElementById('warning_box_msg').innerHTML = msg;	
	top.document.getElementById('glass').style.display = 'block';
	top.document.getElementById('warning_box').style.display = 'block';
}

function quote(id,name,evt){
	if(evt.ctrlKey == true) var strg = true; else var strg = false;  //in variable speichern, denn das onreadystatechange überschreibt das event
	// if(navigator.appVersion.indexOf('MSIE') > -1 && navigator.appVersion.indexOf('MSIE 8.0') == -1){
	if(ieio == false) {
		alert('Diese Funktion wird von deinem Browser nicht unterstützt.'); 
		return;
	}
	feld.focus();
	quoteRange = feld.saveSelection();
	if(req4.readyState == 0 || 4){
	  	  setStatus("Bitte warten, Zitat wird erzeugt!");
		  var postdata = "id="+id;
		  req4.open("POST","get_quote.php",true);
		  req4.onreadystatechange = function(){
			  if(req4.readyState == 4){
				  if(req4.status == 200){
					  var str = req4.responseText;
					  if(strg == true){
						addQuoteText(name,str);
					  }else{
					  	showQuote(name,str);
					  }
	  	 		 	  setStatus("Fertig.");		
				  }else{
						setStatus("Beim Abrufen des Zitates ist ein Fehler aufgetreten!");					
						showWarning("Fehler: Status="+req4.status);  
				  }
			  }else{
					return false;  
			  }
		  }
		  req4.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		  req4.send(postdata);
	  }
}

var enlargeInterval;
var stepInterval;
var actualHeight;
function enlargeTextarea(){
	actualHeight = parseInt(document.getElementById('textfeld').style.height);
	stepInterval = 7;
	targetHeight = actualHeight+100;
	enlargeInterval = setInterval(function(){enlargeTextfeldStep(targetHeight);},20);
}

function enlargeTextfeldStep(targetHeight){
	if(actualHeight < targetHeight){
		if(actualHeight >(targetHeight-75) && stepInterval > 2){
			stepInterval = stepInterval * 0.93;	
		}
		actualHeight = actualHeight+stepInterval;
		document.getElementById('textfeld').style.height = 	actualHeight+'px';
		setFrameHeight();
	}else{
		clearInterval(enlargeInterval);	
		document.getElementById('textfeld').focus();
		setFrameHeight();
	}
}

function destroyActivity(){
	top.document.getElementById('activityContainer').parentNode.removeChild(top.document.getElementById('activityContainer'));
}

function setStatus(text){
  if(text != 'Fertig.') {
		top.document.getElementById("activity").innerHTML = text;
		if(top.document.body.clientWidth != 'undefined'){ 
		  var breite = top.document.body.clientWidth;
		}else{
		  var breite = window.innerWidth;
		}
		top.document.getElementById('activityContainer').style.left = ((breite - top.document.getElementById('activityContainer').offsetWidth)/2)+'px';
		if(top.document.getElementById('activityContainer').style.visibility == 'hidden'){
			top.document.getElementById('activityContainer').style.visibility = 'visible';
		}
	}	
	else {
	  top.document.getElementById('activityContainer').style.visibility = 'hidden';
	}
}

function showQuote(name,quote){
	top.document.getElementById('quoteName').value = name;
	top.document.getElementById('quoteText').value = quote;
	top.document.getElementById('glass').style.display = 'block';
	top.document.getElementById('quoteFunction').style.display = 'block';
	top.document.getElementById('quoteText').focus();
}

function cancelQuote(){
	top.document.getElementById('quoteFunction').style.display = 'none';	
	top.document.getElementById('glass').style.display = 'none';
}

function addQuoteText(name,text){
	if(name != ''){
		str = '[quote='+name+']'+text+'[/quote]';
	}else{
		str = '[quote]'+text+'[/quote]';		
	}
	feld.loadSelection(quoteRange);
	feld.replaceSelection(str,true);
	cancelQuote();
	updatePreview();
}

function gotoPage(){
	var page = null;
	page = prompt('Welche Seite soll angezeigt werden?',currentPage);
	if(page != null){
		if(!isNaN(page)){
			currentPage = page;
			getComments();
		}else{
			showWarning('Der eingegebene Wert ist keine Zahl!');
		}
	}
}

function showLinkInput(name,pfad){
	top.document.getElementById('linkName').value = name;
	top.document.getElementById('linkPfad').value = pfad;
	top.document.getElementById('glass').style.display = 'block';
	top.document.getElementById('linkFunction').style.display = 'block';
	top.document.getElementById('linkName').focus();		
	linkVorschau();
}

function cancelLink(){
	top.document.getElementById('linkFunction').style.display = 'none';	
	top.document.getElementById('glass').style.display = 'none';
}

function addLinkText(name,text){
	if(top.document.getElementById('linkPfad').value != ''){
		if((linkMode == 'mail' && feld.isMail(top.document.getElementById('linkPfad').value)) || linkMode == 'URL'){
			var expression = /^( )*http:\/\/(.)*/;
			var expression2 = /^( )*mailto:(.)*/;
			if(linkMode == 'URL'){
				if(top.document.getElementById('linkName').value == ''){
					linkName = '';
					links = top.document.getElementById('linkPfad').value;
					links = feld.trim(links);
					if(false == expression.test(links)){
						links = 'http://'+links;
					}
					new_text = '[a]'+links+'[/a]';
				}else{
					linkName = top.document.getElementById('linkName').value;
					links = top.document.getElementById('linkPfad').value;
					links = feld.trim(links);
					if(false == expression.test(links)){
						links = 'http://'+links;
					}
					new_text = "[a="+links+"]"+linkName+'[/a]';
				}
			}else{
				if(top.document.getElementById('linkName').value == ''){
					links = top.document.getElementById('linkPfad').value;
					links = linkName = feld.trim(links);
					if(false == expression2.test(links)){
						links = 'mailto:'+links;
					}else{
						linkName = linkName.replace(/^mailto:/,'');	
					}
					new_text = '[a='+links+']'+linkName+'[/a]';
				}else{
					linkName = top.document.getElementById('linkName').value;
					links = top.document.getElementById('linkPfad').value;
					links = feld.trim(links);
					if(false == expression2.test(links)){
						links = 'mailto:'+links;
					}
					new_text = "[a="+links+"]"+linkName+'[/a]';
				}
			}
			feld.loadSelection(linkRange);
			feld.replaceSelection(new_text,true);
			cancelLink();	
		}else{
			cancelLink();
			showWarning('Es wurde kein Link erzeugt, da keine gültige E-Mail-Addresse angegeben wurde.');				
		}
	}else{
		cancelLink();
		showWarning('Es wurde kein Link erzeugt, da keine Addresse angegeben wurde.');	
	}
	updatePreview();
}

function changeLinkMode(mode){
	linkMode = mode;
	if(mode == "URL"){
		top.document.getElementById('addressId').innerHTML = 'Linkaddresse:';	
		top.document.getElementById('tab1').style.backgroundColor = '#F3F3F3';
		top.document.getElementById('tab2').style.backgroundColor = '#FFFFFF';
	}else{
		top.document.getElementById('addressId').innerHTML = 'E-Mail-Addresse:';	
		top.document.getElementById('tab2').style.backgroundColor = '#F3F3F3';
		top.document.getElementById('tab1').style.backgroundColor = '#FFFFFF';		
	}
	linkVorschau();
}

function linkVorschau(){
	var expression4 = /\[a\](.*?)\[\/a\]/;
	var expression5 = /\[a=(.*?)\]([\S\s]*)\[\/a\]/;
	if(top.document.getElementById('linkPfad').value != ''){
		if((linkMode == 'mail' && feld.isMail(top.document.getElementById('linkPfad').value)) || (linkMode == 'URL' && feld.isURL(top.document.getElementById('linkPfad').value))){
			var expression = /^( )*http:\/\/(.)*/;
			var expression2 = /^( )*mailto:(.)*/;
			var linkName;
			if(linkMode == 'URL'){
				if(top.document.getElementById('linkName').value == ''){
					linkName = '';
					links = top.document.getElementById('linkPfad').value;
					links = feld.trim(links);
					if(false == expression.test(links)){
						links = 'http://'+links;
					}
					new_text = '[a]'+links+'[/a]';
				}else{
					linkName = top.document.getElementById('linkName').value;
					links = top.document.getElementById('linkPfad').value;
					links = feld.trim(links);
					if(false == expression.test(links)){
						links = 'http://'+links;
					}
					new_text = "[a="+links+"]"+linkName+'[/a]';
				}
			}else{
				if(top.document.getElementById('linkName').value == ''){
					links = top.document.getElementById('linkPfad').value;
					links = linkName = feld.trim(links);
					if(false == expression2.test(links)){
						links = 'mailto:'+links;
					}else{
						linkName = linkName.replace(/^mailto:/,'');	
					}
					new_text = '[a='+links+']'+linkName+'[/a]';
				}else{
					linkName = top.document.getElementById('linkName').value;
					links = top.document.getElementById('linkPfad').value;
					links = feld.trim(links);
					if(false == expression2.test(links)){
						links = 'mailto:'+links;
					}
					new_text = "[a="+links+"]"+linkName+'[/a]';
				}
			}
			new_text = new_text.replace(expression4,'<a style="display:inline;color:#5A5A5A" target="_blank" href="$1">&raquo;Link testen</a>');
			new_text = new_text.replace(expression5,'<a style="display:inline;color:#5A5A5A" class="ohneBild" target="_blank" href="$1">&raquo;Link testen</a>');
			top.document.getElementById('linkPrev').innerHTML = new_text;
		}else{
			top.document.getElementById('linkPrev').innerHTML = '&nbsp;';
		}
	}else{
		top.document.getElementById('linkPrev').innerHTML = '&nbsp;';
	}
}

function updatePreview(){
	if(previewActive && (document.getElementById('formName').value != '') && (document.getElementById('textfeld').value != '')){
		vorschau(false);	
	}
}

function setFrameHeight(){
	top.document.getElementById('inhframe').style.height = document.body.offsetHeight+20+'px';
}

function revealCal(month,year,evt){
	drawCalendar(month,year,true);
	document.getElementById('calendarDiv').style.right = document.body.offsetWidth - evt.clientX + 5 + 'px';
	document.getElementById('calendarDiv').style.top = evt.clientY + 5 + 'px';	
	document.getElementById('calendarDiv').style.display = 'block';
}

function hideCal(){
	document.getElementById('calendarDiv').style.display = 'none';
}
