function popupWindow(url, name, width, height) {
  newWin = window.open(url, name,"location=no,directories=no,menubar=no,statusbar=no,toolbar=no,scrollbars=no,height=" +height+ ",width=" +width+ ",resizable=no");
  newWin.resizeTo(width,height);
  newWin.focus();
  return false;
}

function doBigImage(file, title, width, height) {
  return popupWindow('display.cgi?title='+title+'&file='+file, 'bigImage', width+80, height+120);
}

function changeClass(elemName, newClass) {
  var elem = document.getElementById(elemName);
  elem.className = newClass;
  return false;
}

function showCalendarEntry(id) {
  width = 370;
  height = 300;
  newWin = window.open('calendar_entry.cgi?aid='+id, 'calendarEntry',"location=no,directories=no,menubar=no,statusbar=no,toolbar=no,scrollbars=yes,height=" +height+ ",width=" +width+ ",resizable=no");
  newWin.resizeTo(width,height);
  newWin.focus();
  return false;
}

/**
 * Extract data from page to pass to flash as XML.
 
 <ul id="theData">
  <li class="first">
   <div class="date">17 07 2009</div>
   <div class="title">Antarctic Ice Sheet: Stable Isotope Analyses of Byrd Station Cores and Interhemispheric Climatic Implications</div>
   <div class="details">
     ...<b>Antarctic</b> <b>Ice</b> <b>Sheet</b>: Stable Isotope Analyses of Byrd Station Cores and Interhemispheric Climatic Implications Samuel Epstein 1, R. P.
   </div>     
   <a href="http://www.sciencemag.org/cgi/content/abstract/168/3939/1570">read more</a>  
  </li>
 </ul>
  
 <data>
  <item>
    <text name="Date" value="07 December 09" />
    <text name="Headline" value="How is global warming changing the world?" />
    <text name="Description" value="Copenhagen - From cautiously advising that man-made, heat-trapping car..." />
    <link name="Link1" value="http://www.readmorelink.com" />
  </item>
 </data>
 */
function scrapeImageData(from) {
  try {
    var iElm = from; // input element (XHTML)
    var rElm = document.createElement("data"); // return element (XML for Flash)
    
    var tElm, tData, tSub; // tmp
    
    for (var ii=0; ii<iElm.childNodes.length; ii++) { 
      tElm = document.createElement("item");
      
      if (iElm.childNodes[ii].nodeName != 'LI') continue; // TO DO .... use getElementsByTagName in place of this
      
      tData = iElm.childNodes[ii].getElementsByTagName("a")[0];
      tSub = document.createElement("link");
      tSub.setAttribute("name", "Link1");
      tSub.setAttribute("value", tData.getAttribute("href"));
      tElm.appendChild(tSub);
      
      var divList = iElm.childNodes[ii].getElementsByTagName("div");
      for (var jj=0; jj<divList.length; jj++) {
        tData = divList[jj];
        
        tSub = document.createElement("text");
        if (tData.getAttribute("class") == 'date') {
          tSub.setAttribute("name", "Date");
        } else if (tData.getAttribute("class") == 'title') {
          tSub.setAttribute("name", "Headline");
        } else if (tData.getAttribute("class") == 'details') {
          tSub.setAttribute("name", "Description");
        }
        
        tSub.setAttribute("value", tData.innerHTML);
        tElm.appendChild(tSub);
      }
      
      rElm.appendChild(tElm);
      
    }
    
    var temp = document.createElement("return");
    temp.appendChild(rElm);
    
    //alert(temp.innerHTML);
    return temp.innerHTML; 
    
  } catch (e) {
    // data scrape failed, return null !!!
    return null;
  }
}

