var DEBUG = true;

/* Enable logging without errors in IE */
var log = function() {
    if(DEBUG && window.console && window.console.firebug) { console.log.apply(this, arguments); }
};

function addPreSlash(url) {
	if (url.indexOf("/") != 0) { url = "/"+url; }
	return url;
}

function addPostSlash(url) {
	if ((url.lastIndexOf("/")+1) != url.length) { url += "/"; }
	return url;
}

function removePreSlash(url) {
	url = url.replace(/^\//, '');
	return url;
}

function removePostSlash(url) {
	url = url.replace(/\/$/, '');
	return url;
}

function removeDomain(url) {
    domain = window.location.protocol+"//"+window.location.hostname;
    url = url.replace(domain, '');
    return url;
}

function removeLanguage(url) {
    if (url.indexOf("/de/") == 0) { url = url.substr(3); }
    if (url.indexOf("de/") == 0) { url = url.substr(2); }
    return url;
}

function removeHash(url) {
    if (url.indexOf("#") > -1) {
        url = url.replace("#"+getHash(url), '');
    }
    return url;
}

function getHash(url) {
    if (url.indexOf("#") > -1) {
        url = url.substr(url.indexOf("#")+1);
    }
	return url;
}

function getActuellUrl() {
    var url = getHash(removeDomain(document.location.href));
    return url;
}

function getAnchor(url) {
    var anchor = "";
    if (url.indexOf("/anchor/") > -1) {
        anchor = removePostSlash(url.substr(url.indexOf("/anchor/")+8));
    }
    return anchor;
}

function GetRandom( min, max ) {
	if ( min > max ) { return( -1 ); }
	if ( min == max ) { return( min ); }
	return( min + parseInt( Math.random() * ( max-min+1 ) ) );
}

function varDump(variable, maxDeep) {
        var deep = 0;
        var maxDeep = maxDeep || 5;

        function fetch(object, parent) {
                var buffer = '';
                deep++;

                for (var i in object) {
                        if (parent) {
                                objectPath = parent + '.' + i;
                        } else {
                                objectPath = i;
                        }

                        buffer += objectPath + ' (' + typeof object[i] + ')';

                        if (typeof object[i] == 'object') {
                                buffer += "\n";
                                if (deep < maxDeep) {
                                        buffer += fetch(object[i], objectPath);
                                }
                        } else if (typeof object[i] == 'function') {
                                buffer += "\n";
                        } else if (typeof object[i] == 'string') {
                                buffer += ': "' + object[i] + "\"\n";
                        } else {
                                buffer += ': ' + object[i] + "\n";
                        }
                }

                deep--;
                return buffer;
        }

        if (typeof variable == 'object') {
                return fetch(variable);
        }

        return '(' + typeof variable + '): ' + variable + "\n";
}

