/*Funcion de carga al incio */
function load() {
    if (GBrowserIsCompatible()) {
				var map = new GMap2(document.getElementById("map"));
				map.setCenter(new GLatLng(40.307624,-3.89851), 15);
				map.addControl(new GSmallZoomControl());
				//map.addControl(new GMapTypeControl()); 
		    map.setMapType(G_HYBRID_MAP);
				var point = new GPoint (-3.89851,40.307624);

		   
				
		   var marker = new GMarker(point);
		   var nombre = "Globalbox";
		   var dir = "Antigua Ctr. Extremadura, Km 21";
		   var codigo = "28935 - ";
		   var ciudad="MOSTOLES";
		   var tfno = "916 854 225";
		   var marker = createMarker (point, nombre, dir, codigo, ciudad, tfno);
		   map.addOverlay(marker); 
 
		}
}

/*Funcion que crea el Globo inicial */
function createMarker(point, nombre, dir, codigo, ciudad, tfno) {
			var marker = new GMarker(point);
         GEvent.addListener(marker, 'click', function() {
          marker.openInfoWindowHtml("<div id='divLogo' style='font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal;line-height: normal;font-weight: normal;font-variant: normal;text-transform: none;color: #666666;text-decoration: none; text-align:left;'><img src='img/globalbox.gif' alt='GlobalBox' vspace='5' /></div><div id='divCuerpo' style='padding-left:5px;font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal;line-height: normal;font-weight: normal;font-variant: normal;text-transform: none;color: #666666;text-decoration: none; text-align:left;'>"+ dir +"<br />"+ codigo+ "<span style='font-weight: bold;'>"+ciudad +"</span><br /><br />Tel.: <span style='font-weight: bold;'>"+ tfno +"</span> - <a href=\"javascript:mostrarForm('" + dir + "','"+codigo+"','"+ciudad+"','"+tfno+"');\" style='font-weight:bold'>Cómo Llegar</a></div>");
       });
      return marker;
}

/*Funcion que muestra el formulario de busqueda */
function mostrarForm(dir, codigo, ciudad, tfno) {
		document.getElementById("divLogo").style.display = "none";
		ffrom = 'Desde..';
		fstreet = 'Calle';
		fnumber = 'Nº';
		fcity = 'Ciudad';
		fzip = 'C.P.';
		document.getElementById("divCuerpo").innerHTML = "<form name='llegar' method='post'><table cellpadding=\"3\" cellspacing=\"0\" width=\"100%\"><tr><td colspan=\"4\"><span style='font-weight:bold'>CÓMO LLEGAR</span></td></tr><tr><tr><td colspan=\"4\"><b>"+ffrom+"</b></td></tr><tr><td>"+fstreet+":</td><td><input id='dir' type='text' size='15' style='border:#CCCCCC 1px solid;font-size:10px;background-color:white; width:85px;' /></td><td>"+fnumber+":</td><td><input id='num' type='text' maxlength='4' size='5' style='border:#CCCCCC 1px solid;font-size:10px;background-color:white;width:30px;' /></td></tr><tr><td>"+fcity+":</td><td colspan=\"3\"><input id='ciudad' type='text' size='15' style='border:#CCCCCC 1px solid;font-size:10px;background-color:white; width:85px;' /></td></tr><tr><td>"+fzip+":</td><td><input id='cp' type='text' maxlength='5' size='5' style='border:#CCCCCC 1px solid;font-size:10px;background-color:white;width:45px;' /></td><td colspan=\"2\" rowspan=\"2\"align=\"right\"><img src=\"img/boton_como_llegar.png\" onclick=\"javascript:enviar();\" style=\"cursor:pointer;\" /></td></tr><tr><td colspan=\"2\"><br><a style=\"color:#999999;\" href=\"javascript:mostrarInicio('" + dir + "','"+codigo+"','"+ciudad+"','"+tfno+"');\"><b>&laquo;Volver</b></a></td></tr></table></form>";
}
/*Funcion que muestra la pantalla inicial */
function mostrarInicio(dir, codigo, ciudad, tfno) {
	document.getElementById("divLogo").style.display = "block";
	document.getElementById("divCuerpo").innerHTML = ""+ dir +"<br />"+ codigo+ "<span style='font-weight: bold;'>"+ciudad +"</span><br /><br />Tel.: <span style='font-weight: bold;'>"+ tfno +"</span> - <a href=\"javascript:mostrarForm('" + dir + "','"+codigo+"','"+ciudad+"','"+tfno+"');\" style='font-weight:bold'>Cómo Llegar</a>";
}
/*Funcion que recibe los datos del formulario de busqueda,  y llama a la funcion que abre el popup*/
function enviar(){
		var lat = "40.307624";
		var lng = "-3.89851";
		var lang = "es";
		var warehouse = "MOSTOLES";
		var city = "MOSTOLES";
		var title_reaching = "Cómo llegar: ";
 		var f = document.forms.llegar;
 		var error = false;
 		if ( !error & f.dir.value == '' ){
 			alert("Debe especificar una dirección válida.");
 			error = true;
 		}
 		if ( !error & f.ciudad.value ==''){
      alert("Debe especificar una ciudad válida");
 			error = true;
 		}
 		if (!error){
 			maplink = 'http://maps.google.com/maps?f=d&hl='+lang+'&saddr='+f.dir.value+'+'+f.num.value+'+'+f.cp.value+'+'+f.ciudad.value+'&daddr='+lat+','+lng;
 			show_map_div(maplink, warehouse, city, title_reaching, "es");
 		}
 	}

/*Funcion que muestra el popup de google*/	
function show_map_div(maplink, warehouse, city, title_reaching, lang) {
	//rem_el('map_div');
	var map_div = document.getElementById('map_div');
	if ( !map_div ) {
		map_div = document.createElement('div');
		map_div.style.position = 'absolute';
		map_div.align='center';
		map_div.id = 'map_div';
		map_div.style.padding='20px';
		map_div.style.border='3px solid #cccccc';
		map_div.style.backgroundColor='#fff';
		map_div.style.width = '782px';
		//map_div.style.height = '500px';
		map_div.style.display = 'none';
		map_div.style.zIndex = 100;
		map_div.style.left =  (parseInt((document.body.offsetWidth - 782)/2)-20) + 'px';
		map_div.style.top = '0px';
		document.body.appendChild( map_div );
		
	}
		map_div.innerHTML = "<table width=\"100%\" style=\"border-bottom:2px solid #0066cc;margin-bottom:10px;\"><tr><td align=\"left\" style=\"padding-bottom:10px\"><h1 class=\"big\">"+title_reaching+" Globalbox "+warehouse+" </h1></td><td align=\"right\" valign=\"top\"><div onclick=\"close_map_div();\" style=\"cursor:pointer;\"><img src=\"images/close_"+lang+".png\" /></td></tr></table>";
		map_div.innerHTML += "<iframe src=\""+maplink+"\" width=\"100%\" height=\"550\" frameborder=\"0\"></iframe>";
		map_div.style.display='block';
}
/*Funcion que cierra el popup */
function close_map_div() {
	document.getElementById('map_div').style.display='none';
}

	

    
