/*-------------------------------------------------------------------------------------
	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 fClick(frmName, objName)
-------------------------------------------------------------------------------------*/
function fClick(frmName, objName) {
	docObj = document.forms[frmName].elements[objName];
	if (docObj.length == undefined) {
		
		if (docObj.checked) {
			docObj.checked = false;
		} else {
			docObj.checked = true;
		} // end if (docObj.checked)
	} // end if (docObj.length == undefined)
} // end function fClick(frmName, objName)


/*-------------------------------------------------------------------------------------
	function fClickAlt(frmName, objName, value)
		used in search.tmpl
-------------------------------------------------------------------------------------*/
function fClickAlt(frmName, objName, value) {
	
	el = document.forms[frmName].elements;
	
	for (i=0; i<el.length; i++) {
		
		if (el[i].name == objName && el[i].value == value) {
			
			if (el[i].checked) {
				el[i].checked = false;
			} else {
				el[i].checked = true;
			} // end if (el[i].checked)
		} // end if (el[i].name == objName && el[i].value == value)
	} // end for (i=0; i<el.length; i++)
} // end function fClickAlt(frmName, objName, value)


/*-------------------------------------------------------------------------------------
	function selectAll(frmName, objName, p, t)
-------------------------------------------------------------------------------------*/
function selectAll(frmName, objName, p, t) {
	
	frm = document.forms[frmName];
	obj = frm.elements[objName];
	
	if (frm.elements[p].checked) {
		
		if (t != "") {
			
			if (confirm(t)) {
				
				if (obj.length == undefined) { // just one element
					
					obj.checked = true;
				} else {
					
					for (i=0; i<obj.length; i++) {
						frm.elements[objName][i].checked = true;
					} // end for (i=0; i<obj.length; i++)
				} // end if (obj.length == undefined)
				
				frm.elements[p].checked = true;
			} else {
				
				// cancel select-all-action
				frm.elements[p].checked = false;
			} // end if (confirm([...]))
		} else {
			
			if (obj.length == undefined) { // just one element
				
				obj.checked = true;
			} else {
				
				for (i=0; i<obj.length; i++) {
					frm.elements[objName][i].checked = true;
				} // end for (i=0; i<obj.length; i++)
			} // end if (obj.length == undefined)
		} // end if
	} else {
		
		if (obj.length == undefined) { // just one element
			
			obj.checked = false;
		} else {
			
			for (i=0; i<obj.length; i++) {
				frm.elements[objName][i].checked = false;
			} // end for (i=0; i<obj.length; i++)
		} // end if (obj.length == undefined)
	} // end if (frm.elements[p].checked)
} // end function selectAll(frm, obj)


/*-------------------------------------------------------------------------------------
	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") {
				
				nuserimgs++;
				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;
			case "SP" :
				//warning.innerHTML = "<small>Esta imagen es de "+ow+" * "+oh+" pixels. Para mantener esta página accesible, la imagen debió ser achicada.</small>";
				warning.innerHTML = "<small>Para poder acceder a la página ágilmente tu imagen ha sido re dimensionada. Haz click sobre la imagen para verla en tamaño original.</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)
	
	nuserimgs--;
	scale_elements();
} // 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+'image/src/'+encode64(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)


/*-----------------------------------------------------------------
	scale_elements
		fixes the size (height) of the inner div AFTER all images
		have completed loading.
		After fixing the height, it calls reposition() once more to
		re-align the page horizontally.
-----------------------------------------------------------------*/
function scale_elements() {
	
	if (nuserimgs > 0) {
		return 0;
	} // end if (nuserimgs > 0)
	
	if (document.getElementById("bannerinside") == null) {
		setTimeout("scale_elements()", 1000);
		return 0;
	} // end if (document.getElementById("bannerinside") == null)
	
	m = document.getElementById("mid_banner");
	mm = document.getElementById("mid_main_banner");
	b = document.getElementById("mybanner");
	bi = document.getElementById("bannerinside");
	
	// reposition vertically
	mid_height = m.clientHeight;
	mid_main_height = mm.clientHeight; // FireFox fix - need to come up with something better
	banner_height = bi.scrollHeight;
	//alert("mh="+mid_height);
	//alert("mmh="+mid_main_height);
	//alert("bh="+b.clientHeight);
	//alert("bhi="+banner_height);
	
	//js_equalizeHeight = {OPT:equalizeheight:true::false/equalizeheight};
	useIE = false;
	if (navigator.userAgent.indexOf("MSIE") > -1) {
		useIE = true; } // end if (navigator.userAgent.indexOf("MSIE") > -1)
	
	/* Internet Explorer, Firefox, etc */
	//b.style.left = ( (document.body.clientWidth / 2) + (745/2) - b.clientWidth) +9 + "px";
	//b.style.top = "106px"; // -> stylesheet
	if (js_equalizeHeight) {
		
		if (useIE) {
			if (mid_main_height > banner_height) {
				bi.style.height = mid_main_height + 23 + "px";
			} else {
				mm.style.height = banner_height - 23 +  "px";
			} // end if
		} else {
			if (mid_main_height > banner_height) {
				bi.style.height = mid_main_height + 23 + "px";
			} else {
				mm.style.height = banner_height - 23 +  "px";
			} // end if
		} // end if (useIE)
		
		//alert("mid__main_height="+mid_main_height+" > banner_height="+banner_height);
		//if (mid_height >= banner_height) {
		//if (mid_main_height >= banner_height) {
		//	
		//	b.style.height = mid_main_height+63+"px";
		//	document.getElementById("banner_mid").style.height = mid_main_height+-16+"px"; // 24 // -16
		//} else { // mid_main_height < banner_height
		//	
		//	/*	use 105 for Internet Explorer and
		//			use 83 for Firefox */
		//	if (useIE) { m.style.height = (banner_height - 93) + "px"; // 105 // 93
		//	} else { m.style.height = (banner_height - 92) + "px"; } // end if (useIE) // was 83
		//} // end if (mid_main_height >= banner_height)
	} else {
		
		// no code :-)
	} // end if (equalizeHeight)
	
	reposition();				// reposition horizontally for the last time
} // end function scale_elements()


/*-----------------------------------------------------------------
	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()


/*-------------------------------------------------------------------------------------
	function encode64(input)
-------------------------------------------------------------------------------------*/
function encode64(input) {
	var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var output = "";
	var chr1, chr2, chr3;
	var enc1, enc2, enc3, enc4;
	var i = 0;
	
	do {
		chr1 = input.charCodeAt(i++);
		chr2 = input.charCodeAt(i++);
		chr3 = input.charCodeAt(i++);
		
		enc1 = chr1 >> 2;
		enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
		enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
		enc4 = chr3 & 63;
		
		if (isNaN(chr2)) {
			enc3 = enc4 = 64;
		} else if (isNaN(chr3)) {
			enc4 = 64;
		}
		
		output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
			keyStr.charAt(enc3) + keyStr.charAt(enc4);
	} while (i < input.length);
	
	return output;
} // end function encode64(input)


/*-----------------------------------------------------------------
	function ShowAllUsers()
		ON click show all users
-----------------------------------------------------------------*/
function ShowAllUsers(description,users) {
	
	document.getElementById("curonline").innerHTML = description;
	
	au = document.getElementById("allusers");
	au_height = au.scrollHeight;
	au.innerHTML = users;
	
	if (au_height < au.scrollHeight) {
		
		// more spaces needed
		mm = document.getElementById("mid_main_banner");
		mm.style.height = (mm.clientHeight + (au.scrollHeight - au_height)) + "px";
		//m = document.getElementById("mid_banner");
		scale_elements();
	} // end if
} // end function storeCursor()
