/*-------------------------------------------------------------------------------------
	function ubb()
-------------------------------------------------------------------------------------*/
function ubb() {
	var w = window.open(imgPrefix+'ubb','Image','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,left=20,top=20,width=450,height=500');
	w.focus;
} // end function ubb()

/*-------------------------------------------------------------------------------------
	function crop()
-------------------------------------------------------------------------------------*/
function crop() {
	
	im = document.images;
	nim = im.length;
	
	for (i=0; i<nim; i++) {
		
		if (im[i].className == "user" && im[i].complete) {
			
			iw = im[i].width;
			ih = im[i].height;
			ic = im[i].complete;
			
			//alert('iw='+iw+', ih='+ih+', ic='+ic);
			resizeImg(0, im[i]);
		} else {
			
			if (im[i].className == "user") {
				im[i].onload = resizeImg;
			} // end if (im[i].className == "user")
		} // end if (im[i].className == "user")
	} // end for (i=0; i<nim; i++)
} // end function crop()


/*-------------------------------------------------------------------------------------
	function resizeImg(e, img)
-------------------------------------------------------------------------------------*/
function resizeImg(e, img) {
	
	if (!img) { img = this; }
	
	var ow = img.width;
	var oh = img.height;
	
	if (ow == 0) {
		
		var tmp = new Image();
		tmp.src = img.src;
		
		ow = tmp.width;
		oh = tmp.height;
	} // end if
	
	// if (img.width > imgMaxWidth) {
	if (ow > imgMaxWidth) {
		img.width = imgMaxWidth;
		
		var warning = document.createElement("div");
		warning.className = "imgwarning";
		warning.style.width = img.width;
		
		switch(JS_LANGUAGE) {
			case "NL" :
				//warning.innerHTML = "<small>Deze afbeelding is "+ow+" * "+oh+" pixels groot. Om het forum leesbaar te houden, wordt de afbeelding verkleind weergegeven.</small>";
				warning.innerHTML = "<small>Om het forum leesbaar te houden, wordt deze afbeelding verkleind weergegeven. Klik voor een grotere versie op de afbeelding.</small>";
				break;
			case "EN" :
				//warning.innerHTML = "<small>This image is "+ow+" * "+oh+" pixels large. To keep this page readable, the image has been cropped.</small>";
				warning.innerHTML = "<small>To keep this forum readable, your image has been resized. Click on image for a larger version.</small>";
				break;
		} // end switch(JS_LANGUAGE)
		
		var ns = img.nextSibling;
		if (ns == null) {
			img.parentNode.appendChild(warning);
		} else {
			img.parentNode.insertBefore(warning, ns);
		} // end if (img.nextSibling == null)
		
		makeClickable(img);
	} else {
		
		var tmp = new Image();
		tmp.src = img.src;
		
		if (tmp.width != img.width) { // image already resized ([img=400,300][/img]) - make clickable
			
			makeClickable(img);
		} // end if (tmp.src != img.src)
	} // end if (img.width > imgMaxWidth)
} // end function resizeImg(e, img)


/*-------------------------------------------------------------------------------------
		function makeClickable(img)
-------------------------------------------------------------------------------------*/
function makeClickable(img) {
	
	if (img.parentNode.tagName.toLowerCase() != "a") { // only if it's no clickable already
		
		img.style.cursor = 'pointer';
		img.style.cursor = 'hand';
		img.style.border = '1px dashed #006691';
		img.onclick = openImage;
	} // end if (img.parentNode.tagName.toLowerCase() != "a")
} // end function makeClickable(img)


/*-------------------------------------------------------------------------------------
	function openImage(e, img)
-------------------------------------------------------------------------------------*/
function openImage(e, img) {
	
	if (!img) { img = this; }
	
	var tmp = new Image();
	tmp.src = img.src;
	
	iw = tmp.width;
	ih = tmp.height;
	s = "no";
	
	incompetent_browser = document.all && navigator.userAgent.indexOf('MSIE') > -1 && navigator.userAgent.indexOf('Opera') == -1;
	if (document.all && navigator.userAgent.indexOf('MSIE') > -1) {
		iw = iw;
		ih = ih;
	} else {
		iw = iw;
		ih = ih;
	} // end if (document.all && navigator.userAgent.indexOf('MSIE') > -1)
	
	if (ih > (screen.height-50)) {
		
		iw = iw+17;
		ih = screen.height - 100;
		s = "yes";
	} // end if (ih > (screen.height-50))
	
	if (ih > (screen.width-50)) {
		
		iw = iw-100;
		ih = screen.height - 100;
		s = "yes";
	} // end if (ih > (screen.width-50))
	
	var w = window.open(imgPrefix+'popup.php?image='+img.src,'Image','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+s+',resizable=no,copyhistory=no,left=20,top=20,width='+iw+',height='+ih);
	w.focus;
} // end function openImage(e, img)


/*-----------------------------------------------------------------
	function insertSmiley(s)
-----------------------------------------------------------------*/
function insertSmiley(s) {
	
	if (target) {
		
		if (typeof target.cursorPos != 'undefined') {
			
			target.focus(); target.onselect(); 			// i only want smileys in message box (forced)
			var cursorPos = target.cursorPos;
			cursorPos.text = s;
		} else if (typeof target.selectionStart != 'undefined') {
			
			var scrollTop = target.scrollTop;			// remember scrollposition
			var sStart = target.selectionStart;
			var sEnd = target.selectionEnd;
			target.value = target.value.substr(0, sStart) + s + target.value.substr(sEnd);
			if (sStart == sEnd) {
				var nStart = sStart + s.length;
			} else { var nStart = sStart; } // endif (sStart == sEnd)
			var nEnd = sStart + s.length;
			target.setSelectionRange(nStart, nEnd);
			target.scrollTop = scrollTop;				// reset scrollposition
		} else {
			target.value += s;
		} // end if (typeof target.cursorPos != 'undefined')
		
		target.focus();
		if (typeof target.cursorPos != 'undefined') {
			target.onselect(); } // end if (typeof target.cursorPos != 'undefined')
	} // end if (target)
} // end function insertSmiley(s)

/*-----------------------------------------------------------------
	function storeCursor()
		used by IE users to keep track of caret position
-----------------------------------------------------------------*/
function storeCursor() {
	this.cursorPos = document.selection.createRange().duplicate();
} // end function storeCursor()
