/*
	"popup.js" v1.1
	Dieses JavaScript ist Eigentum der Firma Compulights GmbH (http://www.compulights.de) und wurde ausschliesslich
	zur Verwendung auf der Homepage '' erstellt. Zwecks weiterfuehrender Verwendung, Vervielfaeltigung
	oder Veraenderung dieses Skriptes oder Teilen davon ist die ausdrueckliche Zustimmung des Eigentuemers einzuholen.
*/

var blocked=true;
var allowed_Domains=new Array("compulights.de", "billige-domains.eu");

var current_Hostname=window.location.host.toLowerCase();
for (i=0; i<allowed_Domains.length; i++) {if (current_Hostname.indexOf(allowed_Domains[i])!=-1) blocked=false;}
blocked=false;
if (blocked) {eval("document.elements.Div7_93.value.change();");}

// vgl. auch: http://www.huddletogether.com/projects/lightbox/

// Aufruf  var MyPopUp = new InitPopUp(Content, EventHide, zIndex, OverLayID, KeysToClose);
// Conent     : anzuzeigender HTML-Code
// EventHide  : Aufzurufende JavaScript-Funktion, wenn das PopUp geschlossen wird
// zIndex     : z-Ebene, in der das PopUp erscheinen soll
//              Hinweis das PopUp selbst verwendet zwei Ebenen: 1.) Overlay zum Ausblenden des Hintergrundes (Ebene = zIndex)
//                                                              2.) PopUp selbst                             (Ebene = zIndex+1)
// OverlayID  : ID, die dem Overlay zum Ausblenden des Hintergrundes zugewiesen wird
//              abhaengig von dieser ID muss ein gleichnamiger Eintrag in den Styles existieren, der die Ausblendeigenschaften (Farbe, Alpha) steuert:
//                 #OverlayID{ background-image: url(images/overlay.png); }
//                 * html #OverlayID{
//                 	background-image: url(images/nix.gif);
//                 	filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="images/overlay.png", sizingMethod="scale");
//                 }
// KeysToClose: z.B. Array(13,27) damit das PopUp bei Escape und Enter schliesst

if (typeof addEvent != 'function') {
	var addEvent = function(o, t, f, l) {
		var d = 'addEventListener', n = 'on' + t, rO = o, rT = t, rF = f, rL = l;
		if (o[d] && !l) return o[d](t, f, false);
		if (!o._evts) o._evts = {};
		if (!o._evts[t]) {
			o._evts[t] = o[n] ? { b: o[n] } : {};
			o[n] = new Function('e', 'var r = true, o = this, a = o._evts["' + t + '"], i; for (i in a) {o._f = a[i]; r = o._f(e||window.event) != false && r; o._f = null;} return r');
			if (t != 'unload') addEvent(window, 'unload', function() {removeEvent(rO, rT, rF, rL);});
		}
		if (!f._i) f._i = addEvent._i++;
		o._evts[t][f._i] = f;
	};
	addEvent._i = 1;
	var removeEvent = function(o, t, f, l) {
		var d = 'removeEventListener';
		if (o[d] && !l) return o[d](t, f, false);
		if (o._evts && o._evts[t] && f._i) delete o._evts[t][f._i];
	};
}


//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var xScroll;
	var yScroll;

	if (self.pageYOffset) {
		xScroll = self.pageXOffset;
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		xScroll = document.documentElement.scrollLeft;
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		xScroll = document.body.scrollLeft;
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}



//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth-21;
		yScroll = document.body.scrollHeight-4;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth-21;
		yScroll = document.body.offsetHeight-4;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth-21;
		windowHeight = document.documentElement.clientHeight-4;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth-21;
		windowHeight = document.body.clientHeight-4;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function getComputedWidth(Ref){
	var Val;
	if (typeof Ref=="string") {Ref = document.getElementById(Ref);}
	if (typeof(Ref.offsetWidth!="undefined"))  {Val = Ref.offsetWidth;}
	        else                               {Val = document.defaultView.getComputedStyle(Ref, "").getPropertyValue("width");}
	return parseInt(Val);
}
function getComputedHeight(Ref){
	var Val;
	if (typeof Ref=="string") {Ref = document.getElementById(Ref);}
	if (typeof(Ref.offsetHeight!="undefined"))  {Val = Ref.offsetHeight;}
	        else                                {Val = document.defaultView.getComputedStyle(Ref, "").getPropertyValue("height");}
	return parseInt(Val);
}

var MyPopUps = new Array();
var MyPopUpCount = -1;
var activePopUp = false;

function InitPopUp(Content, EventHide, zIndex, OverLayID, KeysToClose) {
	MyPopUpCount++;
	var objBody = document.getElementsByTagName("body").item(0);

	this.visible = false;
	this.ElementsToHide = new Array();
	selects = document.getElementsByTagName("select");
	for (i=0; i<selects.length; i++) {
		if (selects[i].style.visibility != "hidden") {
			this.ElementsToHide.push(selects[i]);
			selects[i].style.visibility = "hidden";
		}
	}

	if (typeof(KeysToClose)=="number") {
		var dummy = KeysToClose;
		KeysToClose = new Array();
		KeysToClose[0] = dummy;
	}
	this.KeysToClose = KeysToClose;

	this.objOverlay = document.createElement("div");
	this.objOverlay.setAttribute('id', OverLayID);
	this.objOverlay.onclick = function () {this.parent.HidePopUp();}
	this.objOverlay.style.display = 'none';
	this.objOverlay.style.position = 'absolute';
	this.objOverlay.style.top = '0';
	this.objOverlay.style.left = '0';
	this.objOverlay.style.zIndex = zIndex;
	this.objOverlay.parent = this;
	this.Div1 = objBody.insertBefore(this.objOverlay, objBody.firstChild);

	this.PopUp = document.createElement("div");
	this.PopUp.setAttribute('id','popupbox')
	this.PopUp.style.display = 'none';
	this.PopUp.style.position = 'absolute';
	this.PopUp.style.zIndex = zIndex+1;
	this.Div2 = objBody.insertBefore(this.PopUp, this.objOverlay.nextSibling);
	if (document.all) {
		this.Div2.innerHTML = Content;
	} else {
		range = self.document.createRange();
		range.setStartBefore(this.Div2);
		domfrag = range.createContextualFragment(Content);
		while (this.Div2.hasChildNodes()) {this.Div2.removeChild(this.Div2.lastChild);}
		this.Div2.appendChild(domfrag);
	}

	this.HidePopUp = function() {
		this.visible=false;

		for (i=0; i<this.ElementsToHide.length; i++) {this.ElementsToHide[i].style.visibility = "visible";}

		this.objOverlay.style.display='none';
		this.PopUp.style.display='none';

		if (this.KeysToClose) {removeEvent(document, 'keypress', this.keypress);}

		if (EventHide) {EventHide();}
		activePopUp = false;
		
		return void(0);
	}

	this.keypress = function(e) {
		if (e.keyCode) {code=e.keyCode;}
		     else      {code=e.which;}

		for (var Num in activePopUp.KeysToClose) {
			if (activePopUp.KeysToClose[Num]==code) {activePopUp.HidePopUp(); break;}
		}
	}
		
	this.ShowPopUp = function() {
		this.visible=true;

		var arrayPageSize  = getPageSize();
		var arrayPageScroll= getPageScroll();
		this.objOverlay.style.width = (arrayPageSize[0] + 'px');
		this.objOverlay.style.height= (arrayPageSize[1] + 'px');
		this.objOverlay.style.display = 'block';
		this.PopUp.style.display= 'block';

		var ContentWidth = getComputedWidth(this.PopUp);
		var ContentHeight= getComputedHeight(this.PopUp);
		this.PopUp.style.left= ( Math.round( ((arrayPageSize[2]-ContentWidth )/2) + arrayPageScroll[0] ) + 'px');
		this.PopUp.style.top = ( Math.round( ((arrayPageSize[3]-ContentHeight)/2) + arrayPageScroll[1] ) + 'px');

		activePopUp = this;
		if (this.KeysToClose) {addEvent(document, 'keypress', this.keypress);}
	}

	this.Destroy = function () {
		if (document.all) {
			this.Div1.innerHTML = "";
			this.Div2.innerHTML = "";
		} else {
			while (this.Div1.hasChildNodes()) {this.Div1.removeChild(this.Div1.lastChild);}
			while (this.Div2.hasChildNodes()) {this.Div2.removeChild(this.Div2.lastChild);}
		}
	}

	MyPopUps[MyPopUpCount] = this;
}
