
var glob_root, omgeving, test, versie, res, taal, browser;
var bgKleur, vgKleur, tekstKleur, linkKleur;

omgeving = 'smartserver'; //'thuis'; //'casema';  // te wijzigen bij uploaden

var test = false; // niet wijzigen!!!
if (omgeving == 'thuis') {
   if (document.all) {
   	  glob_root = "/Data/mijn_eigen_site/www/web/"; //IE
   } else {
   	  glob_root = "file:///C|/Data/mijn_eigen_site/www/web/"; //NS + FireFox + Chrome
   }
   test = true;
} else if (omgeving == 'smartserver') {
  	 glob_root = "/";
} else if (omgeving == 'casema') {
  	 glob_root = "/ewout/";
}

taal = 'NL';
if (location.href.substring(location.href.indexOf('.htm')-4, location.href.indexOf('.htm')) == '_eng') {
	// url bevat '_eng.htm'
	taal = 'EN';
}
//alert(taal);

/************************************************/

document._error_messages = new Array();
var foutVenster;

function rootlessUrl(fullUrl) {
   var url = fullUrl;
   /*
   while (url.indexOf("\\\\") >= 0) {
	url = url.replace("\\\\","/");
   }
   glob_root = glob_root.replace(" ","%20");
   var intBeginRlUrl = url.indexOf(glob_root) + glob_root.length - 1;
   url = url.substring(intBeginRlUrl, url.length);
   */
   url = url.replace('http://www.ewout.com', '')
   return url;
}

function doError(msg, url, ln) {
	str = "<html><head>\n"
	if (taal == "EN") {
		str += "<title>Error - www.ewo"+"ut.com</title>\n"
	} else {
		str += "<title>Foutmelding - www.ewo"+"ut.com</title>\n"
	}
	str += "<style>\n"
	str += "body {font-family: arial, helvetica, sans-serif; background: #000000; color: #FFFFFF; margin: 10px;}\n"
	str += "p, h1 {font-family: arial, helvetica, sans-serif; font-size: 10px; margin-left: 10px; margin-right: 10px;}\n"
	str += "h1 {font-size:13px; font-style: italic; margin-bottom: -15px;}\n"
	str += "button {margin: 0; border: 1px solid #FFFFFF; background-color: #FFFFFF; color: black; font-family: verdana, arial, helvetica, sans-serif; font-weight: bold; width: 100px}\n"
	str += "a {color: #FFFFFF; font-weight: 900; text-decoration: none;}\n"
	str += "a:hover {text-decoration: underline;}\n"
	str += "b {font-weight: 900;}\n"
	str += "</style>\n"
	str += "</head>\n"
	str += '<body scroll="no">\n'
	str += "<h1>Oops!</h1>\n"
	str += "<script>\n"
	str += "var glob_root = '"+glob_root+"';\n"
	str += 'var d=document;\n'
	var httpUrl = url;
	while (httpUrl.indexOf("\\") >= 0) {
		httpUrl = httpUrl.replace("\\","/");
	}
	str += 'var kortUrl = window.opener.rootlessUrl("'+httpUrl+'");\n'
	str += 'var foutMelding = "'+msg+'";\n'
	str += 'var regelNr = "'+ln+'";\n'
	if (taal == "EN") {
		str += "d.write('<p>An error has occurred in the file <br><b>'+kortUrl+'</b>.<br>This might cause the page to malfunction.</p>');\n"
		str += "d.write('<p style=\"margin-bottom: 5;\">If you think this error is due to my programming, please <a href=\"mailto:error'+'@ew'+'out.com?subject=JavaScript error&body=In the page '+kortUrl +' on line number '+regelNr+' the following error occurred: '+foutMelding+'. Please describe here what you were doing when the error occurred.\">mail</a> me.</p>');\n"
	} else {	
		str += "d.write('<p>Er is een fout opgetreden in het bestand <br><b>'+kortUrl+'</b>.<br>Hierdoor zou de pagina niet goed kunnen werken.</p>');\n"
		str += "d.write('<p style=\"margin-bottom: 5;\">Als je denkt dat de fout aan mijn programmeerkunsten ligt kun je hem aan mij <a href=\"mailto:fout'+'@ew'+'out.com?subject=JavaScript fout&body=In de pagina '+kortUrl +' op regel nummer '+regelNr+' kreeg ik de volgende foutmelding: '+foutMelding+'. Beschrijf ajb hier wat je deed toen de foutmelding verscheen.\">mailen</a>.</p>');\n"
	}
	str += "d.write('<table style=\"width: 100%;\" cellspacing=0 cellpadding=10><tr><td>');\n"
	if (taal == "EN") {
		str += "d.write('<button onclick=\\\'if (infoArea.style.display!=\"block\") {infoArea.style.display = \"block\";window.resizeTo(400,250);this.innerText=\"Hide\";}else{infoArea.style.display=\"none\";window.resizeTo(400,200);this.innerText=\"Error details\";}\\\'');\n"
		str += "d.write('onmouseover=\"this.style.borderColor=\\\'#000000\\\'\" onmouseout=\"this.style.borderColor=\\\'#FFFFFF\\\'\">Error details</button>');\n"
	} else {	
		str += "d.write('<button onclick=\\\'if (infoArea.style.display!=\"block\") {infoArea.style.display = \"block\";window.resizeTo(400,250);this.innerText=\"Verberg\";}else{infoArea.style.display=\"none\";window.resizeTo(400,200);this.innerText=\"Fout details\";}\\\'');\n"
		str += "d.write('onmouseover=\"this.style.borderColor=\\\'#000000\\\'\" onmouseout=\"this.style.borderColor=\\\'#FFFFFF\\\'\">Fout details</button>');\n"
	}
	str += "d.write('</td><td align=\"right\"><button onclick=\"window.close()\" onmouseover=\"this.style.borderColor=\\\'#000000\\\'\" onmouseout=\"this.style.borderColor=\\\'#FFFFFF\\\'\">OK</button>');\n"
	str += "d.write('</td></tr></table>');\n"
	str += "d.write('<div id=\"infoArea\" style=\"display: none;\">');\n"
	str += "d.write('<div id=\"info\" style=\"border: 1px solid #FFFFFF; margin: 10px; margin-bottom: 0px;\">');\n"
	str += "d.write('<table>');\n"
	if (taal == "EN") {
		str += "d.write('<tr><td><p>Error:</p></td><td><p>'+foutMelding+'</p></td></tr>');\n"
		str += "d.write('<tr><td><p>Line:</p></td><td><p>'+regelNr+'</p></td></tr>');\n"
	} else {	
		str += "d.write('<tr><td><p>Fout:</p></td><td><p>'+foutMelding+'</p></td></tr>');\n"
		str += "d.write('<tr><td><p>Regel:</p></td><td><p>'+regelNr+'</p></td></tr>');\n"
	}
	str += "d.write('</table>');\n"
	str += "d.write('</div>');\n"
	str += "</script>"
	str += '</body>'
	str += '</html>'

	if (!foutVenster || foutVenster.closed) {
		foutVenster = window.open("","_smart_error_win","width=390,height=180");
		var fd = foutVenster.document;
		fd.open();
		fd.write(str);
		fd.close();
		foutVenster.focus();
	}
	return true
}

if (document.all) window.onerror = doError

/************************************************/

versie = navigator.appVersion;
if (versie.indexOf('MSIE') >= 0) {
	versie = versie.substring(versie.indexOf('MSIE'), versie.length);
	versie = parseFloat( versie.substring(5, versie.indexOf(';')) );
} else {
	versie = parseFloat( versie );
}
//alert('['+versie+']');

browser = 'onbekend';
if (navigator.appName == 'Netscape') {
	browser = 'NS';
} else if (navigator.appVersion.indexOf('MSIE') >= 0) {
	browser = 'IE';
}
//alert(browser)

res = screen.width;
//alert('['+res+']');

var d = document;

/************************************************/

d.write('<style type="text/css">');

var Xpos, Ypos;
var breedte, hoogte, html;
if (res <= 800) {
	breedte = 450;
} else {
	breedte = 500;
}
hoogte = 60;
//gets top and left positions based on user's resolution so hint window is centered.
Xpos = (window.screen.width/2) - ((breedte/2) + 10); //half the screen width minus half the new window width (plus 5 pixel borders).
Ypos = (window.screen.height/2) - ((hoogte/2) + 50); //half the screen height minus half the new window height (plus title and status bars).

d.write('#divLaden, #divCommuniceer, #tblRechtermenu {');
d.write('	position: absolute;');
d.write('	top:	   '+Ypos+'px;');
d.write('	left:	   '+Xpos+'px;');
d.write('	height:	   '+hoogte+'px;');
d.write('	width:	   '+breedte+'px;');
d.write('	visibility: visible;');
d.write('	border:	   1px solid #FFFFFF;');
d.write('	background-color: #000000;');
d.write('	padding:   10px;');
d.write('	font-size: 10pt;');
d.write('	font-family: arial, helvetica, sans-serif;');
d.write('	color:	   #FFFFFF;');
d.write('	z-index:   99;');
d.write('}');
d.write('#divCommuniceer {');
d.write('	top:	   100px;');
d.write('	visibility: hidden;');
d.write('	background-repeat: no-repeat;');
d.write('}');
d.write('td.tdCommuniceer {');
d.write('	font-size: 10pt;');
d.write('	font-family: arial, helvetica, sans-serif;');
d.write('	color:	   #FFFFFF;');
d.write('}');

d.write('#tblBlockAll {');
d.write('	position: absolute;');
d.write('	top:	   0px;');
d.write('	left:	   0px;');
d.write('	width:	   '+(res-20)+'px;');
d.write('	height:	   '+(screen.height-145)+'px;'); // was 415
//d.write('	background-color: red;'); //deze doet het
//d.write('	background-color: transparent;'); //deze niet bij div!!
d.write('	visibility: hidden;');
d.write('	z-index:   98;');
d.write('}');

d.write('#tblRechtermenu {');
d.write('	position: absolute;');
d.write('	top:	   150px;');
d.write('	left:	   400px;');
d.write('	height:	   10px;');
d.write('	width:	   10px;');
d.write('	visibility: hidden;');
d.write('	padding:   1px;');
d.write('	background-color: #FFFFFF;');
d.write('	border:	   0px solid #000000;');
d.write('	z-index:   97;');
d.write('}');
d.write('td.rechtermenu, td.rechtermenuActive {');
d.write('	background-color: #000000;');
d.write('	color: #FFFFFF;');
d.write('	font-family: arial, helvetica, sans-serif;');
d.write('	font-size: 8pt;');
d.write('	cursor: hand;');
d.write('}');
d.write('td.rechtermenuActive {');
d.write('	background-color: #FFFFFF;');
d.write('	color: #000000;');
d.write('}');

d.write('input.comm {'); // knoppen van class .comm
d.write('	visibility: hidden;'); // zie stylesheet.js
d.write('	background-color: #FFFFFF;');
d.write('	border:	   1px solid #FFFFFF;'); // outset activeborder of #FFFFFF //solid treedlightface
d.write('	color:	   #000000;');
d.write('	font-family: verdana, arial, helvetica, sans-serif;');
d.write('	font-weight: bold;');
d.write('	width:	   85px;');
d.write('}');

d.write('</style>');

/************************************************/

function getFileName() {
	arrFileName = location.href.split('/');
	return arrFileName[arrFileName.length-1];
}

function getPageTitle() {
	var strDel = "Ewout's site - ";
	var strTitel = document.title;
	if (strTitel.indexOf(strDel) >= 0) {
		strTitel = strTitel.substring(strDel.length, strTitel.length);
	}
	return strTitel;
}

function firstPage() {
	// als een pagina (niet de homepage) wordt geopend in frameset
    var html = '';
    if (taal == 'EN') {
    	html += 'Welcome on <u>www.ewo'+'ut.com<\/u><br>This is not the homepage.<br><br>';
    	html += 'Do you want to go to the homepage?<br>';
    	html += 'There you can adjust the design of this site as you prefer.';
	vraag(html, "location.href='"+glob_root+"home_eng.htm'");
    } else {
    	html += 'Welkom op <u>www.ewo'+'ut.com<\/u><br>Dit is niet de thuispagina.<br><br>';
    	html += 'Wil je naar de thuispagina gaan?<br>';
    	html += 'Je kunt daar de vormgeving van <br>deze site naar eigen keuze instellen.';
	vraag(html, "location.href='"+glob_root+"home.htm'");
    }
}

function vraag(strVraag, actieJa) {
	// actieJa moet als string doorgegeven worden!
	actieJa = actieJa.replace("'","\'");
	actieJa = actieJa.replace('"','\"');
	actieJa = actieJa.replace('/','\/');
	//alert(actieJa);
	var html = '';
	html += '<table><tr><td width="70"><img src="'+glob_root+'confirm.gif" style="border: 0px;"></td><td align="center" class="tdCommuniceer" width="100%" nowrap>'+strVraag.replace('\n','<br>')+'</td></table>';
	//html += strVraag.replace('\n','<br>');
	html += '<form><input type="button" value="OK" class="comm" id="inpVraagOK" onClick="antwoord();'+actieJa+'" onmouseover="this.style.borderColor=\'#000000\'" onmouseout="this.style.borderColor=\'#FFFFFF\'">'
	if (taal == "EN") {
		html += '&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="Cancel" class="comm" id="inpVraagCancel" onClick="antwoord();" onmouseover="this.style.borderColor=\'#000000\'" onmouseout="this.style.borderColor=\'#FFFFFF\'"><\/form>'
	} else {
		html += '&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="Annuleren" class="comm" id="inpVraagCancel" onClick="antwoord();" onmouseover="this.style.borderColor=\'#000000\'" onmouseout="this.style.borderColor=\'#FFFFFF\'"><\/form>'
	}
	//alert('1'+strVraag);
	document.getElementById('divCommuniceer').innerHTML = html;
	//alert('2'+strVraag);
	//document.getElementById('divCommuniceer').style.backgroundImage = 'url('+glob_root+'confirm.gif)';
	showButtons()
	//alert('3'+strVraag);
	document.getElementById('divCommuniceer').style.visibility = 'visible';
	if (versie < 5) {
		document.getElementById('tblBlockAll').style.height = mainContent.scrollHeight+60;
	} else {
		document.getElementById('tblBlockAll').style.height = screen.height-145;
	}
	document.getElementById('tblBlockAll').style.visibility = 'visible';
	if (browser == 'NS') {
		document.getElementById('divCommuniceer').style.height = 100;
	}
	//alert('['+document.getElementById('divCommuniceer').innerHTML.width+']'); // IE 4: getable, not setable
}
function antwoord() {
	//showButtons()
	hideButtons();
	document.getElementById('divCommuniceer').style.visibility = 'hidden';
	document.getElementById('tblBlockAll').style.visibility = 'hidden';
}
function meld(strVraag) {
	var html = '';
	html += '<table><tr><td width="70"><img src="'+glob_root+'alert.gif" style="border: 0px;"></td><td align="center" class="tdCommuniceer" width="100%" nowrap>'+strVraag.replace('\n','<br>')+'</td></table>';
	html += '<form align="center">';
	//html += '<form align="center">'+strVraag.replace('\n','<br>')+'<br><br>';
	html += '<input type="button" value="OK" class="comm" id="inpMeldingOK" onClick="antwoord();" onmouseover="this.style.borderColor=\'#000000\'" onmouseout="this.style.borderColor=\'#FFFFFF\'"><\/form>'
	document.getElementById('divCommuniceer').innerHTML = html;
	//document.getElementById('divCommuniceer').style.backgroundImage = 'url('+glob_root+'alert.gif)';
	showButtons()
	document.getElementById('divCommuniceer').style.visibility = 'visible';
	if (versie < 5) {
		document.getElementById('tblBlockAll').style.height = mainContent.scrollHeight+60;
	} else {
		document.getElementById('tblBlockAll').style.height = screen.height-145;
	}
	document.getElementById('tblBlockAll').style.visibility = 'visible';
	if (browser == 'NS') {
		document.getElementById('divCommuniceer').style.height = 100;
	}
}
function showButtons() {
	//alert(browser)
	if (browser == 'IE') {
		document.styleSheets.styleFormHidden.disabled = false;
	} else {
		//alert('1\n'+typeof document.getElementById('inpMeldingOK'));
		if(document.getElementById('inpMeldingOK') != null) {
			//alert('1.5\n'+document.getElementById('inpMeldingOK').style.visibility);
			document.getElementById('inpMeldingOK').style.visibility = 'visible';
		}
		//alert('2\n'+typeof document.getElementById('inpVraagOK'));
		if(document.getElementById('inpVraagOK') != null) {
			document.getElementById('inpVraagOK').style.visibility = 'visible';
		}
		//alert('3\n'+typeof document.getElementById('inpVraagCancel'));
		if(document.getElementById('inpVraagCancel') != null) {
			document.getElementById('inpVraagCancel').style.visibility = 'visible';
		}
	}

}

function hideButtons() {
	//alert(browser)
	if (browser == 'IE') {
		document.styleSheets.styleFormHidden.disabled = true;
	} else {
		//alert(typeof document.getElementById('inpMeldingOK'))
		if(document.getElementById('inpMeldingOK') != null) {
			document.getElementById('inpMeldingOK').style.visibility = 'hidden';
		}
		if(document.getElementById('inpVraagOK') != null) {
			document.getElementById('inpVraagOK').style.visibility = 'hidden';
		}
		if(document.getElementById('inpVraagCancel') != null) {
			document.getElementById('inpVraagCancel').style.visibility = 'hidden';
		}
	}

}

/************************************************/

if (top.location.href != location.href) {
	//pagina zit in frameset: uitbreken dus
	if (test) {
		top.location.href = glob_root+"/default.htm";
	} else {
		top.location.href = "http://www.ewo"+"ut.com/";
	}
}

/************************************************/

function fromCookieToVar() {
    if (document.cookie != "") {
    	// Haalt de variabelen uit de cookie en maakt er variabelen van.
    	//alert('Er is een cookie gevonden!\n'+document.cookie);
	//document.write(document.cookie);
	var strCookie = document.cookie;
    	var varNaam, varWaarde;
    	while (strCookie.indexOf("=") > 0) {
        	varNaam = strCookie.substring(0, strCookie.indexOf('='));
        	strCookie = strCookie.substring(strCookie.indexOf('=')+1, strCookie.length);
    		if (strCookie.indexOf(";") > 0) {
        	   varWaarde = strCookie.substring(0, strCookie.indexOf(';'));
        	   //scheidingsteken is '; ', twee tekens dus!
    		   strCookie = strCookie.substring(strCookie.indexOf(';')+2, strCookie.length);
    		} else {
    		   varWaarde = strCookie;
    		}
    		//Zet kleuren:
    		if (varNaam.indexOf("Kleur") >= 0) {
    			eval(varNaam+" = '"+varWaarde+"';");
    		}
    	}
    }
}

fromCookieToVar();

/************************************************/

function highlightTD(id) {
	id.className = 'rechtermenuActive';
}

function normalTD(id) {
	id.className = 'rechtermenu';
}

function attentieCommunicatie() {
	if (tblBlockAll.style.visibility == 'visible') {
		document.getElementById('divCommuniceer').focus();
		document.getElementById('divCommuniceer').style.border = '2px solid #FF0000';
		setTimeout("document.getElementById('divCommuniceer').style.border = '1px solid #FFFFFF'",1000);
	}
	return false;
}
d.write('<table id=\"tblBlockAll\" onClick=\"attentieCommunicatie()\"><tr><td><img src=\"'+glob_root+'pixel.gif\" style=\"border: 0px;\"><\/td><\/tr><\/table>');
d.write('<div id=\"divCommuniceer\" align=\"center\" nowrap><\/div>');

d.write('<table id=\"tblRechtermenu\" cellpadding=\"1\" cellspacing=\"1\">');
if (taal == 'EN') {
	d.write('<tr><td nowrap class="rechtermenu" onmouseover="highlightTD(this)" onmouseout="normalTD(this)" onclick="location.href=\'reageer_eng.htm\'">&copy; www.ewo'+'ut.com&nbsp;<\/td><\/tr>');
	d.write('<tr><td nowrap class="rechtermenu" onmouseover="highlightTD(this)" onmouseout="normalTD(this)" onclick="history.back()">Back</a><\/td><\/tr>');
	d.write('<tr style="display:none;" id="trKleurRechts"><td nowrap class="rechtermenu" onmouseover="highlightTD(this)" onmouseout="normalTD(this)" onclick="resetKleur()">Standard colors</a><\/td><\/tr>');
	d.write('<tr><td nowrap class="rechtermenu" onmouseover="highlightTD(this)" onmouseout="normalTD(this)" onclick="window.external.AddFavorite(\'http://www.ewout.com'+rootlessUrl(location.href)+'\', document.title)">Add to Favorites...<\/td><\/tr>');
	d.write('<tr><td nowrap class="rechtermenu" onmouseover="highlightTD(this)" onmouseout="normalTD(this)" onclick="window.print()">Print<\/td><\/tr>');
	d.write('<tr><td nowrap class="rechtermenu" onmouseover="highlightTD(this)" onmouseout="normalTD(this)" onclick="location.reload(true)">Refresh<\/td><\/tr>');
} else {
	d.write('<tr><td nowrap class="rechtermenu" onmouseover="highlightTD(this)" onmouseout="normalTD(this)" onclick="location.href=\'reageer.htm\'">&copy; www.ewo'+'ut.com<\/td><\/tr>');
	d.write('<tr><td nowrap class="rechtermenu" onmouseover="highlightTD(this)" onmouseout="normalTD(this)" onclick="history.back()">Vorige</a><\/td><\/tr>');
	d.write('<tr style="display:none;" id="trKleurRechts"><td nowrap class="rechtermenu" onmouseover="highlightTD(this)" onmouseout="normalTD(this)" onclick="resetKleur()">Standaard kleuren</a><\/td><\/tr>');
	d.write('<tr><td nowrap class="rechtermenu" onmouseover="highlightTD(this)" onmouseout="normalTD(this)" onclick="window.external.AddFavorite(\'http://www.ewout.com'+rootlessUrl(location.href)+'\', document.title)">Toevoegen aan Favorieten...<\/td><\/tr>');
	d.write('<tr><td nowrap class="rechtermenu" onmouseover="highlightTD(this)" onmouseout="normalTD(this)" onclick="window.print()">Afdrukken<\/td><\/tr>');
	d.write('<tr><td nowrap class="rechtermenu" onmouseover="highlightTD(this)" onmouseout="normalTD(this)" onclick="location.reload(true)">Vernieuwen<\/td><\/tr>');
}
d.write('<\/table>');

//alert(rootlessUrl(location.href));

function showRechtermenu(e) {
	if (!document.all) { 
		document.captureEvents(Event.CONTEXTMENU); // was Event.MOUSEMOVE
	}
	var temp_x =(document.all)? event.x : e.pageX;
	var temp_y =(document.all)? event.y : e.pageY;

	if (getPageTitle() == 'Home') trKleurRechts.style.display = 'block'; 
	tblRechtermenu.style.left = temp_x;
	tblRechtermenu.style.top = temp_y;
    	//window.status = "X: " + temp_x + ", Y: " + temp_y;
	tblRechtermenu.style.visibility = 'visible';
	tblRechtermenu.focus();

	return false;
}
function hideRechtermenu() {
	tblRechtermenu.style.visibility = 'hidden';
}

d.oncontextmenu = showRechtermenu;
if (versie < 5) d.ondblclick = showRechtermenu;

d.onclick = hideRechtermenu;


window.onload = PaginaGeladen;

function PaginaGeladen() {
   
   	//SetActiveMenuItem

	if (browser == 'IE') {
		//werkt alleen in IE
   		//alert(location.href+'\n'+divLeftMenu.all.tags('A').length);
   
		   for(var i = 0; i < divLeftMenu.all.tags('A').length; i++) {
			//alert(location.href+'\n'+eval("divLeftMenu.all.tags('A')["+i+"].href"));
			if(eval("divLeftMenu.all.tags('A')["+i+"].href") == location.href) {
				eval("divLeftMenu.all.tags('A')["+i+"].style.fontStyle = 'italic';");
				eval("divLeftMenu.all.tags('A')["+i+"].style.fontWeight = 'bold';");
			}
		   }
		
		if (typeof geladen == 'function') {geladen()}; // functie staat in kieskleuren.js
	}

}

