// Inicialización de widgets if (typeof edi2WidgetInicializar == 'undefined') { function edi2WidgetInicializar() { // Cotizaciones var widgets = document.getElementsByTagName("div"); var idWidget = 0; for (var i = 0; i < widgets.length; i++) { if (widgets[i].className == "edi2_widget_cotizacion") { var atributos = widgets[i].getAttribute("rel"); var widget = new edi2WidgetCotizacion(idWidget, atributos); eval("edi2WidgetCotizacion_" + idWidget + " = widget;"); idWidget++; } } } } // Añade funciones que se ejecutarán al cargar la página if (typeof addLoadListener == 'undefined') { function addLoadListener(fn) { if (typeof window.addEventListener != 'undefined') window.addEventListener('load', fn, false); else if (typeof document.addEventListener != 'undefined') document.addEventListener('load', fn, false); else if (typeof window.attachEvent != 'undefined') window.attachEvent('onload', fn); else { var oldfn = window.onload; if (typeof window.onload != 'function') window.onload = fn; else window.onload = function() { oldfn(); fn(); }; } } } // Crea la clase de objetos widget de cotización addLoadListener(edi2WidgetInicializar); if (typeof edi2WidgetCotizacion == 'undefined') { function edi2WidgetCotizacion(id, id_notation) { this.id = id; this.id_notation = id_notation; this.div = "edi2_widget_cotizacion_" + id; this.divContenido = "edi2_widget_cotizacion_contenido_" + id; this.datos = null; var divsWidget = new Array(); var divs = document.getElementsByTagName("div"); for (var i = 0; i < divs.length; i++) if (divs[i].className == "edi2_widget_cotizacion") divsWidget.push(divs[i]); divsWidget[id].id = this.div; var flag = false; for (var i = 0; i < divsWidget[id].childNodes.length; i++) { if (divsWidget[id].childNodes[i].className == "cabecera-edi2") flag = true; if (divsWidget[id].childNodes[i].className == "contenido-edi2") divsWidget[id].childNodes[i].id = this.divContenido; } this.obtenerDatos = edi2WidgetCotizacion_ObtenerDatos; this.pintarDatos = edi2WidgetCotizacion_PintarDatos; this.obtenerEstilos = edi2WidgetCotizacion_ObtenerEstilos; if (!flag) { alert("La estructura del widget no es correcta"); return; } this.obtenerEstilos(); this.obtenerDatos(); } function edi2WidgetCotizacion_ObtenerDatos() { sc = document.getElementById(this.div + "_js"); con = document.getElementById(this.div); if (sc) con.removeChild(sc); sc = document.createElement("script"); sc.id = this.div + "_js"; con.appendChild(sc); sc.src = "http://www.estrategias.mdgms.com/www/v2/widgetData.html?WIDGET=edi2WidgetCotizacion_" + this.id + "&ID_NOTATION=" + this.id_notation; setTimeout("edi2WidgetCotizacion_" + this.id + ".obtenerDatos()", 60000); } function edi2WidgetCotizacion_PintarDatos() { sc = document.getElementById(this.divContenido); var datos = this.datos.valores; var contenido = ""; contenido += "
"; for (var i = 0; i < datos.length; i++) { contenido += "
"; contenido += ""; contenido += ""; contenido += ""; contenido += ""; contenido += ""; contenido += ""; contenido += ""; contenido += ""; contenido += ""; contenido += ""; contenido += "
"; contenido += "" + datos[i].valor + ""; contenido += "
Precio:" + datos[i].cotizacion + "
Variación:" + datos[i].diferencia + "
Fecha:" + datos[i].fecha + "
Hora:" + datos[i].hora + "
"; contenido += "
"; if (datos[i].grafico == "on") { contenido += "
"; contenido += ""; contenido += "
"; } sc.innerHTML = contenido; } } function edi2WidgetCotizacion_ObtenerEstilos() { var cssElementCheck = document.getElementById(this.div + "_css"); if (cssElementCheck) cssElementCheck.parentNode.removeChild(cssElementCheck); var cssElement = document.createElement("link"); cssElement.id = this.div + "_css"; cssElement.rel = "stylesheet"; cssElement.type = "text/css"; document.getElementsByTagName("head")[0].appendChild(cssElement); cssElement.href = "http://www.estrategias.mdgms.com/css/v2/widget.css"; } }