//*********************************************************************
//
// ============================================
//
// Copyright (c) 2007 by Geodata Sistemas S.L.
// http://www.geodata.es
// Written by Adrià Mercader & Arturo Bandini
//
//
// Javascript "classes" for encoding / decoding strings
//
//
// This program is free software. You can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License.
//
//*********************************************************************

/**
*	This "class" provides functions for encoding strings
*/
var jsEncoder = {

	/**
	*	Encodes the provided text
	* @returns output Encoded text (if text)
	* @type variable
	*/	
	encode: function(value){
		var output = value;
		if (typeof(output) == "string"){
			output = escape(output);
		}
		return output;
	},
	
	/**
	*	Encodes the provided object or array members, recursively
	* @returns object Encoded object or array
	* @see encode(),encodeObject()
	* @type object or array
	*/	
	encodeObject: function(object){
		if (typeof(object) == "object") {
			for (var i in object){
				if (typeof(object[i]) == "object") {
					object[i] = this.encodeObject(object[i]);
				} else {
					object[i] = this.encode(object[i]);
				}
			}
		} else {
			object = this.encode(object);
		}
		return object;
	}	
}

/**
*	This "class" provides functions for decoding strings
*/
var jsDecoder = {

	/**
	*	Decodes the provided text
	* @returns output Decoded text (if text)
	* @type variable
	*/
	decode: function(value){
		var output = value;
		if (typeof(output) == "string"){
			output = unescape(output);
		}
		return output;
	},
	
	/**
	*	Decodes the provided object or array members, recursively
	* @returns object Decoded object or array
	* @see decode(),decodeObject()
	* @type object or array
	*/	
	decodeObject: function(object){
		if (typeof(object) == "object") {
			for (var i in object){
				if (typeof(object[i]) == "object") {
					object[i] = this.decodeObject(object[i]);
				} else {
					object[i] = this.decode(object[i]);
				}
			}
		} else {
			object = this.decode(object);
		}
		return object;
	}	

}