switch (location.hostname) {
	case 'www.paraelcole.com':
		var GM_KEY = new String("ABQIAAAAh3GTttbDMBqNWCHBaxDhPBRYILoVbVA8FBxnKW-BvzAO4udGcRTsE3jeMRdgNtHaS0PP2dLTCzK4DQ");
		break;
	case 'www.nucleo-paraelcole.com':
		var GM_KEY = new String("ABQIAAAAh3GTttbDMBqNWCHBaxDhPBRtDg8SRSAb3cY-7xMKqdkCcII5bxR2RFy_H2htMmuILXGWqod_pMv3pQ");
		break;
	case 'paraelcole.mailxmail.com':
		var GM_KEY = new String("ABQIAAAAh3GTttbDMBqNWCHBaxDhPBRD3yB80uxtn7djiIzleEJ4wo39lhTBT1HssKNI6fJChe4lPK_6q4Yztw");
		break;
	case 'paraelcole.nucleo-mailxmail.com':
		var GM_KEY = new String("ABQIAAAAh3GTttbDMBqNWCHBaxDhPBTLdJl2hifTSHnKahavdmOERRHuNBTzk2iANjUdopUdS8Cakfoow_wgKA");
		break;		
	case 'www.practicaidiomas.com':
			 var GM_KEY = new String("ABQIAAAAh3GTttbDMBqNWCHBaxDhPBTqc7JR7j43P-WFxTD58h8GNHsFUxR0O6VH04_eu_ju7jP43rLn295XVw");
			 break;
	case 'www.nucleo-practicaidiomas.com':
			 var GM_KEY = new String("ABQIAAAAh3GTttbDMBqNWCHBaxDhPBRVSenvZ6HsS6eHkGUuaRIXzHHYxhS6BIckuFsHRMHvKMJK1L7aybBqPw");
			 break;	 
	case 'practicaidiomas.nucleo-mailxmail.com':
			 var GM_KEY = new String("ABQIAAAAITvuQNhG2rzKlQEEqG7r_BTaeKOT3ebqu4A0i_kN-dIXwgKNoBQuv4C452PQvJR9hST3vq58nMsI2w");
			 break;
        case 'practicaidiomas.mailxmail.com':
			 var GM_KEY = new String("ABQIAAAAJFsy9KMx9hlb4gGZL-8pLhRveCNnnrxhcp3r_2NeTL6yDDrmEhQs6css_sLUnKUqVJKctOx-zWAEow");
			 break;
	case 'www.misidiomas.com':
			 var GM_KEY = new String("ABQIAAAAh3GTttbDMBqNWCHBaxDhPBQLuyzc0iBYVsUPRMMPsC3TYMy4nRTyLmMDbtosilxatpssPRO879NaYw");
			 break;
	case 'misidiomas.mailxmail.com':
			 var GM_KEY = new String("ABQIAAAAJFsy9KMx9hlb4gGZL-8pLhR7I6Ve_tWn0FTjrwTlu0VY9CJ4JRSx_danopXtFu7pjNj1qwnggtMDUw");
			 break;
	case 'www.nucleo-misidiomas.com':
			 var GM_KEY = new String("ABQIAAAAh3GTttbDMBqNWCHBaxDhPBQ2vx0qgagVhpggcnjmmjINAYdJsRQyMxmHidou2_bDWCL1Mnj2u56c7w");
			 break;
	case 'www.profesor-particular.com':
			 var GM_KEY = new String("ABQIAAAAlKPMYGetCASosS8oioy4WBQ9UK65HZycDbvJUTY6VtR9FJkr_hQ7qZdE2DqYUiGCSgmpuTYkpOp_PQ");
			 break;
	case 'www.nucleo-profesor-particular.com':
			 var GM_KEY = new String("ABQIAAAAlKPMYGetCASosS8oioy4WBTz8_BISzIA-sWRnj3juntdDdgwARSOjzSwyy5ltvEdZgYNvmkJJpcdtQ");
			 break;
	case 'www.tuwork.com':
		var GM_KEY = new String("ABQIAAAAt43tA9Bpyvf2LCItwoHZjhT84OXEjsngn1AeGxJYHZwL2ZFqiBRPGAMmDIsjioVRja9Mwbii9pgRvQ");
		break;
	case 'www.nucleo-tuwork.com':
		var GM_KEY = new String("ABQIAAAAt43tA9Bpyvf2LCItwoHZjhR54_ZH4-bk_N_aNNtFjkT40WFVdBSeeu80FO5pNxTdlp97GPJ5xaIRMQ");
		break;
	case 'www.nucleo-fxstreet.com':
		var GM_KEY = new String("ABQIAAAAt43tA9Bpyvf2LCItwoHZjhQSW81gbqJZOXRj_tn1TzilKMv4VhSgsM59yUTuNPu1UZ6qiclb343lVg");
		break;
	default:
		var GM_KEY = new String("ABQIAAAAh3GTttbDMBqNWCHBaxDhPBRYILoVbVA8FBxnKW-BvzAO4udGcRTsE3jeMRdgNtHaS0PP2dLTCzK4DQ");
		break;
}


var GM_lang = "es";
var GM_location = "";
var GM_charset = "iso-8859-1"; // UTF8 or iso-8859-1
var GM_address;
var GM_zip;
var GM_city;
var GM_province;
var GM_country;
var GM_city_ID;
var GM_province_ID;
var GM_country_ID;
var map = null;
var geocoder = null;
var GM_BIG_ZOOM = 15;
var GM_SMALL_ZOOM = 4;
var GM_ADDRESS = "Spain";



document.write('<script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;ie=' + GM_charset + '&amp;hl=' + GM_lang + '&amp;key=' + GM_KEY + '"></script>');


// -----------------------------------------------------------------------------
function GM_init() {
	map = new GMap2(document.getElementById("googleMap"));
	geocoder = new GClientGeocoder();
	map.addControl(new GMapTypeControl(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(3, 3)));
	map.addControl(new GSmallMapControl());
	map.enableDoubleClickZoom();
	map.enableContinuousZoom();
	map.setCenter(new GLatLng(37.4419, -122.1419), 5);
	return true;
}


// -----------------------------------------------------------------------------
function GM_reInitMap() {
	
	var location = new String('');	

	if (document.getElementById('googleMapBox').style.display == 'none')
		document.getElementById('googleMapBox').style.display = '';

	// if not loaded earlier
	GM_load();
	
	GM_province=GM_province.split('/')[0];
	GM_city=GM_city.split('/')[0];
	GM_country=GM_country.split('/')[0];
	
	
	GM_city = (GM_city_ID.match('TOD') != null) ? "" : GM_city;
	GM_province = (GM_province_ID.match('TOD') != null) ? "" : GM_province;
	GM_address = (GM_city == '' && GM_province == '') ? "" : GM_address;
	GM_country = (GM_country_ID.match('TOD') != null) ? "" : GM_country;
	
	switch (GM_country_ID) {
		case 'ESTADOSUNIDOS':
			GM_country = 'USA';
			break;
		case 'ESPANA':
			break;
		default:
			GM_zip = '';
			break;
	}
	
	location += (GM_address != '') ? GM_normalizeAddress(GM_address) + ", " : "";
	location += (GM_zip != '') ? GM_zip + ", " : "";
	location += (GM_city != '') ? GM_city + ", " : "";
	location += (GM_province != '') ? GM_province + ", " : "";
	location += (GM_country != '') ? GM_country : "";

	GM_findLocation(location);
	GM_location = location;
	
	/*
	alert(location);
	
	geocoder.getLatLng(location,
  		function showLocation(point) {
    		if (!point) {
      		alert(location + " no encontrado.");
    		} else {
    		alert(point);
      		map.setCenter(point, 17);
    		}
  	}
);*/
		
	return true;
}


// -----------------------------------------------------------------------------
function GM_displayMessage(msg) {
	if (document.getElementById("googleMapMessage")) {
		document.getElementById("googleMapMessage").innerHTML = '<p>' + msg + '</p>';
	}
	else if (document.getElementById("googleMapText")) {
		var elem = document.getElementById("googleMapText");
		var p = document.createElement("p");
		Element.extend(p);
		p.setAttribute("id", "googleMapMessage");
		// elem.appendChild(p);
		document.getElementById("googleMapText").insertBefore(p, document.getElementById("googleMapText").firstChild);
		p.innerHTML = msg;	
	}
	else {
		alert(msg);
	}
	return true;
}


// -----------------------------------------------------------------------------
function GM_addAddressToMap(response) {
	map.clearOverlays();
	if (!response || response.Status.code != 200) {
		map.setZoom(GM_SMALL_ZOOM);
		GM_displayMessage("Sorry, we were unable to geocode that address");
	} 
	else {
		place = response.Placemark[0];
		// note =  place.address + '<br />' + '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode;
		note = '';
		if (place.AddressDetails) {
			if (place.AddressDetails.Country) {
				if (place.AddressDetails.Country.AdministrativeArea) {
					if (place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea) {
						if (place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality) {
							if (place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare) {
								if (place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName) {
									note += place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName + '<br />';
								}
							}
							if (place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode) {
								if (place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode.PostalCodeNumber) {
									note += place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode.PostalCodeNumber + '<br />';
								}
							}
							if (place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName) {
								note += place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName + '<br />';
							}
						}
					}
				}
				if (place.AddressDetails.Country.CountryNameCode) {
					note += place.AddressDetails.Country.CountryNameCode + '<br />';
				}
			}
		}
		point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
		marker = new GMarker(point);
		map.panTo(point);
		// window.setTimeout(function() {map.setZoom(GM_BIG_ZOOM-1);}, 1000);
		map.setZoom(GM_BIG_ZOOM);
		/*
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(note);
		});
		GEvent.addListener(map, "mouseout", function() {
			map.closeInfoWindow();
		});
		*/
		map.addOverlay(marker);
	}
	return true;
}


// -----------------------------------------------------------------------------
function GM_showLocation(address) {
	// var address = document.forms[0].q.value;
	if (geocoder) {
		geocoder.getLocations(address, GM_addAddressToMap);
	}	
	return true;
}


// -----------------------------------------------------------------------------
function GM_findLocation(address) {
	// document.forms[0].q.value = address; // nur, wenn wir den text irgendwo ausgeben wollen
	GM_showLocation(address);
	return true;
}


// -----------------------------------------------------------------------------
function GM_load() {
	GM_init();
	GM_showLocation(GM_ADDRESS);
	return true;
}


// -----------------------------------------------------------------------------
function GM_gotoGoogle() {
	var linksArray = document.getElementById("googleMap").getElementsByTagName("a");
	//alert(decodeURIComponent(linksArray[1].getAttribute("href")).key);
	
	// sin prototype
	for (var i = 0; i < linksArray.length; i++){
		var linksString = linksArray[i].toString();		
		var dividido = linksString.split('&');	
		for (var k = 0; k < dividido.length; k++){
			if (dividido[k].match('key')){
				var llave = dividido[k];	
				var trozo = llave.split('=');
				var mikey = trozo[1];
			 if (mikey == GM_KEY){
			 window.open(linksArray[i].getAttribute("href") + "&q=" + GM_location, "_blank");	
			 return undefined;
				}
			}
		}
		
	}
	//con prototype
	/*for (var i = 0; i < linksArray.length; i++) {		
		if (linksArray[i].getAttribute("href").toQueryParams().key == GM_KEY) {
			window.open(linksArray[i].getAttribute("href") + "&q=" + GM_location, "_blank");
			return undefined;
		}
	}*/
	window.open("http://maps.google.com", "_blank");
	return undefined;
}


// -----------------------------------------------------------------------------
function GM_normalizeAddress(DIR) {
	/* Stolen from Inyaki :-) */
	
	DIR=String(DIR);
	//Eliminamos caracteres y palabras inecesarios.
	V=DIR.split(" No."); DIR=V.join(" ");
	V=DIR.split(" no."); DIR=V.join(" ");
	V=DIR.split("c/"); DIR=V.join(" ");
	V=DIR.split("C/"); DIR=V.join(" ");
	V=DIR.split("."); DIR=V.join(" ");
	V=DIR.split(","); DIR=V.join(" ");
	V=DIR.split("-"); DIR=V.join(" ");
	V=DIR.split("/"); DIR=V.join(" ");
	V=DIR.split("n�"); DIR=V.join(" ");
	V=DIR.split("N�"); DIR=V.join(" ");
	V=DIR.split("�"); DIR=V.join(" ");
	V=DIR.split("�"); DIR=V.join(" ");
	V=DIR.split("BIS"); DIR=V.join(" ");
	V=DIR.split("S/N"); DIR=V.join(" ");
	V=DIR.split("s/n"); DIR=V.join(" ");
	V=DIR.split("S/n"); DIR=V.join(" ");
	V=DIR.split("Calle"); DIR=V.join(" ");
	V=DIR.split("calle"); DIR=V.join(" ");
	V=DIR.split("carrer"); DIR=V.join(" ");
	V=DIR.split("Carrer"); DIR=V.join(" ");
	V=DIR.split("pl "); DIR=V.join(" ");
	V=DIR.split("Pl "); DIR=V.join(" ");
	V=DIR.split("P�"); DIR=V.join(" ");
	V=DIR.split("p�"); DIR=V.join(" ");
	V=DIR.split("paseo"); DIR=V.join(" ");
	V=DIR.split("Paseo"); DIR=V.join(" ");
	V=DIR.split("Paseig"); DIR=V.join(" ");
	V=DIR.split("paseig"); DIR=V.join(" ");
	V=DIR.split("Passeig"); DIR=V.join(" ");
	V=DIR.split("passeig"); DIR=V.join(" ");
	V=DIR.split("Av "); DIR=V.join(" ");
	V=DIR.split("AV "); DIR=V.join(" ");
	V=DIR.split("av "); DIR=V.join(" ");
	V=DIR.split("avd "); DIR=V.join(" ");
	V=DIR.split("Avd "); DIR=V.join(" ");
	V=DIR.split("AVD "); DIR=V.join(" ");
	V=DIR.split("Avenida"); DIR=V.join(" ");
	V=DIR.split("avenida"); DIR=V.join(" ");
	V=DIR.split("Avinguda"); DIR=V.join(" ");
	V=DIR.split("avinguda"); DIR=V.join(" ");
	V=DIR.split("    "); DIR=V.join(" ");
	V=DIR.split("  "); DIR=V.join(" ");
	V=DIR.split("  "); DIR=V.join(" ");
	V=DIR.split("  "); DIR=V.join(" ");
	
	// Cuando encuentra un numero elimina todo lo que queda.
	for (conti=0; DIR.charAt(conti); conti++ ) 
	{
		if ((DIR.charAt(conti)==parseInt(DIR.charAt(conti)))&&(DIR.charAt(conti+1)==' '))
		{
		DIR = DIR.substring(0,conti+1);
		break;
		}
	}	
	
	return DIR;
}

