document.onmousemove = getMouseMove;
document.onkeydown = getKeyDown;
var eventClientX=0;
var eventClientY=0;
var eventShiftKey;
var eventCtrlKey;
var popDivX=0;
var popDivY=0;

var currentPopupOffsetX = 0;
var currentPopupOffsetY = 0;

function getMouseMove(e)
{
  try
    {
      eventClientX =  e.clientX+document.body.scrollLeft;
      eventClientY =  e.clientY+document.body.scrollTop;
    }
  catch(e)
    {
      eventClientX =  event.clientX+document.body.scrollLeft;
      eventClientY =  event.clientY+document.body.scrollTop;
    }

     
  popDiv.style.position = "absolute";
  popDiv.style.left = eventClientX + currentPopupOffsetX;
  popDiv.style.top = eventClientY + currentPopupOffsetY;

}
//----------------------
function getKeyDown(e)
{
   try
    {
      eventShiftKey =  e.shiftKey;
      eventCtrlKey =  e.ctrlKey;
    }
  catch(e)
    {
      eventShiftKey =  event.shiftKey;
      eventCtrlKey =  event.ctrlKey;
    }
// alert('getKeyDown'+eventShiftKey+eventCtrlKey);
  
}
//-----------------------------------------------------
//-----------------------------------------------------
var sortedPtD = new Array();

var gKeyColumnCount = 0;
var gKeyRowCount = 0;

var gCategoryColumnCount = 0;
var gCategoryRowCount = 0;

var NumSelected = 0;
var selected = new Array();

var lastZitHighlighted;
//-----------------------------------------------------
//-----------------------------------------------------

function HighlightZit(SpotID,IsHighlightFromSpot){

  DropZits(SpotID);
  currentSpot = PtD[SpotID];
  
  spotImage = currentSpot["Spot"]
  DotPosition = spotImage.indexOf('.')
  if (DotPosition != -1)   
    spotHighlight = spotImage.slice(0,DotPosition)+'_'+spotImage.slice(DotPosition,spotImage.length)
  else
    spotHighlight = spotImage

  keyDisplaySuppressed = currentSpot["Type"]=="leafMap"  && mzjsLeafMapKeySuppression;

  document.all['img_'+SpotID].src = httpSpotImageLocation + spotHighlight;  
  document.all['img_'+SpotID].style.cursor = 'hand';  
  if (!keyDisplaySuppressed && !MapIndexName == 'uk')document.all['k'+SpotID].style.color = 'red'; 
  document.all['m'+SpotID].style.visibility='visible';
  document.all['m'+SpotID].style.zIndex=100;
  NumSelected++;
  selected[NumSelected]=SpotID;

  if ((currentSpot.Gp =='yes')&& IsHighlightFromSpot) HighlightClass(currentSpot.Cl);
}
function UnhighlightZit(SelectedID,SpotID)
{
  keyDisplaySpressed = false;
	
  if (SpotID != "x" && SpotID != SelectedID) 
  {
    document.images['img_'+SpotID].src = httpSpotImageLocation + PtD[SpotID]["Spot"];
    
    keyDisplaySpressed = (PtD[SpotID]["Type"]=="leafMap")  && mzjsLeafMapKeySuppression;
    
    if ((PtD.length > 0) && !keyDisplaySpressed && !MapIndexName == 'uk')
    {
      document.all['k'+SpotID].style.color =PtD[SpotID]["Kt"];
    }
    document.all['m'+SpotID].style.zIndex=PtD[SpotID]["zIndex"];
    if (PtD[SpotID]["Spot"].charAt(1) == '_')
      {
//      alert('PtD[SpotID]["Spot"].charAt(1)');
      document.all['m'+SpotID].style.visibility = 'hidden'
    }
  return 1
  }
  else
  {
    //Current spot - do not remove it from the selected list.
    return 0
  }
}
function HighlightClass(className)
{
  for (i=0;i<PtD.length;i++)
  {
    currentSpot = PtD[i]
    NotGroup = true; //(currentSpot.Gp != 'yes')
    if (NotGroup && (currentSpot.Cl == className))
    {
      document.all['img_'+ i].src = httpSpotImageLocation + currentSpot["Highlight"];  
      document.all['img_'+ i].style.cursor = 'hand';  
      document.all['k'+ i].style.color = 'red'; 
      document.all['m'+ i].style.zIndex=100;
      document.all['m'+ i].style.visibility='visible';
  
      NumSelected++;
      selected[NumSelected]=i;
    }
  }
}
function DropZits(SelectedID)
{
//  alert("DropZits:NumSelected:"+NumSelected);
  for (i = NumSelected; i > 0; i--) 
  {   
    if (UnhighlightZit(SelectedID,selected[i])==1)
    {
      //Remove this Spot from the selected array
      selected[i]="x";
      NumSelected--;
    }
  }  
}

//-----------------------------------------------------
function dispMap(w,h) {

   txt =   ''
   
   txt +=  '<div id="xSpotDiv" style="position:absolute; visibility:hidden;">'
   txt +=  '<img src="'+httpSpotImageLocation+'x.gif">'
   txt +=  '</div>'
      
   txt +=  '<div style="position:relative; left:0; top:0; z-Index:0"'
   txt +=  'onMouseDown="mapMouseDown()">'
  
   txt +=  '<img name="ViewerImage" border="0" '
   txt +=  'src="'+ httpViewerImageLocation + 'viewer2.jpg" ' 
   txt +=  'style="position:absolute; left:2px; top:8px;" usemap="#hello99">'
   
   txt +=  '<div class="mapHeading" id="banner1" >'
   txt +=  ''+(mapTheme+MapLabel).replace(' ','&nbsp;')+ '</div>'
   
   txt +=  '<img name="MapImage" border="0" width="350" height="350" '
   txt +=  'src="'+httpMapImageLocation+MapIndexName+'.png" ' 
   txt +=  'style="position:relative;'
   txt +=  'left:'+(mzjsMapCornerLeft+1)+';'
   txt +=  'top:'+(mzjsMapCornerTop+1)+'; z-Index:1">'
   
   txt +=  '</div>'

   txt +=  '<div class="ukPageInfo" id="banner2" style="position:absolute; left:10px;'
   txt +=  'top:420px; width:380px;">'

	
	txt += 'MapZit.com provides local information for most areas '
	txt += 'of Great Britain. Perfect for both residents and tourists alike. '
	txt += 'This site will give detailed information to help you make the '
	txt += 'most of your chosen area.<br/><br/>'
	
	txt += 'From restaurants, bars and clubs to the nearest cash-machine or '
	txt += 'petrol station, MapZit.com will provide you with easy access '
	txt += 'to the information you need. Just click on an area of the map '
	txt += 'to get going.<br/><br/>'
	
	
   txt +=  'Click the following link for '
   txt +=  '<a href="../legalStuff.htm">Legal, disclaimers, copyright etc.</a>'
   txt +=  '</div>'

   for (i=0;i<PtD.length;i++)
   {
      txt2 =        ''
      txt2 +=  '<div ID="m'+i+'" style="position:absolute; '
      if (PtD[i]["Spot"].charAt(1) == '_')
          {
          txt2 +=  'visibility:hidden; '
          }
      txt2 +=  'left:' + (eval(PtD[i].x)+mzjsMapCornerLeft-mzjsSpotSizeAdjustmentX).toString() + ';'
      txt2 +=  'top: ' + (eval(PtD[i].y)+mzjsMapCornerTop-mzjsSpotSizeAdjustmentY).toString() + ';'
      txt2 +=  'z-Index:2;">'
      txt2 +=  '<img name="img_'+i+'" src="' + '' +httpSpotImageLocation + PtD[eval(i)]["Spot"] +'" border=0 '
      txt2 +=  'onMouseOver="HighlightZit(\''+i+'\', true);popSummary(\''+i+'\')" '
      txt2 +=  'onMouseOut="killpop()" '
      txt2 +=  'onMouseDown="spotMouseDown(\'' + i + '\')" >'
      txt2 +=  '</div>'
      
      txt= txt + txt2;
   }
   
   
   txt +=  '</div>'
//gb17jul04   zitInfoUndisplay()   


   document.all['mapDiv'].innerHTML = txt
   
 }
//---------------------
function killpop()
{
   popDiv.innerHTML = ''; 
   popDiv.style.visibility = "hidden"
}

function popSummary(ZitID)
{
   var txt, regx;
     
   txt = ''
   txt += '<table border=0 cellpadding=2 cellspacing=0 bgcolor=\'green\'>'
   txt += '<tr><td>'
   txt += '<table width=100% border=0 cellpadding=2 cellspacing=0 bgcolor=\'white\'>'
   
   txtXXX = '' + PtD[ZitID]["Popup"];
   txtEnd = txtXXX.indexOf('//<')
//   alert('txtEnd:'+txtEnd)
   if (txtEnd>=0)
     {
     txtXXX = txtXXX.slice(0,txtEnd)
     }
   
   if (PtD[ZitID]["Type"]=='leafMap')
     txtXXX += '//..click zoom in'
   else if (PtD[ZitID]["Type"]=='parentMap')
     txtXXX += '//..click zoom out'
   else
     txtXXX += '//..click for more'
   
   regx = new RegExp('//','g')
   txtXXX = txtXXX.replace(regx, '<br/>');
   txt+= '<tr><td>' + txtXXX + '</td></tr>';

   txt+= '</table>';
   txt+= '</td></tr>';
   txt+= '</table>';


   if (PtD[ZitID]['Type']=='spot')
     {
     currentPopupOffsetX = mzjsSpot_SpotPopupOffsetX;
     currentPopupOffsetY = mzjsSpot_SpotPopupOffsetY;
     }
   else
     {
     currentPopupOffsetX = mzjsSpot_ZoomPopupOffsetX;
     currentPopupOffsetY = mzjsSpot_ZoomPopupOffsetY;
     }

   popDiv.style.position = "absolute";
   popDiv.style.left = eventClientX + currentPopupOffsetX;
   popDiv.style.top = eventClientY + currentPopupOffsetY; 

   document.all['popDiv'].innerHTML = txt
   popDiv.style.visibility = "visible"; 
   popDiv.style.zIndex = 100
}

// display under construction notice - nick 24/02/05
function dispIntro(myCategory) 
{


txt = ''
txt += '<table cellpadding=0 cellspacing=0 width="' + mzjsBlurbWidth + '">'
txt += '<tr><td>'
txt += '<h3 align="center">WWW.MAPZIT.COM</h3>'

txt += mzjsUkMapIntroduction 


txt += '<p>MapZit.com is a '
txt += '<a href="http://www.beacon-dodsworth.co.uk">Beacon Dodsworth</a> '
txt += 'product. For our other products see our '
txt += '<a href="http://www.beacon-dodsworth.co.uk">main website</a>.</p>'

txt += '<p>Do let us have any comments on '
txt += '<a href="mailto:developers@MapZit.com">developers@MapZit.com</a></p>'

txt += '</td></tr>'
txt += '</table>'

introDiv.innerHTML = txt
introDiv.style.position = "absolute"
introDiv.style.left = "440px"
introDiv.style.top = "30px"
introDiv.style.visibility = "visible"
introDiv.style.zIndex = "100"

}

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

function KeyMouseDownXX(ZitID)
{
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;
        }
}

