
function retrieveActionAlerts()
{
    var   actionAlertsList;

    var   fetchFrame;

    actionAlertsList = document.getElementById('actionAlertsList');

    actionAlertsList.innerHTML = '<h3>Fetching action alerts...</h3>';

    document.domain = 'aclu-nj.org';
    window.gotAJAXData = updateActionAlerts;

    fetchFrame = document.getElementById('crossSubDomainFetcher');

    if ((fetchFrame == null) || (fetchFrame == undefined))
    {
        fetchFrame = document.createElement('iframe');
        fetchFrame.setAttribute('id','crossSubDomainFetcher');

        document.body.appendChild(fetchFrame);
        fetchFrame.style.display = 'none';
    };

    fetchFrame.src = 'http://action.aclu-nj.org/cross-subdomain-patch.html';
};

function updateActionAlerts(actionAlertData)
{
      var   actionAlertsList;

      var   xmlParser;

      var   actionAlertXML;
      var   issueNodes;

      var   i;

      var   currentIssue;
      var   actionAlerts;
      var   actionAlert;

      var   newLI;
      var   newAnchor;

      var   nameValue;
      var   urlValue;

      actionAlertsList = document.getElementById('actionAlertsList');

      xmlParser = new DOMImplementation();

      actionAlertXML = xmlParser.loadXML(actionAlertData).getDocumentElement();

      issueNodes = actionAlertXML.childNodes;
      for (i = 0; i < issueNodes.getLength(); i++)
      {
          currentIssue = issueNodes.item(i);

          if (currentIssue.childNodes.item(1).firstChild.nodeValue ==
              pageName)
          {
              break;
          };

          currentIssue = null;
      };

      if (currentIssue == null)
      {
          return;
      };

      document.getElementById('actionAlerts').style.display = 'block'

      actionAlerts = currentIssue.childNodes.item(2).childNodes;

      if (actionAlerts.getLength() == 0)
      {
          actionAlertsList.style.display = 'none';

          return;
      };

      actionAlertsList.innerHTML = '';

      for (i = 0; i < actionAlerts.getLength(); i++)
      {
          actionAlert = actionAlerts.item(i);

          newLI = document.createElement('li');
          actionAlertsList.appendChild(newLI);

          newAnchor = document.createElement('a');
          newLI.appendChild(newAnchor);


          nameValue =
            actionAlert.childNodes.item(0).childNodes.item(0).nodeValue;
          newAnchor.appendChild(document.createTextNode(nameValue));


          urlValue =
            actionAlert.childNodes.item(1).childNodes.item(0).nodeValue;
          newAnchor.setAttribute('href',urlValue);

      };
};

addEvent(window,'load',function () {retrieveActionAlerts()});

