function charReplace(test, out, replace) {
  if(out==replace) return test;
  pos=test.indexOf(out);
  while(pos>-1) {
    test=test.substring(0,pos) + replace + test.substring(pos+out.length,test.length);
    pos=test.indexOf(out,pos+replace.length);
  }
  return test;
}

function toHex(d)
{
  H=d.toString(16).toUpperCase()
  if(H.length % 2==1){H="0"+H}
  return H
}

function toHexString(Str)
{
  var hStr=""
  for(i=0;i<=Str.length-1;i++)
  {
    hStr+=toHex(Str.charCodeAt(i))
  }
  return hStr
}

function fromHexString(Str)
{
  var frmh=""
  if(Str.length % 2==1){Str="0"+Str}
  for(i=0;i<=Str.length-1;i+=2)
  {
    frmh+=String.fromCharCode(parseInt(Str.substring(i,i+2),16))
  }
  return frmh
}

function cyphr(InpString,kstr,d)
{// d=-1 for encoding
  var key=new Array(InpString.length)
  var keystr=kstr
  var zkey="m"
  while(keystr.length<InpString.length){keystr+=kstr}
  for(c=0; c<=InpString.length-1; c++)
  {
    key[c]=keystr.charCodeAt(c)-zkey.charCodeAt(0)
  }
  var cyphered=""
  var tempChar
  for(c=0; c<=InpString.length-1; c++)
  {
    tempChar=InpString.charCodeAt(c)+d*key[c]
    tempChar=tempChar & 255   // DON'T USE % 256 as treats negatives incorrectly
    cyphered+=String.fromCharCode(tempChar)
  }
  return cyphered
}

function cypher(InpString,kstr)
{return cyphr(InpString,kstr,-1)}

function uncypher(InpString,kstr)
{return cyphr(InpString,kstr,1)}

function cypherURI(InpString,kstr)
{return encodeURIComponent(cypher(InpString,kstr))}

function uncypherURI(InpString,kstr)
{return uncypher(decodeURIComponent(InpString),kstr)}

function cypherEsc(InpString,kstr)
{return escape(cypher(InpString,kstr))}

function uncypherEsc(InpString,kstr)
{return uncypher(unescape(InpString),kstr)}

function cypherHex(InpString,kstr)
{return toHexString(cypher(InpString,kstr))}

function uncypherHex(InpString,kstr)
{return uncypher(fromHexString(InpString),kstr)}

function oneWay(InpString)
{
  var c=cypher(InpString.substring(1,InpString.length),InpString)
  var cm=""
  var chck=0
  for (var i=0; i<InpString.length; i++)
  {
//alert(toHex(InpString.charCodeAt(i)))
    chck+=InpString.charCodeAt(i)
    chck&=255
  }
//alert("chck: "+toHex(chck))
  for (var i=0; i<c.length; i++)
  {
    cm+=String.fromCharCode((c.charCodeAt(i)+chck)&255)
  }
  return cm
}

function oneWayHex(InpString)
{return toHexString(oneWay(InpString))}

function getSearchAsArray()
{
  var results=new Array();
  var input = parent.location.search;
  if (input)
  {
    if (input.substring(0, 1) == '?') {input = input.substring(1)}
    var srchArray=input
    var tempArray=srchArray.split("?")
    for(l=0; l<tempArray.length; l++) {
      var temp2Array=tempArray[l].split("=")
      results[temp2Array[0]]=unescape(tempArray[l].substring(temp2Array[0].length+1,tempArray[l].length))
    }
  }
  return results;
}
