/* ubitec JavaScript-Document */
/** GENERAL FUNCTIONS **/

function $(id)
{
	if (document.getElementById) return document.getElementById(id);
	else return false;
}
function addEvent(o,n,h)
{
	if(o.attachEvent) o.attachEvent("on"+n,h);
	else if (o.addEventListener) o.addEventListener(n,h,false);
}
function cancelEvent (e)
{
	try
	{
		if (typeof(e) == "undefined") e = window.event;
		if (typeof(e) == "undefined") return false;
		if(e.preventDefault)
		{
			e.preventDefault();
		}
		else
		{
			e.returnValue=false;
			e.cancelBubble=true;
		}
	}
	catch(e) {}
	return false;
}
function MM_swapImage(img,d,src,d2)
{
   if(document.images["wk"])document.images["wk"].src = src;
}
var lastZInd = 1000;
function createLayer(namlay)
{
	if (typeof(namlay) == "undefined") return;
	if (!$(namlay))
	{
		b=document.createElement("div");
		var zI =  lastZInd + 1;
		b.style.cssText='visibility:hidden;position:absolute;z-index:' + zI.toString() + '';
		b.id = namlay;
		if (document.getElementsByTagName)
			document.getElementsByTagName("body")[0].appendChild(b);
		else if (document.all)
			document.all("body").parentNode.appendChild(b);
	}
}
/** Favorit **/
function Webmerk()
{
	if ( typeof(WebmerkQueryA)=="undefined" || WebmerkQueryA == "" ) WebmerkQueryA='PC-Systeme: Druecken Sie Strg + D; Apple-Macintosh-Systeme: Druecken Sie Befehlstaste + D';
	if (  typeof(WebmerkQueryB)=="undefined" || WebmerkQueryB == "" ) WebmerkQueryB='PC-Systeme: Druecken Sie Strg + G; Apple-Macintosh-Systeme: Druecken Sie Befehlstaste + G';
	if (  typeof(WebmerkFavtext)=="undefined" || WebmerkFavtext == "" ) WebmerkFavtext = window.location.host + ' - ' +document.title;
	if ( typeof(WebmerkQuery)=="undefined" || WebmerkQuery == "" ) WebmerkQuery = "Möchten Sie diese Webseite zu Ihren Favoriten hinzufügen?";
	if (document.all) // IE
	{
		if (confirm(WebmerkQuery)) window.external.addFavorite("http://" + window.location.host,WebmerkFavtext);
	}
	else if (document.layers) // NS 4
	{
		alert(WebmerkQueryA);
	} else if (!document.all && document.getElementById) {
		if(navigator.appName == "Netscape") { // NS > 6
			alert(WebmerkQueryA );
		}
	}
}

function _Get_Cookie(name) { 
   var start = document.cookie.indexOf(name+"="); 
   var len = start+name.length+1; 
   if ((!start) && (name != document.cookie.substring(0,name.length))) return 0; 
   if (start == -1) return 0; 
   var end = document.cookie.indexOf(";",len); 
   if (end == -1) end = document.cookie.length; 
   return unescape(document.cookie.substring(len,end)); 
} 

function _Set_Cookie(name,value,expires,path,domain,secure) { 
    var cookieString = name + "=" +escape(value) + 
       ( (expires) ? ";expires=" + expires.toGMTString() : "") + 
       ( (path) ? ";path=" + path : "") + 
       ( (domain) ? ";domain=" + domain : "") + 
       ( (secure) ? ";secure" : "");
    document.cookie = cookieString; 
} 

function _Delete_Cookie(name,path,domain)
{
   if (_Get_Cookie(name)) document.cookie = name + "=" +
      ( (path) ? ";path=" + path : "") +
      ( (domain) ? ";domain=" + domain : "") +
      ";expires=Thu, 01-Jan-70 00:00:01 GMT";
}


var ISZero = 0;
function MakeFontSize(PLUSSize) {
	FontnameArr = new Array("xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large");
	if (document.styleSheets.length > 0 && ((ISZero <= -3 && PLUSSize > 0) || (ISZero >= 7 && PLUSSize < 0) || (ISZero < 7 && ISZero > -3)) ) 

         {
		ISZero += PLUSSize;
		for(var sS=0; sS < document.styleSheets.length; sS++)
		{
		var Sheet = document.styleSheets[sS];
try{
		var curRule = (document.styleSheets[sS].rules) ? document.styleSheets[sS].rules : document.styleSheets[sS].cssRules;
} catch(ex) { continue;}
		for(i=0; i < curRule.length; i++)
		{
			if (curRule[i].style.fontSize != null) {
				FontString = new String(curRule[i].style.fontSize);
				ISFONTNONAME = -1;
				for (j = 0; j < FontnameArr.length; j++) {
					if (FontString == FontnameArr[j]) {
						ISFONTNONAME = j;
						break;
					}
				}
				
				if (ISFONTNONAME == -1) {
					ClassFontSize = (FontString.substr(0, FontString.length-2)) * 1;
					ClassFontFormat = FontString.substr(FontString.length-2, 2);
					if (ClassFontSize > 1 ) {
						ClassFontSize += PLUSSize;
						curRule[i].style.fontSize = (ClassFontSize +  ClassFontFormat);
					}
				} else {
					ISFONTNONAME += PLUSSize
					if (ISFONTNONAME > -1 && ISFONTNONAME < FontnameArr.length)
						curRule[i].style.fontSize = FontnameArr[ISFONTNONAME];
				}
			}
		}
			// cookie speichern
			var today = new Date(); 
			var zero_date = new Date(0,0,0); 
			today.setTime(today.getTime() - zero_date.getTime()); 
			var cookie_expire_date = new Date(today.getTime() + (8 * 7 * 86400000)); 
			_Set_Cookie("_fontsize", ISZero, cookie_expire_date,"/", document.domain,0);
		}
	}
}

// Scriftgr. ändern
function CheckFontSize()
{
	if ( _Get_Cookie("_fontsize") )
	{
		mCounter = _Get_Cookie("_fontsize")*1;
		if (mCounter != 0 ) MakeFontSize(mCounter)
	}
}


/** CHECK FORMULAR **/
function CheckSendForm(formname) {
	if(typeof(formname) == "undefined") formname = "ecomasform";
	eval("var f = document." + formname);
	var dothis = true;
         var arrCheck = new Array();	
         var arrElements = new Array();
         var TMP = new Array();
	for (i = 0; i < f.elements.length; i++) 
         {
                  NameIndex="";
		if (f.elements[i].title != "") 
                  {
                      NameIndex=f.elements[i].name;
                      if(!TMP[NameIndex])                      
                      {
                        TMP[NameIndex]=1;
                        arrElements[arrElements.length]=NameIndex;
                        if(!arrCheck[NameIndex])arrCheck[NameIndex]=new Array();
                      } 
		       
                      if (f.elements[i].type == "text") 
                      {
                               if(f.elements[i].value == "")
				arrCheck[NameIndex]['check']=0;
                               else  arrCheck[NameIndex]['check']=1;
                      }
		    else if (f.elements[i].type == "checkbox" || f.elements[i].type == "radio")
		    {	
                                if( f.elements[i].checked == false && !arrCheck[NameIndex]['check'])
                                  arrCheck[NameIndex]['check']=0;
                                else if(f.elements[i].checked == true)
                                   arrCheck[NameIndex]['check']=1;
                       }
			
                       arrCheck[NameIndex]['title'] = f.elements[i].title;
                       arrCheck[NameIndex]['index'] = i;

		}
	}


         for(j=0;j< arrElements.length;j++)
         {            if(arrCheck[arrElements[j]]['check']==0)
            {
             dothis=false;
             alert(arrCheck[arrElements[j]]['title']);
             f.elements[arrCheck[arrElements[j]]['index']].focus();
             break;
            }
         }
	
         //if(dothis)alert('true');
         //else alert('false');

	return dothis;
} 


/*############## BEGIN Comment-functions ###################*/
/***   Editable: ***/
var backcolor	= '#ffffe1';		// Hintergrund
var bordercolor	= '#000';			// Ramenfarbe
var textcolor	= '#000';			// Textfarbe
var displaytime	= '30000';		// Zeit
var tablewidth	= '230';			// Tabellenbreite in px
var object	= 'Layer2';		// objekt - Ebene ID
/*******************/
var tipTimer = false;			// dHTML Toolltip Timer

function hideKommentar() 
{
	if ($(object))
	{
		if (tipTimer) window.clearTimeout(tipTimer);
		tipTimer = false;
		$(object).style.visibility="hidden";
		$(object).style.left = -200;
		$(object).style.top = -200;
		return false;
	}
	else return true;
}

function showKommentar(e, tipContent)
{
	if (!$(object)) return true;
	if (tipTimer) window.clearTimeout(tipTimer);
	$(object).innerHTML='<div style="text-align:left; font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 11px; border: 1px solid '+bordercolor+'; background-color: '+backcolor+'; padding:4px; width:'+tablewidth+'px; max-width:'+tablewidth+'px; color: '+textcolor+';">'+unescape(tipContent)+'</div>';
	var top = 0, left = 0;

	if (typeof window.pageXOffset != 'undefined')
	{
		left = window.pageXOffset;
		top = window.pageYOffset;
	}
	else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat')
	{
		left = document.documentElement.scrollLeft;
		top = document.documentElement.scrollTop;
	}
	else if (typeof document.body != 'undefined')
	{
		left = document.body.scrollLeft;
		top = document.body.scrollTop;
	}
	left = parseInt(left);
	top = parseInt(top);
	if (e.x)
	{
		left += e.x;
		top += e.y;
	}
	else if (e.clientX)
	{
		left += e.clientX;
		top += e.clientY;
	}
	left = parseInt(left) - 10;
	top = parseInt(top) + 20;

	$(object).style.top = top.toString()+"px";
	$(object).style.left = left.toString()+"px";
	$(object).style.visibility="visible";
	tipTimer = window.setTimeout("hideKommentar('"+object+"')", displaytime);
	return true;
}

/*############### END Comment-functions ####################*/

/*################ BEGIN Images-functions ##################*/
function BildDown(DownURL,winfeatures) {
	window.open(DownURL,'Filedown','top=0,left=0' + (winfeatures ? (','+winfeatures) : '') );
}
function getAttrib(selEl, nm, default_value)
{
	if(typeof(default_value) == "undefined") default_value = "";
	var v = default_value;
	if (selEl.getAttribute)
	{
		if (selEl.getAttribute(nm,0) != null) v = selEl.getAttribute(nm,0);
	}
	else if (selEl.attributes)
	{
		var oAttrColl = selEl.attributes;
		var oAttr = oAttrColl.getNamedItem(nm);
		if(oAttr != null) v = oAttr.value;
	}
	if (nm == "noWrap") v = selEl.noWrap;
	if (nm == "class") v = selEl.className;
	return '' + v;
}

function OpenFoto(BildURL, x, y) {
	var win = "";
	win = window.open("","bild",'height=' + y + ',width=' + x +',location=0,status=0,toolbar=no,resizable=0,scrollbar=no,top=0,left=0');
	win.document.writeln('<html><head><title>Das Bild</title>');
	win.document.writeln('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">');
	win.document.writeln('</head><body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">');
	win.document.writeln('<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">');
	win.document.writeln('<tr><td align="center">');
	win.document.writeln('<a href="javascript:window.close()">');
	win.document.writeln('<img src="' + BildURL + '" border=0  alt="Fenster schließen">');
	win.document.writeln('</a></td></tr></table></body></html>');
	win.document.close();
	win.focus();
}
function in_array(needle, arr)
{
	var CurStr = new String("," + arr + ",");
	if (CurStr.indexOf("," + needle + ",") == -1) return false;
	else return true;
}
var allCollection = new Array();
var allImgTitles = new Array();
var curPos = 0;
var setLoupe = false;
function getDoBildImgs(BILD)
{
	allCollection = new Array();
	if (document.getElementsByTagName)
		var elements=document.getElementsByTagName('a');
	else if (document.all)
		var elements=document.all('a');
	var txt;
	if(elements.length > 0)
	{
		var re=new RegExp("[ \t\n\r\f]","gi");
		for (var i = 0; i < elements.length; i++)
		{
			txt = new String(elements[i].href);
			if (txt.toLowerCase().indexOf("javascript:") == -1)
			{
				txt = new String(getAttrib(elements[i],"onclick"));
				if (txt.indexOf("DoBild(") != -1) txt = "javascript:"+txt;
			}
			txt = txt.replace(re, "");
			if (txt.toLowerCase().indexOf("javascript:") != -1 && txt.indexOf("DoBild(") != -1)
			{
				txt = txt.substring(txt.indexOf("'")+1, txt.lastIndexOf("'"));
				if (!setLoupe)
				{
elements[i].style.cursor = "url('"+http_host+"navigation/loupe.png'), url("+http_host+"navigation/loupe.cur), default";
				}
				if (!in_array(txt, allCollection))
				{
					if (txt == BILD) curPos = allCollection.length;
					allCollection.push(txt);
					allImgTitles[allCollection.length-1] = getTitle(elements[i]);
				}
			}
		}
	}
}

function getTitle(node)
{
	if (typeof(node) == "undefined") return "";
	if (node.childNodes.length == 0) return "";
	for (var i = 0; i < node.childNodes.length; i++)
	{
		if (typeof(node.childNodes[i].tagName) == "undefined") continue;
		if (node.childNodes[i].tagName.toLowerCase() == "img")
		{
			if (node.childNodes[i].title != "") return node.childNodes[i].title.substr(0,90);
			else if (node.childNodes[i].alt != "")
			{
				if(node.childNodes[i].alt == "Bitte klicken zum Vergrößern" || node.childNodes[i].alt == "Bitte klicken zum Vergößern") return document.title.substr(0,90);
				else return node.childNodes[i].alt.substr(0,90);
			}
		}
	}
	return "";
}

function DoBild(BILD)
{
	getDoBildImgs(BILD);
	if (DoBildWindowClose == "") DoBildWindowClose = "Bitte klicken zum Verkleinern";
	var x = 0;
	var y = 0;
	if (typeof window.pageXOffset != 'undefined')
	{
		x = window.pageXOffset;
		y = window.pageYOffset;
	}
	else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat')
	{
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	else if (typeof document.body != 'undefined')
	{
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}

	if (!$("sashadow"))
	{
		var b = document.createElement("div");
		b.id = "sashadow";
		b.style.display = "none";
		b.innerHTML = "&nbsp;";
		addEvent(b, "click", HideImage);
		document.getElementsByTagName("body")[0].appendChild(b);
	}
	if (!$("imagelayer"))
	{
		var b = document.createElement("div");
		b.id = "imagelayer";
		b.style.display = "none";
		document.getElementsByTagName("body")[0].appendChild(b);
	}
	
	var b_g = $("sashadow");
	var b_i = $("imagelayer");

	b_i.style.left = x+"px";
	b_i.style.top = y+"px";

	var h = 0, w = 0;
	if (document.documentElement) h = parseInt(document.documentElement.scrollHeight);
	if (document.body.scrollHeight > h) h = parseInt(document.body.scrollHeight);
	if (document.body.clientHeight > h) h = parseInt(document.body.clientHeight);
	if (h > 0)
	{
		if (!document.all) h += 20;
		b_g.style.height = h+"px";
	}

	if (document.documentElement) w = parseInt(document.documentElement.scrollWidth);
	if (w == 0) h = parseInt(document.body.scrollWidth);
	if (document.body.clientWidth > w) w = parseInt(document.body.clientWidth);
	if (w > 0) b_g.style.width = w+"px";
 
	b_i.innerHTML = "<table border=0 cellspacing=0 cellpadding=1 style='width:100%;height:100%;'><tr><td align='center' valign='middle'><table border=0 cellspacing=0 cellpadding=8 bgcolor=#FFFFFF><tr><td bgcolor=#FFFFFF align='center'><div id='CloseButtonLayer' style='display:none;'></div><a href='#' onclick='HideImage();return false;' id='ecomasResizedLink'><img src='" + BILD + "' alt='" + DoBildWindowClose + "' title='" + DoBildWindowClose + "' class='BildHidden' onLoad='resizeImage()' width='1' height='1' id='ecomasResizedImage' ><img src='" + http_host + "navigation/img_load.gif' id='ecomasLoadImage' width='42' height='12' border='0' onClick='HideImage();'></a><div id='ArraowsLayer' style='display:none;'></div></td></tr></table></td></tr></table>";

	b_g.style.display = "";
	b_i.style.display = "";
}
function HideImage()
{
	var b_g = $("sashadow");
	var b_i = $("imagelayer");
	b_g.style.display = "none";
	b_i.style.display = "none";
}
function resizeImage()
{
	var ibj = $("ecomasResizedImage");
	var img = new Image();
	img.src = ibj.src;
	var cS = 2;
	var sta = img.width/cS;
	var stb = img.height/cS;
	$("ecomasLoadImage").style.display = "none";
	ibj.className = "BildVisible";
	dynamicImage(1,1,img.width,img.height,sta, stb);
}
function dynamicImage(wc,hc,w,h,sta,stb)
{
	var ibj = document.getElementById("ecomasResizedImage");
	wc = Math.round(wc + sta);
	hc = Math.round(hc + stb);
	if (wc >= w) wc = w;
	if (hc >= h) hc = h;
	ibj.width = wc;
	ibj.height = hc;
	if (wc == w || hc == h)
	{
		if(allCollection.length > 0)
		{
			document.getElementById("ArraowsLayer").style.display = "";
			document.getElementById("ArraowsLayer").style.paddingTop = "3px";
                        
			var  HTML = "";
/*
			if (curPos < (allCollection.length -1))
				HTML = "<img src='/navigation/img_arrow_right.gif' align='right' style='cursor:pointer;' onClick='DoBild(\"" + allCollection[parseInt(curPos)+1] + "\");'>";
			if (curPos > 0)
				HTML += "<img src='/navigation/img_arrow_left.gif' align='left' style='cursor:pointer;' onClick='DoBild(\"" + allCollection[parseInt(curPos)-1] + "\");''>";
*/                         
                            
			document.getElementById("ArraowsLayer").innerHTML = HTML;
			var HTML2 = "<img src='/navigation/img_close.gif' align='right' style='cursor:pointer;' onClick='HideImage();'>";
			var Titel = allImgTitles[curPos];
			HTML2 = HTML2 + "<div style='line-height:18px;'>" + Titel + "&nbsp;</div>";
			document.getElementById("CloseButtonLayer").innerHTML = HTML2;
			document.getElementById("CloseButtonLayer").style.display = "";
			document.getElementById("CloseButtonLayer").style.paddingBottom = "8px"; 
		}
		return;
	}
	window.setTimeout("dynamicImage(" + wc + ","+ hc +"," + w + "," + h + "," + sta + "," + stb + ")", 0);
}
function loadScript(url)
{
	if (document.createElementNS)
		var se=document.createElementNS('http://www.w3.org/1999/xhtml','script');
	else if (document.createElement)
		var se=document.createElement('script');

	if (typeof (se) != "undefined")
	{
		se.setAttribute('language','javascript');
		se.setAttribute('type','text/javascript');
		se.setAttribute('src', url );

		if (document.getElementsByTagName)
			document.getElementsByTagName("head")[0].appendChild(se);
		else if (document.all)
			document.all("head").parentNode.appendChild(se);

		return true;
	}
	else return false;
}

function getParam(nm) {
var cons = nm + '=';
var ps = window.location.search;
 if (ps.length > 0) {
     var start = ps.indexOf(cons);
	 if (start != -1) {
	     start += cons.length;
		 var end = ps.indexOf('&',start);
		 if (end == -1) end = ps.length;
		  return unescape(ps.substring(start,end));
	}
}
   return null;
}

function str_replace(in_str, reg_exp, replace_str, opts)
{
	if(in_str==null) return in_str;
	if(typeof(opts)=="undefined") opts='g';
	var re=new RegExp(reg_exp,opts);
	return in_str.replace(re,replace_str);
}

function dvoid()
{

}

var errfound = false;
function ValidLength(item, len) {
   return (item.length >= len);
}
function ValidEmail(item) {
   if (!ValidLength(item, 5)) return false;
   if (item.length > 0) {
      if (item.indexOf ('@', 0) == -1) return false;
      return true;
   }
   return true;
}
function doConfirm(elem, text) {
   if (errfound) return;
   if (confirm(text)) {
	elem.select();
	elem.focus();
	errfound = true;
   }
   else { errfound = false; }
}
function doCheckBox(elem){
	if (elem.checked == false ) return false;
	else return true;
}
function doRadio(elem){
	if (elem.checked == false ) return false;
	else return true;
}
function isCheckBox(elem) {
	doCheckBox(elem);
}
function isRadio(elem) {
	doRadio(elem);
}
function error(elem, text) {
   if (errfound) return;
   window.alert(text);
   if (elem.type == "text")
     elem.select();
   elem.focus();
   errfound = true;
}
/** EOF GENERAL FUNCTION **/
