
IE = document.all&&!window.opera;
DOM = document.getElementById&&!IE;

function getBody(){
  return (window.document.compatMode == "CSS1Compat") ?
          window.document.documentElement : window.document.body || null;
}


function show(element) {
        if (document.getElementById) {
            if (document.getElementById(element).style.display == "block") {
                document.getElementById(element).style.display = "none";
            } else {
                document.getElementById(element).style.display = "block";
            }

        }
    }
function show2(element) {
        if (document.getElementById) {
            document.getElementById(element).style.display = "block";
        }
    }

function hide(element) {
        if (document.getElementById) {
                document.getElementById(element).style.display = "none";
        }
    }

function hover(element) {
        if (document.getElementById) {
            if (document.getElementById(element).style.border == "none") {
                document.getElementById(element).style.backgroundColor = "#D7E1E8";
                document.getElementById(element).style.border = "1px solid #005580";
            } else {
                document.getElementById(element).style.backgroundColor = "transparent";
                document.getElementById(element).style.border = "none";
            }
        }
    }

function more (id) {
  if (document.getElementById("span_" + id).style.display == 'none') {
    document.getElementById("img_" + id).src = "gfx/minus.gif";
    document.getElementById("span_" + id).style.display = "block";
  }
  else {
    document.getElementById("img_" + id).src = "gfx/plus.gif";
    document.getElementById("span_" + id).style.display = "none";
  }
}

function insert(aTag, eTag) {
  var input = document.forms['formular'].elements['textarea'];
  var scrollTop = input.scrollTop;
  input.focus();
  /* für Internet Explorer */
  if(typeof document.selection != 'undefined') {
    /* Einfügen des Formatierungscodes */
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = aTag + insText + eTag;
    /* Anpassen der Cursorposition */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -eTag.length);
    } else {
      range.moveStart('character', aTag.length + insText.length + eTag.length);
    }
    range.select();
    input.scrollTop = scrollTop;
  }
  /* für neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Einfügen des Formatierungscodes */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
    /* Anpassen der Cursorposition */
    var pos;
    if (insText.length == 0) {
      pos = start + aTag.length;
    } else {
      pos = start + aTag.length + insText.length + eTag.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
    input.scrollTop = scrollTop;
  }
  /* für die übrigen Browser */
  else
  {
    /* Abfrage der Einfügeposition */
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Einfügen an Position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    /* Einfügen des Formatierungscodes */
    var insText = prompt("Bitte geben Sie den zu formatierenden Text ein:");
    input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);
    input.scrollTop = scrollTop;
  }
}

function openPopUpWindow( side, width, height, top, left, scrolling )
{
        if (side && side != null)
        {
                var parameters = "";
                if ( width != null )
                {
                        parameters += ",width=" + width;
                }
                if ( height != null )
                {
                        parameters += ",height=" + height;
                }
                if ( top != null )
                {
                        parameters += ",top=" + top;
                }
                if ( left != null )
                {
                        parameters += ",left=" + left;
                }
                if ( scrolling == "true" )
                {
                        parameters += ",scrollbars=auto";
                        parameters += ",scrollbars=yes";
                }
                else
                {
                        parameters += ",scrollbars=no";
                }
                var newWindow = window.open( side, "_blank","toolbar=no,status=no,location=no,menubar=no,directories=no,resizable=yes" + parameters );
                newWindow.focus();
        }
        return;
}


function isLinked(img) {
    if(img.nodeName.toUpperCase() != 'IMG') return false;
    var current = img;
    do {
    current = current.parentNode;
    if(current.nodeName == 'A') return true;
    } while(current.nodeName != 'DIV' && current.nodeName != 'BODY');
    return false;
    }

function resizeImages(imageMaxWidth, imageMaxHeight) {
        for (var i = 0; i < document.images.length ;i++){
                if (document.images[i].className == 'resizeImage') {
                        var imageWidth = document.images[i].width;
                        var imageHeight = document.images[i].height;
                        if ((imageMaxWidth != 0 && imageWidth > imageMaxWidth) || (imageMaxHeight != 0 && imageHeight > imageMaxHeight)) {

                                if (imageMaxWidth != 0) var div1 = imageMaxWidth / imageWidth;
                                else var div1 = 1;
                                if (imageMaxHeight != 0) var div2 = imageMaxHeight / imageHeight;
                                else var div2 = 1;

                                if (div1 < div2) {
                                        document.images[i].width = imageMaxWidth;
                                        document.images[i].height = Math.round(imageHeight * div1);
                                }
                                else {
                                        document.images[i].height = imageMaxHeight;
                                        document.images[i].width = Math.round(imageWidth * div2);
                                }
                                if (!isLinked(document.images[i])) {
                                        var popupLink = document.createElement("a");
                                        popupLink.setAttribute('href', document.images[i].src);
                                        popupLink.setAttribute('target', '_blank');
                                        popupLink.appendChild(document.images[i].cloneNode(true));

                                        document.images[i].parentNode.replaceChild(popupLink, document.images[i]);
                                  }
                        }
                }
        }
}


function checkselect(element,value,showelement) {
      if (document.getElementById) {
          if (document.getElementById(element).options[document.getElementById(element).selectedIndex].value == value)
             {
             show2(showelement);
             }
          else
             {
             hide(showelement);
             }
          }
}


function checkmycheckbox(element,active_element)
  {
  anzahlchecked=0;
  amount=document.poll.amount.value;
  anzcheckboxen=document.poll.anz_checkboxen.value;
  for (var j=1; j <= anzcheckboxen ; j++)
    {
    if (document.poll.elements['checkbox_'+j].checked)
      anzahlchecked++;
    }
  if (anzahlchecked > amount)
    {
    alert("Maximal "+amount+" Stimme(n)");
    document.poll.elements['checkbox_'+active_element].checked=false;
    }
  }



function addli(parent) {
  var li = document.createElement("li");
  li.setAttribute("style", "margin-bottom:3px;", 0);
  var input = document.createElement("input");
  input.type="text";
  input.name="choices[]";
  li.appendChild(input);
  document.getElementById(parent).appendChild(li);
}


function killli(parent)
  {
  var li = document.getElementById(parent).lastChild;
  document.getElementById(parent).removeChild(li);
  }
  
wmtt = null;
z=10;
document.onmousemove = updateWMTT;

function updateWMTT(e) {
	x = (document.all) ? window.event.x + getBody().scrollLeft : e.pageX;
	y = (document.all) ? window.event.y + getBody().scrollTop  : e.pageY;
	if (wmtt != null) {
    if (wmtt.style.border != "1px solid blue" && wmtt.style.border != "blue 1px solid")
	   {
		  wmtt.style.left = (x) + "px";
		  wmtt.style.top 	= (y + 25) + "px";
		 }
	}
}

function wait(millis)
    {
    var date = new Date();
    var curDate = null;
    
    do { curDate = new Date(); }
    while(curDate-date < millis);
    } 

function SetOpacity(elem, opacityAsInt)
    {
     var opacityAsDecimal = opacityAsInt;
    
    if (opacityAsInt > 100)
        opacityAsInt = opacityAsDecimal = 100; 
    else if (opacityAsInt < 0)
        opacityAsInt = opacityAsDecimal = 0; 
    
    opacityAsDecimal /= 100;
    if (opacityAsInt < 1)
        opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0
    
    elem.style.opacity = (opacityAsDecimal);
    elem.style.MozOpacity = (opacityAsDecimal);
    elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
    }
    
    

function FadeOpacity(elemId, fromOpacity, toOpacity, time, fps)
    {
    var steps = Math.ceil(fps * (time / 1000));
    var delta = (toOpacity - fromOpacity) / steps;
    
    FadeOpacityStep(elemId, 0, steps, fromOpacity, 
                    delta, (time / steps));
    }

function FadeOpacityStep(elemId, stepNum, steps, fromOpacity, 
                         delta, timePerStep)
    {
    SetOpacity(document.getElementById(elemId), 
               Math.round(parseInt(fromOpacity) + (delta * stepNum)));

    if (stepNum < steps)
        setTimeout("FadeOpacityStep('" + elemId + "', " + (stepNum+1) 
                 + ", " + steps + ", " + fromOpacity + ", "
                 + delta + ", " + timePerStep + ");", 
                   timePerStep);
  }


function showWMTT(id, verz, einblenden) {
  if (verz > 0) wait(verz);
  wmtt = document.getElementById(id);
  wmtt.style.display = "block";
  if (einblenden > 0)
    {
    FadeOpacity(id, 0, 100, einblenden, 30);
    }
	z++;
	wmtt.style.zIndex = z;

  }

function hideWMTT() {
    if (wmtt.style.border != "1px solid blue" && wmtt.style.border != "blue 1px solid")
    { wmtt.style.display = "none"; }
}

function saveWMTT(id)
    {
    wmtt = document.getElementById(id);      
    if (wmtt.style.border != "1px solid blue" && wmtt.style.border != "blue 1px solid")
      { wmtt.style.border = "1px solid blue"; }
    else
      { wmtt.style.border = "1px solid #626262"; wmtt.style.display = "none"; }
    }


function changearrow(id)
    {
    element = document.getElementById(id);
    if (element.style.borderColor == 'red' || element.style.borderColor == 'red red red red')
      { element.src = 'gfx/uarr.gif'; element.style.borderColor='green'; }
    else { element.src = 'gfx/darr.gif'; element.style.borderColor='red';}
    }

function changetype()
    {
    formular = document.getElementById('newpost_form');
    select = document.getElementById('newpost_type');
    for (i = 0; i < select.length; ++i)
      if (select.options[i].selected == true)
      value = select.options[i].value;
      
    var input = document.createElement("input");
    input.type="hidden";
    input.name="type";
    input.value=value;    
    formular.appendChild(input);
    
    var input = document.createElement("input");
    input.type="hidden";
    input.name="type_changed";
    input.value=1;
    formular.appendChild(input);
    
    formular.submit();
    }


function openPopUpWindow( side, width, height, top, left, scrolling )
{
        if (side && side != null)
        {
                var parameters = "";
                if ( width != null )
                {
                        parameters += ",width=" + width;
                }
                if ( height != null )
                {
                        parameters += ",height=" + height;
                }
                if ( top != null )
                {
                        parameters += ",top=" + top;
                }
                if ( left != null )
                {
                        parameters += ",left=" + left;
                }
                if ( scrolling == "true" )
                {
                        parameters += ",scrollbars=auto";
                        parameters += ",scrollbars=yes";
                }
                else
                {
                        parameters += ",scrollbars=no";
                }
                var newWindow = window.open( side, "_blank","toolbar=no,status=no,location=no,menubar=no,directories=no,resizable=yes" + parameters );
                newWindow.focus();
        }
        return;
}

