var ISITE = {
	// we use a javascript feature here called "inner functions"
	// using these means the local variables retain their values after the outer function
	// has returned. this is useful for thread safety, so
	// reassigning the onreadystatechange function doesn't stomp over earlier requests.
	// methodology invented/used from brockweaver on xml.com http://www.xml.com/cs/user/view/cs_msg/2815
	
	HttpRequest : function(url, callback, async) {
		// this function is a 'universal callback'
		// that allows us to store several requests
		// at once without losing callbacks
		function GetCallback()
		{
			 if (http_request.readyState == 4) {
		        if (http_request.status == 200) {
		            http_callback(http_request);
		        } else {
		            alert('There was a problem with the HTTP request. (HTTP Error ' + http_request.status + ' ' + http_request.statusText + ')');
		            return false;
		        }
		    }
		}
		
		// validate parameters
		if( typeof( async ) == 'undefined' ) {
			async = true;
		}
		
		if( typeof( callback ) != 'function' && async ) {
			alert( "No callback defined. A callback must be defined for async requests." );
			return false;
		}
	
		// these can have multiple copies over function calls
		// thus isolating them from event handler overwritings
	    var http_request = false;
	    var http_callback = callback;
		
		
		// create the httprequest object
	    if (window.XMLHttpRequest) { // Mozilla, Safari,...
	        http_request = new XMLHttpRequest();
	        if (http_request.overrideMimeType) {
	            http_request.overrideMimeType('text/xml');
	        }
	    } else if (window.ActiveXObject) { // IE
	        try {
	            http_request = new ActiveXObject("Msxml2.XMLHTTP");
	        } catch (e) {
	            try {
	                http_request = new ActiveXObject("Microsoft.XMLHTTP");
	            } catch (e) {}
	        }
	    }
	
	    if (!http_request) {
	        alert('Your browser does not support HTTP requests.');
	        return false;
	    }
	    
	    if( async ) {
	    	http_request.onreadystatechange = GetCallback;
	    }
	    http_request.open('GET', url, async);
	    http_request.send(null);
	    
	    // for non-async requests, we just return the request object when we're done
	    if( !async ) {
	    	if (http_request.readyState == 4) {
		        if (http_request.status == 200) {
		            return http_request;
		        } else {
		            alert('There was a problem with the request. (HTTP Error ' + http_request.status + ' ' + http_request.statusText + ')');
		            return false;
		        }
	   		}
	    }
	},
	
	HttpFormPost : function(form, callback) {
		// this function is a 'universal callback'
		// that allows us to store several requests
		// at once without losing callbacks
		function GetCallback()
		{
			 if (http_request.readyState == 4) {
		        if (http_request.status == 200) {
		            http_callback(http_request);
		        } else {
		            alert('There was a problem with the HTTP request. (HTTP Error ' + http_request.status + ' ' + http_request.statusText + ')');
		            return false;
		        }
		    }
		}
		
		// validate parameters
		if( !form ) {
			alert("Form to post was not found.");
		}
		
		if( typeof( callback ) != 'function' ) {
			alert( "No callback defined. A callback must be defined for async requests." );
			return false;
		}
	
		// these can have multiple copies over function calls
		// thus isolating them from event handler overwritings
	    var http_request = false;
	    var http_callback = callback;
		
		// get form vars
		this.formvars = ISITE.ParseFormVars(form);
		alert(this.formvars);
		// create the httprequest object
	    if (window.XMLHttpRequest) { // Mozilla, Safari,...
	        http_request = new XMLHttpRequest();
	        if (http_request.overrideMimeType) {
	            http_request.overrideMimeType('text/html');
	        }
	    } else if (window.ActiveXObject) { // IE
	        try {
	            http_request = new ActiveXObject("Msxml2.XMLHTTP");
	        } catch (e) {
	            try {
	                http_request = new ActiveXObject("Microsoft.XMLHTTP");
	            } catch (e) {}
	        }
	    }
	
	    if (!http_request) {
	        alert('Your browser does not support HTTP requests.');
	        return false;
	    }
	    
	    
	    http_request.onreadystatechange = GetCallback;
	    http_request.open('POST', form.action, true);
	    http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	    http_request.setRequestHeader("Connection", "close");
	    http_request.send(this.formvars);
	    
	    // for non-async requests, we just return the request object when we're done
	    if( !async ) {
	    	if (http_request.readyState == 4) {
		        if (http_request.status == 200) {
		            return http_request;
		        } else {
		            alert('There was a problem with the request. (HTTP Error ' + http_request.status + ' ' + http_request.statusText + ')');
		            return false;
		        }
	   		}
	    }
	},
	
	/*
	 * Copyright 2005 Matthew Eernisse (mde@fleegix.org)
	 *
	 * Licensed under the Apache License, Version 2.0 (the "License");
	 * you may not use this file except in compliance with the License.
	 * You may obtain a copy of the License at
	 * 
	 *   http://www.apache.org/licenses/LICENSE-2.0
	 * 
	 * Unless required by applicable law or agreed to in writing, software
	 * distributed under the License is distributed on an "AS IS" BASIS,
	 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	 * See the License for the specific language governing permissions and
	 * limitations under the License.
	 *
	 * Original code by Matthew Eernisse (mde@fleegix.org)
	 * Additional bugfixes by Mark Pruett (mark.pruett@comcast.net)
	 *
	*/
	
	// The var docForm should be a reference to a <form>
	ParseFormVars : function(docForm) {
	
	  var submitContent = '';
	  var formElem;
	  var lastElemName = '';
	  
	  for (i = 0; i < docForm.elements.length; i++) {
	    
	    formElem = docForm.elements[i];
	    switch (formElem.type) {
	      // Text fields, hidden form elements
	      case 'text':
	      case 'hidden':
	      case 'password':
	      case 'textarea':
	      case 'select-one':
	        submitContent += formElem.name + '=' + escape(formElem.value) + '&'
	        break;
	        
	      // Radio buttons
	      case 'radio':
	        if (formElem.checked) {
	          submitContent += formElem.name + '=' + escape(formElem.value) + '&'
	        }
	        break;
	        
	      // Checkboxes
	      case 'checkbox':
	        if (formElem.checked) {
	          // Continuing multiple, same-name checkboxes
	          if (formElem.name == lastElemName) {
	            // Strip of end ampersand if there is one
	            if (submitContent.lastIndexOf('&') == submitContent.length-1) {
	              submitContent = submitContent.substr(0, submitContent.length - 1);
	            }
	            // Append value as comma-delimited string
	            submitContent += ',' + escape(formElem.value);
	          }
	          else {
	            submitContent += formElem.name + '=' + escape(formElem.value);
	          }
	          submitContent += '&';
	          lastElemName = formElem.name;
	        }
	        break;
	        
	    }
	  }
	  // Remove trailing separator
	  submitContent = submitContent.substr(0, submitContent.length - 1);
	  return submitContent;
	},
	
	GenericCallback : function(response)
	{
		// do nothing
	},
	
	DebugCallback : function(response)
	{
		alert(response.responseText);
	}
}