function ListMPAdverts(MyID, Direction, MaxAds) {

  var xmlHttp;
  try {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e) {
    // Internet Explorer
    try {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e) {
      try  {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e) {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }

    xmlHttp.onreadystatechange=function() {
      if(xmlHttp.readyState == 4) {
          if(xmlHttp.responseText != 0) {
          var pos = 0;
          var Adheader = "";
          var AdBody = "";
          var Target = "";
          if(navigator.appName != "Microsoft Internet Explorer") {
             WinH = window.innerHeight;
             WinW = window.innerWidth;
          } else {
             WinH = document.documentElement.clientHeight -50;
             WinW = document.documentElement.clientWidth;
          }

//    document.write("Adverts&nbsp;By<A Href='http://www.MillionPlaces.com' target='_New'><IMG SRC='images/Millionplaces-logoTM.gif'></A>");

// Find the table
    MPAdsElement  = document.getElementById('MPAdsTABLE');
    if(Direction == "H") MPAdsElement.insertRow(-1); // Add the row for H format

// Process Results
    var AdsText = xmlHttp.responseText.split("|||");
//    document.write(xmlHttp.responseText);
    for(var i=0; i < Math.min(MaxAds,AdsText.length-1); i++) {

       pos = AdsText[i].indexOf("###");
       Target = AdsText[i].substr(0,pos);
       AdsText[i] = AdsText[i].substr(pos+3);
       pos = AdsText[i].indexOf("+++");
       AdHeader = AdsText[i].substr(0,pos);
       AdBody = AdsText[i].substr(pos+3);

    if(Direction == "V") {
       MPAdsRow = MPAdsElement.insertRow(-1);
       MPAdsCell = MPAdsRow.insertCell(-1); 
       if(Target == 0) {
           MPAdsCell.innerHTML = "<SPAN Class='MPAdHead'>More Adverts needed<SPAN>";
       } else {
           MPAdsCell.innerHTML = "<A Class='MPAdHead' Href='../MPLink.php?S=" + MyID + "&T=" + Target + "' target='_new'>" + AdHeader + "" + "</A><BR><SPAN Class='MPAdBody'>" + AdBody + "</SPAN>";
       }
       if( (MPAdsElement.offsetHeight + MPAdsElement.offsetTop) > WinH) {
          MPAdsElement.deleteRow();
          break;
       }
// Add a blank row
       MPAdsRow = MPAdsElement.insertRow(-1);
       MPAdsCell = MPAdsRow.insertCell(-1);   
       MPAdsCell.innerHTML = "&nbsp;";
       if( (MPAdsElement.offsetHeight + MPAdsElement.offsetTop) > WinH) {
          MPAdsElement.deleteRow();
          break;
       }

    } else { // Horizontal
       MPAdsRow = MPAdsElement.rows[0];
 //      MPAdsRow.height = WinH - MPAdsElement.offsetTop;
       MPAdsCell = MPAdsRow.insertCell(-1);
       if(Target == 0) {
           MPAdsCell.innerHTML = "<SPAN Class='MPAdHead'>More Adverts needed<SPAN>";
       } else {
           MPAdsCell.innerHTML = "<A Class='MPAdHead' Href='MPLink.php?S=" + MyID + "&T=" + Target + "' target='_new'>" + AdHeader + "" + "</A><BR><SPAN Class='MPAdBody'>" + AdBody + "</SPAN>";
       }
// Add Cell
  
       if ( MPAdsElement.offsetWidth > WinW) { 
          MPAdsRow.deleteCell();
          break;
       }
       MPAdsCell = MPAdsRow.insertCell(-1); 
       MPAdsCell.innerHTML = "&nbsp;";

    }
              } // end For

          }
       }
      }
    var url = "../ajaxListAdverts.php?S=" + MyID;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null); 
}

