// Public methods.
function text2html( text )
{
  if (text != null)
  {
    var html = text.replace( /&/g,"&amp;");
    html = html.replace( /"/g,"&quot;");
    html = html.replace( /</g,"&lt;");
    html = html.replace( /\n/g,"<br>");
    html = html.replace( /\+/g,"&nbsp;");
    //alert(html);
    return html;
  }
  else
  {
    return "";
  }
}

function textAreaFormat(text)
{
   var res = text.replace( /\n/g, "<br/>");
   return res;
}

function debug(msg)
{
	//alert(msg);
}

function getparamfrom(str, name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( str );
  if( results == null )
    return "";
  else
    return results[1];
}

function getparam( name )
{
  return getparamfrom(window.location.href, name);
}


Http = function(cbSuccess, cbFailure)
{
  this._ajax = null;
  if (!(this._cbSuccess = cbSuccess))
  {
//    alert("Http initialization error. Success callback must be defined.");
  }
  this._cbFailure = cbFailure;

  if (window.XMLHttpRequest) { // Mozilla and Safari.
    this._ajax = new XMLHttpRequest();
//    if (this._ajax.overrideMimeType)
  //    this._ajax.overrideMimeType('text/xml');
  } else 
      if (window.ActiveXObject) { // IE.
        try {
          this._ajax=new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
              this._ajax = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
//                alert("Error. Cannot create Http object.");
            }
          }
      } else {
//          alert("Error. Unsupported browser.");
      }
};

Http.prototype.load = function(url)
{
//  alert('load: ' + url);
  this._url = url;
  if (this._ajax) {
    var instance = this;
    this._ajax.onreadystatechange = function() { instance._processState(); };
    this._ajax.open('GET', this._url, true);
    this._ajax.setRequestHeader("If-Modified-Since", new Date(0));
    this._ajax.send(null);
//    alert('send OK');
  }
};

Http.prototype.post = function(url, params)
{
//  alert('load: ' + url);
  this._url = url;
  this._params = params;
  if (this._ajax) {
    var instance = this;
    this._ajax.onreadystatechange = function() { instance._processState(); };

    this._ajax.open('POST', this._url, true);
	this._ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	this._ajax.setRequestHeader("Content-length", this._params.length);
	this._ajax.setRequestHeader("Connection", "close");
	this._ajax.send(this._params);
//    alert('send OK');
  }
};

// Private methods.

Http.prototype._processState = function()
{
//  if ((this._ajax.readyState != 4) || (this._ajax.status != 200))
//  alert('_processState' + this._ajax.readyState + ', ' + this._ajax.status + ', ' + this._ajax.statusText + ', ' + this._ajax.responseText);
  if (this._ajax.readyState == 4) // Request of file completed.
    if (this._ajax.status == 200) // Request was successful.
      this._cbSuccess(this._ajax.responseText);
    else
      if (this._cbFailure)
        this._cbFailure(this._ajax.status + ' : ' + this._ajax.statusText + ' : ' + this._ajax.responseText);
};

function showElement(id, shown)
{
//    alert('showElement(' + id + ', ' + shown + ')');
    document.getElementById( id ).style.display = ((shown) ? "block" : "none");
}

function setElementText(id, value)
{
    document.getElementById( id ).innerHTML=value;
}

function getElementText(id)
{
//    alert('getElementText');
    return document.getElementById( id ).innerHTML;
}

function EvalSound(soundobj) 
{
	try //doesn't work on Mozilla
	{
    var thissound= eval("document."+soundobj);
    thissound.Play();
    }
    catch (err)
    {
    }
}
  
function EvalSoundMsg() 
{
//    EvalSound('soundmsg');
}

