var currentelement;
var MagIk = true;
var cp = new cpaint();
cp.set_transfer_mode('post');
cp.set_response_type('text');
cp.set_persistent_connection(false);
cp.set_async(true);
cp.set_proxy_url('');
cp.set_debug(0);

function getSelection(ta)
 { var bits = [ta.value,'','',''];
   if(document.selection)
     { var vs = '#$%^%$#';
       var tr=document.selection.createRange()
       if(tr.parentElement()!=ta) return null;
       bits[2] = tr.text;
       tr.text = vs;
       fb = ta.value.split(vs);
       tr.moveStart('character',-vs.length);
       tr.text = bits[2];
       bits[1] = fb[0];
       bits[3] = fb[1];
     }
   else
     { if(ta.selectionStart == ta.selectionEnd) return null;
       bits=(new RegExp('([\x00-\xff]{'+ta.selectionStart+'})([\x00-\xff]{'+(ta.selectionEnd - ta.selectionStart)+'})([\x00-\xff]*)')).exec(ta.value);
     }
    return bits;
 }

function matchPTags(str)
 { str = ' ' + str + ' ';
   ot = str.split(/\[[B|U|I].*?\]/i);
   ct = str.split(/\[\/[B|U|I].*?\]/i);
   return ot.length==ct.length;
 }

function addPTag(ta,pTag)
 { bits = getSelection(ta);
   if(bits)
     { if(!matchPTags(bits[2]))
         { alert('\t\tInvalid Selection\nSelection contains unmatched opening or closing tags.');
           return;
         }
       ta.value = bits[1] + '[' + pTag + ']' + bits[2] + '[/' + pTag + ']' + bits[3];
     }
   else
   	{
   		ta.value = ta.value + '[' + pTag + ']' + ' ' + '[/' + pTag + ']';   		
   	}   	
 }
 
function insertext(tekst, ta){
	document.getElementById(ta).value += tekst;
}

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

function hidereactie(reactieid)
{						
	cp.call('../includes/cls/cpaint.asp', 'admin.hidecomment', showhidereactie, reactieid);
}	

function showhidereactie(result)
{
	alert(result);
}

function checkusername(elementid){
	currentelement = document.getElementById(elementid);
	cp.call('../includes/cls/cpaint.asp', 'func.checkusername', showCheckUsername, currentelement.value);
}

function showCheckUsername(result){
	if (result=='True'){
		//Gebruikersnaam bestaat al
		document.getElementById('aPopUpStatus').innerHTML = 'De ingevoerde gebruikersnaam bestaat al<br /><br />Of er zijn ongeldige tekens gebruikt!';
		new Effect.Appear(document.getElementById('aPopUp'), {duration: 0.5, from: 0, to: 0.9});		
	}
}

function checkemail(elementid){
	currentelement = document.getElementById(elementid);
	cp.call('../includes/cls/cpaint.asp', 'func.checkemail', showCheckEmail, currentelement.value);	
}

function showCheckEmail(result){
	if (result=='True'){
		//EMail bestaat al
		document.getElementById('aPopUpStatus').innerHTML = 'Het ingevoerde email-adres is al in gebruik!';
		new Effect.Appear(document.getElementById('aPopUp'), {duration: 0.5, from: 0, to: 0.9});		
	}
}

function ShowPM(){
	document.getElementById('aPopUpStatus').innerHTML = 'Er is een nieuw ongelezen prive bericht !';
	new Effect.Appear(document.getElementById('aPopUp'), {duration: 0.5, from: 0, to: 1});			
}

//function initProfile () 
//{
//	var photoScroller = new PhotoScroller("photoscroller");
//}

//Event.observe(window, "load", initProfile, false);

//var PhotoScroller = Class.create ();
/*
PhotoScroller.prototype = {
	
	initialize: function (scrollerDiv)
	{	
		this.scrollerDiv    = $(scrollerDiv);
		this.scrollerWidth  = Element.getDimensions(this.scrollerDiv).width;
		this.scrollerOffset = Position.cumulativeOffset($('container'))[0] + Position.positionedOffset(this.scrollerDiv)[0];
		//this.scrollerOffset = Position.cumulativeOffset(this.scrollerDiv)[0];
		this.scrollerDelta  = 0;
		this.scrollerAccel  = 2; 
		this.contentDiv     = this.scrollerDiv.getElementsByTagName("div")[0];
		this.contentWidth   = 0;
		this.executer	    = null;
		
		var photos = this.contentDiv.getElementsByTagName("a");

		for (var i = 0; i < photos.length; i++)
		{
			this.contentWidth += Element.getDimensions(photos[i]).width + 6;
		}

		Element.setStyle(this.contentDiv, { width: this.contentWidth + "px" });
		
		this.scrollerDiv.onmouseover = this.onMouseOver.bindAsEventListener(this);
		this.scrollerDiv.onmouseout  = this.onMouseOut.bindAsEventListener(this);
		
		Element.setStyle(this.scrollerDiv, { visibility: "visible" });
		
		if (photos.length > 0 && this.contentWidth > this.scrollerWidth)
		{
			this.start();
		}
	},
	
	onMouseOver: function (e)
	{
		Event.observe(this.scrollerDiv, "mousemove", this.onMouseMoved.bindAsEventListener(this), true);
	},
	
	onMouseOut: function (e)
	{
		Event.stopObserving(this.scrollerDiv, "mousemove", this.onMouseMoved.bindAsEventListener(this), true);
		this.scrollerAccel = 3 * (this.scrollerAccel == 0 ? 1 : (this.scrollerAccel / Math.abs(this.scrollerAccel)));
	},
	
	onMouseMoved: function (e)
	{
		this.scrollerAccel = 5 * Math.round((Event.pointerX(e) - this.scrollerOffset - (this.scrollerWidth / 2)) * 10 / this.scrollerWidth);
	},
	
	start: function ()
	{
		this.executer = new PeriodicalExecuter(this.doScroll.bindAsEventListener(this), 0.05);
	},
	
	doScroll: function ()
	{	  
		if (this.scrollerAccel <= 0 && this.scrollerDelta - this.scrollerAccel > 0)
		{
			Element.setStyle(this.contentDiv, { left: 0 + "px" });
			this.scrollerDelta = 0;
		}
		else if (this.scrollerAccel >= 0 && this.scrollerDelta + this.contentWidth - this.scrollerWidth - this.scrollerAccel < 0)
		{
			Element.setStyle(this.contentDiv, { left: (-this.contentWidth + this.scrollerWidth) + "px" });
			this.scrollerDelta = -this.contentWidth + this.scrollerWidth;
		}
		else
		{
			this.scrollerDelta = this.scrollerDelta - this.scrollerAccel;
			Element.setStyle(this.contentDiv, { left: this.scrollerDelta + "px" });
		}
	}
}
*/