﻿var esIE = false
//Detectar el navegador explorer 5.01
if (navigator.appVersion.indexOf("MSIE") != -1) { esIE = true;}
swIE501 = (navigator.appVersion.indexOf("5.01") == (-1))?1:0;
//Detectar el navegador explorer 5.5
swIE55 = (navigator.appVersion.indexOf("5.5") != -1)?1:0;
//Se detecta si es opera
esOpera = (navigator.userAgent.indexOf("Opera") !=-1)?1:0;
//Se sobre escribe el estilo para los casos que tenga Javascript
var newStyle = "<style>"; var endStyle = "</style>";
//todos los navegadores menos intenet explorer 5.01
if (swIE501) { newStyle += ".bloqueDestacados { border:0;width:100%;}";}
else { newStyle += ".ListCentro.class03 #contenidosBox{width:20.1em;}";}
document.write(newStyle+endStyle);

var rounded = {
	corners:function(obj)
	{
		innerContenedora = obj.innerHTML;
		//Declaraccion de las capas de de cierre superior
		objUp = '<div class="b"><div class="l"><div class="r"><div class="t"><div id="bl" class="bl"><div id="br" class="br"><div class="tl"><div class="tr">';
		//Cierres de los div de las capas de border
		objDown = '</div></div></div></div></div></div></div></div>';
		newContenedora = objUp+innerContenedora+objDown;
		obj.innerHTML = newContenedora;
	}
}
var vWindow = {
	/*
		url:direccion de la pagina
		target:donde queremos abrir la pagina
		w: ancho
		h: alto
		l: posiccion respecto a la izquierda de la ventana
		t: posiccion respecto al top de la ventana
		s: scroll
		tb: toolbar
		mb: menu bar
	*/
	abrir:function(url,target,w,h,l,t,s,tb,mb)
	{
		ventana = window.open (url,target,"width="+w+",height="+h+",left="+l+",top="+t+",scrollbars="+s+",toolbar="+tb+",menubar="+mb);
		ventana.focus();
	}
}
//Ventana emergente FLASH
var vFlash = {
	abrir:function(url,w,h) { vWindow.abrir(url,'newWin',w+10,h+10,100,100,0,0);}
}
//Funcion de cambio de idioma
var change = {
	language:function(language,urlHOME)
	{
		goToURL = urlHOME;
		if ( document.location.href.indexOf("?") != (-1))
		{
			parametros="";
			idioma = language.split("change_");
			aux_lang = document.location.href.split("language=");
			if (aux_lang[1].length > 2) { parametros = aux_lang[1].substring(2,aux_lang[1].length);}
			goToURL  = aux_lang[0]+"language="+idioma[1]+parametros;
		}		
		document.location.href=goToURL;
	}
}
//Funciones Google
var map;
var geocoder;
function load()
{
	map = new GMap2(document.getElementById("map"));
	map.setCenter(new GLatLng(34, 0), 13);
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	geocoder = new GClientGeocoder();
}
function addAddressToMap(response)
{
	map.clearOverlays();
	if (!response || response.Status.code != 200) { alert("No es posible obtener las coordenadas para esa dirección");}
	else
		{
			place = response.Placemark[0];
			point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
			marker = new GMarker(point);
			map.addOverlay(marker);
			marker.openInfoWindowHtml(place.address + '<br />' +'<strong>C&oacute;digo de pa&iacute;s:</strong> ' + place.AddressDetails.Country.CountryNameCode);
		}
}
function showLocation(address) { geocoder.getLocations(address, addAddressToMap);}

var generar = {
	url:function(qObj,language)
	{
		//No se visualiza el lector para el idioma rumano
		if (language != "ro")
		{
			//Si existe la clase la visualizamos
			classSpeaker = document.getElementsByClassName("lspeaker");
			for (var i=0;i<classSpeaker.length;i++)
			{
				var objContenedora = classSpeaker[i];
				if (objContenedora != null) { objContenedora.style.display = "block";}
			}
		}
		url = "http://asp.readspeaker.net/cgi-bin/madridorgrsone?customerid=1003776&lang="+language+"&url=";
		qObj.onclick = function()
		{
			urlPage = document.location.href;
			vWindow.abrir(url+urlPage,'winSpeak',610,425,100,100,'auto','no','no');
			return false;
		}
	}
}
window.onload = function()
{
	//Declaracion de la capa contenedora a la cual se le quiere aplicar los bordes redondeados
	document.getElementsByClassName=function(className)
	{
		var data = [];
		var node=(document.getElementById("CuerpoCentro"))? document.getElementById("CuerpoCentro"):document;
		var tags = (!document.all) ? node.getElementsByTagName("*") : document.all
		for(var i=0;i<tags.length;i++) { if(tags[i].className == className) data[data.length]=tags[i];}
		return data;
	}
	var myObject = document.getElementsByClassName("bloqueDestacados");
	for (var i=0;i<myObject.length;i++)
	{
		var objContenedora = myObject[i];
		if (objContenedora != null) { if (swIE501) { rounded.corners(objContenedora);} }
	}
	//Declaracion de los iconos de impresion
	objIconos = document.getElementById("iconos");
	if (objIconos != null) { objIconos.style.display = "block";}
	//Objeto de impresion
	objPrint = document.getElementById("print");
	if (objPrint != null)
	{
		objPrint.onclick = function() { window.print(); return false;}
		objPrint.onkeypress = objPrint.onclick;
	}
	//Google maps
	objMap = document.getElementById("map");
	if (objMap != null) { load(); showLocation(direccion);}
	//definicion volver
	var objGoTo = document.getElementById("goTo");
	if (objGoTo != null)
	{
		objGoTo.style.display = "inline";
		classMayor = document.getElementsByClassName("mayor");
		for (var i=0;i<classMayor.length;i++)
		{
			var objContenedora = classMayor[i];
			if (objContenedora != null) { objContenedora.style.display = "inline";}
		}
		classRaya = document.getElementsByClassName("raya");
		for (var i=0;i<classRaya.length;i++)
		{
			var objContenedora = classRaya[i];
			if (objContenedora != null) { objContenedora.style.display = "inline";}
		}
	}
	//definicion del boton subir
	var objGoUp = document.getElementById("goUp");
	if (objGoUp != null)
	{
		objGoUp.onclick = function() { contGoTo=2;}
		objGoUp.onkeypress = objGoUp.onclick;
	}
	//Galeria de imagenes
	var contIDGal = 0;
	while (document.getElementById("AmpGal"+contIDGal) != null)
	{
		objGal = document.getElementById("AmpGal"+contIDGal);
		objTxtGal = document.getElementById("txtGalx"+contIDGal);
		objGal.onclick = function() { vWindow.abrir(this.href,'winGal',610,425,100,100,'auto','no','no');return false;}
		objTxtGal.onclick = objGal.onclick;
		contIDGal++;
	}
	//Links pie pagina
	var contItemsPie = 1;
	while (document.getElementById("LinkPie"+contItemsPie) != null)
	{
		objPie = document.getElementById("LinkPie"+contItemsPie);
		objPie.onclick = function() { vWindow.abrir(this.href,'',596,480,100,100,'yes','no','no'); return false;}
		contItemsPie++;
	}
	//Combo Informacion practica
	var irA = {
		redirect:function(opSel)
		{
			if (opSel != (-1)) { document.location.href = opSel;}
			else { alert("Seleccione una opción");}
		}
	}
	var objCmbInfPrac = document.getElementById("imgOpcion");
	if (objCmbInfPrac != null)
	{
		objCmbInfPrac.onclick = function()
		{
			vSelect = document.getElementById("cmbOpcion").value;
			irA.redirect(vSelect);return false;
		}
		objCmbInfPrac.onkeypress = objCmbInfPrac.onclick;
	}
	//ficha detalle Modulo Atencion al ciudadano
	var objModAten = document.getElementById("modAten");
	if (objModAten != null)
	{
		objModAten.onclick = function() { vWindow.abrir(this.href,'winInfo',610,425,100,100,'yes','no','no'); return false;}
		objModAten.onkeypress = objModAten.onclick;
	}
	//Cambio de idioma
	var aLanguages = ["es","en","fr","ro"];
	for (var i=0;i<aLanguages.length;i++)
	{
		if (document.getElementById("change_"+aLanguages[i]))
		{
			document.getElementById("change_"+aLanguages[i]).onclick = function() {
				change.language(this.id, this.href);return false;
			}
		}
	}
	//Formulario de Suscripciones
	objnombre = document.getElementById("nombre");
	if (objnombre != null) { objnombre.focus();}
	objpreviewPostal = document.getElementById("previewPostal");
	if (objpreviewPostal != null) { objpreviewPostal.onsubmit=valida.captura;}
	objreset = document.getElementById("btnBorrar");
	if (objreset!=null)
	{
		objreset.onclick= function()
		{
			var myObject = document.getElementsByClassName("txtForm");
			for (var i=0;i<myObject.length;i++)
			{
				var objInput = myObject[i];
				document.getElementById(objInput.id).style.background = "#fff";
			}
			objpreviewPostal.reset();
			return false;
		}
	}
	//Formulario Sugerencias
	objNombreRemitente = document.getElementById("NombreRemitente");
	if (objNombreRemitente != null) { objNombreRemitente.focus();}
	objSugerencias = document.getElementById("formSugerencias");
	if (objSugerencias != null) { objSugerencias.onsubmit=valida.captura;}
	//Objeto speaker
	aux_objSpeak = null;
	objSpeakES = document.getElementById("speaker_es"); if (objSpeakES != null) { aux_objSpeak = objSpeakES;}
	objSpeakEN = document.getElementById("speaker_en"); if (objSpeakEN != null) { aux_objSpeak = objSpeakEN;}
	objSpeakFR = document.getElementById("speaker_fr"); if (objSpeakFR != null) { aux_objSpeak = objSpeakFR;}
	objSpeakRO = document.getElementById("speaker_ro"); if (objSpeakRO != null) { aux_objSpeak = objSpeakRO;}
	if (aux_objSpeak != null)
	{
		language = aux_objSpeak.id.split("speaker_");
		generar.url(aux_objSpeak,language[1]);
	}
	//Objeto Metodohont
	objMetDhont=document.getElementById("dhont");
	if (objMetDhont!=null) { objMetDhont.onclick=function() { vWindow.abrir(this.href,'calculadora',700,570,100,100,'yes',0,0);return false;}}
	//Busqueda Mesa Electoral
	objsME = document.getElementById("sME");
	if (objsME != null) { objsME.onclick=function() { vWindow.abrir(this.href,'searchMesaElectoral',700,500,100,100,'yes',0,0);return false;}}
	//Comprobar objeto eleccione
	var iElec = 0;
	while (document.getElementById("elec"+iElec) != null)
	{
		obj_aux = document.getElementById("elec"+iElec);
		obj_aux.onclick = function()
		{
			ventana = window.open(this.href,'wElecciones');
			return false;
		}
		iElec++;
	}
	//Objeto Video
	var objVideo = document.getElementById("vidHome");
	if (objVideo != null) {	objVideo.onclick = function() { vWindow.abrir(this.href,'Webcast',600,400,50,50,'no','no','no'); return false;}}
}