<html>

<head>
<title>Ilias</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="{LOCATION_STYLESHEET}" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
</head>

<body onLoad="initForm();">

<form method=post name="form">
<br>
{TXT_EXTERNAL_URL}:<br>
<input type="text" size="30" name="externalurl" value="http://www." style="width:100%"><br>
<font size=1>{TXT_EXAMPLE}: <b>http://www.google.de</b> {TXT_OR} <b>http://www.google.de/test/index.html</b></font> 
<p>
{TXT_TITLE}:<br>
<input type="text" size="30" name="externaltitle" value="" style="width:100%">
<p>
<table cellspacing="0" cellpadding="0" width="100%"><tr><td>
	<input type="button" value="{BTN_SUBMIT}" onClick="returnXtlLink();">
</td>

<td align=center>
	<input type="button" value="{BTN_DELETE}" onClick="if(confirm('{DELETE_QUESTION}')) deleteXln();" name="deletelink">
</td>

<td align=right>
	<input type="button" value="{BTN_CLOSE}" onClick="window.close();">
</td></tr></table>

</form>


<script>

var oldUrl = "";
var oldTitle = "";
var oldLink = "";
var xln_sel_text = false;
function initForm()
{

	xln_sel_text = false;
	N ="";
	var ancestors = opener.editor.getAllAncestors();
	for (k=0;k<ancestors.length-1;k++)
	{
		var el = ancestors[k];
		var cl = el.className;
		var tn = el.tagName.toLowerCase();
		
		if (tn=="a" && cl=="ilc_ExtLink") 
		{
			
			var at = el.attributes;
			
			for(i=0;i<at.length;i++) 
			{
				
				if (at[i].name=="url") 
				{
					//N += at[i].name+" "+at[i].value+" ";
					
					oldUrl = at[i].value;
					H = opener.editor.getHTML();
					
					pos1 = H.indexOf("<a url=\""+oldUrl+"\" class=\"ilc_ExtLink\">");
					if (pos1==-1) pos1 = H.indexOf("<a class=\"ilc_ExtLink\" url=\""+oldUrl+"\">");
					L = H.substring(pos1,H.length);
					L = L.substring(0,L.indexOf("</a>")+4);
					oldLink = L;
					var re= /<\S[^>]*>/g; 
					oldTitle = L.replace(re,"");
					
				}
			}
			

		}
		
	}
	
		
		
	if ( opener.editor.hasSelectedText() )
	{
		xln_sel_text = true;
		document.form.externaltitle.value = opener.editor.getSelectedHTML();
		if(oldUrl!="") document.form.externalurl.value = oldUrl;
		if(oldTitle!="") document.form.externaltitle.value = oldTitle;
		
		if(document.form.externaltitle.value=="&nbsp;") document.form.externaltitle.value = "";
		P = document.form.externaltitle.value;
		for(i=0;i<100;i++) {
			P = P.replace("&nbsp;","");
			P = P.replace("<P>","");
			P = P.replace("</P>","");
			P = P.replace("<BR>","");
			P = P.replace("<BR />","");
		}
		var re= /<\S[^>]*>/g; 
		P = P.replace(re,"");

		document.form.externaltitle.value = P;
		document.form.externalurl.focus();
	} else {
		if(oldUrl!="") document.form.externalurl.value = oldUrl;
		if(oldTitle!="") document.form.externaltitle.value = oldTitle;
	}
	
	if(oldTitle=="") {
		
		document.form.deletelink.disabled=true;
	}
	
	window.focus();
}

function returnXtlLink() 
{
	//opener.editor.surroundHTML("[xln url=&quot;"+document.form.externalurl.value+"&quot;]"+document.form.externaltitle.value,"[/xln]");
	
	// alex changed
	//opener.editor.insertHTML("<span class=\"iliasxln\" url=\""+document.form.externalurl.value+"\">"+document.form.externaltitle.value+"</span>");
	A = opener.getClearTags();
	
	if(oldUrl=="") 
	{
	
		if (A[0]=="") 
		{
			opener.editor.insertHTML("<a class=\"ilc_ExtLink\" url=\""+document.form.externalurl.value+"\">"+document.form.externaltitle.value+"</a> ");
			//S = opener.editor.getHTML();
			//opener.editor.setHTML(S+"&nbsp;");
		} 
		else 
		{
			N = "<a class=\"ilc_ExtLink\" url=\""+document.form.externalurl.value+"\">"+document.form.externaltitle.value+"</a>"+"&nbsp;";
			S = opener.editor.getSelectedHTML();
			opener.editor.insertHTML("#!#*#!#");
			H = opener.editor.getHTML();
			H = H.replace("#!#*#!#",A[1]+N+A[0]);
			
			for(k=0;k<20;k++) 
			{
				H = H.replace("<span class=\"ilc_Comment\"></span>","");
				H = H.replace("<span class=\"ilc_Quotation\"></span>","");
				H = H.replace("<span class=\"ilc_Strong\"></span>","");
				H = H.replace("<span class=\"ilc_Emph\"></span>","");
				H = H.replace("<p>","");
				H = H.replace("</p>","<br>");
				H = H.replace("<strong></strong>","");
			}
			
			opener.editor.setHTML(H+"&nbsp;");
			opener.editor.focusEditor();
	
		}
	}
	else 
	{
		N = "<a class=\"ilc_ExtLink\" url=\""+document.form.externalurl.value+"\">"+document.form.externaltitle.value+"</a>"+"&nbsp;";
		S = opener.editor.getHTML();
		S = S.replace(oldLink,N);
		opener.editor.setHTML(S+"&nbsp;");
		opener.editor.focusEditor();
		opener.editor.updateToolbar();
	}
	
	window.close();
}



function deleteXln() {

	N = oldTitle;
	S = opener.editor.getHTML();
	S = S.replace(oldLink,N);
	opener.editor.setHTML(S+"&nbsp;");
	opener.editor.focusEditor();
	opener.editor.updateToolbar();

	window.close();
}


</script>

</body>
</html>