
// Fichero con funciones utiles para la aplicacion

function DarFecha () {
    var d=new Date();
    var dayarray=new Array("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado")
    var montharray=new Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
    var f="",h="",c=":",w;

    var dia = dayarray[d.getDay()];
    var mes = montharray[d.getMonth()];
        
    mi_dia = d.getDate();
    mi_anyo = d.getYear();
    

    f += d.getDate() + "/";
    f += (d.getMonth() + 1) + "/";
    f += d.getYear();

    h += d.getHours() + c;
    w = d.getMinutes();
    h += (w > 9) ? w+c : "0"+w+c;
    w = d.getSeconds();
    h += (w > 9) ? w : "0"+w;
 
    var t = mi_dia + " " + mes + " " + mi_anyo + "<br>" + h;
        
    if (navigator.appName == "Netscape") {
        if (document.getElementById)  // Netscape 6.x
            document.getElementById("reloj").innerHTML = t;
        else
        if (document.layers) {        // Netscape 4.x
            document.layers["reloj"].document.open();
            document.layers["reloj"].document.write(t);
            document.layers["reloj"].document.close();
        }
    }
    else {
        reloj.innerHTML = t;
    }
    
}

function Inicio () {
    DarFecha();
    setTimeout("Inicio()",1000);
}

// Codigo javascript para el manejo de las pulsaciones de botones
// 0 significa inactivo, 1 activado

var estadoGrupoAbasa = 0;
var estadoProductos = 0;
var estadoNovedades = 0;
var estadoContactar = 0;
var estadoInicio = 0;

function volverInicio ()
{
  parent.frames['framelogo'].document.location = "gris.html";
  parent.frames['frameprincipal'].document.location = "home.html";
  document.location = "botones_inicio.html";
}

function apagarRestoBotones ( boton )
{
  if ( boton == 0 )
  {
    document.productos.src = "imagenes/menu/boton_productos_malva.jpg";
    estadoProductos = 0;
  
    document.novedades.src = "imagenes/menu/boton_novedades_malva.jpg";
    estadoNovedades = 0;
    
    document.contactar.src = "imagenes/menu/boton_contactar_malva.jpg";
    estadoContactar = 0;
    
    document.inicio.src = "imagenes/menu/boton_inicio_malva.jpg";
    estadoInicio = 0;
    
  }
  else if ( boton == 1 )
  {
    document.grupoAbasa.src = "imagenes/menu/boton_grupo_malva.jpg";
    estadoGrupoAbasa = 0;
    
    document.novedades.src = "imagenes/menu/boton_novedades_malva.jpg";
    estadoNovedades = 0;
    
    document.contactar.src = "imagenes/menu/boton_contactar_malva.jpg";
    estadoContactar = 0;

    document.inicio.src = "imagenes/menu/boton_inicio_malva.jpg";
    estadoInicio = 0;
  }
  else if ( boton == 2 )
  {
    document.grupoAbasa.src = "imagenes/menu/boton_grupo_malva.jpg";
    estadoGrupoAbasa = 0;
    
    document.productos.src = "imagenes/menu/boton_productos_malva.jpg";
    estadoProductos = 0;
    
    document.contactar.src = "imagenes/menu/boton_contactar_malva.jpg";
    estadoContactar = 0;
  
    document.inicio.src = "imagenes/menu/boton_inicio_malva.jpg";
    estadoInicio = 0;
  }
  else if ( boton == 3 )
  {
    document.grupoAbasa.src = "imagenes/menu/boton_grupo_malva.jpg";
    estadoGrupoAbasa = 0;
  
    document.productos.src = "imagenes/menu/boton_productos_malva.jpg";
    estadoProductos = 0;
    
    document.novedades.src = "imagenes/menu/boton_novedades_malva.jpg";
    estadoNovedades  = 0;
    
    document.inicio.src = "imagenes/menu/boton_inicio_malva.jpg";
    estadoInicio = 0;
  }
  else if ( boton == 4 )
  {
    document.grupoAbasa.src = "imagenes/menu/boton_grupo_malva.jpg";
    estadoGrupoAbasa = 0;
    
    document.productos.src = "imagenes/menu/boton_productos_malva.jpg";
    estadoProductos = 0;
    
    document.novedades.src = "imagenes/menu/boton_novedades_malva.jpg";
    estadoNovedades  = 0;
    
    document.contactar.src = "imagenes/menu/boton_contactar_malva.jpg";
    estadoContactar = 0;
  }
}


function cambiarImagen( boton )
{
	if (boton == 0) // Se pulso el boton Grupo Abasa
	{
	  document.grupoAbasa.src = "imagenes/menu/boton_grupo_marron.jpg";
	  estadoGrupoAbasa = 1;
	  //parent.frameprincipal.document.DivContenido.innerHTML="logo.html";
	  apagarRestoBotones( 0 );
	  parent.frames['frameprincipal'].document.location = "grupo_abasa.html";
	}
	else if (boton == 1) // Se pulso el boton Productos
	{
	  document.productos.src = "imagenes/menu/boton_productos_marron.jpg";
	  estadoProductos = 1;
	  apagarRestoBotones( 1 );
	  parent.frames['frameprincipal'].document.location = "productos.html";
	}
	else if (boton == 2) // Se pulso el boton Novedades
	{
	  document.novedades.src = "imagenes/menu/boton_novedades_marron.jpg";
	  estadoNovedades = 1;
	  apagarRestoBotones( 2 );
	  parent.frames['frameprincipal'].document.location = "novedades.html";
	}
	else if (boton == 3) // Se pulso el boton Contactar
	{
	  document.contactar.src = "imagenes/menu/boton_contactar_marron.jpg";
	  estadoContactar = 1;
	  apagarRestoBotones( 3 );
	  parent.frames['frameprincipal'].document.location = "contactar.html";
	}
	else if (boton == 4) // Se pulso el boton Inicio
	{
	  document.inicio.src = "imagenes/menu/boton_inicio_marron.jpg";
	  estadoInicio = 1;
	  apagarRestoBotones( 4 );
	}
}

function cambiarImagenBotonesInicio ( boton )
{
  // Mostramos el logo
  parent.frames['framelogo'].document.location = "logo.html";
  
  if (boton == 0) // Se pulso el boton Grupo Abasa
  {
    parent.frames['frameprincipal'].document.location = "grupo_abasa.html";
    document.location = "botones.html?boton=0";
  }
  else if (boton == 1) // Se pulso el boton Productos
  {
    parent.frames['frameprincipal'].document.location = "productos.html";
    document.location = "botones.html?boton=1";
  }
  else if (boton == 2) // Se pulso el boton Novedades
  {
    parent.frames['frameprincipal'].document.location = "novedades.html";
    document.location = "botones.html?boton=2";
  }
  else if (boton == 3) // Se pulso el boton Contactar
  {
    parent.frames['frameprincipal'].document.location = "contactar.html";
    document.location = "botones.html?boton=3";
  }
}


// Funcion que maneja la pulsacion de un enlace en la pagina de novedades

function pulsacionEnlaceNovedades ( categoriaProductos )
{
  
  // En el menu de botones resaltamos el boton Productos
  parent.frames['framebotones'].document.location = 'botones.html?boton=1';

  if ( categoriaProductos == 0 ) // Novedades de Vajillas
  {
    parent.frames['framemenu'].location = "menu_productos.html?boton=0";
  }
  else if ( categoriaProductos == 1 ) // Novedades de Cuberterias
  {
    parent.frames['framemenu'].location = "menu_productos.html?boton=1";
  }
  else if ( categoriaProductos == 2 ) // Novedades de Cristalerias
  {
    parent.frames['framemenu'].location = "menu_productos.html?boton=2";
  }
  else if ( categoriaProductos == 3 ) // Novedades de Mantelerias
  {
    parent.frames['framemenu'].location = "menu_productos.html?boton=3";
  }
  else if ( categoriaProductos == 4 ) // Novedades de Menaje
  {
    parent.frames['framemenu'].location = "menu_productos.html?boton=4";
  }
  else if ( categoriaProductos == 5 ) // Novedades de Mobiliario
  {
    parent.frames['framemenu'].location = "menu_productos.html?boton=5";
  }
  else if ( categoriaProductos == 6 ) // Novedades de Maquinaria
  {
    parent.frames['framemenu'].location = "menu_productos.html?boton=6";
  }
}


function apagarRestoBotonesInicio ( boton )
{
   alert( "Entro el apagarRestoBontonesInicio" );
  // Generamos actividad para el boton de inicio
  //document.celdainicio.innerHTML = "<img onClick='volverInicio()' name='inicio' src='imagenes/transparent.gif' width='104' height='16' border='0'>";
    
  if ( boton == 0 )
    {
      document.productos.src = "imagenes/menu/boton_productos_malva.jpg";
      estadoProductos = 0;
    
      document.novedades.src = "imagenes/menu/boton_novedades_malva.jpg";
      estadoNovedades = 0;
      
      document.contactar.src = "imagenes/menu/boton_contactar_malva.jpg";
      estadoContactar = 0;
            
      estadoInicio = 0;
      
    }
    else if ( boton == 1 )
    {
      alert( "Se pulso el boton Productos" );
      document.grupoAbasa.src = "imagenes/menu/boton_grupo_malva.jpg";
      estadoGrupoAbasa = 0;
      
      document.novedades.src = "imagenes/menu/boton_novedades_malva.jpg";
      estadoNovedades = 0;
      
      document.contactar.src = "imagenes/menu/boton_contactar_malva.jpg";
      estadoContactar = 0;
        
      estadoInicio = 0;
    }
    else if ( boton == 2 )
    {
      document.grupoAbasa.src = "imagenes/menu/boton_grupo_malva.jpg";
      estadoGrupoAbasa = 0;
      
      document.productos.src = "imagenes/menu/boton_productos_malva.jpg";
      estadoProductos = 0;
      
      document.contactar.src = "imagenes/menu/boton_contactar_malva.jpg";
      estadoContactar = 0;
          
      estadoInicio = 0;
    }
    else if ( boton == 3 )
    {
      document.grupoAbasa.src = "imagenes/menu/boton_grupo_malva.jpg";
      estadoGrupoAbasa = 0;
    
      document.productos.src = "imagenes/menu/boton_productos_malva.jpg";
      estadoProductos = 0;
      
      document.novedades.src = "imagenes/menu/boton_novedades_malva.jpg";
      estadoNovedades  = 0;
            
      estadoInicio = 0;
  }
}

function validar_email(direccion)
{
	arroba_location= direccion.indexOf("@");
	punto_location= direccion.indexOf(".");
	
	if (arroba_location == -1 || punto_location == -1 || arroba_location > punto_location) { return false }
	
	if (arroba_location == 0) { return false }
	if (punto_location - arroba_location <= 1) { return false }
	if (direccion.length - punto_location <= 1) { return false }
	
	return true;
}
