var maxx,maxy;

if (window.screen) { maxx = screen.availWidth - 17; maxy = screen.availHeight - 60; }
else { maxx = 800; maxy = 600; }

function showpic(url, width, height) {
    var scroll = 'no';
    var picheight = height;
    var picwidth = width;

    if (height > maxy) {
        width = Math.round(width / (height / maxy));
        height = maxy;
        picheight = height;
        picwidth = width;

        if (width > maxx) {
            scroll='yes';
            width = maxx;
        }
    } else if (width > maxx) {
        height = Math.round(height / (width / maxx));
        width = maxx;
        picheight = height;
        picwidth = width;

        if (height > maxy) {
            scroll='yes';
            height = maxy;
        }
    }

    var left = (screen.width/2)-(width/2);
    var top = (screen.height/2)-(height/2);

    window.open('jget.php?pic='+url+'&width='+picwidth+'&height='+picheight,''
		,'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+width+',height='+height+',top='+top+',left='+left+',scrollbars='+scroll);
}

function reply(poster, comment_textarea, comment) {
	window.location.hash="posts";
	document.getElementById(comment_textarea).focus();
	document.getElementById(comment_textarea).value = '@' + poster + ': ';
	document.forms[comment].comment_send.disabled = false;
	document.forms[comment].comment_send.style.background = '#fec054';
}


function autogrow(comment_textarea, linenum) {
	var m = document.getElementById(comment_textarea).value.match(/\n/g);
	if (m !=null && m.length >= linenum-1) {
		document.getElementById(comment_textarea).rows = (m.length+2);
	} else {
		document.getElementById(comment_textarea).rows = linenum;
	}
}

function urldecode(encoded)
{
	// Replace + with ' '
	// Replace %xx with equivalent character
	// Put [ERROR] in output if %xx is invalid.
	var HEXCHARS = "0123456789ABCDEFabcdef";
	var plaintext = "";
	var i = 0;
	while (i < encoded.length) {
		var ch = encoded.charAt(i);
		if (ch == "+") {
			plaintext += " ";
			i++;
		} else if (ch == "%") {
				if (i < (encoded.length-2)
						&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1
						&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
					plaintext += unescape( encoded.substr(i,3) );
					i += 3;
				} else {
/*						alert( 'Bad escape combination near ...' + encoded.substr(i) );
					plaintext += "%[ERROR]";*/
					i++;
				}
			} else {
			plaintext += ch;
			i++;
			}
		} // while
	return plaintext;
}

