//*****************************************************************************************************************
// NoqBox
//*****************************************************************************************************************
(function($){$.noqbox=function(options){var settings={labels:"Ok|Cancel",ajax:"",html:"",overlay:true,opacity:0.7,title:"&nbsp;",closebutton:false,confirm:false,onconfirm:function(){}};if(options){$.extend(settings,options);}
function create(){if($('#noqbox').length>0)
$('#noqbox').stop().remove();showOverlay();var html='<table id="noqbox" style="display: none;"><tr><td><div id="noqbox_div"><div class="title">'+(settings.closebutton?'<div class="noqbox_close"></div>':"")+settings.title+'</div><div class="noqbox_inner"></div></div></td></tr></table>';$('body').append(html);if(settings.closebutton){$("#noqbox .title .noqbox_close").click(function(){$(document).trigger('noqbox.close');});}
$('#noqbox').click(function(){$(document).trigger('noqbox.close');});$('#noqbox_div').click(function(e){e.stopPropagation();});$(document).keydown(function(e){if(e.keyCode==27){e.preventDefault();close();}});}
function close(){$(document).trigger('noqbox.close');return false;}
function getPageScroll(){var xScroll,yScroll;if(self.pageYOffset){yScroll=self.pageYOffset;xScroll=self.pageXOffset;}else if(document.documentElement&&document.documentElement.scrollTop){yScroll=document.documentElement.scrollTop;xScroll=document.documentElement.scrollLeft;}else if(document.body){yScroll=document.body.scrollTop;xScroll=document.body.scrollLeft;}
return new Array(xScroll,yScroll)}
function getPageHeight(){var windowHeight;if(self.innerHeight){windowHeight=self.innerHeight;}else if(document.documentElement&&document.documentElement.clientHeight){windowHeight=document.documentElement.clientHeight;}else if(document.body){windowHeight=document.body.clientHeight;}
return windowHeight;}
function showOverlay(){if(settings.overlay==true){if($('#noqbox_overlay').length==0)
$("body").append('<div id="noqbox_overlay" style="display: none;"></div>');$('#noqbox_overlay').css('opacity',settings.opacity).click(function(){$(document).trigger('noqbox.close')}).show();}}
create();if(settings.confirm!==false){$(".noqbox_inner").html('<div class="confirm">'+settings.confirm+'</div><div class="confirm2"><div class="dialog_button button" id="noqbox_ok">'+settings.labels.split("|")[0]+'</div><div class="dialog_button button" id="noqbox_cancel">'+settings.labels.split("|")[1]+'</div></div>');$("#noqbox_ok").click(function(){$(document).bind('noqbox.onconfirm',settings.onconfirm);$(document).trigger('noqbox.onconfirm');close();});$("#noqbox_cancel").click(function(){close();});}else{if(settings.ajax!=""){$(".noqbox_inner").load(settings.ajax);}else{$(".noqbox_inner").html(settings.html);}}
$('#noqbox').css({top:getPageScroll()[1]+(getPageHeight()/5)}).show();};$(document).bind('noqbox.close',function(){$('#noqbox').fadeOut(function(){$('#noqbox').remove();})
$('#noqbox_overlay').remove();$(document).trigger('noqbox.afterclose');})})(jQuery);

//*****************************************************************************************************************
// Cursormessage
//*****************************************************************************************************************
if(jQuery){(function($){$.cursorMessageData={};$(window).ready(function(e){if($('#cursorMessageDiv').length==0){$('body').append('<div id="cursorMessageDiv">&nbsp;</div>');$('#cursorMessageDiv').hide();}
$('body').mousemove(function(e){$.cursorMessageData.mouseX=e.pageX;$.cursorMessageData.mouseY=e.pageY;if($.cursorMessageData.options!=undefined)$._showCursorMessage();});});$.extend({cursorMessage:function(message,options){if(options==undefined)options={};if(options.offsetX==undefined)options.offsetX=5;if(options.offsetY==undefined)options.offsetY=5;if(options.hideTimeout==undefined)options.hideTimeout=5000;var hideCursorMessage=function(){$('#cursorMessageDiv').html(message).fadeOut('slow');};$('#cursorMessageDiv').stop(1,1);$('#cursorMessageDiv').show().html(message);if(jQuery.cursorMessageData.hideTimoutId!=undefined)clearTimeout(jQuery.cursorMessageData.hideTimoutId);jQuery.cursorMessageData.hideTimoutId=setTimeout(hideCursorMessage,options.hideTimeout);jQuery.cursorMessageData.options=options;$._showCursorMessage();},_showCursorMessage:function(){$('#cursorMessageDiv').css({top:($.cursorMessageData.mouseY+$.cursorMessageData.options.offsetY)+'px',left:($.cursorMessageData.mouseX+$.cursorMessageData.options.offsetX)})}});})(jQuery);}

//*****************************************************************************************************************
// Suggest
//*****************************************************************************************************************
(function($){$.suggest=function(input,options){var $input=$(input).attr("autocomplete","off");var $results=$(document.createElement("ul"));var timeout=false;var prevLength=0;var cache=[];var cacheSize=0;var boxwidth=$(input).css("width");$results.addClass(options.resultsClass).appendTo('body');resetPosition();$(window).load(resetPosition).resize(resetPosition);$input.blur(function(){setTimeout(function(){$results.hide()},200);});try{$results.bgiframe();}catch(e){}
if($.browser.mozilla)
$input.keypress(processKey);else
$input.keydown(processKey);function resetPosition(){var offset=$input.offset();$results.css({top:(offset.top+input.offsetHeight)+'px',left:offset.left+'px'});}
function processKey(e){if((/27$|38$|40$/.test(e.keyCode)&&$results.is(':visible'))||(/^13$|^9$/.test(e.keyCode)&&getCurrentResult())){if(e.preventDefault)
e.preventDefault();if(e.stopPropagation)
e.stopPropagation();e.cancelBubble=true;e.returnValue=false;switch(e.keyCode){case 38:prevResult();break;case 40:nextResult();break;case 9:case 13:selectCurrentResult();break;case 27:$results.hide();break;}}else if($input.val().length!=prevLength){if(timeout)
clearTimeout(timeout);timeout=setTimeout(suggest,options.delay);prevLength=$input.val().length;}}
function suggest(){var q=$.trim($input.val());if(q.length>=options.minchars){cached=checkCache(q);if(cached){displayItems(cached['items']);}else{$.get(options.source,{q:q},function(txt){$results.hide();var items=parseTxt(txt,q);displayItems(items);addToCache(q,items,txt.length);});}}else{$results.hide();}}
function checkCache(q){for(var i=0;i<cache.length;i++)
if(cache[i]['q']==q){cache.unshift(cache.splice(i,1)[0]);return cache[0];}
return false;}
function addToCache(q,items,size){while(cache.length&&(cacheSize+size>options.maxCacheSize)){var cached=cache.pop();cacheSize-=cached['size'];}
cache.push({q:q,size:size,items:items});cacheSize+=size;}
function displayItems(items){if(!items)
return;if(!items.length){$results.hide();return;}
var html='';for(var i=0;i<items.length;i++)
html+='<li>'+items[i]+'</li>';$results.html(html).show();$results.css("width",boxwidth);$results.children('li').mouseover(function(){$results.children('li').removeClass(options.selectClass);$(this).addClass(options.selectClass);}).click(function(e){e.preventDefault();e.stopPropagation();selectCurrentResult();});}
function parseTxt(txt,q){var items=[];var tokens=txt.split(options.delimiter);for(var i=0;i<tokens.length;i++){var token=$.trim(tokens[i]);if(token){token=token.replace(new RegExp(q,'ig'),function(q){return'<span class="'+options.matchClass+'">'+q+'</span>'});items[items.length]=token;}}
return items;}
function getCurrentResult(){if(!$results.is(':visible'))
return false;var $currentResult=$results.children('li.'+options.selectClass);if(!$currentResult.length)
$currentResult=false;return $currentResult;}
function selectCurrentResult(){$currentResult=getCurrentResult();if($currentResult){$input.val($currentResult.text());$results.hide();if(options.onSelect)
options.onSelect.apply($input[0]);}}
function nextResult(){$currentResult=getCurrentResult();if($currentResult)
$currentResult.removeClass(options.selectClass).next().addClass(options.selectClass);else
$results.children('li:first-child').addClass(options.selectClass);}
function prevResult(){$currentResult=getCurrentResult();if($currentResult)
$currentResult.removeClass(options.selectClass).prev().addClass(options.selectClass);else
$results.children('li:last-child').addClass(options.selectClass);}}
$.fn.suggest=function(source,options){if(!source)
return;options=options||{};options.source=source;options.delay=options.delay||100;options.resultsClass=options.resultsClass||'ac_results';options.selectClass=options.selectClass||'ac_over';options.matchClass=options.matchClass||'ac_match';options.minchars=options.minchars||1;options.delimiter=options.delimiter||'\n';options.onSelect=options.onSelect||false;options.maxCacheSize=options.maxCacheSize||65536;this.each(function(){new $.suggest(this,options);});return this;};})(jQuery);

//*****************************************************************************************************************
// Constrain (form validatie)
//*****************************************************************************************************************
(function($){$.fn.constrain=function(opt){opt=$.extend(true,{},{limit:{},prohibit:{chars:"",regex:false},allow:{chars:"",regex:false}},opt);function isProhibitedByLimit(input,e){var prohibited=false;$.each(opt.limit,function(token,idx){var max=this;if(token.charCodeAt(0)==e.which){prohibited=max<0?false:max<$(input).val().split(token).length;return false;}});return prohibited;};function isConfigured(item){return item.chars.length>0||(item.regex&&item.regex.length>0);};function match(item,input,e){var arr=item.chars.split("");for(var i in arr){var token=arr[i];if(token.charCodeAt(0)==e.which){return true;}}
if(item.regex){var re=new RegExp(item.regex);if(re.test(String.fromCharCode(e.which))){return true;}}
return false;};function isProhibited(input,e){if(e.which==0||e.which==8||e.which==27){return false;}
var prohibit=isConfigured(opt.prohibit)?match(opt.prohibit,input,e):false;var allow=isConfigured(opt.allow)?match(opt.allow,input,e):true;var limited=isProhibitedByLimit(input,e);return prohibit||!allow||limited;};return this.each(function(){$(this).keypress(function(e){if(isProhibited(this,e)){e.preventDefault();}});});};$.fn.numeric=function(opt){opt=$.extend(true,{},{onblur:true,format:""},opt);var parts=opt.format.split(".");var precision=parts.length>1?parts[1].length:false;return this.each(function(){var allowRe="\\d";if(opt.format.indexOf(".")>-1){allowRe+="\\.";}
if(opt.format.indexOf(",")>-1){allowRe+=",";}
var constraintOptions={allow:{regex:"["+allowRe+"]"},limit:{".":1}};$(this).constrain(constraintOptions);if(precision){$(this).blur(function(e){var n=parseFloat($(this).val());if(!isNaN(n)){var val=$(this).val();$(this).val($.formatNumber(val,opt.format));}});if(!opt.onblur){var prec=new RegExp("\\d+\\.*\\d{0,"+precision+"}");$(this).keyup(function(e){if((e.which<48&&e.which>57)||(e.which<96&&e.which>105)){return;}
var val=$(this).val();$(this).val(val.match(prec));});}}});};})(jQuery);(function($){$.numericFormat=$.numericFormat||{};$.numericFormat.formats=$.numericFormat.formats||new Array();$.extend({formatNumber:function(num,format){function _numberFormat(num,format,context){function createNewFormat(format,formatName){var code="var "+formatName+" = function(num){\n";code+="num = num.replace(/,/,'');";var formats=format.split(";");switch(formats.length){case 1:code+=createTerminalFormat(format);break;case 2:code+="return (num < 0) ? _numberFormat(num,\""
+escape(formats[1])
+"\", 1) : _numberFormat(num,\""
+escape(formats[0])
+"\", 2);";break;case 3:code+="return (num < 0) ? _numberFormat(num,\""
+escape(formats[1])
+"\", 1) : ((num == 0) ? _numberFormat(num,\""
+escape(formats[2])
+"\", 2) : _numberFormat(num,\""
+escape(formats[0])
+"\", 3));";break;default:code+="throw 'Too many semicolons in format string';";break;}
return code+"};";};function createTerminalFormat(format){if(format.length>0&&format.search(/[0#?]/)==-1){return"return '"+escape(format)+"';\n";}
var code="var val = (context == null) ? new Number(num) : Math.abs(num);\n";var thousands=false;var lodp=format;var rodp="";var ldigits=0;var rdigits=0;var scidigits=0;var scishowsign=false;var sciletter="";m=format.match(/\..*(e)([+-]?)(0+)/i);if(m){sciletter=m[1];scishowsign=(m[2]=="+");scidigits=m[3].length;format=format.replace(/(e)([+-]?)(0+)/i,"");}
var m=format.match(/^([^.]*)\.(.*)$/);if(m){lodp=m[1].replace(/\./g,"");rodp=m[2].replace(/\./g,"");}
if(format.indexOf('%')>=0){code+="val *= 100;\n";}
m=lodp.match(/(,+)(?:$|[^0#?,])/);if(m){code+="val /= "+Math.pow(1000,m[1].length)+"\n;";}
if(lodp.search(/[0#?],[0#?]/)>=0){thousands=true;}
if((m)||thousands){lodp=lodp.replace(/,/g,"");}
m=lodp.match(/0[0#?]*/);if(m){ldigits=m[0].length;}
m=rodp.match(/[0#?]*/);if(m){rdigits=m[0].length;}
if(scidigits>0){code+="var sci = toScientific(num,val,"
+ldigits+", "+rdigits+", "+scidigits+", "+scishowsign+");\n"
+"var arr = [sci.l, sci.r];\n";}
else{if(format.indexOf('.')<0){code+="val = (val > 0) ? Math.ceil(val) : Math.floor(val);\n";}
code+="var arr = round(val,"+rdigits+").toFixed("+rdigits+").split('.');\n";code+="arr[0] = (val < 0 ? '-' : '') + leftPad((val < 0 ? arr[0].substring(1) : arr[0]), "
+ldigits+", '0');\n";}
if(thousands){code+="arr[0] = addSeparators(arr[0]);\n";}
code+="arr[0] = reverse(injectIntoFormat(reverse(arr[0]), '"+escape(reverse(lodp))+"', true));\n";if(rdigits>0){code+="arr[1] = injectIntoFormat(arr[1], '"+escape(rodp)+"', false);\n";}
if(scidigits>0){code+="arr[1] = arr[1].replace(/(\\d{"+rdigits+"})/, '$1"+sciletter+"' + sci.s);\n";}
return code+"return arr.join('.');\n";};function toScientific(num,val,ldigits,rdigits,scidigits,showsign){var result={l:"",r:"",s:""};var ex="";var before=Math.abs(val).toFixed(ldigits+rdigits+1).trim('0');var after=Math.round(num,new Number(before.replace(".","").replace(new RegExp("(\\d{"+(ldigits+rdigits)+"})(.*)"),"$1.$2"))).toFixed(0);if(after.length>=ldigits){after=after.substring(0,ldigits)+"."+after.substring(ldigits);}
else{after+='.';}
result.s=(before.indexOf(".")-before.search(/[1-9]/))-after.indexOf(".");if(result.s<0){result.s++;}
result.l=(val<0?'-':'')+leftPad(after.substring(0,after.indexOf(".")),ldigits,"0");result.r=after.substring(after.indexOf(".")+1);if(result.s<0){ex="-";}
else if(showsign){ex="+";}
result.s=ex+leftPad(Math.abs(result.s).toFixed(0),scidigits,"0");return result;};function reverse(str){var res="";for(var i=str.length;i>0;--i){res+=str.charAt(i-1);}
return res;};function escape(string){return string.replace(/('|\\)/g,"\\$1");};function leftPad(val,size,ch){var result=new String(val);if(ch==null){ch=" ";}
while(result.length<size){result=ch+result;}
return result;};function round(num,decimals){if(decimals>0){var m=num.toFixed(decimals+1).match(new RegExp("(-?\\d*)\.(\\d{"+decimals+"})(\\d)\\d*$"));if(m&&m.length){return new Number(m[1]+"."+leftPad(Math.round(m[2]+"."+m[3]),decimals,"0"));}}
return num;};function addSeparators(val){var s=reverse(val).replace(/(\d{3})/g,"$1,");return reverse(s).replace(/^(-)?,/,"$1");};function injectIntoFormat(val,format,stuffExtras){var i=0;var j=0;var result="";var revneg=val.charAt(val.length-1)=='-';if(revneg){val=val.substring(0,val.length-1);}
while(i<format.length&&j<val.length&&format.substring(i).search(/[0#?]/)>=0){if(format.charAt(i).match(/[0#?]/)){if(val.charAt(j)!='-'){result+=val.charAt(j);}
else{result+="0";}
j++;}
else{result+=format.charAt(i);}
++i;}
if(revneg&&j==val.length){result+='-';}
if(j<val.length){if(stuffExtras){result+=val.substring(j);}
if(revneg){result+='-';}}
if(i<format.length){result+=format.substring(i);}
return result.replace(/#/g,"").replace(/\?/g," ");};var formatName="numFormat"+$.numericFormat.formats.length++;eval(createNewFormat(format,formatName));return eval(formatName);};if(!$.numericFormat.formats[format]){$.numericFormat.formats[format]=_numberFormat(num,format);};return $.numericFormat.formats[format](num);}});})(jQuery);

//*****************************************************************************************************************
// Text invoeren at cursor in textarea
//*****************************************************************************************************************
$.fn.insertAtCaret=function(myValue){return this.each(function(){if(document.selection){this.focus();sel=document.selection.createRange();sel.text=myValue;this.focus();}
else if(this.selectionStart||this.selectionStart=='0'){var startPos=this.selectionStart;var endPos=this.selectionEnd;var scrollTop=this.scrollTop;this.value=this.value.substring(0,startPos)+myValue+this.value.substring(endPos,this.value.length);this.focus();this.selectionStart=startPos+myValue.length;this.selectionEnd=startPos+myValue.length;this.scrollTop=scrollTop;}else{this.value+=myValue;this.focus();}});};

//*****************************************************************************************************************
// FieldSelection
//*****************************************************************************************************************
(function(){var c={getSelection:function(){var e=this.jquery?this[0]:this;return(('selectionStart'in e&&function(){var l=e.selectionEnd-e.selectionStart;return{start:e.selectionStart,end:e.selectionEnd,length:l,text:e.value.substr(e.selectionStart,l)}})||(document.selection&&function(){e.focus();var r=document.selection.createRange();if(r==null){return{start:0,end:e.value.length,length:0}}var a=e.createTextRange();var b=a.duplicate();a.moveToBookmark(r.getBookmark());b.setEndPoint('EndToStart',a);return{start:b.text.length,end:b.text.length+r.text.length,length:r.text.length,text:r.text}})||function(){return{start:0,end:e.value.length,length:0}})()},replaceSelection:function(){var e=this.jquery?this[0]:this;var a=arguments[0]||'';return(('selectionStart'in e&&function(){e.value=e.value.substr(0,e.selectionStart)+a+e.value.substr(e.selectionEnd,e.value.length);return this})||(document.selection&&function(){e.focus();document.selection.createRange().text=a;return this})||function(){e.value+=a;return this})()}};jQuery.each(c,function(i){jQuery.fn[i]=this})})();

//*****************************************************************************************************************
// Overige functies
//*****************************************************************************************************************
jQuery(document).ready(function($) {

	$("#top").click(function(){window.location="/";});
	
	// Forum
	$(".forumcontainer ul.posts>li").filter(":even").addClass("row2");
	$(".forumcontainer table tr").not(".forum_title").filter(":even").children().addClass("row2");
	$(".forumcontainer table tr").not(".forum_title").hover(function(){$(this).children().addClass("hover");},function(){$(this).children().removeClass("hover");});
	$(".forumcontainer table tr").not(".forum_title, .header").click(function(){
		if ($(this).data("uri")!=undefined)
			window.location=$(this).data("uri");
		else
			alert($(this).data("uri"));
	});
	$(".btn_newtopic").hover(function(){$(this).attr("src","/images/forum/button_newtopic1.png")},function(){$(this).attr("src","/images/forum/button_newtopic.png")});

	$("blockquote .ubbimg").load(function(){
		$(this).before('<span class="ubberror">Afbeeldingen in quotes worden niet weergegeven</span>');
		$(this).remove();
	}).each(function(){
		if(this.complete) $(this).trigger("load");
	});	
	$(".ubbimg").load(function(){
		if ($(this).attr("width")>640){
			$(this).attr("width",640);
			$(this).addClass("resized");
			$(this).before('<span class="ubberror">De afbeelding hieronder is te groot en word verkleind weergegeven.</span>');
		}
	}).each(function(){
		if(this.complete) $(this).trigger("load");
	});
	
	$("div.forumcontainer .btn_edit").attr("title","Post bewerken");
	$("div.forumcontainer .btn_delete").attr("title","Post verwijderen");
	$("div.forumcontainer .btn_quote").attr("title","Reply met quote");
	$(".btn_pm").attr("title","Stuur een PM (Persoonlijk bericht)");
	$("div.forumcontainer .btn_deletepost").click(function(){
		var id=$(this).data("id");
		if (id!=undefined){
			$.noqbox({title:"Post verwijderen",confirm:"Zeker weten dat je deze post wil verwijderen?",onconfirm:function(){window.location='/forum/actions/delpost/'+id}});
		}
	});
	$("#btnforumpreview").click(function(){  
		$.noqbox({ title: "Preview", ajax: "/?page=ajax&action=preview&type=forum&text="+escape($("#text").val())+"&smilies="+($("#nosmilies").attr("checked")?1:0),closebutton:true});
	});
	$(".btn_movetopic").click(function(){
		$.noqbox({title:"Topic verplaatsen",ajax:"/forum/actions/movetopic_diag/"+$(this).attr("id").substr(9),closebutton:true});
	});
	$("div.forumcontainer .btn_edit").click(function(){
		window.location='/forum/actions/editpost/'+$(this).attr("id").substr(8);
	});
	$(".btn_ip").click(function(){
		window.location='/forum/actions/ip/'+$(this).data("id");
	});
	$(".btn_quote").click(function(){
		window.location='/forum/actions/newpost/'+$(this).data("topicid")+'/'+$(this).data("postid");
	});	
	$(".btn_lock").click(function(){
		window.location='/forum/actions/lock/'+$(this).attr("id").substr(9);
	});	
	$(".btn_sticky").click(function(){
		window.location='/forum/actions/sticky/'+$(this).attr("id").substr(10);
	});
	$(".btn_pm").click(function(e){
		e.stopPropagation();
		window.location='/inbox/actions/new/'+$(this).attr("id").substr(2);
	});	
	$(".btn_forumfeed").click(function(e){
		window.location='/forum/actions/rss-forum/'+$(this).attr("id").substr(4);
	});
	$(".btn_topicfeed").click(function(e){
		window.location='/forum/actions/rss-topic/'+$(this).attr("id").substr(4);
	});		
	
	$(".btn_newpostquick").click(function(){
		var topicid=$(this).attr("id").substr(7);
		if ($('#text').length){
			if ($('#text').val()==""){
				window.location='/forum/actions/newpost/'+topicid;
			} else {
				alert('Maak eerst het Quickreply veld leeg als je een nieuwe post wil toevoegen');
			}
		} else {
			window.location='/forum/actions/newpost/'+topicid;
		}
	});
	$(".btn_newtopic").click(function(){window.location="/forum/actions/newtopic/"+$(this).attr("id").substr(8)});
	$(".forumsearch").click(function(){
		window.location='/forum/actions/search/'+escape($("#q").val())+($("#in").val()>0 ? "/"+$("#in").val() : "");
	});
	$(".input_forumsearch").constrain({allow:	{ regex: "[a-zA-Z0-9_ -]" }});
	
	$("div.ubb_img").click(function(){
		var target=$(this).attr("id").substr(7);
		$.noqbox({ html: '<div class="ubbinsert">Vul de URL van de afbeeling in:<br><input id="ubbhelper_input" type="text" value="http://" class="text" /><br><br><input type="button" class="button" id="ubb_img_ok" value="OK"></div>', title: 'Afbeelding invoeren',closebutton:true })
		$("#ubb_img_ok").click(function(){
			if ($('#ubbhelper_input').val()!=""){
				insert('[img]'+$('#ubbhelper_input').val()+'[/img]',target);
			}
			$(document).trigger('noqbox.close');
		});
	});

	$("div.ubb_url").click(function(){
		var target=$(this).attr("id").substr(7);
		$.noqbox({ html: '<div class="ubbinsert">Link URL:<br><input id="ubbhelper_input1" type="text" value="http://" class="text" /><br><br>Link tekst:<br><input id="ubbhelper_input2" type="text" value="" class="text" /><input type="button" class="button" id="ubb_url_ok" value="OK"></div>', title: 'Link invoeren',closebutton:true })
		$("#ubb_url_ok").click(function(){
			var url=$("#ubbhelper_input1").val();
			var text=$("#ubbhelper_input2").val();
			if (url!="http://" && url!=""){
				if (text=="")
					insert('[url]'+url+'[/url]',target);
				else
					insert('[url='+url+']'+text+'[/url]',target);
			}
			$(document).trigger('noqbox.close');
		});	
	});
	$("div.ubb_video").click(function(){
		var target=$(this).attr("id").substr(9);
		$.noqbox({ html: '<div class="ubbinsert">Vul de URL van de video in:<br><input id="ubbhelper_input" type="text" value="http://" class="text" /><br><br><input type="button" class="button" id="ubb_vid_ok" value="OK"></div>', title: 'Video invoeren',closebutton:true })
		$("#ubb_vid_ok").click(function(){
			if ($('#ubbhelper_input').val()!=""){
				insert('[video]'+$('#ubbhelper_input').val()+'[/video]',target);
			}
			$(document).trigger('noqbox.close');
		});
	});
	$(".smiliesbutton").mouseover(function(){
		var target=$(this).attr("id").substr(13);
		if (!$("div.smilies").length){
			var offset=$(this).offset();
			var height=$(this).height();
			$('body').append('<div class="smilies" style="display: none; position: absolute; top: '+(offset.top+height+2)+'px; left: '+(offset.left-2)+'px; ">'+smilieshtml+'</div>');
			$("div.smilies").slideDown(200);
			$("div.smilies img").click(function(e){
				e.stopPropagation();
				insert($(this).data("ubb"),target);
				$("div.smilies").fadeOut(200,function(){$(this).remove()});
			});
		}
	});
	$("body").click(function(){
		if ($("div.smilies").length){
			$("div.smilies").fadeOut(200,function(){$(this).remove()});
		}
	});	
	
	// reacties
	$(".btn_deletereactie").click(function(){
		var id=$(this).data("id");
		if (id!=undefined){
			$.noqbox({title:"Reactie verwijderen",confirm:"Zeker weten dat je deze reactie wil verwijderen?",onconfirm:function(){window.location='/index.php?page=reactie&action=DEL&id='+id}});
		}
	});
	$(".btn_editreactie").click(function(){
		var id=$(this).data("id");
		if (id!=undefined){
			window.location='/reactie/'+id;
		}
	});	
	
	// PM
	$(".btn_deletepm").click(function(){
		var id=$(this).data("id");
		var ele=$(this).parent().parent();
		if (id!=undefined){
			$.noqbox({title:"Bericht verwijderen",confirm:"Zeker weten dat je dit bericht wil verwijderen?",onconfirm:function(){
				$.ajax({url:'/inbox/actions/delsingle/'+id,success: function(msg){
					if (msg==1)
						ele.fadeOut();
				}});
			}});
		}
	});
	$(".btn_deletepmout").click(function(e){
		e.stopPropagation();
		var id=$(this).data("id");
		var ele=$(this).parent().parent();
		if (id!=undefined){
			$.noqbox({title:"Bericht verwijderen",confirm:"Zeker weten dat je dit bericht wil verwijderen?",onconfirm:function(){
				$.ajax({url:'/inbox/actions/delout/'+id,success: function(msg){
					if (msg==1)
						ele.fadeOut();
				}});
			}});		
		}
	});
	$(".btn_deletepmconversation").click(function(e){
		e.stopPropagation();
		var id=$(this).data("id");
		if (id!=undefined){
			$.noqbox({title:"Berichten verwijderen",confirm:"Zeker weten dat je deze hele conversatie wil verwijderen?",onconfirm:function(){window.location='/inbox/actions/delconversation/'+id}});
		}
	});	
	
	// Tabs
	$("#tabs li").click(function(){
		window.location=String(window.location).split("#")[0]+"#"+$(this).data("tab");
		gettab();
	});
	
	// username check voor register
	$(".usernamecheck").keypress(function(){
		var ele=$(this);
		clearTimeout(display_timeout);
		display_timeout = setTimeout(function() {
			if (ele.val()!=""){
				$.ajax({
					url: "/",
					data: "page=ajax&action=USERNAMECHECK&username="+ele.val(),
					success: function(msg){
						if (msg=="1"){
							ele.addClass("error");
							
						} else
							ele.removeClass("error");
					}
				});
			} else {
				ele.removeClass("error");
			}
		}, 500);
	});
	
});

function gettab(){
	var tabid=String(window.location).split("#")[1]=="" || String(window.location).split("#")[1]==null || String(window.location).split("#")[1]=="undefined" ? "BASIC" : String(window.location).split("#")[1];
	$.get("/"+$("#tabs").data("path")+"/"+tabid,function(s){$("#tab_content").html(s);});
	$("#tabs li").removeClass("current");
	$('#tabs li[data-tab="'+tabid+'"]').addClass("current");
}
	
function forum_getnewposts(topicid){
	var stamp=$("ul.posts>li").eq(0).data("stamp");
	$.ajax({
		url: "/forum/actions/getlatest/"+topicid+"/"+stamp,
		success: function(msg){
			if (msg!=0){
				$("ul.posts").prepend(msg);
				$("ul.posts>li").eq(0).slideDown();
				if ($("ul.posts>li").length>2){
					$("ul.posts>li").eq(3).slideUp();
				}
			}
		}
	});
	setTimeout("forum_getnewposts("+topicid+")",2000);
}

function insert2(sBefore,sAfter,el){
	$("#"+el).insertAtCaret(sBefore+$("#"+el).getSelection().text+sAfter);
}

function insert(s,el){
	$("#"+el).insertAtCaret(s);
}

function formatseconds(seconds){
	if (seconds>0){
		var days=Math.floor(seconds/86400);
		var timeleft=days>0 ? seconds-(days*86400) : seconds;
		var hours=Math.floor(timeleft/3600);
		timeleft=hours>0 ? timeleft-(hours*3600) : timeleft;
		var minutes=Math.floor(timeleft/60);
		timeleft=minutes>0 ? timeleft-(minutes*60) : timeleft;
		return (days>0 ? "<b>"+days+"</b> dagen, " : "")+"<b>"+hours+"</b> uur, <b>"+minutes+"</b> minuten en <b>"+timeleft+" </b>seconden";
	} else {
		return "<b>0</b> seconden";
	}
}

