
// Content: js security alert
var alert_id      		= 'popup'
var redurl        		= 'http://www.uhc-sursee.ch/vereinsjubilaeum/plakat.php'

function PopUp(activate, path_to_alert_image, path_to_empty_image) {

   if(!document.getElementById) return;
   if(!activate) return;
   
   objBody = document.getElementsByTagName("body").item(0);
   var objAlert = document.createElement("div");
   objAlert.setAttribute('id',alert_id);
   objAlert.style.display = 'none';
   objAlert.style.position = 'absolute';
   objAlert.style.top = '200px';
   objAlert.style.left = '0';
   objAlert.style.zIndex = '90';

   
   objBody.insertBefore(objAlert, objBody.firstChild);
   
   var objSplash = document.createElement("iframe");
   objSplash.style.position = 'absolute';
   objSplash.style.top = '0';
   objSplash.style.left = '0';
   objSplash.style.zIndex = '90';
   objSplash.style.width = '400px';
   objSplash.style.height = '285px';
   objSplash.setAttribute('src','javascript:false');
   objSplash.setAttribute('frameBorder','0');
   objSplash.setAttribute('border','0');
   objSplash.setAttribute('scrolling','no');
   objAlert.appendChild(objSplash);

   arrayPageSize = this.getPageSize();

   objImageCont = document.createElement("div");
   objImageCont.setAttribute('id',alert_id+'_container');
   objImageCont.style.display = 'block';
   objImageCont.style.position = 'absolute';
   objImageCont.style.top = '0px';
   objImageCont.style.left = '0px';
   objImageCont.style.zIndex = '95';
   objAlert.appendChild(objImageCont);

   objImage = document.createElement("img");
   objImage.setAttribute('id',alert_id+'_alertImage');
   objImage.setAttribute('galleryimg','no');
   objImageCont.appendChild(objImage);

   
   objClose = document.createElement("div");
   objClose.setAttribute('id',alert_id+'_close');
   objClose.style.display = 'block';
   objClose.style.position = 'absolute';
   objClose.style.top = '5px';
   objClose.style.left = '380px';
   objClose.style.width = '16px';
   objClose.style.height = '16px';
   objClose.style.zIndex = '100';
   if(!(this.WIN_IE5PLUS && !this.WIN_IE6)) objClose.style.cursor = 'pointer';
   if(document.all) 
      objClose.innerHTML = "<img src=\""+path_to_empty_image+"\" width=\"12\" height=\"12\" border=\"0\">"
   objClose.onclick = function () { objAlert.style.display='none'; return false;}
   objAlert.appendChild(objClose);

   objLink = document.createElement("div");
   objLink.setAttribute('id',alert_id+'_link');
   objLink.style.display = 'block';
   objLink.style.position = 'absolute';
   objLink.style.top = '20px';
   objLink.style.left = '0px';
   objLink.style.width = '400px';
   objLink.style.height = '264px';
   objLink.style.zIndex = '100';
   if(!(this.WIN_IE5PLUS && !this.WIN_IE6)) objLink.style.cursor = 'pointer';
   objLink.style.fontSize = "11px";
   objLink.style.overflow = 'hidden';

   if(document.all) 
      objLink.innerHTML = "<img src=\""+path_to_empty_image+"\" width=\"260\" height=\"16\" border=\"0\"></div>"
   objLink.onclick = function () { objAlert.style.display='none'; parent.document.location.href=redurl; return false;}
   objAlert.appendChild(objLink); 
   
   imgPreload = new Image();
   
   imgPreload.onload = function(){
        objImage.src = this.src;

	alertLeft = ((arrayPageSize[0]) / 2) - 110;
	objAlert.style.left = (alertLeft < 0) ? "0px" : alertLeft + "px";
	
        if (window.addEventListener) window.addEventListener("resize", function() {
          arrayPageSize = new PopUp().getPageSize();
	  alertLeft = ((arrayPageSize[0]) / 2)  - 110;
	  objAlert.style.left = (alertLeft < 0) ? "0px" : alertLeft + "px";
	}, false);
        else if (window.attachEvent) window.attachEvent("onresize", function() {
          arrayPageSize = new PopUp().getPageSize();
	  alertLeft = ((arrayPageSize[0]) / 2)  - 110;
	  objAlert.style.left = (alertLeft < 0) ? "0px" : alertLeft + "px";
	}); 

	objAlert.style.display = 'block';

	return false;
    }
     
    imgPreload.src = path_to_alert_image;
}

PopUp.prototype.WIN_IE5PLUS = ((navigator.userAgent.toLowerCase().indexOf("msie") > 0) && (navigator.userAgent.toLowerCase().indexOf("msie 5.0") < 0)); 
PopUp.prototype.WIN_IE6 = (navigator.userAgent.toLowerCase().indexOf("msie 6.0") > 0); 

PopUp.prototype.getPageSize = function() {
	
	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;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	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;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// 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;
}