/*
**File: navigation.js
**Author: Aaron Smalls (appbq0c)
**Javascript Navigation utilities 
*/

/*GetJunction() = Flash hack, Access Manager does this just fine except for with the flash files*/
//This should be update (perhaps) to actually return the junction instead of using the hardcoded value


function getFb2Domain()
{
    var url = String(document.location);
	if (url.match(/172./))
	{
		return "http://localhost:9085";
	}
    else if (url.match(/localhost/))
	{
		return "http://localhost:9085";
	}
	else if ( url.match(/deecm/) || url.match(/www3dev/))
	{
		return "http://www3dev.troweprice.com";
	}
	else if(url.match(/qeecm/) || url.match(/www3qual/))
    {
	    return "http://www3qual.troweprice.com";
    }
	else
	{
	    //this needs updating for PROD url since we aren't in PROD yet but v7 page is
	    return "http://www3.troweprice.com";
	}
}

/* need to account for FB2 running under either FB2 junction or toolstaging */
function getJunction(){
	var url = String(document.location);
	if ( url.match(/www3/)){
		if(url.match(/fb2/))
			return "/fb2";
		else if(url.match(/toolsstaging/))
			return "/toolsstaging";
	}
	else{
		return "";
	}
}

function  openVATopTenWindow()
{
	centerWindowOpener(800,650,"vaTopTenWin",getJunction() + "/fbkweb/variableAnnuityTopTen.do","resizable=false,toolbar=false,scrollbars=1");
	//window.open(getJunction() + "/fbkweb/benchmarkDefinitions.do","benchmarkWin","height=800px,width=650px,resizable=false,toolbar=false,scrollbars=2");
}

function  openBenchmarkWindow()
{
	centerWindowOpener(800,650,"benchmarkWin",getJunction() + "/fbkweb/benchmarkDefinitions.do","resizable=false,toolbar=false,scrollbars=1");
	//window.open(getJunction() + "/fbkweb/benchmarkDefinitions.do","benchmarkWin","height=800px,width=650px,resizable=false,toolbar=false,scrollbars=1");
}

function openGlossary()
{
	centerWindowOpener(800,650,"benchmarkWin",getJunction() + "/fbkweb/glossary.do" ,"resizable=false,toolbar=false,scrollbars=1");
	//window.open(getJunction() + "/fbkweb/glossary.do","glossaryWin","height=800px,width=650px,resizable=false,toolbar=false,scrollbars=1");
}

function openRisksInvesting()
{
	centerWindowOpener(800,650,"benchmarkWin",getJunction() + "/fbkweb/riskOfInvesting.do" ,"resizable=false,toolbar=false,scrollbars=1");
	//window.open(getJunction() + "/fbkweb/riskOfInvesting.do","glossaryRisks","height=800px,width=650px,resizable=false,toolbar=false,scrollbars=1");
}

function gotoRSS()
{
	centerWindowOpener(600,800,"benchmarkWin","http://pricefeeds.troweprice.com/MFTWeb/login.fd?v_linkcomp=FBK&linkplmt=HR&v_link=RSS" ,"resizable=false,toolbar=false,scrollbars=1");
	//window.open("http://pricefeeds.troweprice.com/MFTWeb/login.fd","rssWin","height=600px,width=800px,resizable=false,toolbar=false,scrollbars=1");
}

function centerWindowOpener(windowHeight, windowWidth, windowName, windowUri, features)
{
    var centerWidth = (window.screen.width - windowWidth) / 2;
    var centerHeight = (window.screen.height - windowHeight) / 2;

    newWindow = window.open(windowUri, windowName, 'resizable=0,width=' + windowWidth + 
        ',height=' + windowHeight + 
        ',left=' + centerWidth + 
        ',top=' + centerHeight +
        ',' + features);

    newWindow.focus();
    return newWindow.name;
}

function setCookie(name, value, path, expires, domain, secure) {
	//alert("in set cookie, name = " + name + "value = " + value);
    /*var curCookie = name + "=" + escape(value) +
      ((path) ? "; path=" + path : "") +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
    document.cookie = curCookie;*/
    
     		document.cookie = name + "=" + escape(value) +
	        ((expires) ? "; expires=" + expires.toGMTString() : "") +
	        ((path) ? "; path=" + path : "") +
	        ((domain) ? "; domain=" + domain : "") +
	        ((secure) ? "; secure" : "");
	        //alert("in set cookie, name = " + name + "value = " + value);
}

function getCookie(name) {
	//alert("in Get cookie, name = " + name);
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/* hides all other open tooltips when opening a new tooptip */
function hideAllTooltips(activeTooltip)
{

	var tooltips = YAHOO.util.Dom.getElementsByClassName("fb2tooltip");
	for(var i=0; i<tooltips.length; i++)
	{
		tooltips[i].style.display='none';
	}
}		

function gotoCustomView(action)
{
	var url = String(document.location);
	var customViewURL = "";
	
	if(url.match(/localhost/))
	{
		customViewURL = getJunction() + "/fbkweb/" + action;
	}
	else if( url.match(/www3dev/))
	{
		customViewURL = "https://www3dev.troweprice.com" + getJunction() + "/fbkweb/" + action;
	}
	else if(url.match(/www3qual/))
    {
		customViewURL = "https://www3qual.troweprice.com" + getJunction() + "/fbkweb/" + action;
    }
	else
	{
		customViewURL = "https://www3.troweprice.com" + getJunction() + "/fbkweb/" + action;
    }
    
    window.top.location = customViewURL;
}

function gotoAccountAccessLogin()
{
	var url = String(document.location);
	var loginURL = "";
	if(url.match(/localhost/))
	{
		loginURL = "https://www3dev.troweprice.com/";
	}
	else if( url.match(/www3dev/))
	{
		loginURL = "https://www3dev.troweprice.com/";
	}
	else if(url.match(/www3qual/))
    {
		loginURL = "https://www3qual.troweprice.com/";
    }
	else
	{
		loginURL = "https://www3.troweprice.com/";
    }

    loginURL += "aaweb1/accountAccess/index.do";
    
	window.top.location = loginURL;
}

function gotoAccountAccessLogout()
{
	var url = String(document.location);
	var loginURL = "";
	if(url.match(/localhost/))
	{
		loginURL = "https://www3dev.troweprice.com/";
	}
	else if( url.match(/www3dev/))
	{
		loginURL = "https://www3dev.troweprice.com/";
	}
	else if(url.match(/www3qual/))
    {
		loginURL = "https://www3qual.troweprice.com/";
    }
	else
	{
		loginURL = "https://www3.troweprice.com/";
    }

    loginURL += "aaweb1/accountAccess/logout.do";
    
	window.top.location = loginURL;
}

function gotoFBKTab(tab,ticker)
{

	var url = getFb2Domain() + getJunction() + "/fbkweb";
	if(tab == null || tab == "") tab = snapshot;
	
	if(tab == "snapshot") url += "/snapshot.do";
	if(tab == "objective") url += "/objective.do";
	if(tab == "performance") url += "/performance.do";
	if(tab == "composition") url += "/composition.do";
	if(tab == "management") url += "/management.do";
	if(tab == "expenses") url += "/expenses.do";
	if(tab == "compare") url += "/compare.do";
	
	url += "?ticker=" + ticker;
	
	window.top.location = url;

}
