//
// handling xmlhttp requests
//

// ---- test function -------------------------------------------------------
function ttt(url, param)
{
	alert (url);
	alert (param);
	return false;
	} // ttt

var DHTML = (document.getElementById || document.all || document.layers);
var xmlhttp;

// ---- the following for conditioanl compile for IE4.0 or later ------------
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
    try {
    xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
    } catch (e) {
  try {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    } catch (E) {
    xmlhttp=false
    }
  }
  @else
   xmlhttp=false
  @end @*/

// and this for standards browsers
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    try {
        xmlhttp = new XMLHttpRequest();
        }
    catch (e) {
        xmlhttp=false
        }
    }

// ---- handle the result ---------------------------------------------------
function HandleResult (str)
{
    if (str.match(/ADDED|DONE/)) {
        var x = new getObj('ItemAdded');
        x.style.visibility = 'visible';
	    if (str.match(/DONE/)) {
			document.getElementById('ItemAdded').firstChild.nodeValue = "Already in Cart";
			}
        }
    } // HandleResult
	
// ---- send off a request to the server ------------------------------------
function toserver(url, param)
{
    xmlhttp.open("POST", url, true);
	
    xmlhttp.setRequestHeader ("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
    xmlhttp.send (param);
	
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
	         ret = xmlhttp.responseText;
			 HandleResult (ret);
            }
        }
    // xmlhttp.send(null);
	return (0);
    } // toserver

// ---- get the object we are want to change --------------------------------
function getObj (name)
{
    if (document.getElementById) {
        this.obj = document.getElementById(name);
	    this.style = document.getElementById(name).style;
        }
    else if (document.all) {
        this.obj = document.all[name];
	    this.style = document.all[name].style;
	    }
    else if (document.layers) {
        this.obj = document.layers[name];
        this.style = document.layers[name];
        }
    } // getObj

// ---- that's it -----------------------------------------------------------

