// JavaScript Document


function resaltaPastillaCabecera(nombrePastilla) {
	var laPastilla = document.getElementById(nombrePastilla);
	laPastilla.style.backgroundColor = "#424a52";
	laPastilla.childNodes.item(0).style.color = "#fff";
}

function actualizaMenusDesplegablesSupArnabat(elMenu) {
	
	// Si estamos en Joomla, ocultamos los leads para que ocupen su espacio los desplegables.
	if(document.getElementById('leadOfertas')) {
		document.getElementById('leadOfertas').style.display = 'none';
		document.getElementById('leadAccesorios').style.display = 'none';
	}
	
	switch(elMenu.id) {
		
		case "selectSupArnabatSector":
			if(elMenu.options[elMenu.selectedIndex].value == 0) {
				ocultaMenusDesplegablesSupArnabat('todos', elMenu);
			}
			
			if(isNaN(elMenu.options[elMenu.selectedIndex].value) && elMenu.options[elMenu.selectedIndex].value.indexOf('.') == -1) {
				ocultaMenusDesplegablesSupArnabat('todos', elMenu);
				document.getElementById(elMenu.options[elMenu.selectedIndex].value).style.display = 'block';
			}
			if(elMenu.options[elMenu.selectedIndex].value.indexOf(',') != -1) {
				var apartado = elMenu.options[elMenu.selectedIndex].value.substring(0, elMenu.options[elMenu.selectedIndex].value.indexOf(','));
				var url = elMenu.options[elMenu.selectedIndex].value.substring(elMenu.options[elMenu.selectedIndex].value.indexOf(',') + 1, elMenu.options[elMenu.selectedIndex].value.length);
					
				if(location.href.indexOf(url) == -1) {
					if(location.href.indexOf('cms') != -1)
						url = '../' + url;
					location.href = url;
				}
				else
					document.getElementById(apartado).style.display = 'block';
			}
			else if(elMenu.options[elMenu.selectedIndex].value.indexOf('.') != -1) {
				if(location.href.indexOf('cms') != -1)
					location.href = '../' + elMenu.options[elMenu.selectedIndex].value;
				else
					location.href = elMenu.options[elMenu.selectedIndex].value;
			}
			
			break;
			
		case "selectSupArnabatSistemaProyeccion": case "selectSupArnabatSistemaBombeo":
		
			if(elMenu.options[elMenu.selectedIndex].value == 0) {
				ocultaMenusDesplegablesSupArnabat('secundarios', elMenu);
			}
			
			/*
				Estos menus pueden tener dos valores separados por una coma. Uno indica la url a la que hay que ir y el otro, el submenu que hay que deplegar en caso de que ya
				estemos en esa direccion. El siguiente bloque if() detecta la presencia de la coma separadora y nos lleva a una url o despliega un submenu dependiendo de si
				ya nos encontramos en la pagina de la url o no.
			*/			
			if(isNaN(elMenu.options[elMenu.selectedIndex].value)) {
				ocultaMenusDesplegablesSupArnabat('secundarios', elMenu);
				if(elMenu.options[elMenu.selectedIndex].value.indexOf(',') != -1) {
					var apartado = elMenu.options[elMenu.selectedIndex].value.substring(0, elMenu.options[elMenu.selectedIndex].value.indexOf(','));
					var url = elMenu.options[elMenu.selectedIndex].value.substring(elMenu.options[elMenu.selectedIndex].value.indexOf(',') + 1, elMenu.options[elMenu.selectedIndex].value.length);
					
					if(location.href.indexOf(url) == -1) {
						if(location.href.indexOf('cms') != -1)
							url = '../' + url;
						location.href = url;
					}
					else
						document.getElementById(apartado).style.display = 'block';
				}
				else
					document.getElementById(elMenu.options[elMenu.selectedIndex].value).style.display = 'block';
			}
		
			break;
			
			
		case "selectSupArnabatProductosProyeccionViaSeca": case "selectSupArnabatProductosProyeccionViaHumeda": case "selectSupArnabatProductosBombeoViaHumeda":
			if(isNaN(elMenu.options[elMenu.selectedIndex].value) && elMenu.options[elMenu.selectedIndex].value.indexOf('.') != -1) {
				location.href = elMenu.options[elMenu.selectedIndex].value;
			}
		
			break;
		
	}
	
}

var idsMenusDesplegablesSupArnabatPrimarios = new Array('selectSupArnabatSistemaProyeccion', 'selectSupArnabatSistemaBombeo');
var idsMenusDesplegablesSupArnabatSecundarios = new Array('selectSupArnabatProductosProyeccionViaSeca', 'selectSupArnabatProductosProyeccionViaHumeda', 
															  'selectSupArnabatProductosBombeoViaHumeda');

function ocultaMenusDesplegablesSupArnabat(cuales, elMenu) {
	
	for(var i = 0; i < idsMenusDesplegablesSupArnabatSecundarios.length; i++) {
		document.getElementById(idsMenusDesplegablesSupArnabatSecundarios[i]).style.display = 'none';
		if(idsMenusDesplegablesSupArnabatSecundarios[i] != elMenu)
			document.getElementById(idsMenusDesplegablesSupArnabatSecundarios[i]).options[0].selected = true;
	}
	
	if(cuales == 'todos') {
		for(var i = 0; i < idsMenusDesplegablesSupArnabatPrimarios.length; i++) {
			document.getElementById(idsMenusDesplegablesSupArnabatPrimarios[i]).style.display = 'none';
			if(idsMenusDesplegablesSupArnabatPrimarios[i] != elMenu)
				document.getElementById(idsMenusDesplegablesSupArnabatPrimarios[i]).options[0].selected = true;
		}
	}
	
}

function incrustaFlash(ruta, ancho, alto, transp) {
	
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + ancho + '" height="' + alto + '">');
      document.write('<param name="movie" value="' + ruta + '" />');
      document.write('<param name="quality" value="high" />');
	  if(transp) {
	  	document.write('<param name="wmode" value="transparent">');
		document.write('<embed src="' + ruta + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + ancho + '" height="' + alto + '" wmode="transparent"></embed>');
	  }
	  else
     	 document.write('<embed src="' + ruta + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + ancho + '" height="' + alto + '"></embed>');
    document.write('</object>');
//	document.write('</div>');
	
	
}

function despliegaMenusActuales() {
	var estaPag = location.href.substring(location.href.lastIndexOf('/') + 1, location.href.length).toLowerCase();
	// Los nombres de archivo de las paginas de datos tecnicos empiezan por 'datos'. Si ese es el caso, eliminamos este principio.
	if(estaPag.indexOf('datos') != -1)
		estaPag = estaPag.substring(5, estaPag.length);

	if(estaPag.indexOf('aplicaciones') != -1) {
		document.getElementById('selectSupArnabatSector').selectedIndex = 4;
		return;
	}
	
	if(estaPag.indexOf('compresores') != -1) {
		document.getElementById('selectSupArnabatSector').selectedIndex = 3;
		return;
	}
	
	var elMenuDeProducto;
	var elMenuDeSistema;
	var elMenuDeSector = document.getElementById('selectSupArnabatSector');
	
	for(var i = 0; i < idsMenusDesplegablesSupArnabatSecundarios.length; i++) {
		for(var a = 0; a < document.getElementById(idsMenusDesplegablesSupArnabatSecundarios[i]).options.length; a++) {
			if(document.getElementById(idsMenusDesplegablesSupArnabatSecundarios[i]).options[a].value.toLowerCase().indexOf(estaPag) != -1) {
				elMenuDeProducto = document.getElementById(idsMenusDesplegablesSupArnabatSecundarios[i]);
			}
		}
	}
	// Si estamos en una pagina de producto
	if(elMenuDeProducto) {
		// Desplegamos el menu de producto
		elMenuDeProducto.style.display = 'block';
		for(var i = 0; i < elMenuDeProducto.options.length; i++) {
			if(elMenuDeProducto[i].value.toLowerCase().indexOf(estaPag) != -1)
				elMenuDeProducto.selectedIndex = i;
		}
		// Desplegamos el menu de sistema
		for(var a = 0; a < idsMenusDesplegablesSupArnabatPrimarios.length; a++) {
			for(var b = 0; b < document.getElementById(idsMenusDesplegablesSupArnabatPrimarios[a]).options.length; b++) {
				if(document.getElementById(idsMenusDesplegablesSupArnabatPrimarios[a]).options[b].value.indexOf(elMenuDeProducto.id) != -1) {
					elMenuDeSistema = document.getElementById(idsMenusDesplegablesSupArnabatPrimarios[a]);
					elMenuDeSistema.style.display = 'block';
					elMenuDeSistema.selectedIndex = b;
				}
			}
		}
		// Desplegamos el menu de sector
		for(var c = 0; c < elMenuDeSector.options.length; c++) {
			if(elMenuDeSector.options[c].value.indexOf(elMenuDeSistema.id) != -1) 
				elMenuDeSector.selectedIndex = c;
		}
		return;
	}
	
	// Si estamos en una pagina de sistema
	for(var a = 0; a < idsMenusDesplegablesSupArnabatPrimarios.length; a++) {
		for(var b = 0; b < document.getElementById(idsMenusDesplegablesSupArnabatPrimarios[a]).options.length; b++) {
			if(document.getElementById(idsMenusDesplegablesSupArnabatPrimarios[a]).options[b].value.toLowerCase().indexOf(estaPag) != -1) {
				elMenuDeSistema = document.getElementById(idsMenusDesplegablesSupArnabatPrimarios[a]);
				elMenuDeSistema.style.display = 'block';
				elMenuDeSistema.selectedIndex = b;
				
				
				for(var c = 0; c < elMenuDeSector.options.length; c++) {
					if(elMenuDeSector.options[c].value.indexOf(elMenuDeSistema.id) != -1) {
						elMenuDeSector.selectedIndex = c;
					}
				}
				actualizaMenusDesplegablesSupArnabat(elMenuDeSistema);
				return;
			}
		}
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

//alert(readCookie('empresa'));

function abreVideo(urlVideo) {
	var h = 340;
	var w = 370;
	
	if(screen.width) {
		var winl = (screen.width-w)/2;
		var wint = (screen.height-h)/2;
	}
	else {
		winl = 0;wint =0;
	}
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;
	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',';
	win = window.open('reproductorDeVideo.html?' + urlVideo, 'Arnabat',settings);
	win.window.focus();
	
//	window.open('reproductorDeVideo.html?' + urlVideo, 'Arnabat', 'height=340,width=370');
}

function parametroGet( name ) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function traduce(idioma) {
	
/*	if(idioma == 'fr') {
		alert('D\351sol\351s, la version fran\347aise de ce site est encore en construction.');
		return;
	}*/
	
	if(location.href.indexOf('cms2') != -1) {
		location.href = location.href + '&lang=' + idioma;
		return;
	}
	
	if(location.href.indexOf('index.php') != -1 || location.href.indexOf('.php') == -1) {
		location.href = 'index_' + idioma + '.php';
		return;
	}
	
	if(location.href.indexOf('index_en.php') != -1 || location.href.indexOf('index_fr.php') != -1) {
		location.href = 'index.php';
		return;
	}
	
	var pag = location.href.substring(0, location.href.lastIndexOf('.php') - 2);
	location.href = pag + idioma + '.php';
}











