var loc=location.href;
loc=loc.split('#');
loc=loc[0];
//login function
function loginBG(){
  //replace the login button with an ajax loading image
  document.getElementById("loginButton").innerHTML='<img style="padding-left:20px;padding-top:3px" src="http://www.badgegames.com/images/ajaxLoader1.gif">';
  //make the request
  ajaxRequest("http://www.badgegames.com/_ajxLogin.php?u="+urlencode(document.getElementById("username").value)+"&p="+urlencode(document.getElementById("password").value)+"&r=1",
  loginResponse,
  15,
  loginTimeout);
}

function loginResponse(r){
  if (r=='1'){//success
    window.location.href=loc;
  }else{//failure
    //put the login button back
    document.getElementById("loginButton").innerHTML='<a href="javascript:;"><img src="http://www.badgegames.com/images/btn_login.gif" alt="Login" /></a>';
    //alert the user
    alert("Uh-Oh - Invalid username or password.\n\nPlease try again.");
    
  }
}

function loginTimeout(){
  //put the login button back
  document.getElementById("loginButton").innerHTML='<a href="#"><img src="http://www.badgegames.com/images/btn_login.gif" alt="Login" onClick="login()" /></a>';
  //alert the user
  alert("Uh-Oh - The login request has timed out! Please try again.");
}
