var doc=false;
var xmlData="";
var posNum=0;
var testInc=0;

var customer_name = new Array();
var phone = new Array();
var website = new Array();
var email = new Array();
var address = new Array();
var cust_num= new Array();
//var Clat=new Array();
//var Clon=new Array();
    function showCategoryLocation() {    
//    document.getElementById('evlst').innerHTML+="<div>OK</div>";   
     clearZoom();
        
    var xmlDoc;
      var category_id = document.dispdist.C.value;
      var XMLHttpRequestObject = false;

if(window.XMLHttpRequest){
XMLHttpRequestObject = new XMLHttpRequest();
}else if(window.ActiveXObject){
XMLHttpRequestObject=new ActiveXObject("Microsoft.XMLHTTP");
}
var dataSource="map_eval.php?map_cat="+category_id;
if(XMLHttpRequestObject){XMLHttpRequestObject.open("POST", dataSource);}
else
{display_list.innerHTML+="<br />Request Object not opened<br />";}
XMLHttpRequestObject.onreadystatechange=function(){
if(XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status==200){

var xmlData=XMLHttpRequestObject.responseText;

    var display_list=document.getElementById('evlst');   

if (window.ActiveXObject)
  {
  doc=new ActiveXObject("Microsoft.XMLDOM");
  doc.async="false";
  doc.loadXML(xmlData);
  }
// code for Mozilla, Firefox, Opera, etc.
else
  {
  var parser=new DOMParser();
  var doc=parser.parseFromString(xmlData,"text/xml");
//  var doc=GXml.parse(xmlData);
  }
  var clients = doc.documentElement.getElementsByTagName("event");
//	var x=doc.documentElement;
	
	
//	var xSize=x.childNodes.length;
    for(var cu=0;cu<=clients.length;cu++)
    {

if(navigator.appName=='Microsoft Internet Explorer')
{
    if(clients[cu].childNodes[0].childNodes[0].nodeValue){customer_name[posNum]=clients[cu].childNodes[0].childNodes[0].nodeValue;}else{customer_name[posNum]=0}
    if(clients[cu].childNodes[1].childNodes[0].nodeValue){phone[posNum]=clients[cu].childNodes[1].childNodes[0].nodeValue;}else{phone[posNum]=0}
    if(clients[cu].childNodes[2].childNodes[0].nodeValue){website[posNum]=clients[cu].childNodes[2].childNodes[0].nodeValue;}else{website[posNum]=0}
    if(clients[cu].childNodes[3].childNodes[0].nodeValue){email[posNum]=clients[cu].childNodes[3].childNodes[0].nodeValue;}else{email[posNum]=0}
    if(clients[cu].childNodes[4].childNodes[0].nodeValue){address[posNum]=clients[cu].childNodes[4].childNodes[0].nodeValue;}else{address[posNum]=0}
    if(clients[cu].childNodes[5].childNodes[0].nodeValue){cust_num[posNum]=clients[cu].childNodes[5].childNodes[0].nodeValue;}else{cust_num[posNum]=0}

//geocoder.getLocations(address[posNum], ShowPointsOnMap);
posNum=posNum+1;
}
else
{
//document.getElementById('evlst').innerHTML+="<div>OK</div>";    

//posNum=0;

    if(clients[cu].childNodes[0].childNodes[0].nodeValue){customer_name[posNum]=clients[cu].childNodes[0].childNodes[0].nodeValue;}else{customer_name[posNum]=0;}
    if(clients[cu].childNodes[2].childNodes[0].nodeValue){phone[posNum]=clients[cu].childNodes[2].childNodes[0].nodeValue;}else{phone[posNum]=0;}
    if(clients[cu].childNodes[4].childNodes[0].nodeValue){website[posNum]=clients[cu].childNodes[4].childNodes[0].nodeValue;}else{website[posNum]=0;}
    if(clients[cu].childNodes[6].childNodes[0].nodeValue){email[posNum]=clients[cu].childNodes[6].childNodes[0].nodeValue;}else{email[posNum]=0;}
    if(clients[cu].childNodes[8].childNodes[0].nodeValue){address[posNum]=clients[cu].childNodes[8].childNodes[0].nodeValue;}else{address[posNum]=0;}
    if(clients[cu].childNodes[10].childNodes[0].nodeValue){cust_num[posNum]=clients[cu].childNodes[10].childNodes[0].nodeValue;}else{cust_num[posNum]=0;}

//geocoder.getLocations(address[posNum], ShowPointsOnMap);
posNum=posNum+1;

 
}
ListPoints();
    }
}
}
XMLHttpRequestObject.send(null);
		return null;
    }
    
    
    function ListPoints() {

var window_txt='<div><a href=?customer_id='+cust_num[testInc]+' class=map_nav>' + customer_name[testInc] + '</a></div><div class=point_txt>'+ address[testInc] + '</div>';

if(phone[testInc]!=0)
{
window_txt+='<div class=pk_point_txt>'+phone[testInc]+ '</div>';
}

if(email[testInc]!=0)
{
window_txt+='<div><a href=mailto:'+email[testInc]+'  class=map_nav>'+email[testInc]+'</a></div>';
}

if(website[testInc]!=0)
{
var ht_part=website[testInc].substring(0,6);

if(ht_part!='http://')
{
web_link='http://'+website[testInc];
}
else if(ht_part=='http://')
{
var web_link=website[testInc];
}
var wd_a=web_link.split('//');
var web_disp=wd_a[1];
window_txt+='<div><a href='+web_link+' target=_blank class=map_nav>'+web_disp+'</a></div>';
}

window_txt+='<a href=\"http://www.google.com/maps?source=uds&daddr='+address[testInc]+'\" target=_blank>Get Directions</a>';

//var window_txt='<div>This is the info for the window'+cust_address+'</div>';
document.getElementById('evlst').innerHTML+='<div style=\'border:solid 1px #000; margin:2px; padding:4px; cursor:pointer; background:#669\' onClick="showClient('+cust_num[testInc]+')" onMouseOut="this.style.background=\'#669\'" onMouseOver="this.style.background=\'#aaf\'; showWindow(\''+cust_num[testInc]+'\',\''+customer_name[testInc]+'\',\''+address[testInc]+'\',\''+phone[testInc]+'\',\''+
email[testInc]+'\',\''+website[testInc]+'\')"><div style=\'font-size:8pt; font-weight:bold; color:#fff\'>'+customer_name[testInc]+'</div><div  style=\'font-size:8pt; color:#fff\'>'+address[testInc] + '</div></div>'; 

testInc++;

//marker.bindInfoWindowHtml(window_txt);
//marker.openInfoWindowHtml(window_txt);

  
//}

}


function showClient(num)
{
location.href='?customer_id='+num;
}

//cust_num[posNum],customer_name[posNum],address[posNum],phone[posNum],email[posNum],website[posNum]
function showWindow(C_num,C_name,C_address,C_phone,C_email,C_website)
{
cust_num=C_num;
customer_name[cust_num]=C_name;
address[cust_num]=C_address;
phone[cust_num]=C_phone;
email[cust_num]=C_email;
website[cust_num]=C_website;

showPoint(address[C_num]);

//alert(lat+","+lan);
}
    
    
    function putPointOnMap(response)
    {
          if (response.Placemark[0]) {


	place = response.Placemark[0];

        point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
        
//point = new GLatLng(lat,lan);
//marker = new GMarker(point);
var C_num=cust_num[0];
var winTxt='<div><a href=\'?customer_id='+C_num+'\' class=\'map_nav\'>' + customer_name[C_num] + '</a></div><div  style=\'font-size:8pt; font-weight:bold\'>'+ address[C_num] + '</div>';
if(phone[C_num]!=0)
{
winTxt+='<div class=pk_point_txt>'+phone[C_num]+ '</div>';
}

if(email[C_num]!=0)
{
winTxt+='<div><a href=mailto:'+email[C_num]+'  class=map_nav>'+email[C_num]+'</a></div>';
}

if(website[C_num]!=0)
{
var ht_part=website[C_num].substring(0,6);

if(ht_part!='http://')
{
web_link='http://'+website[C_num];
}
else if(ht_part=='http://')
{
var web_link=website[C_num];
}
var wd_a=web_link.split('//');
var web_disp=wd_a[1];
winTxt+='<div><a href='+web_link+' target=_blank class=map_nav>'+web_disp+'</a></div>';
}

map.panTo(point);
map.openInfoWindowHtml(point,winTxt);     
        
        
        
//Clat[testInc]=place.Point.coordinates[1];
//Clon[testInc]=place.Point.coordinates[0];
marker = new GMarker(point);
map.addOverlay(marker);
}
    }
    
    
    
    
    function showPoint(Caddress)
    {
    geocoder.getLocations(Caddress, putPointOnMap);
    }
    
    
    function clearZoom()
    {
posNum=0;
testInc=0;
/*
customer_name = new Array();
phone = new Array();
website = new Array();
email = new Array();
address = new Array();
cust_num = new Array();
*/

document.getElementById('evlst').innerHTML='';
/*
document.catspot.customer_name.value="";
document.catspot.website.value="";
document.catspot.email.value="";
document.catspot.phone.value="";
document.catspot.cust_num.value="";
document.catspot.addressArray.value="";
*/

    map.clearOverlays();
var boundaries = new GLatLngBounds(new GLatLng(42.013996, -75.820055) , new GLatLng(42.88497,-74.233958));
var zoom_ovrly = new GGroundOverlay("zoom_ovrly.png", boundaries);
map.addOverlay(zoom_ovrly);
map.setCenter(new GLatLng(42.452971, -75.063157), 9);
    }

