function SmartAjax() {    //------------- AJAX FUNCTIONS -----------------------
	// get XMLHttpRequest
	var smartWindowWidth;
	var smartWindowHeight;
	this.smartWindowWidth = 0;
	this.smartWindowHeight = 0;
	this.go = function(url) {		window.location = url	}
 	this.getWindowDimensions = function () { 		var body = document.body;
		if (typeof( body.scrollHeight ) == 'number') { 			tmpY = body.scrollHeight; 		} else {
			tmpY = 0; 		}
 		if (typeof( body.scrollWidth ) == 'number') {
 			tmpX = body.scrollWidth;
 		} else {
			tmpX = 0;
 		}
  		if( typeof( window.innerWidth ) == 'number' ) {
    		this.smartWindowWidth = Math.max(window.innerWidth, tmpX);
    		this.smartWindowHeight = Math.max(window.innerHeight, tmpY);
  		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    		//IE 6+ in 'standards compliant mode'
    		this.smartWindowWidth = Math.max(document.documentElement.clientWidth, tmpX);
    		this.smartWindowHeight = Math.max(document.documentElement.clientHeight,tmpY);
  		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    		//IE 4 compatible
    		this.smartWindowWidth = Math.max(document.body.clientWidth,tmpX);
    		this.smartWindowHeight = Math.max(document.body.clientHeight,tmpY);
  		}
	}
	this.getLeft = function(winWidth) {
		this.getWindowDimensions();
		return Math.round((this.smartWindowWidth - winWidth) / 2);
	}
	this.fadeOut = function (winwidth) {
		this.getWindowDimensions();
	 	var sh = this.$('fader');
		if (sh != null) {
			sh.style.width = this.smartWindowWidth+'px';
			sh.style.height = this.smartWindowHeight+'px';
			this.insertBefore("newwin","fader","div");
        	var nw = this.$('newwin');
			if (nw != null) {				nw.style.width = winwidth+'px';
				nw.style.left = this.getLeft(winwidth) + 'px';
				nw.style.top = '150px';
				/*nw.innerHTML = '<div class="tl">&nbsp;</div><div class="tr">&nbsp;</div><div class="c">test</div><!-- c --><div class="bl">&nbsp;</div><div class="br">&nbsp;</div>';*/
			}
			sh.onclick = function() { smartajax.fadeBack();};
		}
	}
	this.fadeBack = function() {		smartajax.remove('newwin');
 		var sh = this.$('fader');
		if (sh != null) {
			sh.style.width = '0px';
			sh.style.height = '0px';
		}
	}
	this.smartPopup = function(url,winwidth) {		this.fadeOut(winwidth);
		nw = this.$('newwin');
		if (nw != null) {   			this.getRequest(url,'newwin');		}	}
	this.smartPostPopup = function(formId,winwidth) {		this.fadeOut(winwidth);
		nw = this.$('newwin');
		if (nw != null) {
   			this.postRequest(formId,'newwin');
		}	}
	this.getAjax = function() {    	var ajaxObj = null;
		if (typeof(XMLHttpRequest) != "undefined")
			ajaxObj = new XMLHttpRequest();
		if (!ajaxObj && typeof(ActiveXObject) != "undefined") {			try { ajaxObj = new ActiveXObject("Msxml2.XMLHTTP"); }
			catch (err1) {				try { ajaxObj = new ActiveXObject("Microsoft.XMLHTTP"); }
				catch (err2) {					try { ajaxObj = new ActiveXObject("Msxml2.XMLHTTP.4.0"); }
					catch (err3) {						ajaxObj = null;					}				}			}		}
		if (!ajaxObj && window.createRequest)
			ajaxObj = window.createRequest();
		return ajaxObj;    }
	// Anti cache function
 	this.prepareURL = function(url) { 		if (url.indexOf('?') == -1) { 			url += '?smartajax_mode=Y&anticachetime='; 		} else { 			url += '&smartajax_mode=y&anticachetime='; 		}
		url += new Date().getTime();
		return url; 	}
	this.anticacheURL = function(url) { 		if (url.indexOf('?') == -1) {
 			url += '?anticachetime=';
 		} else {
 			url += '&anticachetime=';
 		}
		url += new Date().getTime();
		return url;
	}
	this.loadingMessage = function(id) {		if (this.$(id).innerHTML.search('Loading...') != -1) {			if (this.$(id).innerHTML.search('Loading.......................') != -1)
				this.$(id).innerHTML = 'Loading..';
			this.$(id).innerHTML += ".";			setTimeout("smartajax.loadingMessage('"+id+"');", 300);		}	}
	// perform GET request
    this.getRequest = function(ajxUrl,ajxObjid) {    	ajxUrl = this.prepareURL(ajxUrl);    	var xmlhttp = this.getAjax();
		obj = this.$(ajxObjid);
		if (!obj) return false;
        xmlhttp.open("GET",ajxUrl);
    	xmlhttp.onreadystatechange = function () {    		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {                obj.innerHTML = xmlhttp.responseText;
				if (typeof smartimagesalt == "function")
					smartimagesalt();    		}    	}
		xmlhttp.send(null);
		obj.innerHTML = '<div width="100%" align="center"><img src="/xcart_files/shoppingcart/img/plswait.gif" alt="Loading. Please wait." /></div>';
		//this.loadingMessage(ajxObjid);    }
	// perform GET request // sync
    this.getRequestAndReturn = function(ajxUrl) {
    	ajxUrl = this.prepareURL(ajxUrl);
    	var xmlhttp = this.getAjax();
        xmlhttp.open("GET",ajxUrl,false);
		xmlhttp.send(null);
    }
	// perform POST request
	this.postRequest = function(formId,ajxObjid) {		postVars = '';		ajxUrl = this.$(formId).getAttribute("action");
		for (i=0;i<this.$(formId).elements.length;i++) {			tmpobj = this.$(formId).elements[i];
   			if (typeof tmpobj.name == 'undefined') continue;
			if (typeof tmpobj.value != 'undefined') {    			tmpvalue = tmpobj.value;			} else {				tmpvalue = tmpobj.innerHTML;			}
			if (postVars.search('=') == -1) {				postVars += encodeURIComponent(tmpobj.name) + '=' + encodeURIComponent(tmpvalue);			} else {				postVars += '&' + encodeURIComponent(tmpobj.name) + '=' + encodeURIComponent(tmpvalue);			}		}
		ajxUrl = this.prepareURL(ajxUrl);
		var xmlhttp = this.getAjax();
		obj = this.$(ajxObjid);
		if (!obj) return false;
		xmlhttp.open("POST",ajxUrl);
		xmlhttp.setRequestHeader("Method", "POST " + ajxUrl + " HTTP/1.1");
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    	xmlhttp.onreadystatechange = function () {
    		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                obj.innerHTML = xmlhttp.responseText;
				if (typeof smartimagesalt == "function")
					smartimagesalt();
    		}
    	}
		xmlhttp.send(postVars);
		obj.innerHTML = 'Loading...';
		this.loadingMessage(ajxObjid);	}
    //-------------- DOM FUNCTIONS -----------------------
	// alias for document.getElementById
	this.$ = function(ajxObjid)	{
		if (!ajxObjid) { return null; }
		var res = document.getElementById(ajxObjid);
		if (!res && document.all) {
			res = document.all[ajxObjid];
		}
		return res;
	}
	// insert element before another
	this.insertBefore = function(ajxObjid,beforeId,theTag) {
		var objBefore = this.$(beforeId);
		obj = document.createElement(theTag);
		obj.setAttribute('id',ajxObjid);
		objBefore.parentNode.insertBefore(obj, objBefore);	}
	// create element in specified parent
	this.create = function(parentId, theTag, objId) {
		var objParent = this.$(parentId);
		obj = document.createElement(theTag);
		obj.setAttribute('id',objId);
		if (objParent)
			objParent.appendChild(obj);
	}
	// remove element by id
	this.remove = function(removeId) {		obj = this.$(removeId);
		if (obj && obj.parentNode && obj.parentNode.removeChild)
		{
			obj.parentNode.removeChild(obj);
		}	}
}
var smartajax = new SmartAjax();