function HttpClient() { } // HTTPCLIENT CLASS
HttpClient.prototype = {
	// type GET,POST passed to open
	requestType:'GET',
	// Boundary for POST vars
	boundary:'',
	// when set to true, async calls are made
	isAsync:true,
	// where an XMLHttpRequest instance is stored
	xmlhttp:false,
	// what is called when a successful async call is made
	callback:function(xmlDoc)
	{		
		//Loads Models
		if(xmlDoc.getElementsByTagName("LoadModels").length > 0)
		{		 
		  LoadModels(xmlDoc.getElementsByTagName("LoadModels")[0].childNodes[0].nodeValue+"<br>");
		}
		//Loads FavButton
		if(xmlDoc.getElementsByTagName("LoadFB").length > 0)
		{		 
		  LoadFB(xmlDoc.getElementsByTagName("LoadFB")[0].childNodes[0].nodeValue+"<br>");
		} 
		
		//Load VIP
		if(xmlDoc.getElementsByTagName("LoadVIP").length > 0)
		{		 
		  loadVIP(xmlDoc.getElementsByTagName("LoadVIP")[0].childNodes[0].nodeValue+"<br>");
		} 
		
	    //Call createCar function
		if(xmlDoc.getElementsByTagName("LoadCarInfo").length > 0)
		{
		  loadCarInfo(xmlDoc.getElementsByTagName("LoadCarInfo")[0].childNodes[0].nodeValue+"<br>");
		}
	    //Call createCar function
		if(xmlDoc.getElementsByTagName("CreateCar").length > 0)
		{
		  createCar(xmlDoc.getElementsByTagName("CreateCar")[0].childNodes[0].nodeValue+"<br>");
		}
	    //Call UpdateCar function
		if(xmlDoc.getElementsByTagName("UpdateCar").length > 0)
		{
		  updateCar(xmlDoc.getElementsByTagName("UpdateCar")[0].childNodes[0].nodeValue+"<br>");
		}
		
	    //Call LoadAnnounceInfo function
		if(xmlDoc.getElementsByTagName("LoadAnnounceInfo").length > 0)
		{
		  loadAnnounceInfo(xmlDoc.getElementsByTagName("LoadAnnounceInfo")[0].childNodes[0].nodeValue+"<br>");
		}
	    //Call createAnnonce function
		if(xmlDoc.getElementsByTagName("CreateAnnounce").length > 0)
		{
		  createAnnounce(xmlDoc.getElementsByTagName("CreateAnnounce")[0].childNodes[0].nodeValue+"<br>");
		}
	    //Call UpdateAnnounce function
		if(xmlDoc.getElementsByTagName("UpdateAnnounce").length > 0)
		{
		  updateAnnounce(xmlDoc.getElementsByTagName("UpdateAnnounce")[0].childNodes[0].nodeValue+"<br>");
		} 
		
	    //Call LoadAccessoryInfo function
		if(xmlDoc.getElementsByTagName("LoadAccessoryInfo").length > 0)
		{
		  loadAccessoryInfo(xmlDoc.getElementsByTagName("LoadAccessoryInfo")[0].childNodes[0].nodeValue+"<br>");
		}
	    //Call createAccessory function
		if(xmlDoc.getElementsByTagName("CreateAccessory").length > 0)
		{
		  createAccessory(xmlDoc.getElementsByTagName("CreateAccessory")[0].childNodes[0].nodeValue+"<br>");
		}
	    //Call UpdateAccessory function
		if(xmlDoc.getElementsByTagName("UpdateAccessory").length > 0)
		{
		  updateAccessory(xmlDoc.getElementsByTagName("UpdateAccessory")[0].childNodes[0].nodeValue+"<br>");
		} 
		
	    //Call LoadStransportInfo function
		if(xmlDoc.getElementsByTagName("LoadStransportInfo").length > 0)
		{
		  loadStransportInfo(xmlDoc.getElementsByTagName("LoadStransportInfo")[0].childNodes[0].nodeValue+"<br>");
		}
	    //Call createStransport function
		if(xmlDoc.getElementsByTagName("CreateStransport").length > 0)
		{
		  createStransport(xmlDoc.getElementsByTagName("CreateStransport")[0].childNodes[0].nodeValue+"<br>");
		}
	    //Call UpdateAccessory function
		if(xmlDoc.getElementsByTagName("UpdateStransport").length > 0)
		{
		  updateStransport(xmlDoc.getElementsByTagName("UpdateStransport")[0].childNodes[0].nodeValue+"<br>");
		} 
		
	    //Call LoadCompanyInfo function
		if(xmlDoc.getElementsByTagName("LoadCompanyInfo").length > 0)
		{
		  loadCompanyInfo(xmlDoc.getElementsByTagName("LoadCompanyInfo")[0].childNodes[0].nodeValue+"<br>");
		}
	    //Call createCompany function
		if(xmlDoc.getElementsByTagName("CreateCompany").length > 0)
		{
		  createCompany(xmlDoc.getElementsByTagName("CreateCompany")[0].childNodes[0].nodeValue+"<br>");
		}
	    //Call UpdateCompany function
		if(xmlDoc.getElementsByTagName("UpdateCompany").length > 0)
		{
		  updateCompany(xmlDoc.getElementsByTagName("UpdateCompany")[0].childNodes[0].nodeValue+"<br>");
		} 
		
		//Loads LoadUserInfo
		if(xmlDoc.getElementsByTagName("LoadUserInfo").length > 0)
		{		  
		  loadUserInfo(xmlDoc.getElementsByTagName("LoadUserInfo")[0].childNodes[0].nodeValue+"<br>");
		} 
	    //Call createUser function
		if(xmlDoc.getElementsByTagName("CreateUser").length > 0)
		{
		  createUser(xmlDoc.getElementsByTagName("CreateUser")[0].childNodes[0].nodeValue+"<br>");
		}
	    //Call UpdateUser function
		if(xmlDoc.getElementsByTagName("UpdateUser").length > 0)
		{
		  updateUser(xmlDoc.getElementsByTagName("UpdateUser")[0].childNodes[0].nodeValue+"<br>");
		} 
		
		//Loads Ticket
		if(xmlDoc.getElementsByTagName("LoadTicket").length > 0)
		{		 
		  LoadTicket(xmlDoc.getElementsByTagName("LoadTicket")[0].childNodes[0].nodeValue+"<br>");
		} 
	},
	// what is called when send is called on XMLHttpRequest
	// set your own function to onSend to have a custom loading
	// effect
	onSend:function()
	{
		//document.getElementById('HttpClientStatus').style.display = 'block';		
	},
	
	// what is called when readyState 4 is reached, this is
	// called before your callback
	onload:function()
	{
		//document.getElementById('HttpClientStatus').style.display = 'none';	
				
	},
	
	// what is called when an http error happens
	onError:function(error)
	{
		alert(error);
	},
	createHTMLNode: function(htmlCode, elementName,id) 
    {
        // create html node
        var htmlNode = document.createElement(elementName);
        htmlNode.setAttribute('id',id);
        //htmlNode.setAttribute('style','-moz-user-select: none;');
        //htmlNode.setAttribute('tabindex','-1');
        htmlNode.innerHTML = htmlCode;    
        return htmlNode;
    },
    loading: function(NodeId)
    {	       
       	var layer = document.getElementById('Load'+NodeId);       	
        var cNode = document.getElementById('Loaded'+NodeId);
        
        if(cNode != null) 
        {
            layer.removeChild(cNode);		
		    var HtmlNode = createHTMLNode('<div style="margin-left:7px;margin-right:7px;margin-top:7px;margin-bottom:7px;"><img src="./images/ajax-loader.gif" ></div>','div','Loading'+NodeId);
		    layer.appendChild(HtmlNode);
        }      
        
    },
	// method to initialize an xmlhttpclient
	init:function()
	{
		try
		{
			// Mozilla / Safari
			this.xmlhttp = new XMLHttpRequest();
		}
		catch (e)
		{
			// IE
			var XMLHTTP_IDS = new Array('MSXML2.XMLHTTP.5.0',
				 'MSXML2.XMLHTTP.4.0',
				 'MSXML2.XMLHTTP.3.0',
				 'MSXML2.XMLHTTP',
				 'Microsoft.XMLHTTP');
			var success = false;
			for (var i=0;i < XMLHTTP_IDS.length && !success; i++)
			{
				try
				{
					this.xmlhttp = new ActiveXObject
					(XMLHTTP_IDS[i]);
					success = true;
				}
				catch (e)
				{}
			}
			if (!success)
			{
				this.onError('Unable to create XMLHttpRequest.');
			}
		}
	},
	// method to make a page request
	// @param string url  The page to make the request to
	// @param string payload  What you're sending if this is a POST
	// request
	
	makeGet: function (url,NodeId)
	{
	   this.requestType = 'GET';
	   this.makeRequest(url,NodeId,'');
	},
	makePost: function (url,NodeId,payload,boundary)
	{
	   this.requestType = 'POST';
	   this.boundary = boundary;
	   this.makeRequest(url,NodeId,payload);
	},
	
	makeRequest: function(url,NodeId,payload)
	{    
		if (!this.xmlhttp)
		{
			this.init();
		}

	    this.loading(NodeId);
        
		this.xmlhttp.open(this.requestType,url,this.isAsync);
		
		// set onreadystatechange here since it will be reset after a
		// completed call in Mozilla
		var self = this;
		this.xmlhttp.onreadystatechange = function()
		{
			self._readyStateChangeCallback();
		}

		if (this.requestType == "POST")
		{
			this.xmlhttp.setRequestHeader("Content-type", "multipart/form-data; \
                                            boundary=\""+this.boundary+"\"");
                                            
			this.xmlhttp.setRequestHeader("Content-length", payload.length);
			this.xmlhttp.setRequestHeader("Connection", "close");
		}
		
		this.xmlhttp.send(payload);
		
		if (!this.isAsync)
		{
			return this.xmlhttp.responseXML;
		}
	},
	
	// internal method used to handle ready state changes
	_readyStateChangeCallback:function()
	{
		switch(this.xmlhttp.readyState)
		{
			case 2:
				this.onSend();
				break;
			case 4:
				this.onload();
				if (this.xmlhttp.status == 200)
				{
					this.callback(this.xmlhttp.responseXML);
				}
				else
				{
					this.onError('HTTP Error Making Request: ' + '[' + this.xmlhttp.status + ']' + ' ' + this.xmlhttp.statusText);
				}
				break;
		}
		

		
	}
	

}

