function findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document); return x;
}


function swapImage() {
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function checkchars(reactie) {
	var max=5000;
	if (reactie.itemtext.value.length > max) {
		alert("Je mag niet meer dan 5000 karakters gebruiken in het reactie systeem! Als deze post toch wilt doen moet je hem op het forum zetten.");
		return false;
	} else {
		return true; 
	}
}

function chatbox() {
	window.open('/chatbox/?displaymode=popup', 'chatbox', 'left=50,top=50,width=635,height=480,scrollbars=yes,toolbar=no');
}

function openWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

function sback() {
	parent.window.history.back();
}

function shake(n) {
	if (parent.moveBy) {
		for (i = 10; i > 0; i--) {
			for (j = n; j > 0; j--) {
				for (s = 0; s < 30; s++) {
					parent.moveBy(0,i);
					parent.moveBy(i,0);
					parent.moveBy(0,-i);
					parent.moveBy(-i,0);
				}
		         }
		}
	}
}

function savecursorpos(element)
{
	if ( document.all && element.createTextRange )
		element.cursorPos = document.selection.createRange().duplicate();
}


function smiley(smileytext) {
	box = document.getElementById('reactiontext');	
	
	if ( document.all && box.cursorPos) {
		var cursorPos = box.cursorPos;
		cursorPos.text = smileytext;
		box.focus();
	} else {
		box.value += smileytext;
		box.focus();
	}
}

function objectselecter(typefield, idfield, namefield) {
	window.open('/my/objectselect/?type='+document.getElementById(typefield).value+'&id='+document.getElementById(idfield).value+'&field='+idfield, 'objectselect', 'width=250,height=300,resizable=no,toolbars=no');
}

if(typeof networkbar != 'undefined') {
	networkbar.onHideMenu = function() {
		var elms = document.getElementsByTagName('div');
		for(i = 0; i < elms.length; i++) {
			if(elms[i].className == 'banner') {
				elms[i].style.visibility = 'visible';
			}
		}
	}
	
	networkbar.onShowMenu = function() {
		var elms = document.getElementsByTagName('div');
		for(i = 0; i < elms.length; i++) {
			if(elms[i].className == 'banner') {
				elms[i].style.visibility = 'hidden';
			}
		}
	}
}

function drawBanner(zoneid) {
	if (!document.phpAds_used) document.phpAds_used = ',';
	phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);
	
	document.write ("<" + "script type='text/javascript' src='");
	document.write ("http://adserver.gameparty.net/adjs.php?n=" + phpAds_random);
	document.write ("&amp;what=zone:"+zoneid);
	document.write ("&amp;exclude=" + document.phpAds_used);
	if (document.referrer)
		document.write ("&amp;referer=" + escape(document.referrer));
	document.write ("'><" + "/script>");
}

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 var 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;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
