var selectedObj;

function setSelectedElem(evt)
{
  if (window.event.srcElement == document.getElementById("scala").style)
    selectedObj = window.event.srcElement.style;
  else
    selectedObj = null;
  return;
}

function engage(evt)
{
  setSelectedElem(evt);
  if (selectedObj)
  {
    offsetX = window.event.offsetX;
    offsetY = window.event.offsetY;
    return false;
  }
  else
    return true;
}

function dragIt(evt)
{
  if (selectedObj)
  {
    x = window.event.clientX - offsetX;
    y = window.event.clientY - offsetY;

    if      (x < 0  )  x  = -1;
    else if (x > 600 - document.forms[2].elements[0].value)  x  = 600 - document.forms[2].elements[0].value-1;

    if      (y < 0  )  y  = -1;
    else if (y > 450 - document.forms[2].elements[1].value ) y  = 450 - document.forms[2].elements[1].value-1;

    document.getElementById("scala").style.pixelTop  = y;
    document.getElementById("scala").style.pixelLeft = x;

    document.forms[0].elements[0].value = x;
    document.forms[0].elements[1].value = y;


    return false;
  }
}

function release(evt)
{
  if (selectedObj)
    selectedObj = null;
}

function init()
{
  if (document.getElementById("scala"))
  {
    document.getElementById("scala").style.posLeft = 0;
    document.getElementById("scala").style.posTop  = 0;

    document.onmousedown = engage;
    document.onmousemove = dragIt;
    document.onmouseup   = release;

    document.forms['scala'].elements['width'].value  = 200;
    document.forms['scala'].elements['height'].value = 200;
  }
  if(document.getElementById("edit")) {
    Start();
  }
}

function showmenu(nr)
{
  if (document.getElementById('menu'+nr).style.display == 'none')
  {
    document.getElementById('menu'+nr).style.display = 'block';
  }
  else
  {
    hidelayer("editPage"+nr);
    document.getElementById('menu'+nr).style.display='none';
  }
}

function showlayer(id) {
  if(document.getElementById(id)) {
    document.getElementById(id).style.display = 'block';
  }
}
function hidelayer(id) {
  if(document.getElementById(id)) {
    document.getElementById(id).style.display = 'none';
  }
}


///////////////////////////////////////////////////////////////////////////

function showpicture (path, width, height) {

  if(path != undefined && path != "" && width != "0" && height != "0") {

    var win = window.open(path,"Galerie","toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+width+",height="+(parseInt(height)+50));
    xpos = (screen.width/2)-(width/2);
    ypos = (screen.height/2)-(height/2);
    win.moveTo(xpos,ypos)
    win.focus();
  }
}

/////////////////////////////////////////////////////////////////////////////
function ShowPic(aSrc, aWidth, aHeight, aTitle, aText)
{ picwin=window.open("","PicWindow","width="+aWidth+",height="+aHeight+",menubar=no,locationbar=no,resizable=yes,status=no,scrollbars=yes");
  with (picwin.document)
  { open();
    writeln("<html><head><title>"+aTitle+"</title>");
    writeln("<style type='text/css'>a {text-decoration:none;font-weight:bold;color:#000000;background-color:#C0C0C0}</style>");
    writeln("</head><body leftmargin='0' topmargin='0'>");
    writeln("<table cellpadding=0 cellspacing=0>");
    writeln("<tr><td colspan='2' style='padding-bottom:10'><img src='Homepageverbesserung/index_neu_vorschlag_02/%22+aSrc+%22'></td></tr>");
    writeln("<tr><td align='left' valign='bottom'>"+aText+"</td>");
    writeln("<td align='right' valign='bottom'><a href='#' onclick='self.close()'>Schließen</a></td></tr></table>");
    writeln("</body></html>");
    close();
  }
}


function showprint (path)
{
  if(path != undefined && path != "")
  {
    var win = window.open(path,"Druckansicht","dependent=yes,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=750,height=550");
    win.focus();
  }
}
///////////////////////////////////////////////////////////////////////////////

    function show_field()
    {
      document.getElementById("kontodaten").style.display = "block";
    }

    function hide_field()
    {
      document.getElementById("kontodaten").style.display = "none";
    }