var codeif = "1";

if(typeof(innerWidth) == 'undefined')
{
	innerWidth = document.body.clientWidth;
	innerHeight = document.body.clientHeight;
	displaytype = 'block';
}
else
{
	displaytype = 'table-cell';
}

function bold()
{
	var bold = prompt('Voeg de text in', '');
	if(bold)
	{
		bold2 = "[b]"+bold+"[/b]";
		insert_tekst(bold2);
	}
}
function italic()
{
	var italic = prompt('Voeg de text in', '');
	if(italic)
	{
		italic2 = "[i]"+italic+"[/i]";
		insert_tekst(italic2);
	}
}
function underline()
{
	var underline = prompt('Voeg de text in', '');
	if(underline)
	{
		underline2 = "[u]"+underline+"[/u]";
		insert_tekst(underline2);
	}
}
function quote()
{
	var quote = prompt('Voeg de quote in', '');
	if(quote)
	{
		var quotepersoon = prompt('Voeg gequote persoon in of laat leeg', '')
		if(quotepersoon)
		{
quote2 = "[quote=\""+quotepersoon+"\"]"+quote+"[/quote]";
insert_tekst(quote2);
		}
		else
		{
quote2 = "[quote]"+quote+"[/quote]";
insert_tekst(quote2);
		}
	}
}
function code()
{
	if(codeif == "1")
	{
		sjaak = "[code]";
		insert_tekst(sjaak);
		codeif = "0";
	}
	else
	{
		sjaak = "[/code]";
		insert_tekst(sjaak);
		codeif = "1";
	}
}
function img()
{
	var img = prompt('Voeg de url in', '');
	if(img)
	{
		img2 = "[img]"+img+"[/img]";
		insert_tekst(img2);
	}
}
function url()
{
	var url = prompt('Voeg de url in, beginnend met http://', '');
	if(url)
	{
		var urlnaam = prompt('Voeg websitenaam in of laat leeg', '')
		if(urlnaam)
		{
url2 = "[url="+url+"]"+urlnaam+"[/url]";
insert_tekst(url2);
		}
		else
		{
url2 = "[url="+url+"]"+url+"[/url]";
insert_tekst(url2);
		}
	}
}
function insert_tekst(code)
{
	document.getElementById('topictext').value += code;
}
function smilie(code)
{
	code = " "+code+" ";
	document.getElementById('topictext').value += code;
}
function displayOn(nr)
{
	if (document.all)
	{
		document.all[nr].style.display = 'table-cell';
	}
	else if (document.getElementById)
	{
		document.getElementById(nr).style.display = 'table-cell';
	}
}
function displayOff(nr)
{
	if (document.all)
	{
		document.all[nr].style.display = 'none';
	}
	else if (document.getElementById)
	{
		document.getElementById(nr).style.display = 'none';
	}
}
function nieuws()
{
	displayOn('normaal1');
	displayOn('nieuws1');
	displayOn('nieuws2');
	displayOn('nieuws3');
	displayOn('nieuws4');
	displayOn('nieuws5');
	displayOn('nieuws6');
	displayOn('nieuws7');
	displayOn('nieuws8');
	displayOn('algemeen');
	displayOff('interview1');
	displayOff('interview2');
	displayOff('album1');
	displayOff('album2');
	displayOff('album3');
	displayOff('album4');
	displayOff('album5');
}
function interview()
{
	displayOn('algemeen');
	displayOn('normaal1');
	displayOn('interview1');
	displayOn('interview2');
	displayOff('album2');
	displayOff('nieuws1');
	displayOff('nieuws2');
	displayOff('nieuws3');
	displayOff('nieuws4');
	displayOff('nieuws5');
	displayOff('nieuws6');
	displayOff('nieuws7');
	displayOff('nieuws8');
	displayOff('album1');
	displayOff('album2');
	displayOff('album3');
	displayOff('album4');
	displayOff('album5');
}
function normaal()
{
	displayOn('normaal1');
	displayOn('algemeen');
	displayOff('interview1');
	displayOff('interview2');
	displayOff('nieuws1');
	displayOff('nieuws2');
	displayOff('nieuws3');
	displayOff('nieuws4');
	displayOff('nieuws5');
	displayOff('nieuws6');
	displayOff('nieuws7');
	displayOff('nieuws8');
	displayOff('album1');
	displayOff('album2');
	displayOff('album3');
	displayOff('album4');
	displayOff('album5');
}
function f_album()
{
	document.getElementById("album1").style.display = 'table-cell';
	document.getElementById("album2").style.display = 'table-cell';
	document.getElementById("album3").style.display = 'table-cell';
	document.getElementById("album4").style.display = 'table-cell';
	document.getElementById("album5").style.display = 'table-cell';
	document.getElementById("algemeen").style.display = 'none';
	document.getElementById("interview1").style.display = 'none';
	document.getElementById("interview2").style.display = 'none';
	document.getElementById("normaal1").style.display = 'none';
	document.getElementById("nieuws1").style.display = 'none';
	document.getElementById("nieuws2").style.display = 'none';
	document.getElementById("nieuws3").style.display = 'none';
	document.getElementById("nieuws4").style.display = 'none';
	document.getElementById("nieuws5").style.display = 'none';
	document.getElementById("nieuws6").style.display = 'none';
	document.getElementById("nieuws7").style.display = 'none';
	document.getElementById("nieuws8").style.display = 'none';
}

function youtube(id, naam)
{
	htmlstring = '<table width="100%" cellspacing="0" cellpadding="3"><tr><td class="td1-sm" align="center"><b>'+naam+'</b></td><td class="td1-sm" onclick="javascript:sluit()"><b>X</b></td></tr><tr><td colspan="2" align="center" class="td3"><object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/'+id+'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'+id+'" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object></td></tr></table>';
	document.getElementById("popup").innerHTML = htmlstring;
	document.getElementById("popup").style.visibility = 'visible';
}
function stats()
{
	htmlstring = '<table width="100%" cellspacing="0" cellpadding="3"><tr><td class="td1" align="center" colspan="3"><b>&nbsp;&nbsp;&nbsp;&nbsp;STATS</b></td><td class="td1" onclick="javascript:sluit()"><b>X</b></td></tr><tr><td class="td5" valign="top" align="left">Aantal albums</td><td class="td5" valign="top" align="left"><b>269</b></td><td class="td5" valign="top" align="left">Aantal verzamelalbums</td><td class="td7" valign="top" align="left"><b>70</b></td></tr><tr><td class="td5" valign="top" align="left">Aantal tracks op albums</td><td class="td5" valign="top" align="left"><b>3843</b></td><td class="td5" valign="top" align="left">Aantal tracks op verzamelalbums</td><td class="td7" valign="top" align="left"><b>1249</b></td></tr><tr><td class="td5" valign="top" align="left">Gemiddeld aantal tracks per album</td><td class="td5" valign="top" align="left"><b>14.29</b></td><td class="td5" valign="top" align="left">Gemiddeld aantal tracks per verzamelalbum</td><td class="td7" valign="top" align="left"><b>17.84</b></td></tr><tr><td class="td5" valign="top" align="left">Aantal skits op albums</td><td class="td5" valign="top" align="left"><b>42</b></td><td class="td5" valign="top" align="left">Aantal skits op verzamelalbums</td><td class="td7" valign="top" align="left"><b>7</b></td></tr><tr><td class="td6" valign="top" align="left">Gemiddeld aantal skits per album</td><td class="td6" valign="top" align="left"><b>0.16</b></td><td class="td6" valign="top" align="left">Gemiddeld aantal skits per verzamelalbum</td><td class="td3b" valign="top" align="left"><b>0.03</b></td></tr><tr><td class="td3" valign="top" align="left" colspan="4">&nbsp;</td></tr><tr><td class="td5" valign="top" align="left">Aantal artiesten</td><td class="td5" valign="top" align="left"><b>180</b></td><td class="td5" valign="top" align="left">Gemiddeld aantal albums per artiest</td><td class="td7" valign="top" align="left"><b>1.49</b></td></tr><tr><td class="td6" valign="top" align="left">Gemiddeld aantal tracks per artiest</td><td class="td6" valign="top" align="left"><b>21.35</b></td><td class="td6" valign="top" align="left">Gemiddeld aantal skits per artiest</td><td class="td3b" valign="top" align="left"><b>0.23</b></td></tr></table>';
	document.getElementById("popup").innerHTML = htmlstring;
	document.getElementById("popup").style.visibility = 'visible';
}
function browserwidth()
{
	document.getElementById("width").style.visibility = 'visible';
}
function sluit()
{	
	document.getElementById("popup").innerHTML = '';
	document.getElementById("popup").style.visibility = 'hidden';
}
function verander(id)
{
	if(id == "1")
	{
		document.getElementById("1").style.display = 'block';
		document.getElementById("2").style.display = 'none';
	}
	else
	{
		document.getElementById("1").style.display = 'none';
		document.getElementById("2").style.display = 'block';
	}
}
function aan(id, nummer)
{
	for(i=1;i<=nummer;i++)
	{
		var nummeri = id+'-'+i;
		document.getElementById(nummeri).style.backgroundColor = '#CEAA56';
	}
}
function uit(id, nummer)
{
	for(i=1;i<=nummer;i++)
	{
		var nummeri = id+'-'+i;
		document.getElementById(nummeri).style.backgroundColor = '#DFC48B';
	}
}
function uit2(id, nummer)
{
	for(i=1;i<=nummer;i++)
	{
		var nummeri = id+'-'+i;
		document.getElementById(nummeri).style.backgroundColor = '#DFC17C';
	}
}
function uit3(id, nummer)
{
	for(i=1;i<=nummer;i++)
	{
		var nummeri = id+'-'+i;
		document.getElementById(nummeri).style.backgroundColor = '#DDB766';
	}
}

function nl2br(str)
{
   if(typeof(str)=="string") return str.replace(/(\r\n)|(\n\r)|\r|\n/g,"<br />");
   else return str;
}
function quickedit(id, text, uid)
{
	text2 = text.replace(/REPLACEDENTER/g, '\r\n');
	document.getElementById(id).innerHTML = '<b>Quick edit</b><br /><textarea id="text'+id+'" rows="7" cols="75">'+text2+'</textarea><br /><input type="button" onclick="javascript:bewaar(\'text'+id+'\')" value="Bewaar" /> (BBcodes moeten herladen worden om weer te zien.)';
	document.getElementById(id).name = uid;
}
function bewaar(id)
{
	var nieuwetext = nl2br(document.getElementById(id).value);
	nieuwetext = nieuwetext.replace(/&amp;/g, '&');
	postid = id.slice(4);

	nieuwetext2 = nieuwetext.replace(/:P/gi, ' <img src=\"images/smilies/smile.gif\" alt=\"\" /> ');
	nieuwetext2 = nieuwetext2.replace(/:\)/gi, ' <img src=\"images/smilies/puh2.gif\" alt=\"\" /> ');
	nieuwetext2 = nieuwetext2.replace(/8\)/gi, ' <img src=\"images/smilies/coool.gif\" alt=\"\" /> ');
	nieuwetext2 = nieuwetext2.replace(/:@/gi, ' <img src=\"images/smilies/frown.gif\" alt=\"\" /> ');
	nieuwetext2 = nieuwetext2.replace(/:duh:/gi, ' <img src=\"images/smilies/grmm.gif\" alt=\"\" /> ');
	nieuwetext2 = nieuwetext2.replace(/:hmm:/gi, ' <img src=\"images/smilies/hmmz.gif\" alt=\"\" /> ');
	nieuwetext2 = nieuwetext2.replace(/:z/gi, ' <img src=\"images/smilies/rolleyes.gif\" alt=\"\" /> ');
	nieuwetext2 = nieuwetext2.replace(/:whatever:/gi, ' <img src=\"images/smilies/whatever.gif\" alt=\"\" /> ');
	nieuwetext2 = nieuwetext2.replace(/:denk:/gi, ' <img src=\"images/smilies/denk.gif\" alt=\"\" /> ');
	nieuwetext2 = nieuwetext2.replace(/:\|/gi, ' <img src=\"images/smilies/nosmile.gif\" alt=\"\" /> ');
	nieuwetext2 = nieuwetext2.replace(/\(L\)/gi, ' <img src=\"images/smilies/love.gif\" alt=\"\" /> ');
	nieuwetext2 = nieuwetext2.replace(/\(K\)/gi, ' <img src=\"images/smilies/puh.gif\" alt=\"\" /> ');
	nieuwetext2 = nieuwetext2.replace(/:kus:/gi, ' <img src=\"images/smilies/puh.gif\" alt=\"\" /> ');
	nieuwetext2 = nieuwetext2.replace(/:$/gi, ' <img src=\"images/smilies/bloos.gif\" alt=\"\" /> ');
	nieuwetext2 = nieuwetext2.replace(/:aai:/gi, ' <img src=\"images/smilies/aai.gif\" alt=\"\" /> ');
	nieuwetext2 = nieuwetext2.replace(/\\m\//gi, ' <img src=\"images/smilies/rock.gif\" alt=\"\" /> ');
	nieuwetext2 = nieuwetext2.replace(/:w/gi, ' <img src=\"images/smilies/whatever.gif\" alt=\"\" /> ');
	nieuwetext2 = nieuwetext2.replace(/:loser:/gi, ' <img src=\"images/smilies/loser.gif\" alt=\"\" /> ');
	nieuwetext2 = nieuwetext2.replace(/;\)/gi, ' <img src=\"images/smilies/wink.gif\" alt=\"\" /> ');
	nieuwetext2 = nieuwetext2.replace(/:c/gi, ' <img src=\"images/smilies/clown.gif\" alt=\"\" /> ');
	nieuwetext2 = nieuwetext2.replace(/:D/gi, ' <img src=\"images/smilies/roflol.gif\" alt=\"\" /> ');
	nieuwetext2 = nieuwetext2.replace(/:'\(/gi, ' <img src=\"images/smilies/sadley.gif\" alt=\"\" /> ');
	nieuwetext2 = nieuwetext2.replace(/:'\)/gi, ' <img src=\"images/smilies/huillach.gif\" alt=\"\" /> ');

	document.getElementById(postid).innerHTML = nieuwetext2;
	var uid = document.getElementById(postid).name
	var opslag = new XMLHttpRequest;
	opslag.open('GET', 'includes/opslag.php?text='+nieuwetext+'&id='+postid+'&uid='+uid);
	opslag.send(null);
}
function inuitklap(id)
{
	if(document.getElementById(id).style.display != 'none')
	{
		document.getElementById(id).style.display = 'none';
		document.getElementById(id).colSpan = '2';
	}
	else
	{
		document.getElementById(id).style.display = displaytype;
		document.getElementById(id).colSpan = '2';
	}
}
function leegzoekveld()
{
	var zvtext = document.getElementById('zoekveld').value;

	if(zvtext == 'Zoek in archief')
	{
		document.getElementById('zoekveld').value = '';
	}
}
