﻿function show(id) {
	for (i=0;i<30;i++) {
		var _tab = document.getElementById("tabp_" + i);
		var _tab2 = document.getElementById("tabp2_" + i);
		var _pest = document.getElementById("pest_" + i);
		if (_tab!=null) _tab.style.display = (id==i) ? 'block' : 'none';
		if (_tab2!=null) _tab2.style.display = (id==i) ? 'block' : 'none';
		if (_pest!=null) _pest.className = (id==i) ? 'selected' : '';
	}
};


////////////////
////// GOOGLE MAPS 
////////////
//var map_g;
var map_width = 940;
var map_height = 500;
function map_zoom_to_points_g(map_g, points,zoom,isS) {
    if (points.length > 0) {
        var bounds = new GLatLngBounds();
        for (var i = 0; i < points.length; i++) {
            bounds.extend(points[i]);
        }
        var center = bounds.getCenter();
        var zoom_level = map_g.getBoundsZoomLevel(bounds);
        //map_g.setZoom(zoom_level);
		map_g.setZoom(zoom);
        map_center_g(map_g, _lat(center)+isS, _lon(center));
    }
}

function _lat(point) {
    return point.lat();
}
function _lon(point) {
    return point.lng();
}

function new_point(lat, lon) {
    var point = new GLatLng(lat, lon);
    return point;
}


function createMarker(point, id) {
	var oIcon = new GIcon(G_DEFAULT_ICON);
	oIcon.image = "skin/images/ama_dot.png";
	oIcon.iconSize = new GSize(39, 26);
	oIcon.shadow = "skin/images/ama_dot_shadow.png";
	oIcon.shadowSize = new GSize(53, 26);

    var marker = new GMarker(point, { icon:oIcon});
    var sHTML = generateHtml(id);
    GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(sHTML, { maxWidth: 450 }); });    
    return marker;
}

function map_center_g(map_g, lat, lon) {
    map_g.panTo(new_point(lat, lon));
}

function initialize_g(map_g,zId,mW,mH,zoom,isS) {
    var locs_g = new Array;
    if (GBrowserIsCompatible()) {
        map_g = new GMap2(document.getElementById("map_oficinas_" + zId), { size: new GSize(mW, mH) });
        map_g.setCenter(new GLatLng(40.346544, -3.713379), 2);
		
        map_g.addControl(new GSmallMapControl())
        map_g.addControl(new GMapTypeControl());
		
        var points_g = document.getElementsByName("puntos_google_" + zId);
        for (var i = 0; i < points_g.length; i++) {
			try {
				var point = points_g[i].value.split(',');
				var Gpoint = new GLatLng(point[0], point[1]);
				var marker = createMarker(Gpoint, point[2]);
				map_g.addOverlay(marker);
				locs_g.push(new_point(point[0], point[1]));
			} catch (ex) { }
        }
        map_zoom_to_points_g(map_g, locs_g,zoom,isS);
		
    }
}

function generateHtml(id) {
	if (id==null) return;
    var sHTML = '<div class="bocata_map">';
    sHTML += '<h2 class="bocata_map_title">' + document.getElementById("nom_" + id).value + '</h2>';
    sHTML += '<p>' + document.getElementById("dir_" + id).value + '</p>';
    sHTML += '<p>' + document.getElementById("pob_" + id).value + ' (' + document.getElementById("prov_" + id).value + ')</p>';
    sHTML += '<p>' + document.getElementById("pais_" + id).value + '</p>';
    sHTML += '<p>Telf: ' + document.getElementById("telf_" + id).value + '</p>';
    sHTML += '<p><a href="oficina.html?id=' + id + '">acceder a la ficha</a></p><br/>';
    sHTML += '</div>';
    return sHTML;
}


function ShowForm() {
    tb_show('Solicitar más informaciÓn', '##TB_inline?height=300&width=300&inlineId=pnl_form&modal=true', false);    
}

/** JMEP 30-06-2009 -- función para cambiar el action del form de la home (login)**/
function userExtForm() {
	document.InmediaFrm.action='https://mutualistas.amaseguros.com/menu.asp?obtener_nombre=si';

}

function kH(e) {
var pK = e? e.which: window.event.keyCode;
if (pK == 13 ){
  return objJS_203.doSearch('{$url_web_search}');
}    
}
document.onkeypress = kH;
