/////////////////////////
// Clase VentanaFlotante
/////////////////////////

function VentanaFlotante(url, winName, features, width, height, isCenter) {
	this.oWindow = null;
	this.url = url;
	this.winName = winName;
	
	var ahora = new Date();
	this.winNameUnico = winName + '_' + ahora.getTime();
	
	this.features = features;
	this.width = width;
	this.height = height;
	this.isCenter = isCenter;
	VentanaFlotante.all[VentanaFlotante.all.length] = this;
}

VentanaFlotante.prototype.mostrar = function(parametros) {
	
	if(this.oWindow) {
		if(this.oWindow.closed) {
			this.oWindow = null;
		}
	}
		
	if(!this.oWindow)	{
		// Se cierran todas las ventanas abiertas
		VentanaFlotante.cerrarVentanas();
		
		var strfeatures = this.features 
		strfeatures += (this.features)?',':'';
		strfeatures += 'width=' + this.width + ',height=' + this.height;
				

		var src = (document.all) ? (this.url) : this.url;
		////////////////////////////////////////////

		for(var i=0; i<parametros.length; i++) {
			
			/* Si el i es distinto de cero incluimos el separador de nueva variable '&' */
			alert('dentro parametros');
			if (i!=0){
				src += '&' + parametros[i][0] + '=' + encodeURIComponent(parametros[i][1]); 
				
			}else{
				src += parametros[i][0] + '=' + encodeURIComponent(parametros[i][1]); 
				
			}
		
		}
	
		if(window.screen) {
			if(this.isCenter) {
				var x = (screen.availWidth - this.width)/2;
	    	var y = (screen.availHeight - this.height)/2;
	    	strfeatures += ',left=' + x + ',top=' + y;
	 		}
		}
		this.oWindow = window.open(src, this.winNameUnico, strfeatures);
		//alert(src);
  }
  else {
		this.oWindow.focus();
	}
}

VentanaFlotante.prototype.cerrar = function() {
	if(this.oWindow) {
		if(!this.oWindow.closed) {
			this.oWindow.bCerrarSeguro = true; // Fuerza el cierre de la ventana
			this.oWindow.close();
		}
	}
}

VentanaFlotante.all = new Array();
VentanaFlotante.ventanasNoModales = new Array();

VentanaFlotante.addVentanaNoModal = function(name) {
	VentanaFlotante.ventanasNoModales[name] = true;
}

VentanaFlotante.removeVentanaNoModal = function(name) {
	VentanaFlotante.ventanasNoModales[name] = false;
}

VentanaFlotante.cerrarVentanas = function() {
	for(var i=0; i<VentanaFlotante.all.length; i++) {
		if(!VentanaFlotante.ventanasNoModales[VentanaFlotante.all[i].winName]) {
			VentanaFlotante.all[i].cerrar();
		}
	}
}

VentanaFlotante.hayVentanasAbiertas = function() {
	for(var i=0; i<VentanaFlotante.all.length; i++) {
		var ventana = VentanaFlotante.all[i];
		if(ventana.oWindow) {
			if(!ventana.oWindow.closed) {
				return true;
			}
		}
	}
	return false;
}




