
/*

1. SPEZIELL GEMEINDE
    - showDetail (geschichte)
    - hideDetail (geschichte)
    
2. UTILITIES
    - dalert
    - dalert
    - resizeThumbnailCss
    - resizeThumbnail
    - popup
    - popupAndWrite
    - overButton
    - outButton
    - overRow
    - outRow
    - catchEnter

*/


/* SPEZIELL GEMEINDE */

function showDetail(ev, year, id)
{
    var overdiv = $("overdiv");

    if(overdiv != null)
    {
        overdiv.innerHTML = "<table cellpadding=\"0px\" cellspacing=\"0px\"><tr><td valign=top class=\"text_bold\" style=\"padding:7px 7px 0px 0px;text-align:left\">" + year + "</td><td valign=top>" + $('ev' + id).innerHTML + "</td></tr><table>" ;
       
        var x = $('timebar').offsetLeft;
    
        overdiv.style.left = x + "px";
        
        overdiv.style.display = "block";
        
    }
}

function hideDetail()
{
    var overdiv = $("overdiv");
      
    if(overdiv != null)
        overdiv.style.display = "none";
}

/* UTILITIES */

/* verzögerter alert */
function dalert(msg)
{
    window.setTimeout("alert('" + msg + "');",500);
}

/* verzögerter alert mit eigener zeitangabe im millisekunden */
function dalert(msg,ms)
{
    window.setTimeout("alert('" + msg + "');", ms);
}


/* This method resizes thumbnails */
function resizeThumbnailCss(img,horizontalClass,verticalClass){

if(horizontalClass == null ||horizontalClass == "")
    horizontalClass = "horizontalThumb";

if(verticalClass == null || verticalClass == "")
    verticalClass = "verticalThumb";
      
if(img != null){
		if(img.width >= img.height)
			img.className = horizontalClass; 
		else
			img.className = verticalClass;	
	}
}

/* This method resizes thumbnails */
function resizeThumbnail(img,maxWidth,maxHeight){

if(img != null){
		if(maxWidth > 0 && img.width > maxWidth)
			img.width = maxWidth; 
		
		if(maxHeight > 0 && img.height >= maxHeight)
			img.height = maxHeight; 
	}
}


/* popup */

var lastwindow = null;

function popup(url,title)
{

	var fenster2 = window.open(url, title, "left=0,top=0,menubar=0,fullscreen=1,resizable=1,status=1");	
	fenster2.focus();
}

function popupAndWrite()
{
   
    if(lastwindow != null)
        lastwindow.close();
       
       printTipp();

}

function printTipp() {

    var myLayer = document.getElementById('container');

      today = new Date();

      var strDateTime = today.getDate() + "." + (today.getMonth()+1) + "." + today.getFullYear() + ", " + today.toLocaleTimeString() + " Uhr";

      

      var parameter = "menubar=yes,toolbar=yes,scrollbars=yes,statusbar=no,location=no,resizable=yes,width=750px,height=520px";

      var printWin = window.open("","printSpecial_"+replaceAll(replaceAll(replaceAll(replaceAll(strDateTime,".","_"),":","_")," ","_"),",",""),parameter);

      

      var text = "";

      text += "<table width=100%><tr><td class=printheader style=\"padding-bottom:4px;\" valign=bottom><img src=\"./grafik/druckheader.jpg\" width=\"640\"/><br></td><td align=right style=\"font-size:10px;\"></td></table><br>";

      text += myLayer.innerHTML;

      

      printWin.document.open();    

      printWin.document.write("<html><head><link href='./css/print.css' rel='stylesheet' type='text/css'></link></head><style> body {background-color:white;text-align:left;} div {overflow:visible;} .scroll{overflow:visible;} .highlight{color:black;background-color:white;}</style><body><div class='text'><form onsubmit='return false;'>" + text + "</form></div><br><table width=100%><tr><td align=right style=\"font-size:10px;margin-top:0px\">"+strDateTime+", &copy; 2009 <FONT class=titel><SPAN class=text_fett>bkp.li</td></tr></table></body></html>");

      printWin.document.close();

      

      printWin.print();

}

function replaceAll( str, from, to ) {

    var idx = str.indexOf(from);

 

      var i = 0;

    while (idx > -1 && i<100) {

            i++;

        str = str.replace(from, to); 

        idx = str.indexOf(from);

    }

    return str;

}



/* highlighting buttons */

var isOutActive = true;

/* highlihts button on mouseover */
function overButton(img)
{
	if(img != null)
	{
		img.src = img.src.toLowerCase().replace("_off.gif","_on.gif");
	}
}

/* change to original button on mouseout */
function outButton(img)
{
	if(img != null && isOutActive)
	{
		img.src = img.src.toLowerCase().replace("_on.gif","_off.gif");
	}
}

var lastbgcolor;

/* highlights complete row on mouseover */
function overRow(tr)
{
	if(tr != null)
	{
		lastbgcolor = tr.style.backgroundColor;
		tr.style.backgroundColor = '#F0F0F0';
		
		for(var i=0;i<tr.childNodes.length;i++)
		{
			var td = tr.childNodes[i];
			td.style.backgroundColor = '#F0F0F0';
			
		}
	}
}

/* unhighlights complete row on mouseover */
function outRow(tr)
{
	if(tr != null && isOutActive)
	{
		tr.style.backgroundColor = lastbgcolor;
		
		for(var i=0;i<tr.childNodes.length;i++)
		{
			var td = tr.childNodes[i];
			td.style.backgroundColor = "";
		}
	}
}



var gAutoPrint = false; 
var gSpecialPrint = null;

/* print function */
function printscreen(divid)
{

	var printdiv = $(divid);
	
    if(gSpecialPrint != null)
        printdiv = $(gSpecialPrint);
		
	popupAndWrite();

}

function preZero(nr)
{
    if(nr.length == 1)
        return "0" + nr;
        
    return nr;
}

/* if enterkey is pressed than special button will be activated */
function catchEnter(evt,buttonid)
{
      if (evt.keyCode == 13)
      {
		evt.returnValue=false;
        evt.cancel = true;
        var button = $(buttonid);
        if(button != null)
            button.click();
      } 
}

