String.prototype.right = function(count) {  return this.substr(this.length - count);}function debugPortals() {  var html = "<table>";  for ( var i = 0 ;  i<portals.length;i++) {    html +=  "<tr><td colspan=3>";    html += "Details of portals[" + i + "]";    html += "<tr><td>&nbsp;&nbsp;<td> url: <td>" + portals[i].url;    html += "<tr><td>&nbsp;&nbsp;<td> target:<td> " + portals[i].target;    html += "<tr><td>&nbsp;&nbsp;<td>  name:<td> " + portals[i].name;    html += "<tr><td>&nbsp;&nbsp;<td>  color:<td> " + portals[i].color;    html += "<tr><td>&nbsp;&nbsp;<td>  cols:<td> " + portals[i].cols;    html += "<tr><td>&nbsp;&nbsp;<td>  header:<td> " + portals[i].header;    html += "<tr><td>&nbsp;&nbsp;<td>  type: <td>" + portals[i].type;  }  html += "</table>";  var dbg = window.open('about:blank','dbg','');  dbg.document.write(html);}var portals = new Array;/************************************************* addPortal()    - add a portal to the global array of portal objects  name - name and id of the portal typ - type of portal view or html ( "vw" / "htm" ) url - url to load in the portal target - target for links in the portal  header - title text on portal header color - color of portal border and header bg cols - array of columns to display if type is view******************************************************/function addPortal ( name, typ, url, target, header, color, cols) {  var i = portals.length;  portals[i] = new Object  portals[i].header = header;  portals[i].type = typ;  // handle proxied urls  if ( url.indexOf( "jprox" ) != -1 ) {    var svr = url.split("&")[1];    svr = svr.right( svr.length - 4 );    var path = url.split("&path=")[1];    path = path.split("?")[0] + "/";    portals[i].proxyDestination = "http://" + svr + "/" + path;  } else {    portals[i].proxyDestination = null;  }   portals[i].url = url;    portals[i].target = target;  portals[i].name = name;  portals[i].color = color;  portals[i].cols = cols;}/* return a portal by its name */function getPortal( s ) { for ( var i = 0; i < portals.length; i++ ) {   if ( portals[i].name == s ) {     return portals[i];   }  } return null;}/* load a portal div given its id */function loadPortalDiv( id ) {  var portalDiv = document.getElementById( id );  portalDiv.style.display = "block";  var portal = getPortal( id );// GC  alert(portal);  if ( portalDiv ) {    var url = portal.url;    var dbAndView = portal.url.split("?")[0] + "/";    AjaxRequest.get(    {      'url': url      , 'onSuccess':function(req) { if ( portal.type == "vw") {loadView( portalDiv, dbAndView, portal.cols, req.responseXML )} else { loadHTML( portalDiv, req.responseText ) } }      ,'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}      ,'onLoading':function() { portalDiv.innerHTML = "<div class=\"loading\">Loading " + portal.header + "...<div>"; }     ,generateUniqueUrl:false    }     )        }}/* hide/show child table in portal div header */function hs( objTr ) {  var objDiv = objTr.parentNode.parentNode.parentNode;  var dataTbl = objDiv.getElementsByTagName("div")[0];  var headerTbl = objDiv.getElementsByTagName("table")[0];  var img = headerTbl.getElementsByTagName("img")[0];  if ( dataTbl.style.display == "" ) {    dataTbl.style.display = "none";    img.src =  window._resourcesDb + "/pplus.gif";    img.alt = "expand";  } else {    dataTbl.style.display = "";    img.src =  window._resourcesDb + "/pminus.gif";    img.alt = "collapse";    }}/* load link from within portal s is url target is "" for same win or "_new800x550" for new win 800x550 */// stop;function loadLink( s, target ) {  if ( s.indexOf("http") != -1 ) {    var url = s;    } else {    var url = _serverUrl + s;  }    if ( target == "" ) {    location.href = url;  } else if ( target == "_blank" ) {    var parms = 'addressbar=0,statusbar=0,location=0,scrollbars=1,width=800,height=550';    window.open( url, '', parms );    } else if ( target == "ogci" ) {    var parms = 'addressbar=0,statusbar=0,location=0,width=' + ww + ',height=' + wh;    window.open( url, '', parms );      }}/***************************************  loadView() - Load a view into a div element     div - destination div   dbView - string containing base of url (up to unid)   UNIDs - docunids for each item in the view   colValues - array containing the indexes               of columns to display *****************************************/function loadView( div, sDbAndView, colValues, responseXML  ) {  var portal = getPortal( div.id );  var cols = colValues.length;  var UNIDs = getUnids( responseXML );  var tableData = new Array();  if ( ! UNIDs ) {alert('OGC Portal Error:\nCannot load view data for "' + portal.header +'"');return;}  /* load the table data */  for ( var i = 0; i < cols; i++ ) {    tableData[i] = xmlToArray( responseXML, colValues[i] );  }    /* create the html for the header */  var htm = "<table class=\"div\" style=\"margin-bottom:0;border-color:"   htm += portal.color + "\">";    htm += "<tr onclick=\"hs(this);\" style=\"cursor:pointer;\">";  htm += "<td colspan=\"3\" class=\"divtitle\" style=\"background-color:"   htm += portal.color + "\" ><img src=\"" + window._resourcesDb + "/pminus.gif\" alt=\"collapse\">"  htm += portal.header + " (" + UNIDs.length +  ")";  htm += "</table>";    /* add html to start the table */  htm += "<div id=\"div" + div.id + "\"><table class=\"div\" id=\"tbl" + div.id + "\" style=\"margin-top:0;border-color:" + portal.color + "\">";    /* handle proxied data */  if ( portal.proxyDestination ) {    sDbAndView = portal.proxyDestination  }    /* add the html for rows and cells */  for ( var i = 0; i < UNIDs.length; i++ ) {    htm += "<tr onclick=\"loadLink('" + sDbAndView + UNIDs[i] + "', '" + portal.target + "');\"";    htm += " style=\"cursor:pointer;\" onmouseover=\"this.style.backgroundColor='#ffffaa';\" ";    htm += " onmouseout=\"this.style.backgroundColor='';\" >";    for ( var j = 0; j < cols; j++ ) {      htm += "<td>" + tableData[j][i];    }  }  /* add html to close the table */  htm += "</table></div>";alert(htm);  /* put the html into the div */    div.innerHTML = htm;  var objInnerDiv = document.getElementById("div" + div.id );  /* restrict the height of the div  based on number of rows */  if ( UNIDs.length > 8 ) { // max table height at 5 rows    objInnerDiv.style.height = "150px";    objInnerDiv.style.overflow = "auto";    objInnerDiv.style.border = "1px solid #c0c0c0";  }}/* load the html into a portal div */function loadHTML( div, responseHTML ) {   var portal = getPortal( div.id );    /* create the html for the header */  var htm = "<table class=\"div\" style=\"margin-bottom:0;border-color:"   htm += portal.color + "\">";    htm += "<tr onclick=\"hs(this);\" style=\"cursor:pointer;\">";  htm += "<td colspan=\"3\" class=\"divtitle\" style=\"background-color:"   htm += portal.color + "\" ><img src=\"" + window._resourcesDb + "/pminus.gif\" alt=\"collapse\">"  htm += portal.header;  htm += "</table>";   htm += "<div  id=\"div" + div.id + "\"><table class=\"div\" id=\"tbl" + div.id + "\" style=\"margin-top:0;border-color:" + portal.color + "\">";  htm += "<tr><td><div>";   htm += responseHTML;   /* add html to close the table */  htm += "</div></table></div>";    /* put the html into the div */    div.innerHTML = htm;  var objInnerDiv = document.getElementById("div" + div.id );  }