/* $Id: xml_lib.js,v 1.5 2008/09/07 07:50:03 nuitari Exp $ */
/* $Source: /home/cvs/public/js/xml_lib.js,v $ */

/******************************************************************************
**  Programmer: Stephane Bakhos
**  Date of last revision: $Date: 2008/09/07 07:50:03 $
**  File name: xml_lib.js
**  Package: main / public
**
**  Changelog:
**    $Log: xml_lib.js,v $
**    Revision 1.5  2008/09/07 07:50:03  nuitari
**    Added in array to array objects
**
**    Revision 1.4  2008/05/27 08:13:04  nuitari
**    missing ;
**
**    Revision 1.3  2007/12/11 04:57:40  nuitari
**    Rich text editor update
**
**    Revision 1.2  2006/08/26 06:54:27  nuitari
**    Moved the trim prototype to the more accessible xml_lib.js
**
**    Revision 1.1  2006/05/21 10:06:36  nuitari
**    Split signup.js with xml_lib.js
**    Added variables to set a default value for select fields once they are loaded
**
**
**  Copyright 2002-2006 Stephane Bakhos and Influence Marketing LLC,
**                      all rights reserved.
**
**  Library to contain various XML related functions
**
******************************************************************************/

String.prototype.trim = trimString;

function trimString (str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}


Array.prototype.inArray = function (value) {
  var i;
  for (i=0; i < this.length; i++) {
    if (this[i] == value) {
      return true;
    }
  }
  return false;
};

var isIE = false;

function CreateXMLRequest() {
  var xmldoc;

  try {
    xmldoc = new XMLHttpRequest();
  } catch (e) {
    try {
      xmldoc  = new ActiveXObject("Msxml2.XMLHTTP");
      isIE = true;
    } catch (e) {
      try {
        xmldoc  = new ActiveXObject("Microsoft.XMLHTTP");
        isIE = true;
      } catch (e) {
        try {
          xmldoc  = window.createRequest();
        } catch (e) {
          xmldoc  = false;
        }
      }
    }
  }
  return xmldoc;
}

function Generic_GetFromServer(querystring, callback) {


  var xmlhttp = CreateXMLRequest();

  xmlhttp.open("GET", "/admin/library/generic_get_data.php?"+querystring,true);

  xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState == 4) { // FIXME ERROR HANDLING!!
      if (xmlhttp.responseText.length > 0) {
        received_xml = xmlhttp.responseText;
/*        alert(xmlhttp.responseText);*/
      }
      eval(callback);
    }
  }

  xmlhttp.setRequestHeader("Content-Type", "text/xml");
  xmlhttp.send(null);
}

/*
    var Elem = xmldoc.responseXML.getElementsByTagName(tag);
    var numElem = Elem.length;
*/