// JavaScript Document

/*------ open fixed size browser window ------*/
function openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

/*------ open hyperlink in _blank ------*/
function blank(obj) {
obj.target = '_blank';
}

/*------ open hyperlink in _top ------*/
function top(obj) {
obj.target = '_top';
}

/*------ navigation menu highlighting ------*/
function highlightLinks() {
   var anzHrefs = document.getElementsByTagName("a").length;
   for (var i = 0; i <= anzHrefs - 1; i++) {
      if (document.getElementsByTagName("a")[i].href == document.location.href) {
		 var currentClassName = document.getElementsByTagName("a")[i].className; 
		 var newClassName = currentClassName.replace(/inaktiv/,"aktiv");
         document.getElementsByTagName("a")[i].className = newClassName; 
      }
   }
}

/*------ search function ------*/
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

/*------ form field validation ------*/
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' muss eine korrekte eMail-Adresse enthalten.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' darf nur Ziffern enthalten.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' muss eine Zahl zwischen '+min+' und '+max+' enthalten.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' muss angegeben werden.\n'; }
  } if (errors) alert('Bitte kontrollieren Sie folgende Angaben:\n'+errors);
  document.MM_returnValue = (errors == '');
}

/*------ Seite drucken ------*/

function printPage() {
window.print();
}

/* function printPage() {
if (window.print) {
jetztdrucken = confirm('Seite drucken?');
if (jetztdrucken) window.print();
   }
}*/

/*------ PictureWindow-Fever Popup ------*/
function openPictureWindow_Fever(imageType,imageName,imageWidth,imageHeight,alt,posLeft,posTop,bildid) {  // v4.01
	
	// bildid lässt bei mehreren Bilder auf einer Seite das richtige in Großansicht darstellen.	
	if (bildid == "") {bildid = "Bild"};

	// der ALT-Text des Bildes wird ausgelesen und erscheint in der Titelzeile des PopUps
	if (alt == "") {alt = document.getElementById(bildid).getAttribute("alt")};
	
	//Wenn der imageName leer steht, wird der Dateiname des Bildes in Normalansicht verwendet, jedoch mit dem Zusatz "_hq.jpg" für HighQuality
	
	if (imageName == "") {
		imageName = document.getElementById(bildid).src.replace(/.jpg/g, '_hq.jpg');
		}
	imageWidth = 640;
	imageHeight = 480;	
	posLeft  = (screen.width / 2) - (imageWidth / 2);
    posTop  = (screen.height / 2) - (imageHeight / 2);
	
	//really not important (the first two should be small for Opera's sake)
	PositionX = 10;
	PositionY = 10;
	defaultWidth  = 640;
	defaultHeight = 480;
	
	//kinda important
	var AutoClose = true;
	imageURL=imageName;
	imageTitle=alt;
	//don't touch

  var imgWin = window.open('','_blank','scrollbars=no,resizable=1,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY);
  if( !imgWin ) { return true; } //popup blockers should not cause errors
  imgWin.document.write('<html><head><title>'+imageTitle+'<\/title><script type="text\/javascript">\n'+
    'function resizeWinTo() {\n'+
    'if( !document.images.length ) { document.images[0] = document.layers[0].images[0]; }'+
    'var oH = document.images[0].height, oW = document.images[0].width;\n'+
    'if( !oH || window.doneAlready ) { return; }\n'+ //in case images are disabled
    'window.doneAlready = true;\n'+ //for Safari and Opera
    'var x = window; x.resizeTo( oW + 200, oH + 200 );\n'+
    'var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;\n'+
    'if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }\n'+
    'else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }\n'+
    'else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }\n'+
    'if( window.opera && !document.childNodes ) { myW += 16; }\n'+
    'x.resizeTo( oW = oW + ( ( oW + 200 ) - myW ), oH = oH + ( (oH + 200 ) - myH ) );\n'+
    'var scW = screen.availWidth ? screen.availWidth : screen.width;\n'+
    'var scH = screen.availHeight ? screen.availHeight : screen.height;\n'+
    'if( !window.opera ) { x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2)); }\n'+
    '}\n'+
    '<\/script>'+
    '<\/head><body onload="resizeWinTo();"'+(AutoClose?' onblur="self.close();"':'')+'>'+
    (document.layers?('<layer left="0" top="0">'):('<div style="position:absolute;left:0px;top:0px;display:table;">'))+
    '<img src="'+imageURL+'" alt="Lade Bild ..." title="" onload="resizeWinTo();">'+
    (document.layers?'<\/layer>':'<\/div>')+'<\/body><\/html>');
  imgWin.document.close();
  if( imgWin.focus ) { imgWin.focus(); }

}
