function lockForm(oElement, value) {			
	typeElement = getTypeElement(oElement);				
	switch(typeElement) {		
		case 'text': 
		case 'password':
			oElement.value = Url.decode(value);
			break;
		case 'checkbox':
			oElement.checked=true;
			break;
		case 'radio':
			$each(oElement, function(el){
				if(el.value == value) {
					el.checked = true;	
				}			
			});
			break;		
		case 'select':			
			oElement.value = Url.decode(value);	
			break;
		case 'textarea':
			$(oElement.id).setText(Url.decode(value));
			break;					
	}
}

function getTypeElement(oElement) {
	if(!$defined(oElement)) {
		return '';
	}	
	if($type(oElement) == 'collection') {
		tagName = oElement[0].tagName.toLowerCase();
		oElement = oElement[0];		
	}
	else {
		tagName = oElement.tagName.toLowerCase();
	}
		
	switch(tagName) {
		case 'input': 
			return  oElement.type;
			break;
		case 'select':
			return 'select';
			break;
		case 'textarea':
			return 'textarea';
			break;					
	}
	
	return false;
} 

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 Url._utf8_decode(plaintext);   
};

var Url = {

    // public method for url encoding
    encode : function (string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode : function (string) {
		string = string.replace(/\+/g," ");		
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }
}