<?xml version="1.0" encoding="UTF-8"?><Module>
<ModulePrefs title="SpotCrime" 
             description="The most comprehensive online source of crime information. Local maps, crime reports and classifications, real-time interactive maps."
             author="Nick Gauthier"
             author_email="nick@smartlogicsolutions.com"
             screenshot="http://spotcrime.com/mapplets/spotcrime_mapplet_logo-280x140.png"
             thumbnail="http://spotcrime.com/mapplets/spotcrime_mapplet_logo-120x60.png"
             height="1200">
  <Require feature="sharedmap"/>
  <Require feature="analytics"/>
  <Require feature="dynamic-height"/>
</ModulePrefs>
<Content type="html"><![CDATA[

    <style type='text/css'>
    	#signup-box-large__MODULE_ID__ {
			background: #c31d05 url('http://s3.spotcrime.com/media/style/spotcrime/signup-box-large-background.jpg') no-repeat;

			font-size: 20px;
			font-weight: bold;
			color: #FFF;
			border: 2px solid #DDDDDD;
			padding-left: 0px; 
			padding-top: 0.2em; 
			margin-top: 0em; 
    	}
    
    	#signup-box-large__MODULE_ID__ input{
			height: 24px;
			padding-left: 5px; 
			font-size: 16px;
    	}
    	#signup-box-large__MODULE_ID__ .mylabel{
    		width: 130px;
    		text-align: right;
    		float: left;
    		margin-right: 0.3em;
			color: #FFF;                                                           		
			font-size: 22px;
    	}
    	#signup-box-large__MODULE_ID__ .submitBtn{
    		margin: 0.2em 0 0 4.5em; 
    		padding: 0.1em; 
    		font-weight: bold; 
    		font-size: 20px;
		}    
    </style>

<div id="appContainer__MODULE_ID__" class="app__MODULE_ID__">

	<div id="signup-box-large__MODULE_ID__">
		<form id="signupForm__MODULE_ID__" method="post" action ="" onsubmit="return false;" style="margin:0; padding:0;">
			<input type="hidden" name="FormAction" value="Process">
			
			<div style="padding-left: 83px;">
			Get FREE Local Crime Alerts
			<br />
			<span style="padding-left: -83px;font-size: 14px; font-weight: normal;">Stay updated with inbox alerts for your neighborhood!</span>
			</div>

			<div style="padding-top: 0.1em; ">
				<div class="" style="clear:both;">
					<div class="mylabel"><label for="email" class="" style="">Email:</label></div>
					<input name="signup-email__MODULE_ID__" id="signup-email__MODULE_ID__" style="width: 200px;" value='' />
				</div>

				<div class="" style="clear:both;">
					<div class="mylabel" ><label for="password" class="">Password:</label></div>
					<input type="password" name="signup-password__MODULE_ID__" id="signup-password__MODULE_ID__" style="width: 200px;" value='' />
				</div>

				<div class="" style="padding-top: 0.1em; clear:both;">
					<div class="mylabel" ><label for="crime-alert-address" class="">Address:</label></div>
					<div style="float: left;">
						<textarea id="crime-alert-address__MODULE_ID__" name="crime-alert-address__MODULE_ID__" style="margin:0; width: 200px;" onfocus="if (this.value == 'e.g. 100 Main Str, Baltimore, MD')  this.value = '';">e.g. 100 Main Str, Baltimore, MD</textarea>
						<p style="padding-top: 0; font-size: 12px; font-weight: normal; color: #CCC; margin:0; padding:0;">
						Please include Street and City,<br />State or Zip code
						</p>
					</div>

				</div>

				<button type="submit" class="submitBtn">SIGN UP FREE!</button>
			</div>				
		</form>


		<!-- 
		<div id="spotcrime-blotter-get-local-crime-alerts" style="height: 24px; background: #C42127 url(http://spotcrime.s3.amazonaws.com/widgets/crimeticker/1.0/media/images/get-local-crime-alerts.png) no-repeat scroll center top;">
		<a target="_blank" href="http://www.spotcrime.com/account.php" style="display: block; height: 100%; text-decoration: none;"></a>
		</div>

		<div id="spotcrime-blotter-map-container" style="background: #ffffff url(http://spotcrime.s3.amazonaws.com/widgets/crimeticker/1.0/media/images/map.png) no-repeat center top; padding: 33px 51px 0; text-align: center;">

		<br/><br/>
		<a title="Powered by SpotCrime" href="http://www.spotcrime.com/">

		<img src="http://spotcrime.s3.amazonaws.com/widgets/crimeticker/1.0/media/images/powered-by-spotcrime.png" alt="Powered by SpotCrime" width="145" height="17" border="0"></a>

		</div>

		-->

		<div id="content_div" style="font-size: 12px; font-weight: normal; border: 1px solid #C4BCBD; height: 107px; padding: 2px; margin: 2px 9px 0px; overflow-x: hidden; overflow-y: auto; background-color: white;">
		Loading...
		</div>

		<div style="margin: 5px auto; text-align: center;">
		<a href="http://www.addthis.com/bookmark.php" onclick="url = location.href; url = url.substring(url.indexOf('url=')+4); url = url.substring(0, url.indexOf('&')); addthis_url = 'http://www.google.com/ig/adde?moduleurl='+url+'&source=imag'; addthis_title = 'Add SpotCrime.com to your Google Homepage'; return addthis_click(this);" target="_blank"><img src="http://s9.addthis.com/button1-share.gif" width="125" height="16" border="0" alt="Bookmark and Share" />
		</a>
		</div>


	</div>

</div>

<script type="text/javascript">
		var addthis_pub = 'cdrane';
</script>
<script type="text/javascript" src="http://s9.addthis.com/js/widget.php?v=10"></script>

<script>
	_IG_Analytics("UA-3370515-3", "/mapplet-blotter");

  // Variables //
  // changing map will cancel subsequent asynchronous calls if the map has been changed since then
  var changing_map = false;
  // whether or not we have already sent an xml request
  var waiting_for_content = false;

  // array of the crime markers already on the map, so we can skip them
  var old_crimes = [];

  var map;
  var icon_types;
  var icon_urls;
  var icon_sizes;
  var icon_list;

  try {
    // init map
    map = new GMap2();
    
    // create icons
    createIcons();
      
    // Listen for events
    GEvent.addListener(map, "dragend", refreshMap);
    GEvent.addListener(map, "zoomend", refreshMap);
    function map_change(event) {
      changing_map = true;
    }
    GEvent.addListener(map, "dragstart", map_change);
    GEvent.addListener(map, "zoomstart", map_change);
    // Center map and load points
        refreshMap();
  } catch(err) {
    // If we error, then we are a gadget
    //alert("gadget");
    _gel("content_div").innerHTML = "<i>Loading Recent Crimes ...</i>";
    loadGadgetData();
  }
  
  function createIcons() {
    var icon_template = new GIcon(G_DEFAULT_ICON);
    //  icon_template.iconSize = new GSize(45,35);
    icon_template.shadowSize = new GSize(0,0);
    icon_types = ['arson.png','assault.png','burh.png','default.png','handcuffs.png',
                      'other.png','robber.png','shoot.png','theft.png','vandalism.png'];
    icon_urls = ['arson-30x25.png', 'assault-30x25.png', 'burh-20x25.png', 'default-30x25.png', 'handcuffs-25x25.png',
                     'other-20x25.png', 'robber-30x25.png', 'shoot-25x25.png', 'theft-35x30.png', 'vandalism-30x25.png'];
    icon_sizes = [[30,25], [30,25], [20,25], [30,25], [25,25], 
                      [20,25], [30,25], [25,25], [35,30], [30,25]];
    icon_list = [];
    for (var i in icon_types) {
      var current = new GIcon(icon_template);
      current.image = 'http://www.spotcrime.com/media/icon/'+icon_urls[i];
      current.iconSize = new GSize(icon_sizes[i][0], icon_sizes[i][1]);
      current.iconAnchor = new GPoint(icon_sizes[i][0]/3.0, icon_sizes[i][1]);
      icon_list.push([icon_types[i],current]);
    }
  }
  
  function loadGadgetData() {
    var url = 'http://www.spotcrime.com/mapplets/mapplet_data.php?';
    url += 'sw_lat=22.0';
    url += '&sw_lng=-128.0';
    url += '&ne_lat=51.0';
    url += '&ne_lng=-63.0';
    _IG_FetchXmlContent(url, function (response) {
      if (response == null || typeof(response) != "object" || 
                response.firstChild == null) {
        _gel("content_div").innerHTML = "<i>No Crimes Found</i>";
        return;
      }
      var crimeList = response.getElementsByTagName("Crime");
      
      if (crimeList.length == 0) {
        _gel("content_div").innerHTML = "<i>No Crimes Found</i>";
        return;
      }
      
      _gel("content_div").innerHTML = "";
              
      var crime_table_data = '';
      var crime_table_data_style = 'border-bottom: 1px solid #E7E6E6; color: #585959;';
      crime_table_data_style += 'font-family: Arial,Helvetica,sans-serif;';
      crime_table_data_style += 'font-size: 9pt; height: auto; overflow: hidden; padding: 2px 4px;';
      crime_table_data_style += 'text-align: left; white-space: nowrap;';
      

      // Parse crimes
      for (var i = 0; i < crimeList.length && i < 5; i++) {
        var nodeList = crimeList.item(i).childNodes;
        var id, title, description, address, latitude, longitude, date, icon;
        for (var j = 0; j < nodeList.length; j++) {
          var node = nodeList.item(j);
          if (node.nodeName == "ID") {
            id = node.firstChild.nodeValue;
          }
          if (node.nodeName == "Title") {
            title = node.firstChild.nodeValue;
          }
          if (node.nodeName == "Description") {
            description = node.firstChild.nodeValue;
          }
          if (node.nodeName == "Address") {
            address = node.firstChild.nodeValue;
          }
          if (node.nodeName == 'Latitude') {
            latitude = node.firstChild.nodeValue;
          }
          if (node.nodeName == 'Longitude') {
            longitude = node.firstChild.nodeValue;
          }
          if (node.nodeName == 'Date') {
            date = node.firstChild.nodeValue;
          }
          if (node.nodeName == 'Icon') {
            icon = node.firstChild.nodeValue;
          }
        }
        
        crime_table_data += '<div style="'+crime_table_data_style+'">';
        crime_table_data += '<a href="http://www.spotcrime.com/crime/'+id+'" target="_blank">';
        crime_table_data += '<span style="font-size: smaller;">'+date+'</span><br/>';
        crime_table_data += address+'</a></div>';
        
      }
      _gel("content_div").innerHTML = crime_table_data;
    });
  }

  // Refresh the points on the map
  function refreshMap() {
    changing_map = false;
    _gel("content_div").innerHTML = "<i><b>Loading Data ... Please Wait</b></i>";
    map.getBoundsAsync(function (glatlng) {
      if (changing_map == true) {
        return;
      }
      var sw = glatlng.getSouthWest();
      var sw_url = "sw_lat="+sw.lat()+"&sw_lng="+sw.lng();
      var ne = glatlng.getNorthEast();
      var ne_url = "ne_lat="+ne.lat()+"&ne_lng="+ne.lng();
      
      var url='http://www.spotcrime.com/mapplets/mapplet_data.php?'+sw_url+"&"+ne_url;
      
      if(waiting_for_content) {
        return;
      }
      waiting_for_content = true;
      _IG_FetchXmlContent(url, function (response) {
        waiting_for_content = false;
        if (changing_map == true) {
          return;
        }
        if (response == null || typeof(response) != "object" || 
                  response.firstChild == null) {
          _gel("content_div").innerHTML = "<i>There are no crimes for this view. Move or zoom the "+
            "map to find some crimes</i>";
          return;
        }
        var crimeList = response.getElementsByTagName("Crime");
        
        if (crimeList.length == 0) {
          _gel("content_div").innerHTML = "<i>There are no crimes for this view. Move or zoom the "+
            "map to find some crimes</i>";
          return;
        }
        
        _gel("content_div").innerHTML = "";
                
        var crime_table_data = '';
        var crime_table_data_style = 'border-bottom: 1px solid #E7E6E6; color: #585959;';
        crime_table_data_style += 'font-family: Arial,Helvetica,sans-serif;';
        crime_table_data_style += 'font-size: 9pt; height: auto; overflow: hidden; padding: 2px 4px;';
        crime_table_data_style += 'text-align: left; white-space: nowrap;';

        // Parse crimes
        for (var i = 0; i < crimeList.length; i++) {
          var nodeList = crimeList.item(i).childNodes;
          var id, title, description, address, latitude, longitude, date, icon;
          for (var j = 0; j < nodeList.length; j++) {
            var node = nodeList.item(j);
            if (node.nodeName == "ID") {
              id = node.firstChild.nodeValue;
            }
            if (node.nodeName == "Title") {
              title = node.firstChild.nodeValue;
            }
            if (node.nodeName == "Description") {
              description = node.firstChild.nodeValue;
            }
            if (node.nodeName == "Address") {
              address = node.firstChild.nodeValue;
            }
            if (node.nodeName == 'Latitude') {
              latitude = node.firstChild.nodeValue;
            }
            if (node.nodeName == 'Longitude') {
              longitude = node.firstChild.nodeValue;
            }
            if (node.nodeName == 'Date') {
              date = node.firstChild.nodeValue;
            }
            if (node.nodeName == 'Icon') {
              icon = node.firstChild.nodeValue;
            }
          }
          
          var is_an_old_crime = false;
          for (old in old_crimes) {
            if (old_crimes[old] == id) {
              is_an_old_crime = true;
            }
          }
          if (!is_an_old_crime) {
            old_crimes.push(id);
            // find the icon
            var marker_icon = G_DEFAULT_ICON;
            for (icon_index in icon_list) {
              if (icon_list[icon_index][0] == icon) {
                marker_icon = icon_list[icon_index][1];
              }
            }
            
            // Add the crime to the map
            var mark = new GMarker(new GLatLng(latitude, longitude), {icon:marker_icon});
            map.addOverlay(mark);
            mark.bindInfoWindow(
              '<h3>'+title+'</h3>'+
              '<small>'+address+' on '+date+'</small>'+
              '<p>'+description+
              '... <small>[<a href="http://www.spotcrime.com/crime/'+id+'">read more</a>]</small></p>'
            );
          }
          crime_table_data += '<div style="'+crime_table_data_style+'">';
          crime_table_data += '<a href="http://www.spotcrime.com/crime/'+id+'" target="_blank">';
          crime_table_data += '<span style="font-size: smaller;">'+date+'</span><br/>';
          crime_table_data += address+'</a></div>';
        }
        changing_map = false;
        _gel("content_div").innerHTML = crime_table_data+"</p>";
      });
    });
  }
  
	// Run everything in a private namespace
	(function() {

		var apiUrl = "http://spotcrime.com/mapplets/saferouter/api/signup.php";

		function $(e) {
			return document.getElementById(e);
		}


    	// Validate signup box
    	function initSignup() {
			/**
			* Trims any whitespace from either side of a string.
			*/
			function trim(value){
				return String(value).replace(/^\s+|\s+$/g, "");
			}

			/**
			* Validate an email addresses.
			*/
			function isEmail(v){
				var e = /^(\w+)([-+.][\w]+)*@(\w[-\w]*\.){1,5}([A-Za-z]){2,4}$/;
				return  e.test(v);
			}

    		// Focus email input
    		if ($('signup-email__MODULE_ID__')) $('signup-email__MODULE_ID__').focus()
    		

	    	
	    	// Validate form on submit
	    	$('signupForm__MODULE_ID__').onsubmit = function(e) {
				_IG_Analytics("UA-3370515-3", "/mapplet-blotter-signup-click");
	    		var errors = [];
				// validate email
				if (trim($('signup-email__MODULE_ID__').value) == '') {
					errors.push({message:"Email required.", el: 'signup-email__MODULE_ID__'});
				}
				else 
				if (!isEmail($('signup-email__MODULE_ID__').value)){
					errors.push({message:'Email address is invalid. It should be in the "user@example.com" format.', el: 'signup-email__MODULE_ID__'});
				}

				// validate password
				if (trim($('signup-password__MODULE_ID__').value) == '') {
					errors.push({message:"Password required.", el: 'signup-password__MODULE_ID__'});
				}
				// Validate address
				var addrElement = $('crime-alert-address__MODULE_ID__');
				if (
					(trim(addrElement.value) == 'e.g. 100 Main Str, Baltimore, MD') ||
					(trim(addrElement.value) == '')
				) {
					//addrElement.style.color = 'red';
					errors.push({message:"Address required.", el: 'crime-alert-address__MODULE_ID__'});
					//Set a blank address
					addrElement.value = '';
				}

				if (errors.length > 0) {
					var errorsTxt = [];
					for (var i=0, l=errors.length; i<l; i++) {
						errorsTxt.push(errors[i].message);
						$(errors[i].el).style.background = '#fff195';
					}
					$(errors[0].el).focus(); // Move focus
					alert(errorsTxt.join("\n"));

					// Do not submit form
					return false;
				}
				else {
					// Submit form

					_IG_FetchContent(apiUrl + 
						'?site=BlotterMapplet&signup-email=' + encodeURIComponent($('signup-email__MODULE_ID__').value) + 
						'&signup-password=' + encodeURIComponent($('signup-password__MODULE_ID__').value) + 
						'&crime-alert-address=' + encodeURIComponent($('crime-alert-address__MODULE_ID__').value)+
						'&nc=' + encodeURIComponent((new Date().getTime())), 
						function(response) {

							if (trim(response) != '') {
								alert(response); 
							}
							else {
								alert("Thanks you!\nCheck your inbox for a confirmation email.");
								_IG_Analytics("UA-3370515-3", "/mapplet-blotter-account-created");
							}
						}
					);


					// do not submit form
    	            return false;

				}
    		}

    	}

    	initSignup();
	})();

</script>

]]></Content>
</Module>

