var c_el = new Array();
function change(id)
{
  c_el[id] = getE(id);
  if (c_el[id] != null && c_el[id] != '')
  {
    if(c_el[id].style.display == "none" || c_el[id].style.display == "") //|| c_el[id].style.display == ""
      c_el[id].style.display = "block"; //block nicht, damit es in tabellen geht!
    else
      c_el[id].style.display = "none";
  }
}

function show(id)
{
  c_el[id] = getE(id);
  if (c_el[id] != null && c_el[id] != '')
    c_el[id].style.display = "block"; //block nicht, damit es in tabellen geht!
}
function hide(id)
{
  c_el[id] = getE(id);
  if (c_el[id] != null && c_el[id] != '')
    c_el[id].style.display = "none";
}



function popup(loc, width, height, scroll)
{
  if(width != null && height != null && scroll != null)
  {  
    lft=(screen.availWidth)?(screen.availWidth-width)/2:100;
    tp=(screen.availHeight)?(screen.availHeight-height)/2:100;
    
    p = window.open(loc,'popup','toolbar=no,width='+width+',height='+height+',screenX='+lft+',screenY='+tp+',left='+lft+',top='+tp+',scrollbars='+scroll+',resizable=yes,status=no,menubar=no,directories=no,location=no,dependent=no');
    p.focus();
  }
}


function htmlPopup(imageloc, width, height, scroll)
{
  if(width != null && height != null && scroll != null)
  {  
    lft=(screen.availWidth)?(screen.availWidth-width)/2:100;
    tp=(screen.availHeight)?(screen.availHeight-height)/2:100;
    HTML = "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>\n<html><head><meta http-equiv='content-type' content='text/html; charset=UTF-8'><style>body, html{margin:0px;padding:0px;background-color:#FFFFFF;}</style></head><body><img src='"+ imageloc +"'/><br/></body></html>";
 

    if(typeof(popupImage) != "undefined" && popupImage != null)
      popupImage.close();

    randomnumber=1;//Math.floor(Math.random()*11); 
    popupImage = window.open("",'htmlpopup'+randomnumber,'width='+width+',height='+height+',screenX='+lft+',screenY='+tp+',left='+lft+',top='+tp+',toolbar=no,scrollbars='+scroll+',resizable=yes,status=no,menubar=no,directories=no,location=no,dependent=no');
    popupImage.document.open();
    popupImage.document.write(HTML);
    popupImage.document.close();
    popupImage.focus();
  }
}

//Text-Counter JS
function textCounter(field, cntfield, maxlimit) 
{
  if(field != null && cntfield != null)
  {
  if (field.value.length > maxlimit) 
    field.value = field.value.substring(0, maxlimit);
  else 
    cntfield.innerHTML = maxlimit - field.value.length;
  }
}


function toggler(showid, elementstr)
{
  for (i = 0; i < 200; i++)
  { 
    if(getE(elementstr+i))
    {
      if(elementstr+i == elementstr+showid)
      { 
        if(getE(elementstr+i).style.display == "block")
          getE(elementstr+i).style.display = "none";
        else
          getE(elementstr+i).style.display = "block";
      } 
      else
        getE(elementstr+i).style.display = "none";
    }
  }
}

//Usage: <a href="javascript:void(0)" onClick="boldize(this);">bold</a>
function boldize(obj)
{
	if(obj.style.fontWeight == '' || obj.style.fontWeight == 'normal' )
	  obj.style.fontWeight = "bold";
  else
	  obj.style.fontWeight = "normal";
}

//TOOL: leading zeros
function LZ(x) {return(x<0||x>9?"":"0")+x} 

//TOOL: getElementById
function getE(myel_id){if(document.getElementById(myel_id) != null && document.getElementById(myel_id) != '' && document.getElementById(myel_id) != 'undefined') return document.getElementById(myel_id);}


//Content des Popups darf kein <body> <html> etc. enthalten!
function divPopup(loc, width, height, scroll, div_html_id)
{
  if(width != null && height != null)
  {  
    lft=(screen.availWidth)?(screen.availWidth-width)/2.5:100;
    tp=(screen.availHeight)?(screen.availHeight-height)/2.5:100;

    if(scroll == "yes") sc = "overflow-y:scroll;overflow-x:hidden";
    else sc = "overflow:hidden";

$.ajax({
 type: "POST",
 dataType: "html",
 url: loc,
 data: "",
 success: function(htmlcode)
 {
   if($("#"+div_html_id).html() != null)
     $("#"+div_html_id).show();
   else
     $('body').append("<div id="+div_html_id+" style='width:"+width+"px;height:"+height+"px;"+sc+";background:white;position:absolute;top:"+parseInt(tp)+"px;left:"+parseInt(lft)+"px;' class='popup-div'><div class='popup-div-close'><a href='javascript:;' onClick='$(\"#"+div_html_id+"\").fadeOut();'><b>x</b></a></div><div class='popup-div-inner'>"+htmlcode+"</div></div>");                 
 },
 error: function(msg) { alert("Error: " + msg); }
});

  }

}

