// Copyright Great Ocean Software. All rights reserved.  Licensed only for use by Aerial Photo Pro, Inc.

 	var map;
 	var circleid = 7;
 	
   function initialize() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));       
        map.setCenter(new GLatLng(30.179743, -96.707993), 6, G_HYBRID_MAP);
        var customUI = map.getDefaultUI();
        customUI.controls.scalecontrol = false;
        customUI.controls.smallzoomcontrol3d = false;
        customUI.controls.largemapcontrol3d = false;
        customUI.controls.maptypecontrol = false;
        customUI.controls.menumaptypecontrol = false;
        map.setUI(customUI);        
        //var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10));
        //map.addControl(new GLargeMapControl3D(), topRight);
        var topLeft = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10,10));
        map.addControl(new GLargeMapControl3D(), topLeft);
        //map.addControl(new GSmallZoomControl());
        controlcircles();
      }
    }
    
	function showAddress(address) {
      var geocoder = new GClientGeocoder();
	  geocoder.getLatLng(address, function(point) {
	    if (!point) {
	      alert(address + " not found");
	    } else {
	      map.setCenter(point, 16);
	      var marker = new GMarker(point);        
	      map.addOverlay(marker);        
	      //marker.openInfoWindowHtml(address);      
	    }    
	  });
	}    
    
    function controlcircles() {
    	//hide all circles
    	for (var i = 1; i <= 9; i++) {
    	document.getElementById('circle' + i).style.display = 'none';
    	}
    	//show just one circle
    	document.getElementById("circle" + circleid).style.display = "block";
    }
    
    function makecirclesmaller() {
    	//decrement the circleid
    	if (circleid > 1) {
    	circleid -= 1;
    	controlcircles();
    	}
    }
    
    function makecirclelarger() {
    	//decrement the circleid
    	if (circleid < 9) {
    	circleid += 1;
    	controlcircles();
    	}
    }

    function savejobticket(form) {
    	//are we in the service area?
    	var lng = map.getCenter().lng();
    	var lat = map.getCenter().lat();
    	var zoom = map.getZoom();
    	//check map clarity
    	if (zoom < 14) {
    		//alert('Please zoom in more so we can see your site better. If you cannot see all of your site in the map window, then your site is too large.  Please call 281-565-5600 for a free quote.');
    		alert('Please zoom in more so we can see your site better.');
    		return false;
    	}
    	//check site size
    	if (zoom == 14 && circleid > 4) {
    		alert('Your site is too large for our Standard Package price.  Please make the circle smaller, or call 281-565-5600 for a free quote.');
    		return false;
 		}
    	//check site location
    	if (lng > -93.405257) {
    		// too far east
    		alert('Your site is outside our Standard Package price area.  Please call 281-565-5600 for a free quote.');
    		return false;
    	}
    	if (lng < -98.991079) {
    		// too far west
    		alert('Your site is outside our Standard Package price area.  Please call 281-565-5600 for a free quote.');
    		return false;
    	}
    	if (lat > 33.324898) {
    		// too far north
    		alert('Your site is outside our Standard Package price area.  Please call 281-565-5600 for a free quote.');
    		return false;
    	}
    	if (lat < 25.790113) {
    	    // too far south
    		alert('Your site is outside our Standard Package price area.  Please call 281-565-5600 for a free quote.');
    		return false;
    	}
    	if (lat < 27.933106 && lng > -96.776663) {
   			// in the gulf
    		alert('Your site is outside our Standard Package price area.  Please call 281-565-5600 for a free quote.');
    		return false;
    	}
    	if (lat > 31.254157 && lng > -96.213928) {
   			// too far northeast
    		alert('Your site is outside our Standard Package price area.  Please call 281-565-5600 for a free quote.');
    		return false;
    	}
    	if (lat > 31.254157 && lng < -98.360095) {
   			// too far northwest
    		alert('Your site is outside our Standard Package price area.  Please call 281-565-5600 for a free quote.');
    		return false;
    	}
    	if (lat > 30.192746 && lng < -98.360095) {
   			// too far northwest
    		alert('Your site is outside our Standard Package price area.  Please call 281-565-5600 for a free quote.');
    		return false;
    	}
    	//build job ticket link
		var jobticket = "http://www.aerialphotopro.com/_private/jobticket.asp?Lat=" +lat;
		jobticket += "&Lng=" + lng;
		jobticket += "&Zoom=" + map.getZoom();
		jobticket += "&CircleID=" + circleid;
		//prompt("URL:", jobticket);
		document.getElementById("custom").setAttribute("value",jobticket);
    }

