function removeAllChildren(parent,rem_parent)
{
	while(parent.childNodes.length > 0)
	{
		if(parent.childNodes[0].childNodes.length>0)
		{
			removeAllChildren(parent.childNodes[0]);
		}
		else
		{
			rChild=parent.removeChild(parent.childNodes[0]);
			rChild=null;
		}
	}
	if(rem_parent==true)
	{
		parent.parentNode.removeChild(parent);
	}
}
String.prototype.pad = function(l, s, t){
	return s || (s = " "), (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length)
		+ 1).join(s)).substr(0, t = !t ? l : t == 1 ? 0 : Math.ceil(l / 2))
		+ this + s.substr(0, l - t) : this;
};
// Removes leading whitespaces
function LTrim( value ) 
{
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");	
}
// Removes ending whitespaces
function RTrim( value )
{
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}
// Removes leading and ending whitespaces
function trim ( value ) 
{
	return LTrim(RTrim(value));
	
}
function serialise(v)
{
        var i, s;
        s = '';

        if (v == null || gettype(v) == 'undefined') return 'undef';
        switch (gettype(v))
        {
                case 'boolean':
                        s = 'b:'+(v ? 1 : 0)+';';
                        break;

                case 'integer':
                        s = 'i:'+v+';';
                        break;

                case 'float':
                        s = 'd:'+v+';';
                        break;

                case 'string':
                        s = 's:'+(v.length)+':"'+v+'";';
                        break;

                case 'array':
                        s += 'a:'+(v.length)+':{';
                        var ta = [];
                        for (i=0; i<v.length; i++)
                        {
                                var e = serialise(v[i]);
                                ta.push(e);
                        }
                        s += ta.join(',');
                        s += '}';
                        break;

                case 'object':
                        s += 'a:';
                        var to = [];
                        for (i in v) {
                                var d = serialise(i);
                                var e = serialise(v[i]);
                                if (gettype(v[i]) != 'function') to.push(d+''+e);
                        }
                        s += to.length+':{';
                        s += to.join('');
                        s += '}';
                        break;

                default:
                        return 'undef'
                        break;
        }
        return s;
}
function gettype(w)
{
        var t = typeof(w);
        if (t == 'object')
        {
                t = w.constructor.toString().split("\n").join('');
                if (/\[native code\]/.test(t)) t = t.toLowerCase();
                t = t.replace(/^function /, '');
                t = t.replace(/\(.*/, '');
                if (/^\s*$/.test(t)) t = 'function';
        }
        if (t == 'number')
        {
                if ((0+Math.floor(t)) == (0+t))
                {
                        return 'integer';
                }
                else
                {
                        return 'float';
                }
        }
        return t;
}
