function ajax()
{
	var _request = null;
	var _this = null;

	this.index = null;

	this.GetResponseXML = function(){
		return (_request) ? _request.responseXML : null;
	}

	this.GetResponseText = function(){
		return (_request) ? _request.responseText : null;
	}

	this.GetRequestObject = function(){
		return _request;
	}

	this.InitializeRequest = function(Method, Uri){
		_InitializeRequest();
		_this = this;

		switch (arguments.length)
		{
			case 2: _request.open(Method, Uri);
				break;

			case 3: _request.open(Method, Uri, arguments[2]);
				break;
		}
		if (arguments.length >= 4) _request.open(Method, Uri, arguments[2], arguments[3]);
		this.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	}

	this.SetRequestHeader = function(Field, Value){
		if (_request) _request.setRequestHeader(Field, Value);
	}

	this.Commit = function(Data){
		if (_request) _request.send(Data);
	}

	this.Close = function(){
		if (_request) _request.abort();
	}

	this.GetState = function()
	{
		return _request.readyState;
	}

	this.OnUninitialize = function() { };
	this.OnLoading = function() { };
	this.OnLoaded = function() { };
	this.OnInteractive = function() { };
	this.OnSuccess = function() { };
	this.OnFailure = function() { };

	function _OnUninitialize() { _this.OnUninitialize(); };
	function _OnLoading() { _this.OnLoading(); };
	function _OnLoaded() { _this.OnLoaded(); };
	function _OnInteractive() { _this.OnInteractive(); };
	function _OnSuccess() { _this.OnSuccess(); };
	function _OnFailure() { _this.OnFailure(); };

	function _InitializeRequest(){
		_request = _GetRequest();
		_request.onreadystatechange = _StateHandler;
	}

	function _StateHandler(){
		switch (_request.readyState)
		{
			case 0: window.setTimeout("void(0)", 100);
				_OnUninitialize();
				break;

			case 1: window.setTimeout("void(0)", 100);
				_OnLoading();
				break;

			case 2: window.setTimeout("void(0)", 100);
				_OnLoaded();
				break;

			case 3: window.setTimeout("void(0)", 100);
				_OnInteractive();
				break;

			case 4: if (_request.status == 200) 
					_OnSuccess(); 
				else
					_OnFailure();
				return;
				break;
		}
	}

	function _GetRequest()
	{
		var obj;
		var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0;
		var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0;
		var is_opera = ((navigator.userAgent.indexOf("Opera 6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0;
		var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0;

		if (is_ie) {
			var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';
			try{
				obj = new ActiveXObject(strObjName);
			}
			catch(e){
				alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled');
				return null;
			}
		}
		else if (is_opera){
			alert('Opera detected. The page may not behave as expected.');
			return null;
		}
		else{
			obj = new XMLHttpRequest();
		}

		return obj;
	}
}

/*--------------------- Start VisiCart Ajax App */
var visicartObj = function()
{
	this.OnSuccess = function()
	{
		document.getElementById('visicart-div').innerHTML = this.GetResponseText();
	}

	this.GetData = function(url,data)
	{
		if (location.protocol == "https:")
		{
			url = url.replace(/^http:/, 'https:');
		}
		this.InitializeRequest('POST', url);
		this.Commit(data);
	}
}
visicartObj.prototype = new ajax();
var vcObj = new visicartObj();
/* End VisiCart Ajax App */

/*--------------------- Start Product Specification Ajax App */
var psOnSuccess = function()
{
	var text = this.GetResponseText().split('####');
	document.getElementById('prodspec-div'+text[0]).innerHTML = text[1];
}
var psGetData = function(url,data)
{
	if (location.protocol == "https:")
	{
		url = url.replace(/^http:/, 'https:');
	}
	this.InitializeRequest('POST', url);
	this.Commit(data);
}
var psObjList = new Array();
/* End Product Specification Ajax App */

/*--------------------- Start Add to Cart Ajax App */
var scOnSuccess = function()
{
	var text = this.GetResponseText().split('####');
	if (text[1] == 1)
	{
		document.getElementById(text[0]).innerHTML = "<span class=cartmessage>Item added to cart.</span>";
		reload_visicart();
	}
	else
	{
		document.getElementById(text[0]).innerHTML = "<span class=carterror>Error Occur when item added to cart.</span>";
	}
}
var scGetData = function(url,data)
{
	if (location.protocol == "https:")
	{
		url = url.replace(/^http:/, 'https:');
	}
	this.InitializeRequest('POST', url);
	this.Commit(data);
}
var scAddToCart = function(url,strfnbr,prrfnbr,suffix,attr,qty,search_id,clicked_product,wishlist)
{
	if (typeof(attr) == 'undefined') { attr = ''; }
	if (typeof(qty) == 'undefined') { qty = 1; }
	if (typeof(search_id) == 'undefined') { search_id = ''; }
	if (typeof(clicked_product) == 'undefined') { clicked_product = ''; }
	if (typeof(wishlist) == 'undefined') { wishlist = ''; }

	scObjList[suffix] = new ajax();
	scObjList[suffix].OnSuccess = scOnSuccess;
	scObjList[suffix].GetData = scGetData;
	scObjList[suffix].GetData(url, 'pgm=ajax&func=add_to_cart&log=2&strfnbr='+strfnbr+'&prrfnbr='+prrfnbr+'&attr='+attr+'&suffix='+suffix+'&qty='+qty+'&search_id='+search_id+'&clicked_product='+clicked_product+'&wl='+wishlist);
}
var scObjList = new Array();
/* End Add to Cart Ajax App */
