 var foo = null; // object
 var small = null;
 var sy = 0;
 var fooSx = 0;
 var sr = 0;
 var sb = 0;
 var tx = 0;
 var ty = 0;
 var dx = 0;
 var dy = 0;
 var smallx = 0;
 var smally = 0;
 var xmlhttp=null;
 var small = null;
 var buy = null;
 var interval = null;

function urlEncode( s )
{
  s = s.replace(/\xe0/g, 'a');
  s = s.replace(/\xe1/g, 'a');
  s = s.replace(/\xe2/g, 'a');
  s = s.replace(/\xe3/g, 'a');
  s = s.replace(/\xe4/g, 'a');
  s = s.replace(/\xe5/g, 'a');
  s = s.replace(/\xc0/g, 'A');
  s = s.replace(/\xc1/g, 'A');
  s = s.replace(/\xc2/g, 'A');
  s = s.replace(/\xc3/g, 'A');
  s = s.replace(/\xc4/g, 'A');
  s = s.replace(/\xc5/g, 'A');
  s = s.replace(/\xf0/g, 'o');
  s = s.replace(/\xf2/g, 'o');
  s = s.replace(/\xf3/g, 'o');
  s = s.replace(/\xf4/g, 'o');
  s = s.replace(/\xf5/g, 'o');
  s = s.replace(/\xf6/g, 'o');
  s = s.replace(/\xd2/g, 'O');
  s = s.replace(/\xd3/g, 'O');
  s = s.replace(/\xd4/g, 'O');
  s = s.replace(/\xd5/g, 'O');
  s = s.replace(/\xd6/g, 'O');
  s = s.replace(/\xd8/g, 'O');
  return encodeURIComponent( s ).replace( /\%20/g, '+' ).replace( /!/g, '%21' ).replace( /'/g, '%27' ).replace( /\(/g, '%28' ).replace( /\)/g, '%29' ).replace( /\*/g, '%2A' ).replace( /\~/g, '%7E' );
}

function MakeUserName(n)
{
  var strName = trim(n.value);
  i = strName.indexOf(' ');
  if (i != -1)
  {
    var strFirst = "";
    var strLast = "";
    var words=strName.split(" ");
    for (c=0; c<words.length-1;c++)
      strFirst += trim(words[c]);
    strFirst = trim(strFirst);
    strLast = trim(words[c]);

    var URL = 'newname.php?First=' + urlEncode(strFirst) + '&Last=' + urlEncode(strLast);

/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
   xmlhttp = new ActiveXObject("MfooSxml2.XMLHTTP");
 } catch (e) {
   try {
     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (E) {
     xmlhttp = false;
   }
  }
@end @*/

    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
      try {
        xmlhttp = new XMLHttpRequest();
      } catch (e) {
        xmlhttp=false;
      }
    }

    if (!xmlhttp && window.createRequest) {
      try {
        xmlhttp = window.createRequest();
      } catch (e) {
        xmlhttp=false;
      }
    }

    xmlhttp.open("GET", URL,true);
    xmlhttp.onreadystatechange=function(){
      if (xmlhttp.readyState==4) {
        if (xmlhttp.status==200){
          u = document.getElementById('usrname');
          str = xmlhttp.responseText;
          u.value=trim(str);
        }
        else
        {
          //alert('Status = ' + xmlhttp.status);
        }
      }
    }
    xmlhttp.send(null);

  }
}

function genpwd()
{
  chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  pass = "";
  for(x=0;x<10;x++)
  {
    i = Math.floor(Math.random() * 62);
    pass += chars.charAt(i);
  }
  p1 = document.getElementById('pwd1');
  p2 = document.getElementById('pwd2');
  if (trim(p1.value) == "" || trim(p2.value) == "")
  {
    p1.value = pass;
    p2.value = pass;
  }
}


function call(){
var   URL = "buybasket.php?" + buy;


/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
   xmlhttp = new ActiveXObject("MfooSxml2.XMLHTTP");
 } catch (e) {
   try {
     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (E) {
     xmlhttp = false;
   }
  }
@end @*/

  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp=false;
    }
  }

  if (!xmlhttp && window.createRequest) {
    try {
      xmlhttp = window.createRequest();
    } catch (e) {
      xmlhttp=false;
    }
  }

  xmlhttp.open("GET", URL,true);
  xmlhttp.onreadystatechange=function(){
    if (xmlhttp.readyState==4) {
      if (xmlhttp.status==200){
        small = document.getElementById('smallval');
        small.innerHTML = xmlhttp.responseText;
        try
        {
          soundManager.play('bing');
        }
        catch(err)
        {
        }
      }
      else
      {
        //alert('Status = ' + xmlhttp.status);
      }
    }
  }
  xmlhttp.send(null);
}

function doMove()
{
  tx = tx + dx;
  ty = ty + dy;

  foo.style.left = Math.floor(tx)+'px';
  foo.style.top = Math.floor(ty)+'px';
  if (smally > ty )
  {
  }
  else
  {
    clearInterval(intervall);
    call();
    foo.style.position = "static";
    foo.style.left = fooSx+'px';
    foo.style.top = sy+'px';
  }
}

function getY( oElement )
{
  var iReturnValue = 0;
  while( oElement != null ) {
    iReturnValue += oElement.offsetTop;
    oElement = oElement.offsetParent;
  }
  return iReturnValue;
}

function getX( oElement )
{
  var iReturnValue = 0;
  while( oElement != null ) {
    iReturnValue += oElement.offsetLeft;
    oElement = oElement.offsetParent;
  }
  return iReturnValue;
}


function initbuy() {
  foo = document.getElementById('fooObject'); // get the foo object
  small = document.getElementById('smallbasket'); // get the foo object
  smallx = getX(small);// + parseInt(small.style.width) / 2;
  smally = getY(small);// + parseInt(small.style.height) / 2;
  fooSx = parseInt(foo.style.left);
  sy = parseInt(foo.style.top);
  sr = parseInt(foo.style.right);
  sb = parseInt(foo.style.bottom);
  tx = getX(foo);
  ty = getY(foo);
  dx = (smallx - (tx))/30;// + parseInt(foo.style.width) / 2)) / 100;
  dy = (smally - (ty))/30;// + parseInt(foo.style.height) / 2)) / 100;
  foo.style.left = getX(foo) + 'px'; // set its initial position to 0px
  foo.style.top = getY(foo) + 'px'; // set its initial position to 0px
  foo.style.position = "absolute";
  intervall = setInterval(doMove,20); // call doMove in 20msec
}

function dobuy(n){
  buy=n;
  initbuy();
  return false;
}

function doublebuy(a1, e, nm)
{
  foo = document.getElementById(nm); // get the foo object
  small = document.getElementById('smallbasket'); // get the foo object
  smallx = getX(small);// + parseInt(small.style.width) / 2;
  smally = getY(small);// + parseInt(small.style.height) / 2;
  fooSx = parseInt(foo.style.left);
  sy = parseInt(foo.style.top);
  sr = parseInt(foo.style.right);
  sb = parseInt(foo.style.bottom);
  tx = getX(foo);
  ty = getY(foo);
  dx = (smallx - (tx))/30;// + parseInt(foo.style.width) / 2)) / 100;
  dy = (smally - (ty))/30;// + parseInt(foo.style.height) / 2)) / 100;
  foo.style.left = getX(foo) + 'px'; // set its initial position to 0px
  foo.style.top = getY(foo) + 'px'; // set its initial position to 0px
  foo.style.position = "absolute";
  buy = a1;

  intervall = setInterval(doMove,20); // call doMove in 20msec

  if (window.event)
  {
    window.event.cancelBubble=true;
  }
  else
  {
	if (e.cancelable )
    {
      e.stopPropagation();
    }
  }
  return false;
}

function sendform(el)
{
  var sub = el.getElementsByTagName('input');
  query = new Array();
  for(i in sub)
  {
    if(sub[i].name)
    {
      query.push(sub[i].name + '=' + sub[i].value);
    }
  }
  query = '?' + query.join('&');
  //alert(query);
  dobuy(query);
}



