
var proxy = "";  /// proxy = ""--local proxy = "Y" on server
var flash_width = 565, chart_width = 500, chart_height = 230, options="";
var maxValue= -9999999, minValue= 9999999;//,  nG = 0;
var strDates = "", fromTab = "", tab="Y1", sDateFrom = "", sDateTo="";
var bInit    = 0, nStart = 0, nEnd = 0;
var volUnit = ""; 
var Dat = new Date();
var curMonth = Dat.getMonth()+1;
var curDate  = Dat.getDate() - 1;
var curYear  = Dat.getFullYear();
var curDay   = curMonth +"/"+curDate +"/"+ curYear;
var sIntraDayTime = "", nDailyYears = 1;
var nMonths= 12, nYears = 1;
var bFirst   = true;  /// NO CUSTOM
var bShowFairValue = true;

var images   = new Array()

var selDates  = new Array();
var selDataH  = new Array();
var selDataL  = new Array();
var selDataC  = new Array();
var selDataV  = new Array();
var selDataFV = new Array();
var aIntraToday    = new Array();
//detects the capabilities of the browser
var aMFairValue = new Array();
var aFairValue  = new Array();
var aDPrice     = new Array(), aDVolume    = new Array(), aDPriceH    = new Array(), aDPriceL = new Array(), aDPriceC = new Array();
var aDLPriceH   = new Array(), aDLPriceL   = new Array(), aDLPriceC   = new Array();
var aPriceC     = new Array(), aPriceH     = new Array(), aPriceL     = new Array(), aVolume  = new Array();
var aMPriceC    = new Array(), aMPriceH    = new Array(), aMPriceL    = new Array(), aMVolume = new Array();
var aIntraDay   = new Array(), aDailyDate = new Array(), aMonthlyDate = new Array();
var LastDayClose;
var sDailyDate  = "", sMonthlyDate = "", sSelDate = "";
function BrowserSniffer() 
{
    var type;
	if (navigator.userAgent.indexOf("Opera")!=-1 &&document.getElementById) type="OP";		//Opera
	else if(navigator.userAgent.toLowerCase().indexOf("safari")!=-1) type="SAF";			
	else if (document.all) type="IE";														//Internet Explorer e.g. IE4 upwards
	else if (document.layers) type="NN";													//Netscape Communicator 4
	else if (!document.all && document.getElementById) type="MO";							//Mozila e.g. Netscape 6 upwards
	else type = "IE";	
	return type;
}


/******************************************/
// default charts from body
/******************************************/
function createXMLHttpRequest(t) 
{
   tab   = "Y1"; 
   bInit = 1;
   loadXMLI();
}
/// get etf name and go to flash to display on top
function getETFByTicker(index_ticker)
{
//	return "";
    var ticker = index_ticker.toUpperCase(), fl;
	if (ticker == "COMP" )
		fl= "ONEQ";
	else if (ticker == "$INDU")
		fl= "DIA";
	//else if (ticker == "RUT")
	//	fl= "IWM";
	else if (ticker == "SPX")
		fl= "IVV";
	else if (ticker == "MID")
		fl= "IJH";
	else
		//fl= "DIA";
		fl= "";
	return fl;
}
/// end holdings detrails TAB
function getMaxValue(adata)
{

   var max = -999999, data = null;
   for (var k=0; k<adata.length; k++)
   {
        data = adata[k];
        while (data.indexOf("^") >0 )
		   data = data.replace("^", "|");
		while (data.indexOf("R") >0 )
		   data = data.replace("R", "|");
		try
		{				
			var ss = data.split('|');
			for (var i=0; i< ss.length; i++)
			{
			   if (ss[i].indexOf("--") >=0  || ss[i] == "" || eval(ss[i]) <= -99999)
			     continue;
				max = Math.max(eval(ss[i]), max);
			}
		}
		catch(e)
		{
		}
	}
	return max;
}
function  getMinValue(adata)
{	
   var min= 999999, data = null;
   for (var k=0; k<adata.length; k++)
   {
		data = adata[k];
        while (data.indexOf("^") >0 )
		   data = data.replace("^", "|");
		while (data.indexOf("R") >0 )
		   data = data.replace("R", "|");
		try
		{				
			var ss = data.split('|');		  
			for (var i=0; i< ss.length; i++)
			{
			 if (ss[i].indexOf("--") >=0  || ss[i] == "" || eval(ss[i]) <= -99999)
			     continue;
				min = Math.min(eval(ss[i]), min);
			}
		}
		catch(e)
		{
		}
	}
	return min;
}
/// options P initial onload
function loadXMLI()
{
    var url = ""; 
    document.getElementById("chart").WMode    = "window"; 
    var  xmlhttp = (window.XMLHttpRequest)? new XMLHttpRequest(): new ActiveXObject("MSXML2.XMLHTTP");
    if (proxy == "")
        url ="info.aspx?Security=" + security +"&TimeFrame="+ tab;
    else
        url ="/qtProxy/IndexChartInfo.aspx?Security=" + security +"&TimeFrame="+ tab;
    xmlhttp.onreadystatechange = function() { processToGetPrice(xmlhttp); }; // processReqChanget;
	xmlhttp.open("GET", url, true);
	xmlhttp.send(null);
}

function processToGetPrice(xmlhttp) 
{
	if(xmlhttp.readyState == 4)
	{
		if(xmlhttp.status == 200)
		{	
		 	var temp1       = xmlhttp.responseText;
		 	if (temp1 == "")
		 	{
		 		alert("Not available ticker.");
		 		hide("wait");
		 		return;
		 	}
			var response    = temp1.split('#');	
			if (tab == "AL"  || (tab != "YTD" && tab.indexOf("Y") == 0  && parseInt(tab.substring(1)) > nDailyYears ))	
			{
				aMPriceC   = response[0].split("|");
				aMPriceH   = response[1].split("|");
				aMPriceL   = response[2].split("|");
				volUnit    = response[3].substring(0, response[3].indexOf("|"));
				var temp   = response[3].substring(response[3].indexOf("|")+1);
				aMVolume   = temp.split("|");	
				aMFairValue = response[4].split("|");	
			}else if (tab.indexOf("M") == 0 || tab == "YTD" || tab == "Y1" ){	
				aPriceC    = response[0].split("|");
				aPriceH    = response[1].split("|");
				aPriceL    = response[2].split("|");
				volUnit    = response[3].substring(0, response[3].indexOf("|"));
				var temp   = response[3].substring(response[3].indexOf("|")+1);
				aVolume    = temp.split("|");	
				aFairValue = response[4].split("|");
			//	alert(aFairValue[0] +" "+ aFairValue[1])
		    }else if (tab.indexOf("D") == 0 ){	
				aDPrice  = response[0].split("|");
		      //  alert(response[1])
				aIntraToday  = response[1].split("|");
				volUnit  = response[3].substring(0, response[3].indexOf("|"));
				var temp = response[3].substring(response[3].indexOf("|")+1);			
				aDVolume = temp.split("|");	
		    }

            volUnit = "("+volUnit+")";
			var tt= response[5];    
 			if (tt.indexOf("S")>=0)
 				tt = tt.substring(0, tt.indexOf("S"));
 				
 			if (tab == "D1" || tab == "D5" )
 			{
 			   sIntraDayTime = tt;	
 			   aIntraDay     = ProceeD1D5TimeLabels(tab, sIntraDayTime);	
 			   nStart = 0;
  			   nEnd   = aIntraDay.length - 1;
  			   if (tab == "D5" && aDLPriceL.length < 5)
  					getLastIntradayHL();
  			   else
  					getDay1IntradayHL();
  			
			}else if (tab == "AL"  || (tab != "YTD" && tab.indexOf("Y") == 0 && parseInt(tab.substring(1)) >  nDailyYears))
			{
			   aMonthlyDate         = tt.split("|");
			   sMonthlyDate         = tt;
			   nStart = 0;//getnStart(tab, aMonthlyDate);	
  			   nEnd   = aMonthlyDate.length - 1;
			}else if (tab == "YTD" || tab.indexOf("M") == 0 || parseInt(tab.substring(1)) <=  nDailyYears)
			{
			   aDailyDate = tt.split("|");
			   sDailyDate = tt;
			   nStart = 0;//getnStart(tab, aDailyDate);
  			   nEnd   = aDailyDate.length - 1;
		    }
		    if (bInit == 1)
		    {
		        tab = "Y1";
				bInit = 0;
            	    }
            	    
  		    if (bFirst)
		    {
		    	getLastFourDayHLC();
		    	bFirst = false;
			}	
	
 		    GetData(nStart, nEnd);
		    /// custom change time period
		  
 		}
		else
		{
			alert("There was a problem receiving the XML data:\n" + xmlhttp.statusText);
		}
	}
}
function getLastFourDayHLC()
{
	aDLPriceC.length = 0;
	aDLPriceH.length = 0;
	aDLPriceL.length = 0;

    for (var i=5; i>= 1; i--)
    {
		aDLPriceC[aDLPriceC.length] = aPriceC[aPriceC.length - i];
		if (i == 1) 
		{
			// just commented this will be right, getLastIntradayHL will modify aDLPriceC array.
			//aDLPriceH[aDLPriceH.length] = "n/a";
			//aDLPriceL[aDLPriceL.length] = "n/a";			
		} 
		else {
			aDLPriceH[aDLPriceH.length] = aPriceH[aPriceH.length - i + 1];
			aDLPriceL[aDLPriceL.length] = aPriceL[aPriceL.length - i + 1];
		}
    }
    
    LastDayClose = aDLPriceC[4];  
}
function getLastIntradayHL()
{	
    var dMaxValue = -999999;
    var dMinValue = 999999;   
    var temp = "";
	for (var i=0; i< aIntraToday.length; i++)
	{
	    if (temp == "")
	      temp = aIntraToday[i];
	    else
	      temp = temp +"|"+  aIntraToday[i];
	}

    var aTemp = temp.split("|");
	dMaxValue = Math.max(getMaxValue(aTemp), dMaxValue);
    dMinValue = Math.min(getMinValue(aTemp), dMinValue);
   	aDLPriceC[aDLPriceC.length] = LastDayClose;
	aDLPriceH[aDLPriceH.length] = dMaxValue;
	aDLPriceL[aDLPriceL.length] = dMinValue; 
}
function getDay1IntradayHL()
{
    var dMaxValue = -999999;
    var dMinValue = 999999;
   
    var temp = "";
	for (var i=0; i< aIntraToday.length; i++)
	{
	    if (temp == "")
	      temp = aIntraToday[i];
	    else
	      temp = temp +"|"+  aIntraToday[i];
	}
    var aTemp = temp.split("|");
	dMaxValue = Math.max(getMaxValue(aTemp), dMaxValue);
    dMinValue = Math.min(getMinValue(aTemp), dMinValue);
    aDPriceH.length = 0;
    aDPriceL.length = 0;
    aDPriceC.length = 0;
    
    aDPriceH[aDPriceH.length] = dMaxValue;
    aDPriceL[aDPriceL.length] = dMinValue; 
    aDPriceC[aDPriceC.length] = LastDayClose;
//    for (var i=0; i< aDPrice.length; i++)
//	{
//	    aDPriceH[aDPriceH.length] = dMaxValue;
//	    aDPriceL[aDPriceL.length] = dMinValue; 
//	    //aDPriceC[aDPriceC.length] = "n/a";	    
//	}	 
}

function ChgPrama(tag)
{   
    options = "";
    if (tab.indexOf("C") == 0)
    {
        aMonthlyDate.length = 0;
        aDailyDate.length   = 0;
    }
    showT("wait");
    hide("etf");
	if (tag != "CUT")
	{   
		tab = tag;
		if (tag == "D1"){
			findObj("tframe").src = "images/charts_565px_1day.gif"; 
			nMonths= 0;
			nYears = 0;
		}else if (tag == "D5"){
			findObj("tframe").src = "images/charts_565px_5day.gif";
			nMonths= 0;
			nYears = 0;	
		}else if (tag == "M1"){
			findObj("tframe").src = "images/charts_565px_1mo.gif"; 
			nMonths= 1;
			nYears = 1;
		}else if (tag == "M3"){
			findObj("tframe").src = "images/charts_565px_3mo.gif";
			nMonths= 3;
			nYears = 1;
		}else if (tag == "YTD")
		{
			findObj("tframe").src = "images/charts_565px_ytd.gif";
			nYears = 1;
		}else if (tag == "Y1"){
			findObj("tframe").src= "images/charts_565px_1yr.gif";
			nMonths= 12;
			nYears = 1;
		}else if (tag == "Y3"){
			findObj("tframe").src= "images/charts_565px_3yr.gif";
			nMonths= 36;
			nYears = 3;
		}else if (tag == "Y5"){
			findObj("tframe").src= "images/charts_565px_5yr.gif";
			nMonths= 60;
			nYears = 5;
		}else if (tag == "AL")
			findObj("tframe").src= "images/charts_565px_Max.gif"; 
	    hide("zoom");
	    loadXMLI();
	
	}
}

function getnStart(tab, dates)
{
	var ponits;
	
	if (tab != "YTD" && tab.indexOf("Y") == 0 && parseInt(tab.substring(1))> nDailyYears)
	   points = eval(tab.substring(1))* 12;
	else 
	   points = getNumberOfDataByTab();
	return dates.length - points;
}

function getnMonthlyStart(tab, sDates)
{
    var dates = sDates;
	var ponits;
	points = parseInt(tab.substring(1))* 12;	
	return dates.length - points -1;
}

function leapYear(year)
{
	datea = parseInt(year);
	if(datea%4 == 0)
	{
		if(datea%100 != 0)
		{
			return true;
		}
		else
		{
			if(datea%400 == 0)
				return true;
			else
				return false;
		}
	}
    return false;
}
function getDays(month, year) {
  // create array to hold number of days in each month
  month = month -1;
  var ar = new Array(12);
  ar[0] = 31; // January
  ar[1] = (leapYear(year)) ? 29 : 28; // February
  ar[2] = 31; // March
  ar[3] = 30; // April
  ar[4] = 31; // May
  ar[5] = 30; // June
  ar[6] = 31; // July
  ar[7] = 31; // August
  ar[8] = 30; // September
  ar[9] = 31; // October
  ar[10] = 30; // November
  ar[11] = 31; // December

  // return number of days in the specified month (parameter)
  return ar[month];
}
function getSelDate(days, sdates)
{
   var tt = days.split("/");
   while (sdates.indexOf(days) < 0)
   {
      if (tt[0]-1 > 0 && (eval(tt[1]) -1) < 1)
      {
          tt[1] = getDays(tt[0]-1, tt[2]);
      }else if ((eval(tt[1]) -1) < 1){
          tt[0] = 12;
          tt[2] = tt[2] - 1;
          tt[1] = getDays(tt[0], tt[2]);
      }
      tt[1] = eval(tt[1]) -1;
      days = tt[0] +"/"+ tt[1] +"/"+ tt[2];
   }
   var sSel = sdates.substring(sdates.indexOf(days));
   return sSel;
}
function getNumberOfDataByTab()
{
   var start  = getStartDate();
   var points = 0;
   if (tab.indexOf("D") != 0 )
   {
      sSelDate = getSelDate(start, sDailyDate);
      var temp = sSelDate.split("|");
      points   = temp.length;
   } 
   return points; 
}
function getStartDate()
{
   var cur = curDay;
   if (tab == "YTD")
       cur = "1/4/"+ curYear;
   else if (tab == "Y1" && curMonth != 12)
       cur = curMonth+"/"+curDate +"/"+ (curYear-1);
   else if (tab == "Y1" && curMonth == 12)
       cur = "1/4/"+ curYear;
   else if (tab == "Y3")
       cur = aDailyDate[0];
   else if (tab.indexOf("M") != 0)
   {
		if (eval(tab.substring(1))> nDailyYears &&  curMonth != 12)
			cur = curMonth+"/"+curDate +"/"+ (curYear - eval(tab.substring(1)));
		else if (eval(tab.substring(1))> 1 && curMonth == 12)
			cur = curMonth+"/"+curDate +"/"+ (curYear - eval(tab.substring(1)) - 1);
   }else if (tab.indexOf("M") == 0)
   {
		if (eval(tab.substring(1))>= 1 &&  curMonth - eval(tab.substring(1)) > 0)
			cur = (curMonth - eval(tab.substring(1))) +"/"+curDate +"/"+ curYear;
		else if (eval(tab.substring(1))>= 1 && eval(tab.substring(1)) - curMonth >= 0)
			cur = (12 - (eval(tab.substring(1)) - curMonth) ) +"/"+curDate +"/"+ (curYear - 1);
   
   }
   return cur; 
}
	

function GetData(nStart, nEnd)
{
   if (nStart == nEnd)
      nStart = nStart -1;
   if (tab == "AL" || (nMonths > 12 && nYears > 1 ))
      GetMPriceData(nStart, nEnd, aMPriceH, aMPriceL, aMPriceC, aMVolume,aMFairValue,aMonthlyDate);
   else if (tab.indexOf("D") != 0)
      GetMPriceData(nStart, nEnd, aPriceH, aPriceL, aPriceC, aVolume,aFairValue,aDailyDate);
   else if (tab.indexOf("D") == 0)
      GetDPriceData();
}

function loadCustomData(nSDate, nEDate)
{
    if (nSDate.indexOf(",") < 0 && nSDate == nEDate)
        return;
    showT("wait");
    var url = "";   
    var sm =  GetMonth(nSDate), em = GetMonth(nEDate);
    var sy =  GetYear(nSDate), ey = GetYear(nEDate);
    if (nSDate.indexOf(",") > 0  && sy == ey && sm == em)
    {
       nSDate = sm+"/1/" + sy;
       nEDate = em+"/" + getDays(em, ey) + "/" + ey;
    } 
    nYears = ey - sy + 1;
    if (nYears == 1){
        nMonths = em-sm + 1;
        tab = "M"+(em-sm);
    }else{
        nMonths = curMonth   + (12 - sm);
        tab = "Y" +(ey - sy);
    }
    var  xmlhttp = (window.XMLHttpRequest)? new XMLHttpRequest(): new ActiveXObject("MSXML2.XMLHTTP");
    if (proxy == "")
        url ="info.aspx?Security=" + security + "&TimeFrame=CUT"+"&DateFrom="+ nSDate +"&DateTo=" +nEDate;
    else
        url ="/qtProxy/IndexChartInfo.aspx?Security=" + security + "&TimeFrame=CUT"+"&DateFrom="+ nSDate +"&DateTo=" +nEDate;
    xmlhttp.onreadystatechange = function() { processCutToGetPrice(xmlhttp); }; // processReqChanget;
	xmlhttp.open("GET", url, true);
	xmlhttp.send(null);
}
function processCutToGetPrice(xmlhttp) 
{
	if(xmlhttp.readyState == 4)
	{
		if(xmlhttp.status == 200)
		{	
		 	var temp1       = xmlhttp.responseText;
			var response    = temp1.split('#');	
				
		//	if (tab.indexOf("M") != 0 && parseInt(tab.substring(1)) > nDailyYears )	
			// alert("h=  "+ nMonths + " y= "+ nYears)
		    if (nMonths >= 12 && nYears >= 1 )	
			{
				aMPriceC  = response[0].split("|");
				aMPriceH  = response[1].split("|");
				aMPriceL  = response[2].split("|");
				volUnit   = response[3].substring(0, response[3].indexOf("|"));
				var temp  = response[3].substring(response[3].indexOf("|")+1);
				aMVolume  = temp.split("|");
				if (response[4] != "" )
				   aMFairValue = response[4].split("|");
				else
				   aMFairValue.length = 0;			
			}else {	
				aPriceC  = response[0].split("|");
				aPriceH  = response[1].split("|");
				aPriceL  = response[2].split("|");
				volUnit  = response[3].substring(0, response[3].indexOf("|"));
				var temp = response[3].substring(response[3].indexOf("|")+1);
				aVolume  = temp.split("|");	
				if (response[4] != "" )
				   aFairValue = response[4].split("|");
				else
				   aFairValue.length = 0;	
		    }
            volUnit = "("+volUnit+")";
			var tt= response[5];    
 			if (tt.indexOf("S")>=0)
 				tt = tt.substring(0, tt.indexOf("S"));
 			//if (tab != "YTD" && tab.indexOf("Y") == 0 && parseInt(tab.substring(1)) >  nDailyYears)
 	
 			if (nMonths > 12 && nYears > 1 )	
			{
			   aMonthlyDate         = tt.split("|");
			   sMonthlyDate         = tt;
			   nStart = 0;	
  			   nEnd   = aMonthlyDate.length - 1;
			}else //if (parseInt(tab.substring(1)) <=  nDailyYears)
			{
			   aDailyDate = tt.split("|");
			   sDailyDate = tt;
			   nStart = 0;
  			   nEnd   = aDailyDate.length - 1;
		    }
		    GetData(nStart, nEnd);
		   
 		}
		else
		{
			alert("There was a problem receiving the XML data:\n" + xmlhttp.statusText);
		}
	}
}
function GetDPriceData()
{
   var h   = 200;
   var yb  = 250;
   flashMovie("chart").clearAll(tab, volUnit, security,"no"); 
   /// draw xlabels 
   var xLabels = "", ss="";
   if (tab == "D5")
   {
		var dd = sIntraDayTime.split("|");
		for (i=0; i<dd.length; i++)
		{
			if (dd[i] == "")
			continue;
			if (ss == "")
				ss = dd[i].substring(0, dd[i].indexOf(" "));
			else
				ss = ss +"|"+dd[i].substring(0, dd[i].indexOf(" "));
		}
   }else{   
      ss = "|10:00 AM||11:00 AM||12:00 PM||1:00 PM||2:00 PM||3:00 PM|";
   }
   if (tab == "D1")
       xLabels = GetDColumn(ss , 13, chart_width);
   else
       xLabels = GetDColumn(ss , 5, chart_width);
  // alert(xLabels)
   var xLabel = xLabels.split('^');
   flashMovie("chart").drawXlabel(xLabel[0],xLabel[1]);
   flashMovie("chart").drawSeperator("Volume " + volUnit, yb);
   ///
   var dMaxValue = -999999;
   var dMinValue = 999999;
   if (tab == "D1")
      flashMovie("chart").onSetNumberOfPoints("", 79, chart_width); 
   else
      flashMovie("chart").onSetNumberOfPoints("", 395, chart_width); 
   dMaxValue = Math.max(getMaxValue(aDPrice), dMaxValue);
   dMinValue = Math.min(getMinValue(aDPrice), dMinValue);
   var LL = AdjustFRigthScaleGrid(eval(dMaxValue), eval(dMinValue), 6);
   dMinValue = LL.substring(0,LL.indexOf("|"));
   dMaxValue = LL.substring(LL.lastIndexOf("|")+1);  
  // alert(aDLPriceH) 
   if (tab == "D1")
		flashMovie("chart").onDrawHLCGraph("",aIntraDay,aDPriceH, aDPriceL, aDPriceC,aDPrice, 0, h, yb, dMaxValue, dMinValue, 1);
   else
		flashMovie("chart").onDrawHLCGraph("",aIntraDay,aDLPriceH, aDLPriceL, aDLPriceC,aDPrice, 0, h, yb, dMaxValue, dMinValue, 1);
   flashMovie("chart").onDrawYLabel(LL, h, yb, 0, 1); 
    /// draw volume 
   if (volUnit.indexOf("Not") < 0)
   {
        yb = 355;
		dMaxValue = -999999;
		dMinValue = 999999;
		dMaxValue = Math.max(getMaxValue(aDVolume), dMaxValue);
		dMinValue = Math.min(getMinValue(aDVolume), dMinValue);
		LL = AdjustFRigthScaleGrid(eval(dMaxValue), eval(dMinValue), 6);
		dMinValue = LL.substring(0,LL.indexOf("|"));
		dMaxValue = LL.substring(LL.lastIndexOf("|")+1);
		flashMovie("chart").onDrawPolyline("", aDVolume,3, 85, yb, dMaxValue, dMinValue, 3);
		flashMovie("chart").onDrawYSubLabels(LL,"bottom", yb);
   }
    hide("wait");
}
function GetMPriceData(nStart, nEnd, PriceH, PriceL, PriceC, Volume, FValue, Dates)
{
   var h   = 200;
   var yb  = 250;
   var td = "", tt= "",ns = nStart, ne = nEnd;
   var etfTicker = getETFByTicker(security);
   if (etfTicker.length > 0)
   {
   	//flashMovie("chart").clearAll(tab, volUnit, security, "Fair Value("+etfTicker+")"); 
   	bShowFairValue = true;
   	flashMovie("chart").clearAll(tab, volUnit, security, "Fair Value"); 
   } 
   else 
   {
   	// Yougu modified this part so that it for now does not display fair value for morningstar indexes.
   	// This change is assumed to be temporary and should be changed again when the fair value is available.
   	//
   	bShowFairValue = false;
   	flashMovie("chart").clearAll(tab, volUnit, security, "no"); 
   }
   //flashMovie("chart").clearAll(tab, volUnit, security, "Fair Value("+getETFByTicker(security)+")"); 
   var n = 0;
   var dNS = nStart, dNE = nEnd;
   var dMaxValue = -999999;
   var dMinValue = 999999;
   for (n= 0; n< Dates.length; n++)
   {
       if (Dates[n] == undefined )
          return;
	   if (td == "")
		   td = Dates[n];
	   else
		   td = td +"|"+ Dates[n];
   }
   var xLabels = GetColumn(td , 65, chart_width);  
 //  alert(xLabels)
   var xLabel = xLabels.split('^');
   flashMovie("chart").drawXlabel(xLabel[0],xLabel[1]);
   flashMovie("chart").drawSeperator("Volume " + volUnit+"", yb);
   flashMovie("chart").onSetNumberOfPoints(td, 0, chart_width); 
   selDates  = td.split("|");
 
   selDates  = Dates;
   selDataH  = PriceH;
   selDataL  = PriceL;
   selDataC  = PriceC;
   selDataV  = Volume;
   
   selDataFV = FValue;

   /// draw high-low close chart
   dMaxValue = Math.max(getMaxValue(selDataH), dMaxValue);
   dMinValue = Math.min(getMinValue(selDataH), dMinValue);
   dMaxValue = Math.max(getMaxValue(selDataL), dMaxValue);
   dMinValue = Math.min(getMinValue(selDataL), dMinValue);
   dMaxValue = Math.max(getMaxValue(selDataC), dMaxValue);
   dMinValue = Math.min(getMinValue(selDataC), dMinValue);
   if (selDataFV.length > 0)
   {
		dMaxValue = Math.max(getMaxValue(selDataFV), dMaxValue);
		dMinValue = Math.min(getMinValue(selDataFV), dMinValue);
   }
   var LL = AdjustFRigthScaleGrid(eval(dMaxValue), eval(dMinValue), 6);
   dMinValue = LL.substring(0,LL.indexOf("|"));
   dMaxValue = LL.substring(LL.lastIndexOf("|")+1);
   flashMovie("chart").onDrawHLCGraph("",selDates,selDataH, selDataL, selDataC,selDataC, 0, h, yb, dMaxValue, dMinValue, 0);
   if (selDataFV.length > 0)
   {
      flashMovie("chart").onDrawPolyline("", selDataFV,3, h, yb, dMaxValue, dMinValue, 2);
   }
   flashMovie("chart").onDrawYLabel(LL, h, yb, 0, 1); 
   /// draw volume 
   if (selDataV.length > 1  && volUnit.indexOf("Not") < 0)
   {
        yb = 355; /// 305
		dMaxValue = -999999;
		dMinValue = 999999;
		dMaxValue = Math.max(getMaxValue(selDataV), dMaxValue);
		dMinValue = Math.min(getMinValue(selDataV), dMinValue);
		LL = AdjustFRigthScaleGrid(eval(dMaxValue), 0, 6);
		dMinValue = LL.substring(0,LL.indexOf("|"));
		dMaxValue = LL.substring(LL.lastIndexOf("|")+1);
		 
		flashMovie("chart").onDrawPolyline("", selDataV,3, 85, yb, dMaxValue, 0, 3);
		flashMovie("chart").onDrawYSubLabels(LL,"bottom",yb);
   }
   hide("wait");
}


function getDataWithDailyTab(sdata, tab)
{
   if (tab == "Y10")
      return sdata;
   var temp = sdata.split("|");
   nYear = tab.substring(1);
   var m = temp.length - nYear*252;
   if (m <0)
     m = 0;
   var ss="";
   for (var i=temp.length - 1; i>= m; i--)
   {
     if (ss == "")
       ss = temp[i];
     else 
       ss = temp[i] + "|"+ ss;
   }
   var tt= ss.split("|");
   return ss;
}

function GetYear(str ) 
{
	var l= str;
	if (l.indexOf("S")>0)
		l = l.substring(0, l.indexOf("S"));
	if (l.lastIndexOf("/") >= 0)
		l = l.substring(l.lastIndexOf("/") +1);	
	else if (l.lastIndexOf(",") >= 0)
		l = l.substring(l.lastIndexOf(",") +1);	
	return l;													 
}
function GetYears(dates)
{
	var f = dates[0];
	var l = dates[dates.length-1];
	if (l.indexOf("S")>0)
		l = l.substring(0, l.indexOf("S"));
	if (f.lastIndexOf("/") >0)
	{
		f = f.substring(f.lastIndexOf("/") +1);
		l = l.substring(l.lastIndexOf("/") +1);	
	}else  if (f.lastIndexOf(",") >0)
	{
		f = f.substring(f.lastIndexOf(",") +1);
		l = l.substring(l.lastIndexOf(",") +1);	
	}
	return parseInt(l) - parseInt(f) + 1;	
														 
}
function GetMonth(str ) 
{
	var l  = str;
	if (l.indexOf("S")>0)
		l = l.substring(0, l.indexOf("S"));
	if (l.indexOf("/") >= 0)
	{
		l = l.substring(0,l.indexOf("/"));	
				
	}else if (l.lastIndexOf(",") >= 0)
		l = l.substring(0,l.indexOf(","));			 	
	return parseInt(l);															 
}
function showMessage(msg)
{
  //  findObj("MSG").value = msg;
    alert(msg)
}
function showETF(show)
{
    if (!bShowFairValue) 
    {
    	return;
    }
    if (show > 0)
    {
      showT("etf");
    }else
      hide("etf");
}
function showZoom(show)
{
    if (show > 0)
      showT("zoom");
    else
      hide("zoom");
}
//mmmmm
function flashMovie(name)
{
        var movieName = name;
	 	if (window.document[movieName]) 
		{
			return window.document[movieName];
		}
		if (navigator.appName.indexOf("Microsoft Internet")==-1)
		{
			if (document.embeds && document.embeds[movieName])
			  return document.embeds[movieName]; 
		}
		else  if (navigator.appName.indexOf("Microsoft Internet")!=-1)
		{
			return document.getElementById(movieName);
		}
}

