﻿// JScript File
  	        var today = new Date();
	        var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000); // 1 Year
            var fundList = document.cookie;
            
function setmyfundscookie()
{
    var cookieval = "";
    for (var a=0; a<document.forms[0].elements.length; a++)
	{
		if (document.forms[0].elements[a].type=="checkbox")
		{

		if (document.forms[0].elements[a].checked == true)
		{
		cookieval += ','+document.forms[0].elements[a].value
		}
	}					

	}
    SetCookie ('myfunds', cookieval, expiry, "/", strDomain);	
    window.parent.location=strUrlToRedirect;	
}
			
function WriteMyFundsPage()
{ 
    var getfunNumbers = getCookie ("myfunds");
    if(getfunNumbers==null)
    {
        getfunNumbers="";
    }
    var sProcutsAray=this.ProductsArray;
    var sProductArray ="";
    var txtoutput = "";
    var intnumberofrows=0;
    var arraylength = sProcutsAray.length;
    
    if (type=="IE") 
        arraylength=(arraylength-1);
    
    for(var i=0;i<(arraylength);i++)
    {
        sProductArray = sProcutsAray[i];
        intnumberofrows++;
       
        // if((intnumberofrows)>intNumberOfRowsInFirstColumn+1)
        if((intnumberofrows)>intNumberOfRowsInFirstColumn)
        {        
            txtoutput +=" </td><td valign='top' width='50%'>";
            intnumberofrows=0;
        }        
        txtoutput +='<table cellpadding="2px" cellspacing="0" border="0" width="100%">';
        txtoutput +='<tr class="section-sage"><th colspan="3">';
        txtoutput += sProductArray[0][0];
        txtoutput +='</th></tr>';
        for(var x=0;x<(sProductArray.length-1);x++)
        {
            txtoutput += '<tr class="rulebelow-sage">';
            txtoutput += '<th>';
            txtoutput += sProductArray[x][4] + '(' +sProductArray[x][1] + sProductArray[x][3]+ ')';
            txtoutput += '</th>';
            txtoutput += '<td style="vertical-align:middle;">';
            if(getfunNumbers.indexOf(sProductArray[x][2]) >-1 )
            {      
                txtoutput += '<input name='+sProductArray[x][2]+' type="checkbox" value='+sProductArray[x][2]+' id='+sProductArray[x][2]+' checked />';
            }
            else
            {
            txtoutput += '<input name='+sProductArray[x][2]+' type="checkbox" value='+sProductArray[x][2]+' id='+sProductArray[x][2]+'/>';
            }
            txtoutput += '</td>';
            txtoutput += '</tr>';
         }

        txtoutput +='</table>';
    }
    document.write (txtoutput);
}


 function AddLeadingZeroes(strNumber)
 {
 if(strNumber.length<2){
 strNumber = "0"+strNumber;
 
 }
 return strNumber
 
 }
 
 
function WriteMyFundsPrices()
{
    var getfunNumbers = getCookie ("myfunds");
    var txtoutput = "";
    if(getfunNumbers!=null)
    {  
        var sProcutsAray=this.ProductsArray;  
        var tmppricedate = sProcutsAray[0][5].split('/') ;
  
        for(var i=0;i<(sProcutsAray.length-1);i++)
        {
            if(getfunNumbers.indexOf(ProductsArray[i][0]) >-1 )   
            {
                txtoutput += '<tr>';
                txtoutput += '<th class=\"ruleabove\">';
                txtoutput += sProcutsAray[i][1] +"&nbsp;"+ sProcutsAray[i][2];
                txtoutput += '</th>';
                txtoutput += '<td class=\"align-right\">';
                txtoutput += sProcutsAray[i][4] ;
                txtoutput += '</td>';
                 txtoutput += '<td class=\"width1 align-right\">';
                txtoutput += sProcutsAray[i][6] ;
                txtoutput += '</td>';
                txtoutput += '</tr>';
            }
        }
        document.write (txtoutput);   
        //write the date    
        var pricedate = AddLeadingZeroes(tmppricedate[0]) +"-"+AddLeadingZeroes(tmppricedate[1])+"-"+ AddLeadingZeroes(tmppricedate[2]); 
        var asat = "";
        if(currentLanguage=="EN")
        asat = "as at";
        else
        asat = "au";
        if (type=="IE") 
        {
            document.all[currentLanguage + "MyfundsDate"].innerHTML = asat + " "+ pricedate; 
        }
        if (type=="NN") 
        {
            document.layers[currentLanguage + "MyfundsDate"].document.open();
            document.layers[currentLanguage + "MyfundsDate"].document.write(asat +" "+ pricedate);
            document.layers[currentLanguage + "MyfundsDate"].document.close();
        }

        if (type=="MO" || type=="OP") 
        {
            document.getElementById(currentLanguage + "MyfundsDate").innerHTML = asat + " "+ pricedate;
        } 
    }  
}

function CreateFundPriceTable(Version)
{      
    if(Version == "short") 
    {
        var UserFundNumbers = getCookie ("myfunds");
        if(UserFundNumbers!=null && UserFundNumbers!="")
        {
            CreateMyFundsTable(UserFundNumbers);
        }
        else
        {
            CreateFeaturedFundsTable();
        }
    }
    else if (Version == "full")
    {
        CreateAllFundsTable();
    }
}

function CreateAllFundsTable()
{
    var oTable = document.getElementById("Prices");
    if(oTable != null)
    {
        for(var i = oTable.rows.length - 1; i > 0; i--)
        {
            oTable.deleteRow(i);
        }
        for(fundNumber in funds)
        {
            var fund =funds[fundNumber];
            InsertFundDetails(fund,oTable.insertRow(-1));            
        }   
    }
    CreateBottomLink("short");
    // resize table's containers (glitch of IE7 browser)
    if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.indexOf("MSIE 7.0;") > -1)
    {
        oTable.parentElement.style.cssText = "";
        oTable.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.style.cssText = "";
    }
}

function CreateMyFundsTable(UserFundNumbers)
{
    var oTable = document.getElementById("Prices");
    if(oTable != null)
    {
        for(var i = oTable.rows.length - 1; i > 0; i--)
        {
            oTable.deleteRow(i);
        }
        var FundList = UserFundNumbers.split(',');
        for (i=0;i<FundList.length;i++) 
	    {
	        if(FundList[i] != "")
	        {
	            var fund = funds[FundList[i]];
	            InsertFundDetails(fund,oTable.insertRow(-1));                 
	        }
	    }
	}
	CreateBottomLink("full");
	
	if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.indexOf("MSIE 7.0;") > -1)
    {
        oTable.parentElement.style.cssText = "";
        oTable.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.style.cssText = "";
    }
}

function InsertFundDetails(fund,NewRow)
{
    var cell1 = NewRow.insertCell(-1);
    cell1.innerHTML = fund.desc.replace("&quot;","'");    
    
    var cell2 = NewRow.insertCell(-1);
    cell2.innerHTML = fund.series.replace(" ","");;
    cell2.className="align-right";
    
   	var cell3 = NewRow.insertCell(-1);
   	cell3.className="align-right";
   	cell3.innerHTML = fund.Price;	
   	
   	var cell4 = NewRow.insertCell(-1);
   	
   	if(fund.DollarChange < 0) 
   	    cell4.className="align-right down width1";         
    else
        cell4.className="align-right up width1";        
     
   	cell4.innerHTML = fund.DollarChange;   	
}

function CreateBottomLink(version)
{
    
    var oTable = document.getElementById("Prices");
    if(oTable != null)    
    {
        var priceDate = "";
        for(FundNumber in funds)
        {
            if(priceDate != "")
                break;
            else
               priceDate = funds[FundNumber].PriceDate;             
        } 
        var NewRow = oTable.insertRow(-1);       
        oTD = NewRow.insertCell(-1);
        oTD.colSpan = "2";
        oTD.innerText = priceDate;
        
        oTD = NewRow.insertCell(-1);
        oTD.colSpan = "2";
       // if(version == "full")
       // {   
            if(language == "en")
                oTD.innerHTML = '<a href="/nbadvisor_en/investment-solutions/prices-performance/daily-pricing/">View complete list </a>';
            else
                oTD.innerHTML = '<a href="/nbadvisor_fr/investment-solutions/prices-performance/daily-pricing/" >Voir la liste compl&egrave;te</a>';
      // }            
        //else if(version == "short")
       // {
          //   if(getCookie ("myfunds") != null)
          //   {
            //    if(language == "en")
            //        oTD.innerHTML =  '<a href="#" onClick="Javascript:CreateFundPriceTable(\'short\');">View featured funds</a>'; 
            //    else 
            //     oTD.innerHTML =  '<a href="#" onClick="Javascript:CreateFundPriceTable(\'short\');">Voir les fonds vedettes</a>'; 
            // } 
             //else
            // {
             //   if(language == "en")
               //     oTD.innerHTML =  '<a href="#" onClick="Javascript:CreateFundPriceTable(\'short\');">View featured funds</a>'; 
              //  else 
               //     oTD.innerHTML =  '<a href="#" onClick="Javascript:CreateFundPriceTable(\'short\');">Voir les fonds vedettes</a>'; 
             //}  
        }
    //}
}

function CreateFeaturedFundsTable()
{    
    var oTable = document.getElementById("Prices");
    if(oTable != null)    
    {
       for(var i = oTable.rows.length - 1; i > 0; i--)
        {
        oTable.deleteRow(i);
        }
        for(fundNumber in funds)
        {
            var fund =funds[fundNumber];
            if(fund.IsFeaturedFund=="true")
            {
                var NewRow = oTable.insertRow(-1);
                InsertFundDetails(fund,NewRow); 
                             
            }
        } 
        CreateBottomLink("full"); 
        if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.indexOf("MSIE 7.0;") > -1)
        {
            oTable.parentElement.style.cssText = "";
            oTable.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.style.cssText = "";
        } 
    }
}


