﻿// JScript File

function loadLocation(label, html, city, province, country, pointValues) {
        
            if (GBrowserIsCompatible()) {

		        // This function picks up the click and opens the corresponding info window
    		    
		        // create the map
		        var map = new GMap2(document.getElementById("smMap"));
        			
		        //small map control
		        map.addControl(new GSmallMapControl());
        			
		        
		        map.setCenter(new GLatLng(48.4146186174932,-89.24263000488281),16);
        		
		        // Create our "tiny" marker icon
		        var icon = new GIcon();
		        icon.image = "marker_blue.png";
		        icon.shadow = "shadow.png";
		        icon.iconSize = new GSize(12, 20);
                icon.shadowSize = new GSize(22, 20);
                icon.iconAnchor = new GPoint(6, 20);
                icon.infoWindowAnchor = new GPoint(5, 1);    			
    			
    			var gmarkers = [];	
    				       
	            var pointArray = pointValues.split(",")
	            var point = new GPoint(pointArray[0],pointArray[1]);
	        
	            map.setCenter(new GLatLng(pointArray[1],pointArray[0]),15);
    	         			        
		        // create the marker
		       var marker = new GMarker(point, icon);
    		  
		        map.addOverlay(marker);
		        gmarkers.push(marker);
    			    

		        GEvent.addListener(map, "click", function(overlay, point) {
			        if (overlay) {
				        if (overlay.my_html) {
					        overlay.openInfoWindowHtml('<div style="white-space:nowrap;">'+overlay.my_html+'<\/div>');
			            }
		            }
	            }
            );     
	    } else {
		    alert("Sorry, the Google Maps API is not compatible with this browser");
	    }

        }
        
		function loadSingle(query) {
        
            if (GBrowserIsCompatible()) {

		    // This function picks up the click and opens the corresponding info window
		    
		    // create the map
		    var map = new GMap2(document.getElementById("lgMap"));
    			
		    //small map control
		    map.addControl(new GSmallMapControl());
    			
		    // large map control
		    //map.addControl(new GLargeMapControl());
		    //map.addControl(new GMapTypeControl());
		    map.setCenter(new GLatLng(48.4146186174932,-89.24263000488281),16);
    			
    			        
		    // Create our "tiny" marker icon
		    var icon = new GIcon();
		    icon.image = "marker_blue.png";
		    icon.shadow = "shadow.png";
		    icon.iconSize = new GSize(12, 20);
            icon.shadowSize = new GSize(22, 20);
            icon.iconAnchor = new GPoint(6, 20);
            icon.infoWindowAnchor = new GPoint(5, 1);    			
    			
		    // array to hold copies of the markers 
		    // we cant scan map.overlays[] because the order of the entries changes
		    var gmarkers = [];
    	
		    // Read the data from example.xml
		    var request = GXmlHttp.create();
		    request.open("GET", "/mapXML.asp?" + query, true);
    		
		    request.onreadystatechange = function() {
    		
			    if (request.readyState == 4) {
    			
				    var xmlDoc = request.responseXML;
				    // obtain the array of markers and loop through it
				    var markers = xmlDoc.documentElement.getElementsByTagName("marker");
    			                                                                                                                                                 			   			       
				    for (var i = 0; i < markers.length; i++) {
					    // obtain the attribues of each marker
					    
					    var html = xmlDoc.getElementsByTagName('address')[i].firstChild.data;          
					    var city = xmlDoc.getElementsByTagName('city')[i].firstChild.data;   
					    var province = xmlDoc.getElementsByTagName('province')[i].firstChild.data; 
					    var pointValues = xmlDoc.getElementsByTagName('point')[i].firstChild.data;
					    var label = xmlDoc.getElementsByTagName('name')[i].firstChild.data; 
    			       
    			        var pointArray = pointValues.split(",")
    			        var point = new GPoint(pointArray[0],pointArray[1]);
    			        
    			        map.setCenter(new GLatLng(pointArray[1],pointArray[0]),15);
    			            			        
					    // create the marker
					    var marker = new GMarker(point, icon);
					  
					    map.addOverlay(marker);
					    gmarkers.push(marker);
				    }
				    }
			    }
			    request.send(null);

			    GEvent.addListener(map, "click", function(overlay, point) {
				    if (overlay) {
					    if (overlay.my_html) {
						    overlay.openInfoWindowHtml('<div style="white-space:nowrap;">'+overlay.my_html+'<\/div>');
					    }
				    }
			    }
		    );     
	    } else {
		    alert("Sorry, the Google Maps API is not compatible with this browser");
	    }

        }
        
		function load(query) {
        
            if (GBrowserIsCompatible()) {

		    // This function picks up the click and opens the corresponding info window
		    function myclick(i) {
			    gmarkers[i].openInfoWindowHtml('<div style="white-space:nowrap;">'+gmarkers[i].my_html+'<\/div>');
			    self.location.href = "#top";
		    }

		    // create the map
		    var map = new GMap2(document.getElementById("lgMap"));
    			
		    //small map control
		    //map.addControl(new GSmallMapControl());
    			
		    // large map control
		    map.addControl(new GLargeMapControl());
		    //map.addControl(new GMapTypeControl());
		    map.setCenter(new GLatLng(48.4146186174932,-89.24263000488281),12);
    			
    			        
		    // Create our "tiny" marker icon
		    var icon = new GIcon();
		    icon.image = "marker_blue.png";
		    icon.shadow = "shadow.png";
		    icon.iconSize = new GSize(12, 20);
            icon.shadowSize = new GSize(22, 20);
            icon.iconAnchor = new GPoint(6, 20);
            icon.infoWindowAnchor = new GPoint(5, 1);    			
    			
		    // array to hold copies of the markers 
		    // we cant scan map.overlays[] because the order of the entries changes
		    var gmarkers = [];
    			
		    // functions that open the directions forms
    		
		    function tohere(i) {
			    gmarkers[i].openInfoWindowHtml('<div style="white-space:nowrap;">'+gmarkers[i].to_html+'<\/div>'); 			
		    }
    		
		    function fromhere(i) {
			    gmarkers[i].openInfoWindowHtml('<div style="white-space:nowrap;">'+gmarkers[i].from_html+'<\/div>');
		    }


		    // Read the data from example.xml
		    var request = GXmlHttp.create();
		    request.open("GET", "/mapXML.asp?" + query, true);
    		
		    request.onreadystatechange = function() {
    		
			    if (request.readyState == 4) {
    			
				    var xmlDoc = request.responseXML;
				    // obtain the array of markers and loop through it
				    var markers = xmlDoc.documentElement.getElementsByTagName("marker");
    			                                                                                                                                                 			   			       
				    for (var i = 0; i < markers.length; i++) {
					    // obtain the attribues of each marker
					    
					    var html = xmlDoc.getElementsByTagName('address')[i].firstChild.data;          
					    var city = xmlDoc.getElementsByTagName('city')[i].firstChild.data;   
					    var province = xmlDoc.getElementsByTagName('province')[i].firstChild.data; 
					    var pointValues = xmlDoc.getElementsByTagName('point')[i].firstChild.data;
					    var label = xmlDoc.getElementsByTagName('name')[i].firstChild.data; 
    			       
    			        var pointArray = pointValues.split(",")
    			        var point = new GPoint(pointArray[0],pointArray[1]);
    			        
					    // create the marker
					    var marker = new GMarker(point, icon);
					    // Build the extra html that handles the directions links and forms
					    //     The inactive version of the direction info
					    marker.my_html = '<br\/><b>' + label + '<\/b><br \/>' + html + '<br \/>' + city +', ' + province + '<br \/>Directions: <a href="javascript:tohere('+i+')">To here<\/a> - <a href="javascript:fromhere('+i+')">From here<\/a>';
    					
					    //     The version with the "to here" form open
					    marker.to_html =  '<br\/><b>' + label + '<\/b><br \/>' + html + '<br \/><br \/>Directions: <b>To here<\/b> - <a href="javascript:fromhere(' + i + ')">From here<\/a>' +
						    '<br>Start address:<form action="http://maps.google.com/maps" method="get" target="_blank">' +
						    '<input type="text" size="40" maxlength="40" name="saddr" id="saddr" value="" /><br \/>' +
						    '<input class="button" value="Get Directions" type="submit">' +
						    '<input type="hidden" name="daddr" value="' +
						    point.y + ',' + point.x + "(" + label + ")" + '"\/>';
    						
					    //     The version with the "to here" form open
					    marker.from_html = '<br\/><b>' + label + '<\/b><br \/>' + html + '<br \/><br \/>Directions:  <a href="javascript:tohere(' + i + ')">To here<\/a> - <b>From here<\/b>' +
						    '<br \/>End address:<form action="http://maps.google.com/maps" method="get"" target="_blank">' +
						    '<input type="text" size="40" maxlength="40" name="daddr" id="daddr" value="" \/><br \/>' +
						    '<input class="button" value="Get Directions" type="submit" \/>' +
						    '<input type="hidden" name="saddr" value="' +
						    point.y + ',' + point.x + "(" + label + ")" + '"\/>';
					    marker.my_name = label;
					    map.addOverlay(marker);
					    gmarkers.push(marker);
				    }
				    }
			    }
			    request.send(null);

			    GEvent.addListener(map, "click", function(overlay, point) {
				    if (overlay) {
					    if (overlay.my_html) {
						    overlay.openInfoWindowHtml('<div style="white-space:nowrap;">'+overlay.my_html+'<\/div>');
					    }
				    }
			    }
		    );
			        
	} else {
		alert("Sorry, the Google Maps API is not compatible with this browser");
	}

        }
