var isload = 0;
var lang = "de";

var SaveWindowWidth  = "";
var SaveWindowHeight = "";

var onload_extras = 0;
var init_ticker = 0;
var onresize_extras = 0;

var Toolbar = "";
var Infobox = "";
var InfoboxContent = "";

var active_infos = ""; 
var active_toolbar = ""; 

var ZusatzinfosDiv = "";
var ZusatzinfosKategorienDiv = "";

var loadMouseMoveControl = true;

var macie = -1;
if (navigator.appVersion.indexOf("MSIE") > -1 && navigator.appVersion.indexOf("Macintosh") > -1) macie = 1;


function formatValues(string) {
	var query = /(\w.+)_(\w.+)/;
	if (query.exec(string)) {
		string = RegExp.$1 + " " + RegExp.$2;
	}
	return "   " + string + "\n";;
}

// ------------------  Anfang Fensterfunktionen siehe auch windowObject.js

function getWindowXpos() {
	if (window.screenLeft) return window.screenLeft;
	else if (window.screenX ) return window.screenX;
}
function getWindowYpos() {
	if (window.screenTop) return window.screenTop;
	else if (window.screenY ) return window.screenY;
}
function getWindowWidth(innerouter) {
	if (!innerouter) return getWindowInnerWidth();
	else if (innerouter == "outer")  return getWindowOuterWidth();
	else if (innerouter == "inner")  return getWindowInnerWidth();
}
function getWindowHeight(innerouter) {
	if (!innerouter) return getWindowInnerHeight();
	else if (innerouter == "outer") return getWindowOuterHeight();
	else if (innerouter == "inner") return getWindowInnerHeight();
}

function getWindowOuterWidth() {
	if (window.outerWidth) return window.outerWidth;
	else if (document.body && document.body.offsetWidth) return document.body.offsetWidth;
	else return 0;
}

function getWindowOuterHeight() {
	if (window.outerHeight) return window.outerHeight;
	else if (document.body && document.body.offsetHeight) return document.body.offsetHeight;
	else return 0;
}

function getWindowInnerWidth() {
	if (window.innerWidth) return window.innerWidth;
	else if (document.body && document.body.clientWidth) return document.body.clientWidth;
	else return 0;
}

function getWindowInnerHeight() {
	if (window.innerHeight) return window.innerHeight;
	else if (document.body && document.body.clientHeight) return document.body.clientHeight;
	else return 0;
}



function openWin(which,width,height) {
	var X = getWindowXpos();
	var Y = getWindowYpos();
	var offsetX = offsetY = 10;
	
	var t = window.open(which,'PopUp','width='+ width +',height='+ height +',screenX='+ parseInt(X+offsetX) +', left='+ parseInt(X+offsetX) +', screenY='+ parseInt(Y+offsetY) +', top='+ parseInt(Y+offsetY) +', scrollbars=1, resizable=1, toolbar=1, location=0, status=1');
	t.focus();
	return void(t);
}
function openPureWin(which,width,height) {
	var X = getWindowXpos();
	var Y = getWindowYpos();
	var offsetX = offsetY = 10;

	var t = window.open(which,'PopUp','width='+ width +',height='+ height +',screenX='+ parseInt(X+offsetX) +', left='+ parseInt(X+offsetX) +', screenY='+ parseInt(Y+offsetY) +', top='+ parseInt(Y+offsetY) +', scrollbars=0, resizable=0, toolbar=0, location=0, status=0');
	t.focus();
	return void(t);
}
// ------------------ Ende Fensterfunktionen


function hideLinkBorder(which) {
	if (!document.layers) {
		if (which.blur()) { which.blur(); }
	}
}

function setBookmark(url,titel) {
	if(navigator.userAgent.indexOf('MSIE') > 0) {
		window.external.AddFavorite(url, "Suedtirol.de - Ihr Tourismusportal für Südtirol." + titel);
	}
	else {
		if (lang == "de") { alert('Die verwendete Technik wird von Ihrem Browser ...\n     '+ navigator.userAgent +'\nNICHT unterstützt!\n\nSie können alternativ die Tastenkombination [Strg] + [D] ausprobieren!'); }
		else { alert('This method ist not supported by your browser:\n\n      '+ navigator.userAgent + '\n\n Please try the alternate key-combination [Strg] + [D]. '); }
	}
}

// ----------------------- start infolayer zur anzeige der navigationserklaerungen

var infolayer = "";
function showInfos(id) {
	if (isload) {
		InfoboxContent.paste();
		Infobox.paste();
		Infobox.setZindex(999);
		infolayer = eval('info_'+id);
		infolayer.paste();
//		InfoboxContent.rewrite(infos[id]);
		mousemoveObject(Infobox);
		fadeIn(Infobox);
	}	
}
function hideInfos() {
	if (isload) {
		if (infolayer) infolayer.cut();
		Infobox.cut();
		InfoboxContent.cut();
		Infobox.setPos(-1000,-1000);
		mmObj = false;
	}
}
function showToolbarInfos(id) {
	if (isload) showInfos(id);	
}

var mmObj = false;
function mousemoveObject(which) {
	mmObj = which;
}

var fadeInCounter = 10;
var fadeHandler = false;

function fadeIn(obj) {
//	if (!obj) return;

	saveObj = obj;
	
	if (fadeInCounter < 95) {
		fadeInCounter+=5;
		saveObj.setOpacity(fadeInCounter);
		fadeHandler = setTimeout("fadeIn(saveObj);",20);
	}
	else {
		clearTimeout(fadeHandler);
		fadeInCounter = 10;
	}
}

// ----------------------- start kleine helferlein fuer die Toolbarsuche

function searchAllByValue(searchvalue) {
	if (searchvalue) {
		document.forms['ToolbarSearch'].query.value = searchvalue;
		document.forms['ToolbarSearch'].submit();
	}
}


var oldquery = "";
var basequery = "Allgemeine Suche";
function checkQueryField() {
	if (document.forms['ToolbarSearch'].query.value == "") {
		document.forms['ToolbarSearch'].query.value = basequery;
	}
	else {
		oldquery = document.forms['ToolbarSearch'].query.value;
	}
	if (oldquery != '') {
		document.forms['ToolbarSearch'].query.value = oldquery;
	}
}

function clearQueryField() {
	if (document.forms['ToolbarSearch'].query.value == basequery) {
		document.forms['ToolbarSearch'].query.value = '';
	}
}

// ----------------------- ende kleine helferlein fuer die Toolbarsuche


function scrollToTop() {
	var y=0;
	if (document.body && document.body.scrollTop) { y=document.body.scrollTop; }
	else { window.scrollTo(0,0); }
	while(y > 0) {
		setTimeout("window.scrollBy(0,-10)",10);
		y = y - 10;
	}
}


function OnloadFunctions() {

	SaveWindowWidth  = getWindowWidth();
	SaveWindowHeight = getWindowHeight();   

	Infobox = new LayerObject('InfoboxDiv');
	Infobox.setOpacity(95);
	InfoboxContent = new LayerObject("InfoboxDivContent");

	Infobox.cut();
	InfoboxContent.cut();

	// prüfen ob das Queryfeld bei der Toolbarsuche leer ist
	// falls ja wird der Standard reingeschrieben
	checkQueryField()

	if (loadMouseMoveControl) Event_init();
	isload = true;
	if (onload_extras != 0) { OnloadExtras(); }
	if (init_ticker == 1) { initTicker(); }
}

// falls weitere Seiten den Onload-Event-Haendler benötigen
function OnloadExtras() {
	if (onload_startseitenbanner == 1) startChangeBanner();
}

function OnResizeFunktions() {
}


var mouse = new Array("x","y");
var scrollTopOffset = false;

function handleMouseMove(e) {
	mouse["x"] = (!document.all)? e.pageX : window.event.clientX;
	mouse["y"] = (!document.all)? e.pageY : (window.event.clientY);
	if (document.all) {
		if (document.documentElement.scrollTop) {
			scrollTopOffset = document.documentElement.scrollTop;
		}
		else {
			scrollTopOffset = window.document.body.scrollTop;
		}
	}
	mouse["y"] += scrollTopOffset;

	// infolayer verschieben
	if (mmObj) {
		var offset = 10;
		var moveLeft = mouse["x"] + offset;
		var moveTop  = mouse["y"] + offset;
		
		var rightEdge  = ((getWindowInnerWidth()-mmObj.getWidth())-offset);
		var bottomEdge = ((getWindowInnerHeight())-mmObj.getHeight()-offset);
		var topEdge    = offset;
		
		if (moveLeft > rightEdge) {
			moveLeft = (getWindowInnerWidth()-mmObj.width-(offset*2));
		}
		if (moveTop < topEdge) {
			moveTop = (mmObj.getHeight()+offset);
		}
		else if (moveTop > bottomEdge) {
			moveTop = (moveTop-mmObj.getHeight()-(offset*2));
		}
		mmObj.setPos(moveLeft,moveTop);
	}
	// regionale layer sitemap
	else if (rn && rn_status) {
		var offset = 20;
		var moveLeft = mouse["x"]
		var moveTop  = mouse["y"];
		
		var leftEdge   = rn.getLeft()-offset;
		var rightEdge  = rn.getLeft() + rn.getWidth() + offset;
		var bottomEdge = rn.getTop()  + rn.getHeight() + offset;
		var topEdge    = rn.getTop()-offset;

		if (mouse["x"] < leftEdge) {
			hideRegionenNavigation();
		}
		if (mouse["x"] > rightEdge) {
			hideRegionenNavigation();
		}
		if (moveTop < topEdge) {
			hideRegionenNavigation();
		}
		else if (moveTop > bottomEdge) {
			hideRegionenNavigation();
		}
	}
}

// ----------------------- funktionen fuer die regionale layer sitemap

var rn_status = false;
var rn = false;
function showRegionenNavigation() {
	var PosImage = new ImageObject("PosImage","body");
	if (rn) {
		closeRegionenNavigation();		
		rn.setPositionType("absolute");
		rn.setPos(PosImage.x-52,PosImage.y);
		
		rn.setWidth('310px');
		rn.setHeight(rn.getHeight()+'px');
		
		rn.css.border='solid 1px darkolivegreen';
		rn.setOverflow('auto');
		rn.paste();
		rn_status=true;
	}
}
function hideRegionenNavigation() {
	closeRegionenNavigation();		
	rn.setPositionType("relative");
	rn.setPos(0,0);
	rn.setWidth('');
	rn.setHeight('');
	rn.css.border='solid 1px white';
	rn_status = false;
}

function closeRegionenNavigation() {
	for(i=0; i < id_all_regions.length;i++) {
		var t = eval('Sub_'+id_all_regions[i]);
		t.cut();
	}	
}

// ----------------------- end regionale layer sitemap





function Event_init() {
	if (document.layers){
		window.captureEvents (Event.MOUSEMOVE);
	    window.onmousemove = handleMouseMove;
	}
	else {  document.onmousemove=handleMouseMove; }

}


// Datumsausgabe bei den Benzinpreisen
function getBPD()
{
	var Titel = "Datum & Uhrzeit in der Titelleiste";
	var Datum = new (Date);
	var Tag = Datum.getDate();
	var Wochentag = Datum.getDay();
	var Monat = Datum.getMonth();
	var Jahr = Datum.getFullYear();
	var Tagname = new Array("Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag");
	var Monatname = new Array("Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");
	
	if ((window.location.host.indexOf('cms') == -1) && (self.location.search.indexOf('changeview') == -1) && (self.location.search.indexOf('action') == -1) && (self.location.search.indexOf('area') == -1) && (self.location.search.indexOf('CMS_HTML') == -1)) {
		document.write(Tagname[Wochentag]+", "+Tag+". "+Monatname[Monat]+" "+Jahr);
	}
}


// crossbrowser ondomready funktion
window.onDomReady = initReady;

// Initialize event depending on browser
function initReady(fn) {
	//W3C-compliant browser
	if(document.addEventListener) {
		document.addEventListener("DOMContentLoaded", fn, false);
	}
	//IE
	else {
		document.onreadystatechange = function(){readyState(fn)}
	}
}

//IE execute function
function readyState(func) {
	// DOM is ready
	if(document.readyState == "interactive" || document.readyState == "complete") {
		func();
	}
}

var domReadyFunctions = new Array();
function addDomReady(func) {
//	domReadyFunctions[domReadyFunctions.length++] = func;
}



//execute as soon as DOM is loaded
//window.onDomReady(onReady);

/*
//do when DOM is ready
function onReady()
{
	alert("The DOM is ready!");
}
*/

function setClickStats(werbeart,werbeart_id) {
//	alert(xajax_setClickStats);
//	alert(werbeart+','+werbeart_id)
	xajax_setClickStats(werbeart,werbeart_id);
}