
var XMLHttpRequestObject = false; 
var xmlVomPHP;

if (window.XMLHttpRequest) {
   XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
   XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}
function getDataHTML(data,docobj,pfad) {
   if(XMLHttpRequestObject) {
      XMLHttpRequestObject.open("POST", pfad); 
      XMLHttpRequestObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      XMLHttpRequestObject.onreadystatechange = function() {
      if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
	 document.getElementById(docobj).innerHTML='';
	 document.getElementById(docobj).innerHTML=XMLHttpRequestObject.responseText;
      } 
     }
     XMLHttpRequestObject.send(data); 
  }
}
var h=0;
var h1=0;
var _startX = 0;            // mouse starting positions
var _startY = 0;
var _offsetX = 0;           // current element offset
var _offsetY = 0;
var _dragElement;           // needs to be passed from OnMouseDown to OnMouseMove
var _oldZIndex = 0;

InitDragDrop();

function InitDragDrop()
{
    document.onmousedown = OnMouseDown;
    document.onmouseup = OnMouseUp;
}
function OnMouseDown(e)
{
    // IE is retarded and doesn't pass the event object
    if (e == null) 
       e = window.event; 
    // IE uses srcElement, others use target
       var target = e.target != null ? e.target : e.srcElement;
   /*  darsteullung der debug infos 
       _debug.innerHTML = target.className == 'drag' 
             ? 'draggable element clicked' 
            : 'NON-draggable element clicked';
          */
     // for IE, left click == 1
       // for Firefox, left click == 0
          if ((e.button == 1 && window.event != null || 
               e.button == 0) && 
              target.className == 'drag')
                {
          // grab the mouse position
               _startX = e.clientX;
               _startY = e.clientY;
          // grab the clicked element's position
               _offsetX = ExtractNumber(target.style.left);
               _offsetY = ExtractNumber(target.style.top);
          // bring the clicked element to the front while it is being dragged
               _oldZIndex = target.style.zIndex;
               target.style.zIndex = 10000;
          // we need to access the element in OnMouseMove
               _dragElement = target;
          // tell our code to start moving the element with the mouse
               document.onmousemove = OnMouseMove;
          // cancel out any text selections
               document.body.focus();
          // prevent text selection in IE
               document.onselectstart = function () { return false; };
          // prevent IE from trying to drag an image
               target.ondragstart = function() { return false; };
          // prevent text selection (except IE)
               return false;
               }
}

function ExtractNumber(value)  {
  var n = parseInt(value);
    return n == null || isNaN(n) ? 0 : n;
}

function OnMouseMove(e)	{
    if (e == null) 
       var e = window.event; 
    // this is the actual "drag code"
    /*if ((_offsetX + e.screenX - _startX) <-30) {
    	 _dragElement.style.left = -30 + 'px';
     }else {*/
        _dragElement.style.left = (_offsetX + e.clientX - _startX) + 'px';
    /* }

     if ((_offsetY + e.screenY - _startY) <-65) {
   	_dragElement.style.top = -65 + 'px';
     }else {*/
        _dragElement.style.top = (_offsetY + e.clientY - _startY) + 'px';
    // }
    /*_debug.innerHTML = '(' + _dragElement.style.left + ', ' + 
      _dragElement.style.top + ')';   */
}

function OnMouseUp(e) {
   if (_dragElement != null) {
       _dragElement.style.zIndex = _oldZIndex;
   // we're done with these events until the next OnMouseDown
       document.onmousemove = null;
       document.onselectstart = null;
       _dragElement.ondragstart = null;
   // this is how we know we're not dragging      
       _dragElement = null;
       // _debug.innerHTML = 'mouse up';
    }
    h1=parseInt(document.getElementById("preview_div").style.top) ;
}

/*
function init() {
   testDiv = (document.layers) ? document.preview_div : (document.all) ? window.preview_div : document.getElementById("preview_div");
   if (testDiv.captureEvents) { 
      testDiv.captureEvents(Event.MOUSEDOWN);
      document.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
   }
   testDiv.onmousedown = mdown;
   document.onmouseup = mup;
   document.onmousemove = mmove;
}*/
/*
function mdown(e){
  drag = "aktiv";
  aktivX = (e) ? e.pageX : event.clientX + document.body.scrollLeft;
  aktivY = (e) ? e.pageY : event.clientY + document.body.scrollTop;
  if (document.layers) {
     temp1=parseInt(testDiv.left);
     temp2=parseInt(testDiv.top);
  }else {
     temp1=parseInt(testDiv.style.left);
     temp2=parseInt(testDiv.style.top);
  }
  return false;
}*/
/*
function mmove(e){
  if ( drag == "aktiv"){
    var neuX = (e) ? e.pageX : event.clientX + document.body.scrollLeft;
    var neuY = (e) ? e.pageY : event.clientY + document.body.scrollTop;
    var distX = (neuX-aktivX);
    var distY = (neuY-aktivY);
      if (document.layers) {
	 oldX=parseInt(testDiv.left);
	 oldY=parseInt(testDiv.top);
	 testDiv.left = temp1+distX;
	 testDiv.top = temp2+distY;
	 newX=parseInt(testDiv.left);
	 newY=parseInt(testDiv.top);
      }else {
 	 oldX=parseInt(testDiv.style.left);
	 oldY=parseInt(testDiv.style.top);
	 testDiv.style.left = temp1+distX;
	 testDiv.style.top = temp2+distY;
	 newX=parseInt(testDiv.style.left);
	 newY=parseInt(testDiv.style.top);
      }
    breite = (document.layers) ? window.innerWidth  :  document.body.offsetWidth ;
    hoehe =  (document.layers) ? window.innerHeight  :  document.body.offsetHeight ;
    korektur= (document.all) ? 32 : 0 ;
    if (newX > oldX ) direction="dn"; else direction="up";
    if (newY > oldY ) direction1="dnn"; else direction1="upp";
    if (newX < 2 && direction=="up") {
       direction="dn";
       if (document.layers) {
          testDiv.left = 2;
       }else {
	  testDiv.style.left =2;
       }
    }
    if (newY < 2 && direction1=="upp") {
       direction1="dnn";
       if (document.layers) {
          testDiv.top = 2;
       }else {
	  testDiv.style.top =2;
       }
    }
    if ((newX+parseInt(testDiv.style.width)+24) > breite  && direction=="dn") {
       direction="up";
       if (document.layers) {
	  testDiv.left = breite-24-parseInt(testDiv.style.width);
       } else {
          testDiv.style.left =breite-24-parseInt(testDiv.style.width);
       }
    }
    if (newY > (hoehe-parseInt(testDiv.style.height)- korektur)  && direction1=="dnn") {
       direction1="upp";
       if (document.layers) {
          testDiv.top = (hoehe-parseInt(testDiv.style.height)- korektur) ;
       } else {
          testDiv.style.top =(hoehe-parseInt(testDiv.style.height)- korektur) ;
       }
    }
  }
}
function mup(e){
  drag = "inaktiv";
  h1=parseInt(document.getElementById("preview_div").style.top) ;
}
*/
function anzeigen() {
  VorschauDyn(document.forms[0]);
 
  document.getElementById("preview_div").style.width =b2;
  document.getElementById("preview_div").style.height=h2;
  document.getElementById("preview_div").style.backgroundColor="#afafaf";
  document.getElementById("if").width=b2;
  document.getElementById("if").height=h2;
  
  document.getElementById("preview_div").style.display="block";
  document.getElementById("preview_div").style.visibility="visible";
  document.getElementById("if").style.display="block";
  document.getElementById("if").style.visibility="visible";
  getDataHTML("","if",link2);
//  document.getElementById("Frame").src=link2;
  window.onscroll = scrollen;

  //init();
}

function schliessen() {
  document.getElementById("preview_div").style.visibility="hidden";
  document.getElementById("preview_div").style.display="none";
}
function scrollen() {
  if (document.getElementById("preview_div")) {
     h=parseInt(document.body.scrollTop);
     document.getElementById("preview_div").style.top = h+h1;
  }
}
