url = "http://my.hockeybuzz.com/";


function sendRequest( where , handle )
{
  	var request;

  	//Send the userid and roomid with every request.

  	request = initializeRequestObject();
  	request.open( 'GET' , where , true );
  	//request.setRequestHeader( 'Method' , 'GET ' + where + ' HTTP/1.1' );
  	//request.setRequestHeader( 'Content-Type' , 'application/x-www-form-urlencoded' );

  	request.onreadystatechange = function()
    	{
      		if( request.readyState == 4 )
      		{
        		if( request.status == 200 )
        		{
          			handle( request.responseText );
        		}
        		else
        		{
          			errors++;
        		}
        		//request.onreadystatechange = Fluxchat.emptyFunction;
      		}
    	}

  	request.send('');
}

function initializeRequestObject()
{
	if(typeof XMLHttpRequest != 'undefined')
  	{
    		try
    		{
      			return new XMLHttpRequest();
    		}
    		catch ( error )
    		{
      			errors++;
    		}
  	}
  	else if(window.ActiveXObject)
  	{
    		var Versions = ['MSXML2.XMLHttp.5.0', 'MSXML2.XMLHttp.4.0', 'MSXML2.XMLHttp.3.0', 'MSXML2.XMLHttp', 'Microsoft.XMLHttp'];
    		for ( var i = 0; i < Versions.length; i++ )
    		{
      			try
      			{
        			var XMLHttp = new ActiveXObject( Versions[ i ] );
        			return XMLHttp;
      			}
      			catch ( error )
      			{
        			//Older versions of IE will have tons of errors.
        			errors++;
      			}
    		}
  	}
  	else
  	{
    		errors++;
  	}
}



function add_message(to_user_id)
{
	message = document.getElementById('message_textarea').value;
	sendRequest("/library/services/addMessage.php?message=" + message + "&to_user_id=" + to_user_id, update_messages);
}

function delete_message(message_id)
{
	sendRequest("/library/services/deleteMessage.php?message_id=" + message_id, update_messages);
}

function update_messages(str)
{
	document.getElementById('messages_list').innerHTML = str;
	document.getElementById('message_textarea').value = '';
}

function add_comment(post_id)
{
        comment = document.getElementById('comment_textarea').value;
	document.getElementById('comment_textarea').value = 'Message Posted';
        sendRequest("/library/services/addComment.php?comment=" + comment + "&post_id=" + post_id, update_comments);
}

function delete_comment(comment_id)
{
        sendRequest("/library/services/deleteComment.php?comment_id=" + comment_id, update_comments);
}

function update_comments(str)
{
	document.getElementById('comments_list').innerHTML = str;
}

function send_friend_request(user_id)
{
        sendRequest("/library/services/friendRequest.php?user_id=" + user_id, site_alert);
}

function site_alert(str)
{
	document.getElementById('shadow').style.visibility = 'visible';
	document.getElementById('crosshairs').style.visibility = 'visible';
	document.getElementById('alert').style.visibility = 'visible';
	str = str + '<br><br><center><a href="#" onClick="hide_alert();"><img src="http://cdn.hockeybuzz.com/images/myhockeybuzz/ok_button.gif" border="0"></a></center>';
	document.getElementById('alert').innerHTML = str;
}

function hide_alert()
{
	document.getElementById('shadow').style.visibility = 'hidden';
        document.getElementById('crosshairs').style.visibility = 'hidden';
        document.getElementById('alert').style.visibility = 'hidden';
        document.getElementById('alert').innerHTML = '';
}



