      
      function initTab(tabName) {
        // execute the javascript inside the ajax page
        var pane = dijit.byId(tabName).domNode;

        dojo.query("script", pane).forEach(
          function(scriptTag) {
            // We can't use dojo.eval(scriptTag.innerHTML), it does not always work
            var appendNode = dojo.doc.body;
            var n = appendNode.ownerDocument.createElement('script');
            n.type = "text/javascript";
            appendNode.appendChild(n);
            n.text = scriptTag.innerHTML;
          }
        );
      }
      
      function myOnLoad() {
        var pane = dijit.byId("lev1_1");
        dojo.connect(pane, "onLoad", pane, function() {initTab("lev1_1");});
        pane = dijit.byId("lev1_2");
        dojo.connect(pane, "onLoad", pane, function() {initTab("lev1_2");});
        pane = dijit.byId("lev1_3");
        dojo.connect(pane, "onLoad", pane, function() {initTab("lev1_3");});
        pane = dijit.byId("lev1_4");
        dojo.connect(pane, "onLoad", pane, function() {initTab("lev1_4");});
        pane = dijit.byId("lev1_7");
        dojo.connect(pane, "onLoad", pane, function() {initTab("lev1_7");});
      
        // make a player and play the new movie
        qp = new swx.QuotePlayer(sip_movie, mop_updateHeaderCells);
        qp.play();

      }

      dojo.addOnLoad(myOnLoad);
      
      // Cell updater for the header line
      function mop_updateHeaderCells(updateEvent) {
        var updateCol = updateEvent.columnid;
        if (updateEvent.newValue.replace(/^\s+|\s+$/g, '').replace(/\u00A0/g, "")  == "") return; // movie problem, updates shoud not be empty
  
        var cell = dojo.byId("mop_"+updateCol);
        if (cell) {
          cell.innerHTML = updateEvent.newValue;
          if (updateCol == "ClosingDelta") {
            dojo.style(cell, "color", getColor(updateEvent.newValue));
          }
        }
      }
      
      // Cell updater for the overview page
      function sip_ov_updateCell(updateEvent) {
        var updateCol = updateEvent.columnid;
        if (updateEvent.newValue.replace(/^\s+|\s+$/g, '').replace(/\u00A0/g, "")  == "") return; // movie problem, updates shoud not be empty
  
        var cell = dojo.byId("SIP_OV_"+updateCol);
        if (cell) {
          if (updateCol == "DailyHighTime" ||
              updateCol == "DailyLowTime") {
            // remove seconds
            updateEvent.newValue = updateEvent.newValue.substring(0,5);
          }
          
          cell.innerHTML = updateEvent.newValue;
          if (updateCol == "ClosingPrice") {
            // Special case, update another cell
            var absChange = updateEvent.newValue - SIP_OV_SavedPreviousClosingPrice;
            absChange = absChange.toFixed(2); 
            dojo.byId("SIP_OV_ClosingPriceDiff").innerHTML = absChange;
            
            // 52 weeks change
            changeCellDeltaIfPossible("SIP_OV_HistoricPercentSpecial", window.SIP_OV_SavedHistoricPrice, updateEvent.newValue);
            
            // Prev year change
            changeCellDeltaIfPossible("SIP_OV_PrevYearPercentSpecial", window.SIP_OV_SavedPrevYearPrice, updateEvent.newValue);
            
            // 1/4 week difference for indices
            changeCellDeltaIfPossible("SIP_OV_OneWeekPercentSpecial", window.SIP_OV_SavedOneWeekPrice, updateEvent.newValue);
            changeCellDeltaIfPossible("SIP_OV_FourWeeksPercentSpecial", window.SIP_OV_SavedFourWeeksPrice, updateEvent.newValue);
          } else if (updateCol == "ClosingDelta") {
            dojo.style(dojo.byId("SIP_OV_ClosingPriceSpecial"), "color", getColor(updateEvent.newValue));
          }
        }
              
      }

      // Cell updater for the market data page
      function sip_md_updateCell(updateEvent) {
        var updateCol = updateEvent.columnid;
        if (updateEvent.newValue.replace(/^\s+|\s+$/g, '').replace(/\u00A0/g, "")  == "") return; // movie problem, updates shoud not be empty
  
        var cell = dojo.byId("SIP_MD_"+updateCol);
        if (cell) {
          if (updateCol == "DailyHighTime" ||
              updateCol == "DailyLowTime") {
            // remove seconds
            updateEvent.newValue = updateEvent.newValue.substring(0,5);
          }
          
          cell.innerHTML = updateEvent.newValue;
          
          // special cases
          if (updateCol == "BidPrice" || updateCol == "AskPrice") {
            // Bid or ask affect spread
            var ask = dojo.byId("SIP_MD_AskPrice").innerHTML;
            var bid = dojo.byId("SIP_MD_BidPrice").innerHTML;
            dojo.byId("SIP_MD_SpreadSpecial").innerHTML = (bid - ask).toFixed(2);
            
          } else if (updateCol == "ClosingPrice") {
            // Closing price affects daily change, 52 week change, YTD change ...
            var absChange = updateEvent.newValue - SIP_MD_SavedPreviousClosingPrice;
            absChange = absChange.toFixed(2); 
            dojo.byId("SIP_MD_ClosingPriceSpecial").innerHTML = absChange;
            
            // 52 weeks change
            changeCellDeltaIfPossible("SIP_MD_HistoricPercentSpecial", window.SIP_MD_SavedHistoricPrice, updateEvent.newValue);
            
            // Prev year change
            changeCellDeltaIfPossible("SIP_MD_PrevYearPercentSpecial", window.SIP_MD_SavedPrevYearPrice, updateEvent.newValue);
            
            // 1/4 week difference for indices
            changeCellDeltaIfPossible("SIP_MD_OneWeekPercentSpecial", window.SIP_MD_SavedOneWeekPrice, updateEvent.newValue);
            changeCellDeltaIfPossible("SIP_MD_FourWeeksPercentSpecial", window.SIP_MD_SavedFourWeeksPrice, updateEvent.newValue);
          } else if (updateCol == "ClosingDelta") {
            dojo.style(cell, "color", getColor(updateEvent.newValue));
          }
          
        }
      }
      
      // Cell updater for the chart page
      function sip_cp_updateCell(updateEvent) {
        var updateCol = updateEvent.columnid;
        if (updateEvent.newValue.replace(/^\s+|\s+$/g, '').replace(/\u00A0/g, "")  == "") return; // movie problem, updates shoud not be empty
        //alert(selectedTimeRange);
        var cell = dojo.byId("SIP_CP_"+updateCol);
        var data_change_value = dojo.byId("data_change_value");
        var updateSelectedPeriodColumn = false;
        if (cell) {          
          var oldValue = cell.innerHTML;     
          cell.innerHTML = updateEvent.newValue;
          if (updateCol == "MonthAgoDelta" ||
              updateCol == "MonthSixAgoDelta" ||
              updateCol == "YearAgoDelta" ||
              updateCol == "YearThreeAgoDelta") {
            dojo.style(dojo.byId("SIP_CP_"+updateCol+"Special"), "color", getColor(updateEvent.newValue));
          }
          
          if ( updateSelectedPeriodPriceEnabled ) {
          
            if ( updateCol == "MonthAgoDelta" && selectedTimeRange == "1m" ) {
                data_change_value.innerHTML = updateEvent.newValue;
                updateSelectedPeriodColumn = true;
            }
          
            if ( updateCol == "MonthSixAgoDelta" && selectedTimeRange == "6m" ) {
                data_change_value.innerHTML = updateEvent.newValue;
                updateSelectedPeriodColumn = true;
            }
          
            if ( updateCol == "YearAgoDelta" && selectedTimeRange == "1y" ) {
                data_change_value.innerHTML = updateEvent.newValue;
                updateSelectedPeriodColumn = true;
            }
          
            if ( updateCol == "YearThreeAgoDelta" && selectedTimeRange == "3y" ) {
                data_change_value.innerHTML = updateEvent.newValue;
                updateSelectedPeriodColumn = true;
            }
            
          }
          
          // highlight cell in green or red color according to new value
          if(oldValue!=updateEvent.newValue){
            changeCellColor(dojo.byId("SIP_CP_"+updateCol+"Special"), updateEvent.newValue.replace('%','')-oldValue.replace('%',''));
            if ( updateSelectedPeriodColumn ) {
              changeCellColor(dojo.byId("data_change_cell"), updateEvent.newValue.replace('%','')-oldValue.replace('%',''));
            } 
          }
        }              
      }
      
      // This function calculates the delta from prevPrice to currPrice and
      // returns the result with the corresponding red/black/green color 
      function getDeltaAndColor(prevPrice, currPrice) {
        var deltaChange = 100 * (currPrice - prevPrice) / prevPrice;
        deltaChange = deltaChange.toFixed(2);
        var color = "black";
        if (deltaChange > 0) {
          color = "green";
        } else if (deltaChange < 0) {
          color = "red";
        }
        
        return [deltaChange, color];
      }
      
      function getColor(value) {
        var delta = value;
        delta = delta.replace("%", "");
        var color = "black";
        if (delta > 0) {
          color = "green";
        } else if (delta < 0) {
          color = "red";
        }
        return color;
      }
      
      // This function changed the color of the cellId and displays the 
      // calculated delta from prevPrice to currPrice
      function changeCellDeltaIfPossible(cellId, prevPrice, currPrice) {
        var cell = dojo.byId(cellId);
        if (cell && prevPrice > 0) {
          deltaAndColor = getDeltaAndColor(prevPrice, currPrice);
          dojo.style(cell, "color", deltaAndColor[1]);
          cell.innerHTML = deltaAndColor[0]+"%";
        }
      }
