function ajax()
{
   //---------------------
   // Private Declarations
   //---------------------
   var _request = null;
   var _this = null;
       
   //--------------------
   // Public Declarations
   //--------------------
   this.GetResponseXML = function()
   {
      return (_request) ? _request.responseXML : null;
   }
       
   this.GetResponseText = function()
   {
      return (_request) ? _request.responseText : null;
   }
       
   this.GetRequestObject = function()
   {
      return _request;
   }
       
   this.InitializeRequest = function(Method, Uri)
   {
      _InitializeRequest();
      _this = this;
               
      switch (arguments.length)
      {
         case 2:
            _request.open(Method, Uri);
            break; 
                               
         case 3:
            _request.open(Method, Uri, arguments[2]);
            break;
      }
               
      if (arguments.length >= 4) _request.open(Method, Uri, arguments[2], arguments[3]);
      this.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
   }
       
   this.SetRequestHeader = function(Field, Value)
   {
      if (_request) _request.setRequestHeader(Field, Value);
   }
       
   this.Commit = function(Data)
   {
      if (_request) _request.send(Data);
   }
       
   this.Close = function()
   {
      if (_request) _request.abort();
   }
       
   //---------------------------
   // Public Event Declarations.
   //---------------------------
   this.OnUninitialize = function() { };
   this.OnLoading = function() { };
   this.OnLoaded = function() { };
   this.OnInteractive = function() { };
   this.OnSuccess = function() { };
   this.OnFailure = function() { };
       
   //---------------------------
   // Private Event Declarations
   //---------------------------
   function _OnUninitialize() { _this.OnUninitialize(); };
   function _OnLoading() { _this.OnLoading(); };
   function _OnLoaded() { _this.OnLoaded(); };
   function _OnInteractive() { _this.OnInteractive(); };
   function _OnSuccess() { _this.OnSuccess(); };
   function _OnFailure() { _this.OnFailure(); };

   //------------------
   // Private Functions
   //------------------
   function _InitializeRequest()
   {
      _request = _GetRequest();
      _request.onreadystatechange = _StateHandler;
   }
       
   function _StateHandler()
   {
      switch (_request.readyState)
      {
         case 0:
            window.setTimeout("void(0)", 100);
            _OnUninitialize();
            break;
                               
         case 1:
            window.setTimeout("void(0)", 100);
            _OnLoading();
            break;
                               
         case 2:
            window.setTimeout("void(0)", 100);
            _OnLoaded();
            break;
                       
         case 3:
            window.setTimeout("void(0)", 100);
            _OnInteractive();
            break;
                               
         case 4:
            if (_request.status == 200)
               _OnSuccess();
            else
               _OnFailure();
                                       
            return;
            break;
      }
   }
       
   function _GetRequest()
   {
      var obj;
               
      try
      {
         obj = new XMLHttpRequest();
      }
      catch (error)
      {
         try
         {
            obj = new ActiveXObject("Microsoft.XMLHTTP");
         }
         catch (error)
         {
            return null;
         }
      }
               
      return obj;
   }
}

function getData(url){

	this.trys=0;
	this.status=0;
	this.response = '';
	//this.data="";
	//$('debugger').innerHTML = url;
	this.OnSuccess = function(){
	//	window.setTimeout("void(0)", 100);  // IE sometimes needs a little more time
		this.status="complete";
		
		//this.response=this.GetResponseText();
		//alert(this.GetResponseText());
	}
	this.OnLoading = function(){
		this.status="loading";
		//alert("loading");
	}
	this.OnLoaded = function(){
		this.status="loaded";
		//alert("loaded");
	}
	this.OnInteractive= function(){
		this.status="interactive";
		//alert("interactive");
	}
	
	this.OnFailure =function(){
		this.error=this.status;
		this.Close;
	}
	
	this.InitializeRequest('GET', url);
	this.Commit(null);
}
getData.prototype = new ajax();



/*
**   Mysite Class = for logging in/logging out and retrieving variables from database
**   Requires [xmlDirectory]/Login.php
**   Initiate with Mysite = new mysite(xmlDirectory); 
**   Uses: 
**   Mysite.login(email, password) //: to log in
**   Mysite.logout();  //:to log out
**   Mysite.userName  // returns Users first name 
**   Mysite.userId  // returns Users db  id
**   Mysite.error()  // returns errors such as incorrect password, unregistered user
**   etc....
*/

function mysite(xmlDirectory) {	
		this.userId='';
		this.userName='';
		this.userPass='';
		this.userEmail='';
		this.isLoggedIn="false";
		this.error= "";
		this.userSurname="";
		this.userTitle='';
		
		this.OnSuccess = function(){
			data=this.GetResponseText();
			data=data.split("\n");
				
				if(data[0]=='loggingin'){
				
					str=data[1];
					str=str.split("=");
					this.userId=str[1];
				
					str=data[2];
					str=str.split("=");
					this.userName=str[1];
					
					str=data[3];
					str=str.split("=");
					this.userEmail=str[1];
					
					str=data[4];
					str=str.split("=");
					this.userSurname=str[1];
				
					str=data[5];
					str=str.split("=");
					this.userTitle=str[1];
				
					this.isLoggedIn="true";
				}else{
					this.isLoggedIn="false";
					
					str=data[1];
					str=str.split("=");
					this.error=str[1];
				}
		}
		this.login= function (email,password){
			if(email==""){
				this.error="Please enter an email address";
			} else
			if(password==""){
				this.error="Please enter a Password";
			} else{
				url=xmlDirectory+"login.php?logging=in&email="+email+"&password="+password;
				this.InitializeRequest('GET', url);
				this.Commit(null);
				this.userPass=password;
				this.userEmail=email;
			}
		}
		this.logout= function () {
				url=xmlDirectory+"login.php?logging=out";
				this.InitializeRequest('GET', url);
				this.Commit(null);
		}
		
      }
      
mysite.prototype = new ajax();
