function URLEncode(plaintext)
{
	if (typeof(plaintext) == 'undefined') return '';
	return encodeURIComponent(plaintext);
}

function URLDecode(encoded) {
	if (typeof(encoded) == 'undefined') return '';
	return decodeURIComponent(encoded);
}

function error_filler(t, where, url) {
	$(where).innerHTML = '<div class="error">Error <b>' + t.status + '</b> in <b>' + url + '</b>: <b>' + t.statusText + '</b></div>';
}

var last_response_text = '';

function ajax_load(config) { //url, pars, where, evalonsuccess, hideloading) {
	if ((config.where != '') && (typeof(config.where) != 'undefined')) {
		if ($(config.where) != null) {
			if (config.hideloading == true) {
				//do nothing
			} else {
				var toinsert = '<span style="background:#CCFFCC;border:1px solid #77CC77;padding:3px;position:absolute;z-index:2">Loading...</span>'; //hardcoded loading
				$(config.where).innerHTML = toinsert + $(config.where).innerHTML;
			}
		} else {
			alert('id="' + config.where + '" not found. cannot load "' + config.url + '"');
		}
	}
	
	var myAjax = new Ajax.Request(
		config.url,
		{
			method: 'get',
			parameters: config.pars,
			onSuccess: function(t) {
				do_the_update = true;
				if (config.hideloading == true) {
					if (last_response_text == t.responseText) {
						do_the_update = false;
					} else {
						last_response_text = t.responseText;
					}
				}
				if ((do_the_update) && (config.where != '')) {
					$(config.where).innerHTML = t.responseText;
				}
				eval(config.onsuccess);
				t.responseText.evalScripts();
			},
			onFailure: function(t) {
				error_filler(t, config.where, config.url);
			}
		}
	);
}
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.
{
	for(var i=0; i<document.images.length; i++)
	{
		var img = document.images[i]
		var imgName = img.src.toUpperCase()
		
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		{
			var imgID = (img.id) ? "id='" + img.id + "' " : ""
			var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			var imgStyle = "display:inline-block;" + img.style.cssText
			var imgAttribs = img.attributes;
			var onMouseOver = "", onMouseOut = "";
			
			for (var j=0; j<imgAttribs.length; j++)
			{
				var imgAttrib = imgAttribs[j];
				
				if (imgAttrib.nodeName == "align")
				{
					if (imgAttrib.nodeValue == "left") imgStyle = "float:left;" + imgStyle
					if (imgAttrib.nodeValue == "right") imgStyle = "float:right;" + imgStyle
					break
				}
			}
			
			if (img.name && !img.id) imgID= "id='" + img.name + "' "
			
			if ((pos=img.outerHTML.toUpperCase().indexOf("ONMOUSEOVER="))>0) 
			{
				onMouseOver=img.outerHTML.substring(pos);
				pos=onMouseOver.indexOf(");");
				if (onMouseOver.substr(12,1)== "\"") pos=onMouseOver.indexOf(");\"");
				onMouseOver=" " + onMouseOver.substring(0,pos+2).replace("MM_swap","MM_PNGswap") + ((onMouseOver.substr(12,1)== "\"") ? "\"":"") + " ";
			}
			
			pos=0
			
			if ((pos=img.outerHTML.toUpperCase().indexOf("ONMOUSEOUT="))>0) 
			{
				onMouseOut=img.outerHTML.substring(pos);
				pos=onMouseOut.indexOf(");");
				if (onMouseOut.substr(11,1)== "\"") pos=onMouseOut.indexOf(");\"");
				onMouseOut=" " + onMouseOut.substring(0,pos+2).replace("MM_swap","MM_PNGswap") + ((onMouseOut.substr(11,1)== "\"") ? "\"":"") + " ";
			}
			
			pos=0
			
			var strNewHTML = "<span " + imgID + imgClass + imgTitle
			strNewHTML += " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			strNewHTML += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			strNewHTML += "(src=\'" + img.src + "\', sizingMethod='scale');\"";
			strNewHTML += onMouseOver + onMouseOut + "></span>"
			img.outerHTML = strNewHTML
			i = i-1
		}
	}

	for(var i=0; i<document.links.length; i++)
	{
	var lnk = document.links[i];
	var tStr="";
	
		if ((pos=lnk.outerHTML.indexOf("MM_swapImage("))>0) 
		{
			tStr=lnk.outerHTML.substring(pos+13);
			pos=tStr.indexOf(");");
			if (pos>0) 
			{
				pos=tStr.substring(0,pos).toUpperCase().indexOf(".PNG");
				if (pos>0) lnk.outerHTML = lnk.outerHTML.replace(/MM_swap/g,"MM_PNGswap");
			}
		}
	}
}

function MM_PNGswapImage() { //v3.0
	var i,j=0,x,a=MM_PNGswapImage.arguments;
	document.MM_sr=new Array;
	for(i=0;i<(a.length-2);i+=3)
		if ((x=MM_findObj(a[i]))!=null){
			document.MM_sr[j++]=x;
			if(!x.oSrc) x.oSrc=x.filters(0).src; 
			x.filters(0).src=a[i+2];
		}
}

function MM_PNGswapImgRestore() { //v3.0
	var i,x,a=document.MM_sr;
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.filters(0).src=x.oSrc;
}

if (window.attachEvent)
{
	window.attachEvent("onload", correctPNG);
}
function URLEncode(plaintext)
{
	if (typeof(plaintext) == 'undefined') return '';
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
/*			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
*/
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
}

function blury_top() {
	if (document.getElementById('cr1').value == '') document.getElementById('cr1').value = 'Search';
	if (document.getElementById('cr2').value == '') document.getElementById('cr2').value = 'In';
}
function blury() {
	if (document.getElementById('add_cat').value == '') document.getElementById('add_cat').value = 'Category';
	if (document.getElementById('add_subcat').value == '') document.getElementById('add_subcat').value = 'Sub-Category';
	if (document.getElementById('add_real').value == '') document.getElementById('add_real').value = 'Real Name';
	if (document.getElementById('add_nick').value == '') document.getElementById('add_nick').value = 'Nickname';
}

function reload() {
	document.getElementById('add_cat').value = 'Category';
	document.getElementById('add_subcat').value = 'Sub-Category';
	document.getElementById('add_real').value = 'Real Name';
	document.getElementById('add_nick').value = 'Nickname';
}