// $Id: units.js,v 1.1.1.1 2009/05/27 09:50:06 paul Exp $

var head = document.getElementsByTagName('head')[0];

// insert unit HTML into DOM
function loadUnit(id) {
  if (document.getElementById) {
    var e = document.getElementById('unit_'+id);
    e.innerHTML = eval(id);  // insert into DOM
  }
}

// ensure unit is fully loaded
function checkForUnit(id) {
  // IE returns 'object' not 'undefined' before variable is set
  if (typeof window[id] != 'undefined' && typeof window[id] != 'object') {
    loadUnit(id);
  } else {
    intTimer = setTimeout("checkForUnit('"+id+"')",500);
  }
}

/**
 * Returns a JavaScript variable containing HTML to be inserted into the DOM.
 *
 * @param unit a string e.g. /blogs/soccer/onecolumn.htm
 * @param id a string used indetify the unit
 */

function getUnit(unit,id) {
  // add script node to the document
  if (document.createElement) {
    scriptNode    = document.createElement('script');
    scriptNode.id = id;
    scriptNode.setAttribute('type','text/javascript');
    scriptNode.setAttribute('charset','utf-8');
    scriptNode.setAttribute('src','http://president.jp.reuters.com/unit.php?unit='+unit+'&id='+id);
    head.appendChild(scriptNode);
    checkForUnit(id);
    return;
  }
}

function getUnitPerl(unit,id,param) {
  // add script node to the document
  if (document.createElement) {
    scriptNode    = document.createElement('script');
    scriptNode.id = id;
    scriptNode.setAttribute('type','text/javascript');
    scriptNode.setAttribute('charset','utf-8');
    scriptNode.setAttribute('src','http://stg-widgets.reuters-sports.com/unit.ehtml?unit='+unit+'&id='+id+param);
    head.appendChild(scriptNode);
    checkForUnit(id);
    return;
  }
}

