/*** 
Created - BJY 2/15/2006	
This function checks the referring URL on a page load and 
redirects if the referring URL matches any of the tokens 
declared within.
This file is to be included in briefing.com/default.htm 

Updated:
    Brian Jensen    01/05/2009 - Added new partners and their sources
    Brian Jensen    02/10/2009 - Changed from 14 day to 30 day Trial
    Brian Jensen    07/14/2009 - Added Redirect to each partner url so that differenct partners can redirect to different places
                               - Added briefingadvisor.com redirect
    Brian Jensen    08/04/2009 - Changed the Yahoo url from https://www.briefing.com/GeneralContent/Active/Signup/InPlayEQ/InPlayTrial.aspx
                                 to http://www2.briefing.com/lps/partners/yahoo1.html
    Brian Jensen    08/18/2009 - Added eight new partner specific redirects
    Brien Jensen    10/19/2009 - Added Mobile redirects
    Brian Jensen    10/22/2009 - Removed the specific partner redirects and added the BIP redirect
***/
function checkReferrerAndRedirect()
{	
    if (document.URL.toUpperCase().indexOf('BRIEFINGADVISOR.COM') != -1)
    {
        location.href = "http://www.briefing.com/Advisor/";
    }
    else if ((document.URL.toUpperCase().indexOf('MOBILE.BRIEFING.COM') != -1) || (document.URL.toUpperCase().indexOf('BRIEFING.MOBI') != -1))
    {
        location.href = "http://www.briefing.com/Mobile/EQ/MobileInPlay.htm";
    }
    else
    {
	    var redirectURL = "https://www.briefing.com/GeneralContent/Active/Signup/InPlayEQ/InPlayTrial.aspx";
	    var BIPRedirectURL = "http://www2.briefing.com/Marketing/LandingPages/Partners/All/BIP-Partners.html";

	    // declare tokens to catch for redirect in this array
	    var refTokens = new Array();
        refTokens[0]  = {url:'moneycentral.msn.com'            ,source:'MSN'               ,redirect:BIPRedirectURL};   // MSN Money
        refTokens[1]  = {url:'biz.yahoo.com'                   ,source:'Yahoo'             ,redirect:BIPRedirectURL};   // Yahoo! Finance Public
        refTokens[2]  = {url:'finance.yahoo.com'               ,source:'Yahoo'             ,redirect:BIPRedirectURL};   // Yahoo! Finance Public
        refTokens[3]  = {url:'gobaker.com'                     ,source:'BakerGroup'        ,redirect:BIPRedirectURL};   // Baker Group
        refTokens[4]  = {url:'morningstar.com'                 ,source:'Morningstar'       ,redirect:BIPRedirectURL};   // Morningstar
        refTokens[5]  = {url:'wyse-sec.com'                    ,source:'Pyramid'           ,redirect:BIPRedirectURL};   // Pyramid Financial
        refTokens[6]  = {url:'smartmoney.com'                  ,source:'SmartMoney'        ,redirect:BIPRedirectURL};   // SmartMoney
        refTokens[7]  = {url:'DailyFX.com'                     ,source:'DailyFX'           ,redirect:BIPRedirectURL};   // Forex Capital Markets
        refTokens[8]  = {url:'nasdaq.com'                      ,source:'NASDAQ'            ,redirect:BIPRedirectURL};   // NASDAQ.com
        refTokens[9]  = {url:'etrade.com'                      ,source:'Etrade'            ,redirect:BIPRedirectURL};   // etrade.com

        refTokens[10] = {url:'aol.com'                         ,source:'AOL'               ,redirect:redirectURL};      // AOL
        refTokens[11] = {url:'clearstation.com'                ,source:'ClearStation'      ,redirect:redirectURL};      // ClearStation
        refTokens[12] = {url:'scottrade.com'                   ,source:'Scottrade'         ,redirect:redirectURL};      // Scottrade
        refTokens[13] = {url:'tdameritrade.com'                ,source:'TDAmeritrade'      ,redirect:redirectURL};      // TD Ameritrade
        refTokens[14] = {url:'online.wsj.com'                  ,source:'WSJPartner'        ,redirect:redirectURL};      // WSJ Online
        refTokens[15] = {url:'fisbonds.com'                    ,source:'AAM'               ,redirect:redirectURL};      // Advisors Asset Management
        refTokens[16] = {url:'bmoinvestorline.com'             ,source:'BMO'               ,redirect:redirectURL};      // BMO InvestorLine
        refTokens[17] = {url:'bmolignedaction.com'             ,source:'BMO'               ,redirect:redirectURL};      // BMO InvestorLine
        refTokens[18] = {url:'bonds.com'                       ,source:'Bonds'             ,redirect:redirectURL};      // Bonds.com
        refTokens[19] = {url:'hsbc.com'                        ,source:'HSBC'              ,redirect:redirectURL};      // HSBC Canada
        refTokens[20] = {url:'securities.hsbc.com'             ,source:'HSBC'              ,redirect:redirectURL};      // HSBC Canada
        refTokens[21] = {url:'quicken.com'                     ,source:'Intuit'            ,redirect:redirectURL};      // Intuit
        refTokens[22] = {url:'marketsimplified.com'            ,source:'INXS'              ,redirect:redirectURL};      // INXS
        refTokens[23] = {url:'jamisonfinancialgroup.com'       ,source:'JamisonFinancial'  ,redirect:redirectURL};      // Jamison Financial
        refTokens[24] = {url:'alawsat.com'                     ,source:'KMEFIC'            ,redirect:redirectURL};      // KMEFIC
        refTokens[25] = {url:'bkmeonline.com'                  ,source:'KMEFIC'            ,redirect:redirectURL};      // KMEFIC
        refTokens[26] = {url:'knightbondpoint.com'             ,source:'KnightBondPoint'   ,redirect:redirectURL};      // Knight BondPoint
        refTokens[27] = {url:'quote123.com'                    ,source:'Momentum'          ,redirect:redirectURL};      // Momentum
        refTokens[28] = {url:'morgankeegan.com'                ,source:'MorganKeegan'      ,redirect:redirectURL};      // Morgan Keegan & Co.
        refTokens[29] = {url:'thefidreport.com'                ,source:'RaymondJames'      ,redirect:redirectURL};      // Raymond James
        refTokens[30] = {url:'smartmoneyselect.com'            ,source:'SmartMoney'        ,redirect:redirectURL};      // SmartMoney
        refTokens[31] = {url:'step.com'                        ,source:'Step'              ,redirect:redirectURL};      // Step.com
        refTokens[32] = {url:'tdwaterhouse.ca'                 ,source:'TDWaterhouse'      ,redirect:redirectURL};      // TD Waterhouse (Canada)
        refTokens[33] = {url:'dailygraphs.com'                 ,source:'WilliamONeil'      ,redirect:redirectURL};      // William O'Neil & Company
        refTokens[34] = {url:'optionsxpress.com'               ,source:'OptionsXpress'     ,redirect:redirectURL};      // optionsXpress
        refTokens[35] = {url:'urwealthy.com'                   ,source:'Teabull'           ,redirect:redirectURL};      // Teabull Asset Timer
        refTokens[36] = {url:'bonddesk.com'                    ,source:'Fidelity'          ,redirect:redirectURL};      // Bond Desk - Fidelity Direct
        refTokens[37] = {url:'fidelity.com'                    ,source:'Fidelity'          ,redirect:redirectURL};      // Bond Desk - Fidelity Direct
        refTokens[38] = {url:'investools.com'                  ,source:'Zava'              ,redirect:redirectURL};      // Comtext sublicensees Investools, Zava
        refTokens[39] = {url:'zavatech.com'                    ,source:'Zava'              ,redirect:redirectURL};      // Comtext sublicensees Investools, Zava
        refTokens[40] = {url:'schwab.com'                      ,source:'Schwab'            ,redirect:redirectURL};      // Knight BondPoint (formerly ValuBond) - Schwab
        refTokens[41] = {url:'firstrepublicbrokerage.com'      ,source:'Pershing'          ,redirect:redirectURL};      // Pershing - First Republic, Hewitt Financial, Stanford Research
        refTokens[42] = {url:'hewittfs.com'                    ,source:'Pershing'          ,redirect:redirectURL};      // Pershing - First Republic, Hewitt Financial, Stanford Research
        refTokens[43] = {url:'investments.stanfordgroup.com'   ,source:'Pershing'          ,redirect:redirectURL};      // Pershing - First Republic, Hewitt Financial, Stanford Research
        refTokens[44] = {url:'bettertrades.com'                ,source:'Zacks'             ,redirect:redirectURL};      // Zacks - Bear Stearns, BetterTrades.com
        refTokens[45] = {url:'jpmorgan.com'                    ,source:'Zacks'             ,redirect:redirectURL};      // Zacks - Bear Stearns, BetterTrades.com
        refTokens[46] = {url:'internationalinvesting.com.au'   ,source:'II-AU'             ,redirect:redirectURL};      // International Investing - Australia

	    for(i=0; i<refTokens.length; i++)
	    {	
		    if (document.referrer.toUpperCase().indexOf(refTokens[i].url.toUpperCase()) != -1)
		    {
		        var src = refTokens[i].source;
		        if (src && src.length > 0)
		        {
			        location.href = refTokens[i].redirect + "?Source=" + refTokens[i].source;
			    }
			    else
			    {
			        location.href = refTokens[i].redirect;
			    }
		    }
	    }
	}
}

checkReferrerAndRedirect();