// Position and show the popup, relative to an anchor object

function FindXY(obj){
    //***Find the x,y location in pixels for a relatively positioned object
    //***returns an object with .x and .y properties.
    if ( document.layers ) { // this is Netscape 4.?
         return { x:obj.x, y:obj.y };
    }
    var res = { x:0,y:0 };     // IE or DOM browsers
    while ( obj ) {        // iteration ensures no stack overflow
          res.x += parseInt( obj.offsetLeft, 10 );    // parseInt ignores denominator
          res.y += parseInt( obj.offsetTop, 10 );
          obj = obj.offsetParent;
   }
   return res;
}
function FindXYWH(obj){
     //***Find the x,y location in pixels for a relatively positioned object
     //***returns an object with .x, .y, .w (width) and .h (height) properties.
     if (!obj) return { x:0, y:0, w:0, h:0 };
     var objXY = FindXY(obj);
     return { x:objXY.x, y:objXY.y, w:obj.offsetWidth, h:obj.offsetHeight };
}

function Visibility_Selects(x,y,w,h,isOn) {
	for(var i=0;i<document.forms.length;i++) {
		f = document.forms[i];
		for(var t=0;t<f.elements.length;t++) {
			e = f.elements[t];
			if(e) {
				if (e.tagName=="SELECT") {
					d = FindXYWH(e);
					x2 = d.x;//e.offsetParent.offsetLeft;
					y2 = d.y;//e.offsetParent.offsetTop;
					w2 = d.w;//e.clientWidth;
					h2 = d.h//e.clientHeight;
/* DEBUG					if (!isOn)
					{
						var content = objInfoHTML(e);
						showInfo(content);
						alert(''+(isOn?'show ':'hide ')+'x:'+x+' y:'+y+' w:'+w+' h:'+h+' x2:'+x2+' y2:'+y2+' w2:'+w2+' h2:'+h2);
					} */
					if ((x<(x2+w2)||(x+w)<x2)&&(y<(y2+h2)||(y+h)<y2)){
						if(document.getElementById || document.all) {
							e.style.visibility = isOn? "visible":"hidden";
						} else if (document.layers) {
							e.visibility = isOn ? "show":"hide";
						}
					}
				}
			}
		}
	}
}
//					var content = objInfoHTML(e.offsetParent);
//					showInfo(content);
//					alert(''+x+' '+y+' '+w+' '+h);
//					alert(''+x2+' '+y2+' '+w2+' '+h2);
function Hide_Selects(x,y,w,h) {
	Visibility_Selects(x,y,w,h,false);
}
function Show_Selects(x,y,w,h) {
	Visibility_Selects(x,y,w,h,true);
}
function Proper_showPopup(anchorname) {
	this.getXYPosition(anchorname);
	this.x += this.offsetX;
	this.y += this.offsetY;
	if (!this.populated && (this.contents != "")) {
		this.populated = true;
		this.refresh();
		}
	if (this.divName != null) {
		// Show the DIV object
		if (this.use_gebi) {
			document.getElementById(this.divName).style.left = this.x;
			document.getElementById(this.divName).style.top = this.y;
			document.getElementById(this.divName).style.visibility = "visible";
			Hide_Selects(this.x, this.y, document.getElementById(this.divName).clientWidth, document.getElementById(this.divName).clientHeight);
			}
		else if (this.use_css) {
			document.all[this.divName].style.left = this.x;
			document.all[this.divName].style.top = this.y;
			document.all[this.divName].style.visibility = "visible";
			Hide_Selects(this.x, this.y, document.all(this.divName).clientWidth, document.all(this.divName).clientHeight);
			}
		else if (this.use_layers) {
			document.layers[this.divName].left = this.x;
			document.layers[this.divName].top = this.y;
			document.layers[this.divName].visibility = "visible";
//			Hide_Selects(this.x, this.y, document.layers[this.divName].clientWidth, document.layers[this.divName].clientHeight);
			}
		// Hide Select objects
		}
	else {
		if (this.popupWindow == null || this.popupWindow.closed) {
			// If the popup window will go off-screen, move it so it doesn't
			if (this.x<0) { this.x=0; }
			if (this.y<0) { this.y=0; }
			if (screen && screen.availHeight) {
				if ((this.y + this.height) > screen.availHeight) {
					this.y = screen.availHeight - this.height;
					}
				}
			if (screen && screen.availWidth) {
				if ((this.x + this.width) > screen.availWidth) {
					this.x = screen.availWidth - this.width;
					}
				}
			var avoidAboutBlank = window.opera || ( document.layers && !navigator.mimeTypes['*'] ) || navigator.vendor == 'KDE' || ( document.childNodes && !document.all && !navigator.taintEnabled );
			this.popupWindow = window.open(avoidAboutBlank?"":"about:blank","window_"+anchorname,this.windowProperties+",width="+this.width+",height="+this.height+",screenX="+this.x+",left="+this.x+",screenY="+this.y+",top="+this.y+"");
			}
		this.refresh();
		}
	}
// Hide the popup
function Proper_hidePopup() {
	if (this.divName != null) {
		if (this.use_gebi) {
			e=document.getElementById(this.divName);
			if (e) { e.style.visibility = "hidden"; }
			}
		else if (this.use_css) {
			e=document.all[this.divName];
			if (e) { e.style.visibility = "hidden"; }
			}
		else if (this.use_layers) {
			e=document.layers[this.divName];
			if (e) { e.visibility = "hidden"; }
			}
		// Show Selects
		Show_Selects(this.x,this.y,this.width,this.height);
		}
	else {
		if (this.popupWindow && !this.popupWindow.closed) {
			this.popupWindow.close();
			this.popupWindow = null;
			}
		}
	}



var calendar = new CalendarPopup("caldiv");
calendar.showYearNavigation();
calendar.showPopup = Proper_showPopup;
calendar.hidePopup = Proper_hidePopup;
calendar.setMonthNames('Januari', 'Februari', 'Maart', 'April','Mei','Juni', 'Juli','Augustus', 'September','October', 'November', 'December');
calendar.setDayHeaders('Zo','Ma','Di','Wo','Do','Vr','Za');
calendar.setWeekStartDay(1);
calendar.setTodayText('Vandaag');
calendar.offsetX = 0;
calendar.offsetY = 24;

