/*!
Copyright © 2009 Clickwise Limited
All rights reserved.

No part of this code may be used, reproduced, transmitted, or stored in any
retrieval system of any nature, without the written permission of Clickwise
Limited.
*/

/********************************************************************************
CLCK global object
********************************************************************************/
var CLCK = CLCK || {};

//CLCK.root = 'http://www.cuisinedetachee.nl';
//PWNT.root = 'file:///Users/Daniel/Projects/PWN Technologies/www.pwntechnologies.nl/development/wwwroot';
//CLCK.root = 'http://www.clickwise.co.nz/laboratory/www.pwntechnologies.nl/';

/*###############################################################################
PWNT tools namespace
###############################################################################*/
CLCK.tools = CLCK.tools || {};

/********************************************************************************
log method to write a message to the console
********************************************************************************/
CLCK.tools.log = function(message) {
    if (window.console) {
        console.debug(message);
    } else {
        alert(message);
    }
};

/********************************************************************************
query method to read the querystring
********************************************************************************/
CLCK.tools.query = function() {
    var key, result, query, val;

    result = {};
    query = location.search;
    /* remove the leading ? */
    query = query.replace(/^\?/, '');
    /* remove the trailing & */
    query = query.replace(/\&$/, '');
    $.each(query.split('&'), function() {
        key = this.split('=')[0];
        val = this.split('=')[1];
        /* convert floats */
        if (/^[0-9.]+$/.test(val)) {
            val = parseFloat(val);
        }
        /* ingnore empty values */
        if (val) {
            result[key] = val;
        }
    });
    return result;
};
