function spotMouseDown(ZitID)
{
    KeyMouseDown(ZitID);
}
//-----------------------------------------------------
function KeyMouseDown(ZitID)
{
killpop()

spotType = PtD[ZitID]["Type"]

if ((spotType=='leafMap')||(spotType=='parentMap')||(spotType=='legal'))
    {
    txt = '../'
    txt += mzDataSet + '/'
    txt += PtD[ZitID]['Url']
    document.location=txt
    }
else
    if ((spotType=='sponsor'))
        {
        txt = 'http://'
        txt += PtD[ZitID]['Url']
        document.location=txt
        }
    else
        {
        showChangeBox(ZitID);
        return;
        }
}

//-----------------------------------------------------------

function showChangeBox(ZitID)
{
      txt = showChangeBoxTxt(ZitID)
      document.all['linkMapDiv'].innerHTML = txt
      linkMapDiv.style.position = 'absolute';
      linkMapDiv.style.top =  ''+(mzjsKey_ChangeBoxOffsetY+eventClientY);
      linkMapDiv.style.left = ''+(mzjsKey_ChangeBoxOffsetX+eventClientX);
      linkMapDiv.style.visibility = 'visible'; 
      linkMapDiv.style.zIndex = 200;
}

//-----------------------------------------------------------
function hideChangeBox()
{
    linkMapDiv.style.visibility = 'hidden'
}

//-----------------------------------------------------------
function showChangeBoxColumn(ZitID)
{
//--alert('showChangeBoxColumn - used for click on a spot')


Url=PtD[ZitID]['Url']

Popup1stLine = PtD[ZitID]['Popup']
CrPosition = Popup1stLine.indexOf('//')
if (CrPosition >-1) Popup1stLine = Popup1stLine.slice(0,CrPosition)
 
//if (typeof PtD[ZitID]['GG']=='undefined') // this works ...
if (PtD[ZitID]['GG']==undefined)            // so does this
  {
    regx = new RegExp('//','g')
    GoogleString = PtD[ZitID]['Popup'].replace(regx,' ')
    AnglePosition = GoogleString.indexOf('<')
    if (AnglePosition >-1) GoogleString = GoogleString.slice(0,AnglePosition)
  }
else
  {
    GoogleString = Popup1stLine + ' ' + PtD[ZitID]['GG']
  }

if (msjsGoogleExtra.length>0)
  {
  GoogleExtra = ' for ' + msjsGoogleExtra
  GoogleString += msjsGoogleExtra
  }
else
  GoogleExtra = ''
  
//-- fill the box
    txt = ''
    txt += '<tr><td style="background:white;" align="center">'
    txt += '<span class="spotPopupName">' +Popup1stLine+ '</span>'
    txt += '</td></tr><tr><td align="center">'

    
if (!mzjsNoUrlMode && Url!=undefined)
    {
    txt += '<a class="spotPopup" href="http://' +Url+ '">' +mzjsClickedPopupText_GotoWebsite+ '</a>'
    txt += '</td></tr><tr><td align="center">'
    }
    
if (!mzjsNoGoogleMode)
    {
    txt += '<a class="spotPopup" href="http://www.google.com/search?q=' +encodeURI(GoogleString)+ '">Search Google' +GoogleExtra+ '</a>'
    txt += '</td></tr><tr><td align="center">'
    }


if (!mzjsNoWikiMode)
    {
    WikiString=wikiString + '/' +Popup1stLine +'Council'
    txt += '<a class="spotPopup" href="' +WikiString+ '">Lookup Wiki</a>'
    txt += '</td></tr><tr><td align="center">'
    }


if (!mzjsNoChangePopupMode)
    {
    txt += '<input class="spotPopup" ' +buttonAndStyle+ ' value="Change Popup" name= "ChangePopup" '
    txt += 'onclick="javascript:hideChangeBox();changePopup(' +ZitID+ ')">'
    txt += '</td></tr><tr><td align="center">'
    }
    
if (!mzjsNoEditSpotInfoMode)
    {
    txt += '<input class="spotPopup" ' +buttonAndStyle+ ' value="Edit Spot Information" name= "EditSpotInformation" '
    txt += 'onclick="javascript:hideChangeBox();editSpotInformation(' +ZitID+ ')">'
    txt += '</td></tr><tr><td align="center">'
    }

if (!mzjsNoDeleteSpotMode)
    {
    txt += '<input class="spotPopup" ' +buttonAndStyle+ ' value="Delete Spot" name= "DeleteSpot" '
    txt += 'onclick="javascript:hideChangeBox();deleteSpot(' +ZitID+ ')">'
    txt += '</td></tr><tr><td align="center">'
    }

return txt
}
//-----------------------------------------------------
function showChangeBoxTxt(ZitID)
{
//--alert('showChangeBoxTxt - used for click on a spot')


    txt=''
    txt += '<table  border="2" cellpadding=0 cellspacing=0 '
    txt += ' style="font-family:arial, verdana, helvetica;font-size:8pt; background:#cccccc;">'
    txt += '<tr><td align="center">'
    
    
    txt += '<input class="spotPopup" type="button" value="Cancel" name= "next1" '
    txt += 'onclick="javascript:hideChangeBox();">'
    txt += '</td></tr>'
    
//-- show spot specific actions first
if (!mzjsNoStreetMapMode)
    {
    txt += '<tr><td align="center">'
    txt += '<a class="spotPopup" href="' +streetmapSpot(ZitID)+ '">Visit Streetmap</a>'
    txt += '</td></tr>'
    }

if (!mzjsNoTerraserverMode && PtD[ZitID]['Lt']!=undefined && PtD[ZitID]['Ln']!=undefined)
    {
    TerraserverString = ''
    TerraserverString += 'http://www.terraserver.com/imagery/image_gx.asp?cpx=' + PtD[ZitID]['Ln']
    TerraserverString += '&cpy=' + PtD[ZitID]['Lt'] + '&res=15&provider_id=340'

    txt += '<tr><td align="center">'
    txt += '<a class="spotPopup" href="' +encodeURI(TerraserverString)+ '">Visit Terraserver</a>'
    txt += '</td></tr><tr><td align="center">'
    }

//-- now show entry specific actions
    
       if (typeof PtD[ZitID]["Dp"] == 'undefined')
           {
           txt += showChangeBoxColumn(ZitID);
           }
       else
           {
           dpIndex=PtD[ZitID]["Dp"].slice(2)
    //       alert('dpIndex:'+dpIndex)
    //       alert('dp[dpIndex][0]:'+dp[dpIndex][0])
           for (duplicate in dp[dpIndex])
               {
    //           alert('duplicate:'+duplicate)
    //           alert('dp[dpIndex][duplicate]:'+dp[dpIndex][duplicate])
                 txt += showChangeBoxColumn(dp[dpIndex][duplicate]);
               }
           }    


    
    txt += '</td></tr>'
    txt += '</table>'
    
    return txt
}
//-----------------------------------------------------------
function webifyPostCode( pc )
{
   // check PCs of the from 'X nn Ynn'
   re =/(\S)(\s)(\S)/;
   pc2 = pc.replace( re,"$1+$3")
   re =/(\s)/;
   pc2 = pc2.replace( re,"+")
   return pc2
}
//-----------------------------------------------------------
function createStreetmapPostcodeRef( postCode )
{
  postCode = webifyPostCode( postCode )
  url  = "http://www.streetmap.co.uk/streetmap.dll?Postcode2Map?" + postCode
  txt = url
  return txt
}
//-----------------------------------------------------------
function createStreetmapEnRef( e,n )
{
  
  txt  = 'http://www.streetmap.co.uk/streetmap.dll?G2M?X=' + e + '&Y=' + n + '&A=Y&Z=3'
  txt  = 'http://www.streetmap.co.uk/streetmap.dll?G2M?x=' + e + '&y=' + n  + '&a=y&z=3'
  txt  = 'http://www.streetmap.co.uk/streetmap.dll?grid2map?' + e + '&' + n 
  txt  = 'http://www.streetmap.co.uk/streetmap.dll?grid2map?X=' + e + '&Y=' + n
  txt  = 'http://www.streetmap.co.uk/newmap.srf?x=465814&y=446606&z=3&ar=Y'
  txt  = 'http://www.streetmap.co.uk/streetmap.dll?grid2map?' + e + '&' + n 
  txt  = 'http://www.streetmap.co.uk/streetmap.dll?G2M?X=' + e + '&Y=' + n + '&A=Y&Z=3'
  return txt
}

//--http://www.streetmap.co.uk/streetmap.dll?G2M?X=461254&Y=432354&A=Y&Z=1

//-----------------------------------------------------
function streetmapSpot(ZitID)
{
//--alert('streetmapSpot - creating reference to streetmap')

    locationString = PtD[ZitID]["Loc"]
    if (locationString==undefined)locationString= PtD[ZitID]["Popup"]
    
    eStart = locationString.indexOf('<e="')
    if (eStart>=0)
      {
      nStart = locationString.indexOf(',n="')
      eEnd = locationString.indexOf('",n="')
      nEnd = locationString.indexOf('"/')
      e = locationString.slice(eStart+4,eEnd)
      n = locationString.slice(nStart+4,nEnd)
      txt = createStreetmapEnRef( e,n )
      return txt;
      }
    pcStart = locationString.indexOf('<pc="')
    if (pcStart>=0)
      {
      pcEnd = locationString.indexOf('"/')
      postCode = locationString.slice(pcStart+5,pcEnd)
    
      txt = createStreetmapPostcodeRef( postCode )
      return txt;
    }

}
//----------------------------------------------------------
function deleteSpot(ZitID)
{
    if (mzjsNoDeleteSpotMode)return;
    txt = cgiDirectory+'deleteSpot.py?'
    txt += 'SpotID=' + PtD[ZitID]["ID"]
//    txt += '&Name=' + PtD[ZitID]["N"]
    txt += '&mzDataSet=' + mzDataSet
    txt += '&MapIndexName=' + MapIndexName
//    txt += '&MapContinuation=' + PtD[ZitID]["Continuation"]
    document.location = txt;
    return;
}
//----------------------------------------------------------
function editSpotInformation(ZitID)
{
    txt = cgiDirectory+'saveEntry.py?'
    txt += 'SpotID=' + PtD[ZitID]["ID"]
//    txt += '&Name=' + PtD[ZitID]["N"]
    txt += '&mzDataSet=' + mzDataSet
    txt += '&MapIndexName=' + MapIndexName
//    txt += '&MapContinuation=' + PtD[ZitID]["Continuation"]
    document.location = txt;
    return;
}
//----------------------------------------------------------
function changePopup(ZitID)
{
	spotID = PtD[ZitID]["ID"]
	popupText =  '' + PtD[ZitID]["Popup"];
	var regx = new RegExp('//','g')
	popupText = popupText.replace(regx, '\n');
	spotUrl = PtD[ZitID]["Url"];
	spotClass = PtD[ZitID]["Cl"];
	spotIcon = PtD[ZitID]["Spot"];
	
	if (PtD[ZitID]["Gp"] == "yes")
	    spotIsGroup = 'checked';
	else
	    spotIsGroup = '';

    txt = popupChangeDivTxt(MapIndexName, spotID, popupText, spotClass, spotIsGroup, spotIcon)
    
    document.all['popupChangeDiv'].innerHTML = txt
    popupChangeDiv.style.position = "absolute";
    popupChangeDiv.style.top = "50px";
    popupChangeDiv.style.left = "500px";
    popupChangeDiv.style.visibility = "visible"; 
    popupChangeDiv.style.zIndex = 200;
}
//----------------------------------------------------------
function popupChangeDivTxt(mapIndexName, spotID, popupText, spotClass, spotIsGroup, spotIcon)
{
txt=''
txt += '<form name="popupChangeForm" action="' +cgiDirectory+ 'addSpot.py" method="get">'
txt += '<table bgcolor="cccccc">'
txt += '<tr>'
txt += '<td style="background-color:\'ffffff\'" colspan="2">Change popup text</td>'
txt += '<td><input type="button" style="background-color:\'cc8888\'; cursor:hand" value="Cancel" name= "next1" '
txt += 'onclick="javascript:popupChangeDiv.style.visibility = \'hidden\';"></td>'
txt += '<td><input type="button" style="background-color:\'cc8888\'; cursor:hand" value="Save" name= "next2" '
txt += 'onclick="javascript:document.forms.popupChangeForm.submit();"></td>'
txt += '</tr>'
txt += '<tr><td>'
txt += 'Popup Text:</td><td colspan="3"><textarea rows="4" value="" name="Popup" id="Popup">'+ popupText + '</textarea>'
txt += '</td></tr><tr><td>'
txt += 'Url:</td><td colspan="3"><input type="text" size="24" value="'+ spotUrl + '" name="Url" id="Url">'
txt += '<input type="hidden"  value="' +mzDataSet+ '" name="mzDataSet" id="mzDataSet">'
txt += '<input type="hidden"  value="'+ mapIndexName + '" name="MapIndexName" id="MapIndexName">'
txt += '<input type="hidden"  value="'+ spotID + '" name="SpotID" id="SpotID"> '
txt += '</td></tr><tr><td>'
txt += 'Class:</td><td colspan="3"><input type="text" size="20" value="'+ spotClass + '" name="Class" id="Class">'
txt += '&nbsp;&nbsp;Group Leader?<input type="checkbox" '+ spotIsGroup + ' value="yes" name="IsGroup" id="IsGroup">'
txt += '</td></tr><tr><td>'
txt += 'Icon:</td><td colspan="3">'
txt += '<select name="Icon" value="spotR.gif" id="Icon">'
txt += '<option>Custom'
txt += '<option>spotR.gif'
txt += '<option>spotB.gif'
txt += '<option>fiat.gif'
txt += '<option>sportscar.gif'
txt += '</select>'
txt += '</td></tr><tr><td>'
txt += 'Custom:</td><td colspan="3"><input type="text" size="40" value="'+ spotIcon + '" name="Custom" id="Custom"> '
txt += '</td></tr>'
txt += '</table>'
txt += '</form>'
return txt
}
//----------------------------------------------------------


