function createObject()
{
  var ajaxReq = null;
  try
  { 
    ajaxReq = new XMLHttpRequest();
  } catch(e) {ajaxReq = null;}
  if (!ajaxReq)
  {
    try
    {
      ajaxReq = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e) {ajaxReq = null;}
  }
  if (!ajaxReq)
  {
    try
    { 
      ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch(e) {ajaxReq = null;}
  }
  return ajaxReq;
}

var ajax = {request: createObject()};

function preparePostQuery(data)
{
  var query = [];
  
  for (var key in data)
  {
    try
    {
      if (data[key] === undefined || data[key] === null)
        continue;
      query.push(encodeURIComponent(key) + '=' + encodeURIComponent(data[key]));
    } catch (e) {}
  }
  return query.join('&');
}
   
function doShowParsed()
{
  if (ajax['request'].readyState != 4)
    return;
  try
  {
    var text = ajax['request'].responseText;
    var res = text.substring(0, 1);
    text = text.substring(1);
    document.getElementById('parsed_text').innerHTML = text;
  }
  catch (e) {}
}

function showParse(objid)
{
  if (objid == null)
    return;
  var objtext = document.getElementById(objid);
  if (objtext == null)
    return;
  var txt;
  try
  {
    txt = objtext.value;
  } catch(e) {return; }
  ajax['request'].open('POST', 'ajaxparse.php');
  ajax['request'].onreadystatechange = doShowParsed;
  ajax['request'].setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  ajax['request'].setRequestHeader("X-Requested-With", "XMLHttpRequest");
  var data = {'p_text': txt};
  ajax['request'].send(preparePostQuery(data));
}

function doShowWTVGames()
{
  if (ajax['request'].readyState != 4)
    return;
  try
  {
    wtv_obj = document.getElementById('wtv_games');
    if (wtv_obj == null)
      return;
    var text = ajax['request'].responseText;
    var res = text.substring(0, 1);
    text = text.substring(1);
    if (res == 1)
    {
      wtv_obj.innerHTML = text;
      wtv_obj.style.display = "block";
    }
  }
  catch (e) {}
}

function showWTVGames()
{
  ajax['request'].open('GET', 'wtvparse.php');
  ajax['request'].onreadystatechange = doShowWTVGames;
  ajax['request'].setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  ajax['request'].setRequestHeader("X-Requested-With", "XMLHttpRequest");
  ajax['request'].send();
}

