function adjustpage(usertype)
{
	var show = new Array();
	var hide = new Array();
	switch (usertype){
		case '1':
			show['show_to_admin'] = true;
			show['show_to_moderator'] = true;
			show['show_to_user'] = true;
			break;
		case '2':
			hide['show_to_admin'] = true;
			show['show_to_moderator'] = true;
			show['show_to_user'] = true;
			break;
		case '3':
			hide['show_to_admin'] = true;
			hide['show_to_moderator'] = true;
			show['show_to_user'] = true;
			break;
		default:
			hide['show_to_admin'] = true;
			hide['show_to_moderator'] = true;
			hide['show_to_user'] = true;
	}

	var all = document.getElementsByTagName('div');
	for(var k=0;k<all.length;k++){
		if(show[all[k].className]){
			all[k].style.display = 'inline';
		}else if(hide[all[k].className]){
			all[k].style.display = 'none';
		}
	}
}



// Check image size
function CheckImageSize(img, maxwidth, maxheight)
{
	if (!maxwidth || maxwidth > 400 ) maxwidth = 400;
	if (!maxheight || maxheight > 400 ) maxheight = 400;

	if (img.height <= img.width && img.width > maxwidth)
		img.width = maxwidth;
	else if (img.height > img.width && img.height > maxheight)
		img.height = maxheight;
}

function show(id){
	document.getElementById(id).style.display = 'block';
}

function hide(id){
	document.getElementById(id).style.display = 'none';
}

function submitViaEnter(formfield, evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode :
        ((evt.which) ? evt.which : evt.keyCode);
    if (charCode == 13) {
		document.getElementById(formfield).submit();
		return false;
    }
    return true;
}

function doViaEnter(evt, func) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode :
        ((evt.which) ? evt.which : evt.keyCode);
    if (charCode == 13) {
		eval(func+'();');
		return false;
    }
    return true;
}

function textCounter(field, cntfield ,maxlimit)
{
	if (field.value.length > maxlimit)
	{
		// if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	}
	else
	{
		// otherwise, update 'characters left' counter
		cntfield.value = maxlimit - field.value.length;
	}
}


function insertSmilie(tag, form, field)
{
	document.forms[form].elements[field].value += tag;
    document.forms[form].elements[field].focus();
}



// bbCode control by
// subBlue design
// www.subBlue.com

// Startup variables
var imageTag = false;
var theSelection = false;

// Check for Browser & Platform for PC & IE specific bits
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version

var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
                && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
                && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
var is_moz = 0;

var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac = (clientPC.indexOf("mac")!=-1);

// Helpline messages
b_help = "Vette tekst: [b]tekst[/b]  (alt+b)";
i_help = "Italic tekst: [i]tekst[/i]  (alt+i)";
u_help = "Underline tekst: [u]tekst[/u]  (alt+u)";
q_help = "Quote text: [quote]tekst[/quote]  (alt+q)";
c_help = "Code display: [code]code[/code]  (alt+c)";
l_help = "Lijst: [list]tekst[/list] (alt+l)";
o_help = "Geordende lijst: [list=]tekst[/list]  (alt+o)";
p_help = "Afbeelding: [img]http://www.jouwwebsite.nl/fotos/foto.jpg[/img]  (alt+p)";
w_help = "Link: [url]http://www.website.nl/[/url] of [url=http://www.website.nl/]Dit is een link[/url]  (alt+w)";
a_help = "Alle open BBcode tags sluiten";
s_help = "Letterkleur: [color=red]tekst[/color]  Tip: Je kan ook dit gebruiken: =#FF0000";
f_help = "Lettergrootte: [size=small]Kleine tekst[/size]";

// Define the bbCode tags
bbcode = new Array();
bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[code]','[/code]','[list]','[/list]','[list=]','[/list]','[img]','[/img]','[url]','[/url]');
imageTag = false;

// Shows the help messages in the helpline window
function helpline(help) {
	document.postForm.helpbox.value = eval(help + "_help");
}


// Replacement for arrayname.length property
function getarraysize(thearray) {
	for (i = 0; i < thearray.length; i++) {
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
			return i;
		}
	return thearray.length;
}

// Replacement for arrayname.push(value) not implemented in IE until version 5.5
// Appends element to the array
function arraypush(thearray,value) {
	thearray[ getarraysize(thearray) ] = value;
}

// Replacement for arrayname.pop() not implemented in IE until version 5.5
// Removes and returns the last element of an array
function arraypop(thearray) {
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
}

function bbfontstyle(bbopen, bbclose) {
	var txtarea = document.postForm.post;

	if ((clientVer >= 4) && is_ie && is_win) {
		theSelection = document.selection.createRange().text;
		if (!theSelection) {
			txtarea.value += bbopen + bbclose;
			txtarea.focus();
			return;
		}
		document.selection.createRange().text = bbopen + theSelection + bbclose;
		txtarea.focus();
		return;
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, bbopen, bbclose);
		return;
	}
	else
	{
		txtarea.value += bbopen + bbclose;
		txtarea.focus();
	}
	storeCaret(txtarea);
}


function bbstyle(bbnumber, txtarea) {
	var txtarea = document.getElementById(txtarea);

	txtarea.focus();
	donotinsert = false;
	theSelection = false;
	bblast = 0;

	if (bbnumber == -1) { // Close all open tags & default button names
		while (bbcode[0]) {
			butnumber = arraypop(bbcode) - 1;
			txtarea.value += bbtags[butnumber + 1];
			buttext = eval('document.postForm.addbbcode' + butnumber + '.value');
			eval('document.postForm.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
		}
		imageTag = false; // All tags are closed including image tags :D
		txtarea.focus();
		return;
	}

	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text; // Get text selection
		if (theSelection) {
			// Add tags around selection
			document.selection.createRange().text = bbtags[bbnumber] + theSelection + bbtags[bbnumber+1];
			txtarea.focus();
			theSelection = '';
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, bbtags[bbnumber], bbtags[bbnumber+1]);
		return;
	}

	// Find last occurance of an open tag the same as the one just clicked
	for (i = 0; i < bbcode.length; i++) {
		if (bbcode[i] == bbnumber+1) {
			bblast = i;
			donotinsert = true;
		}
	}

	if (donotinsert) {		// Close all open tags up to the one just clicked & default button names
		while (bbcode[bblast]) {
				butnumber = arraypop(bbcode) - 1;
				txtarea.value += bbtags[butnumber + 1];
				buttext = eval('document.postForm.addbbcode' + butnumber + '.value');
				eval('document.postForm.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
				imageTag = false;
			}
			txtarea.focus();
			return;
	} else { // Open tags

		if (imageTag && (bbnumber != 14)) {		// Close image tag before adding another
			txtarea.value += bbtags[15];
			lastValue = arraypop(bbcode) - 1;	// Remove the close image tag from the list
			document.postForm.addbbcode14.value = "Img";	// Return button back to normal state
			imageTag = false;
		}

		// Open tag
		txtarea.value += bbtags[bbnumber];
		if ((bbnumber == 14) && (imageTag == false)) imageTag = 1; // Check to stop additional tags after an unclosed image tag
		arraypush(bbcode,bbnumber+1);
		eval('document.postForm.addbbcode'+bbnumber+'.value += "*"');
		txtarea.focus();
		return;
	}
	storeCaret(txtarea);
}

// From http://www.massless.org/mozedit/
function mozWrap(txtarea, open, close)
{
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2)
		selEnd = selLength;

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1 + open + s2 + close + s3;
	return;
}

// Insert at Claret position. Code from
// http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

// Check image size
function CheckImageSize(img, maxwidth, maxheight)
{
	if (!maxwidth || maxwidth > 400 ) maxwidth = 400;
	if (!maxheight || maxheight > 400 ) maxheight = 400;

	if (img.height <= img.width && img.width > maxwidth)
		img.width = maxwidth;
	else if (img.height > img.width && img.height > maxheight)
		img.height = maxheight;
}

// Check size of images with specified class
function CheckImagePosts(classname)
{
	var inc = 0;
	var alltags = document.all ? document.all : document.getElementsByTagName( "*" );

	for ( i=0; i< alltags.length; i++ ){
	  if (alltags[i].className == classname)
		  CheckImageSize(alltags[i]);
	}
}

// Clear items from select list
function clearforumlist(list)
{
	for(var i = 0;i < list.length; i++){
		list.options[i].selected = false;
	}
}

function fixFlash()
{
	objects = document.getElementsByTagName("object");
	for (var i = 0; i < objects.length; i++)
	{
		objects[i].outerHTML = objects[i].outerHTML;
	}

	embed = document.getElementsByTagName("embed");
	for (var i = 0; i < embed.length; i++)
	{
		embed[i].outerHTML = embed[i].outerHTML;
	}
}

function popup(pupid,msg) {

    if (document.getElementById(pupid)) {
    	var a = document.getElementById(pupid);
        a.innerHTML=msg;
        a.style.visibility="visible";
        a.style.overflow="hidden";
    }
}

function kill(pupid) {
    if (document.getElementById(pupid)) {
        var a = document.getElementById(pupid);
        a.innerHTML="";
        a.style.visibility="hidden";
        a.style.overflow="hidden";
    }
}

change_clip = function (clip_title,clip_url){
	location.href = clip_url;
}

var clsVideo = new Class({

	initialize: function(count)
	{
		this.count = count;
		this.scrollpos = 0;
		$('next').setStyle('display','block');
	},

	scroll: function(by)
	{
		var orgpos = this.scrollpos;
		this.scrollpos += (by.toInt() * 4);

		if(this.scrollpos < 0){ this.scrollpos = 0; }

		new Fx.Morph('video_scroller', {duration:1500}).start({'left':this.scrollpos * -146});

		//var marginChange = new Fx.Style('video_scroller', 'left', {duration:1500, transition:Fx.Transitions.Cubic.easeInOut});
		//marginChange.start(orgpos * -146, this.scrollpos * -146);

		if((this.scrollpos+4) < this.count){
			$('next').setStyle('display','block');
		}else{
			$('next').setStyle('display','none');
		}
		if((this.scrollpos) > 0){
			$('previous').setStyle('display','block');
		}else{
			$('previous').setStyle('display','none');
		}
	}
});

var clsVote = new Class({

	initialize: function(item, score, type)
	{
		this.item 	   = item;
		this.score 	   = score;
		this.type 	   = type;
	},

	showThumbs: function()
	{
		var votes = new Hash.Cookie('VJ_session_gv', {duration: 30*24*60*60});

		// Get score from the cookie
		var cookieValue = unescape(document.cookie);
		var start = cookieValue.indexOf(':') + 1;
		var end = cookieValue.indexOf('}');
		var userScore = cookieValue.substring(start, end);
		if(userScore == 1){
			userScoreText = 'negatief';
		}else{
			userScoreText = 'positief';
		}

		if(votes.has(this.item))
		{
			$('voteText').set('html','Je hebt al ' + userScoreText + ' gestemd.');
		}
		else
		{
			var thumbs = $$('div.thumb');
			thumbs.each(function(thumb,index){
				thumb.setStyle('cursor','pointer');
				thumb.addEvent('click', function(){ objVote.vote((index*9)+1); });
			});
		}
	},

	vote: function(choice)
	{
		var cookieVotes = new Hash.Cookie('VJ_session_gv', {duration: 30*24*60*60});

		if(cookieVotes.has(this.item))
		{
			return;
		}
		else
		{
			cookieVotes.set(this.item, choice);
			cookieVotes.save();

			$('voteText').set('html','Een moment geduld, jouw stem wordt verwerkt...');
			new Request.HTML(
			{
				url:	'/shared/php/vote.php',
				update: 'score_view'
			}
			).post(
			{
				'int_newsID':	this.item,
				'score':		choice,
				'type':			this.type
			});

			var thumbs = $$('div.thumb');
			thumbs.each(function(thumb,index){
				thumb.removeEvents();
				thumb.setStyle('cursor','default');
			});

			$('voteText').set('html','Je stem is verwerkt.');
		}
	}

});

/**
 * TOOLTIP SCRIPTING
 */
var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip

var offsetdivfrompointerX=14 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=9 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="/layout/images/blank.gif">') //write out pointer image
document.write('<img id="dhtmlpointer2" src="/layout/images/blank.gif">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false

if (ie)
	ieaftrek = 9
else
	ieaftrek = 1

if (ie||ns6)
	var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""
var pointerobj2=document.all? document.all["dhtmlpointer2"] : document.getElementById? document.getElementById("dhtmlpointer2") : ""

function ietruebody()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor)
{
	if (ns6||ie)
	{
		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
		tipobj.innerHTML=thetext
		enabletip=true
		return false
	}
}

function positiontip(e)
{
	if (enabletip)
	{
		var nondefaultpos=false
		var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
		var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

		var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
		var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY
		var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipobj.offsetWidth)
		{
			//move the horizontal position of the menu to the left by it's width
			tipobj.style.left=curX-tipobj.offsetWidth+"px"

			nondefaultpos=true
		}
		else if (curX<leftedge)
			tipobj.style.left="5px"
		else
		{
			//position the horizontal position of the menu where the mouse is positioned
			tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
			pointerobj.style.left=curX+offsetfromcursorX+"px"
			pointerobj2.style.left=curX+offsetfromcursorX+"px"
		}

		//same concept with the vertical position
		if (bottomedge<tipobj.offsetHeight)
		{
			tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
			nondefaultpos=true
			pointerobj.style.top=curY-offsetfromcursorY-ieaftrek+"px"
			pointerobj.style.visibility="visible"

			pointerobj2.style.visibility="hidden"
		}
		else
		{
			tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
			pointerobj2.style.top=curY+offsetfromcursorY+"px"
			pointerobj2.style.visibility="visible"
			pointerobj.style.visibility="hidden"
		}

		tipobj.style.visibility="visible"
	}
}

function hideddrivetip()
{
	if (ns6||ie)
	{
		enabletip=false
		tipobj.style.visibility="hidden"
		pointerobj.style.visibility="hidden"
		pointerobj2.style.visibility="hidden"
		tipobj.style.left="-1000px"
		tipobj.style.backgroundColor=''
		tipobj.style.width=''
	}
}

document.onmousemove=positiontip
//window.onerror = noError;

function noError()
{
	return true;
}

/* ENQUETE */
var enquete_active			= true;
var enquete_url				= 'http://www.surveymonkey.com/s.aspx?sm=X57rOBtKLxtf6uZdUlgXng_3d_3d';
var enquete_site			= 'Vetja.nl';
var enquete_aantal_vragen	= 15;
var enquete_fake_popup		= true;
var enquete_bg_image		= 'contentvlak4';
var enquete_width			= 432;

// Show the question DIV with the settings used in the vars above
function checkEnquete()
{
	if(enquete_active)
	{
		if(MooTools && MooTools.version == '1.11')
		{
			// Check the cookie for an enquete, if not here, show a div with a link to the enquete
			if(Cookie.get('enquete_showed') == false)
			{
				var style = {
					'font-size'			:	'12px',
					'width'				:	enquete_width+'px',
					'z-index'			:	'5000',
					'background-color'	:	'#AED84E;',
					'color'				:	'#185080'
				}
				if(enquete_fake_popup)
				{
					style = $merge({
							'position'	:	'absolute',
							'top'		:	'155px',
							'left'		:	'100px',
							'border'	:	'4px outset #BCDA5C'
							}, style);
				}

				var enquete  = new Element('div',
											{
												'id'	:	'enquete',
												'styles':	style
											});

				var html = '';
				// Header
				html = html +	'<div style="margin: 0px; background-image: url(/layout/images/'+enquete_bg_image+'_kop.jpg); height: 39px;">';
				html = html +	'<div style="margin: 0px; padding-left: 10px; padding-top: 10px; font-size: 15px; font-weight: bold; color:#FFFFFF;">ENQU&Ecirc;TE</div>';
				html = html +	'</div>';
				// Content
				html = html +	'<div style="margin: 0px; padding: 0px 26px 0px 6px; background-image: url(/layout/images/'+enquete_bg_image+'_bg.jpg);">';
				html = html +	'	<p style="margin: 0px;">Geef jouw mening en help mee <strong>'+enquete_site+'</strong> te verbeteren!</p>';
				html = html +	'	<p>Deze enqu&ecirc;te is geheel anoniem, bestaat uit '+enquete_aantal_vragen+' korte vragen en zal niet langer dan twee minuten van jouw tijd in beslag nemen.</p>';
				html = html +	'	<p>Wil je meedoen?</p>';
				html = html +	'	<br/>';
				html = html +	'	<a href="javascript:showEnquete(true);"><span style="color: #FF0000;">Ja, ik help graag even mee</span></a>';
				html = html +	'	<br/><br/>';
				html = html +	'	<a href="javascript:showEnquete(false);"><span style="color: #FF0000;">Sorry, ik wil geen vragenlijst invullen.</span></a>';
				html = html +	'	<br/>';
				html = html +	'</div>';
				// Footer
				html = html +	'<div style="margin: 0px; background-image: url(/layout/images/'+enquete_bg_image+'_bottom.jpg); height: 21px;"></div>';

				enquete.setHTML(html);
				enquete.inject($('content'), 'top');
			}
		}
	}
}

// Load the popup, set the cookie and hide the question DIV
function showEnquete(open_popup)
{
	Cookie.set('enquete_showed','yes',{duration: 60, path: "/"});
	$('enquete').setStyle('display','none');
	if(open_popup)
	{
		var width	= 800;
		var height	= 600;

		var left	= (screen.width/2)-(width/2);
		var top		= (screen.height/2)-(height/2);

		window.open(enquete_url, 'enquete', 'top=' + top + ',left=' + left + ',resizeable=1,scrollbars=1,toolbar=0,location=0,directories=0,status=0,menubar=0,copyhistory=0,width=' + width + ',height=' + height);
	}
}

// Load the Enquete on DOM ready
window.addEvent('domready', function() {checkEnquete();} );

/* END ENQUETE */

function randomDate(id){
	new Request(
	{
		url:		'/shared/php/randomDate',
		onSuccess:	function(responseText, responseXML)
		{
			document.getElementById('publishDate_'+id).value = responseText;
		}
	}
	).post({'id':id});
}

function newsCheck(id,status){
	new Request(
	{
		url:		'/shared/php/newsCheck',
		onSuccess:	function(responseText, responseXML)
		{
			document.getElementById('ok_'+id).style.display = 'none';
			document.getElementById('not_ok_'+id).style.display = 'none';
		}
	}
	).post({
		'id':id,
		'status':status
	});
}