
addLoadEvent(addHandlers);

function addHandlers()
{
	var h = document.getElementsByTagName('html');
	var idioma = h[0].lang;
	switch(idioma.toLowerCase())	{
		case "es":
			var texto = ' (se abre en nueva ventana)';
			break;
		case "en":
			var texto = ' (open a new window)';
			break;
		case "fr":
			var texto = ' (il est ouvert dans une nouvelle fenętre)';
			break;
		case "ca":
  		var texto = ' (sobre en finestra nova)';
			break;
		case "gl":
			var texto = ' (ábrese en fiestra nova)';
			break;
		case "eu":
			var texto = ' (lehio berria apurtu)';
			break;
		}

	var enlaces = document.getElementsByTagName('a'); 
	for (var i = 0; i < enlaces.length; i++) { 
		if(enlaces[i].className.indexOf('cert_tooltip') != -1)
		{
				
			var span = document.createElement('span');
			var contenido = document.createTextNode(texto);
			span.appendChild(contenido);
			enlaces[i].appendChild(span);
		    enlaces[i].onclick = function(event){return launchWindow(this, event);}
		    enlaces[i].onkeypress = function(event){return launchWindow(this, event);}
		}
		
		if(enlaces[i].className.indexOf('cert_newwin') != -1)
		{
			if(enlaces[i].title != ""){
				enlaces[i].title += texto;
			}else{
				enlaces[i].title = enlaces[i].innerHTML+texto;
			}	
      		var span = document.createElement('span');
			var imagen = document.createElement('img');
			imagen.src = '/extfrontinteco/img/intecocert/new_window.png';
			imagen.border = '0';
			imagen.alt=texto;
			imagen.hspace='5'; // Solución para separar la imagen en IE
			span.innerHTML=' '; // Solución para separar la imagen en FireFox
			span.appendChild(imagen);
			enlaces[i].appendChild(span);
		    enlaces[i].onclick = function(event){return launchWindow(this, event);}
		    enlaces[i].onkeypress = function(event){return launchWindow(this, event);}
		}
		
		
	}
}

function launchWindow(objAnchor, objEvent)
{
  var iKeyCode, bSuccess=false;

  // If the event is from a keyboard, we only want to open the
  // new window if the user requested the link (return or space)
  if (objEvent && objEvent.type == 'keypress')
  {
    if (objEvent.keyCode)
      iKeyCode = objEvent.keyCode;
    else if (objEvent.which)
      iKeyCode = objEvent.which;

    // If not carriage return or space, return true so that the user agent
    // continues to process the action
    if (iKeyCode != 13 && iKeyCode != 32)
      return true;
  }

  bSuccess = window.open(objAnchor.href);

  // If the window did not open, allow the browser to continue the default
  // action of opening in the same window
  if (!bSuccess)
    return true;

  // The window was opened, so stop the browser processing further
  return false;
}
