
/*

1. SPEZIELL GEMEINDE
    - showDetail (geschichte)
    - hideDetail (geschichte)
    
2. UTILITIES
    - dalert
    - dalert
    - resizeThumbnailCss
    - resizeThumbnail
    - popup
    - popupAndWrite
    - overButton
    - outButton
    - overRow
    - outRow
    - catchEnter

*/



/* SPEZIELL GEMEINDE */

/* this method makes the header smaller if the windowheight is very small */
function fitToWindowHeight() {
    return;
    var docHeight = $(document.body).getSize().y;

    if (docHeight < 800) {

        var div = $('masterheader');
        
        if (div != null) {
            div.id = 'masterheadersmall';
            $('headerimg').src = "grafik/logo_neu_klein.png";
        }
        
    } else {
  
        var div = $('masterheadersmall');
    
        if (div != null) {
            div.id = 'masterheadersmall';
            $('headerimg').src = "grafik/logo_neu_klein.png";
        }
        
    }
    
   initializeMenu();

    if (div != null) {
        return div.getSize().y;
    }

}

/* load's the pulldown-menu at the top */
function initializeMenu() 
{
    var myMenu = new MenuMatic({ matchWidthMode: true, matchWidthOffset: 1, tweakInitial: { x: -1, y: 0 }, tweakSubsequent: { x: 0, y: -1 }, duration: 400, hideDelay: 400, effect: 'slide' });
}

/* if no quicklink-image is found we take the default-image */
function onQuicklinkError(img) {
   img.src = "grafik/quicklinks/Q_Leer.jpg";}

var x = 0;

function loadHits(txt) {
    return;
    x++;

    if (x == 4) {

        var htmlRequest = new Request.HTML({ url: "ajaxservice.aspx?action=search&keywords=" + txt.value + "&d=" + new Date().getMilliseconds(), onComplete: function(responseTree, responseElements, responseHTML, responseJavaScript) {
            var div = new Element('div', { id : 'searchbox' });
            
            // var popup = new mooPopup({ dockelem: txt, peakmode: 'ro', headline: "Detail", width: 365, content: responseHTML, ydelta: -40, xdelta: -4 });

        }
        }).get();

        x = 0;
    }
}


/* UTILITIES */

/* verzögerter alert */
function dalert(msg)
{
    window.setTimeout("alert('" + msg.replace(/\\n/gi,'x') + "');",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", "_on"); 
	}
}

/* change to original button on mouseout */
function outButton(img)
{
	if(img != null)
	{
	    if(new URI(window.location.href).get('query').parseQueryString().mid == img.title)
	        return;

	    img.src = img.src.toLowerCase().replace("_on", "_off");
	}
}

/* highlihts button on mouseover */
function overButtonBack(img) {
    if (img != null) {
        img.style.backgroundImage = img.style.backgroundImage.toLowerCase().replace("_off.gif", "_on.gif"); 
    }
}

/* change to original button on mouseout */
function outButtonBack(img) {
    if (img != null && isOutActive) {
        img.style.backgroundImage = img.style.backgroundImage.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/druckheader_triesen.jpg\" border=\"0\">";
	text += "<div class=\"statusright\"> www.triesen.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/triesen.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();
      } 
}

