function AjaxTransport(targetElementID)
{
	this.elementID = targetElementID;
	this.getXMLHTTP = function(url)
	{
		var xmlHttp = false;
		// Internet Explorer
		try
		{
			xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				xmlHttp  = false;
			}
		}          
		// Mozilla, Opera und Safari
		if (!xmlHttp && typeof XMLHttpRequest != 'undefined')
		{
			xmlHttp = new XMLHttpRequest();
		}
		if (xmlHttp)
		{
			xmlHttp.open('POST', url, true);
			xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');						
			xmlHttp.onreadystatechange = function ()
			{
				if (xmlHttp.readyState == 4) //Complete
				{
					var oldElement = document.getElementById('configurator');
					if (oldElement)
					{	
						var responseText = xmlHttp.responseText;
						if( responseText.indexOf("global.errors.Exception") > -1 )
						{
							window.location = "system.dt";
						}
						else
						{
							var parentElement = oldElement.parentNode;
							oldElement.innerHTML = responseText;
							
							init();
						}
					}
				}
			};
			return xmlHttp;
		}
		else
		{
			alert("Your browser does not support XmlHttpRequest. Please use either Firefox 1.5, Internet Explorer 6.0, or Opera 9.0 or better.");
                        return null;
		}
	}
	
	this.send = function(postURL, postValue)
	{
		this.getXMLHTTP(postURL).send(postValue);
	}				
}

function ajaxSubmit(formID, elementID, originalFormAction, ajaxFormAction, params)
{
	var form = document.getElementById(formID);
	if (typeof encodeURIComponent == "function")
	{
		var postURL = form.action;
		postURL = postURL.replace(originalFormAction, ajaxFormAction);					
		var postValue = "cs_ignore=true";
		if (params!=null && params!="")					
		{
			postURL = postURL + "?" + params;
		}
		
		for (i = 0; i < form.elements.length; i++)
		{
			if (form.elements[i].type == 'checkbox')
			{
				if (form.elements[i].checked)
				{
					postValue += '&';
					postValue += encodeURIComponent(form.elements[i].name);
					postValue += '=';
					postValue += encodeURIComponent(form.elements[i].value);
				}
			}
			else if (form.elements[i].type == 'radio')
			{
				if (form.elements[i].checked)
				{
					postValue += '&';
					postValue += encodeURIComponent(form.elements[i].name);
					postValue += '=';
					postValue += encodeURIComponent(form.elements[i].value);
				}
			}
			else if (form.elements[i].type != 'submit')
			{
				postValue += '&';
				postValue += encodeURIComponent(form.elements[i].name);
				postValue += '=';
				postValue += encodeURIComponent(form.elements[i].value);
			}
		}
		if (new AjaxTransport(elementID).send(postURL, postValue) == false)
		{
			form.submit();
		}
	}
	else
	{
		form.submit();
	}
}

function toggleCartOnServer(sessionID)
{
	var url = "cartstatus.dt;jsessionid=" + sessionID;
	var xmlHttp = false;
	
	// Internet Explorer
	try
	{
		xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e)
		{
			xmlHttp  = false;
		}
	}          
	// Mozilla, Opera und Safari
	if (!xmlHttp && typeof XMLHttpRequest != 'undefined')
	{
		xmlHttp = new XMLHttpRequest();
	}
	if (xmlHttp)
	{
		xmlHttp.open('POST', url, true);			
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');
		
		xmlHttp.onreadystatechange = function()
		{
		};
		xmlHttp.send("null");
	}
	else
	{
		alert("Your browser does not support XmlHttpRequest. Please use either Firefox 1.5, Internet Explorer 6.0, or Opera 9.0 or better.");
	}
			
}