if (top.frames.length==0) {
	if (location.pathname != '/index.html' && location.pathname != 'index.html' && location.pathname != '/') {
		append="";
		params = getParams();
		if (params) {
			for (var p=0; p<params.length;p++) {
				append="&"+params[p]
			}
		}
		top.location="/index.html?url="+location.pathname+append;
	}
}

path=location.pathname;
var lang=getCookie('lang');if (lang == null) {lang='en'};
fileName=path.substring(path.lastIndexOf("/")+1,path.lastIndexOf(".htm"))+"_"+lang+".html"
// the variables lang and fileName are used in the lang redirection files

function getParams() {
	var idx = document.URL.indexOf('?');
	var params = null;
	if (idx != -1) {
		params = document.URL.substring(idx+1, document.URL.length).split('&');
	}
	return params;
}

function updateLangSwitch(displayedPage) {
	var txt = '<small><sub>[<u onclick=\'fillFrame("/sitemap.html")\'>sitemap</u>]</sub></small>&nbsp;&nbsp;&nbsp;&nbsp;<small><sub>';
	txt+= '<a href="'+displayedPage+'" target="_self" onclick=\'javascript:langSwitch(';
	if (lang=="en") {
		txt += '"du");\'">In het Nederlands';
	} else if (lang=="du") {
		txt += '"en");\'>In English';
	}
	top.document.getElementById('langRef').innerHTML=txt+"</a></sub></small>";
}

function redirect() {
	updateLangSwitch(path)
	window.location=fileName+location.search;
}

var LOC_HOMEPAGE=0
var LOC_ABOUT_US=1
var LOC_OUR_HOME=2
var LOC_PROF=3
var LOC_HOBBIES=4
var LOC_TRIPS=5
var LOC_FAM_EVT=6
var LOC_FAM_TREE=7
var LOC_HOT_NEWS=8
var LOC_NEWS_HEADL=9
var LOC_LINKS=10
var LOC_RECIPES=11
var LOC_CONTACT_US=12
//var LOC_GUESTBOOK=13
var LOC_SITEMAP=13

function getCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
			return getCookieVal(j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function setCookie (name, value) {
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	value = name + "=" + escape (value) +
        	((expires == null) ? "" : ("; expires=" + expires.toUTCString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
	document.cookie = value;
}

function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function getExpTime(days) {
	var expDate = new Date();
	expDate.setTime(expDate.getTime()+(days*24*60*60*1000));
	return expDate;
}

function setPassword(name,page) {
	days=5;
	if (name=='sun') {days=14}
	setCookie(name, hex_sha1(document.pwdForm.pwd.value)+page, getExpTime(days), '/');
}


function goToLink(loc)
{
	priv_loc="http://www.den-baes.be/pwd_protected/"+getCookie(loc);
	checkPageExists(priv_loc)
	return
}

function goToLink(cookieLoc,loc)
{
	days=7;
	if (cookieLoc=='sun') {days=14}
	protectedPath=getCookie(cookieLoc);
	if (protectedPath.indexOf("/") !=-1) {
		protectedPath=protectedPath.substring(0,protectedPath.indexOf("/"))+loc;
	}
	priv_loc="http://www.den-baes.be/pwd_protected/"+protectedPath;
	checkPageExists(priv_loc);
	setCookie(cookieLoc, getCookie(cookieLoc), getExpTime(days), '/');
	return
}

function checkPageExists(url) 
{
	xmlhttp=null
	idx = url.indexOf('?')
	if (idx != 1) {
		url=url.substring(0,idx)
	}
	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest()
	}
	// code for IE
	else if (window.ActiveXObject)
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	if (xmlhttp!=null)
	{
		xmlhttp.onreadystatechange=state_Change
		xmlhttp.open("HEAD",priv_loc,true)
		xmlhttp.send(null)
	}
}

function state_Change()
{
	
	if (xmlhttp.readyState==4)
	{
		// if "OK"
		if (xmlhttp.status==200)
		{
			window.location=priv_loc;
		} else {
			window.location="/wrong_password.html"
		}
	}
}

