function newWinOpen(docpath,w,h) {
	win = window.open(docpath, "docwindow", "width=" + w + ", height=" + h + ", status=no, location=yes, resizable=yes, scrollbars=yes");
	win.moveTo(150,150);
}
function ExtractID()
{
	var url = document.location.href;
	var i = url.indexOf("?");
	var s = url.substring(i+1, url.length);
	var w = s.split("&");
	w = w[0].split("=");
	return(w[1]);
}

function popup(aurl, awidth, aheight, aname)
{
	win = window.open(aurl, aname, 'width='+awidth+', height='+aheight +', status=yes,resizable=yes,menubar=no,locationbar=no,scrollbars=yes,dependent=yes,left=00,top=00');
	win.opener = self;
	win.focus();
	return;
}

function printpopup()
{
	popup(document.location.href + "&printit=1", 780,500,"PRINT")
	return
}

var	DebugWin;

function debug(was)
{
	if (!DebugWin)
	{
		if (window.opener == null)
		{
    		    DebugWin = window.open('', 'DEBUG', 'width='+ (screen.width-10) +',height=200,left=0,top=0,status=yes,resizable=yes,scrollbars=yes');
		    DebugWin.document.open();
		    DebugWin.document.writeln('<HTML>');
		    DebugWin.document.writeln('<HEAD>');
		    DebugWin.document.writeln('<TITLE>DEBUG</TITLE>');
		    DebugWin.document.writeln('<link rel="stylesheet" href="/css/cont.css">');

//		    DebugWin.document.writeln('<script language="JavaScript1.2" src="/js/popup.js"></script>');
		    DebugWin.document.writeln('<script language="JavaScript1.2" src="/js/md5.js"></script>');
		    DebugWin.document.writeln('<META HTTP-EQUIV="Expires" CONTENT="0">');
		    DebugWin.document.writeln('<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">');

		    DebugWin.document.writeln('</HEAD><BODY bgcolor=#A5BBD1>');
		    DebugWin.document.writeln('</BODY></HTML>');
		    DebugWin.document.close();

		}
		else
		    DebugWin = window.opener;
	}
	DebugWin.document.body.innerHTML = DebugWin.document.body.innerHTML + was;
}

function EditHtmlText(FELDNAME, FELDTYP)
{
	EDITORTEXT   = document.getElementById(FELDNAME)
	EDITORTEXT_A = document.getElementById(FELDNAME+'_'+FELDTYP)
	if (FELDTYP == '') FELDTYP = 'INPUT'
	EDITORTYPE = FELDTYP
	EDITORTITLE = FELDNAME


	var ie4=document.all; //&&navigator.userAgent.indexOf("Opera")==-1
	var ns6=document.getElementById&&!document.all
	var ns4=document.layers

	var dwidth = screen.width-150
	var dheight= screen.height-150

//	window.open('/xul/test.xul', 'test', 'status=no,location=no,resizeable=yes');
//	popup('/xul/test.xul', 800, 600, 'POPUPEDITOR');
	popup('htedit.htm', 800, 600, 'POPUPEDITOR');
	// if (!document.all) popup('htedit.htm', 800, 600, 'POPUPEDITOR');
	// else
	// popup('index.php?cSID='+ExtractID()+'&action=ShowPage&which=admin/editor_popup&param=notemplate', dwidth, dheight, 'POPUPEDITOR')
}


// Soll Dateinamen aus Workspace "files" zurueckliefern
function SetFileText(A)
{
	FILETEXT.value = A;	
}

function EditFileText(FELDNAME)
{
	FILETEXT   = document.getElementById(FELDNAME);
	SETFUNC = SetFileText;
	popup('file.php?cSID='+ExtractID()+'&dir=dateien/&'+'val='+FILETEXT.value, 850, 600, 'FILEPOPUP');
}


function DHTML_SetImage(A)
{
	RunCom("InsertImage", A);
}
function DHTML_GetImage()
{
	SETFUNC = DHTML_SetImage;
	popup('file.php?cSID='+ExtractID()+'&dir=dateien/bilder/&'+'val=', 850, 600, 'FILEPOPUP');
}


function DHTML_SetFileLink(A)
{
//	mytext.document.execCommand("CreateLink","",A)
//	RunCom("CreateLink", A, "TESTLINK")

//	var isA = getEl("A", mytext.document.selection.createRange().parentElement());
  
//	if (isA != null)
	{
		if (mytext.document.selection.type == "None")
		{
			var sel=mytext.document.selection.createRange();
			sel.pasteHTML("<A HREF=\""+str+"\">"+str+"</A> ");
			sel.select();
		}
		else 
		//If user had selected/blocked the string  just pass this command.
		
		var txt = prompt("Eingabe Linkbezeichnung:", isA ? isA.href : "http:\/\/");
		RunCom("CreateLink",str,txt);
	}
//	else 
	//If nothing entered just Focust in our IFRAME.
	mytext.focus();
}
function DHTML_GetFileLink()
{
	SETFUNC = DHTML_SetFileLink;
	popup('file.php?cSID='+ExtractID()+'&dir=dateien/&'+'val=', 850, 600, 'FILEPOPUP');
}

//-------------------------------------------------------------------;
function getEl(sTag,start)
{
	while ((start!=null) && (start.tagName!=sTag))
	{
		start = start.parentElement;
	}
	return start;
}

function DHTML_EditLink()
{
	var isA = getEl("A",mytext.document.selection.createRange().parentElement());

	LINKTEXT = isA ? isA.innerHTML : '';
	LINKZIEL = isA ? isA : '';
	popup('pages/admin/link_popup.htm', 850, 600, 'FILEPOPUP');
}



