
//POI ..........................................................................................................
//..............................................................................................................
//..............................................................................................................
// function list:
//   Map_Data_POI( Ndx )
//   sort_Def_Handler( thisObject, thatObject) 
//   sort_Label_Handler( thisObject, thatObject)  
//   sort_poi_dtime() 
//   open_poi_win() 
//   sort_poi_ref() 
//   First_POI() 
//   POI_to_XML()
//   help_poi() 
//   POI_ON() 
//   POI_OFF() 
//   poi_location( latlng ) 
//   set_poi_del_opt( iMode, ndx ) 
//   sx_poi_opts_table() 
//   sx_table_POI() 
//   sx_row_ref( ndx ) 
//   sxTime( nsecs, ampm ) 
//   sxDateTime( ddate, nsecs, ampm ) 
//   sx_row_dtime( ndx ) 
//   sx_row_url( ndx ) 
//   sx_row_note( ndx ) 
//   sx_row_addr( ndx ) 
//   Show_POI_Disp_Ctrl( iCtrl )
//   Toggle_POI_Display(iCtrl) 
//   display_POI_Table() 
//   sx_Note_to_HTML( sText ) 
//   sx_info_table( ndx ) 
//   Sx_AMPM( AmPm ) 
//   save_poi_gx() 
//   openInfoWindow(ndx) 
//   save_poi() 
//   update_poi() 
//   edit_poi( ndx ) 
//   close_poi_info( ndx ) 
//   delete_poi_ndx( ndx ) 
//   delete_poi() 
//   close_poi() 
//   poi_add_marker( latlng ) 
//   poi_marker_listener( mmarker, ndx ){
//   Show_POI(){
//    
//..............................................................................................................

function Map_Data_POI( Ndx ){
    this.ndx         = Ndx;
    this.mmarker     = null;
    this.mopts       = null;
    this.mLxL        = null;
    this.poi_date    = '';
    this.nsecs       = -1;
    this.ampm        =  0;
    this.ref         = '';
    this.note        = '';
    this.addr        = '';
    this.label       = '';
    this.url_link    = '';
    this.url_ref     = '';
    this.sort_def    = '';
    this.mInfoWin    = null;
    this.mlistener   = null;
    this.marker_fx   = null;
    this.marker_name = null;
}

var nPOIs       =  0;
var Map_POI     = [];
var obj_Map_POI = null;

//.....................................................
function sort_Def_Handler( thisObject, thatObject) {//ok v3

    if( thisObject.sort_def > thatObject.sort_def ){
	    return 1;
    }else if( thisObject.sort_def < thatObject.sort_def ){
	   return -1;
    }

    return 0;
}
//.....................................................
function sort_Ref_Handler( thisObject, thatObject) {//ok v3

    if( thisObject.ref > thatObject.ref ){
	    return  1;
    }else if( thisObject.ref < thatObject.ref ){
	    return -1;
    }
    return 0;
}
//.....................................................
function sort_poi_dtime(){//ok v3

    if( Map_POI.length == 0 )return;

    var mmddyy = new Array();
    var mm = 0;
    var dd = 0;
    var yy = 0;

    for( var i=0; i<Map_POI.length; ++i ){

         Map_POI[i].sort_def = '';

         if( Map_POI[i].poi_date.length != 0 ){
             mmddyy   = Map_POI[i].poi_date.split('-');
             mm = mmddyy[0];
             dd = mmddyy[1];
             yy = mmddyy[2];
             var ddate = new Date (yy, mm , dd );

             d = Date.parse( ddate );

             if( isNaN(d) )d=0;

             d+= Map_POI[i].nsecs;
             Map_POI[i].sort_def = d;
         }
    }

    Map_POI.sort( sort_Def_Handler );
    display_POI_Table();
}
//.....................................................
function open_poi_win(){//ok v3

    alert('\nNot Yet Implemented.');

}
//.....................................................
function sort_poi_ref(){//ok v3

    if( Map_POI.length == 0 )return;
    Map_POI.sort( sort_Ref_Handler );
    display_POI_Table();
}
//.....................................................
function First_POI(){//ok v3

    if( Map_POI.length == 0 )return -1;

    for( var i=0; i<Map_POI.length; ++i ){

         if( Map_POI[i].ndx >= 0 ){
             return i;
             break;
         }
    }

    return -1;

}
//.....................................................
function POI_to_XML(){

    var sXML      = '';
    var sRef      = '';
    var sImage    = '';
    var sName     = '';
    var sNote     = '';
    var sLabel    = '';
    var sURL_Link = '';
    var sURL_Ref  = '';
    var sAddr     = '';
    var sDate     = '';
    var sSecs     = '';
    var sAMPM     = '';
    var latlng    = null;
    var lat       = null;
    var lng       = null;
    var ndx       = -1;
    
    var nPOI = Count_POI();
    if( nPOI == 0 )return sXML;

    sXML = '<?xml version="1.0" encoding="UTF-8"?>';
    sXML+= '<points_of_interest name="POI" >';

    for( var i=0; i<Map_POI.length; ++i ){

         if( Map_POI[i].ndx >= 0 ){

             sRef       = escape( Map_POI[i].ref        );
             sNote      = escape( Map_POI[i].note       );
             sURL_Link  = escape( Map_POI[i].url_link   );
             sURL_Ref   = escape( Map_POI[i].url_ref    );
             sAddr      = escape( Map_POI[i].addr       );
             sMarkImage = escape( Map_POI[i].marker_fx  );
             sMarkName  = escape( Map_POI[i].marker_name);

             sSecs      = ''+Map_POI[i].nsecs;
             sAMPM      = ''+Map_POI[i].ampm;
             sDate      = escape( Map_POI[i].poi_date );
             sSecs      = escape( sSecs  );
             sAMPM      = escape( sAMPM  );
             
             latlng     = Map_POI[i].mmarker.getPosition();

             //  lat = Map_POI[i].mLxL.lat();
             //  lng = Map_POI[i].mLxL.lng();
                 lat = latlng.lat();
                 lng = latlng.lng();
                 ndx = Map_POI[i].ndx;

             sXML+= '<POI id="' +ndx+ '" >';

             sXML+= '    <lat>'      + lat       + '</lat>';
             sXML+= '    <lng>'      + lng       + '</lng>';
             sXML+= '    <ref>'      + sRef      + '</ref>';
             sXML+= '    <poi_date>' + sDate     + '</poi_date>';
             sXML+= '    <poi_time>' + sSecs     + '</poi_time>';
             sXML+= '    <poi_ampm>' + sAMPM     + '</poi_ampm>';
             sXML+= '    <note>'     + sNote     + '</note>';
             sXML+= '    <url_link>' + sURL_Link + '</url_link>';
             sXML+= '    <url_ref>'  + sURL_Ref  + '</url_ref>';
             sXML+= '    <addr>'     + sAddr     + '</addr>';
             sXML+= '    <mark_fx>'  + sMarkImage+ '</mark_fx>';
             sXML+= '    <mark_name>'+ sMarkName + '</mark_name>';

             sXML+= '</POI>'
         }
    }
    sXML+= '</points_of_interest>';

    return sXML;
}
//.....................................................
function help_poi(){//ok v3

    arg = 'UG_POI.html';
    if ( help_win && !help_win.closed){ help_win.close() }
    help_win = window.open( arg, 'help_win', 'menubar=yes,scrollbars=yes,resizable=yes,width=750, height=575' );
    
}
//.....................................................
function about_poi(){//ok v3

    arg = 'UG_POI.html';
    if ( help_win && !help_win.closed){ help_win.close() }
    help_win = window.open( arg, 'help_win', 'menubar=yes,scrollbars=yes,resizable=yes,width=750, height=575' );
    
}
//.....................................................
function POI_ON(){//ok v3
    
    if( b_Private_User == 0 ){//Do not Display this Alert for Registered Users 
        if( Route_ID != 0 && b_POI_Warning == 0 && bb_Save_OK == 0 ){
            var msg =   '\nNote: This is an Already Existing Route / POI / Itinerary.';
                msg+= '\n\nYou can add "Points of Interest" (POI) to the display but they will not be Saved.';
                msg+= '\n\nClick "New Map" to start fresh if you would like to save your own POIs.';
                msg+= '\n\nSign up for your own account - Existing routes can be modified by the owner of the account.';
            alert(msg);
            b_POI_Warning = 1;
        }
    }
    
    spot_info_off();
    map_router( 3 );// Turn ON Point of Interest Clicking

    var out = '<a href="javascript:POI_OFF();" title="Turn Point of Interest OFF"><img src="../map_markers/mm_20_blue.png" width="12" height="20" border="0" ></a>';
    document.getElementById("poi_span" ).innerHTML = out;
}
//.....................................................
function POI_OFF(){ //v3

    map_router( 0 );// Turn "Point of Interest" Off
    close_poi();

    var out = '<a href="javascript:POI_ON();" title="Create Point of Interest Markers"><img src="../icons/map_a.gif" width="16" height="16" border="0"></a>';
    document.getElementById("poi_span" ).innerHTML = out;
}
//.....................................................
function poi_latxlng( lat, lng ){//ok v3  Called from "Jump to Location" or Spot Clicks

    var latlng = new google.maps.LatLng( lat, lng );
    poi_location( latlng );
}
//.....................................................
function show_POI_geocode( results, status ) { //v3

    var state   = '';
    var city    = '';
    var addr    = '';
    var country = '';
        
    if (! results) {
      alert("Google Maps did not return a valid response");
      addr= 'No Location info for the spot you clicked.';
      document.getElementById("spot_address" ).innerHTML = addr;
      return;
    } 
    
    if (status != google.maps.GeocoderStatus.OK) { 
        alert("Google Maps  did not return a valid response");
        addr= 'No Location info for the spot you clicked.';
        document.getElementById("spot_address" ).innerHTML = addr;
    } 
           
    var latlng = results[0].geometry.location;
    geoCode = adx_geocode( results );
    
    var addr = geoCode[9];
        
    document.Map_Form.POI_Reference.value = addr;
    document.Map_Form.POI_Address.value   = addr;
    document.Map_Form.POI_Content.value   = '';

    document.Map_Form.POI_Date.value      = '';
    document.Map_Form.POI_Hour.value      = '';
    document.Map_Form.POI_Min.value       = '';
    document.Map_Form.POI_AmPm[2].checked = true;

    var ndx = Map_POI.length;

    document.Map_Form.POI_Content.value = '';
    document.Map_Form.POI_Ndx.value     = -1;

    //var latxlng = '(' +latlng.lat()+', '+latlng.lng()+')';
    //document.getElementById("poi_lat_lng" ).innerHTML = latxlng;
}

//-------------------------------------------------------
function poi_image_tag( marker_fx ){//ok v3

    var image_path = URL_markers+marker_fx;
    var image_tag  = '<img src="' +image_path +'" border="0"/>';
    
    return image_tag;
}
//-------------------------------------------------------
function sx_poi_marker( marker_fx, marker_name ){//ok v3

// Sets the marker selected by user

    if( poi_marker != null ) pt_marker_disp_v3( 0, poi_marker );

    var image_path = URL_markers  + marker_fx;
    var image_tag  = poi_image_tag( marker_fx );

    document.getElementById("poi_marker_image" ).innerHTML = image_tag;
    document.getElementById("poi_marker_name"  ).innerHTML = marker_name;

    var lat = document.Map_Form.POI_Lat.value;
    var lng = document.Map_Form.POI_Lng.value;
    var ndx = document.Map_Form.POI_Ndx.value;

    document.Map_Form.POI_fx.value    = marker_fx;
    document.Map_Form.POI_mname.value = marker_name;

    //alert('ndx = '+ndx );

    if( ndx == -1 ){
        var latlng = new google.maps.LatLng( lat, lng );
        poi_marker = new google.maps.Marker({
            map:      map,
            position: latlng,
            icon:     image_path,
            visible:  true
        });

        remove_jump_marker();
        pt_marker_disp_v3( 1, poi_marker, latlng );

    }else{
        var mmarker = Map_POI[ndx].mmarker;
        mmarker.setIcon(image_path);
    }

}
//-------------------------------------------------------
function poi_location( latlng ){ //v3

    onClicks();
    add_jump_marker( latlng );

    var request = { 'latLng': latlng } 
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode( request, show_POI_geocode );    
    
    document.Map_Form.POI_Ndx.value = -1;
    document.Map_Form.POI_Lat.value = latlng.lat();
    document.Map_Form.POI_Lng.value = latlng.lng(); 
    
    document.Map_Form.POI_fx_orig   .value = '';        
    document.Map_Form.POI_fx        .value = '';        
    document.Map_Form.POI_mname     .value = ''; 

    document.getElementById("poi_marker_image" ).innerHTML = '';
    document.getElementById("poi_marker_name"  ).innerHTML = 'No marker yet selected: choose one from above.';
    
    set_poi_del_opt( 0, -1 );
    ShowDiv_POI();

}
//-------------------------------------------------------
function set_poi_del_opt( iMode, ndx ){//ok v3

      var del_opt = '';
      var del_cap = '';

      if( iMode == 1 ){
          del_cap = 'Delete';
          del_opt = '<a href="javascript:delete_poi();"><img src="../icons/del_16.gif" width="16" height="16" border="0" /></a>';
      }

      document.getElementById("poi_delete_cap" ).innerHTML = del_cap;
      document.getElementById("poi_delete_opt" ).innerHTML = del_opt;
}
//-------------------------------------------------------
function sx_poi_opts_table(){//ok v3
    var tbl = '';
    tbl = '<table border="0" cellspacing="0" cellpadding="0">';
    tbl+= '      <tr>';
    tbl+= '        <td><a href="javascript:Toggle_POI_Display(0);" title="HIDE Points of Interest Sidebar"><img src="../icons/close_16.gif" width="16" height="16" border="0" /></a></td>';
    tbl+= '        <td><img src="../icons/spacer.gif" width="8" height="5"></td>';
    tbl+= '        <td><a href="javascript:about_poi();" title="About Points of Interest"><img src="../icons/about_16.gif" width="16" height="16" border="0" /></a></td>';
    tbl+= '        <td><img src="../icons/spacer.gif" width="8" height="5"></td>';
    tbl+= '        <td><a href="javascript:sort_poi_dtime();" title="Sort List by Date Time"><img src="../icons/sort_by_date_16.gif" width="16" height="16" border="0" /></a></td>';
    tbl+= '        <td><img src="../icons/spacer.gif" width="8" height="5"></td>';
    tbl+= '        <td><a href="javascript:sort_poi_ref();" title="Sort List by Reference"><img src="../icons/sort_by_name_16.gif" width="16" height="16" border="0" /></a></td>';
    tbl+= '        <td><img src="../icons/spacer.gif" width="8" height="5"></td>';
    tbl+= '        <td><a href="javascript:open_poi_win();" title="Open Itineray in New Window"><img src="../icons/opnbr_16.gif" width="16" height="16" border="0" /></a></td>';
if( nPoints != 0 ){
    tbl+= '        <td><img src="../icons/spacer.gif" width="8" height="5"></td>';
    tbl+= '        <td><img src="../icons/spacer.gif" width="8" height="5"></td>';
    tbl+= '        <td><a href="javascript:dir_display_on();" title="Display Directions in Sidebar"><img src="../icons/notep_16.gif" width="16" height="16" border="0"></a></td>';
}
    tbl+= '      </tr>';
    tbl+= '    </table>';
    return tbl;
}
//-------------------------------------------------------
function Count_POI(){//ok v3
    
    var nPOI = 0;
    
    for( var i=0; i<Map_POI.length; ++i ){
         if( Map_POI[i].ndx >= 0 )++nPOI;
    }
    return nPOI;
}
//-------------------------------------------------------
function sx_table_POI(){//ok v3
    
    var nPOI = Count_POI();
    
    var tbl = '';
    tbl = '<table width="300" border="0" cellspacing="0" cellpadding="1">';
    tbl+= '  <tr>';
    tbl+= '    <td colspan="2">';
    tbl+=      sx_poi_opts_table();
    tbl+= '    </td>';
    tbl+= '  </tr>';
    tbl+= '  <tr>';
    tbl+= '    <td  colspan="2" width="299" class="poi_heading" >&nbsp;Itinerary&nbsp;&amp;&nbsp;Points of Interest:&nbsp;'+nPOI+'</td>';
    tbl+= '  </tr>';
    tbl+= '  <tr>';
    tbl+= '    <td colspan="2"><hr size="1" /></td>';
    tbl+= '</tr>';

    return tbl;
}
//-------------------------------------------------------
function sx_row_ref( ndx ){//ok v3
  var row_poi = '';
  row_poi = '<tr>';
  row_poi+= '  <td width="1%" valign="top" align="center"><a title="Edit Point of Interest Details" href="javascript:edit_poi('  +ndx+  ');"><img src="../icons/edit_16.gif" width="16" height="16" border="0" /></a></td>';
  row_poi+= '  <td bgcolor="#EEEEFF">' +Map_POI[ndx].ref+'</td>';
  row_poi+= '</tr>';
  return row_poi;
} 
//-------------------------------------------------------
function sxTime( nsecs, ampm ){//ok v3


    var time_obj = new time_hms_clock( nsecs, ampm );
    var stime = time_obj.sHour +':'+ time_obj.sMin;

    if( ampm == 0 )stime+= ' MIL';
    if( ampm == 1 )stime+= ' AM';
    if( ampm == 2 )stime+= ' PM';

    //alert('nsecs ='+nsecs );
    //alert('ampm ='+ampm );
    //alert('stime >'+stime );

    return stime;
}
//-------------------------------------------------------
function sxDateTime( ddate, nsecs, ampm ){//ok v3

  if( ddate.length == 0 && nsecs == -1 )return '';

  var sdtime = '';
  var stime  = '';
  var sdate  = '';

  if( nsecs > -1 ){
      stime = sxTime( nsecs, ampm );
  }else{
      stime = '';
  }

  if( ddate.length != 0 ){
      if( stime.length != 0 )sdtime = ddate +'&nbsp;|&nbsp;'+ stime;
      else                   sdtime = ddate;
  }else{
      if( stime.length != 0 )sdtime = stime;
  }

  return sdtime;
}
//-------------------------------------------------------
function sx_row_dtime( ndx ){//ok v3

  if( Map_POI[ndx].poi_date.length == 0 && Map_POI[ndx].nsecs == -1 )return '';

  var sdtime = sxDateTime( Map_POI[ndx].poi_date, Map_POI[ndx].nsecs, Map_POI[ndx].ampm );

  var row_poi = '';
  row_poi = '<tr>';
  row_poi+= '  <td width="1%" valign="top"><a title="Edit Point of Interest Details" href="javascript:edit_poi('  +ndx+  ');"><img src="../icons/alarm_16.gif" width="16" height="16" border="0" /></a></td>';
  row_poi+= '  <td>'+sdtime+'</td>';
  row_poi+= '</tr>';
  return row_poi;
}
//-------------------------------------------------------
function sx_row_url( ndx ){//ok v3

	var sURL    = '';
	var sREF    = '';
	var row_poi = '';

	sURL = Map_POI[ndx].url_link;
	sREF = Map_POI[ndx].url_ref;

	if( sURL.length == 0 )return row_poi;
	if( sREF.length == 0 )sREF = sURL;

	row_poi+= '<tr>';
	row_poi+= '  <td width="1%" ><a href="'+sURL+'" target="_blank" title="Click to visit Link"><img src="../icons/opnbr_16.gif" width="16" height="16" border="0"></a></td>';
	row_poi+= '  <td width="99%" align="left"><a href="'+sURL+'" target="_blank" title="Click to visit Link">'+sREF+'</a></td>';
	row_poi+= '</tr>';

	return row_poi;
}
//.....................................................
function sx_row_note( ndx ){//ok v3

  var sInfo = sx_Note_to_HTML( Map_POI[ndx].note );
  var row_poi = '';

  row_poi = '<tr>';
  row_poi+= '  <td colspan="2">'+sInfo+'</td>';
  row_poi+= '</tr>';
  return row_poi;
}
//.....................................................
function sx_row_addr( ndx ){//ok v3


  var fx_icon   = URL_markers + Map_POI[ndx].marker_fx;
  var image_src = '<img src="' +fx_icon+ '" border="0">';

  var sURL = 'javascript:openInfoWindow('+ndx+')';
  var row_poi = '';
  row_poi+= '<tr>';
  row_poi+= '  <td colspan="2" class="testelement" ><div class="testelement"></div></td>';
  row_poi+= '</tr>';
  row_poi = '<tr>';
  row_poi+= '  <td width="1%" valign="top" align="center"><a href="'+sURL+'" title="Point to this marker on the map">';
  row_poi+= image_src+'</a></td>';
  row_poi+= '  <td colspan="2" class="poi_location">Location:&nbsp;'+Map_POI[ndx].addr+'</td>';
  row_poi+= '</tr>';
  row_poi+= '<tr>';
  row_poi+= '  <td colspan="2"><hr size="1" /></td>';
  row_poi+= '</tr>';
  return row_poi;
}
//.....................................................
function Show_POI_Disp_Ctrl( iCtrl ){//ok v3

// iCtrl == 0  Display Control to "BLANK" - No POI to Display
// iCtrl == 1  Display Control to "SHOW POI Sidebar"
// iCtrl == 2  Display Control to "HIDE POI Sidebar"

    if( iCtrl == 0 ){
        out = '';
    }

    if( iCtrl == 1 ){
        if( b_Private_User == 1 )out = '<a href="javascript:Toggle_POI_Display(1);" title="SHOW Sidebar: Points of Interest ">POI</a>';
        else                     out = '<a href="javascript:Toggle_POI_Display(1);" title="SHOW Sidebar: Points of Interest ">POI Sidebar</a>';
    }
    if( iCtrl == 2 ){
        out = '';
    }

    document.getElementById("POI_Show_Table" ).innerHTML = out;

}
//.....................................................
function Toggle_POI_Display(iCtrl){//ok v3
        
        b_POI_Displayed = 1 - b_POI_Displayed;
        
        
	if( b_POI_Displayed == 1 ){
	    b_POI_Displayed = 1;
	    b_DIR_Displayed = 0;
	    display_POI_Table();
	  //Show_POI_Disp_Ctrl( 2 );
	}else{
	    b_POI_Displayed = 0;
	  //Show_POI_Disp_Ctrl( 1 );
	    document.getElementById("POI_Table_ID").innerHTML = '<img src="../icons/spacer.gif" width="1" height="1">';
	}
		
        ////route_load_msg( b_POI_Displayed );
        
        resize();

}
//.....................................................
function Toggle_POI(){//ok v3
        
        if( b_POI_Displayed == 1 )Toggle_POI_Display(0);
        else                      Toggle_POI_Display(1);

}
//.....................................................
function display_POI_Table(){//ok v3
    
   
    if( b_POI_Displayed == 0 ){
        //Show_POI_Disp_Ctrl( 1 );
        return;
    }
    
    b_DIR_Displayed = 0;
    //Show_POI_Disp_Ctrl( 2 );

    var IO   = '';
    var xIO   = '';

    IO += sx_table_POI();

    for( var i=0; i<Map_POI.length; ++i ){

         if( Map_POI[i].ndx >= 0 ){

             IO += sx_row_ref( i );
             IO += sx_row_url( i );
             IO += sx_row_dtime( i );
             IO += sx_row_note( i );
             IO += sx_row_addr( i );
         }
    }
    IO += '</table>';

  //document.getElementById("POI_Table_ID").innerHTML = '<div class="scroll">'+IO+'</div>';
    document.getElementById("POI_Table_ID").innerHTML = IO;
}
//-------------------------------------------------------
function sx_Note_to_HTML( sText ){//ok v3

	var sHTML = '';
	var chr   = '';

	for( var i=0; i<sText.length; ++i ){
	     chr = sText.charAt(i);
	     if( chr.charCodeAt(0) == 10 )sHTML += '<br>';
	     else sHTML += chr;
    }

    return sHTML;
}
//-------------------------------------------------------
function sx_info_table( ndx ){//ok v3

	var sTable = new String('');

	var sURL = Map_POI[ndx].url_link;
	var sREF = Map_POI[ndx].url_ref;

	if( sURL.length != 0 ){
	    if( sREF.length == 0 )sREF = sURL;
	}


sTable = '<table width="250" border="0" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" >';
sTable+= '<tr>';
sTable+= '  <td width="1" colspan="2"><table border="0" cellspacing="0" cellpadding="0">';
sTable+= '    <tr>';
sTable+= '      <td><a title="Edit P.O.I. Details" href="javascript:edit_poi('  +ndx+  ');"><img src="../icons/edit_16.gif" width="16" height="16" border="0" /></a></td>';
sTable+= '      <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>';
sTable+= '      <td><a title="Delete this P.O.I." href="javascript:delete_poi_ndx('  +ndx+  ');"><img src="../icons/del_16.gif" width="16" height="16" border="0" /></a></td>';
sTable+= '      <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>';
sTable+= '      <td><a title="Close Window" href="javascript:close_poi_info('  +ndx+  ');"><img src="../icons/close_16.gif" width="16" height="16" border="0" /></a></td>';
sTable+= '    </tr>';
sTable+= '  </table></td>';
sTable+= '</tr>';
sTable+= '<tr>';
sTable+= '<td colspan="2" bgcolor="#EEEEFF">'+Map_POI[ndx].ref+'</td>';
sTable+= '</tr>';

if( sURL.length != 0 ){
sTable+= '<tr>';
sTable+= '  <td width="1%" valign="top"><a href="'+sURL+'" target="_blank" title="Click to visit Link"><img src="../icons/opnbr_16.gif" width="16" height="16" border="0"></a></td>';
sTable+= '  <td width="99%" align="left"><a href="'+sURL+'" target="_blank" title="Click to visit Link">'+sREF+'</a></td>';
sTable+= '</tr>';
}

sTable += sx_row_dtime( ndx );

var sInfo = sx_Note_to_HTML( Map_POI[ndx].note );

sTable+= '<tr>';
sTable+= '<td colspan="2">'+sInfo+'</td>';
sTable+= '</tr>';
sTable+= '<tr>';
sTable+= '<td colspan="2" bgcolor="#FDE2BB">Location:&nbsp;'+Map_POI[ndx].addr+'</td>';
sTable+= '</tr>';
sTable+= '</table>';

	return sTable;
}
//.....................................................
function Sx_AMPM( AmPm ){//ok v3

    var iAMPM = 0;
    if( AmPm[0].checked )iAMPM = 1;
    if( AmPm[1].checked )iAMPM = 2;

    return iAMPM;
}
//.....................................................
function save_poi_gx(){ //v3

    var ndx = Map_POI.length;
    
    pt_marker_disp_v3( 0, poi_marker );
    
    remove_jump_marker();

    var lat          = document.Map_Form.POI_Lat.value;
    var lng          = document.Map_Form.POI_Lng.value;

    var latlng = new google.maps.LatLng( lat, lng );
    
    var sRef   = document.Map_Form.POI_Reference.value;
    var ddate  = document.Map_Form.POI_Date.value;
    var iampm  = Sx_AMPM( document.Map_Form.POI_AmPm );
    var nsecs  = To_Seconds( document.Map_Form.POI_Hour, document.Map_Form.POI_Min, iampm );
  
    var mmarker_icon = URL_markers+document.Map_Form.POI_fx.value;
    var marker_name  = ''+document.Map_Form.POI_mname.value;
    var sRef         =    document.Map_Form.POI_Reference.value;
    
    if( sRef.length == 0 )sRef = marker_name;

    var mmarker = new google.maps.Marker({
               map: map,
              icon: mmarker_icon,
             title: sRef,
          position: latlng,
         draggable: true,
           visible: true
    });

    var ndx = Map_POI.length;
    obj_Map_POI = new Map_Data_POI( ndx );
    

    obj_Map_POI.mopts    = null;                                 
    obj_Map_POI.mmarker  = mmarker;                              
    obj_Map_POI.mLxL     = latlng;                                
  
    obj_Map_POI.ref      = sRef;
    obj_Map_POI.note     = document.Map_Form.POI_Content.value;
    obj_Map_POI.addr     = document.Map_Form.POI_Address.value;  
    obj_Map_POI.url_link = document.Map_Form.POI_URL_Link.value;  
    obj_Map_POI.url_ref  = document.Map_Form.POI_URL_Ref.value;  
    obj_Map_POI.label    = ''; //No Longer Used                              

    obj_Map_POI.poi_date = ddate;                                
    obj_Map_POI.ampm     = iampm;                                
    obj_Map_POI.nsecs    = nsecs;          
    
    obj_Map_POI.marker_fx   = document.Map_Form.POI_fx.value;
    obj_Map_POI.marker_name = document.Map_Form.POI_mname.value;  
    
    document.Map_Form.POI_fx_orig.value    = document.Map_Form.POI_fx.value;                    

    mmarker.ndx = ndx;
    
    var mInfoWin = new google.maps.InfoWindow();
    obj_Map_POI.mInfoWin = mInfoWin;

    obj_Map_POI.mlistener = google.maps.event.addListener( mmarker, "click", function(){
         var mndx   = mmarker.ndx;
         poi_info_wins_Off(mndx);
         var sTable = sx_info_table( mndx );         
         mInfoWin.setContent( sTable );
         mInfoWin.open( map, mmarker );
    });
    
    Map_POI.push( obj_Map_POI );
    
    close_poi();

    if( Map_POI.length == 1 )b_POI_Displayed = 1;

    display_POI_Table();

}
//-------------------------------------------------------
function poi_info_wins_Off(ndx ){

    if( Map_POI.length == 0 )return;
    
    for( var i=0; i<Map_POI.length; ++i ){
        if( i != ndx )Map_POI[i].mInfoWin.close();
    }
}
//-------------------------------------------------------
function openInfoWindow( ndx ){//ok v3

    poi_info_wins_Off(ndx);
    
    var sTable   = sx_info_table( ndx );                   
    var mInfoWin = Map_POI[ndx].mInfoWin;    
    var mmarker  = Map_POI[ndx].mmarker;
    
    var bounds   = map.getBounds();
    var latlng   = mmarker.getPosition();

    if( !bounds.contains(latlng) ){
        map.setCenter( latlng );
    }
    
    mInfoWin.setContent( sTable );
    mInfoWin.open( map, mmarker );

}
//-------------------------------------------------------
function save_poi(){//ok v3

    var ndx       = document.Map_Form.POI_Ndx.value;
    var marker_fx = document.Map_Form.POI_fx.value;
    
    if( marker_fx.length == 0 ){
        alert('Please select a marker for this Point of Interest.');
        return;
    }
    	
    if( ndx == -1 )save_poi_gx();
    else           update_poi();
        
    mapping_state( 3 );

}
//-------------------------------------------------------
function update_poi(){//ok v3

    pt_marker_disp_v3( 0, poi_marker );
    
    var ndx = document.Map_Form.POI_Ndx.value;

    Map_POI[ndx].note     = document.Map_Form.POI_Content.value;
    Map_POI[ndx].ref      = document.Map_Form.POI_Reference.value;
    Map_POI[ndx].addr     = document.Map_Form.POI_Address.value;
    Map_POI[ndx].url_link = document.Map_Form.POI_URL_Link.value;
    Map_POI[ndx].url_ref  = document.Map_Form.POI_URL_Ref.value;  
    Map_POI[ndx].label    = ''; //No Longer Used  

    Map_POI[ndx].poi_date = document.Map_Form.POI_Date.value;
    Map_POI[ndx].ampm     = Sx_AMPM( document.Map_Form.POI_AmPm );
    Map_POI[ndx].nsecs    = To_Seconds( document.Map_Form.POI_Hour, document.Map_Form.POI_Min, Map_POI[ndx].ampm );

    var mmarker       = Map_POI[ndx].mmarker;
    var marker_fx_Old = Map_POI[ndx].marker_fx;
    var marker_fx_New = document.Map_Form.POI_fx.value;
        
    if( marker_fx_New != marker_fx_Old ){ 
        var image_path = URL_markers  + marker_fx_New;
        mmarker.setIcon(image_path);
        Map_POI[ndx].marker_fx   = marker_fx_New;
        Map_POI[ndx].marker_name = document.Map_Form.POI_mname.value;
        
        document.Map_Form.POI_fx_orig   .value = marker_fx_New;              
    }
    
    var sRef = Map_POI[ndx].ref;
    if( sRef.length == 0 )var sTitle = Map_POI[ndx].marker_name;
    else                  var sTitle = sRef;
    
    mmarker.setTitle(sTitle);
    
    close_poi();
    display_POI_Table();

}
//-------------------------------------------------------
function edit_poi( ndx ){ //v3

    document.Map_Form.POI_Date.value       = Map_POI[ndx].poi_date;
    document.Map_Form.POI_Address.value    = Map_POI[ndx].addr;
    document.Map_Form.POI_Content.value    = Map_POI[ndx].note;
    document.Map_Form.POI_Reference.value  = Map_POI[ndx].ref;
    document.Map_Form.POI_URL_Link.value   = Map_POI[ndx].url_link;
    document.Map_Form.POI_URL_Ref.value    = Map_POI[ndx].url_ref;
    document.Map_Form.POI_fx.value         = Map_POI[ndx].marker_fx;   
    document.Map_Form.POI_fx_orig.value    = Map_POI[ndx].marker_fx;
    document.Map_Form.POI_mname.value      = Map_POI[ndx].marker_name; 

    if( Map_POI[ndx].ampm == 1 )document.Map_Form.POI_AmPm[0].checked = true;
    if( Map_POI[ndx].ampm == 2 )document.Map_Form.POI_AmPm[1].checked = true;
    if( Map_POI[ndx].ampm == 0 )document.Map_Form.POI_AmPm[2].checked = true;

    if( Map_POI[ndx].nsecs == -1 ){
        document.Map_Form.POI_Hour.value = '';
        document.Map_Form.POI_Min.value  = '';
    }else{
        var time_obj = new time_hms_clock( Map_POI[ndx].nsecs, Map_POI[ndx].ampm );
        document.Map_Form.POI_Hour.value = time_obj.sHour;
        document.Map_Form.POI_Min.value  = time_obj.sMin;
    }

    var latlng = Map_POI[ndx].mmarker.getPosition();
    document.Map_Form.POI_Lat.value = latlng.lat();
    document.Map_Form.POI_Lng.value = latlng.lng();
    document.Map_Form.POI_Ndx.value = ndx;
    
    var marker_fx   = document.Map_Form.POI_fx.value;
    var marker_name = document.Map_Form.POI_mname.value;
    var image_tag   = poi_image_tag( marker_fx );

    document.getElementById("poi_marker_image" ).innerHTML = image_tag;
    document.getElementById("poi_marker_name"  ).innerHTML = marker_name;
    
    //var latxlng = '(' +latlng.lat()+ ', '+ latlng.lng()+')';
    //document.getElementById("poi_lat_lng" ).innerHTML = latxlng;

    Map_POI[ndx].mInfoWin.close();

    set_poi_del_opt(1, ndx);
    ShowDiv_POI();

}
//-------------------------------------------------------
function close_poi_info( ndx ){ //v3

   Map_POI[ndx].mInfoWin.close();

}
//-------------------------------------------------------
function delete_poi_ndx( ndx ){ //v3

    var msg ='\nDelete this "Point of Interest" ?';
    
    if( confirm(msg) ){ 
        
        var mmarker = Map_POI[ndx].mmarker; 
        mmarker.setVisible( false );
        
        Map_POI[ndx].mInfoWin.close(); 
        
        //if( Map_POI[ndx].mlistener != null ){
        //    google.maps.event.removeListener( Map_POI[ndx].mlistener );
        //}

        //delete Map_POI[ndx].mmarker;
        //delete Map_POI[ndx].mlistener;
        //Map_POI[ndx].mlistener = null;        
        //Map_POI[ndx].mmarker   = null;
        //Map_POI[ndx].mInfoWin  = null;
        
        Map_POI[ndx].ndx = -1;
        display_POI_Table();
                
        if( iState == 3 )mapping_state( 3 );
    }

    CloseDiv_POI();

}
//-------------------------------------------------------
function delete_poi(){ //v3  This module is called from the Div: POI_Edit_Template.cfm

    var ndx = document.Map_Form.POI_Ndx.value;
    if( ndx == -1 )return;
    
    delete_poi_ndx( ndx );

}
//-------------------------------------------------------
function ShowDiv_POI(){//ok v3

    document.getElementById("edit_poi_div").style.left = 95;
}
//------------------------ 
function CloseDiv_POI(){//ok v3

    document.getElementById("edit_poi_div").style.left = -1000;
}
//-------------------------------------------------------
function close_poi(){//v3
 
    var ndx = document.Map_Form.POI_Ndx.value; 
    
    document.Map_Form.POI_Address.value   = ''; 
    document.Map_Form.POI_Content.value   = ''; 
    document.Map_Form.POI_Reference.value = ''; 
    document.Map_Form.POI_URL_Link.value  = ''; 
    document.Map_Form.POI_URL_Ref.value   = ''; 
    document.Map_Form.POI_Ndx.value       = -1; 
    document.Map_Form.POI_Lat.value       =  0; 
    document.Map_Form.POI_Lng.value       =  0; 
    
    if( ndx != -1 ){
    
        var marker_fx_orig = document.Map_Form.POI_fx_orig.value;
        var marker_fx      = document.Map_Form.POI_fx.value;
            
        if( marker_fx_orig != marker_fx ){
            var mmarker    = Map_POI[ndx].mmarker; 
            var image_path = URL_markers  + marker_fx_orig;
                                
            mmarker.setIcon(image_path);
            mmarker.setTitle(Map_POI[ndx].ref);
            
            Map_POI[ndx].marker_fx   = marker_fx_orig;   
            
            document.Map_Form.POI_fx   .value = Map_POI[ndx].marker_fx
            document.Map_Form.POI_mname.value = Map_POI[ndx].marker_name;
            
        }
    }
    
    if( poi_marker != null ) pt_marker_disp_v3( 0, poi_marker );
    remove_jump_marker(); 
    CloseDiv_POI();  

}
//-------------------------------------------------------
function poi_add_marker( latlng ){//ok v3

  close_poi();

  remove_jump_marker();
  poi_location( latlng );

}
//-------------------------------------------------------
function poi_marker_listener( mmarker, ndx ){ //v3
        
    var mlistener = google.maps.event.addListener( mmarker, "click", function(){
                  
         var mInfoWin = Map_POI[ndx].mInfoWin;
         
         poi_info_wins_Off(ndx);
         
         var sTable = sx_info_table( ndx );         
         mInfoWin.setContent( sTable );
         mInfoWin.open( map, mmarker );
    });
    
    return mlistener;

}
//-------------------------------------------------------
function Show_POI(){ //v3

    var mmarker;
    var fx_icon;
    var latlng;
    var sTitle;
    
    var ndx = Map_POI.length;
    if( ndx == 0 )return;
    
    for( var i=0; i<ndx; ++i ){
        
        var fx_icon  = URL_markers + Map_POI[i].marker_fx;
        var mInfoWin = new google.maps.InfoWindow();
        
        Map_POI[i].mmarker = new google.maps.Marker({
                 map: map,
                icon: fx_icon,
               title: Map_POI[i].ref,
            position: Map_POI[i].mLxL,
           draggable: true,
             visible: true
        });

        Map_POI[i].ndx         = i;       
        Map_POI[i].mmarker.ndx = i;     
        Map_POI[i].mopts       = null;
        Map_POI[i].mInfoWin    = mInfoWin; 
        Map_POI[i].mlistener = poi_marker_listener( Map_POI[i].mmarker, i );
    }

    b_POI_Displayed = 1;

    display_POI_Table();
}
//..............................................................................................................
//..............................................................................................................
