// AJAX
// -----
// the createRequestObject function and it's invocation
// is required for using ajax and should be included on any page

function createRequestObject()
{
	switch( navigator.appName )
	{
		case "Microsoft Internet Explorer":
			return new ActiveXObject("Microsoft.XMLHTTP");
		default:
			return new XMLHttpRequest();
	}
}

// defaultResponse
// ---
// a generic function that can parse for successful ajax response, return an error
// or follow a redirection command

function defaultResponse( ajax )
{
  if( ajax.readyState == 4 )
  {
    // Debugging
    // alert(ajax.responseText);

    // if the tab is added successfully close the addtab popbox
    // otherwise check for ERROR or REDIRECT messages
    
    if( !ajax.responseText.match(/^(ERROR|REDIRECT):/) )
    {
    	return true;
  	}
  	var responseArray = ajax.responseText.split(":");
    switch( responseArray[0] )
    {
    	case "ERROR":
    		alert( responseArray[1] );
    		break;
    	case "REDIRECT":
    		window.location = responseArray[1];
    		break;
    }
  }
  return false;
}

// simpleDefaultResponse
// ---
// A debugging tool that just spits out the response text
function simpleDefaultResponse()
{
  if( ajax.readyState == 4 )
  {
    alert(ajax.responseText);
  }
}

var ajax = createRequestObject();
