// FUNCIONES COMUNES A TODO EL PORTAL MAPFRE

// Aumentamos y disminuimos el texto
var txtSz = 0.7;
function textSize(signo)
{
	var cuerpo = document.getElementsByTagName("BODY")
	txtSz = (signo=="plus") ? txtSz+0.10 : txtSz-0.10;
	if (txtSz>1.1) txtSz = 1.1;
	if (txtSz<0.5) txtSz = 0.5;
	ts = txtSz+"em";
	cuerpo[0].style.fontSize = ts;
}

// Funciones par el CONTROL DE MENU
var menuAct = 0;
function menu(num)
{
	var numMenus = document.getElementById("menu").getElementsByTagName('DIV').length; // El número de menús es el número de DIV que contiene el objeto MENU
	var smNum = eval("document.getElementById('sm"+num+"')");
	var smAct = eval("document.getElementById('sm"+menuAct+"')");
	var mNum = eval("document.getElementById('m"+num+"')");
	var mAct = eval("document.getElementById('m"+menuAct+"')");	
	
	if (num == 0)
	{
		for (i=1;i<=numMenus;i++)
		{
			eval("document.getElementById('sm"+i+"').style.display = 'none'");
		}
		if (menuAct!=0)
		{
			if (mAct.className == "smOnCl") mAct.className = "smOn";
			if (mAct.className == "smCl") mAct.className = "sm";
		}
	}
	
	else
	{
		smNum.style.display = "block";
		if (mNum.className == "smOn") mNum.className = "smOnCl";
		else if (mNum.className == "sm") mNum.className = "smCl";
	
		if (menuAct != 0)
		{
			smAct.style.display = "none";
			if (mAct.className == "smOnCl") mAct.className = "smOn";
			else if (mAct.className == "smCl") mAct.className = "sm";		
			if (num ==  menuAct) 
			{
				smNum.style.display = "block";
				if (mNum.className == "smOn") mNum.className = "smOnCl";
				if (mNum.className == "sm") mNum.className = "smCl";
			}
		}
	}
	menuAct = num;
}


// Funciones par el CONTROL DE MENU
// funciones menu para no parpadeo
var timerID = null;
var rollID = null;
var timerOn = false;
var timecount = 500;	

function startTime() 
{
	if (timerOn == false) 
	{
       	timerID = setTimeout( "menu0()" , timecount);
		timerOn = true;
	}
}

function stopTime() 
{
	if (timerOn) 
	{
		clearTimeout(timerID);
       	timerID = null;
		rollID = null;
    	timerOn = false;
    }
}
function menu0()
{
	menu('0');
}

/* Dado un objeto y un className, comprimimos todos los objetos con dicho class */
function inicio(objeto,clase,posicion)
{

	var capas = document.getElementsByTagName(objeto);
	var nCapas = capas.length;	
	for (i=0;i<nCapas;i++)
	{	
		if (capas[i].className == clase)
		{
			capas[i].style.position = posicion;
			capas[i].style.display = "none";
		}
	}
}

/* Función que controla el Menú Lateral izquierdo */
function subMenuLat(num)
{
	var sm = eval("document.getElementById('smLat"+num+"')");
	eval("document.getElementById('sml"+num+"').style.position = 'static'");
	switch (sm.className)
	{
		case "mLat on":
		sm.className = "mLat onZip";
		eval("document.getElementById('sml"+num+"').style.display = 'none'");
		break;
		case "mLat onZip":
		sm.className = "mLat on";
		eval("document.getElementById('sml"+num+"').style.display = 'block'");
		break;
		case "mLat":
		sm.className = "mLat noZip";
		eval("document.getElementById('sml"+num+"').style.display = 'block'");
		
		break;
		case "mLat noZip":
		sm.className = "mLat";
		eval("document.getElementById('sml"+num+"').style.display = 'none'");	
		break;
	}
}

/* Función para las FAQ del lateral derecho */
function menuFAQ(num)
{
	var m = eval("document.getElementById('mFAQ"+num+"')");
	eval("document.getElementById('mFAQ"+num+"').style.position = 'static'");
	switch (m.className)
	{
		case "mFAQ":
		m.className = "mFAQ displayNone";
		eval("document.getElementById('mFAQ"+num+"').style.display = 'block'");
		break;
		case "mFAQ displayNone":
		m.className = "mFAQ";
		eval("document.getElementById('mFAQ"+num+"').style.display = 'none'");	
		break;
	}	
}

/* Abrir Ventana */
function abrirVentana(url,ancho,alto)
{
	eval("window.open(url, 'ventana', 'toolbar=no, directories=no, location=no, status=no, menubar=no, resizable=no, scrollbars=yes, width="+ancho+", height="+alto+"')"); 
}

function irCombo()
{
	alert("Enviando selección...")
}

/* Activar capas de los servicios telefónicos */
var srvActiv = 0;
function srv(num)
{
	if (srvActiv != 0)
	{
		eval ("document.getElementById('ser"+srvActiv+"').style.display = 'none'");
		if (srvActiv%2 == 0)
		{
			eval ("document.getElementById('srv"+srvActiv+"').className = 'par'");	
		}
		else
		{
			eval ("document.getElementById('srv"+srvActiv+"').className = ''");
		}
		
	}	
	eval ("document.getElementById('ser"+num+"').style.display = 'block'");
	eval ("document.getElementById('srv"+num+"').className = 'activo'");
	srvActiv = num;
}

/* Colocamos los linsk de zoom según el navegador. */
// La última línea (window.onresize=colocarZoom;) debe descomentarse en caso que se elija esta opción.
function colocarZoom()
{
var winW = 630, winH = 460;

if (parseInt(navigator.appVersion)>3) {
 if (navigator.appName=="Netscape") {
  winW = window.innerWidth;
  winH = window.innerHeight;
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {
  winW = document.body.offsetWidth;
  winH = document.body.offsetHeight;
 }
}
	var ancho = document.body.clientWidth;
	//var anchoP = document.getElementById("principal").clientWidth;
	if (ancho > 920)
	{
		document.getElementById("tipo").className = "sup";			
	}
	else
	{
		document.getElementById("tipo").className = "";			
	}
}
//window.onresize=colocarZoom;

/* Función para ocultar y mostrar el mapa web */
var mwAct = 0;
function mapaweb(num)
{
	if (mwAct != 0)
	{
		eval ("document.getElementById('smMW"+mwAct+"').style.display = 'none'");
		eval ("document.getElementById('mw"+mwAct+"').className = ''");
	}	
	eval ("document.getElementById('smMW"+num+"').style.display = 'block'");
	eval ("document.getElementById('mw"+num+"').className = 'on'");
	mwAct = num;
}

/* Función para cargar los videos en la Home */
function cargarVideo(numVideo)
		{								
			if (numVideo == 1)
			{								
				url='<embed  id="objVideo" src="mms://video.ono.com/streaming/mapfre/video1_bancos.wmv" loop="false" width="180" height="180"></embed>';
				document.getElementById("boton1").className = 'botonNumero activo';
				document.getElementById("boton2").className = 'botonNumero';
				document.getElementById("boton3").className = 'botonNumero';
			}
			else if (numVideo == 2)
				{
					url='<embed  id="objVideo" src="mms://video.ono.com/streaming/mapfre/video2_ama.wmv" loop="false" width="180" height="180"></embed>';
					document.getElementById("boton2").className = 'botonNumero activo';
					document.getElementById("boton1").className = 'botonNumero';
					document.getElementById("boton3").className = 'botonNumero';
				}
				else if (numVideo == 3)
					{
						url='<embed  id="objVideo" src="mms://video.ono.com/streaming/mapfre/video3_pueblo.wmv" loop="false" width="180" height="180"></embed>';
						document.getElementById("boton3").className = 'botonNumero activo';
						document.getElementById("boton2").className = 'botonNumero';
						document.getElementById("boton1").className = 'botonNumero';					
					}					
			document.getElementById("capaVideo").innerHTML = url;								
		}
/* Función para pasar de un video a otro */		
		function pasarVideo(posicion)
		{			
			for (i=1;i<=3;i++)
			{			
				var boton = eval("document.getElementById('boton"+i+"')");
				if (boton.className == "botonNumero activo")
				{					
					break;
				}
			}	
			if (posicion == 0)
			{
				if (i == 1)
				{
					cargarVideo(3);
				}
				else
				{
					if (i==2)
					{
						cargarVideo(1);
					}
					else
					{
						cargarVideo(2);	
					}
				}
			}
			else
			{				
				if (i == 1)
				{
					cargarVideo(2);
				}
				else
				{
					if (i==2)
					{
						cargarVideo(3);
					}
					else
					{
						cargarVideo(1);	
					}
				}
			}		
		}
		
		
	
		
/* Script que detecta el tipo de Navegador que se está utilizando */		
		
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

		
		
		
/* Abrir Ventana Gnral*/
function abrirVentanaGnral(url,ancho,alto, location, toolbar, menubar, resize, scroll)
{
	if(toolbar == null) toolbar = "1"; if(toolbar=="0") toolbar = "no"; else toolbar="yes";
	if(location == null) location = "1"; if(location=="0") location = "no"; else location="yes";
	if(menubar == null) menubar = "1";if(menubar=="0") menubar = "no"; else menubar="yes";
	if(resize == null) resize = "1";if(resize=="0") resize = "no"; else resize="yes";
	if(scroll == null) scroll = "1";if(scroll=="0") scroll = "no"; else scroll="yes";
	
	var entrada = document.location.href;
	var entorno = entrada.substring(0,entrada.indexOf("/seguros"))
	
	if(url.indexOf("/buzones/generar")!=-1 && entorno.indexOf("http://")!=-1){	
		url = entorno.replace("http://","https://") + url.substring(url.indexOf("/buzones"));
	}
	
	eval("window.open(url, 'ventana', 'toolbar=" + toolbar + ",location=" + location + ", menubar=" + menubar + ", resizable=" + resize +", scrollbars="+scroll+", width="+ancho+", height="+alto+"')"); 
}

/* Funciones para controlar el menú lateral */	
/* Oculta el submenú al cargar la página */
function inicioMenuLat(objeto,clase)
{

	var capas = document.getElementsByTagName(objeto);
	var nCapas = capas.length;	
	for (i=0;i<nCapas;i++)
	{	
		if (capas[i].className == clase)
		{			
			capas[i].style.display = "none";
		}
	}
}
/* Muestra y Oculta el submenú */
var prox = "none";
var ante = "none";	
var pest = "none";	
function pc(idM,idSM,carr)
{
	if (eval(carr) == "none")
	{
		document.getElementById(idSM).style.display = "block";
		document.getElementById(idM).className = "act";
		eval(carr+" = 'block'");
	}
	else
	{
		document.getElementById(idSM).style.display = "none";
		if (carr == pest)
		{
			document.getElementById(idM).className = "act";
		}
		else
		{
			document.getElementById(idM).className = "";
		}
		
		eval(carr+" = 'none'");
	}
}		
function blockNone(idCapa,estado)
{
	document.getElementById(idCapa).style.display = estado;
}
function noticias(idCapa)
{
	blockNone("cc125","none");
	blockNone("cc250","none");
	blockNone("motoGP","none");
	blockNone(idCapa,"block");
	document.getElementById("cc125LI").className="";
	document.getElementById("cc250LI").className="";
	document.getElementById("motoGPLI").className="";
	eval("document.getElementById('"+idCapa+"LI').className='act'");
}
function circuito(idCapa)
{
	blockNone("ficha","none");
	blockNone("general","none");
	blockNone("horarios","none");
	blockNone(idCapa,"block");
	document.getElementById("fichaLI").className="";
	document.getElementById("generalLI").className="";
	document.getElementById("horariosLI").className="";
	eval("document.getElementById('"+idCapa+"LI').className='act'");
}	

function comprobarQ(){
	var form =document.getElementById('diccionario');
	var QAUX = form.q.value
	form.q.value=QAUX.replace('&','');
	
	document.getElementById('diccionario').submit();

}

function comprobarQintro(){
	if (window.event.keyCode==13) {
		comprobarQ();
	}
}

function activar(num){
	for (i=1;i<=5;i++)
	{
		eval("document.getElementById('m"+i+"').className = 'smNo'");
	}
	eval("document.getElementById('m"+num+"').className = 'smOnCl'");
}
