var JSLekue = Class.create();

Event.observe(window,"load", function(){
	jsLekue = new JSLekue();
	Object.extend(window, jsLekue);
});

JSLekue.prototype = {
	initialize : function(){
		if($('buscarTop')){
			Event.observe($("buscarTop"), "click", this.buscarTop);
		}
		if($('imprimir')){
			Event.observe($("imprimir"), "click", this.imprimir);
		}
		if($('msgResolucion')){
			if(screen.width < 1024){
				$('msgResolucion').innerHTML = " | Optimal resolution: 1024 x 768";
			}
		}
	},

	buscarTop : function(){
		window.location = "buscador.php?opcion=linea&tipoProducto="+$F('tipoProductoTop') + "&coleccionProducto=" + $F("coleccionTop");
		return false;
	},

	imprimir : function(){
		window.print();
		return false;
	},

	mostrarLoading : function(capa){
		var opciones = {asynchronous:false, evalScripts: true};
		new Ajax.Updater(capa, "loading.php", opciones);
	}
}

CapaDescrip = Class.create();

CapaDescrip.prototype = {
	win : null,
	opciones : null,

	initialize : function() {
		this.opciones = Object.extend({
			titol : "",
			ancho : 500,
			alto : 400,
			mostrar : "",
      		onComplete : Prototype.emptyFunction,
      		onCloseWindow : Prototype.emptyFunction,
      		showEffect : Effect.BlindDown,
			hideEffect : Effect.BlindUp
    	}, arguments[0] || {});
	},

	mostrar : function(){
		this.win = new Window('modal_window', {
            className: "dialog",
            title: "<img src='img/shim.gif'>",
            width: this.opciones.ancho,
            height: this.opciones.alto,
            zIndex:150,
            opacity:1,
            minimizable: false,
            maximizable: false,
            resizable: false,
            closable : false,
            draggable : false,
            showEffect : this.opciones.showEffect,
			hideEffect : this.opciones.hideEffect
		});

		this.win.setDestroyOnClose();

		var params = {asynchronous:true, evalScripts: true, encoding: 'UTF-8', onComplete : this.completado.bindAsEventListener(this)};
		url = "descripcion.php";
		this.win.setAjaxContent(url, params, true, true);
	},

	completado : function(){
		Event.observe($('cerrarDescript'), "click", this.cerrarDescript.bindAsEventListener(this));
		new Ajax.Updater('contenidoDescript', this.opciones.mostrar, {
			onComplete : this.opciones.onComplete
		});
		
	},

	cerrarDescript : function(){
		this.win.close();
		this.opciones.onCloseWindow();
	}
}

var ControlFichExt = Class.create();

ControlFichExt.prototype = {
	initialize : function(){
		$$('input.fichero').each(function(item){
			Event.observe(item, "change", this.recojerExtFich);
		}.bind(this));
	},

	recojerExtFich : function(evt){
		elemento = Event.element(evt);
		var fichero = $F(elemento);
		long_fichero = fichero.length;
		pos_extension = fichero.lastIndexOf(".");
		$(elemento.id + "Ext").value = fichero.substring(pos_extension+1, long_fichero);
	}
}