/* (c) copyright, Peter Russ, 4D f/x, 2004 This software may only be used with
    written permission by peter.russ@4dfx.de To use this software get your quote!
    This software may not be used, altered, printed in any form without written permission
    by peter.russ@4dfx.de
    (c) copyright, 2004 by 4D f/x Kommunikationsservice, info@4dfx.de */
//fdfx_atagReplacer.js
var selectedElement;
var stopDrag;
var dragElementArray=new Array();
// Problem des Explorers mit iframes bei ssl!!!
var MIST=document.all && (location.protocol=='https:');
/*  Preset the CSS */
if (parent.fdfd_css && parent.fdfd_css!="")
{
	for (var i=0; i<parent.fdfd_css.length; i++)
    {
    	if (parent.fdfd_css[i]!="")
        {
			document.writeln('<link rel="stylesheet" href="'+parent.fdfd_css[i]+'">');
        }
    }
}
function findDraggableElement (target)
{
	if (document.getElementById && target!=null)
    {
	    do
        {
	    	if (target.className == 'draggableElement')
            {
            	return target;
            }
        } while ((target = target.parentNode));
	}
	return null;
}
function bringToFront(t)
{
	if (!dragElementArray[t.id])
    {
    	dragElementArray[t.id]=(t.style.zIndex)?t.style.zIndex:1;
        dragElementArray.length++;
    }
    for (var sel in dragElementArray)
    {
    	if (sel!=t.id)
        {
        	document.getElementById(sel).style.zIndex=dragElementArray[sel];
        }
    }
    t.style.zIndex=999;
}
function checkSelection (evt)
{
     if (document.all && selectedElement==null)
     {
     	selectedElement = findDraggableElement (this);
     } else if (document.getElementById) {
     	selectedElement = findDraggableElement (evt.target);
     }
     if (selectedElement)
     {
     	bringToFront(selectedElement);
     	document.onmousemove = dragDom;
        document.onmouseup = stopDragDom;
     }
}
/**********************************************
    DRAG AND DROP DOM i.e. Mozilla
**********************************************/
function dragDom (evt)
{
	if (selectedElement)
    {
    	var e=(document.all)?event:evt;
        var w=selectedElement.scrollWidth/2;
        var h=selectedElement.scrollHeight;
	selectedElement.style.left = e.clientX-w + 'px';
	selectedElement.style.top = e.clientY-h+ 'px';
        return false;
    }
    return true;
}
function stopDragDom (evt)
{
	document.onmousemove = null;
	document.onMouseup = null;
	selectedElement = null;
}
/**********************************************
    POP-UP Handling
**********************************************/
function close(id)
{
	document.getElementById(id).style.visibility="hidden";
}
function printMe(id)
{
    var doc=document.getElementById(id);
    var pos1=doc.src.lastIndexOf('/')+1;
    var pos2=doc.src.lastIndexOf('.html');
    var url="";
    if (pos2>pos1)
    {
    	url=doc.src.substr(0,pos1);
    	id=doc.src.substr(pos1,pos2-pos1);
    } else {
    	url=doc.src;
    	id=1;
    }
    doc.src=url+"index.php?type=98&id="+id;
}
function addIframe (id,header,width,height)
{
	if (document.getElementById)
    {
        var div=document.createElement('div');
        div.id="div"+id;
        div.className="draggableElement";
		var iframe=(MIST)? "":
        	'<iframe id="'+id+'" width="'+width+'" src="about:blank" height="'+height+'" border="0" frameborder="0"></iframe>';
		div.innerHTML=
        	'<table class="popup" border="0" cellspacing="0" cellpadding="0">'
            +'<tr><td class="fdfx_pl1-1"></td><td class="fdfx_pl1-2" colspan="2">'
            +'<a href="javascript:printMe(\''+id+'\')" class="img" style="z-index:1000">'
            +'<img src="fileadmin/img/icon.print.gif" width="25" height="23" border="0" alt="Drucken">'
            +'</a></td><td class="fdfx_pl1-3"></td></tr>'
            +'<tr><td class="fdfx_pl2-1"></td><td colspan="2">'+iframe+'</td><td class="fdfx_pl2-3"></td></tr>'
            +'<tr><td class="fdfx_pl3-1"></td><td class="fdfx_pl3-2" colspan="2"></td><td class="fdfx_pl3-3"></td></tr>'
            +'<tr><td></td><td class="popupHeader">'
            +header+'</td><td class="popupHeader" style="text-align:right;"><a href="javascript:close(\''
            +div.id+'\');" title="schliessen" class="img" style="z-index:1000;">&nbsp;X&nbsp;</a></td><td></td></tr>'
            +'</table>';
        document.body.appendChild(div);
        this.div=document.getElementById(div.id);
        this.div.onmousedown = checkSelection;
	this.div.onMouseup = stopDrag;
        var ifr=document.getElementById(id);
  	}
    return ifr;
}
function showPopup(src)
{
	src += (src.lastIndexOf('?')>0)? "&popup=1":"?popup=1";
	this.popUp.src=src;
	bringToFront(this.div);
	this.div.style.visibility="visible";
}
function fdfx_PopUp(header,width,height)
{
	if (document.getElementById)
    {
	this.width=width;
	this.height=height;
	this.top=0;
	this.left=0;
	this.displayed=false;
	this.addPopUp=addIframe;
	var d=new Date();
	this.id="fdfxPU"+d.getTime()+""+parseInt(Math.random()*10000);
	this.popUp=this.addPopUp(this.id,header,this.width,this.height);
	this.showPopup=showPopup;
    }
}
function fdfx_aTagReplacer(oldTarget,newTarget)
{
	if (document.getElementById)
    {
	this.oldTarget=oldTarget;
	this.newTarget=newTarget;
	var aTags=document.getElementsByTagName("a");
	for (i=0;i<aTags.length;i++)
	    {
		var a=aTags[i];
		if (a.target==this.oldTarget)
	        {
		    if (!MIST)
                {
			a.href="Javascript:"+newTarget+".showPopup('"+escape(a.href)+"');";
                }
		    a.target="_self";
	    }
	}
    }
}