<!--

//alert('a2');

function Ajax(methodtype,formname,responseFormat) 
{

this.req = null;
this.url = null;
//this.method = 'GET';
//this.method = 'POST';
this.method = methodtype;
this.async = true;
this.status = null;
this.statusText = '';
this.postDate = null;
this.readyState = null;
this.responseText = null;
this.responseXML = null;
this.handleResp = null;
this.responseFormat = responseFormat; // 'text', 'xml' or 'object'
this.mimeType = null;


	//******* Method to init the creation of an XMLHttpRequest object *******
	this.init = function()
	{
		
		if(!this.req)
		{
	
			try 
			{
			// Try to create object for Firefox, Safari, IE7, etc...
			this.req = new XMLHttpRequest();
			}
			catch (e)
			{
				try 
				{
				// Try to create object for later versions of IE.
				this.req = new ActiveXObject('MSXML2.XMLHTTP');
				}
				catch (e)
				{
					try 
					{
					// Try to create object for early versions of IE.
					this.req = new ActiveXObject('MSXML.XMLHTTP');
					}
					catch (e)
					{
					alert('Could not create an XMLHttpRequest object.');
					// Could not create an XMLHttpRequest object.
					}
				}	
			}
		}
	return this.req;
	};
	
	//******* Method that creates an XMLHttpRequest from the created object *******
	this.doReq = function()
	{
		//alert('here3');
		if(!this.init())
		{
		alert('Could not create XMLHttpRequest object.');
		return;
		}
	
		this.req.open(this.method, this.url, this.async);
		
		// if a POST then set header to handle as a form POST
		if (this.method == 'POST')
		{
		//alert('here');
		// this does not seem to make the post work?
		//this.req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		this.req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8");
		//this.req.onreadystatechange = Response;
 
		var fields = new Array();
    
		if(formname)
		{
      	var ajax = formname;
    	}

    	//loop through form elements and retrieve field NAMEs and Values
  	
		if (eval('document.'+ajax) != undefined)
		{
		 
		for (var x = 0; x < eval("document."+ajax+".elements.length"); x++)
		{
     	
		//+   %2B
		//&   %26
		//=   %3D
		
		// convert special charaters &, = , +
		eval("document."+ajax+".elements[x].value = document."+ajax+".elements[x].value.replace(/&/g,\"%26\")");
		eval("document."+ajax+".elements[x].value = document."+ajax+".elements[x].value.replace(/=/g,\"%3D\")");
		eval("document."+ajax+".elements[x].value = document."+ajax+".elements[x].value.replace(/\\+/g,\"%2B\")");
		
		// join them into a string.
 		eval("fields.push(document."+ajax+".elements[x].name+'='+document."+ajax+".elements[x].value)");
    	
		// convert back special charater so input box look correct
		eval("document."+ajax+".elements[x].value = document."+ajax+".elements[x].value.replace(/%26/g,\"&\")");
		eval("document."+ajax+".elements[x].value = document."+ajax+".elements[x].value.replace(/%3D/g,\"=\")");
		eval("document."+ajax+".elements[x].value = document."+ajax+".elements[x].value.replace(/%2B/g,\"+\")");
		
		
		}
		
		var elem
		 elem = 'errors';
    	//sendf looks like "username=myusername&password=mypass"
    	var POSTstr = fields.join('&');
		
		//do this outside post if
		//this.req.send(POSTstr)
		
    	}
	
	
   
			}
	
		/*	this is causing a problem */
		if (this.mimeType)
		{
			try
			{
			req.overrideMimeType(this.mimeType);
			}
			catch (e)
			{
			alert('Couldnt override MIME type -- IE6 or Opera?');
			// couldn't override Mim type -- IE6 or Opera?
			}
		
		}
		
	
		var self = this; // Fix loss-of-scope in inner function
	
		this.req.onreadystatechange = function()
		{
	
		var resp = null;
	
		// 0: uninitialized - open has not been called yet
		// 1: loading - send has not been called yet
		// 2: loaded - send has been called, but the response is not yet available
		// 3: interactive - the response is being downloaded, and the responseText property holds partial date
		// 4: completed - the response has been loaded and the request is completed
	
			if(self.req.readyState == 4)
			{
			// do stuff to handle response
			
				switch (self.responseFormat)
				{
				case 'text':
					resp = TrimString(self.req.responseText);
					//document.getElementById('errorarea').innerHTML = resp;
					//alert('~' + resp);
					break;
				case 'xml':
					resp = self.req.responseXML;
					break;
				case 'object':
					resp = req;
					break;
				}
			
				if(self.req.status >= 200 && self.req.status <= 299)
				{
				self.handleResp(resp);
				}
				else
				{
				self.handleErr(resp);
				}
			
			
			}
	
		};
		
	this.req.send(POSTstr)
		
	//alert('here5');
	// the post is happening above
	//this.req.send(this.postData);
	//alert('here6');
	};
	
	//******* Method sets the mineType property *******
	this.setMimeType = function(mimeType)
	{
		this.mineType = mimeType;
	};
	
	//******* Method checks to make sure pop-ups are not bloacked, then tries to display the full text of the server's error page content in a new browser window. *******
	this.handleErr = function()
	{
		var errorWin;
		try
		{
		errorWin = window.open('error.cfm', 'errorWin');
		errorWin.document.body.innerHTML = '-' + this.responseText + '-';
		}
		
		catch (e)
		{
		alert('An error occurred, but the error message cannot be '
		+ 'displayed. This is probably because of your browser\'s '
		+ 'pop-up blocker.\n'
		+ 'Please allow pop-ups from this web site if you want to '
		+ 'see the full error messages.\n'
		+ '\n'
		+ 'Status Code: ' + this.req.status + '\n'
		+ 'Status Description: ' + this.req.status.Text);
		}
	};
	
	//******* Method for setting custome error handling info 
	this.setHandlerErr = function(funcRef)
	{
	this.handleErr = funcRef;
	};
	
	//******* Method for handling both successful responses and errors. 
	this.setHandlerBoth = function(funcRef)
	{
	this.handleResp = funcRef;
	this.handleErr = funcRef;
	};
	
	//******* Method changes the onreadystate event handler to an empty function, calls the abort method on your instance of the XMLHttpRequest class, then destroys the instance you've created. 
	this.abort = function()
	{
		if (this.req)
		{
		this.req.onreadystatechange = function() {};
		this.req.abort();
		this.req = null;
		}
	};
	
	//******* Method sets both the target url and a handler functiin for the response
	this.doGet = function(url, hand, format)
	{
		//alert('here2');
		this.url = url;
		this.handleResp = hand;
		this.responseFormat = format || 'text';
		this.doReq();
	};
	
	
} // Ajax()
//-->

