﻿// JScript File
var geocoder = null;
var searchZip = null;

function LoadMap(lat,lon,zoom)
{
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("mapCanvas"));
        
        //map.addControl(new YSliderControl());
        map.addControl(new GSmallZoomControl());
		map.setCenter(new GLatLng(lat, lon), zoom);

	    geocoder = new GClientGeocoder();
	}
	
}

function StartLookup()
{

    // workaround for ie 6 slow screen redraws
    // pause for screen update before starting search...

    document.body.style.cursor = 'wait';
    zipbox = document.getElementById('txtSearch');
    zipbox.className += ' disabled';
    searchZip = zipbox.value;
    zipbox.value = 'searching...';
    zipbox.innerHtml = 'searching...';
    document.getElementById('txtSearch').disabled = true;
    
    // delay for ie to disable textbox        
    var t=setTimeout(LookupZip,500);
}

function LookupZip()
{
    

	// Clear Markers from map
	map.clearOverlays(); 

    // center on zipcode
    center = geocoder.getLatLng(searchZip, function(p)
    {
        if (p == null) alert("invalid zipcode");
        else map.setCenter(new GLatLng(p.y, p.x), 11);
    });
    
    
    // init icon for reuse below
	var icon = new GIcon();
	icon.image =  "images/red_mrkr.png";
	icon.iconSize = new GSize(28, 28);
	icon.shadowSize = new GSize(37, 34);
	icon.iconAnchor = new GPoint(9, 34);
	icon.infoWindowAnchor = new GPoint(9, 2);
	icon.infoShadowAnchor = new GPoint(18, 25);

    // draw pins
    for(q=0;q < branch.length; q++)
    {
        var point = new GLatLng(branch[q][8], branch[q][9]);
        

        html = "<div id='infoDiv'>" + "<div style='float:left;'><img src='images/boa_logo_1.gif' style='float:left;margin:0 5px 0 0;' /></div>" +
                "<div style='float:left;'><h3>" + branch[q][1] + "</h3> " + branch[q][2] + ",<br/>" + 
		        branch[q][3] + ", " + branch[q][4] + " " + branch[q][5] +  "<br />Tel: " + branch[q][6] + "</div>";
			
        // append to html, but not to maxText		
	   // html += "<br style='clear:both;'/><br/><a style='float:right;' href='javascript:map.getInfoWindow().maximize();' class='infoLink'>Click here for more info...</a>";
		
	    map.addOverlay(createMarker(point, html, icon, ""));
    }

    // re-enable search
    document.body.style.cursor = 'default';
    document.getElementById('txtSearch').value = searchZip;
    document.getElementById('txtSearch').disabled = false;
    zipbox.className = zipbox.className.replace('disabled','');

}

function createMarker(point, html, icon, maxHTML) {
		
	var marker = new GMarker(point, icon);
	
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html, {maxWidth: 210, maxContent: maxHTML} );
	});
	
	return marker;
}

function ClearDefault()
{
    if (document.getElementById('txtSearch').value == document.getElementById('txtSearch').defaultValue)
        document.getElementById('txtSearch').value = '';
}

function doEnterKey(event)
{
    if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13))
        StartLookup();
}

function ShowBusy()
{
    document.getElementById('mapCanvas').innerHTML = '<img src="images/wait3.gif" style="margin:110px 130px;" />';
}