function validateAddCrime()
{
	
	// Check if lan is choosen
	var lanIndex = document.getElementById("lan").selectedIndex;
	var lanValue = document.getElementById("lan").options[lanIndex].value;
	if(!checkFieldEmpty(lanValue, "lan"))
	{
		Form.errors = 1;
		Form.emptyFields = 1;
	}
	
	// Check if kommun is choosen
	var kommunIndex = document.getElementById("kommun").selectedIndex;
	var kommunValue = document.getElementById("kommun").options[kommunIndex].value;
	if(!checkFieldEmpty(kommunValue, "kommun"))
	{
		Form.errors = 1;
		Form.emptyFields = 1;
	}
	
	// Check if crime type is choosen
	var crimeTypeIndex = document.getElementById("crimeTypeID").selectedIndex;
	var crimeTypeValue = document.getElementById("crimeTypeID").options[crimeTypeIndex].value;
	if(!checkFieldEmpty(crimeTypeValue, "crimeTypeID"))
	{
		Form.errors = 1;
		Form.emptyFields = 1;
	}
	
	// Check if headline is choosen
	if(!checkFieldEmpty(document.getElementById("headline").value, "headline"))
	{
		Form.errors = 1;
		Form.emptyFields = 1;
	}
	
	// Check if description is choosen
	if(!checkFieldEmpty(document.getElementById("description1").value, "description1"))
	{
		Form.errors = 1;
		Form.emptyFields = 1;
	}

	
	
	// Check if place is choosen
	if(!checkFieldEmpty(document.getElementById("place").value, "place"))
	{
		var adress = confirm("Du har inte fyllt i någon adress, din efterlysning kommer inte att synas på kartan. Är du säker på att du vill fortsätta?");
		if (!adress) {
			Form.errors = 1;
			Form.emptyFields = 1;
		}
	}
	
	// Check that enddate is bigger (or equal to) then startdate
	var startDate = document.getElementById("startYear").value + "" + document.getElementById("startMonth").value + "" + document.getElementById("startDay").value;
	var endDate = document.getElementById("endYear").value + "" + document.getElementById("endMonth").value + "" + document.getElementById("endDay").value;
	
	if(startDate > endDate)
	{
		Form.errors = 1;
		document.getElementById("validatedate").setAttribute("src", "images/no.png");
	}
	else
	{
		document.getElementById("validatedate").setAttribute("src", "images/ok.png");
	}
}

function showHideEndDate()
{
	if(document.getElementById("endDateSpan").style.display == "none")
	{
		document.getElementById("endDateSpan").style.display = "";
		document.getElementById("viewTimeSpan").style.display = "none";
	}
	else
	{
		document.getElementById("endDateSpan").style.display = "none";
		document.getElementById("viewTimeSpan").style.display = "";
	}
}

function showHideTime()
{
	if(document.getElementById("timeSpan").style.display == "none")
	{
		document.getElementById("timeSpan").style.display = "";
		document.getElementById("viewEndDateSpan").style.display = "none";
	}
	else
	{
		document.getElementById("timeSpan").style.display = "none";
		document.getElementById("viewEndDateSpan").style.display = "";
	}
}

function showPicturesTable()
{
	document.getElementById("picturesTable").style.display = "";
}

function hidePicturesTable()
{
	document.getElementById("picturesTable").style.display = "none";
}

function showInfoMsg()
{
	document.getElementById("rewardInfoDiv").style.display = "";
}

function hideInfoMsg()
{
	document.getElementById("rewardInfoDiv").style.display = "none";
}

function showSignalment()
{
	document.getElementById("signalment").style.display = "";
}

function hideSignalment()
{
	document.getElementById("signalment").style.display = "none";
	document.getElementById("signalment").value = "";
}


var map = "";
var markers = new Array();
var newMarker = new google.maps.Marker({
     
	});
function initializeMap() {
	var lcLat =  61.5042;
	var lcLng =  17.4200;
	
	var localCenter = new google.maps.LatLng(Number(lcLat),Number(lcLng));
	
	
	var myOptions = {
	      zoom: 4,
	      center: localCenter,
	      mapTypeId: google.maps.MapTypeId.ROADMAP
   	};
	map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	newMarker.setPosition(localCenter); 
    newMarker.setMap(map);
    newMarker.setTitle("Händelsens position");
	newMarker.setVisible(false);
	
	
	google.maps.event.addListener(map, 'click', function(event) {
		var myLatlng = event.latLng;
		placeNewMarker(myLatlng, 16);
	});
	markAddress();
		
}
function placeNewMarker(coords, zoom){
	var myLatlng = new google.maps.LatLng(Number(coords.lat()),Number(coords.lng()));
		newMarker.setPosition(myLatlng);
		newMarker.setVisible(true);
		map.setCenter(myLatlng);
		map.setZoom(zoom);
		var myLatLngShort = myLatlng.toUrlValue().split(",");
		jQuery("#latitude").val(myLatLngShort[0]);
		jQuery("#longitude").val(myLatLngShort[1]);
}

function markAddress(){
	var address = document.getElementById("place").value;
	var selected = jQuery("#kommun option:selected");
	if(selected.val() != 0){
		   var kommun = selected.text();
	}else{
		kommun = "";
	}
	
	findCoord(address, kommun);
}
function findCoord(address, kommun){
	geocoder3 = new google.maps.Geocoder();
	geocoder3.geocode( { "address": address+","+kommun+", sverige"}, function(results, status3) {
		if (status3 == google.maps.GeocoderStatus.OK) {
			var c = results[0].geometry.location;
			placeNewMarker(c, 14);
		}else{
			geocoder3.geocode( { "address": "sverige"}, function(results, status3) {
				if (status3 == google.maps.GeocoderStatus.OK) {
					var c = results[0].geometry.location;
					placeNewMarker(c, 3);
				}else{
					alert("Error:"+status3);
				}
			});
		}
			
	});
}

function showMapLink(){
	jQuery("#confirmMapLink").show();
}

jQuery(document).ready(function() {
	jQuery("#confirmMapLink").click(function() {
		jQuery("#mapContainer").slideDown(function(){
			if (map==""){
				initializeMap();
			}
			
		});
	});
		
	jQuery("#saveLink").click(function() {
		jQuery("#mapContainer").slideUp();

	});
		
});
