function parseStr(str) { 

  var keysArray = new Object(); 
    // The Object ("Array") where our data will be stored. 

  separator = ','; 
    // The token used to separate data from multi-select inputs 

  query = '' + str; 
  qu = query 
    // Get the current URL so we can parse out the data. 
    // Adding a null-string '' forces an implicit type cast 
    // from property to string, for NS2 compatibility. 

  query = query.substring((query.indexOf('?')) + 1); 
    // Keep everything after the question mark '?'. 

  if (query.length < 1) { return false; }  // Perhaps we got some bad data? 

  keypairs = new Object(); 
  numKP = 1; 
    // Local vars used to store and keep track of name/value pairs 
    // as we parse them back into a usable form. 

  while (query.indexOf('&') > -1) { 
    keypairs[numKP] = query.substring(0,query.indexOf('&')); 
    query = query.substring((query.indexOf('&')) + 1); 
    numKP++; 
      // Split the query string at each '&', storing the left-hand side 
      // of the split in a new keypairs[] holder, and chopping the query 
      // so that it gets the value of the right-hand string. 
  } 

  keypairs[numKP] = query; 
    // Store what's left in the query string as the final keypairs[] data. 

  for (i in keypairs) { 
    keyName = keypairs[i].substring(0,keypairs[i].indexOf('=')); 
    keyName = keyName.replace(/(\n|\r| |\t)*([^ \n\r\t]*)( |\n|\r|\t)*/i, "$2");
	//for(i1 = 0; i1 < keyName.length && keyName[i1] !=; i1++)
      // Left of '=' is name. 
    keyValue = keypairs[i].substring((keypairs[i].indexOf('=')) + 1); 
      // Right of '=' is value. 
    while (keyValue.indexOf('+') > -1) { 
      keyValue = keyValue.substring(0,keyValue.indexOf('+')) + ' ' + keyValue.substring(keyValue.indexOf('+') + 1); 
        // Replace each '+' in data string with a space. 
    } 
//	alert(keyName+"="+keyValue);
    keyValue = unescape(keyValue); 
      // Unescape non-alphanumerics 

    if (keysArray[keyName]) { 
      keysArray[keyName] = keysArray[keyName] + separator + keyValue; 
        // Object already exists, it is probably a multi-select input, 
        // and we need to generate a separator-delimited string 
        // by appending to what we already have stored. 
    } else { 
      keysArray[keyName] = keyValue; 
        // Normal case: name gets value. 
    } 
  } 

  return keysArray; 
} 

function getValueOrDef(value, def)
{
	if(value) return value;
	return def;
}

function setCookie(name,value)
{
	document.cookie = name+"="+value+";";
}
function getCookie(name)
{
    var arrCookies = document.cookie.split(";");
    for (var i = 0; i < arrCookies.length; i++) 
    {
      var arrCookie = arrCookies[i].split("=");
//	  arrCookie[0].
		arrCookie[0] = arrCookie[0].replace(/^[ ]*/g, "");
//		alert(arrCookie[0].indexOf(name));
      if (arrCookie[0].indexOf(name) == 0) 
      {
        if (arrCookie[1].length) {
          return unescape(arrCookie[1]).replace(/\\/g, "");
        } else
          return "";
        break;
      }
    }
	return "";
}
function sprintf()
{
	if (!arguments || arguments.length < 1 || !RegExp)
	{
		return;
	}
	var str = arguments[0];
	var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
	var a = b = [], numSubstitutions = 0, numMatches = 0;
	while (a = re.exec(str))
	{
		var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4];
		var pPrecision = a[5], pType = a[6], rightPart = a[7];
		
		

		numMatches++;
		if (pType == '%')
		{
			subst = '%';
		}
		else
		{
			numSubstitutions++;
			if (numSubstitutions >= arguments.length)
			{
				alert('Error! Not enough function arguments (' + (arguments.length - 1) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).');
			}
			var param = arguments[numSubstitutions];
			var pad = '';
			       if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1);
			  else if (pPad) pad = pPad;
			var justifyRight = true;
			       if (pJustify && pJustify === "-") justifyRight = false;
			var minLength = -1;
			       if (pMinLength) minLength = parseInt(pMinLength);
			var precision = -1;
			       if (pPrecision && pType == 'f') precision = parseInt(pPrecision.substring(1));
			var subst = param;
			       if (pType == 'b') subst = parseInt(param).toString(2);
			  else if (pType == 'c') subst = String.fromCharCode(parseInt(param));
			  else if (pType == 'd') subst = parseInt(param) ? parseInt(param) : 0;
			  else if (pType == 'u') subst = Math.abs(param);
			  else if (pType == 'f') subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(param);
			  else if (pType == 'o') subst = parseInt(param).toString(8);
			  else if (pType == 's') subst = param;
			  else if (pType == 'x') subst = ('' + parseInt(param).toString(16)).toLowerCase();
			  else if (pType == 'X') subst = ('' + parseInt(param).toString(16)).toUpperCase();
		}
		subst = new String(subst);
		for(i=subst.length; i < pMinLength; i++)
			subst = pPad + subst;
		//alert(leftpart+','+pPad+','+ pJustify+','+ pMinLength+','+ pPrecision+','+subst+','+subst.length);	
		str = leftpart + subst + rightPart;
	}
	return str;
}