
/*

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";
}

/* wechselt das bild des linkpanels für das archiv auf der rechten seite */
function switchArchivLink(img) {
    if (img.src.indexOf("video") >= 0) {
        img.src = "grafik/layout/link_archiv.jpg";
    } else {
        img.src = "grafik/layout/link_videoarchiv.jpg";
    }
}

/* 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(url,title,html,parameter)
{
   
    if(lastwindow != null)
        lastwindow.close();
        
	var fenster2 = window.open(url, title, parameter);	
	fenster2.document.write(html);
	fenster2.focus();
	lastwindow = fenster2;
}


/* 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);
	
	today = new Date();
	
	var strDateTime = preZero(today.getDate()) + "." + preZero(today.getMonth()+1) + "." + today.getFullYear() + " - " + preZero(today.getHours()) + ":" + preZero(today.getMinutes()) + " Uhr";
	
	var content = printdiv.innerHTML;
	
	//content = content.replace(/<\/?(script)(.|\n)*?>/gi, "");
	content = content.replace(/<script /gi, "<!--<script");
	content = content.replace(/<\/script>/gi, "</script>-->");
	
	var parameter = "menubar=yes,toolbar=yes,scrollbars=yes,statusbar=no,location=no,resizable=yes,width=" + (printdiv.offsetWidth+60) + "px";
	
	var text = "<div style=\"width:" + printdiv.offsetWidth + "\">";
	text += "<div class=\"printheader\"><img class=\"printlogo\" src=\"grafik/header_druck2.gif\" border=\"0\">";
	text += "<div class=\"statusright\"> www.schellenberg.li, "+strDateTime+"</div></div>";
	text += "<div id=\"printcontent\">" + content + "</div>";
	text += "<div class=\"printfooter\">" + document.URL + "</div>";
	text += "</div>";

	popupAndWrite("", "Druckversion", "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><link href='css/schellenberg.css' rel='stylesheet' type='text/css'></link><link href='css/print.css' rel='stylesheet' type='text/css'></link><style> body {background-color:white;text-align:left; }</style></head><body><form onsubmit='return false;'>" + text + "</form></body></html>", parameter);

}

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();
      } 
}

