// Trip Override

function MembersListRoster (membersIn,all) {
  var members=membersIn;
  //if (members==null) members=CERTmembers;
  if (members==null) members=ZoneMembers;
  var lines=members;
  var line,data;
//alert(txt);
  //return txt;  
  var w=window.open();
  var html='<table style="font-family:Arial;white-space:nowrap;" >';
   html+='<tr><th>Zone </th><th>TeamLeader </th><th>Active </th><th>Last Name </th><th>FirstName </th><th>Address </th><th>City </th><th>State </th><th>ZIP </th><th>Nhighborhood </th><th>Tel </th><th>Tel work </th><th>Cell </th><th>Pages </th><th>tax </th><th>eMail </th><th>RadioOp </th><th>Graduation </th><th>Class </th><th>ID </th><th>CERT radio </th><th>Skills </th><th>Type </th></tr>';
  //w.document.write(txt);
  for (var i=0;i<lines.length;i++) {
    line=lines[i];
    data=line;
    if (data[3]=='' && all==null) continue;
    html+='<tr>';
    for (var j=0;j<data.length;j++) {
      //if (j>0) html+='\t';
      html+='<td style="font-family:Arial;white-space:nowrap;" >';
      html+=data[j];
      html+='</td>';
    };
    html+='</tr>';
  };
  html+='</table>';
  w.document.write(html);
  w.document.close();
  //alert(ZonesPageMapsListTitle);
  w.document.title=ZonePageTitle+' Members Roster List';
};


function MembersListRosterText (membersIn,all) {
  var members=membersIn;
  //if (members==null) members=CERTmembers;
  if (members==null) members=ZoneMembers;
  var lines=members;
  var line,data;
//alert(txt);
  //return txt;  
  var html='<pre>';
  html+='Zone \tTeamLeader \tActive \tLast Name \tFirstName \tAddress \tCity \tState \tZIP \tNhighborhood \tTel \tTel work \tCell \tPages \ttax \teMail \tRadioOp \tGraduation \tClass \tID \tCERT radio \tSkills \tType \n';
  //w.document.write(txt);
  for (var i=0;i<lines.length;i++) {
    line=lines[i];
    data=line;
    if (data[3]=='' && all==null) continue;
    for (var j=0;j<data.length;j++) {
      if (j>0) html+='\t';
      html+=data[j];
    };
    html+='\n';
  };
  html+='</pre>';
  w=window.open();
  w.document.write(html);
  w.document.close();
  //alert(ZonesPageMapsListTitle);
  w.document.title=ZonePageTitle+' Members Roster List';
};



function isTeamLeaderIx(ix) {
  var is=false;
  for (var i=0;i<ZoneTeamLeadersIx.length;i++) {
    is=(ZoneTeamLeadersIx[i]==ix);
    if (is) break;
  };
  return is;
};


//var EMailSubject='CERT';
var EMailSubject;
var EMails;
if (EMails==null) EMails=[];
function EMailsHTML (txt) {
  var html='';
  if (EMails.length<1) return html;
  html+='<a href="';
  html+='mailto:?bcc=';
  for (var i=0;i<EMails.length;i++) {
    //html+=', '+EMails[i];
    //if (i>0) html+=', ';
    if (i>0) html+='; ';
    html+=EMails[i];
  };
  html+='&subject='+EMailSubject;
  html+='">'+txt+'</a>';
  //alert(html);
  return html;
};


function ShowWindow(html,title) {
  var w=window.open();
  w.document.title=title;
  w.document.body.innerHTML=html;
};

function ShowEmailsWindow() {
  var html='';
  //html+='';
  //html+='<html>';
  //html+='<head>';
  //html+='<title>';
  //html+='CERT members email';
  //html+='</title>';
  //html+='</head>';
  //html+='<body>';
  html+='<center>';
  html+='<table><tr><td align="left">';
  for (var i=0;i<EMails.length;i++) {
    html+='<a href="mailto:'+EMails[i]+'">'+EMails[i]+'</a>';
    html+='<br/>';
  };
  html+='</td></tr></table>';
  html+='</center>';
  //html+='</body>';
  //html+='</html>';

  //var w=window.open();
  //w.document.body.innerHTML=html;
  //ShowWindow(html,'CERT Members email: '+ZoneName);
  var zonename=ZoneName;
  if (zonename==null) zonename='All Zones';
  ShowWindow(html,'CERT Members email ('+EMails.length+'): '+zonename);
};

var ZoneRadiosTxt=[];
function GetZoneRadiosTxt() {
  var indexCertRadio=window.opener.indexCertRadio;
  var indexLastName=window.opener.indexLastName;
  var indexFirstName=window.opener.indexFirstName;
  var indexIsTeamLeader=window.opener.indexIsTeamLeader;
  ZoneRadiosTxt=[];
  var name,radio;
  for (var i=0;i<ZoneMembers.length;i++) {
    if (ZoneMembers[i][indexCertRadio]==null || ZoneMembers[i][indexCertRadio]=='') continue;
    name='';    
    //if (ZoneMembers[i][indexIsTeamLeader]!=null && ZoneMembers[i][indexIsTeamLeader]!='') 
    //  name=name+'<b>';
    name=name+ZoneMembers[i][indexLastName];
    name=name+' ';
    name=name+ZoneMembers[i][indexFirstName];
    //if (ZoneMembers[i][indexIsTeamLeader]!=null && ZoneMembers[i][indexIsTeamLeader]!='') 
    //  name=name+'</b>';
    //html+=' : ';
    radio=ZoneMembers[i][indexCertRadio];
    //html+='<br/>';
    ZoneRadiosTxt[ZoneRadiosTxt.length]=[name,radio,ZoneMembers[i][indexIsTeamLeader]];
  };
  return ZoneRadiosTxt;
};


function ShowRadiosWindow() {
  if (ZoneRadiosTxt==null || ZoneRadiosTxt.length<1) GetZoneRadiosTxt();
  var html='';
  //var indexCertRadio=window.opener.indexCertRadio;
  html+='<center>';

  html+='<big><b>';
  html+='CERT Members Radio: <br/>';
  html+=ZoneName;
  html+='</b></big>';

  html+='<br/><br/>';

  //html+='<table><tr><td align="left">';
  html+='<table>';
  for (var i=0;i<ZoneRadiosTxt.length;i++) {
    html+='<tr>';
    html+='<td align="left">';
    if (ZoneRadiosTxt[i][2]!=null && ZoneRadiosTxt[i][2]!='') 
      html+='<b>';
    html+=ZoneRadiosTxt[i][0];
    if (ZoneRadiosTxt[i][2]!=null && ZoneRadiosTxt[i][2]!='') 
      html+='</b>';
    html+='</td>';
    html+='<td align="left">';
    html+=':';
    html+='</td>';
    html+='<td align="left">';
    html+=ZoneRadiosTxt[i][1];
    html+='</td>';
    html+='</tr>';
  };
  if (ZoneRadiosTxt.length<1) 
    html+=' - none - ';
  //html+='</td></tr></table>';
  html+='</table>';
  html+='</center>';
  ShowWindow(html,'CERT Members Radio: '+ZoneName);
};

function ShowRadiosMessage() {
  //if (ZoneRadiosTxt==null || ZoneRadiosTxt.length<1) GetZoneRadiosTxt();
  var html='';
  html+='CERT Members Radio: \n';
  html+=ZoneName;
  html+='\n';

  html+='\n';

  for (var i=0;i<ZoneRadiosTxt.length;i++) {
    if (ZoneRadiosTxt[i][2]!=null && ZoneRadiosTxt[i][2]!='') 
      html+='* '
     else
      html+='  ';
    html+=ZoneRadiosTxt[i][0];
    html+=' : ';
    html+=ZoneRadiosTxt[i][1];
    html+='\n';
  };
  if (ZoneRadiosTxt.length<1) 
    html+=' - none - \n';
  alert(html);
};


function ZoneBoundariesPoints(boundaryArray) {
  //var pArray=[];
  var pArray=null;
  //alert('zoneBoundary \n'+boundaryArray);
  if (boundaryArray==null || boundaryArray=='') return pArray;
  pArray=[];
  var lat,lon, point;
  for (var i=0;i<boundaryArray.length;i++) {
    lat=boundaryArray[i][0];
    lon=boundaryArray[i][1];
    point=new GLatLng(lat,lon);
    pArray[pArray.length]=point;
  };
  return pArray;
};


//-- override


    function showLocationDetails(ix)
    // Show a marker and open it's info window
    {   
        map.closeInfoWindow(); // else get problems
        var marker = getMarkerIdent( Locations[ix][0] );
        //--eval(marker + ".openInfoWindowHtml(" + marker + ".html);");
        map.focus();
        LocationsMarkers[ix].openInfoWindowHtml(LocationsMarkers[ix].html);
        //eval("GEvent.trigger(" + marker + ", click)"
    }



function LocationsListHTML (showExtra) {
	var html="";
	// zoom back to trip
	html+="<center>";
	//html+='<input type="button" value="Show Trip" onClick="ZoomToTrip()" />';
	html+='<input type="button" value="Re-Zoom" onClick="ZoomToTrip()" />';
	html+="</center>";
	html+="<br/>";
	//
	html+="<ol>";
	for (var i=0;i<Locations.length;i++) {
  	  html+="<li>";
          html+=LocationListHTML(i,showExtra);
          //html+="<br/>";
	  html+="</li>";
        };
	html+="</ol>";

	html+="<center>";
	//html+=EMailsHTML('<font face="webdings" style="{text-decoration:none}">i </font>eMail members');
	html+=EMailsHTML('<font face="webdings" style="{text-decoration:none}">i </font>');
	html+='<a href="javascript:ShowEmailsWindow()">eMail members list</a>';

	html+='<a href="javascript:ShowRadiosWindow()"><font face="webdings" style="{text-decoration:none}">º </font>radios list</a>';

	html+="</center>";

        //html='<small><small>'+html+'</small></small>';
        html='<small>'+html+'</small>';

	return html;
};

/*
function showLocation(ix) {
  var cmd='showLocationDelayed('+ix+');';
alert(cmd+'\n'+(ix*100));
  setTimeout(cmd,ix*100);
};
function showLocationDelayed(ix) {
*/

function ShowLocations() {
	ShowLocationsList();
	showLocation(0);
};

var PushpinStartStop=false;

function showLocation(ix) {
  if (ix>=Locations.length) return;
  var id,name,address,tel,html,lat,lon, description;
  id=Locations[ix][0];
  name=Locations[ix][1];
  address=Locations[ix][2];
  tel=Locations[ix][3];
  lon=Locations[ix][4];
  lat=Locations[ix][5];
  description=Locations[ix][6];
  if (description==null) description="";
  image=Locations[ix][12];
  pushpinImage=Locations[ix][13];
  if (pushpinImage==null) {
    pushpinImage=PushpinImageDefault;
    if (PushpinStartStop) {
      if (ix==0) pushpinImage=PushpinImageStart;
      if (ix==(Locations.length-1)) pushpinImage=PushpinImageStop;
    };
  };
  /*
  //html="<div><b>"+name+"</b><br/>"+address+"<br/>Tel: "+tel+"<br/><a href='http://www.NicolaZordan.net' target='_blank'>www.NicolaZordan.net</a></div>";
  html="<div>";
  html+="<b>"+name+"</b>";
  html+="<br/>"+address;
  if (description!=null && description.length>0) {
    html+="<br/>"+description;
  };
  //html+="<div><b>"+name+"</b><br/>"+address+"<br/>Tel: "+tel+"<br/><a href='http://www.NicolaZordan.net' target='_blank'>www.NicolaZordan.net</a></div>";
  html+="</div>";
  */
  //-html="<div>"+LocationDescriptionHTML(ix)+"</div>";

  geocoder.getLatLng(
    address,
    function(point) {
      var where=point;
      if (!point) {
        LocationsUseLatLon[ix]=false;
 	if (lon==null || lat==null) {
	  lat=0;
	  lon=0;
          //alert("Google maps API cannot find: \n"+address+"\nusing lat="+lat+" lon="+lon);
          //-alert("Google maps API cannot Geolocate: \n"+name+"\n"+address+"\nfix the address or use latitude longitude\n lat="+lat+" lon="+lon);
  	  //Locations[ix][4]=null;
	  //Locations[ix][5]=null;
  	  LocationsPathPoints[ix]='NOPOINT';
          //alert("Google maps API cannot Geolocate: \n"+name+"\n"+address);
          window.status=("Google maps API cannot Geolocate: \n"+name+"\n"+address);
  	  ShowLocationsPath(Locations.length);
        //showLocation(ix+1);
        //-setTimeout('showLocation('+(ix+1)+')',100);
        setTimeout('showLocation('+(ix+1)+')',10);
           return;
         } else {
	};
 	//where=new GPoint(lat,lon);
	//where=new GPoint(lon,lat);
	where=new GLatLng(lat,lon);
       } else { 
        LocationsUseLatLon[ix]=true;
	lon=where.x;
    	lat=where.y;
      };

	Locations[ix][4]=lon;
	Locations[ix][5]=lat;

	LocationsPathPoints[ix]=where;

	/*
        map.setCenter(point, 13);
        var marker = new GMarker(point);
        map.addOverlay(marker);
        marker.openInfoWindowHtml(address);
	*/

        var iconName = "iconHome";
        var markerName = getMarkerIdent( id );
        //eval(markerName + "= new GMarker( point, " + iconName + ");");
        //-eval(markerName + "= new GMarker( where, " + iconName + ");");
	//--eval(markerName + "= new GMarker( where );");
        //LocationsMarkers[ix]=new GMarker(where);
        var thisMarker=null;
        if (pushpinImage==null) {
          thisMarker=new GMarker(where);
         } else {
          var thisIcon=new GIcon(G_DEFAULT_ICON);
          thisIcon.image=pushpinImage;
          thisMarker=new GMarker(where,thisIcon);
          LocationsMarkers[ix]=new GMarker(where,thisIcon);
        };
        LocationsMarkers[ix]=thisMarker;



        //--eval(markerName + '.html = "' + html + '";');
        html="<div>"+LocationDescriptionHTML(ix)+"</div>";
	LocationsMarkers[ix].html=html;
        //--eval("GEvent.addListener(" + markerName +", 'click', function() { " + markerName + ".openInfoWindowHtml(" + markerName + ".html); });");
	//alert(ix+'. '+markerName+'\n'+LocationsMarkers[ix]);
	//+GEvent.addListener(LocationsMarkers[ix], 'click', eval('function() { LocationsMarkers['+ix+'].openInfoWindowHtml(LocationsMarkers['+ix+'].html); }') );
        //+alert('function() { LocationsMarkers['+ix+'].openInfoWindowHtml(LocationsMarkers['+ix+'].html); }'+'\n'+eval('function() { LocationsMarkers['+ix+'].openInfoWindowHtml(LocationsMarkers['+ix+'].html); }'));
	//GEvent.addListener(LocationsMarkers[ix], 'click', eval('function() { LocationsMarkers['+ix+'].openInfoWindowHtml(LocationsMarkers['+ix+'].html); }') );
	eval("GEvent.addListener(LocationsMarkers["+ix+"], 'click', function() { LocationsMarkers["+ix+"].openInfoWindowHtml(LocationsMarkers["+ix+"].html); } );" );
        //--eval("map.addOverlay(" + markerName + ");");
        map.addOverlay(LocationsMarkers[ix]);
      /* } */

	ShowLocationsPath(Locations.length);

        //showLocation(ix+1);
        //-setTimeout('showLocation('+(ix+1)+')',100);
        setTimeout('showLocation('+(ix+1)+')',10);

    }
  );
}

function showLocation0(ix) {
  var id,name,address,tel,html,lat,lon, description;
  id=Locations[ix][0];
  name=Locations[ix][1];
  address=Locations[ix][2];
  tel=Locations[ix][3];
  lon=Locations[ix][4];
  lat=Locations[ix][5];
  description=Locations[ix][6];
  if (description==null) description="";
  /*
  //html="<div><b>"+name+"</b><br/>"+address+"<br/>Tel: "+tel+"<br/><a href='http://www.NicolaZordan.net' target='_blank'>www.NicolaZordan.net</a></div>";
  html="<div>";
  html+="<b>"+name+"</b>";
  html+="<br/>"+address;
  if (description!=null && description.length>0) {
    html+="<br/>"+description;
  };
  //html+="<div><b>"+name+"</b><br/>"+address+"<br/>Tel: "+tel+"<br/><a href='http://www.NicolaZordan.net' target='_blank'>www.NicolaZordan.net</a></div>";
  html+="</div>";
  */
  //-html="<div>"+LocationDescriptionHTML(ix)+"</div>";

  geocoder.getLatLng(
    address,
    function(point) {
      var where=point;
      if (!point) {
        LocationsUseLatLon[ix]=false;
 	if (lon==null || lat==null) {
	  lat=0;
	  lon=0;
          //alert("Google maps API cannot find: \n"+address+"\nusing lat="+lat+" lon="+lon);
          //-alert("Google maps API cannot Geolocate: \n"+name+"\n"+address+"\nfix the address or use latitude longitude\n lat="+lat+" lon="+lon);
  	  //Locations[ix][4]=null;
	  //Locations[ix][5]=null;
  	  LocationsPathPoints[ix]='NOPOINT';
          //alert("Google maps API cannot Geolocate: \n"+name+"\n"+address);
          window.status=("Google maps API cannot Geolocate: \n"+name+"\n"+address);
  	  ShowLocationsPath(Locations.length);
           return;
         } else {
	};
 	//where=new GPoint(lat,lon);
	//where=new GPoint(lon,lat);
	where=new GLatLng(lat,lon);
       } else { 
        LocationsUseLatLon[ix]=true;
	lon=where.x;
    	lat=where.y;
      };

	Locations[ix][4]=lon;
	Locations[ix][5]=lat;

	LocationsPathPoints[ix]=where;

	/*
        map.setCenter(point, 13);
        var marker = new GMarker(point);
        map.addOverlay(marker);
        marker.openInfoWindowHtml(address);
	*/

        var iconName = "iconHome";
        var markerName = getMarkerIdent( id );
        //eval(markerName + "= new GMarker( point, " + iconName + ");");
        //-eval(markerName + "= new GMarker( where, " + iconName + ");");
	//--eval(markerName + "= new GMarker( where );");
        LocationsMarkers[ix]=new GMarker(where);
        //--eval(markerName + '.html = "' + html + '";');
        html="<div>"+LocationDescriptionHTML(ix)+"</div>";
	LocationsMarkers[ix].html=html;
        //--eval("GEvent.addListener(" + markerName +", 'click', function() { " + markerName + ".openInfoWindowHtml(" + markerName + ".html); });");
	//alert(ix+'. '+markerName+'\n'+LocationsMarkers[ix]);
	//+GEvent.addListener(LocationsMarkers[ix], 'click', eval('function() { LocationsMarkers['+ix+'].openInfoWindowHtml(LocationsMarkers['+ix+'].html); }') );
        //+alert('function() { LocationsMarkers['+ix+'].openInfoWindowHtml(LocationsMarkers['+ix+'].html); }'+'\n'+eval('function() { LocationsMarkers['+ix+'].openInfoWindowHtml(LocationsMarkers['+ix+'].html); }'));
	//GEvent.addListener(LocationsMarkers[ix], 'click', eval('function() { LocationsMarkers['+ix+'].openInfoWindowHtml(LocationsMarkers['+ix+'].html); }') );
	eval("GEvent.addListener(LocationsMarkers["+ix+"], 'click', function() { LocationsMarkers["+ix+"].openInfoWindowHtml(LocationsMarkers["+ix+"].html); } );" );
        //--eval("map.addOverlay(" + markerName + ");");
        map.addOverlay(LocationsMarkers[ix]);
      /* } */

	ShowLocationsPath(Locations.length);

    }
  );
}

function zoomToPolyLine(pl) {
  var bounds = new GLatLngBounds();
  //var bounds = new GBounds();
  for (var i=0;i<pl.length;i++) {
    //alert(i+'. \n'+pl[i]+'\n'+bounds);
    //if (pl[i]=='NOPOINT') continue;
    if (pl[i]!='NOPOINT') 
      bounds.extend(pl[i]); 
  };  
  //alert(bounds);
  map.setCenter(bounds.getCenter(),map.getBoundsZoomLevel(bounds)); 
  return pl;
};

function ZoomToTrip() {
  var zoomPoints=[];
  for (var i=0;i<LocationsPathPoints.length;i++) {
    zoomPoints[zoomPoints.length]=LocationsPathPoints[i];
  };
  if (ZoneBoundaries!=null) {
    for (var i=0;i<ZoneBoundaries.length;i++) {
      zoomPoints[zoomPoints.length]=ZoneBoundaries[i];
    };
  };
//alert(zoomPoints.length+'\n'+LocationsPathPoints.length);
  //zoomToPolyLine(LocationsPathPoints);
  zoomToPolyLine(zoomPoints);
};


    function showLocationDetails(ix)
    // Show a marker and open it's info window
    {   
        if(LocationsPathPoints[ix]=='NOPOINT') {
          //alert('Google Maps CANNOT map\n'+Locations[ix][1]+'\n'+Locations[ix][2]);
          //alert("Google maps API cannot Geolocate: \n"+Locations[ix][1]+"\n"+Locations[ix][2]+"\nTel: "+Locations[ix][3]+"\n"+Locations[ix][6]);
          alert("Google maps API cannot Geolocate: \n"+Locations[ix][1]+"\n"+Locations[ix][2]+"\nTel: "+Locations[ix][3]);
          return;
        };
        map.closeInfoWindow(); // else get problems
        var marker = getMarkerIdent( Locations[ix][0] );
        //--eval(marker + ".openInfoWindowHtml(" + marker + ".html);");
        LocationsMarkers[ix].openInfoWindowHtml(LocationsMarkers[ix].html);
        //eval("GEvent.trigger(" + marker + ", click)");
    }


function ShowLocationsPath(lenExpected,force) {
  if (force!=null) ShowLocationPathDrawn=false;
  if (ShowLocationPathDrawn==true) return;
  //alert(LocationsPathPoints.length+" ~ "+lenExpected+"\n"+LocationsPathPoints);
  if (LocationsPathPoints.length<lenExpected) return;
  for (var i=0;i<LocationsPathPoints.length;i++) {
    if (LocationsPathPoints[i]==null) {
      //alert("found "+i+" null point");
      return;
    };
  };  
//  if (ShowLocationPathDrawn==true) return;
  ShowLocationPathDrawn=true;
//DebugLoop('ShowLocationsPath '+lenExpected+'\n'+LocationsPathPoints+'\n'+force+':'+ShowLocationPathDrawn);
  var points=LocationsPathPointsValid();
  //LocationsPath=new GPolyline(LocationsPathPoints);
  LocationsPath=new GPolyline(points);
  //-MapContacts.com- map.addOverlay(LocationsPath);

/*
  //LocationsPath.F.title='test title';

  //showPolyLineBorder(LocationsPathPoints);
  //zoomToPolyLine(LocationsPathPoints);
  showPolyLineBorder(points);
  zoomToPolyLine(points);
   ShowLocationsList();
  //ShowLocationPathDrawn=true;
*/

  DisplayAreaMark();
  ZoomToTrip();
  ShowLocationsList();
  ShowTripData();

};

/*
function ShowLocationsPath(lenExpected) {
  //alert(LocationsPathPoints.length+" ~ "+lenExpected+"\n"+LocationsPathPoints);
  if (LocationsPathPoints.length<lenExpected) return;
  for (var i=0;i<LocationsPathPoints.length;i++) {
    if (LocationsPathPoints[i]==null) {
      //alert("found "+i+" null point");
      return;
    };
  };  
  LocationsPath=new GPolyline(LocationsPathPoints);
  //-map.addOverlay(LocationsPath);

  DisplayAreaMark();

  //LocationsPath.F.title='test title';

  //zoomToPolyLine(LocationsPathPoints);
  ZoomToTrip();

   ShowLocationsList();

  ShowTripData();
};
*/


//TripBorderColor='#00FFFF'; // Cyan
//TripBorderColor='#00FF00'; // Lime
TripBorderColor='#FF0000'; // Red
//TripBorderColor='#0000FF'; // Blue
function DisplayAreaMark() {

  var points=[];
  var bounds=new GLatLngBounds();
  for (var i=0;i<LocationsPathPoints.length;i++) {
    if (LocationsPathPoints[i]==null) {
      //alert("found "+i+" null point");
      return;
    };
  };  

  for (var i=0;i<LocationsPathPoints.length;i++) {
    if (LocationsPathPoints[i]=='NOPOINT') continue;
    bounds.extend(LocationsPathPoints[i]);
  };

  var border=ZoneBoundaries;
//alert(ZoneBoundaries);

  if (border==null || border.length<1) { 
    border=[];
    var pSW=bounds.getSouthWest();
    var pNE=bounds.getNorthEast();
    border[0]=pSW;
    border[1]=new GLatLng(pSW.y,pNE.x);
    border[2]=pNE;
    border[3]=new GLatLng(pNE.y,pSW.x);
     border[4]=pSW;
    //alert(points);
  };
//alert(border);


  //alert('zoneline:\n'+points);
  //var line=new GPolyline(points);
  //map.addOverlay(line);
  //var line=new GPolyline(border);
  if (TripBorderColor==null) return; // no border if TripBorderColor is null
  var line=new GPolyline(border,TripBorderColor);
  map.addOverlay(line);
};





function LocationDescriptionHTML(ix) {
  var html="";
  //if (Locations[ix]==null) return html;
  var id,name,address,tel,html,lat,lon, description, detailsURL;
  id=Locations[ix][0];
  name=Locations[ix][1];
  address=Locations[ix][2];
  tel=Locations[ix][3];
  lon=Locations[ix][4];
  lat=Locations[ix][5];
  //alert(Locations[ix]+'\n'+lon+'\n'+lat);
  description=Locations[ix][6];
  //alert(description);
  detailsURL=Locations[ix][7];
  dateStart=Locations[ix][8];
  timeStart=Locations[ix][9];
  dateEnd=Locations[ix][10];
  timeEnd=Locations[ix][11];
  //description=Locations[ix][6];
  // http://maps.google.com/maps?&ll=35.962446,-77.817535
  var LatLonURL='';
  if (LocationsUseLatLon[ix]==false && LocationsPathPoints[ix]!='NOPOINT') {
  //if (lat!=null && LocationsUseLatLon[ix]==false) {
    LatLonURL='http://maps.google.com/maps?&ll='+lat+','+lon+'';
   } else {
    //var addressMap=address;
    //addressMap=address.replace(/ /g,'%20');
    //LatLonURL='http://maps.google.com/maps?&q='+addressMap;
    //LatLonURL='http://maps.google.com/maps?&q='+address;
    LatLonURL='http://maps.google.com/maps?f=q&hl=en&q='+address;
    //alert(LatLonURL);
  };
  LatLonURL=URLnoBlanks(LatLonURL);
  //alert(LatLonURL);
  //var LatLonIcon='LNPRidlûüýþw~ë';
  var LatLonText='i';
  var LatLonHTML='<a href='+LatLonURL+' target="_blank"><font face="webdings" style="{text-decoration: none;}">'+LatLonText+'</font></a>';

    if (LocationsPathPoints[ix]=='NOPOINT') {
      LatLonHTML=LatLonHTML+' '+'<font face="webdings" color="red" onClick="alert(\'No Map\')">x</font>'+'';
    };

  if (description==null) description="";
  //html="<div><b>"+name+"</b><br/>"+address+"<br/>Tel: "+tel+"<br/><a href='http://www.NicolaZordan.net' target='_blank'>www.NicolaZordan.net</a></div>";
  html="";
  if (detailsURL!=null && detailsURL.length>0) {
    //html+='<br/><a href="'+detailsURL+'" target="_blank">details</a>';
    html+='<a href="'+detailsURL+'" target="_blank">';
  };
  html+="<b>"+name+"</b>";
  if (detailsURL!=null && detailsURL.length>0) {
    //html+='<br/><a href="'+detailsURL+'" target="_blank">details</a>';
    html+='</a>';
  };

  if (dateStart!=null && dateStart.length>0) {
    html+=' '+dateStart;
  };
  if (timeStart!=null && timeStart.length>0) {
    html+=' '+timeStart;
  };
  if (dateEnd!=null && dateEnd.length>0) {
    html+=' - '+dateEnd;
  };
  if (timeEnd!=null && timeEnd.length>0) {
    html+=' '+timeEnd;
  };
  html+=" "+LatLonHTML;


  //html+="<br/>"+address;
  if (address!=null && address.length>0) {
    html+="<br/>"+address;
  };
  if (tel!=null && tel.length>0) {
    html+="<br/>Tel: "+tel;
  };
  if (description!=null && description.length>0) {
    html+="<br/>"+description;
  };
  //if (detailsURL!=null && detailsURL.length>0) {
  //  html+='<br/><a href="'+detailsURL+'" target="_blank">details</a>';
  //};
  if (Connections[ix]!=null) {
    html+='<br/>'+ConnectionDescriptionHTML(ix);
  };
  //html+="<div><b>"+name+"</b><br/>"+address+"<br/>Tel: "+tel+"<br/><a href='http://www.NicolaZordan.net' target='_blank'>www.NicolaZordan.net</a></div>";
  html+="";
  html="<small>"+html+"</small>";
  return html;
};


/*
// no xsl

function TripConnectionsXML(url,pathIn) {
  var connections=[];
  // load locations xsl

  var path=pathIn;
  if (path==null) path='';
// LOAD XML domains
  // Load XML 
  var xml=GetTripXML(url,pathIn);

  // build connection

  //var lXML=xml.getElementsByTagName('Connections/Connection');
  var lXML=xml.getElementsByTagName('Connection');

    // Connections[Connections.length]=[index, name, text, (url), (transportType), (company), (id), (dateStart), (timeStart), (dateEnd), (timeEnd), (duration), (description) ];
  var l,lts,lt,index, name, text, url, transportType, company,id, ds,ts,de,te, duration, description;
  for (i=0;i<lXML.length;i++) {
    l=lXML[i];
    index, name, text, url, transportType, company, ds,ts,de,te, duration, description;
    index=l.getAttribute('indexStartLocation');
    name=l.getAttribute('Name');
    text=getElementByTagName(l,'Address');
    url=getElementByTagName(l,'DetailsURL');
    lts=l.getElementsByTagName('Transportation');
    if (lts!=null && lts.length>0) {
      lt=lts[0];
      transportType=lt.getAttribute('transportType');
      company=lt.getAttribute('transportCompany');
      id=lt.getAttribute('transportID');
      ds=lt.getAttribute('dateStart');
      ts=lt.getAttribute('timeStart')
      de=lt.getAttribute('dateEnd');
      te=lt.getAttribute('timeEnd');
      duration=lt.getAttribute('duration');
      description=getElementByTagName(lt,'Description');
     } else {
      transportType='';
      company='';
      id='';
      ds='';
      ts='';
      de='';
      te='';
      duration='';
      description='';
    };
    connections[connections.length]=[index, name, text, url, transportType, company, id, ds,ts,de,te, duration, description];    
//alert(i+'. '+connections[connections.length-1]);
  }
  connections[connections.length]=null;    

  //alert('connections:'+connections.length)

  //connections=LocationsDescriptionFix(locations);
  Trip.Connections=connections;
  return Trip.Connections;
};

function TripTripXML(url,pathIn) {
  var path=pathIn;
  if (path==null) path='';
// LOAD XML domains
  // Load XML 
  var xml=GetTripXML(url,pathIn);

  var trip=[];
  var name,description,DetailsURL,ImageURL,ds,ts,de,te;
  var lXML=xml.getElementsByTagName('Trip');
  var l=lXML[0];
  name=l.getAttribute('Name');
  description=getElementByTagName(l,'Description');
  DetailsURL=getElementByTagName(l,'DetailsURL');
  ImageURL=getElementByTagName(l,'ImageURL');
  ds=l.getAttribute('dateStart');
  ts=l.getAttribute('timeStart')
  de=l.getAttribute('dateEnd');
  te=l.getAttribute('timeEnd');
  var trip=[name,description,DetailsURL,ImageURL,ds,ts,de,te];
  return trip;
};

function TripLocationsXML(url,pathIn) {
  var locations=[];
  // load locations xsl

  var path=pathIn;
  if (path==null) path='';
// LOAD XML domains
  // Load XML 
  var xml=GetTripXML(url,pathIn);

  // build locations

  //var lXML=xml.getElementsByTagName('Locations/Location');
  var lXML=xml.getElementsByTagName('Location');

    // Locations[Locations.length]=["id","name","address","tel",longitude,latitude, "<a href='http://www.NicolaZordan.net' target='_blank'>www.NicolaZordan.net</a> 12a", "detailsURL", dateStart, timeStart, dateEnd, timeEnd ];	
  var l,id,name,address,tel, lat,lon, desc, detUrl, ds,ts,de,te;
  for (i=0;i<lXML.length;i++) {
    l=lXML[i];
    id=l.getAttribute('index');
    name=l.getAttribute('Name');
    address=getElementByTagName(l,'Address');
    tel=getElementByTagName(l,'Tel');
    lat=l.getAttribute('latitude');
    lon=l.getAttribute('longitude');
    desc=getElementByTagName(l,'Notes');
    detUrl=getElementByTagName(l,'DetailsURL');
    ds=l.getAttribute('dateStart');
    ts=l.getAttribute('timeStart')
    de=l.getAttribute('dateEnd');
    te=l.getAttribute('timeEnd');

    locations[locations.length]=[id,name,address,tel, lat,lon, desc, detUrl, ds,ts,de,te];    
//alert(i+'. '+locations[locations.length-1]);
  }
  locations[locations.length]=null;    

  //alert('locations:'+locations.length)

  locations=LocationsDescriptionFix(locations);
  Trip.Locations=locations;
  return Trip.Locations;
};


function getElementByTagName(l,name) {
  var r='';
  var es=l.getElementsByTagName(name);
  if (es==null || es.length<1) return r;
  var e=es[0];
  r='';
  if (e.text != null) r=r+e.text;
  if (e.textContent != null) r=r+e.textContent;
//alert(r);
  return r;
};
*/


//-- /override

//-- override2

var MembersCountText='Team Members';
function TripDataHTML() {
  var html="";
  //if (Locations[ix]==null) return html;
  var id,name,text,html,url,imageURL,dateStart,timeStart,dateEnd,timeEnd, description;
  name=TripData[0];
  text=TripData[1];
  url=TripData[2];
  imageURL=TripData[3];
  dateStart=TripData[4];
  timeStart=TripData[5];
  dateEnd=TripData[6];
  timeEnd=TripData[7];
  description=TripData[8];
  if (description==null) description="";
  //html="<div><b>"+name+"</b><br/>"+address+"<br/>Tel: "+tel+"<br/><a href='http://www.NicolaZordan.net' target='_blank'>www.NicolaZordan.net</a></div>";
  html="";
  //html+="Trip: <b>"+name+"</b>";
  //html+="trip: ";

  if (url!=null && url.length>0) {
    //html+='<br/><a href="'+url+'" target="_blank">trip details</a>';
    html+='<a href="'+url+'" target="_blank">';
  };
  html+="<b>"+name+"</b>";
  if (url!=null && url.length>0) {
    html+='</a>';
  };
  html+='<br/>';
  if (dateStart!=null && dateStart.length>0) {
    html+=' '+dateStart;
  };
  if (timeStart!=null && timeStart.length>0) {
    html+=' '+timeStart;
  };
  if (dateEnd!=null && dateEnd.length>0) {
    html+=' - '+dateEnd;
  };
  if (timeEnd!=null && timeEnd.length>0) {
    html+=' '+timeEnd;
  };

  if (description!=null && description.length>0) {
    html+="<br/>"+description;
  };

  if (text!=null && text.length>0) {
    html+='<br/>'+text;
  };
  //if (url!=null && url.length>0) {
  //  html+='<br/><a href="'+url+'" target="_blank">trip details</a>';
  //};
  if (imageURL!=null && imageURL.length>0) {
    html+='<br/><img src="'+imageURL+'"/>';
  };


  // Team Leaders

//alert(ZoneName+'\n'+ZoneTeamLeadersIx.length+'\n'+ZoneTeamLeadersIx);
  if (ZoneTeamLeadersIx!=null && ZoneTeamLeadersIx.length>0) {
    html+="<ul>";
    html+="Team Leaders";
     html+=' <img src="TeamLeader.png" alt="Team Leader" />'
     //-html+=' <img src="marker-TeamLeader.gif" alt="Team Leader" />'

    html+='<br/>';
    html+='<br/>';
    for (var i=0;i<ZoneTeamLeadersIx.length;i++) {
      html+="<li>";
      //html+=LocationListHTML(ZoneTeamLeadersIx[i]+1,showExtra);
      //html+=LocationDescriptionHTML(ZoneTeamLeadersIx[i]);
      html+='<big><b>';
      html+='<a href="javascript:showLocationDetails('+ZoneTeamLeadersIx[i]+')">';
      html+=Locations[ZoneTeamLeadersIx[i]][1];
      html+='</a>';
      html+='</b></big>';
      //html+="<br/>";
      html+="</li>";
    };
    html+="</ul>";
  };

  // Meeting Places

//alert(ZoneName+'\n'+ZoneMeetingPlaces.length+'\n'+ZoneMeetingPlaces);
  if (ZoneMeetingPlaces!=null && ZoneMeetingPlaces.length>0) {
    html+="<ol>";
    html+="Meeting Places";
     html+=' <img src="MeetingPlace.png" alt="Meeting Place" />'
     //-html+=' <img src="marker-MeetingPlace.gif" alt="Meeting Place" />'
    html+='<br/>';
    html+='<br/>';
    for (var i=0;i<ZoneMeetingPlaces.length;i++) {
      html+="<li>";
      //html+=LocationListHTML(ZoneTeamLeadersIx[i]+1,showExtra);
      //html+=LocationDescriptionHTML(ZoneTeamLeadersIx[i]);
      html+='<big>';
      html+='<a href="javascript:showLocationDetails('+(Locations.length-ZoneMeetingPlaces.length+i)+')">';
      //-html+='<a href="javascript:showLocationDetails('+(Locations.length+i)+')">';
      //html+=Locations[ZoneTeamLeadersIx[i]][1];
      //html+=Locations[ZoneTeamLeadersIx[i]][1];
      html+=ZoneMeetingPlaces[i][0];
      html+='</a>';
      if (ZoneMeetingPlaces[i][1]!=null && ZoneMeetingPlaces[i][1]!='') {
        html+="<br/>";
        html+=ZoneMeetingPlaces[i][1];
      };
      html+='</big>';
      //html+="<br/>";
      html+="</li>";
    };
    html+="</ol>";
  };


  //html+="<div><b>"+name+"</b><br/>"+address+"<br/>Tel: "+tel+"<br/><a href='http://www.NicolaZordan.net' target='_blank'>www.NicolaZordan.net</a></div>";
  //html+=LocationsListHTML(true);
  html+='<ol>';
 if (ZonePageFlag==true) {
  //html+='Team Members'+' ('+(Locations.length-ZoneMeetingPlaces.length)+')';
  html+=MembersCountText+' ('+(Locations.length-ZoneMeetingPlaces.length)+')';
     html+=' <img src="Member.png" alt="Member" />'
     html+=' <img src="Radio.png" alt="Radio" />'
     //-html+=' <img src="marker-Member.gif" alt="Member" />'
     //-html+=' <img src="marker-Radio.gif" alt="Radio" />'
  //html+='<br/>';
  if (ZonesPageMailEmail!=null) {
    //var emailLink='mailto:'+ZonesPageMailEmail+'?subject='+ZonePageTitle+' '+ZoneName+' User Update&body=Name:%0d%0aZone: '+ZoneName+'%0d%0a%0d%0aChanges requested:%0d%0a';
    // %0d%0a = \n = crlf
    var emailLink='mailto:'+ZonesPageMailEmail+'?subject=User Update Request: '+ZoneName+': '+ZonePageTitle+'&body=Name: %0d%0aZone: '+ZoneName+'%0d%0a%0d%0aChanges requested:%0d%0a';
    html+='&nbsp; &nbsp; &nbsp;'+'(eMail '+'<a href="'+emailLink+'">'+ZonesPageMailEmail+'</a>'+' to change your data)';
  };
  html+='<br/>';
 };
  html+='<br/>';
  for (i=0;i<Locations.length-ZoneMeetingPlaces.length;i++) {
  //for (i=0;i<Locations.length;i++) {
    html+='<li>';
    html+='<big>';
    html+=LocationDescriptionHTML(i);
    html+='</big>';
    html+='</li>';
  };
  html+='</ol>';
  html+="";
  //html="<small>"+html+"</small>";
  return html;
};

function LocationListHTML0(ix,showExtra) {
  var bold=isTeamLeaderIx(ix);
  var html="";
  //if (Locations[ix]==null) return html;
  //html+="<a href='javascript: showLocationDetails(\""+ix+"\")'>"+Locations[ix][1]+"</a>";
  //html+="<a href='javascript: showLocationDetails("+ix+")'>"+Locations[ix][1]+"</a>";
  html+="<a href='javascript: showLocationDetails("+ix+")'>";
  if (bold) html+="<b>";
  html+=Locations[ix][1];
  if (bold) html+="</b>";
  html+="</a>";
  if (showExtra!=null && Locations[ix][7]!=null && Locations[ix][7].length>0) {
    html+='<br/><small><a href="'+Locations[ix][7]+'" target="_blank">details</a></small>'
  };
  if (showExtra!=null && Connections[ix]!=null) {
    html+='<br/>'+ConnectionDescriptionHTML(ix);
  };
  //html+="<br/>";
  return html;
};

var ZonePageTitle='CERT Zone:';
function LocationsListHTML (showExtra) {
        var title=ZonePageTitle;
        if (title!='') title=title+' ';
        title=title+ZoneName;
        document.title=title;
	var html="";
	// zoom back to trip
	html+="<center>";
	//html+='<input type="button" value="Show Trip" onClick="ZoomToTrip()" />';
	html+='<input type="button" value="Re-Zoom" onClick="ZoomToTrip()" />';
	html+="</center>";
	html+="<br/>";
	//
	html+="<ol>";
	for (var i=0;i<Locations.length;i++) {
  	  html+="<li>";
          if (i==Locations.length-ZoneMeetingPlaces.length-1+1)
            html+="<b>";
          html+=LocationListHTML(i,showExtra);
          if (i==Locations.length-ZoneMeetingPlaces.length-1+1)
            html+="</b>";
          //html+="<br/>";
          if (i==Locations.length-ZoneMeetingPlaces.length-1)
            html+="<br/><br/>";
	  html+="</li>";
        };
	html+="</ol>";

       if (ZonePageFlag) {
	html+="<center>";
        GetZoneRadiosTxt();
        if(ZoneRadiosTxt.length>0)
  	  html+='<a href="javascript:ShowRadiosMessage()"><font face="webdings" style="{text-decoration:none}">~ </font></a><a href="javascript:ShowRadiosWindow()">radios members list</a> <br/>';

	//html+=EMailsHTML('<font face="webdings" style="{text-decoration:none}">i </font>eMail members');
	html+=EMailsHTML('<font face="webdings" style="{text-decoration:none}">i </font>');
	html+='<a href="javascript:ShowEmailsWindow()">eMail members list</a>';

        html+='<br/><a href="javascript:MembersListRoster()" 0target="_blank">Members List</a>';
        html+='<br/><a href="Census.htm" target="_blank">Census Members List</a>';
        html+='<br/><a href="FRSRadioCheck.htm" target="_blank">FRS radio check</a>';
        html+='<br/><a href="ZoneDamageAssessment.htm" target="_blank">Damage Assessment</a>';
        html+='<br/><a href="VolunteerHours.htm" target="_blank">Volunteer Hours</a>';
        html+='<br/><a href="ZoneDisasterPlan.htm" target="_blank">Standard Disaster Plan</a>';

	html+="</center>";
       };

        //html='<small><small>'+html+'</small></small>';
        html='<small>'+html+'</small>';

	return html;
};


// - 

function LocationDescriptionHTML(ix) {
  var html="";
  //if (Locations[ix]==null) return html;
  var id,name,address,tel,html,lat,lon, description, detailsURL;
  id=Locations[ix][0];
  name=Locations[ix][1];
  address=Locations[ix][2];
  tel=Locations[ix][3];
  lon=Locations[ix][4];
  lat=Locations[ix][5];
  //alert(Locations[ix]+'\n'+lon+'\n'+lat);
  description=Locations[ix][6];
  //alert(description);
  detailsURL=Locations[ix][7];
  dateStart=Locations[ix][8];
  timeStart=Locations[ix][9];
  dateEnd=Locations[ix][10];
  timeEnd=Locations[ix][11];
  //description=Locations[ix][6];
  // http://maps.google.com/maps?&ll=35.962446,-77.817535
  var LatLonURL='';
  if (LocationsUseLatLon[ix]==false && LocationsPathPoints[ix]!='NOPOINT') {
  //if (lat!=null && LocationsUseLatLon[ix]==false) {
    LatLonURL='http://maps.google.com/maps?&ll='+lat+','+lon+'';
   } else {
    //var addressMap=address;
    //addressMap=address.replace(/ /g,'%20');
    //LatLonURL='http://maps.google.com/maps?&q='+addressMap;
    //LatLonURL='http://maps.google.com/maps?&q='+address;
    LatLonURL='http://maps.google.com/maps?f=q&hl=en&q='+address;
    //alert(LatLonURL);
  };
  LatLonURL=URLnoBlanks(LatLonURL);
  //alert(LatLonURL);
  //var LatLonIcon='LNPRidlûüýþw~ë';
  var LatLonText='i';
  var LatLonHTML='<a href='+LatLonURL+' target="_blank"><font face="webdings" style="{text-decoration: none;}">'+LatLonText+'</font></a>';

    if (LocationsPathPoints[ix]=='NOPOINT') {
      LatLonHTML=LatLonHTML+' '+'<font face="webdings" color="red" onClick="alert(\'No Map\')">x</font>'+'';
    };

  if (description==null) description="";
  //html="<div><b>"+name+"</b><br/>"+address+"<br/>Tel: "+tel+"<br/><a href='http://www.NicolaZordan.net' target='_blank'>www.NicolaZordan.net</a></div>";
  html="";
  if (detailsURL!=null && detailsURL.length>0) {
    //html+='<br/><a href="'+detailsURL+'" target="_blank">details</a>';
    html+='<a href="'+detailsURL+'" target="_blank">';
  };
  html+="<b>"+name+"</b>";
  if (detailsURL!=null && detailsURL.length>0) {
    //html+='<br/><a href="'+detailsURL+'" target="_blank">details</a>';
    html+='</a>';
  };

  if (dateStart!=null && dateStart.length>0) {
    html+=' '+dateStart;
  };
  if (timeStart!=null && timeStart.length>0) {
    html+=' '+timeStart;
  };
  if (dateEnd!=null && dateEnd.length>0) {
    html+=' - '+dateEnd;
  };
  if (timeEnd!=null && timeEnd.length>0) {
    html+=' '+timeEnd;
  };

  //if (ix<=Locations.length-ZoneMeetingPlaces.length-1) {
  //     html+=' <a href="javascript:VolunteerHours('+ix+')"><font face="webdings" style="text-decoration:none">`<!--hfpm])la`--></font></a> ';
  //};

  html+=" "+LatLonHTML;


  //html+="<br/>"+address;
  if (address!=null && address.length>0) {
    html+="<br/>"+address;
  };
  if (tel!=null && tel.length>0) {
    html+="<br/>Tel: "+tel;
  };
  if (description!=null && description.length>0) {
    html+="<br/>"+description;
  };
  //if (detailsURL!=null && detailsURL.length>0) {
  //  html+='<br/><a href="'+detailsURL+'" target="_blank">details</a>';
  //};
  if (Connections[ix]!=null) {
    html+='<br/>'+ConnectionDescriptionHTML(ix);
  };
  //html+="<div><b>"+name+"</b><br/>"+address+"<br/>Tel: "+tel+"<br/><a href='http://www.NicolaZordan.net' target='_blank'>www.NicolaZordan.net</a></div>";
  html+="";
  html="<small>"+html+"</small>";
  return html;
};

var VolunteerIx=0;
function VolunteerHours(memberIx) {
  VolunteerIx=memberIx;
  window.open('VolunteerHours.htm');
};


//-- /override2


