/**************************************************************************
 *                                                                        *
 *  JAVASCRIPT MENU HIGHLIGHTER v.1.0 (051123)                            *
 * --------------------------------------------                           *
 * ©2005 Media Division (www.MediaDivision.com)                           *
 *                                                                        *
 * Written by Marius Smarandoiu & Armand Niculescu                        *
 *                                                                        *
 * You are free to use, modify and distribute this file, but please keep  *
 * this header and credits                                                *
 *                                                                        *
 * Usage:                                                                 *
 * - the script will apply the .current class to the <a> and its parent   *
 *   <li> that is contained in the element with id="primarynav" and points*
 *   to the current URL                                                   *
 * - works in IE6, Firefox and Opera                                      *
 **************************************************************************/
function extractPageName(hrefString)
{
 var arr = hrefString.split('.');
 if(arr.length >= 2) {
  arr = arr[arr.length-2].split('/');
  return arr[arr.length-1].toLowerCase();
 } else {
  return "x";
 }
}

function setActiveMenu(arr, crtPage)
{
	for(var i=0; i < arr.length; i++)
		if(extractPageName(arr[i].href) == crtPage)
		{
			var nombre;
			nombre=arr[i].parentNode.getAttribute("class");
			if(nombre==null){
				nombre="selec";
			}else{
				nombre=nombre + " selec";
			}
			arr[i].parentNode.className = nombre;	
		}

}

function setPage()
{
	if(document.location.href) 
		hrefString = document.location.href;
	else
		hrefString = document.location;
		
	/*if (document.getElementById("menu")!=null) 
		setActiveMenu(document.getElementById("menu").getElementsByTagName("a"), extractPageName(hrefString));*/
	if (document.getElementById("submenu")!=null) 
		setActiveMenu(document.getElementById("submenu").getElementsByTagName("a"), extractPageName(hrefString));
}
window.onload=function()
{
  setPage();
  externalLinks();
  	/*if(document.getElementById("video")){
  		cargar_video("video",460,330,"http://community.flowplayer.org/video/honda_commercial.flv","http://flowplayer.org/img/splash.jpg","http://flowplayer.org/img/splash.jpg","conf01");
	}*/
   if(document.getElementById("playlist")) 
	  cargar_playlist("video",372,232);
}

//usado para abrir nuevo navegador
function externalLinks() {

 if (!document.getElementsByTagName) return;

 var anchors = document.getElementsByTagName("a");
 var imagenes = document.getElementsByTagName("img");

 for (var i=0; i<anchors.length; i++) {

   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&

       anchor.getAttribute("rel") == "external")

     anchor.target = "_blank";
	 
	if (anchor.getAttribute("rel") == "external"){
		if(anchor.getAttribute("title")){
			var tit = anchor.getAttribute("title");
			if(obtenerIdioma()=="es"){
				anchor.title = tit + ". Se abre en ventana nueva";
			}
			if(obtenerIdioma()=="en"){
				anchor.title = tit + ". New window";
			}
		}else{
	     	if(obtenerIdioma()=="es"){
		     anchor.title = "Se abre en ventana nueva";
			}
			if(obtenerIdioma()=="en"){
		     anchor.title = "New window";
			}
		}
	}
	
 }
 //Comprobar imagenes con enlaces externos
 for(var b=0; b<imagenes.length; b++){
		
		var imagen = imagenes[b];
		if(imagen.parentNode.getAttribute("rel")=="external"){
			if(imagen.getAttribute("alt")){
				if(obtenerIdioma()=="es"){
				imagen.alt = imagen.getAttribute("alt") + ". Se abre en ventana nueva";
			     }
				 if(obtenerIdioma()=="en"){
				imagen.alt = imagen.getAttribute("alt") + ". New window";
			     }
			}else{
				
				if(obtenerIdioma()=="es"){
				imagen.alt = "Se abre en ventana nueva";
			     }
				 if(obtenerIdioma()=="en"){
				imagen.alt = "New window";
			     }
			}
			
		}

	}

}

function obtenerIdioma(){
	var idioma;
	var tmpURL=window.location.href;
	
	if (tmpURL.indexOf("/es/") != -1){
		idioma="es";
	}
	
	if (tmpURL.indexOf("/en/") != -1){
		idioma="en";
	}
	return idioma;
}

function validarColaborar(){
	var pattern = /^[a-zA-Z0-9\-\._]+@[a-zA-Z0-9\-_]+(\.?[a-zA-Z0-9\-_]*){2,3}\.[a-zA-Z]{2,3}$/;
				var Str;
        with (document.forms['formColabora']){
			
			if (apellidos.value=="" || apellidos.value==apellidos.title){
				alert(apellidos.title);
				apellidos.focus();
				return false;
           	} 
			if (nombre.value=="" || nombre.value==nombre.title){
				alert(nombre.title);
				nombre.focus();
				return false;
           	} 
			if (correo.value=="" || correo.value==correo.title){
				alert(correo.title);
				correo.focus();
				return false;
           	}
			Str = idea.value;
				if (Str.length == 0 || idea.value==idea.title)
				{
					alert (idea.title);
					idea.focus();
					return false;
				}
		}
}

/*Cargar video*/

function cargar_playlist(id,ancho,alto){
	var playerConfig = { 
		initialScale:'scale',
		showLoopButton:true,
		showPlayList:true,
		showPlayListButtons:true,
		scaleSplash:false,
		autoPlay:false,
		autobuffering:false,
		bufferLength:0,
		splashImageFile:'/imagenes/fot_00_02.jpg',
		noVideoClip:{ url:'/imagenes/fot_00_02.jpg'},
		loop:true
	}
	var flowplayer = null;  
    
   /************* THE PLAYLIST ***************/ 
    
   // loop all links within DIV#playlist and customize their onClick event  
   var links = document.getElementById("playlist").getElementsByTagName("a");  
    
   for (var i = 0; i < links.length; i++) { 
 
      links[i].onclick = function() {  
    
         /* 
          * set links href attribute as the videoFile property in our  
          * configuration. of cource you can modify other properties as well 
          */ 
         playerConfig.videoFile = this.getAttribute("href"); 
          
         // if flowplayer is not loaded. load it now. 
         if (flowplayer == null) { 
          
            // create Flowplayer instance into DIV element whose id="player" 
            // Flash API is automatically returned (flashembed.js ver. 0.27) 
            flowplayer = flashembed(id,  
               {src:'/videos/FlowPlayerDark.swf',
				width: ancho, 
				height: alto},  
                
               // supply our (modified) configuration to the player 
               {config: playerConfig} 
            );  
             
         // flowplayer is already loaded - now we simply call setConfig() 
         } else {     
            flowplayer.setConfig(playerConfig);  
         } 
          
         // disable link's default behaviour 
         return false;  
      }      
   } 
   
   //Cargar video
   playerConfig.videoFile = links[0].getAttribute("href"); 
          
         // if flowplayer is not loaded. load it now. 
         if (flowplayer == null) { 
          
            // create Flowplayer instance into DIV element whose id="player" 
            // Flash API is automatically returned (flashembed.js ver. 0.27) 
            flowplayer = flashembed(id,  
               {src:'/videos/FlowPlayerDark.swf',
				width: ancho, 
				height: alto},  
                
               // supply our (modified) configuration to the player 
               {config: playerConfig} 
            );  
             
         // flowplayer is already loaded - now we simply call setConfig() 
         } else {     
            flowplayer.setConfig(playerConfig);  
         } 
   
}


function cargar_video(id,ancho,alto,flv,img,imgNoVideo,conf){

if(conf=='conf01'){	
	var playerConfig = { 
		videoFile: flv,			
		splashImageFile:img,
		noVideoClip:{ url:imgNoVideo},
		initialScale:'scale',
		showLoopButton:true,
		showPlayList:true,
		showPlayListButtons:true,
		scaleSplash:false,
		autoPlay:false,
		autobuffering:false,
		bufferLength:0,
		loop:false
	} 
}else{
	var playerConfig = { 
		videoFile: flv,
		splashImageFile:img,
		noVideoClip:{ url:imgNoVideo},
		initialScale:'scale',
		showLoopButton:true,
		showPlayList:true,
		showPlayListButtons:true,
		scaleSplash:false,
		autoPlay:false,
		autobuffering:false,
		bufferLength:0,
		loop:false,			   
		showVolumeSlider: false,
		controlsOverVideo: 'ease',
        controlBarGloss: 'none' 
	}
}

		flashembed(id, 
		  {
			 src:'/videos/FlowPlayerDark.swf',
				width: ancho, 
				height: alto
		  },
		  {config: playerConfig}
	   );

}