var isOpera = ( navigator.appName.indexOf("Opera")>-1  || (!window.showHelp && navigator.appName=="Microsoft Internet Explorer"));
var isNS4   = (!isOpera && document.layers) ? true : false;
var isIE    = (!isOpera && document.all   ) ? true : false;
var isIE4   = (!isOpera && document.all && !document.getElementById ) ? true : false;
var isNS6   = (!isOpera && !isIE&&document.getElementById) ? true : false;
var isMac   = navigator.platform.indexOf("Mac")>-1;

function show_info(name){
    lib_OpenWindowCentered('account_show.asp?name='+name,'accountinfo', 520, 430, "Profiel "+unescape(name))
}

function TBInit( blnAlignLeft ) {
	static_blnAlignLeft = blnAlignLeft
	
	document.write ("<table cellpadding=0 cellspacing=0 width=1%><TR align=" + (blnAlignLeft ? "left" : "right") + ">" + (!blnAlignLeft? "<td width=99% >&nbsp</td>" : ""));
}

function TB( strContent ) {
	document.write ('' + (!static_blnAlignLeft ? "<td>&nbsp&nbsp</td>" : "") + 
		"<td nowrap class=button>&nbsp&nbsp" + strContent + "&nbsp&nbsp</td>" +
		(static_blnAlignLeft ? "<td>&nbsp&nbsp</td>" : ""));
}

function TBEnd( blnAlignLeft ) {
	document.write ( (blnAlignLeft ? "<td width=99%></td>" : "") + "</tr></table>");
}

// Eenvoudige validatie, velden die met 'required-' beginnen zijn verplicht
// aanroep in form definitie => onsubmit="return form_valid(this)"
function form_valid(form) {
var tel,objfield,strfieldname,strerror='',blnFirst=true,strSubmitButton='Bewaar';
for (tel=0;tel<form.length;tel++) {
	objfield=form[tel];
	strfieldname=objfield.name;
	if (strfieldname.substring(0,8).toLowerCase()=='required') {
		if (objfield.value=='') {
			if (blnFirst) {
				objfield.focus();
				blnFirst=false;
			}
			strerror+=(' - het veld "'+strfieldname.substring(8)+'" is niet ingevuld.\n');
		} 
	}	
}
if (strerror=='') {
	if (document.all){
		for (tel=0;tel<form.length;tel++) {
			objfield=form[tel];
			if (objfield.type=="submit"||objfield.type=="button")  
		   		objfield.disabled = true;
		} 
	}
	return true;
} else {
	strerror='Het formulier is niet correct of niet volledig ingevuld:\n\n'+strerror+'\nHerstel de fout(en) en druk opnieuw op '+strSubmitButton+'.';
	alert(strerror);
	return false;
}
}

//  Set's the required fields to another background color => <body onload="form_init()">, move the input focus to the first field
function form_init() {}

// Discussion handling 

var arr_items 
var int_itemcount = 0 
var str_search
var str_color1
var str_color2
var str_color_sel
var old_sel_color
var old_sel_id = -1
var str_default_year

var const_type_separator = 1
var const_type_item	   = 2

var cur_thread = new Object();
var cur_forum  = new Object();

// sets's the active forum
function F( forum_id ){
	cur_forum.id = forum_id;
}

// sets's the active thread
function T( thread_id){
	// fill object 
	cur_thread.id = thread_id
	if (int_itemcount>0)
		arr_items[int_itemcount-1].last_item = true;
}

// Creates a new Separator
function S( forum_id, name) {
	var item = new Object();
	
	F( forum_id );
	item.type = const_type_separator;
	item.forum_id = cur_forum.id;
	item.forum_name = name;

	arr_items[int_itemcount] = item;
	int_itemcount++;
}

// Creates a new Item
function I( id, response_to, messagetype, subject, author, datum, found, account) {
	var item = new Object();
	
	item.type = const_type_item;

	// from the F function
	item.forum_id = cur_forum.id;
	
	// from the T function
	item.thread_id = cur_thread.id;
	item.id = id;
	// fill thread object if it's the main thread 
	if (item.id == cur_thread.id) {
		cur_thread.subject = subject;
		cur_thread.author  = author;
		cur_thread.date    = datum;
	}
	
	item.response_to = response_to;
	item.messagetype = messagetype.toLowerCase();
	if (subject=='') {
		item.subject = cur_thread.subject;
		if (item.id != item.thread_id)
			item.subject = 'Re:' + item.subject
	} else
		item.subject = subject;
	item.author =   (author=='') ? cur_thread.author : author;
	item.datum  = (((datum =='') ? cur_thread.date   : datum ).replace("*", str_default_year)).replace("~", '<font class=s>');
	item.level  = response_to!=0 ? (find_parent_level( response_to, int_itemcount-1) + 1) : 1;
	item.foundicon = (found!=0);
	item.account   = (account!=0);
	item.last_item = false;
	
	arr_items[int_itemcount] = item;
	int_itemcount++;
}

function have_reacties( item_id, from ) {
	// a child always follows the parent, thus the array-item should be after the parent item..
	var teller
	for (teller=from; teller<int_itemcount; teller++) {
		if (arr_items[teller].response_to==item_id)
			return true;
	}	
	return false;
}

function find_parent_level( parent_id, from ) {
	// a parent always precedes the child, thus the array-item should be before the added item..
	var teller
	for (teller=from; teller>0; teller--) {
		if (arr_items[teller].id==parent_id)
			return arr_items[teller].level;
	}
	return 1;
}

function InitDisc(searchfor, color1, color2, color_sel, default_year) {
	arr_items = new Array; 
	int_itemcount = 0;
	str_search = searchfor;
	str_color1 = color1;
	str_color2 = color2;
	str_color_sel = color_sel;
	str_default_year = default_year;
}

function hilightrow( id ) {
	if (old_sel_id != -1) {
		document.all('row'+old_sel_id).className = old_sel_color;
	}
	if (document.all('row'+id)) {
	   old_sel_color = document.all('row'+id).className;
	   document.all('row'+id).className = str_color_sel;
	   old_sel_id = id;
	}
}

function WriteDisc() {
	var link 
	var cur_color = str_color1;
	var t;
	var sLine;
	
	document.write ('<tr><th width=65% style=height:18px align=left><font class=titles>&nbsp;Onderwerp</font></th><th width=30% align=left><font class=titles>Door</font></th><th width=5% align=left><font class=titles>Datum</a></th></tr>');
	for (x=0; x<int_itemcount; x++) {
	  cur_item = arr_items[x];
	  with (cur_item) {
	  	if (type==const_type_item) {
	  		link = '<a onclick=javascript:hilightrow('+id+') target=I href="i.asp?F=' + forum_id + '&I=' + id + (str_search!=''? '&S='+str_search:'') + '">';
	  		sLine = '<TR class=' + cur_color + ' id=row' + id + '>';
	  		sLine = sLine + '<TD nowrap>';
	  		if (level>1) {
	  			if (isNS4 || isNS6 || isMac || isIE4 || isOpera) {
	  				for (t=1; t++; t<=level)
	  					sLine = sLine + '&nbsp;&nbsp;&nbsp;'; 
	  			} else {
	  				sLine = sLine + '<font style=text-indent:' + (14*(level-1)) + 'px>'; 
	  			}
			}
	  		sLine = sLine + link + '<img src=i/' + ( foundicon ? 'f' : '') + 'i' + messagetype + (have_reacties(id, x) ? '_r' : '' ) + 
	  						'.gif width=13 height=14 border=0></a>' + 
	  						'&nbsp;' + link + subject + '</a></TD>' +
 	  						'<TD nowrap>' + (account ? '<a title=\"Meer info over deze auteur\" href=# target=\"_self\" onclick="javascript:show_info(\'' + escape(author) + '\');return false;">' :'') + author + (account ? '</a>' : '') + '</TD>' +
	  						'<TD nowrap>' + datum + '</TD>' + 
	  						'</TR>';
	  		
	  		document.write(sLine);
	  		cur_color = cur_color == str_color1 ? str_color2: str_color1;
	  	} else {
	  		document.write ('<tr></tr><tr><th colspan=3 style=height:18px><a href=index.asp?F=' + forum_id + ' target=_top>' + forum_name + '</a></th></tr>');
	  	}
	  }
	}
	document.write ('<TR><TD colspan=4><hr size=1 noshade color=333366></TD></TR></TABLE>');
}

