// Variables globales

///////////////////////////////////
//  MODIFICAR ESTO - INICIO      //
///////////////////////////////////
var requiredVersion = 6;         // Versión de flash necesitada (mínima v2 máxima v9)
///////////////////////////////////
//  MODIFICAR ESTO - FIN         //
///////////////////////////////////

var useRedirect = false;         // true cargara una página dependiendo del resultado del discriminador
                           
// Cambiar esto si useRedirect = true (si no es asi ni se usan).
var flashPage   = "siflash.htm"  // Página donde está el flash
var noFlashPage = "noflash.htm"  // Página si no se detecta flash
var upgradePage = "upgrade.htm"  // Página si la versión de flash es vieja

///////////////////////////////////
// NO MODIFICAR A PARTIR DE AQUÍ //
///////////////////////////////////
// Globales del sistema
var flash2Installed = false;     // booleano. true si flash 2 esta instalado
var flash3Installed = false;     // booleano. true si flash 3 esta instalado
var flash4Installed = false;     // booleano. true si flash 4 esta instalado
var flash5Installed = false;     // booleano. true si flash 5 esta instalado
var flash6Installed = false;     // booleano. true si flash 6 esta instalado
var flash7Installed = false;     // booleano. true si flash 7 esta instalado
var flash8Installed = false;     // booleano. true si flash 8 esta instalado
var flash9Installed = false;     // booleano. true si flash 9 esta instalado
var maxVersion = 9;              // version más alta que se puede detectar actualmente
var actualVersion = 0;           // versión que tiene el usuario
var hasRightVersion = false;     // booleano. true si se puede embeber el flash en la página
var jsVersion = 1.0;             // versión de javascript soportada


// Chequeamos por el navegador. Buscamos IE pero no el de AOL
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;    // true si es IE
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false; // true si estamos en WINDOWS


// Este es un cacho de código en javascript 1.1 para comprobar que funciona.
jsVersion = 1.1;

// Escribimos la detección vbscript para IE en WINDOWS. 
// IE en WINDOWS no soporta detecciones de array por javascript.
if(isIE && isWin){
  document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
  document.write('on error resume next \n');
  document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
  document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
  document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
  document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');  
  document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');  
  document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
  document.write('flash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
  document.write('flash9Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n');
  document.write('<\/SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
}


// Detección estadar de flash buscando en el array navigator.plugins
function detectFlash() {  
  // Si existe navigator.plugins existe...
  if (navigator.plugins) {
    // ... buscamos flash v2 ó v3+
    if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
      // Se ha encontrado una versión de flash. Veamos cual.
      var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;

      // alert("Descripción del pluging Flash: " + flashDescription);
      
      var flashVersion = parseInt(flashDescription.substring(16));
      flash2Installed = flashVersion == 2;    
      flash3Installed = flashVersion == 3;
      flash4Installed = flashVersion == 4;
      flash5Installed = flashVersion == 5;
      flash6Installed = flashVersion == 6;
      flash7Installed = flashVersion == 7;
      flash8Installed = flashVersion == 8;
      flash9Installed = flashVersion >= 9;
    }
  }
  
  // Bucle entre todas las versiones que chequeamos
  // Seleccionar la mas alta como la actual.
  for (var i = 2; i <= maxVersion; i++) {  
    if (eval("flash" + i + "Installed") == true) actualVersion = i;
  }
  
  // Si estamos en msntv (formalmente webtv), la versión soportada es la 4
  if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 4;  
  
  // alert("version detected: " + actualVersion);


  if (actualVersion >= requiredVersion) {
    if (useRedirect) {
      if(jsVersion > 1.0) {
        window.location.replace(flashPage);  
      }
	  else {
        window.location = flashPage;
      }
    }
    hasRightVersion = true;                
  } 
  else {  
    if (useRedirect) {
      if(jsVersion > 1.0) {
        window.location.replace((actualVersion >= 2) ? upgradePage : noFlashPage);
      } 
	  else {
        window.location = (actualVersion >= 2) ? upgradePage : noFlashPage;
      }
    }
  }
}

detectFlash();


//FUNCIÓN PARA ABRIR VENTANA CENTRADA, SE LLAMA AL EJECUTAR EL ALTERNATECONTENT

function GP_AdvOpenWindow(theURL,winName,features,popWidth,popHeight,winAlign,ignorelink,alwaysOnTop,autoCloseTime,borderless) { //v2.0
  var leftPos=0,topPos=0,autoCloseTimeoutHandle, ontopIntervalHandle, w = 480, h = 340;  
  if (popWidth > 0) features += (features.length > 0 ? ',' : '') + 'width=' + popWidth;
  if (popHeight > 0) features += (features.length > 0 ? ',' : '') + 'height=' + popHeight;
  if (winAlign && winAlign != "" && popWidth > 0 && popHeight > 0) {
    if (document.all || document.layers || document.getElementById) {w = screen.availWidth; h = screen.availHeight;}
		if (winAlign.indexOf("center") != -1) {topPos = (h-popHeight)/2;leftPos = (w-popWidth)/2;}
		if (winAlign.indexOf("bottom") != -1) topPos = h-popHeight; if (winAlign.indexOf("right") != -1) leftPos = w-popWidth; 
		if (winAlign.indexOf("left") != -1) leftPos = 0; if (winAlign.indexOf("top") != -1) topPos = 0; 						
    features += (features.length > 0 ? ',' : '') + 'top=' + topPos+',left='+leftPos;}
  if (document.all && borderless && borderless != "" && features.indexOf("fullscreen") != -1) features+=",fullscreen=1";
  if (window["popupWindow"] == null) window["popupWindow"] = new Array();
  var wp = popupWindow.length;
  popupWindow[wp] = window.open(theURL,winName,features);
  if (popupWindow[wp].opener == null) popupWindow[wp].opener = self;  
  if (document.all || document.layers || document.getElementById) {
    if (borderless && borderless != "") {popupWindow[wp].resizeTo(popWidth,popHeight); popupWindow[wp].moveTo(leftPos, topPos);}
    if (alwaysOnTop && alwaysOnTop != "") {
    	ontopIntervalHandle = popupWindow[wp].setInterval("window.focus();", 50);
    	popupWindow[wp].document.body.onload = function() {window.setInterval("window.focus();", 50);}; }
    if (autoCloseTime && autoCloseTime > 0) {
    	popupWindow[wp].document.body.onbeforeunload = function() {
  			if (autoCloseTimeoutHandle) window.clearInterval(autoCloseTimeoutHandle);
    		window.onbeforeunload = null;	}  
   		autoCloseTimeoutHandle = window.setTimeout("popupWindow["+wp+"].close()", autoCloseTime * 1000); }
  	window.onbeforeunload = function() {for (var i=0;i<popupWindow.length;i++) popupWindow[i].close();}; }   
  document.MM_returnValue = (ignorelink && ignorelink != "") ? false : true;
}

function popupnoflash() {
    GP_AdvOpenWindow("noflash.htm","noflash","fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no",500,280,"center","ignoreLink","",0,"");
    return document.MM_returnValue;
}