var PTloc = 0;

//
//   Reset parameter counter
// *************************
function ResetParamTokenLoc()
{
   PTloc = 0;
}

//
//   Tokenizes the parameter string
// ********************************
function ParamToken(str)
{
   //   Remove ? if necessary
   if (str.indexOf("?") == 0)
      str = str.substring(1);

   if (PTloc == 0)
   {
      PTloc = str.indexOf("&") + 1;
      if (PTloc <= 0)
         PTloc = str.length + 1;
      return str.substring(0, PTloc - 1);
   }
   else
   {
      ibeg = PTloc;
      iend = str.substring(ibeg).indexOf("&") + PTloc;
      if (iend <= PTloc)
         iend = str.length;
      if (iend <= ibeg)
         return "";
      PTloc = iend + 1;
      return str.substring(ibeg, iend);// - ibeg + 1);
   }
}

//
//   Returns value from a given parameter
// **************************************
function ParamVal(str)
{
   return str.substring(str.indexOf("=") + 1);
}

//
//   Returns name of a given parameter
// ***********************************
function ParamName(str)
{
   return str.substring(0, str.indexOf("="));
}
