/**
 * requestVars.js
 *
 * This file contains functions to access the content of cookies
 * and GET parameters easily for javascript.
 * They are inspired by their PHP equivalent.
 *
 * This source file is subject to version 2.1 of the GNU Lesser
 * General Public License (LPGL), found in the file LICENSE that is
 * included with this package, and is also available at
 * http://www.gnu.org/copyleft/lesser.html.
 * @package     Javascript
 *
 * @author      Dieter Raber <dieter@dieterraber.net>
 * @copyright   2004-12-27
 * @version     1.0
 * @license     http://www.gnu.org/copyleft/lesser.html
 *
 */

/**
 * TOC
 *
 * - readGet
 * - readCookies
 */


/**
 * _GET is the equivalent to PHP's $_GET
 * An associative array of variables passed to the current script
 * via the HTTP GET method. This function is called onload.
 * This means that as soon as this file is included _GET will be available
 *
 * example:
 *   If the curent URL contains GET parameters e.g.
 *   myurl.htm?color1=red&color2=blue
 *   then _GET['color1'] will contain 'red'
 *   and  _GET['color2'] will contain 'blue'
 */

function readGet()
{
  var _GET    = new Array();
  var uriStr  = window.location.href.replace(/&amp;/g, '&');
  var paraArr, paraSplit;

  if (uriStr.indexOf('?') > -1)
  {
    var uriArr  = uriStr.split('?');
    var paraStr = uriArr[1];
  }
  else
  {
    return _GET;
  }

  if (paraStr.indexOf('&') > -1)
  {
    paraArr = paraStr.split('&');
  }
  else
  {
    paraArr = new Array(paraStr)
  }

  for(var i = 0; i < paraArr.length; i++)
  {
    paraArr[i] = paraArr[i].indexOf('=') > -1
               ? paraArr[i]
               : paraArr[i] + '=';
    paraSplit  = paraArr[i].split('=')
    _GET[paraSplit[0]] = decodeURI(paraSplit[1].replace(/\+/g, ' '));
  }
  return _GET;
}
var _GET = readGet();
/*****************************************************************************/

