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;
}

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+' enthält keine gültige E-Mail Adresse\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='  - '+nm+' enthählt keine Ziffern\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+'. beinhalten\n';
    } } } else if (test.charAt(0) == 'R') errors += '  - '+nm+' fehlt\n'; }
  } if (errors) alert('Bitte folgende Eingaben ausbessern:    \n-------------------------------------------\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

/* check or unckeck all checkboxes in the SAME form than checkbox AND the name of which start with the ckecboxes name. */
function checkAllSiblings(checkbox) {
  var myForm = checkbox.form;
  var myLength = checkbox.name.length;
  for (var i=0; i < myForm.length; i++) {
    var elem = myForm[i];
    if (elem.type == 'checkbox' && elem.name.substring(0, myLength) == checkbox.name) elem.checked = checkbox.checked;
  }
}

/* validiere ob maximale anzahl an zeichen fuer z.b. textarea erreicht */
function validateMaxlength(textObj, maxlength) { 
	if (textObj.value.length > maxlength) {
		alert("Maximale Anzahl an Zeichen (" + maxlength + ") erreicht!");
		textObj.value = textObj.value.substring(0,maxlength);
	}
}

/* write current year for example in copyright.htm */
function writeCurrentYear() {
	var now = new Date();
	var year = now.getFullYear();
	document.write(year);
}

/* for bankAccountValidation */
function setBankAccountBankHidden() {
	var bankName = document.getElementById("bankAccountBank_field").value;
	document.getElementById("HiddenBankAccountBank").value = bankName; 
}



// IE5.5+ PNG Alpha Fix v2.0 Alpha: Background Tiling Support
// (c) 2008 Angus Turnbull http://www.twinhelix.com

// This is licensed under the GNU LGPL, version 2.1 or later.
// For details, see: http://creativecommons.org/licenses/LGPL/2.1/

var IEPNGFix = window.IEPNGFix || {};

IEPNGFix.tileBG = function(elm, pngSrc, ready) {
	// Params: A reference to a DOM element, the PNG src file pathname, and a
	// hidden "ready-to-run" passed when called back after image preloading.

	var data = this.data[elm.uniqueID],
		elmW = Math.max(elm.clientWidth, elm.scrollWidth),
		elmH = Math.max(elm.clientHeight, elm.scrollHeight),
		bgX = elm.currentStyle.backgroundPositionX,
		bgY = elm.currentStyle.backgroundPositionY,
		bgR = elm.currentStyle.backgroundRepeat;

	// Cache of DIVs created per element, and image preloader/data.
	if (!data.tiles) {
		data.tiles = {
			elm: elm,
			src: '',
			cache: [],
			img: new Image(),
			old: {}
		};
	}
	var tiles = data.tiles,
		pngW = tiles.img.width,
		pngH = tiles.img.height;

	if (pngSrc) {
		if (!ready && pngSrc != tiles.src) {
			// New image? Preload it with a callback to detect dimensions.
			tiles.img.onload = function() {
				this.onload = null;
				IEPNGFix.tileBG(elm, pngSrc, 1);
			};
			return tiles.img.src = pngSrc;
		}
	} else {
		// No image?
		if (tiles.src) ready = 1;
		pngW = pngH = 0;
	}
	tiles.src = pngSrc;

	if (!ready && elmW == tiles.old.w && elmH == tiles.old.h &&
		bgX == tiles.old.x && bgY == tiles.old.y && bgR == tiles.old.r) {
		return;
	}

	// Convert English and percentage positions to pixels.
	var pos = {
			top: '0%',
			left: '0%',
			center: '50%',
			bottom: '100%',
			right: '100%'
		},
		x,
		y,
		pc;
	x = pos[bgX] || bgX;
	y = pos[bgY] || bgY;
	if (pc = x.match(/(\d+)%/)) {
		x = Math.round((elmW - pngW) * (parseInt(pc[1]) / 100));
	}
	if (pc = y.match(/(\d+)%/)) {
		y = Math.round((elmH - pngH) * (parseInt(pc[1]) / 100));
	}
	x = parseInt(x);
	y = parseInt(y);

	// Handle backgroundRepeat.
	var repeatX = { 'repeat': 1, 'repeat-x': 1 }[bgR],
		repeatY = { 'repeat': 1, 'repeat-y': 1 }[bgR];
	if (repeatX) {
		x %= pngW;
		if (x > 0) x -= pngW;
	}
	if (repeatY) {
		y %= pngH;
		if (y > 0) y -= pngH;
	}

	// Go!
	this.hook.enabled = 0;
	if (!({ relative: 1, absolute: 1 }[elm.currentStyle.position])) {
		elm.style.position = 'relative';
	}
	var count = 0,
		xPos,
		maxX = repeatX ? elmW : x + 0.1,
		yPos,
		maxY = repeatY ? elmH : y + 0.1,
		d,
		s,
		isNew;
	if (pngW && pngH) {
		for (xPos = x; xPos < maxX; xPos += pngW) {
			for (yPos = y; yPos < maxY; yPos += pngH) {
				isNew = 0;
				if (!tiles.cache[count]) {
					tiles.cache[count] = document.createElement('div');
					isNew = 1;
				}
				var clipR = (xPos + pngW > elmW ? elmW - xPos : pngW),
					clipB = (yPos + pngH > elmH ? elmH - yPos : pngH);
				d = tiles.cache[count];
				s = d.style;
				s.behavior = 'none';
				s.left = xPos + 'px';
				s.top = yPos + 'px';
				s.width = clipR + 'px';
				s.height = clipB + 'px';
				s.clip = 'rect(' +
					(yPos < 0 ? 0 - yPos : 0) + 'px,' +
					clipR + 'px,' +
					clipB + 'px,' +
					(xPos < 0 ? 0 - xPos : 0) + 'px)';
				s.display = 'block';
				if (isNew) {
					s.position = 'absolute';
					s.zIndex = -999;
					if (elm.firstChild) {
						elm.insertBefore(d, elm.firstChild);
					} else {
						elm.appendChild(d);
					}
				}
				this.fix(d, pngSrc, 0);
				count++;
			}
		}
	}
	while (count < tiles.cache.length) {
		this.fix(tiles.cache[count], '', 0);
		tiles.cache[count++].style.display = 'none';
	}

	this.hook.enabled = 1;

	// Cache so updates are infrequent.
	tiles.old = {
		w: elmW,
		h: elmH,
		x: bgX,
		y: bgY,
		r: bgR
	};
};


IEPNGFix.update = function() {
	// Update all PNG backgrounds.
	for (var i in IEPNGFix.data) {
		var t = IEPNGFix.data[i].tiles;
		if (t && t.elm && t.src) {
			IEPNGFix.tileBG(t.elm, t.src);
		}
	}
};
IEPNGFix.update.timer = 0;

if (window.attachEvent && !window.opera) {
	window.attachEvent('onresize', function() {
		clearTimeout(IEPNGFix.update.timer);
		IEPNGFix.update.timer = setTimeout(IEPNGFix.update, 100);
	});
}





/* dynamisch posititonierter footer */
function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
function setFooter() {
	// gueltig fuer folgende domains
	var validFooterDomainsString = "bttv.de, bttv.click-tt.de, bttv.burdadigital.de, bttvdemo.clickt-tt.de";
	var validFooterSubomainsString = "*.bttv.de, *.bttv.click-tt.de, *.bttv.burdadigital.de, *.bttvdemo.click-tt.de";

	if(((validFooterDomainsString.indexOf( window.location.hostname ) != -1 ) && ( validFooterDomainsString.charAt(validFooterDomainsString.indexOf( window.location.hostname )-1) == ' '))  //wenn die domain oben angegeben ist (ohne stern davor) 
	  	|| ((validFooterSubomainsString.indexOf( window.location.hostname.substr(window.location.hostname.indexOf('.')+1) ) != -1 )  && ( validFooterSubomainsString.charAt(validFooterSubomainsString.indexOf( window.location.hostname.substr(window.location.hostname.indexOf('.')) )-1) == '*')  )) { //wenn host eine sub ist und oben *.host angegeben ist
		if (document.getElementById) {
			var windowHeight = getWindowHeight();
			if (windowHeight > 0) {
				if (document.getElementById('tabs-external') == null){
				      return null;				
				}		
				// container gesamthoehe ueber dem footer (id) eintragen
				var contentHeight = document.getElementById('container').offsetHeight + document.getElementById('tabs-external').offsetHeight;;
				var footerElement = document.getElementById('footer');
				var footerHeight  = footerElement.offsetHeight;
				if (windowHeight - (contentHeight + footerHeight) >= 0) {
					footerElement.style.position = 'absolute';
					footerElement.style.top = (windowHeight - footerHeight) + 'px';
				}
				else {
					footerElement.style.position = 'static';
				}
			}
		}
	}
}



window.onload = function() {
	initTerminationMessageTicker();
	setFooter();
}
window.onresize = function() {
	setFooter();
}


/* email encoding */
function encodeEmail(topLevelDomain, m1, domain, m2) {
	var prefix = 'ma' + 'il' + 'to';
	var path = 'hr' + 'ef' + '=';
	var delimiter1 = '&#'+'64;';
	var delimiter2 = '&#'+'46;';
		
	if(m2 != '') {
		var concatString = m1+delimiter2+m2+delimiter1+domain+delimiter2+topLevelDomain;
	} else {
		var concatString = m1+delimiter1+domain+delimiter2+topLevelDomain;
	}
	document.write('<a '+path+'"'+prefix+':'+concatString+'">'+concatString+'</a>');
}

function checkboxWithRadioBehavior (checkbox) {
 	var form = checkbox.form;
  	for (var i=0; i < form.length; i++) {
    	var elem = form[i];
    	if (elem.type == 'checkbox' && elem.name == checkbox.name && elem != checkbox) elem.checked = false;
  	}
}

