var db = (document.compatMode && document.compatMode.toLowerCase() != "backcompat") ? document.documentElement : (document.body || null);

function str_replace(sNeedle, sReplace, sHaystack)
{
	return sHaystack.split(sNeedle).join(sReplace);
}

function is_null(oObj)
{
	return oObj == null;
}

function empty(sString)
{
	return (is_null(sString) || sString == undefined || sString == "");
}

function isIE()
{
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
	{
		var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number

		if(ieversion <= 7)
		{
			return true;
		}
	}

	return false;
}

function getInt(x,y)
{
	return isNaN(y = parseInt(x)) ? 0 : y;
}

function getWinWidth()
{
	return (db && db.clientWidth) ? db.clientWidth : (window.innerWidth || 0);
}

function getWinHeight()
{
	return getInt((db && db.clientHeight) ? db.clientHeight : (window.innerHeight || 0));
}

function getScrollPosX()
{
	return getInt(window.pageXOffset || (db ? db.scrollLeft : 0));
}

function getScrollPosY()
{
	return getInt(window.pageYOffset || (db ? db.scrollTop : 0));
}

function browserRelated(ff,ie)
{
	if (isIE()) return ie;
	else return ff;
}

function highlightThumb(_this,over)
{
	var imgs = _this.getElementsByTagName('img');

	if (over)
	{
		if (imgs.length) imgs[0].style.border='1px solid #FFFFFF';
		else if (isIE()) _this.getElementsByTagName('object')[0].style.border='1px solid #FFFFFF';

		_this.style.backgroundColor = '#6E8CB1';
	}
	else
	{
		if (imgs.length) imgs[0].style.border='1px solid #C7CACA';
		else if (isIE()) _this.getElementsByTagName('object')[0].style.border='1px solid #C7CACA';

		_this.style.backgroundColor = '#8AA5C7';
	}
}

function highlightRow(_this,c,ht,c2)
{
	_this.style.backgroundColor = c;

	if (ht)
	{
		var href = _this.getElementsByTagName("a");

		for (i=0; i<href.length; i++)
		{
			href[i].style.color = c2;
		}
	}
}

function highlightForm(_this,focused,defstr)
{
	if (focused)
	{
		_this.style.border = "1px solid #92C2DD";
		_this.style.backgroundColor = "#FFFFFF";

		if (defstr && _this.value == defstr) _this.value = "";
	}
	else
	{
		_this.style.border = "1px inset #92C2DD";
		_this.style.backgroundColor = "#FFFFFF";

		if (defstr && _this.value == "") _this.value = defstr;
	}
}

function toggle(_this,trigger,arr_display)
{
	var ie = 0;
	var ff = 1;

	if (_this.style.display == "none")
	{
		if (trigger == "toggle")
		{
			if (arr_display) _this.style.display = (isIE()) ? arr_display[ie] : arr_display[ff];
			else _this.style.display = "block";
		}
	}
	else
	{
		_this.style.display = "none"
	}
}

function toggleSearch(tabon,taboff,hide)
{
	for (i=1; i<2; i++)
	{
		$(String(tabon+'_'+i)).style.backgroundImage = $(String(tabon+'_'+i)).style.backgroundImage.replace(/off\./, "on.");

		if ($(String(tabon+'_'+i)).getElementsByTagName("span")[0])
		{
			$(String(tabon+'_'+i)).className = "search-tab active";
//			$(String(tabon+'_'+i)).getElementsByTagName("span")[0].style.class.name = "search-tab active";
			$(String(tabon)).style.display = "block";
		}
	}



	if (taboff.indexOf(",") != -1)
	{
		tabsoff = new Array();
		tabsoff = taboff.split(",");

		for (h=0; h<tabsoff.length; h++)
		{
			for (i=1; i<2; i++)
			{
				$(String(tabsoff[h]+'_'+i)).style.backgroundImage = $(String(tabsoff[h]+'_'+i)).style.backgroundImage.replace(/on\./, "off.");

				if ($(String(tabsoff[h]+'_'+i)).getElementsByTagName("span")[0])
				{
					//$(String(tabsoff[h]+'_'+i)).getElementsByTagName("span")[0].style.color = "#000000";
					$(String(tabsoff[h]+'_'+i)).className = "search-tab inactive";
//					$(String(tabsoff[h]+'_'+i)).getElementsByTagName("span")[0].style.class.name = "search-tab inactive";
					$(String(tabsoff[h])).style.display = "none";
				}
			}
		}
	}
	else
	{
		for (i=1; i<2; i++)
		{
			$(String(taboff+'_'+i)).style.backgroundImage = $(String(taboff+'_'+i)).style.backgroundImage.replace(/on\./, "off.");

			if ($(String(taboff+'_'+i)).getElementsByTagName("span")[0])
			{
				$(String(taboff+'_'+i)).className = "search-tab inactive";
//				$(String(taboff+'_'+i)).getElementsByTagName("span")[0].style.class.name = "search-tab inactive";
				$(String(taboff)).style.display = "none";
			}
		}
	}

	if (hide) $(String('result')).style.display = "none";
	else $(String('result')).style.display = "block";
}

function tab(_this,active,smalltab)
{
	if (smalltab)
	{
		var tab_on  = PATH_IMG+"tab_s_on.gif";
		var tab_off = PATH_IMG+"tab_s_off.gif";
	}
	else
	{
		var tab_on  = PATH_IMG+"tab_on.gif";
		var tab_off = PATH_IMG+"tab_off.gif";
	}

	if (active)
	{
		_this.style.background = "url("+tab_on+")";
		_this.getElementsByTagName("a")[0].style.color = "#FFFFFF";
	}
	else
	{
		_this.style.background = "url("+tab_off+")";
		_this.getElementsByTagName("a")[0].style.color = "#000000";
	}
}

function confirmMsg(e)
{
	if (confirm(am.getMessage(e)))
	{
		return true;
	}

	return false;
}

function popItem(p,n,w,h,t,l)
{
	pwo = window.open(p,n,'width='+w+',height='+h+',top='+t+',left='+l+',location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
}

function regenerateCode()
{
	if ($("cmg").src.indexOf("?x=") != -1) $("cmg").src = $("cmg").src.replace(/\?x=\d.+\B/,"?x="+Math.round(Math.random()*1000000000000));
	else $("cmg").src = $("cmg").src+"?x="+Math.round(Math.random()*1000000000000);
}

function setCookie(name,value,expires,path,domain)
{
	var curCookie = name+"="+escape(value)+((expires) ? "; expires="+expires.toGMTString() : "")+((path) ? "; path="+path : "")+((domain) ? "; domain="+domain : "");
	document.cookie = curCookie;
}

function snl(loc)
{
	location.href = PATH_HTTP+loc;
}

function setL(_str)
{
	if (_str.indexOf('||') != -1)
	{
		var arr_str = _str.split('||');
		var loc = arr_str.join('/');
			loc = loc.replace(/#/,'.');

		snl(loc);
	}
}

function switchTopTeasers(show_them)
{
	if ( show_them )
	{
		$("low-top-teasers").style.display = "block";
//		$("show-more-button").className = "up";
		$("show-more-button").style.background = "url("+PATH_HTTP+"images/teaser_up.gif) no-repeat bottom right";
		$("show-more-button").title = "Weniger News anzeigen...";
	} else {
		$("low-top-teasers").style.display = "none";
//		$("show-more-button").className = "down";
		$("show-more-button").style.background = "url("+PATH_HTTP+"images/teaser_down.gif) no-repeat bottom right";
		$("show-more-button").title = "Mehr News anzeigen...";
	}
	topteasers_open = show_them;
}

function switchVariations(show_them)
{
	if ( show_them )
	{
		var aElm=document.body.getElementsByTagName('*');
		for(var i=0; i<aElm.length; i++) {
			if(aElm[i].className=="variation") {
				aElm[i].style.display = "block";
			}
		}
//		document.getElementById("low-top-teasers").style.display = "block";
		document.getElementById("show-more-button-v").className = "up";
		document.getElementById("show-more-button-v").title = "Weniger Variationen anzeigen...";
	} else {
		var aElm=document.body.getElementsByTagName('*');
		for(var i=0; i<aElm.length; i++) {
			if(aElm[i].className=="variation") {
				aElm[i].style.display = "none";
			}
		}
//		document.getElementById("low-top-teasers").style.display = "none";
		document.getElementById("show-more-button-v").className = "down";
		document.getElementById("show-more-button-v").title = "Alle Variationen anzeigen...";
	}
	variations_open = show_them;
}

/* * * * * * * * * */
function debug(obj)
{
	var i = 0;
	var list;

	for (prop in obj)
	{
		list += prop+" => "+obj[prop]+"\n";

		if (i%20 == 0)
		{
			alert(list);
			list = "";
		}
		i++;
	}
}

function lupeHover(over)
{
	if ( over )
	{
		document.getElementById('lupe-img').src=PATH_HTTP+"images/gal_zoom.gif";
	} else {
		document.getElementById('lupe-img').src=PATH_HTTP+"images/zoom.png";
	}
}

function tabnav_over(id)
{
	if ( document.getElementById(id).className.search(/active/) != -1 )
	{
		document.getElementById(id).className = 'ttl hover active';
	} else {
		document.getElementById(id).className = 'ttl hover';
	}
}


function tabnav_out(id)
{
//	alert(document.getElementById(id).className);
	if ( document.getElementById(id).className.search(/.*active.*/) != -1 )
	{
		document.getElementById(id).className = 'ttl active';
	} else {
		document.getElementById(id).className = 'ttl';
	}
}




function is_numeric(mText)
{
	var sValidChars = "0123456789.";

	for (i=0;i<mText.length;i++)
	{
		if(sValidChars.indexOf(sText.charAt(i)) == -1)
		{
			return false;
		}
	}

	return true;
}


function manipulateTimer(_this, uiChange)
{
	_this.value = str_replace("uhr", "", _this.value.toLowerCase());
	if(_this.value.split(":").length == 1)
	{
		_this.value = _this.value+":00";
	}

	var uiMinutes = Number(_this.value.split(":")[0])*60+Number(_this.value.split(":")[1].split(" ")[0]);

	// im aktuellem Tage bleiben
	uiMinutes += uiChange;
	uiMinutes -= uiMinutes%15;
	uiMinutes += 60*24
	uiMinutes = uiMinutes%(60*24);

	var uiHours = (uiMinutes - uiMinutes%60)/60;
	uiMinutes -= uiHours*60;

	uiMinutes = uiMinutes < 10 ? "0"+uiMinutes : uiMinutes;
	uiHours = uiHours < 10 ? "0"+uiHours : uiHours;

	if(isNaN(uiMinutes))
	{
		uiMinutes = "00";
	}

	if(isNaN(uiHours))
	{
		uiHours = "10";
	}

	_this.value = uiHours+":"+uiMinutes+" Uhr";
}

function toGal(a, b)
{
	window.location = PATH_HTTP+"galerie/"+a+"/"+b+",1.html";
}
