function initMap() {
	var mcs=$('map-container').getCoordinates();
	geocoder = new google.maps.Geocoder();

	map = new google.maps.Map($('map-container'), myMapOptions);
}

function start(){
	initMap();
	markSearchResult();
}

function codeAddress(address,total) {
	var ax= address.split(',');
	var axs= "'"+ax[0]+','+ax[1]+', MÉXICO'+"'";
	
	try{
		console.log(ax);
		console.log(axs);
	}
	catch(err){
		
	}

	if (geocoder){
		geocoder.geocode( { 'address': axs}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
				var bgColor=getBgColor(address);

				var marker = new google.maps.Marker({
					map: map, 
					position: results[0].geometry.location,
					icon: new google.maps.MarkerImage('http://chart.apis.google.com/chart?chst=d_map_pin_letter_withshadow&chld='+total+'|'+bgColor+'|FFFFFF'),
					title: address,
					clickable:true
				});
				
				google.maps.event.addListener(marker, 'click', function(evt) {
					findRegistroByLoc(evt.target.title);
				});

				
			}
			else{
				//alert("Geocode was not successful for the following reason: " + status);
				try{
					console.log("Geocode was not successful for the following reason: " + status);
				}
				catch(err){}
			}
		});
	}
}

function getBgColor(address){
	var t1= address.split(', ');
	var c= bgEdo.get(t1[1]);
	if(c!=null) return c;
	return '7C7F06';

}

function markSearchResult(){
	var str= new Array();
	
	$$('div.locs').each(function(item, index){
		var val=1;
		
		if(locsx.has(item.get('text'))){
			val=locsx[item.get('text')]+1;
		}
		
		locsx.set(item.get('text'),val); 
	});
	
	var i=1;
	locsx.each(function(v,k){
		setTimeout("codeAddress('"+k+"',"+v+")",1000*i);
		i++;
	});
}

function markSearchResult2(){
	var str= new Array();
	
	$$('div.locs').each(function(item, index){
		var val=1;
		
		if(locsx.has(item.get('text'))){
			val=locsx[item.get('text')]+1;
		}
		
		locsx.set(item.get('text'),val); 
	});
	
	var i=1;
	locsx.each(function(v,k){
		setTimeout("codeAddress2('"+k+"',"+v+")",1000*i);
		i++;
	});
}

function codeAddress2(address,total) {
	if (geocoder){
		geocoder.geocode( { 'address': address}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
				var bgColor=getBgColor(address);
				
				var marker = new google.maps.Marker({
					map: map, 
					position: results[0].geometry.location,
					icon: new google.maps.MarkerImage('http://chart.apis.google.com/chart?chst=d_map_pin_letter_withshadow&chld='+total+'|'+bgColor+'|FFFFFF'),
					title: address,
					clickable:true
				});
				
				google.maps.event.addListener(marker, 'click', function(evt) {
					showInfo(evt.target,this.getPosition());
				});

				
			}
			else{
				//alert("Geocode was not successful for the following reason: " + status);
			}
		});
	}
}

