function regRedirect(){
	var currentURL = window.location.href;
	var regURL = "http://www.bullsconnect.com/register.html?url=";
	window.location = currentURL + escape(regURL);
	//window.location = "http://www.bullsconnect.com/myprofile.html";
	}
 function showDiv(evt, id, offset){
 
    posx = mouseX(evt) - offset;    
    posy = mouseY(evt) - 20;
    //normalize to make sure we at least appear on the screen
    if(posx < 0) posx = 10;
    if(posy < 0) posy = 10;
    
    document.getElementById(id).style.left = posx + "px";
    document.getElementById(id).style.top = posy + "px";
    document.getElementById(id).style.display = "block";
    document.getElementById('UserLoginBox').style.display = "none";
 }
  function hideDiv(id){
 	document.getElementById(id).style.display = "none";
	document.getElementById('UserLoginBox').style.display = "block";
 }
function jprocessUser(user) {
    var userDataHtml = "";
	var userStatsHtml = "";
	var currentURL = window.location.href;
    if (user.DisplayName == 'anonymous') {
     // userDataHtml += "<div><a href='#none' onclick=\"showDiv(event, 'loginGoesHere',380);\" style=''>Login</a> | <a href='http://www.bullsconnect.com/register.html?url="+ escape(window.location.href); 
	 // userDataHtml +="'  style=''>Register</a></div>"; 
	  document.getElementById('loginGoesHere').style.display = "block";
	 // document.getElementById('UserLoginBox').style.display = "none";
    }
    else {
	//var urlofpers = "/profile.html?UID=" + user.UserKey.Key;
	var urlofpers = "/myprofile.html";
	//  document.getElementById('loginGoesHere').style.display = "none";
	//  document.getElementById('UserLoginBox').style.display = "block";
	  userDataHtml += "<div class='userPic'><a href='" + urlofpers + "'><img src='" + user.AvatarPhotoUrl + "' /></a></div>";
      userDataHtml += "<div class='userInfo'>Welcome, <a href='" + urlofpers + "'>" + user.DisplayName; 
	  userDataHtml += "</a>!<br />";
	  //if (user.UserTier == 'Editor') {
		//userDataHtml += "<a href='/ver1.0/cmw/overview' target='_blank'><img src='/img/workbench.jpg' /></a>&nbsp;&nbsp;";  
		  //}
	  userDataHtml += "<a href=\"javascript:gSLAuthProxy.__Render('/Authentication/Logout.rails?reloadPage=true');\"><strong>Logout</strong></a>";  
	 userDataHtml += "</div>"; 
       
	  userStatsHtml +=  "<b>Class:</b> "+user.UserTier;
	  userStatsHtml +=  "<br /><b>Messages:</b> " + user.NumberOfMessages;   
	  userStatsHtml +=  "<br/><b>LastUpdated:</b> " + user.LastUpdated;  
      userStatsHtml +=  "<br/><b>Age:</b> " + user.Age;  
      userStatsHtml += "<br/><b>Sex:</b> " + user.Sex;  
      userStatsHtml += "<br/><b>AboutMe:</b> " + user.AboutMe;  
      userStatsHtml += "<br/><b>Location:</b> " + user.Location;  
      userStatsHtml += "<br/><b>NumberOfRecommendations:</b> " + user.NumberOfRecommendations;  
      userStatsHtml += "<br/><b>CustomAnswers:</b>";  
      for (key in user.CustomAnswers) {  
      userStatsHtml += "<br/>   " + key + ": " + user.CustomAnswers[key];  
      } 

		
      // write the HTML into a <div> tag on the page.  
    //  userDataHtml = '<div id="loginStatus">' + userDataHtml + '<\/div>';
  }
var tmp;  
  	if (tmp = document.getElementById("loginStatus"))
		tmp.innerHTML = userDataHtml; 
  	if (tmp = document.getElementById("userStats"))
		tmp.innerHTML = userStatsHtml; 
}

function jClientCallBack(responseBatch) {

   for (var i = 0; i < responseBatch.Messages.length; i++) {
        var serverMessage = responseBatch.Messages[i];
    }

    for (var i = 0; i < responseBatch.Responses.length; i++) {
        var response = responseBatch.Responses[i];
        articleProcessResponse(response);
        
    }
}

function articleProcessResponse(response) {
    
	if (response.User != null) {
	     jprocessUser(response.User);
    }
    // skip the others
}

function loadUser() {
	
		var jRequestBatch = new RequestBatch();
		// Tell SiteLife who we are.
		jRequestBatch.AddToRequest(new UserKey()); 
        jRequestBatch.BeginRequest(daapiServerUrl, jClientCallBack);
	//	document.getElementById('loginGoesHere').style.display = "none";
		
}


