var _ms_XMLHttpRequest_ActiveX = ""; // Holds type of ActiveX to instantiate
var _ajax;                           // Reference to a global XMLHTTPRequest object for some of the samples
var _logger = false;                  // write output to the Activity Log
var _status_area;                    // will point to the area to write status messages to

var BASE_URL = 'http://ml.chainofthoughts.com/cgi-bin/ajax.cgi?';
var pingAJAX;


//generic function to get refs for a number of different browsers...good stuff.
function getRef(id) {


	var isDOM = (document.getElementById ? true : false);
	var isIE4 = ((document.all && !isDOM) ? true : false);
	var isNS4 = (document.layers ? true : false)

	if (isDOM)
		return document.getElementById(id);

	if(isIE4)
		return document.all[id];

	if(isNS4)
		return document.layers[id];

}

//
function closeRow(ref) {
    var parRef = ref.parentNode;
   parRef.removeChild( ref );
}
function orderFirst(ref){

   var pclone = ref.cloneNode(true);
   //var mySnippet = ref.outerHTML;
   //alert( encode( mySnippet ) );
   //var myElement = document.createElement( encode( mySnippet ) );
   var parRef = ref.parentNode;
   closeRow(ref);
   var  f1 = parRef.firstChild;
   parRef.insertBefore( pclone, f1);

}

var glbID;
function decrementAndClose(aRef,lang,word,add) {
   //aRef = getRef(aRef);
   var l = encode( lang );
   var n = encode( word );
   var a = encode( add  );
   var requestString = 'ac=decr&n=' + n + '&a=' + a + '&l='+ l;

   //alert( aRef.id );
   glbID = aRef;
   //my_ajax( requestString, reportResponse );  
   my_ajax( requestString, doNothing );
   closeRow(aRef.parentNode);

  return true;
}

function incrementAndHighlight(aRef,lang,word,add) {
   //aRef = getRef(aRef);
   var l = encode( lang );
   var n = encode( word );
   var a = encode( add  );
   var requestString = 'ac=incr&n=' + n + '&a=' + a + '&l='+ l;

   //alert( aRef.id );
   //alert( "parent " + aRef.parentNode.id );
   glbID = aRef;
   //my_ajax( requestString, reportResponse );  
   my_ajax( requestString, doNothing );
   orderFirst(aRef.parentNode);
   return true;
}


function expandRow( aRef, lang, add) {
   //aRef = getRef(aRef);
   var l = encode( lang );
   //var n = encode( word );
   var a = encode( add  );
   var requestString = 'ac=expR&a=' + a + '&l='+ l;

   //alert( aRef.id );
   glbID = aRef;
   //my_ajax( requestString, reportResponse );  
   //my_ajax( requestString, doNothing );
   my_ajax( requestString, insertAfterID );   
}

function reportResponse() {
	if ( pingAJAX.readyState == 4 ) {
                alert( pingAJAX.responseText );
	}
}

function doNothing(){
   return true;
}

function insertAfterID(){
	if ( pingAJAX.readyState == 4 ) {
                //alert( pingAJAX.responseText );
   		var htmlText = pingAJAX.responseText;
                var myBox = document.createElement('div');
  		//var myClass = document.createAttribute('class');
		//myBox.setAttribute(myClass,'containerBox');
		myBox.innerHTML = htmlText;
                insertAfter(myBox, glbID);
 
	}
}

function insertAfter(newChild, refChild) { 
 refChild.parentNode.insertBefore(newChild,refChild.nextSibling); 
}


<!----------------------- AJAX dependencies ------------------------------->

// If you plan on doing anything outside of North America, then you'd better encode the things you pass back and forth
// the escape() method in Javascript is deprecated -- should use encodeURIComponent if available
function encode( uri ) {
    if (encodeURIComponent) {
        return encodeURIComponent(uri);
    }

    if (escape) {
        return escape(uri);
    }
}

function decode( uri ) {
    uri = uri.replace(/\+/g, ' ');

    if (decodeURIComponent) {
        return decodeURIComponent(uri);
    }

    if (unescape) {
        return unescape(uri);
    }

    return uri;
}

function my_ajax( text , cb) {
    r=text;
    //logger("PING: Initializing XMLHttpRequest");
    // Instantiate an object
    // Test to see if XMLHttpRequest is a defined object type for the user's browser
    // If not, assume we're running IE and attempty to instantiate the MS XMLHTtp object
    // Don't be confused by the ActiveXObject indicator. Use of this code will not trigger 
    // a security alert since the ActiveXObject is baked into IE and you aren't downloading it
    // into the IE runtime engine
    if ( window.XMLHttpRequest ) {
	   pingAJAX = new XMLHttpRequest();
    } else {
	   pingAJAX = new ActiveXObject("MSXML2.XMLHTTP");
    }
    //logger("PING: Setting Callback");
    // In Javascript, everything is an object. Functions are objects, everything inherits from Object
    // So assigning onreadystatechange to pingCallback means that you can call pingCallback by doing the following
    // pingAJAX.onreadystatechange( "blahblah")
    pingAJAX.onreadystatechange = cb;    
    //logger("PING: Opening POST Request (async)");
    // The open statement initializes the request. In this example, we'll just pass the value in the URL.
   var url=BASE_URL + r;
   //logger("URL: " + url);
    //alert( url );   
    pingAJAX.open( "GET", url, true ); //&value=" + encode(text)
    //logger("PING: Sending Request");
    // Send request to the server
    pingAJAX.send(null);

}

function pingCallback() {
	// Called from ping
	//logger("PING: pingCallback. readyState = " + pingAJAX.readyState /* + " | Status: " + pingAJAX.status */); a
	if ( pingAJAX.readyState == 4 ) {
		//alert("Response from server: " + pingAJAX.responseText );
		// find the ping_status DIV and replace its HTML
		document.getElementById("recently").innerHTML = pingAJAX.responseText;
		//alert ("Restarting: r="+r); 
		mystarttime();
		//alert ("Done restarting: r="+r); 
	}
}

