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 randomNr(){ return String((new Date()).getTime()).replace(/\D/gi,'') }

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;//randomNr()
    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,
 success: function(htmlcode)
 {
   if($("#"+div_html_id).html() != null)
     $("#"+div_html_id).show();
   else
   {
     
     $(document).ready(function(){
     $('body').append("<div id="+div_html_id+" style='z-index:900000;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); }
});

  }

}

/**
* EasyDrag 1.4 - Drag & Drop jQuery Plug-in
*
* Thanks for the community that is helping the improvement
* of this little piece of code.
*
* For usage instructions please visit http://fromvega.com
*/

(function($){

  // to track if the mouse button is pressed
  var isMouseDown    = false;

  // to track the current element being dragged
  var currentElement = null;

  // callback holders
  var dropCallbacks = {};
  var dragCallbacks = {};

  // global position records
  var lastMouseX;
  var lastMouseY;
  var lastElemTop;
  var lastElemLeft;

  // track element dragStatus
  var dragStatus = {};

  // returns the mouse (cursor) current position
  $.getMousePosition = function(e){
    var posx = 0;
    var posy = 0;

    if (!e) var e = window.event;

    if (e.pageX || e.pageY) {
      posx = e.pageX;
      posy = e.pageY;
    }
    else if (e.clientX || e.clientY) {
      posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
      posy = e.clientY + document.body.scrollTop  + document.documentElement.scrollTop;
    }

    return { 'x': posx, 'y': posy };
  };

  // updates the position of the current element being dragged
  $.updatePosition = function(e) {
    var pos = $.getMousePosition(e);

    var spanX = (pos.x - lastMouseX);
    var spanY = (pos.y - lastMouseY);

    $(currentElement).css("top",  (lastElemTop + spanY));
    $(currentElement).css("left", (lastElemLeft + spanX));
  };

  // when the mouse is moved while the mouse button is pressed
  $(document).mousemove(function(e){
    if(isMouseDown && dragStatus[currentElement.id] == 'on'){
      // update the position and call the registered function
      $.updatePosition(e);
      if(dragCallbacks[currentElement.id] != undefined){
        dragCallbacks[currentElement.id](e, currentElement);
      }

      return false;
    }
  });

  // when the mouse button is released
  $(document).mouseup(function(e){
    if(isMouseDown && dragStatus[currentElement.id] == 'on'){
      isMouseDown = false;
      if(dropCallbacks[currentElement.id] != undefined){
        dropCallbacks[currentElement.id](e, currentElement);
      }

      return false;
    }
  });

  // register the function to be called while an element is being dragged
  $.fn.ondrag = function(callback){
    return this.each(function(){
      dragCallbacks[this.id] = callback;
    });
  };

  // register the function to be called when an element is dropped
  $.fn.ondrop = function(callback){
    return this.each(function(){
      dropCallbacks[this.id] = callback;
    });
  };

  // stop the element dragging feature
  $.fn.dragOff = function(){
    return this.each(function(){
      dragStatus[this.id] = 'off';
    });
  };


  $.fn.dragOn = function(){
    return this.each(function(){
      dragStatus[this.id] = 'on';
    });
  };

  // set an element as draggable - allowBubbling enables/disables event bubbling
  $.fn.easydrag = function(allowBubbling){

    return this.each(function(){

      // if no id is defined assign a unique one
      if(undefined == this.id || !this.id.length) this.id = "easydrag"+(new Date().getTime());

      // set dragStatus
      dragStatus[this.id] = "on";

      // change the mouse pointer
      $(this).css("cursor", "move");

      // when an element receives a mouse press
      $(this).mousedown(function(e){

        // set it as absolute positioned
        $(this).css("position", "absolute");

        // set z-index
        $(this).css("z-index", "10000");

        // update track variables
        isMouseDown    = true;
        currentElement = this;

        // retrieve positioning properties
        var pos    = $.getMousePosition(e);
        lastMouseX = pos.x;
        lastMouseY = pos.y;

        lastElemTop  = this.offsetTop;
        lastElemLeft = this.offsetLeft;

        $.updatePosition(e);

        return allowBubbling ? true : false;
      });
    });
  };

})(jQuery);


var firstClick = false;
var arrPop = new Array();

function divImagePopup(imgsrc, width, height, scroll)
{
	if(width != null && height != null)
  {
		if($.browser.msie && $.browser.version == 6.0)
		{
			htmlPopup(imgsrc, width, height, scroll);
			return;
		}

		div_html_id = "dip"+imgsrc;
		div_html_id = div_html_id.replace(/[^a-zA-Z0-9]/g, "");

		if (height > $(window).height() - 50)
		{
			width = width * 0.75;
			height = height * 0.75;
		}

		var lft= ($(window).width()-width) / 2 + $(document).scrollLeft();
		var st = (($(window).height()-height) / 2.5) + $(document).scrollTop();

		st = parseInt(st);
		lft = parseInt(lft);

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


		div_html_id2 = "dip2"+randomNr();
		closex = "javascript:$(\"#"+div_html_id+"\").fadeOut(300, function() {$(\"#"+div_html_id+"\").remove();} );firstClick=false;$(\"#blocker\").fadeOut(\"fast\");"; //
		if($('#'+div_html_id).html() == null)
		{
			$('body').append("<div id='"+div_html_id+"'>");
			$("#"+div_html_id).attr("style", ""+sc+";top:"+parseInt(st)+"px;left:"+parseInt(lft)+"px;");
			$("#"+div_html_id).attr("class", "popup-image-div");
			$("#"+div_html_id).append("<span onClick='"+closex+"' style='cursor:pointer !important'><b style='color:white;font-size:15px;padding-bottom:2px'>&times;</b></span>");
			$("#"+div_html_id).append("<div id='"+div_html_id2+"'>");
			$("#"+div_html_id2).attr("style", "cursor:pointer !important;width:"+width+"px;height:"+height+"px;");
			$("#"+div_html_id2).append("<img onClick='"+closex+"' src='"+imgsrc+"'>");
			$("#"+div_html_id).easydrag();
		}

		$("#"+div_html_id).fadeIn(300);

		arrPop.push(div_html_id);

		//NUR 1 Popup offen!
		for (x in arrPop)
		{
			if(x != div_html_id && x != "" && div_html_id != "")
			{
				if($('#'+x).html() != null)
				{
					$("#"+x).remove();
				}
			}
		}
	}
}


