/* 
 * Tivid Javascript Libraries
 * All rights reserved, Copyright 2008 Tivid Inc.
 */

/*****************************************************************************
 * SECTION 1: All Pages: tivid popups                                        *
 *****************************************************************************/
var nwin = null;

function show_newwindow(wname) {
  var wwid = 640;
  var whei = 480;

  if (nwin == null || nwin.closed) {
    nwin = window.open(wname,"TIVID_NEWWINDOW","menubar=yes,location=yes,scrollbars=yes,resizable=yes,width="+wwid+",height="+whei);
  }
  else {
    window.nwin.location=wname;
  }

  nwin.focus();
  return nwin;
}

function show_tivid_popup( PopWidth, tOffset, PopData ) {
  var mycurtain = document.getElementById( "bodycurtain" );
  var mybox = document.getElementById( "tividdialog" );
  var bheada = document.getElementById( "tividdialogheadera" );
  var bheadb = document.getElementById( "tividdialogheaderb" );
  var popupObj  = document.getElementById("tividdialogcontent");

  // Scroll to the top of the page
  window.scrollTo(0,0)

  //mycurtain.style.height = document.documentElement.clientHeight  + "px";
  mycurtain.style.height = document.documentElement.scrollHeight  + "px";
  mybox.style.width  = PopWidth  + "px";
  mybox.style.left = ((document.body.clientWidth - PopWidth) / 2) + "px";
  myscrolltop = (self.pageYOffset) ? self.pageYOffset : 
		(document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop :
		document.body.scrollTop;
  mybox.style.top = (tOffset ? tOffset : 200) + myscrolltop + "px";
  popupObj.innerHTML = PopData;

  document.body.scroll = "no";
  mycurtain.style.display = "block";
  mybox.style.display = "block";
}

function hide_tivid_popup( ) {
  var mycurtain = document.getElementById( "bodycurtain" );
  var mybox = document.getElementById( "tividdialog" );

  mycurtain.style.display = "none";
  mybox.style.display = "none";
  document.body.scroll = "yes";

  /* If there is a follow up function, execute it */
  if ( TividFollowPopup ) { eval( TividFollowPopup ); }
}

/*****************************************************************************
 * SECTION 2: Tivid top navigation bar                                       *
 *****************************************************************************/
function showTividTopNav( tNavSelected, tNavClass ) {
  var tSubNav = document.getElementById( "tivid_subnav" );

  if ( tNavSelected && TividTopNavArray[tNavSelected] ) {
    tSubNav.innerHTML = TividTopNavArray[tNavSelected];
    tSubNav.className = tNavClass;
    TividTopNavTimer = 200;
  }
}

function showTividTopNavDefault() {
  var tSubNav = document.getElementById( "tivid_subnav" );

  if ( TividTopNavBlock ) {
    setTimeout("showTividTopNavDefault();", 200);
  }
  else if ( TividTopNavTimer ) {
    var exTividTopNavTimer = TividTopNavTimer;
    TividTopNavTimer = 0;
    setTimeout("showTividTopNavDefault();", exTividTopNavTimer);
  }
  else
  if ( TividTopNavDefault && TividTopNavArray[TividTopNavDefault] ) {
    tSubNav.innerHTML = TividTopNavArray[TividTopNavDefault];
    tSubNav.className = TividTopNavDefaultClass;
    TividTopNavTimer = 200;
  }
}

function showTividSubNavFull() {
  var tSubNav = document.getElementById( "tivid_subnav" );

  TividTopNavArray["mytivid"] = TividTopNavArray["mytivid_full"];
  tSubNav.innerHTML = TividTopNavArray["mytivid"];
}

/*****************************************************************************
 * SECTION 3: All Pages: tivid autocomplete                                  *
 *****************************************************************************/
var ClearDivList = new Array();

function tividClearAutoComplete( sDivName ) {
  if ( sDivName ) { ClearDivList.unshift( sDivName ); }
}

function tividUpdateClearACList( sDivName ) {
  var sDiv;

  for( i=0; i < ClearDivList.length; i++ ) {
    if ( ClearDivList[i] != sDivName ) { 
      sDiv = document.getElementById( ClearDivList[i] );
      sDiv.innerHTML = "";
    } 
  } 
}

function tividAutoCompleteFormElements( sFormID ) {
  var sForm = document.getElementById( sFormID );

  for(i=0; i< sForm.elements.length; i++) {
    sForm.elements[i].onfocus = function() { tividUpdateClearACList("tac_" + this.name); }
  }
}

function getCursorPosition( iField ) {
  var r;

  if ( iField.createTextRange ) {
     r = document.selection.createRange().duplicate();
     r.moveEnd('character', iField.value.length);
     if (r.text == '') { return iField.value.length; }
     else { return iField.value.lastIndexOf(r.text); }
  }
  else { return iField.selectionStart; }
}

function getStringArrayPosition( iStr, mStart ) {
  var c = 0;
  for( i=mStart; i > 0; i-- ) {
    if ( iStr.charAt(i) == "," || iStr.charAt(i) == ";" ) { c++; }
    
  }

  return c;
}

function tividAutoCompleteSelect( iFname, lIndex, iValue, sDivName, multiEntry ) {
  var iFel = document.getElementById( iFname );
  var sDiv = document.getElementById( sDivName );

  // No empty values
  if ( ! iValue ) return;

  if ( multiEntry ) {
    mField = iFel.value.split(/[ \t]*[,;][ \t]*/);
    mField[lIndex] = iValue;
    iFel.value = mField.join(", ", mField) + ", ";
    iFel.focus();
  }
  else { iFel.value = iValue; }

  sDiv.innerHTML = "";
}

function tividAutoCompleteLocal(iField, sArray, sDivName, pKey, tabCheck, multiEntry) {
  var fMatch = 0;
  var tabKeys ="9;";
  var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";
  var i, j, j_next, mField, lField;
  var sDiv = document.getElementById( sDivName );

  // Tabcheck and no Tab pressed: do not proceed
  if ( tabCheck && tabKeys.indexOf(pKey+";") == -1 ) { return false; }

  // Multi-entry
  lIndex = 0;
  if ( multiEntry ) { 
    mField = iField.value.split(/[ \t]*[,;][ \t]*/);
    mStart = getCursorPosition(iField);
    lIndex = getStringArrayPosition(iField.value, mStart);
    lField = mField[lIndex];
  }
  else { lField = iField.value; }

  // Now search the array
  fList = "";
  lElement = "";
  for (i in sArray) {
    if ( ! sArray[i][0] ) { continue; }

    if (sArray[i][0].toUpperCase().indexOf(lField.toUpperCase()) == 0) {
      nLoc = lField.length;
      fList += "<DIV onClick='tividAutoCompleteSelect(\"" + iField.name + "\"," + lIndex + ",\"" + sArray[i][0] + "\",\""
		+ sDivName + "\"," + multiEntry + ")'>" + "<B>" + sArray[i][0].substr(0,nLoc) + "</B>" + sArray[i][0].substr(nLoc);
      if ( sArray[i][1] ) { fList += ": " + sArray[i][1]; }
      fList += "</DIV>\n";

      fMatch += 1;
      lElement = sArray[i][0];
    }
    else if (sArray[i][1].toUpperCase().indexOf(lField.toUpperCase()) == 0) {
      nLoc = lField.length;
      fList += "<DIV onClick='tividAutoCompleteSelect(\"" + iField.name + "\"," + lIndex + ",\"" + sArray[i][0] + "\",\""
		+ sDivName + "\"," + multiEntry + ")'>" + sArray[i][0];
      if ( sArray[i][1] ) { fList += ": " + "<B>" + sArray[i][1].substr(0,nLoc) + "</B>" + sArray[i][1].substr(nLoc); }
      fList += "</DIV>\n";

      fMatch += 1;
      lElement = sArray[i][0];
    }
  }

  //  If found then let us show
  if ( fMatch ) {
    if ( fMatch > 2 ) { height = " STYLE='height: 64px;'"; } else { height = ""; }
    sDiv.innerHTML = "<DIV CLASS=tividautocomplete" + height + ">" + fList + "</DIV>";
  }
  else { sDiv.innerHTML = ""; }

  //  If tab pressed make sure the single entry is auto selected
  if (tabKeys.indexOf(pKey+";") != -1) {
    if ( fMatch == 1 ) {
      tividAutoCompleteSelect( iField.name, lIndex, lElement, sDivName, multiEntry);
    }
    else { sDiv.innerHTML = ""; }
  }
}

function tividAutoCompleteAjax(iField, sURL, sDivName, pKey, tabCheck, multiEntry) {
  var ajaxObj = new sack();

  // Multi-entry
  lIndex = 0;
  if ( multiEntry ) { 
    mField = iField.value.split(/[ \t]*[,;][ \t]*/);
    mStart = getCursorPosition(iField);
    lIndex = getStringArrayPosition(iField.value, mStart);
    lField = mField[lIndex];
  }
  else { lField = iField.value; }

  ajaxObj.URLString = "first_visit=no";
  ajaxObj.requestFile = sURL + "/" + encodeURI(lField);

  ajaxObj.onCompletion = function(){
    var sArray = new Array();
    var tArray = ajaxObj.response.split(";##;");
    for( i=0; i < tArray.length; i++ ) {
      sArray[i] = tArray[i].split(";#;");
    }
    tividAutoCompleteLocal(iField, sArray, sDivName, pKey, tabCheck, multiEntry);
  };

  ajaxObj.runAJAX();
}

/*****************************************************************************
 * SECTION 4: Competition page javascript                                    *
 *****************************************************************************/

var colorSelected;
var colorHighlight;
var colorAlternateLight;
var colorAlternateDark;

var currDIVid;
var currTRid;
var defaultRows = new Array();
var selectedRows = new Array();

function tividChangeColor(TRname, highLight)
{
   var tableRow = document.getElementById(TRname);

   tableRow.style.cursor = "hand";
   if (highLight)
   {
      selectedRows[TRname] = tableRow.style.backgroundColor;
      tableRow.style.backgroundColor = colorHighlight;
   }
   else
   {
       tableRow.style.backgroundColor = selectedRows[TRname];
   }
}

function DoNav(theUrl)
{
   document.location.href = theUrl;
}

//-----------------------------------------------------------------------------
// sortTable(id, col, rev)
//
//  id  - ID of the TABLE, TBODY, THEAD or TFOOT element to be sorted.
//  col - Index of the column to sort, 0 = first column, 1 = second column,
//        etc.
//  rev - If true, the column is sorted in reverse (descending) order
//        initially.
//
// Note: the team name column (index 1) is used as a secondary sort column and
// always sorted in ascending order.
//-----------------------------------------------------------------------------

function sortTable(id, col, rev)
{
  // Get the table or table section to sort.
  var tblEl = document.getElementById(id);

  // The first time this function is called for a given table, set up an
  // array of reverse sort flags.
  if (tblEl.reverseSort == null)
  {
     tblEl.reverseSort = new Array();

     // Also, assume the team name column is initially sorted.
     tblEl.lastColumn = 1;
  }

  // If this column has not been sorted before, set the initial sort direction.
  if (tblEl.reverseSort[col] == null)
     tblEl.reverseSort[col] = rev;

  // If this column was the last one sorted, reverse its sort direction.
  if (col == tblEl.lastColumn)
     tblEl.reverseSort[col] = !tblEl.reverseSort[col];

  // Remember this column as the last one sorted.
  tblEl.lastColumn = col;

  // Set the table display style to "none" - necessary for Netscape 6
  // browsers.
  var oldDsply = tblEl.style.display;
  tblEl.style.display = "none";

  // Sort the rows based on the content of the specified column using a
  // selection sort.

  var tmpEl;
  var i, j;
  var minVal, minIdx;
  var testVal;
  var cmp;

  for (i = 0; i < tblEl.rows.length - 1; i++)
  {
     // Assume the current row has the minimum value.
     minIdx = i;
     minVal = getTextValue(tblEl.rows[i].cells[col]);

     // Search the rows that follow the current one for a smaller value.
     for (j = i + 1; j < tblEl.rows.length; j++)
     {
        testVal = getTextValue(tblEl.rows[j].cells[col]);
        cmp = compareValues(minVal, testVal);

        // Negate the comparison result if the reverse sort flag is set.
        if (tblEl.reverseSort[col])
           cmp = -cmp;

        // Sort by the second column (team name) if those values are equal.
        if (cmp == 0 && col != 1)
           cmp = compareValues(getTextValue(tblEl.rows[minIdx].cells[1]),
                               getTextValue(tblEl.rows[j].cells[1]));
        // If this row has a smaller value than the current minimum, remember its
        // position and update the current minimum value.
        if (cmp > 0)
        {
           minIdx = j;
           minVal = testVal;
        }
     }

     // By now, we have the row with the smallest value. Remove it from the
     // table and insert it before the current row.
     if (minIdx > i)
     {
        tmpEl = tblEl.removeChild(tblEl.rows[minIdx]);
        tblEl.insertBefore(tmpEl, tblEl.rows[i]);
     }
  }

  // Make it look pretty.
  //makePretty(tblEl, col);

  // Set team rankings.
  setRanks(id, col, rev);

  // Restore the table's display style.
  tblEl.style.display = oldDsply;

  return false;
}

//-----------------------------------------------------------------------------
// Functions to get and compare values during a sort.
//-----------------------------------------------------------------------------

// This code is necessary for browsers that don't reflect the DOM constants
// (like IE).
if (document.ELEMENT_NODE == null)
{
   document.ELEMENT_NODE = 1;
   document.TEXT_NODE = 3;
}

function getTextValue(el)
{
   var i;
   var s;

   // Find and concatenate the values of all text nodes contained within the
   // element.
   s = "";
   for (i = 0; i < el.childNodes.length; i++)
     if (el.childNodes[i].nodeType == document.TEXT_NODE)
        s += el.childNodes[i].nodeValue;
     else if (el.childNodes[i].nodeType == document.ELEMENT_NODE &&
              el.childNodes[i].tagName == "BR")
             s += " ";
          else
            // Use recursion to get text within sub-elements.
            s += getTextValue(el.childNodes[i]);

   return normalizeString(s);
}

function isNumeric(x)
{
   // I usually use the this function like this: if (isNumeric(myVar)) { }
   // regular expression that validates a value is numeric
   var RegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)|(^-?\d{1,3}(\,(\d){3})*(\.\d\d)$)/;

   //var RegExp = /^(-)?(\d*)((\,?)(\d*))*(\.?)(\d*)$/;

   // Note: this WILL allow a number that ends in a decimal: -452.
   // compare the argument to the RegEx
   // the 'match' function returns 0 if the value didn't match

   var result = x.match(RegExp);
   return result;
}

function compareValues(v1, v2)
{
   var f1, f2;

   // If the values are numeric, convert them to floats.
   if (isNumeric(v1) && isNumeric(v2))
   {
      v1 = v1 + 0;
      v2 = v2 + 0;

      /* Remove commas so that parseFloat can parse the number */
      f1 = parseFloat(v1.replace(/,/g,""));
      f2 = parseFloat(v2.replace(/,/g,""));
      if (!isNaN(f1) && !isNaN(f2))
      {
         v1 = f1;
         v2 = f2;
      }

      // Compare the two values.
      if (v1 == v2)
         return 0;
      else if (v1 < v2)
         return -1;
      else return 1;
   }
   else
   {
      // Compare the two values.
      if (v1 == v2)
         return 0;
      else if (v1.toString().toUpperCase() > v2.toString().toUpperCase())
         return 1;
      else return -1;
   }
}

// Regular expressions for normalizing white space.
var whtSpEnds = new RegExp("^\\s*|\\s*$", "g");
var whtSpMult = new RegExp("\\s\\s+", "g");

function normalizeString(s)
{
   s = s.replace(whtSpMult, " ");  // Collapse any multiple whites space.
   s = s.replace(whtSpEnds, "");   // Remove leading or trailing white space.

   return s;
}

//-----------------------------------------------------------------------------
// Functions to update the table appearance after a sort.
//-----------------------------------------------------------------------------

// Style class names.
var rowClsNm = "alternateRow";
var colClsNm = "sortedColumn";

// Regular expressions for setting class names.
var rowTest = new RegExp(rowClsNm, "gi");
var colTest = new RegExp(colClsNm, "gi");

function makePretty(tblEl, col)
{
   var i, j;
   var rowEl, cellEl;

    // Set style classes on each row to alternate their appearance.
   for (i = 0; i < tblEl.rows.length; i++)
   {
      rowEl = tblEl.rows[i];
      rowEl.className = rowEl.className.replace(rowTest, "");
      if (i % 2 != 0)
         rowEl.className += " " + rowClsNm;

      rowEl.className = normalizeString(rowEl.className);
      // Set style classes on each column (other than the name column) to
      // highlight the one that was sorted.

      for (j = 2; j < tblEl.rows[i].cells.length; j++)
      {
         cellEl = rowEl.cells[j];
         cellEl.className = cellEl.className.replace(colTest, "");
         if (j == col)
           cellEl.className += " " + colClsNm;
         cellEl.className = normalizeString(cellEl.className);
      }
   }

   // Find the table header and highlight the column that was sorted.
   var el = tblEl.parentNode.tHead;
   rowEl = el.rows[el.rows.length - 1];

   // Set style classes for each column as above.
   for (i = 2; i < rowEl.cells.length; i++)
   {
      cellEl = rowEl.cells[i];
      cellEl.className = cellEl.className.replace(colTest, "");

      // Highlight the header of the sorted column.
      if (i == col)
        cellEl.className += " " + colClsNm;
      cellEl.className = normalizeString(cellEl.className);
   }
}

function setRanks(tbName, col, rev)
{
   var tblEl = document.getElementById(tbName);

   // Determine whether to start at the top row of the table and go down or
   // at the bottom row and work up. This is based on the current sort
   // direction of the column and its reversed flag.
   for (i = 0; i < tblEl.rows.length; i++)
   {
      defaultRows[tblEl.rows[i].id] = (i % 2 == 0) ? colorAlternateDark : colorAlternateLight;
      if (tblEl.rows[i].id != currTRid) {
         tblEl.rows[i].style.backgroundColor = defaultRows[tblEl.rows[i].id];
      }
      else {
        tblEl.rows[i].style.backgroundColor = colorSelected;
      }
   }
}

/*****************************************************************************
 * SECTION 5: More competition page javascript                               *
 *****************************************************************************/

function setDisplay(id,value)
{
   var elm = document.getElementById(id);
   if (elm)
   {
      elm.style.display = value;
      return 1;
   }
   else
   {
      return 0;
   }
}

function togLayer(TRname, id)
{
   var tempColor;
   var tableRow = document.getElementById(TRname);

   if (currTRid)
   {
     ntableRow = document.getElementById(currTRid);
     ntableRow.style.backgroundColor = defaultRows[currTRid];
     selectedRows[currTRid] = defaultRows[currTRid];
   }

   if (TRname)
   {
     tableRow.style.backgroundColor = colorSelected;
     selectedRows[TRname] = colorSelected;
   }
   currTRid = TRname;


   if (currDIVid)
   {
     setDisplay(currDIVid, "none");
   }

   if (id)
   {
     setDisplay(id, "block");
   }

   currDIVid = id;
}

function graphEnableDisable(elm, value)
{
   var elm2 = document.getElementById(elm);
   if (elm2)
     elm2.style.display=value;
}

function navbarEnableDisable(elm, value)
{
   var elmTD = document.getElementById("td_" + elm);
   if (elmTD) {
     if ( value == 0 ) { elmTD.style.background="#F3F3F3"; elmTD.style.borderBottom="1px solid #959595"; }
     else { elmTD.style.background="#FFF"; elmTD.style.borderBottom="none"; }
   }
}


function showGraph(id, vp_short_name)
{
   graphEnableDisable('portfolio_chart'+vp_short_name, "none");
   navbarEnableDisable('portfolio_chart', 0);
   graphEnableDisable('sector_chart'+vp_short_name, "none");
   navbarEnableDisable('sector_chart', 0);
   graphEnableDisable('industry_chart'+vp_short_name, "none");
   navbarEnableDisable('industry_chart', 0);
   graphEnableDisable('value_chart'+vp_short_name, "none");
   navbarEnableDisable('value_chart', 0);
   graphEnableDisable('ranking_chart'+vp_short_name, "none");
   navbarEnableDisable('ranking_chart', 0);
   graphEnableDisable(id+vp_short_name, "block");
   navbarEnableDisable(id, 1);

}

/*****************************************************************************
 * SECTION 6: MIT Licensed Small Ajax Library --- START                      *
 *****************************************************************************
 * Simple AJAX Code-Kit (SACK) v1.6.1                                        *
 * ©2005 Gregory Wild-Smith                                                  *
 * www.twilightuniverse.com                                                  *
 * Software licenced under MIT license                                       *
 *****************************************************************************/

function sack(file) {
	this.xmlhttp = null;

	this.resetData = function() {
		this.method = "POST";
  		this.queryStringSeparator = "?";
		this.argumentSeparator = "&";
		this.URLString = "";
		this.encodeURIString = true;
  		this.execute = false;
  		this.element = null;
		this.elementObj = null;
		this.requestFile = file;
		this.vars = new Object();
		this.responseStatus = new Array(2);
  	};

	this.resetFunctions = function() {
  		this.onLoading = function() { };
  		this.onLoaded = function() { };
  		this.onInteractive = function() { };
  		this.onCompletion = function() { };
  		this.onError = function() { };
		this.onFail = function() { };
	};

	this.reset = function() {
		this.resetFunctions();
		this.resetData();
	};

	this.createAJAX = function() {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				this.xmlhttp = null;
			}
		}

		if (! this.xmlhttp) {
			if (typeof XMLHttpRequest != "undefined") {
				this.xmlhttp = new XMLHttpRequest();
			} else {
				this.failed = true;
			}
		}
	};

	this.setVar = function(name, value){
		this.vars[name] = Array(value, false);
	};

	this.encVar = function(name, value, returnvars) {
		if (true == returnvars) {
			return Array(encodeURIComponent(name), encodeURIComponent(value));
		} else {
			this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
		}
	}

	this.processURLString = function(string, encode) {
		encoded = encodeURIComponent(this.argumentSeparator);
		regexp = new RegExp(this.argumentSeparator + "|" + encoded);
		varArray = string.split(regexp);
		for (i = 0; i < varArray.length; i++){
			urlVars = varArray[i].split("=");
			if (true == encode){
				this.encVar(urlVars[0], urlVars[1]);
			} else {
				this.setVar(urlVars[0], urlVars[1]);
			}
		}
	}

	this.createURLString = function(urlstring) {
		if (this.encodeURIString && this.URLString.length) {
			this.processURLString(this.URLString, true);
		}

		if (urlstring) {
			if (this.URLString.length) {
				this.URLString += this.argumentSeparator + urlstring;
			} else {
				this.URLString = urlstring;
			}
		}

		// prevents caching of URLString
		this.setVar("rndval", new Date().getTime());

		urlstringtemp = new Array();
		for (key in this.vars) {
			if (false == this.vars[key][1] && true == this.encodeURIString) {
				encoded = this.encVar(key, this.vars[key][0], true);
				delete this.vars[key];
				this.vars[encoded[0]] = Array(encoded[1], true);
				key = encoded[0];
			}

			urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
		}
		if (urlstring){
			this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
		} else {
			this.URLString += urlstringtemp.join(this.argumentSeparator);
		}
	}

	this.runResponse = function() {
		eval(this.response);
	}

	this.runAJAX = function(urlstring) {
		if (this.failed) {
			this.onFail();
		} else {
			this.createURLString(urlstring);
			if (this.element) {
				this.elementObj = document.getElementById(this.element);
			}
			if (this.xmlhttp) {
				var self = this;
				if (this.method == "GET") {
					totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
					this.xmlhttp.open(this.method, totalurlstring, true);
				} else {
					this.xmlhttp.open(this.method, this.requestFile, true);
					try {
						this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
					} catch (e) { }
				}

				this.xmlhttp.onreadystatechange = function() {
					switch (self.xmlhttp.readyState) {
						case 1:
							self.onLoading();
							break;
						case 2:
							self.onLoaded();
							break;
						case 3:
							self.onInteractive();
							break;
						case 4:
							self.response = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.responseStatus[0] = self.xmlhttp.status;
							self.responseStatus[1] = self.xmlhttp.statusText;

							if (self.execute) {
								self.runResponse();
							}

							if (self.elementObj) {
								elemNodeName = self.elementObj.nodeName;
								elemNodeName.toLowerCase();
								if (elemNodeName == "input"
								|| elemNodeName == "select"
								|| elemNodeName == "option"
								|| elemNodeName == "textarea") {
									self.elementObj.value = self.response;
								} else {
									self.elementObj.innerHTML = self.response;
								}
							}
							if (self.responseStatus[0] == "200") {
								self.onCompletion();
							} else {
								self.onError();
							}

							self.URLString = "";
							break;
					}
				};

				this.xmlhttp.send(this.URLString);
			}
		}
	};

	this.reset();
	this.createAJAX();
}

/*****************************************************************************
 * MIT Licensed Small Ajax Library --- END                                   *
/*****************************************************************************/

