var minAncho = 1000;
var minAlto = 495;

var extraActual = "";

var habilitaForm = true;

var fotoActual = 0;
var numFotos = 0;

var linkActual = 0;
var numLinks = 0;

var pdfActual = 0;
var numPdfs = 0;

var videoActual = 0;
var numVideos = 0;

var youtubeActual = 0;
var numYoutubes = 0;

var numPartners = 0;
var partnerActivo = -1;

var winName = "titulo";
var win = null;

var scrollDchaImg = true;
var scrollIzdaImg = false;

var scrollDchaLink = true;
var scrollIzdaLink = false;

var scrollDchaPdf = true;
var scrollIzdaPdf = false;

var scrollDchaVideo = true;
var scrollIzdaVideo = false;

var scrollDchaYoutube = true;
var scrollIzdaYoutube = false;

var seccionActual = 0;
var numSecciones = 0;


function AbreN( theURL, ancho, alto )
{
    var h = (screen.width-ancho)/2;
    var v = (screen.height-alto)/2;
    var windowprops = "top=0,left=0,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes, resizable=no,width="+ancho+",height="+alto+",left="+h+", top="+v;
    
    if( win )
    {
        win.close();
    }
    
    win = window.open(theURL, winName, windowprops);
}

function Actualiza()
{
    w = document.getElementById ('flash');
    ancho = alto = 0;
    if (typeof (window.innerWidth) == 'number')
	{
        ancho = window.innerWidth;
        alto = window.innerHeight;
    }
	else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
        ancho = document.documentElement.clientWidth;
        alto = document.documentElement.clientHeight;
    }
	else if (document.body && (document.body.clientWidth || document.body.clientHeight))
	{
        ancho = document.body.clientWidth;
        alto = document.body.clientHeight;
    }
	
    w.style.width = ancho < minAncho ? minAncho + "px" : "100%";
    w.style.height = alto < minAlto ? minAlto + "px" : "100%";
}

function CambiaAlto( idElemento, alto )
{
	$("#" + idElemento ).stop().animate( { top: alto }, 300 );
	//document.getElementById( idElemento ).style.top = alto;
}

function CambiaDestacado( estado )
{
	if( estado == 'over' )
	{
		$("#destacadoOver" ).stop().animate( { opacity: 0.5 }, 200 );
		/*$("#destacado" ).stop().animate( { backgroundColor: "#EF5626", borderBottomColor: "#EF5626", borderLeftColor: "#EF5626", borderRightColor: "#EF5626", borderTopColor: "#EF5626" }, 200 );
		$("#destacadoTit" ).stop().animate( { color: "#FFFFFF" }, 200 );
		$("#destacadoTxt" ).stop().animate( { color: "#FFFFFF" }, 200 );*/
	}
	else
	{
		$("#destacadoOver" ).stop().animate( { opacity: 0 }, 200 );
		/*$("#destacado" ).stop().animate( { backgroundColor: "#FFFFFF", borderBottomColor: "#DFDFDF", borderLeftColor: "#DFDFDF", borderRightColor: "#DFDFDF", borderTopColor: "#DFDFDF" }, 200 );
		$("#destacadoTit" ).stop().animate( { color: "#EF4611" }, 200 );
		$("#destacadoTxt" ).stop().animate( { color: "#808576" }, 200 );*/
	}
}

function CambiaFondo( id, color )
{
	document.getElementById( id ).style.background = color;
}

function CambiaImg( idElemento, imagen )
{
    document.getElementById( idElemento ).src = imagen;
}

function CambiaNoticia( numero, estado )
{
	if( estado == "over" )
	{
		$("#not" + numero ).stop().animate( { backgroundColor: "#EF4611" }, 200 );
		$("#notTit" + numero ).stop().animate( { color: "#FFFFFF" }, 200 );
		$("#notFecha" + numero ).stop().animate( { color: "#FFFFFF" }, 200 );
		$("#notTxt" + numero ).stop().animate( { color: "#FFFFFF" }, 200 );
	}
	else
	{
		$("#not" + numero ).stop().animate( { backgroundColor: "#EEEEEE" }, 200 );
		$("#notTit" + numero ).stop().animate( { color: "#EF4611" }, 200 );
		$("#notFecha" + numero ).stop().animate( { color: "#808576" }, 200 );
		$("#notTxt" + numero ).stop().animate( { color: "#808576" }, 200 );
	}
}

function CambiaPartners()
{
	if( partnerActivo != -1 )
	{
		$("#partner" + partnerActivo ).stop().animate( { left: "-250px" }, 300 );
		
		partnerActivo++;
		
		if( partnerActivo >= numPartners ) partnerActivo = 0;
		
		document.getElementById( 'partner' + partnerActivo ).style.left = "250px";
		
		$("#partner" + partnerActivo ).stop().animate( { left: "0px" }, 300 );
	}
	else
	{
		partnerActivo = Math.floor( Math.random() * numPartners );
		
		document.getElementById( 'partner' + partnerActivo ).style.left = "0px";
	}
}

function CambiaSeccion( cual )
{
	document.getElementById( 'cuad' + seccionActual ).src = "_imagenes/cuboGris.png";
	
	$( '#el' + seccionActual ).hide( 500 );
	
	seccionActual = cual;
	
	$( '#el' + seccionActual ).show( 500 );
}

function CierraExtra()
{
	if( extraActual != "" )
	{
		$("#" + extraActual ).stop().animate( { height: "0px" }, 200);
		extraActual = "";
	}
}

function EntraBusqueda()
{
	var bc = document.getElementById( 'busquedaCampo' );
	bc.className = "busquedaCampo";
	
	if( bc.value == "buscar..." || bc.value == "search..." )
	{
		bc.value = "";
	}
}

function FormuContacto( idioma )
{
	if( habilitaForm )
	{
		var seguir = true;
		
		if( document.getElementById( 'nombre' ).value.length < 2 )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Enter your name.' );
				break;
				case 'ca':
					alert( 'Introduiu el vostre nom.' );
				break;
				default:
					alert( 'Introduzca su nombre.' );
				break;
			}
		}
		
		if( seguir && document.getElementById( 'email' ).value.length < 2 )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Enter your e-mail.' );
				break;
				case 'ca':
					alert( 'Introdueixi el seu e-mail.' );
				break;
				default:
					alert( 'Introduzca su e-mail.' );
				break;
			}
		}
		
		if( seguir && ( document.getElementById( 'email' ).value.length <  8 || document.getElementById( 'email' ).value.indexOf('@',0)==-1 || document.getElementById( 'email' ).value.indexOf('@',0)==0 || document.getElementById( 'email' ).value.indexOf('.',0)==-1 || document.getElementById( 'email' ).value.indexOf('.',0)==0 ) )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Enter a valid e-mail.' );
				break;
				case 'ca':
					alert( 'Introduiu un e-mail valid.' );
				break;
				default:
					alert( 'Introduzca un e-mail valido.' );
				break;
			}
		}
		
		if( seguir && document.getElementById( 'telefono' ).value.length < 2 )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Enter your phone number.' );
				break;
				case 'ca':
					alert( 'Introduiu el teu telefon.' );
				break;
				default:
					alert( 'Introduzca su telefono.' );
				break;
			}
		}
		
		if( seguir && document.getElementById( 'consulta' ).value.length < 2 )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Fill in message.' );
				break;
				case 'ca':
					alert( 'Ompli el camp missatge.' );
				break;
				default:
					alert( 'Rellene el campo mensaje.' );
				break;
			}
		}
		
		if( seguir )
		{
			document.getElementById( 'nombre' ).style.color = "#999999";
			document.getElementById( 'cargo' ).style.color = "#999999";
			document.getElementById( 'empresa' ).style.color = "#999999";
			document.getElementById( 'email' ).style.color = "#999999";
			document.getElementById( 'telefono' ).style.color = "#999999";
			document.getElementById( 'sector' ).style.color = "#999999";
			document.getElementById( 'consulta' ).style.color = "#999999";
			document.getElementById( 'seguridad' ).style.color = "#999999";
			
			document.forms[ 'contacto' ].submit();
			
			habilitaForm = false;
		}
	}
}

function FormuTrabajo( idioma )
{
	if( habilitaForm )
	{
		var seguir = true;
		
		if( document.getElementById( 'nombre' ).value.length < 2 )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Enter your name.' );
				break;
				case 'ca':
					alert( 'Introduiu el vostre nom.' );
				break;
				default:
					alert( 'Introduzca su nombre.' );
				break;
			}
		}
		
		if( seguir && document.getElementById( 'email' ).value.length < 2 )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Enter your e-mail.' );
				break;
				case 'ca':
					alert( 'Introdueixi el seu e-mail.' );
				break;
				default:
					alert( 'Introduzca su e-mail.' );
				break;
			}
		}
		
		if( seguir && ( document.getElementById( 'email' ).value.length <  8 || document.getElementById( 'email' ).value.indexOf('@',0)==-1 || document.getElementById( 'email' ).value.indexOf('@',0)==0 || document.getElementById( 'email' ).value.indexOf('.',0)==-1 || document.getElementById( 'email' ).value.indexOf('.',0)==0 ) )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Enter a valid e-mail.' );
				break;
				case 'ca':
					alert( 'Introduiu un e-mail valid.' );
				break;
				default:
					alert( 'Introduzca un e-mail valido.' );
				break;
			}
		}
		
		if( seguir && document.getElementById( 'telefono' ).value.length < 2 )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Enter your phone number.' );
				break;
				case 'ca':
					alert( 'Introduiu el teu telefon.' );
				break;
				default:
					alert( 'Introduzca su telefono.' );
				break;
			}
		}
		
		if( seguir && document.getElementById( 'adjunto' ).value.length < 2 )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Enter your cv as an attachment.' );
				break;
				case 'ca':
					alert( 'Introdueixi el seu curriculum com a arxiu adjunt.' );
				break;
				default:
					alert( 'Introduzca su curriculum como archivo adjunto.' );
				break;
			}
		}
		
		if( seguir )
		{
			document.getElementById( 'divEnviando' ).style.display = "block";
			
			document.getElementById( 'nombre' ).style.color = "#999999";
			document.getElementById( 'especialidad' ).style.color = "#999999";
			document.getElementById( 'email' ).style.color = "#999999";
			document.getElementById( 'telefono' ).style.color = "#999999";
			document.getElementById( 'adjunto' ).style.color = "#999999";
			document.getElementById( 'consulta' ).style.color = "#999999";
			document.getElementById( 'seguridad' ).style.color = "#999999";
			
			document.forms[ 'empleo' ].submit();
			
			habilitaForm = false;
		}
	}
}

function Inicia( ancho, alto, img, ver )
{
    if( ver==0 )
	{
        w = document.getElementById ('noFlash');
        w.innerHTML = "<img src=\""+img+"\" alt=\"logotipo\" border=\"0\"><br /><br />" +
            "Necesita flash player para ver esta p&aacute;gina. " +
            "Desc&aacute;rguelo desde <a href=\"http://www.adobe.com/es/products/flashplayer/\" " +
            "target=\"_blank\">adobe.com</a>.<br />Need flash player to view this page. Please download it in " +
            "<a href=\"http://www.adobe.com/products/flashplayer/\" target=\"_blank\">" +
            "adobe.com</a>.";
    }
   
    minAncho = ancho;
    minAlto = alto;
    window.onresize=function(){Actualiza ();}
    Actualiza();
}

function PonExtra( cual )
{
	if( extraActual != cual )
	{
		CierraExtra();
		
		extraActual = cual;
		$("#" + extraActual ).stop().animate( { height: "130px" }, 200);
	}
	else
	{
		CierraExtra();
	}
}

function PonSubtitulo( cual )
{
	document.getElementById( "secTit" + cual ).style.display = "none";
	document.getElementById( "secSubtit" + cual ).style.display = "block";
}

function QuitaSubtitulo( cual )
{
	document.getElementById( "secTit" + cual ).style.display = "block";
	document.getElementById( "secSubtit" + cual ).style.display = "none";
}

function ScrollImagenes( cuantas )
{
	fotoActual += cuantas;
	
	for( x=0; x<numFotos; x++ )
	{
		var tmp = 110 * ( x + fotoActual );
		
		$("#extraFoto" + x ).stop().animate( { left: tmp + "px" }, 200);
		
		//document.getElementById( 'extraFoto' + x ).style.left = tmp + "px" ;
	}
	
	if( fotoActual == 0 )
	{
		scrollIzdaImg = false;
		
		document.getElementById( 'scrollizdaImg' ).style.cursor='default';
		document.getElementById( 'scrollizdaImg' ).src = '_imagenes/scrollizdaC.jpg';
	}
	else
	{
		scrollIzdaImg = true;
		document.getElementById( 'scrollizdaImg' ).src = '_imagenes/scrollizdaA.jpg';
	}
	
	if( fotoActual == - numFotos + 8 )
	{
		scrollDchaImg = false;
		document.getElementById( 'scrolldchaImg' ).style.cursor='default';
		document.getElementById( 'scrolldchaImg' ).src = '_imagenes/scrolldchaC.jpg';
	}
	else
	{
		scrollDchaImg = true;
		document.getElementById( 'scrolldchaImg' ).src = '_imagenes/scrolldchaA.jpg';
	}
}

function ScrollLinks( cuantas )
{
	linkActual += cuantas;
	
	for( x=0; x<numLinks; x++ )
	{
		var tmp = 305 * ( x + linkActual );
		
		$("#extraLink" + x ).stop().animate( { left: tmp + "px" }, 200);
	}
	
	if( linkActual == 0 )
	{
		scrollIzdaLink = false;
		
		document.getElementById( 'scrollizdaLink' ).style.cursor='default';
		document.getElementById( 'scrollizdaLink' ).src = '_imagenes/scrollizdaC.jpg';
	}
	else
	{
		scrollIzdaLink = true;
		document.getElementById( 'scrollizdaLink' ).src = '_imagenes/scrollizdaA.jpg';
	}
	
	if( linkActual == - numLinks + 4 )
	{
		scrollDchaLink = false;
		document.getElementById( 'scrolldchaLink' ).style.cursor='default';
		document.getElementById( 'scrolldchaLink' ).src = '_imagenes/scrolldchaC.jpg';
	}
	else
	{
		scrollDchaLink = true;
		document.getElementById( 'scrolldchaLink' ).src = '_imagenes/scrolldchaA.jpg';
	}
}

function ScrollPdfs( cuantas )
{
	pdfActual += cuantas;
	
	for( x=0; x<numPdfs; x++ )
	{
		var tmp = 305 * ( x + pdfActual );
		
		$("#extraPdf" + x ).stop().animate( { left: tmp + "px" }, 200);
	}
	
	if( pdfActual == 0 )
	{
		scrollIzdaPdf = false;
		
		document.getElementById( 'scrollizdaPdf' ).style.cursor='default';
		document.getElementById( 'scrollizdaPdf' ).src = '_imagenes/scrollizdaC.jpg';
	}
	else
	{
		scrollIzdaPdf = true;
		document.getElementById( 'scrollizdaPdf' ).src = '_imagenes/scrollizdaA.jpg';
	}
	
	if( pdfActual == - numPdfs + 4 )
	{
		scrollDchaPdf = false;
		document.getElementById( 'scrolldchaPdf' ).style.cursor='default';
		document.getElementById( 'scrolldchaPdf' ).src = '_imagenes/scrolldchaC.jpg';
	}
	else
	{
		scrollDchaPdf = true;
		document.getElementById( 'scrolldchaPdf' ).src = '_imagenes/scrolldchaA.jpg';
	}
}

function ScrollPdfsMini( cuantas )
{
	pdfActual += cuantas;
	
	for( x=0; x<numPdfs; x++ )
	{
		var tmp = 305 * ( x + pdfActual );
		
		$("#extraPdf" + x ).stop().animate( { left: tmp + "px" }, 200);
	}
	
	if( pdfActual == 0 )
	{
		scrollIzdaPdf = false;
		
		document.getElementById( 'scrollizdaPdf' ).style.cursor='default';
		document.getElementById( 'scrollizdaPdf' ).src = '_imagenes/scrollizdaC.jpg';
	}
	else
	{
		scrollIzdaPdf = true;
		document.getElementById( 'scrollizdaPdf' ).src = '_imagenes/scrollizdaA.jpg';
	}
	
	if( pdfActual == - numPdfs + 3 )
	{
		scrollDchaPdf = false;
		document.getElementById( 'scrolldchaPdf' ).style.cursor='default';
		document.getElementById( 'scrolldchaPdf' ).src = '_imagenes/scrolldchaC.jpg';
	}
	else
	{
		scrollDchaPdf = true;
		document.getElementById( 'scrolldchaPdf' ).src = '_imagenes/scrolldchaA.jpg';
	}
}

function ScrollVideos( cuantas )
{
	videoActual += cuantas;
	
	for( x=0; x<numVideos; x++ )
	{
		var tmp = 305 * ( x + videoActual );
		
		$("#extraVideo" + x ).stop().animate( { left: tmp + "px" }, 200);
	}
	
	if( videoActual == 0 )
	{
		scrollIzdaVideo = false;
		
		document.getElementById( 'scrollizdaVideo' ).style.cursor='default';
		document.getElementById( 'scrollizdaVideo' ).src = '_imagenes/scrollizdaC.jpg';
	}
	else
	{
		scrollIzdaVideo = true;
		document.getElementById( 'scrollizdaVideo' ).src = '_imagenes/scrollizdaA.jpg';
	}
	
	if( videoActual == - numVideos + 4 )
	{
		scrollDchaVideo = false;
		document.getElementById( 'scrolldchaVideo' ).style.cursor='default';
		document.getElementById( 'scrolldchaVideo' ).src = '_imagenes/scrolldchaC.jpg';
	}
	else
	{
		scrollDchaVideo = true;
		document.getElementById( 'scrolldchaVideo' ).src = '_imagenes/scrolldchaA.jpg';
	}
}

function ScrollYoutubes( cuantas )
{
	youtubeActual += cuantas;
	
	for( x=0; x<numYoutubes; x++ )
	{
		var tmp = 305 * ( x + youtubeActual );
		
		$("#extraYoutube" + x ).stop().animate( { left: tmp + "px" }, 200);
	}
	
	if( youtubeActual == 0 )
	{
		scrollIzdaYoutube = false;
		
		document.getElementById( 'scrollizdaYoutube' ).style.cursor='default';
		document.getElementById( 'scrollizdaYoutube' ).src = '_imagenes/scrollizdaC.jpg';
	}
	else
	{
		scrollIzdaYoutube = true;
		document.getElementById( 'scrollizdaYoutube' ).src = '_imagenes/scrollizdaA.jpg';
	}
	
	if( youtubeActual == - numYoutubes + 4 )
	{
		scrollDchaYoutube = false;
		document.getElementById( 'scrolldchaYoutube' ).style.cursor='default';
		document.getElementById( 'scrolldchaYoutube' ).src = '_imagenes/scrolldchaC.jpg';
	}
	else
	{
		scrollDchaYoutube = true;
		document.getElementById( 'scrolldchaYoutube' ).src = '_imagenes/scrolldchaA.jpg';
	}
}

function SubMnuFuera( cual )
{
	document.getElementById( 'btSubMnu' + cual ).className = "btSubMnu";
}

function SubMnuSobre( cual )
{
	document.getElementById( 'btSubMnu' + cual ).className = "btSubMnuOver";
}
