/* **********************************************************************************
 *                                   FUNCIONES COMUNES A TODO EL PANEL DE CONTROL
 * PROYECTO:
 *           GENERAL.
 *
 * Desarrollado por:
 *           FORMATIA - Formación, Consulta y Desarrollo PEFER, S.L.
 *                    - C/ Capitán Gallarza, 1 entlo. - 26001 - Logroño - La Rioja
 *                    - 941 202 596 - 941 214 304 - desarrollo@formatia.net
 *
 * Fecha de inicio del proyecto: 07/11/2007
 * **********************************************************************************
 * Fichero JavaScript: /js/general_funciones01.js
 * Archivos asociados:
 *    cualquiera
 *
 * Fecha de creación del fichero:  06/06/2007
 * Desarrollador: Luis Fernández
 * Modificaciones:
 *
 * ******************************************************************************* */

/* **********************************************************************************
 * function DetectaNavegador()
 *    Entrada:
 *    Salida:
 *       Detecta el navegador cliente y asigna a 3 variables un valor true/false.
 *       ns4: Netscape4
 *       ns6: Netscape6+ / Internet Explorer 5+
 *       ie4: Internet Explorer 4
 * ******************************************************************************* */
var ns4;
var ns6;
var ie4;

function DetectaNavegador(){
    ns4 = (document.layers)? true:false;
    ns6 = (document.getElementById)? true:false;
    ie4 = (document.all)? true:false;
}
DetectaNavegador();
/* **********************************************************************************
 * ###### CAPAS - LAYERS - DIVS
 * ******************************************************************************* */
/* **********************************************************************************
 * function mostrarCapa(capa)
 *    Entrada:
 *       capa: Variable que contiene el id de la capa a mostrar.
 *    Salida:
 *       Hace visible la capa [capa].
 * ******************************************************************************* */
function mostrarCapa(capa){
   if (ns6){
      document.getElementById(capa).style.visibility = "visible";
      document.getElementById(capa).style.display = "block";
   }else if (ie4){
      document.all[capa].style.visibility = "visible";
      document.all[capa].style.display = "block";
   }else if (ns4){
      document.layers[''+capa].visibility = "visible";
      document.layers[''+capa].display = "block";
   }
}

/* **********************************************************************************
 * function ocultarCapa(capa)
 *    Entrada:
 *       capa: Variable que contiene el id de la capa a mostrar.
 *    Salida:
 *       Oculta la capa [capa].
 * ******************************************************************************* */
function ocultarCapa(capa){
   if (ns6){
      document.getElementById(capa).style.visibility = "hidden";
      document.getElementById(capa).style.display = "none";
   }else if (ie4){
      document.all[capa].style.visibility = "hidden";
      document.all[capa].style.display = "none";
   }else if (ns4){
      document.layers[''+capa].visibility = "hide";
      document.layers[''+capa].display = "none";
   }
}

/* **********************************************************************************
 * function pintarCapa(capa, color)
 *    Entrada:
 *       capa: Variable que contiene el id de la capa a pintar el background.
 *       color: Valor RGB.
 *    Salida:
 *      Pinta el background de la capa [capa] del color [color].
 * ******************************************************************************* */
function pintarCapa(capa, color){
   if (ns6){
      document.getElementById(capa).style.backgroundColor = color;
   }else if (ie4){
      document.all[capa].style.backgroundColor = color;
   }else if (ns4){
      document.layers[''+capa].backgroundColor = color;
   }
}

/* **********************************************************************************
 * function writeCapaInnerHTML(capa, texto)
 *    Entrada:
 *       capa: Variable que contiene el id de la capa a escribir.
 *       texto: contenido HTML que hay que escribir.
 *    Salida:
 *       Escribe el innerHTML de la capa [capa] con el texto [texto].
 * ******************************************************************************* */
function writeCapaInnerHTML(capa, texto){
   if (ns6){
      document.getElementById(capa).innerHTML = texto;
   }else if (ie4){
      document.all[capa].innerHTML = texto;
   }else if (ns4){
      document.layers[''+capa].innerHTML = texto;
   }
}

/* **********************************************************************************
 * ###### IMAGENES
 * ******************************************************************************* */
/* **********************************************************************************
 * function isImageOnload(img, time_out_var, func)
 *    Entrada:
 *       img: Objeto imagen de la que se quiere controlar su carga.
 *       time_out_var: Variable setTimeOut que controla la repetición cíclica.
 *       func: Función a ejecutar. Se debe pasar com texto.
 *
 *    Salida:
 *       Controla si la imagen img ha sido cargada. Al terminar la carga aplica
 *       un clearTimeout a la variable time_out_var y ejecuta la función func.
 * ******************************************************************************* */
function isImageOnload(img, time_out_var, func){
    if (!img.complete) return false;
    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) return false;
    window.clearTimeout(eval(time_out_var));
    eval(func);
    return true;
}

/* **********************************************************************************
 * ###### DIMENSIONES - SCREEN - CAPAS
 * ******************************************************************************* */
/* **********************************************************************************
 * function getWidth(obj):  Devuelve la anchura del objeto obj.
 * function getHeight(obj): Devuelve la altura del objeto obj.
 * ******************************************************************************* */
function getWidth(obj){
   width_x = 0;
   if (typeof(window.innerWidth) == 'number'){
      width_x = obj.innerWidth;
   }else if (document.documentElement && document.documentElement.clientWidth){
      width_x = obj.document.documentElement.offsetWidth;
   }else if (document.body && document.body.clientWidth){
      width_x = obj.document.body.clientWidth;
   }
   return width_x;
}
function getHeight(obj){
   height_y = 0;
   if (typeof(window.innerHeight) == 'number'){
      height_y = obj.innerHeight;
   }else if (document.documentElement && document.documentElement.clientHeight){
      height_y = obj.document.documentElement.offsetHeight;
   }else if (document.body && document.body.clientHeight){
      height_y = obj.document.body.clientHeight;
   }
   return height_y;
}

/* #############################################################################
function runSWF(archivo, ancho, alto, version, bgcolor, id, menu, FlashVars, quality, allowScriptAccess)
	Esta función lo que hace es que cuando insertemos un flash en nuestra página no aparezca un cuadro en internet en explorer que nos diga
	"Pulse aquí para activar el control"
	ESTÁ CONFIGURADO PARA QUE EL FONDO SEA TRANSPARENTE
	Entrada:
		Archivo: nombre del archivo
		Ancho: ancho del archivo
		Alto: alto del archivo
		Los demás parametros no son obligatorios
############################################################################# */

   function runSWF(archivo, ancho, alto, version, bgcolor, id, menu, FlashVars, quality, allowScriptAccess)
   {
      if(version!="")
	  {
         var version_data=version;
      }
	  else
	  {
	     var version_data="6,0,0,0";
	  }
	  if(menu!="")
	  {
	     menu_data=menu;
	  }
	  else
	  {
	     menu_data=false;
	  }
	  if(bgcolor!="")
	  {
	     var bgcolor_data=bgcolor;
	  }
	  else
	  {
	     var bgcolor_data="#FFFFFF";
	  }
	  if(id!="")
	  {
	     id_data=id;
	  }
	  else
	  {
	     id_data="flashMovie";
	  }
	  if(quality!="")
	  {
	     quality_data=quality;
	  }
	  else
	  {
	     quality_data="high";
	  }
	  if (allowScriptAccess != "")
	  {
	     allowScriptAccess_data=allowScriptAccess;
	  }
	  else
	  {
	     allowScriptAccess_data="always";
	  }
	  var quality="high";
	  document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase= "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version= '+version_data+'" width='+ancho+' height='+alto+' id='+id_data+'>\n');
	  document.write('<param name="movie" value='+archivo+'>\n');
	  document.write('<param name= "allowScriptAccess" value= '+allowScriptAccess_data+'>\n');
	  document.write('<param name="quality" value='+quality_data+'>\n');
	  document.write('<param name="FlashVars" value='+FlashVars+'>\n');
	  document.write('<param name="wmode" value="transparent">\n');
	  document.write('<param name="wmode" value="transparent">\n');
	  document.write('<param name="menu" value='+menu_data+' >\n');
	  document.write('<embed src='+archivo+' bgcolor='+bgcolor_data+' wmode=transparent FlashVars='+FlashVars+' menu='+menu_data+' allowScriptAccess='+allowScriptAccess_data+' quality='+quality_data+' pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width='+ancho+' height='+alto+' swLiveConnect=true name='+id_data+'></embed>');
	  document.write('</object>\n');
   }

/* **********************************************************************************
 * ###### LANZAR POPUP
 * ******************************************************************************* */
function lanzarPopup(archivo,tgt,ancho,alto,scrlbrs)
{
	var hz=window.screen.height
	var wz=window.screen.width
	var top
	var left
	try {
		top = (hz / 2) - (alto / 2);
		left = (wz / 2) - (ancho / 2);
	}
	catch(e) {
		alert(e.message);
	}
	window.open(archivo,tgt,'width=' + ancho + ',height=' + alto + ',menubar=no,scrollbars=' + scrlbrs + ',toolbar=no,location=no,directories=no,resizable=no,top=' + top + ',left=' + left);
}