/* ========================
	External links function
======================== */
function externalLinks() {
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 } 
} 

function open_plaatje(mypage, myname, w, h) {
	var scroll = 'no';
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no'
	win = window.open(mypage, myname, winprops)

	if (
		parseInt(navigator.appVersion) >= 4) { win.window.focus(); 
	}
	
	win.document.open();
	win.document.writeln('<html>');
	win.document.writeln('<head>');
	win.document.writeln('<title>'+myname+'</title>');
	win.document.writeln('</head>');
	win.document.writeln('<body background="'+mypage+'" margin="0" padding="0">');
	win.document.writeln('</body>');
	win.document.writeln('</html>');
	win.document.close();
}

function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0'
	win = window.open(mypage, myname, winprops)
	//win.resizeTo(w, h);
	win.moveTo(winl, wint);

	if (
		parseInt(navigator.appVersion) >= 4) { win.window.focus();
	}

	win.document.open();
	win.document.writeln('<html>');
	win.document.writeln('<head>');
	win.document.writeln('<title>'+myname+'</title>');
	win.document.writeln('</head>');
	win.document.writeln('<body background="'+mypage+'" margin="0" padding="0">');
	win.document.writeln('</body>');
	win.document.writeln('</html>');
	win.document.close();
}

/* Begin utocomplete functions */

function checkProvIsEmpty(obj, provincie) {
	prov = document.getElementById(provincie);
	if(provincie.value == "") {
   	alert("U heeft nog geen provincie gekozen");
      provincie.focus();
      obj.value = "";
   }
}

/* End autocomplete functions */
function tableruler() {
	if (document.getElementById && document.createTextNode)
	{
   	var tables=document.getElementsByTagName('table');
	   for (var i=0;i<tables.length;i++) {
		   if(tables[i].className=='ruler')	{
     			var trs=tables[i].getElementsByTagName('tr');
     			for(var j=0;j<trs.length;j++) {
      			if(trs[j].parentNode.nodeName=='TBODY' && trs[j].parentNode.nodeName!='TFOOT') {
       				trs[j].onmouseover=function(){this.className='ruled';return false;}
		       		trs[j].onmouseout=function(){this.className='';return false;}
     				}
   			}
 			}
  		}
 	}
}

function sfHover() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

function onLoadPage() {
	externalLinks();
   tableruler();
   sfHover();
}


var ShowImage = function(obj, width, height) {
	this.view();
	
	this.objects = null;
	this.sluiten = null;
	this.activeFoto = null;
	this.fotosBox = null;
	this.box = null;
	this.height = height;
	this.width = width;
	
	if(this.height > 450) {
		this.width = this.width - (this.height - 450);
		this.height = 450;
	}
	this.formatField(obj);
	
	
}
ShowImage.prototype = {
	view: function() {
		this.divBackground = document.createElement("div");
		this.divBackground.style.height = document.body.offsetHeight + "px";
		this.divBackground.style.width = "100%";
		this.divBackground.style.position = "absolute";
		this.divBackground.style.top = "0px";
		this.divBackground.style.left = "0px";
		this.divBackground.style.zIndex = "1000";
		this.divBackground.style.background = "black";
		this.divBackground.style.filter = "alpha(opacity=30)";
		this.divBackground.style.opacity = "0.3";
		this.divBackground.innerHTML = "&nbsp;";
		
		document.body.appendChild(this.divBackground);
	}, 
	formatField: function(obj) {
		this.objects = obj;
		
		this.fotosBox = document.createElement("div");
		this.fotosBox.innerHTML = obj.parentNode.parentNode.outerHTML;
		
		this.box = document.createElement("div");
		var newTop = 80;
		
		var ScrollTop = document.body.scrollTop;
		if (ScrollTop == 0) {
			if (window.pageYOffset)
				ScrollTop = window.pageYOffset;
			else
				ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		}

		newTop += ScrollTop
		//alert(document.body.scrollTop + "--" + window.pageYOffset)
		this.box.style.cssText = "padding:5px;z-index:2000;top:" + newTop + "px;left:50%;position:absolute;background:#fff;";
		
		this.activeFoto = document.createElement("img");
		this.activeFoto.alt = "";
		this.activeFoto.style.width = this.width + "px";
		this.activeFoto.style.height = this.height + "px";
		this.activeFoto.src = obj.parentNode.href;
		
		var newObj = this;
		
		this.sluiten = document.createElement("a");
		this.sluiten.href = "javascript:void(0);";
		this.sluiten.innerHTML = "[ Sluiten ]";
		this.sluiten.style.display = "block";
		this.sluiten.style.clear = "both";
		this.sluiten.onclick = function() {
			newObj.close();
		}
		
		this.header = document.createElement("h2");
		this.header.innerHTML = "Foto's";
		this.header.style.display = "block";
		this.box.appendChild(this.header);
		
		this.fotosBox = document.createElement("div");
		this.box.appendChild(this.activeFoto);
		this.box.appendChild(this.fotosBox);
		this.box.appendChild(this.sluiten);
		document.body.appendChild(this.box);
		
		this.box.style.marginLeft = "-" + (this.box.offsetWidth/2) + "px";
		this.imagesBox();
	},
	imagesBox: function() {
		
		var par = "<UL>" + this.objects.parentNode.parentNode.parentNode.innerHTML + "</UL>";
		//if(par) {
			//alert(this.objects.parentNode.parentNode.parentNode.innerHTML)
		//}
		this.fotosBox.innerHTML = par;
		this.fotosBox.style.paddingTop = "5px";
		this.fotosBox.style.textAlign = "center";
		//this.fotosBox.style.textAlign = "center";
		this.fotosBox.getElementsByTagName("ul")[0].style.cssText = "float:left;list-style:none;";
		for(var i = 0; i < this.fotosBox.getElementsByTagName("li").length; i++) {
			this.fotosBox.getElementsByTagName("li")[i].style.cssText = "margin:0px;padding:2px;float:left;list-style:none;";
		}
		
		var newObj = this;
		for(var i = 0; i < this.fotosBox.getElementsByTagName("img").length; i++) {
			this.fotosBox.getElementsByTagName("img")[i].onclick = function() {
				newObj.switchImage(this);
			}
		}
		this.box.style.marginLeft = "-" + (this.box.offsetWidth/2) + "px";
	},
	switchImage: function(obj) {
		this.activeFoto.src = obj.parentNode.href;
		
		var newImg = new Image();
		newImg.src = obj.parentNode.href;
		//alert(newImg)
		var height = newImg.height;
		var width = newImg.width;
		
		if(height > 450) {
			this.activeFoto.style.width = width - (height - 450);
			this.activeFoto.style.height = 450;
		} else {
			
			if(width > parseInt(this.activeFoto.style.width)) {
				this.activeFoto.style.width = width;
			}
			//this.activeFoto.style.width = width;
		}
	},
	close: function() {
		try {
			document.body.removeChild(this.divBackground);
			document.body.removeChild(this.box);
		} catch(e) {
			
		}
	}
}

window.onload = onLoadPage;

