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); }
});

  }

}



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())
		{
			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(100, 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;padding-right:5px;'>&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 style='width:"+width+"px;height:"+height+"px;' onClick='"+closex+"' src='"+imgsrc+"'>");
			
		}

		$("#"+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();
				}
			}
		}
	}
}


