//----------------------------  public functions ----------------------------
  //-- get symbol main page
  function getQuoteHref(aSymbol)
  {
     return "/quotes/"+aSymbol+"/default.aspx";
  }

  //-- format the input numeric_str to '##,###,###.##' 
  function formatNumeric(sNumeric) 
  { 
    //-- check the input numeric, $1 is whole number, $2 is decimal fraction
    var re = /(^-?(?:(?:\d{0,3}(?:,\d{3})*)|\d*))(\.\d+)?$/;  
    tempstr = sNumeric.replace(/,/g, " ");
    var tempint = 0; 
    var tempstr = ""; 
    if (re.test(sNumeric)) 
    { 
      //-- if input_str like -0.0938
      tempint = parseInt(RegExp.$1);
      if (tempint == 0 && sNumeric.substring(0,1) == "-" )
      {
	    tempint = "-0";
      }
      if (!isNaN(tempint))
      { 
        //-- dell the dot
        var tempint1 = 0; 
        var tempint2 = 0; 
        //-- decimal fraction
        if (RegExp.$2.length > 3) 
        { 
          tempint1 = parseInt(RegExp.$2.charAt(3)); 
          tempint2 = RegExp.$2.substr(1,2); 
          if(tempint1> 4) tempint2++; 
        } else if (RegExp.$2.length == 3)
        {
          tempint2 = RegExp.$2.substr(1,2); 
        } else if (RegExp.$2.length == 2)
        {
		  tempint2 = RegExp.$2.substring(1,2) + "0";
        } else if (RegExp.$2.length == 0) 
		{
		  tempint2 = "00";
		}

        //recircle and add "," per three num
        while(tempint> 1000)   
        { 
          tempstr = "," + (tempint % 1000) + tempstr; 
          tempint = Math.floor(tempint/1000); 
        } 
		//-- add dot
        tempstr = "" + tempint + tempstr + "." + tempint2;
        return tempstr;
      } else 
      { 
	    //-- input_numeric not right 
        return null; 
      } 
    } else 
    { 
	  //-- input_numeric not right 
      return null; 
    } 
  } 
  //-- dell the quotemedia jsdata
  //-- input like <span class="qmjsdatadown">-45.44</span>,<span class="qmjsdata">10.81 k</span>
    function getQuoteMediaFormatStr(sNumeric)
    {
        var tmpFront = "";
        var tmpMiddle = "";
        var tmpEnd = "";
        tmpFront = sNumeric.substring(0 , sNumeric.indexOf(">") + 1);
        tmpMiddle = sNumeric.substring(sNumeric.indexOf(">") + 1 , sNumeric.length);
        var sNumberStr = "-0123456789.";
        var midIndex=0;
        for (var i = 0;i < tmpMiddle.length ; i++)
        {
           if (sNumberStr.indexOf(tmpMiddle.substring(i,i+1)) < 0)
           {
             midIndex=i;
	         break;
           }
        }

        tmpEnd = tmpMiddle.substring(midIndex,tmpMiddle.length);
        tmpMiddle = tmpMiddle.substring(0,midIndex);
        tmpMiddle = formatNumeric(tmpMiddle);
        return tmpFront+tmpMiddle+tmpEnd;
    }

    function writeCookie(name,value,hours) 
    { 
        var expire=" "; 
        if (hours   !=   null)   
        { 
            expire = new Date((new Date()).getTime() + hours * 3600000); 
            expire = ";   expires= "+expire.toGMTString(); 
        } 
        document.cookie = name + "= " + escape(value) + expire; 
    } 
    
    function readCookie(name)   
    { 
      var cookieValue = " "; 
      var search = name + "="; 
      if (document.cookie.length > 0)
      { 
        offset   =   document.cookie.indexOf(search); 

        if (offset != -1)
        { 
          offset += search.length; 
          end   =   document.cookie.indexOf( "; ",   offset); 
          if   (end   ==   -1)   
          { 
            end   =   document.cookie.length; 
          } 
          cookieValue   =   unescape(document.cookie.substring(offset,   end)) 
        } 
      } 
      return cookieValue; 
    } 
    //-- create the no date string
    function replaceNoDataByStr(aOwnerId,aModelName,aCompanyName,aSymbol,aFindNoDataStr)
    {
       var tmpOut="";
       tmpOut  = " <br/><br/>";
       tmpOut += " <table width=550 align=center cellpadding=10 cellspacing=10><tr><td>";
       tmpOut += " <div class='qmShowNoData'>";
       tmpOut += " Sorry, but " + aModelName + " are not available for " + aCompanyName + "(" + aSymbol + ").";
       tmpOut += " They're available for plenty of other symbols though - if you're looking for ideas, check out <a href=\"/zeccoshare/default.aspx\">ZeccoShare</a>!";
       tmpOut += " <br/><br/><br/>";
       tmpOut += " </div>";
       tmpOut += " </td></tr></table>";
       
       try
       {
          var theDivList = document.getElementById(aOwnerId).getElementsByTagName("div");
          for (var i=0; i < theDivList.length; i++)
          {
             if (theDivList[i].className = "qm_maintext")
             {
//                if (theDivList[i].innerHTML.indexOf("No Data Available") >= 0 || theDivList[i].innerHTML.indexOf("Symbol is not valid") >= 0)
                if (theDivList[i].innerHTML.indexOf(aFindNoDataStr) >= 0)
                {
                   theDivList[i].style.align = "center";
                   theDivList[i].innerHTML = tmpOut;
                }
             }          
          }
       }catch(e){}
    }
    
//----------------------------  called by StockScreener start ----------------------------
  function adjustShowResultHeight()
  {
     try
     {
         var theObj=document.getElementById("qmsm-tbl-container");
         theObj.style.height=theObj.scrollHeight+20;
     } catch(e)
     {
     }
  }
  //-- hide the table class=="qmsm_header"
  //-- eg. "Stock Screener  	Mar 17 2:33 AM EDT "
  function hideQmHeaderTable()
  {
     var collections=document.getElementsByTagName("table");
     for (var i = 0;i < collections.length;i ++ )
     {
        if (collections[i].className == "qmsm_header")
        {
	       collections[i].style.display="none";
        }     
     }
  }
  //adjustIframeHeightAndWidth
  //-- get the funcs(qmsm_addRow,qmsm_delRow,qm_openChangeTab,qm_ToggleFilter) str and add "adjustIframeHeightAndWidth()" at the end of funs
  function getStockScreenerFuncString(funcName)
  {    
     var tmpOut = "";
	 var tmpFuncStr = "";
	 var functionName, firstIndex, endIndex;
	 try
	 {
         eval ("tmpFuncStr=" + funcName + ".toString();")
	     firstIndex = tmpFuncStr.indexOf("{");
	     endIndex = tmpFuncStr.lastIndexOf("}");
	     functionName = tmpFuncStr.substring(0,firstIndex);
	     tmpOut =  functionName;
	     tmpOut += " {";
	     tmpOut += tmpFuncStr.substring(firstIndex+1,endIndex);
	     tmpOut += " adjustIframeHeightAndWidth();";
	     tmpOut += " }";
	 } catch(e)
	 {
	 }
	 return tmpOut;
  }

  function overrideStockScreenerFuncs()
  {
     document.write("<script language=javascript>");
     document.write(getStockScreenerFuncString("qmsm_addRow"));  
     document.write(getStockScreenerFuncString("qmsm_delRow"));  
     document.write(getStockScreenerFuncString("qm_openChangeTab"));  
     document.write(getStockScreenerFuncString("qm_ToggleFilter"));  
     document.write("<\/script>");
  }
//----------------------------  called by StockScreener start ----------------------------

//----------------------------  called by Mutual Fund start ----------------------------
  function getFundControlsInn(theObj)
  {
      var theTdList=theObj.getElementsByTagName("td");      
  
      var tmpOut="";
      var showRates="";
      var showEarns="";
      var showCorpo="";
      
      if (theTdList[0].style.cursor =="default") showRates="Selected";
      
      if (theTdList[1].style.cursor =="default") showEarns="Selected";

      if (theTdList[2].style.cursor =="default") showCorpo="Selected";

      tmpOut =" <table cellpadding=\"0\" cellspacing=\"0\" class=\"tabGradient\" width=\"100%\">";
      tmpOut+="   <tr valign=\"middle\">";
//      tmpOut+="     <td><img src=\"/themes/default/images/tabs/tabLeftGradient.gif\"></td>";
      
      tmpOut+="     <td><img src=\"/themes/default/images/tabs/tabLeft"+showRates+".gif\" style=\"border-width:0px;\" /></td>";
      tmpOut+="     <td class=\"tabMiddle"+showRates+"\"><a href=\"#\" onclick=\""+getFundClickStr(theTdList[0])+"\" >"+theTdList[0].innerHTML+"</a></td>" ;
      tmpOut+="     <td><img src=\"/themes/default/images/tabs/tabRight"+showRates+".gif\" style=\"border-width:0px;\" /></td>";
      
      tmpOut+="     <td><img src=\"/themes/default/images/tabs/tabLeft"+showEarns+".gif\" style=\"border-width:0px;\" /></td>";
      tmpOut+="     <td class=\"tabMiddle"+showEarns+"\"><a href=\"#\" onclick=\""+getFundClickStr(theTdList[1])+"\" >"+theTdList[1].innerHTML+"</a></td>" ;
      tmpOut+="     <td><img src=\"/themes/default/images/tabs/tabRight"+showEarns+".gif\" style=\"border-width:0px;\" /></td>";
      
      tmpOut+="     <td><img src=\"/themes/default/images/tabs/tabLeft"+showCorpo+".gif\" style=\"border-width:0px;\" /></td>";
      tmpOut+="     <td class=\"tabMiddle"+showCorpo+"\"><a href=\"#\" onclick=\""+getFundClickStr(theTdList[2])+"\" >"+theTdList[2].innerHTML+"</a></td>" ;
      tmpOut+="     <td><img src=\"/themes/default/images/tabs/tabRight"+showCorpo+".gif\" style=\"border-width:0px;\" /></td>";
      
      tmpOut+="     <td><img src=\"/themes/default/images/tabs/tabRightEnd.gif\"></td>";
      tmpOut+="     <td width=\"100%\">&nbsp;</td>";
      tmpOut+="   </tr>";
      tmpOut+=" </table>";
      return tmpOut;      
  }
  
  function getFundClickStr(theTdObj){
    var tmpOut=-"";
    var tmpIndex1=0;
    var tmpIndex2=0;
    tmpIndex1=theTdObj.onclick.toString().indexOf("{");
    tmpIndex2=theTdObj.onclick.toString().lastIndexOf("}");    
    tmpOut=theTdObj.onclick.toString().substring(tmpIndex1+1,tmpIndex2);
    tmpOut=tmpOut.replace(/\"/,"'");
    tmpOut=tmpOut.replace(/\"/,"'");
    return tmpOut;
  }

  function initFundControls()
  {  
      /*---- 
        get the replace_area object e.g
	      <td style="padding-bottom: 0px;">      
	        <!-- top bar of buttons -->            
	        <table cellpadding="0" cellspacing="0" border="0" width="100%">
		      <tr>                  
		        <td width="33%" onclick="qmmf_forward_4468(0, 'showMarketOverview');" class="qm_activebutton" style="cursor: default; border-right: 0px;">Market Overview</td> 
			    <td width="33%" onclick="qmmf_forward_4468(1, 'showSnapShotOverview');" class="qm_inactivebutton" style="border-right: 0px;" 
			      onmouseover="this.className = 'qm_activebutton'" onmouseout="this.className = 'qm_inactivebutton'">Detailed Quote</td>                                       
			    <td width="33%" onclick="qmmf_forward_4468(2, 'showScreener');" class="qm_inactivebutton" onmouseover="this.className = 'qm_activebutton'" 
			      onmouseout="this.className = 'qm_inactivebutton'">Screener</td>
		      </tr>        
		    </table>      
		    <!-- end top bar of button -->    
	      </td>  
      ----*/
      var theObj=(document.getElementsByTagName("table"))[1].rows[0].cells[0];
      theObj.innerHTML=getFundControlsInn(theObj)
  } 
//----------------------------  called by Mutual Fund end ----------------------------

//----------------------------  called by Financials start ----------------------------
  function fixFinancialsStyleInIE()
  {
      if (Sys.Browser.agent == Sys.Browser.InternetExplorer)
      {
          try
          {
              $('qmFinancials').childElements()[2].childElements()[0].rows[0].cells[0].lastChild.rows[2].cells[0].firstChild.width = "99%";
          }
          catch(e)
          {
              window.status="QM DOM changed";
          }
      }
  }
//----------------------------  called by Financials end ----------------------------

//----------------------------  called by Calendar start ----------------------------
    function getCalendarControlsInn(a_selectType,searchTypeArray)
    {
      var tmpOut="";
      var showRates="";;
      var showEarns="";
      var showCorpo="";
      
      if (a_selectType=="showUpgrades") showRates="Selected";
      
      if (a_selectType=="showPositiveEarnings") showEarns="Selected";

      if (a_selectType=="showStockSplits") showCorpo="Selected";
      
      tmpOut =" <table cellpadding=\"0\" cellspacing=\"0\" class=\"tabGradient\" width=\"100%\">";
      tmpOut+="   <tr valign=\"middle\">";
      //tmpOut+="     <td><img src=\"/themes/default/images/tabs/tabLeftGradient.gif\"></td>";
      tmpOut+="     <td></td>";
      tmpOut+="     <td><img src=\"/themes/default/images/tabs/tabLeft"+showRates+".gif\" style=\"border-width:0px;\" /></td>";
      tmpOut+="     <td class=\"tabMiddle"+showRates+"\"><a href=\"#\" onclick=\"qm_calendarSubmitcalendarNavForm('showUpgrades')\">"+searchTypeArray[0]+"</a></td>" ;
      tmpOut+="     <td><img src=\"/themes/default/images/tabs/tabRight"+showRates+".gif\" style=\"border-width:0px;\" /></td>";
      
      tmpOut+="     <td><img src=\"/themes/default/images/tabs/tabLeft"+showEarns+".gif\" style=\"border-width:0px;\" /></td>";
      tmpOut+="     <td class=\"tabMiddle"+showEarns+"\"><a href=\"#\" onclick=\"qm_calendarSubmitcalendarNavForm('showPositiveEarnings')\" >"+searchTypeArray[1]+"</a></td>" ;
      tmpOut+="     <td><img src=\"/themes/default/images/tabs/tabRight"+showEarns+".gif\" style=\"border-width:0px;\" /></td>";
      
      tmpOut+="     <td><img src=\"/themes/default/images/tabs/tabLeft"+showCorpo+".gif\" style=\"border-width:0px;\" /></td>";
      tmpOut+="     <td class=\"tabMiddle"+showCorpo+"\"><a href=\"#\" onclick=\"qm_calendarSubmitcalendarNavForm('showStockSplits')\" >"+searchTypeArray[2]+"</a></td>" ;
      tmpOut+="     <td><img src=\"/themes/default/images/tabs/tabRight"+showCorpo+".gif\" style=\"border-width:0px;\" /></td>";
      
      tmpOut+="     <td><img src=\"/themes/default/images/tabs/tabRightEnd.gif\"></td>";
      tmpOut+="     <td width=\"100%\">&nbsp;</td>";
      tmpOut+="   </tr>";
      tmpOut+=" </table>";
      return tmpOut;      
    }

    function getDropdownActionInn()
    {
        var tmpOut = "";
        tmpOut  = "<select name=\"selectAction\" onchange=\"selectActionChange()\" id=\"dropdownAction_new\" length=\"12\" >"
        tmpOut += document.getElementById("dropdownAction").innerHTML;
        tmpOut += "</select>";
        return tmpOut;
/*
      var tmpOut="";
      var tmpArray=a_array;
      
      var tmpValue="";
      var tmpText="";
      
      tmpOut ="<select name=\"selectAction_new\" onchange=\"selectActionChange()\" id=\"dropdownAction_new\" length=\"12\" >";
      for (var i=0;i<tmpArray.length;i++)      
      {
        tmpValue=tmpArray[i].substring(tmpArray[i].indexOf("#")+1,tmpArray[i].length);
        tmpText=tmpArray[i].substring(0,tmpArray[i].indexOf("#"));
        if (a_selectValue==tmpValue)
        {
           tmpOut+=" <option value=\""+tmpValue+"\" selected >"+tmpText+"</option>";
           a_selectText=tmpText;
        } else 
        {
           tmpOut+=" <option value=\""+tmpValue+"\" >"+tmpText+"</option>";
        }
      }
      tmpOut+="</select>";
      if (a_selectText=="") a_selectText=tmpArray[0].substring(0,tmpArray[0].indexOf("#"));

      return tmpOut;
*/      
    }

    function getCalendarSelectName(a_selectType)
    {
      var tmpOut;
      if (a_selectType == "showUpgrades")
      {
        tmpOut=searchTypeArray[0]+" :";
      } else if (a_selectType == "showPositiveEarnings")
      {
        tmpOut=searchTypeArray[1]+" :";
      } else {
        tmpOut=searchTypeArray[2]+" :";
      }
      return tmpOut;
    }
    
    function selectActionChange()
    {
      document.getElementById('dropdownAction').value=document.getElementById('dropdownAction_new').value;      
    }
    
    function showAllCompanes()
    {
      document.getElementById("idSymbol").value="";
      qm_calendarSubmitcalendarNavForm(""); 
    }
    
    function displayNoneObjByStr(aStr)
    {
      var collections=document.getElementsByTagName("span");
	  var tmpstr=(aStr+" Page").replace(/ /g,"&nbsp;");
	  for (var i=0;i<collections.length;i++)
	  {
        if (collections[i].innerHTML.indexOf(tmpstr)>=0)
        {
	      collections[i].style.display="none";
        }
	  }
    }

    //-- replace UPGRADES (ALL COMPANIES) as UPGRADES
    //-- old html is "<td style="display: inline;" class="qmmt_header_text">Upgrades<span style="font-weight: normal;">&nbsp;(All Companies)</span></td>"
    //--             "<td style="display: inline;" class="qmmt_header_text">Upgrades&nbsp;for AAPL</td>"
    function displayTableTitle()
    {
        var theList =  document.getElementsByTagName("div");     
        for (var i=0; i < theList.length; i++)
        {
            if (theList[i].className == "qmmt_header_bar")
            {
                if (theList[i].getElementsByTagName("td").length == 1)
                {
                    if (theList[i].getElementsByTagName("td")[0].innerHTML.indexOf("<") >= 0 )
                    {
                        theList[i].getElementsByTagName("td")[0].innerHTML = theList[i].getElementsByTagName("td")[0].innerHTML.substring(0,theList[i].getElementsByTagName("td")[0].innerHTML.indexOf("<"))+"  all Companies";
                    }

                    theList[i].innerHTML = theList[i].innerHTML.replace("&nbsp;"," ");
                    theList[i].getElementsByTagName("td")[0].innerHTML = theList[i].getElementsByTagName("td")[0].innerHTML.toUpperCase();
                    theList[i].style.display = "inline";
                    theList[i].getElementsByTagName("td")[0].style.display = "inline";
                    return;
                }
            }
        }
    }

    function hiddenBlankShow()
    {
        var theList = document.getElementsByTagName("table");
        var j=0;
        for (var i = 0; i < theList.length ;i++)
        {
            if (theList[i].className == "qmmt_main")
            {
                j ++;
                if (j == 2)
                { 
                    theList[i].style.display = "none";
                }
            }
        }
    }
    
    function initCalendarControls(a_selectType,a_array,a_selectValue,a_selectText,a_selectSymbol,a_selectTypeValue)
    {
      document.getElementById('showControls').innerHTML=getCalendarControlsInn(a_selectType,searchTypeArray);
      document.getElementById('showDropdownAction').innerHTML=getDropdownActionInn();
      document.getElementById('showSelectName').innerHTML=getCalendarSelectName(a_selectType);  
      displayNoneObjByStr(a_selectTypeValue);
      displayTableTitle();
      hiddenBlankShow();
	  document.getElementById("qmCalendar").style.display = "inline";
    }        
//----------------------------  called by Calendar end ----------------------------

//----------------------------  called by indices start ----------------------------

    var base0, base1, base2; //src for the 3 images without the symbol and chscale parameters
    var symbol0, symbol1, symbol2; //basic symbol
    var compare0, compare1, compare2; //3 arrays to hold the comparing symbols
    var scale0, scale1, scale2; //basic chscale
    var colors = new Array('8080C0','A52A2A','008000','FFFF00','FFA500','800080','4682B4','EE82EE','808080','7FFF00');
    
    // related with updateChart and fixTable index(1,2,4,6)
    function fixQM()
    {
        var tables = $$('table.qmmt_main');
        
        var i;
		//-- change by chao.chen 20080519
        for(i = 1; i < tables.length; i++) //skip 0,1,4,6,total=8 
        {
		  if (i==1 || i==2 || i==4 || i==6)
		  {
		     //-- focus the table
             var theRealTable = tables[i].childElements()[0].rows[1].cells[0].getElementsByTagName('table')[0];
             //-- focus US tab
             if (i==1 || i==2 )
             {
                fixTable(theRealTable, i,1);
             } else 
             {
                fixTable(theRealTable, i,0);
             }
		  }		  
        }
        initImgSrc();
    }

    //add checkboxes to all the tables
    function fixTable(table, index,type)
    {
        //somehow the prototype is not attached here in IE
        //var rows = table.childElements()[0].rows;
        //rows[0].insert({'top' : '<td>&nbsp;</td>'});//add the column header
        
        var rows = Element.childElements(table)[0].rows;
        Element.insert(rows[0], {'top' : '<td>&nbsp;</td>'});
        
        //-- if US tab fix the TD's width
        if (type == 1)
        {
            rows[0].cells[0].width=12;
            rows[0].cells[1].width=240;
            rows[0].cells[2].width=73;
            rows[0].cells[3].width=73;
            rows[0].cells[4].width=73;
            rows[0].cells[5].width=73;
        }
                
        var i;
        for(i = 1; i<rows.length; i++)
        {
            tr = rows[i];
            var symbol = findSymbol(tr.cells[0]);
            var checkbox = '<td><input type="checkbox" onclick="updateChart(this,\'' 
                + symbol + '\', ' + index + ')" '
            //-- always check the first one
            if (index != 2 && i == 1)   //exclude the US treasury
                checkbox += ' checked="checked" ';    
            checkbox += '></td'; 
            Element.insert(tr, {'top' :  checkbox});
            
            //-- change the url,add by chao.chen
            modifyIndicesHref(tr.cells[1]);
        }
    }            
    
    //-- call by minichart
    function callBackUpdateChart(objectId,chscale)
    {
        var img = getCharts();
        var imgIndex;
        var src="";
        //-- find the img object by input objectId
        for (var i = 0; i < img.length; i++)
        {
           if (img[i].id == objectId)
           {
              imgIndex = i;
           }
        }
        //-- change scale imgIndex  
        eval('scale' + imgIndex + ' = chscale');
        src = eval('base' + imgIndex) + '&chscale=' + eval('scale' + imgIndex) + '&symbol=' + eval('symbol' + imgIndex);
        if (eval('compare' + imgIndex + '.length') != 0)
        {
           src+= '&compare=' + eval('compare' + imgIndex).join('&compare=') + getColorString(eval('compare' + imgIndex).length) + '&chtype=compare';
        }  
        img[imgIndex].src = src;
    }
    
    //relate with fixQM seee index(1,2,4,6)
    function updateChart(checkbox, symbol, index)
    {
        var imgIndex;   //table 3,4 map to image 0, table 6 to image 1, table 8 to image 2
        if (index == 1 || index == 2) 
        {
           imgIndex = 0;
        } else if (index == 4)
        {
           imgIndex = 1;
        } else if (index == 6)
        {
           imgIndex = 2 ;
        } else  //-- not the object table
        {
           return ;
        }
        
        var img =  getCharts();

        if (checkbox.checked)
        {
            //check is easy, just add a new comparison to the array and refresh
            eval('compare' + imgIndex).push(symbol); 
            var src = eval('base' + imgIndex) 
                        + '&chscale=' + eval('scale' + imgIndex)
                        + '&symbol=' + eval('symbol' + imgIndex)
                        + '&compare=' + eval('compare' + imgIndex).join('&compare=')
                        + getColorString(eval('compare' + imgIndex).length)
                        + '&chtype=compare';
        }
        else
        {
            //a little tricky if uncheck
            if (eval('compare' + imgIndex).length == 0)//uncheck the last one
            {                
                checkbox.checked = true;
                return;
            }
            else if(eval('compare' + imgIndex).length == 1) //there are only two left
            {
                if (eval('symbol' + imgIndex) == symbol) //uncheck the base symbol
                {
                    eval('symbol' + imgIndex + ' = \'' + eval('compare' + imgIndex)[0] + '\'');
                    eval('compare' + imgIndex + ' = new Array();');
                }
                else
                {
                    eval('compare' + imgIndex + ' = new Array();');
                }
                src = eval('base' + imgIndex) + '&chscale=' + eval('scale' + imgIndex) + '&symbol=' + eval('symbol' + imgIndex);//no comparer
            }
            else
            {
                if (eval('symbol' + imgIndex) == symbol) //uncheck the base symbol
                {
                    //make the first comparer as the base symbol, and shift the comparer array
                    eval('symbol' + imgIndex + ' = \'' + eval('compare' + imgIndex)[0] + '\'');
                    eval('compare' + imgIndex + '.shift()');
                }
                else
                {
                    //remove from the comparer
                    var i = eval('compare' + imgIndex).indexOf(symbol);
                    eval('compare' + imgIndex + '.splice(' + i + ',1)');
                }            
                src = eval('base' + imgIndex) 
                        + '&chscale=' + eval('scale' + imgIndex)
                        + '&symbol=' + eval('symbol' + imgIndex)
                        + '&compare=' + eval('compare' + imgIndex).join('&compare=')
                        + getColorString(eval('compare' + imgIndex).length)
                        + '&chtype=compare';
            }
        }
        img[imgIndex].src = src;
    }

    function getColorString(number)
    {
        var arr = colors;
        if (number <= colors.length)
        {
            arr = colors.slice(0,number);
        }
        
        return '&chcmp=' + arr.join('&chcmp=');
    }


    //find the symbol of the link, the link is like this:
    //<a href="javascript:openDetail_0328('^IRX')" style="text-decoration: none;" class="qmmt">13 Week Treasury Bill Index</a>
    function findSymbol(td)
    {
        href = td.getElementsByTagName('a')[0].href;
        return href.split('\'')[1];
    }

    //-- get the img_objects list
    function getCharts()
    {
      var charts=new Array();
      charts[0]=document.getElementById("qm_img_MiniCharts1");
      charts[1]=document.getElementById("qm_img_MiniCharts2");
      charts[2]=document.getElementById("qm_img_MiniCharts3");
      return charts
    }

    //-- init the params about img 
    function initImgSrc()
    {
        //this also assumes that there is only one symbol parameter and it's NOT the last one
        var charts= getCharts();

        var i;
        
        for(i=0; i<charts.length; i++)
        {
            var src = eval('charts[' + i + ']').src;
            var arr = src.split('&symbol=');
            var index = arr[1].indexOf('&');
            //-- init symbol0,1,2
            eval('symbol' + i + ' = arr[1].substring(0,' + index + ');');
            eval('base' + i + ' = arr[0] + arr[1].substring(' + index + ');');

            arr=eval('base' + i ).split("&chscale");
            index=arr[1].indexOf('&');
            //-- init scale0,1,2
            eval('scale' + i + ' = arr[1].substring(1,' + index + ');');
            //-- init base0,1,2
            eval('base' + i + ' = arr[0] + arr[1].substring(' + index + ');');

            eval('compare' + i + ' = new Array();');            
        }
    }
    
    //-- add by chao.chen
	function modifyIndicesHref(aObj)
	{
        tmpSymbol = findSymbol(aObj); 
        tmpSymbol = tmpSymbol.replace(":","-");
		var collections=aObj.getElementsByTagName("a");
        collections[0].href=tmpQuoteUrl.replace("{0}",escape(tmpSymbol));
    }
//----------------------------  called by indices end ----------------------------



//called by MarketMover.ascx start

function showAll()
	{
		document.getElementById(div_AllMarketMovers).style.display = "";
	}

	function hidenAll()
	{
		document.getElementById(div_AllMarketMovers).style.display = "none";
		document.getElementById(div_MarketMoversNYE).style.display = "none";
		document.getElementById(div_MarketMoversNSD).style.display = "none";
		document.getElementById(div_MarketMoversAMX).style.display = "none";
	}

	function showNYE(result)
	{
		document.getElementById(div_MarketMoversNYE).style.display = "";
		document.getElementById(div_MarketMoversNYE).innerHTML = "<div id='qmMarketMovers'>" +  result + "</div>";
		updatedIdString += div_MarketMoversNYE + ",";
	}

	function showNSD(result)
	{
		document.getElementById(div_MarketMoversNSD).style.display = "";
		document.getElementById(div_MarketMoversNSD).innerHTML =  "<div id='qmMarketMovers'>" +  result + "</div>";
		updatedIdString += div_MarketMoversNSD + ",";
	}

	function showAMX(result)
	{
		document.getElementById(div_MarketMoversAMX).style.display = "";
		document.getElementById(div_MarketMoversAMX).innerHTML =  "<div id='qmMarketMovers'>" +  result + "</div>";
		updatedIdString += div_MarketMoversAMX + ",";
	}
	
	function isUpdated(divId)
	{
		if(updatedIdString.indexOf(divId) > -1)
		{
			return true;
		}
		
		return false;
	}
	
	//called by MarketMover.ascx end
	
	
	//send feedback email
	function sendFeedback()
	{
		var title = $('txtFeedbackTitle').value;
		var body = $('txtFeedbackBody').value;
	
		CommunityServerWeb.QuoteMedia.Widgets.WidgetService.SendFeedback(title, body);
		closeTabPopup('popupSendFeedback'); 
		alert('Thank you for your feedback!');
		return false;
	
	}

//----------------------------  called by ChartRelated start ----------------------------
  function addHrefToRelatedChart(aObjId)
  {
     var theObj=document.getElementById(aObjId);
     var theList=theObj.getElementsByTagName("div");
	 var theChildList = null;
	 var theDiv = null;
	 var theTDList=null;
     for (var i=0;i<theList.length;i++)
     {
        if (theList[i].id == "qmQuoteChartRelated")
        {
	       theChildList = theList[i].getElementsByTagName("div");
	       if (theChildList[0].className == "qmmt_header_bar") 
	       {
	         theTDList = theChildList[0].getElementsByTagName("td");
	         theTDList[0].innerHTML = "<a href='"+getQuoteHref(theList[i].getAttributeNode("symbol").value)+"'>"+theTDList[0].innerHTML+"</a>";
	       }
	       
           theList[i].style.display = "inline";
        }
        
     }
  }
//----------------------------  called by ChartRelated end ----------------------------

//----------------------------  called by MiniChart start ----------------------------
function changeChartScale(obj, scale,src,uid,callback)
{
    for (i=0; i < 7; i++)
	    {
		document.getElementById('qm_ch_tab' + i + '_'+uid).className = (i == obj) ? 'qmmt_tabactive' : 'qmmt_tab';
		document.getElementById('qm_ch_tab' + i + '_'+uid).style.cursor = (i == obj) ? 'default' : (qm_isIE()) ? 'hand': 'pointer';
		document.getElementById('qm_ch_tab' + i + '_'+uid).style.borderTopWidth = (i == obj) ? '0px' : '1px';
	    }		
   if(callback !="")
   {
         eval(callback + "('qm_img_"+uid+"','"+scale+"')");
   }else
   {  
	    document.getElementById('qm_img_'+uid).src = src + scale ;  
	}
}

function qm_isIE()
{
	var ua = navigator.userAgent.toLowerCase();
	var isIE = ( (ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1) );
	return (isIE);  
}
//----------------------------  called by MiniChart end ----------------------------    
