var sj = "";      /* Fix for a problem in IE which was complaining about the object sj not being defined */

sj = {

createHttpObj :  function(){         /* Function to make sure your browser can use AJAX */

var ajaxRequest;                                                                

try
{
ajaxRequest = new XMLHttpRequest();      /* Firefox, Opera, Safari, IE7 */  
}
  catch (e)
  { 
    try
    {
    ajaxRequest = new ActiveXObject("Msxml12.XMLHTTP");    /* IE6 */
    }
      catch(e)
      {
        try
        {
        ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");    /*IE 5.5 */
        }
          catch(e)
          {
            alert("Your Browser Does Not Support AJAX! Please Update It!")      /* This could be changed to whatever you want to happen in this case */
            return false;
          }
      }
  }
  
  return ajaxRequest;

},

load : function(url, callback, method){

var http = this.startUp();                  /* Create the Object */

if (!http || !url){alert('Error: Undefined Http Obj OR Url');return;}           /* Stop! Hammer Time! */

method = method.toUpperCase();            /* Make the method upper case */

if(!method){method = "GET";}              /* Default method is GET */

if(method != 'GET' && method != 'POST'){method = "GET";}       /* Default method is still GET */
                                                                          
var addOn = "ssRandNum=" + new Date().getTime();

url += (url.indexOf("?")+1) ? "&" : "?";
url += addOn;            /* Add Current Time To Url To Stop IE Caching The Request */


var parameters = null;     /* Default for the parameters is null, as is required for GET */


if(method == "POST")
{
                                                                               
var parts = url.split("?");     /* Remove parameters from URL and set them into the parameters variable */

url = parts[0];
parameters = parts[1];

}



http.open(method, url, true);        /* OPEN the connection */

if(method == "POST")
{
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Content-length", parameters.length);     /* Send headers about content if POST */
		http.setRequestHeader("Connection", "close");
}

http.send(parameters);          /* SEND the request */


	http.onreadystatechange = function(){            /* On state change, do something */
	if(http.readyState == 4){                /* Only if the stage is 4 though (Completed) */
	
	var res = http.responseText;              /* Set the response text into a variable */
	
		if(callback){callback(res);}           /* If a user specified callback in place, call it */
	}
}



},


startUp : function(){             /* Let's start it up */

return this.createHttpObj();      /* Create the Http Object, else we can't do anything */

}

};

 /*
 *  Useage (Example):
 *  
 *  function myFunction()
 *  {
 *    sj.load("myFile.php", function(data){document.getElementById('myElement').innerHTML = data;}, "GET");  
 *  }   
 *  
 *  The above would send a GET request to the myFile.php page and any response text would be inserted into the innerHTML of the myElement element.
 *  
 *  It would be used like so: <a href="#" onClick="myFunction();return false;">Click Me</a>
 *  
 *  (Example 2):
 *  
 *  function myFunction(var1, var2)
 *  {
 *  var1 = encodeURIComponent(var1);
 *  var2 = encodeURIComponent(var2);
 *  sj.load("myFile.php?var1="+var1+"&var2="+var2, function(data){alert('Data Receieved: ' + data);}, "POST");   
 *  }       
 *
 *  The above would send a POST request to myFile.php with the parameters var1 and var2 and their values as specified in the myFunction parameters.
 *  It would send an alert back to the browser on completion.
 *  
 *  It would be used like so: <a href="#" onClick="myFunction('value 1', 'value 2');return false;">Click Me</a>    
 *
 *
 *  CREATED BY: Conn Warwicker
 *  URL: http://www.cmrwarwicker.com 
 *  DATE: 08.03.2010
 *
 */    
