var ajax = {
		'XMLRequestObject':function(){
			var xmlhttp = false;
    	/*@cc_on @*/
    	/*@if (@_jscript_version >= 5)
    	// JScript gives us Conditional compilation, we can cope with old IE versions.
    	// and security blocked creation of the objects.
    	 try {
    	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    	 } catch (e) {
    	  try {
    	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    	  } catch (E) {
    	   xmlhttp = false;
    	  }
    	 }
    	@end @*/
    	if (!xmlhttp && typeof XMLHttpRequest != "undefined") {
    		try {
    			xmlhttp = new XMLHttpRequest();
    		}
    		catch (e) {
    			xmlhttp = false;
    		}
    	}
    	if (!xmlhttp && window.createRequest) {
    		try {
    			xmlhttp = window.createRequest();
    		}
    		catch (e) {
    			xmlhttp = false;
    		}
    	}
    	return xmlhttp;
		},
		'RequestUrl':function(url,callback){
			var req = this.XMLRequestObject();
			if(!req){return false;}
			var async = false;
			if(callback){
				async = true;
				req.onreadystatechange = function(){
					if(req.readyState == 4)
						callback(req);
				};
			}
			req.open("GET", url, async);
			req.send("");
			if(async)
				return true;
			return req;
		},
		'DelayedRequestUrl':function(delay,url,callback){
			if(!callback){
				throw "Delayed requests should always have a callback";
			}
			var req = this.XMLRequestObject();
			if(!req){return false;}
			req.onreadystatechange = function(){
				if(req.readyState == 4)
					callback((req.status==200),req);
			};
			req.open("GET", url, true);
			setTimeout(function(){req.send("");},delay);
			return true;
		},
		'RequestUrlInto':function(delay,url,callback,obj,property){
			var portFunct =  function(status,req){
				if(req.status == 200){
					obj[property] = req.responseText;
					$A.interactive.addTitleSpans();
					if(callback)
						callback(true,req);
				}else{
					obj[property] = 'Server response: '+req.status;
					if(callback)
						callback(false,req);
				}
			}
			return this.DelayedRequestUrl(delay,url,portFunct);
		},
		'PostForm':function(frm,callback,actionAppend){
			var conf = this.GetConfigForm({form:frm,callbackMethod:callback,uriAppend:actionAppend});
			return this.ConfigedRequest(conf);
		},
		'PostFormSimple':function(formId,newFormAction,ajaxHtmlId)
		{		  
		  var ajaxFormObj = document.getElementById(formId);
		  // store old action, we will be temporarily replacing it
		  var oldFormAction = ajaxFormObj.action;
		  // set the new action
		  ajaxFormObj.action = newFormAction;
		  // make the Ajax call
			var toReturn = this.PostForm(ajaxFormObj,function(success,req){document.getElementById(ajaxHtmlId).innerHTML = req.responseText;},'&-PARTIAL-='+ajaxHtmlId);
			// restore the original form action
			ajaxFormObj.action = oldFormAction;
			return toReturn;
		},
		'ConfigedRequest':function(conf){
			var req = this.XMLRequestObject();
			if(!req){return false;}
			if(conf.errorCallback == void(0) && conf.callbackMethod){
				conf.errorCallback = conf.callbackMethod;
			}
			if(conf.asyncCallback){
				req.onreadystatechange = function(){
					if(req.readyState == 4){
						if(req.status == 200){
							if(conf.callbackMethod)
								conf.callbackMethod(true,req);
						}else{
							if(conf.errorCallback){
								conf.errorCallback(false,req);
							}
						}
					}
				};
			}
			var finalUri = conf.requestUri+conf.uriAppend;
			req.open(conf.requestMethod, finalUri,conf.asyncCallback);
			if(conf.requestMethod == 'POST'){
				req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				req.setRequestHeader("Content-length", conf.sendContent.length);
				req.setRequestHeader("Connection", "close");
			}
			if(conf.beforeSend){
				if(!conf.beforeSend()){
					return false;
				}
			}
			req.send(conf.sendContent);
			if(!conf.asyncCallback && conf.callbackMethod){
				conf.callbackMethod((req.status == 200),req);
			}
			return true;
		}
		,
		'GetConfigForm':function(config){
			if(!config.form){
					throw "No form found";
			}
			var params = this.FormToParamsString(config.form);
			var uri = config.form.attributes.action.value;
			if(!config.requestMethod){
				if(/get/i.test(config.form.getAttribute('method'))){
					config.requestMethod = 'GET';
				}else{
					config.requestMethod ='POST';
				}
			}
			if(config.requestMethod == 'GET'){
				if(uri.indexOf('?') > -1){
					uri += '&'+params;
				}else{
					uri += '?'+params;
				}
				config.sendContent = '';
			}else{
				config.sendContent = params;
			}
			config.requestUri = uri;
			if(!config.uriAppend){config.uriAppend = '';}
			if(config.asyncCallback == void(0)){config.asyncCallback = true;}
			return config;
		},
	
		'FormToNamedArray':function(form){
			if(!form.elements)
				throw "Object is not a form";
			var params = [];
			for(var i=0; i< form.elements.length;i++){
				var element = form.elements[i];
				if(element && (element.nodeName == 'INPUT' || element.nodeName == 'TEXTAREA' || element.nodeName == 'SELECT')){
					if(element.type == 'checkbox'){							// enable checkbox support even when it is not checked
						params[element.name] = element.checked?'on':'off';
					}else if( element.type == 'radio'){						// only save the selected one
						if(element.checked){
							params[element.name] = element.value;
						}
					}else{
						params[element.name] = element.value;
					}
				}
			}
			return params;
		},
		'NamedArrayToUrlencParamsString':function(namedArray){
			var myLine = "";
			var first = true;
			for (var e in namedArray){
				var value = namedArray[e];
				var encName = encodeURIComponent(e);
				var encVal = encodeURIComponent(value);
				if(!first){
					myLine += "&";
				}else{
					first = false;
				}
				myLine += encName+"="+encVal;
			}
			return myLine;
		},
		'FormToParamsString':function(form){
			var namedArray = this.FormToNamedArray(form);
			return this.NamedArrayToUrlencParamsString(namedArray);
		}

	};
