function openPopup(u){
var h=455
var w=250
var x=20
var y=40
var scrollbar = 'scrollbars=yes';
if(openPopup.arguments.length==5){
w=openPopup.arguments[1]
h=openPopup.arguments[2]
x=openPopup.arguments[3]
y=openPopup.arguments[4]
scrollbar = 'scrollbars=no';
if (screen.width <= 800){
	y=19;
	x=309;
}
}
if(openPopup.arguments.length==3){
w=openPopup.arguments[1]
h=openPopup.arguments[2]
}
window.open(u,'infowindow','width='+w+',height='+h+',left='+x+',top='+y+',location=no,resizable=yes,menubar=no,status=no,toolbar=no,' + scrollbar)
}

function showPiePopUp (header, odc, camw, top1, top2, top3, positionX, positionY){

	layer = 'imagepopup';
	if(header){
		document.getElementById('head').innerHTML = header;
	}
	if(odc){
		document.getElementById('ODC').innerHTML = odc;
		this.odc = parseFloat(odc);
		styleFixer(this.odc, 'ODC', 'odcimg');
	}
	if(camw){
		document.getElementById('CAMW').innerHTML = camw;
	}
	if(top1){
		document.getElementById('top1').innerHTML = top1;
		this.top1 = parseFloat(top1);
		styleFixer(this.top1, 'top1', 'top1img');
	}
	if(top2){
		document.getElementById('top2').innerHTML = top2;
		this.top2 = parseFloat(top2);
		styleFixer(this.top2, 'top2', 'top2img');

	}
	if(top3){
		document.getElementById('top3').innerHTML = top3;
		this.top3 = parseFloat(top3);
		styleFixer(this.top3, 'top3', 'top3img');
	}

	document.getElementById(layer).style.display="block";

	if(positionX){
		document.getElementById(layer).style.left = getAbsoluteLeft(document.getElementById('piechart'))+parseInt(positionX)-48+"px";
	}
	if(positionY){
		document.getElementById(layer).style.top = getAbsoluteTop(document.getElementById('piechart'))+parseInt(positionY)-document.getElementById(layer).offsetHeight+"px";
	}
}

function hidePiePopUp(){
	layer = 'imagepopup';
	document.getElementById(layer).style.display="none";
}


styleFixer = function (value, textId, imgId) {

    if (value<0)    {
        document.getElementById(textId).className = 'red';
        var img = document.getElementById(imgId);
        if(img) {
            var src = img.src.replace(/[^\/]+.gif$/, 'down-arrow.gif');            
            img.src = src;
        }
    }
    else{
        document.getElementById(textId).className = 'green';
        var img = document.getElementById(imgId);
        if(img) {
            var src = img.src.replace(/[^\/]+.gif$/, 'greenarrowup.gif');            
            img.src = src;
        }
    }
}

getAbsoluteLeft = function(o) {    
	oLeft = o.offsetLeft	
	while(o.offsetParent!=null) {	
		oParent = o.offsetParent	
		oLeft += oParent.offsetLeft	
		o = oParent	
	}	
	return oLeft	
}
	
getAbsoluteTop = function (o) {	
	oTop = o.offsetTop	
	while(o.offsetParent!=null) {	
		oParent = o.offsetParent	
		oTop += oParent.offsetTop	
		o = oParent	
	}	
	return oTop	
}

function popLargerWin(u){
var wlarge=window.open(u,'infowindowlarge','width=617,height=380,left=080,top=080,location=no,resizable=yes,menubar=no,status=no,toolbar=no,scrollbars=yes,fullscreen=no')
wlarge.focus()
}
function openNua(u){window.open(u,'newWindow','width=680,height=500,resizable=yes,scrollbars=yes')}
function sigNewsFormChanged(f,u){
var d=f.days.options[f.days.selectedIndex].value
var l=f.filter.options[f.filter.selectedIndex].value
location.href=u+"&days="+d+"&name=sig&category="+l

}
function buildURL(u,ta){top.location.href=u+ta.value}
function buildURLTargetBottom(u,ta){location.href=u+ta.value}
function buildURLPopup(u,ta){
var aU=u+ta.value
if(buildURLPopup.arguments.length==4) openPopup(aU,buildURLPopup.arguments[2],buildURLPopup.arguments[3])
else if(buildURLPopup.arguments.length==6) openPopup(aU,buildURLPopup.arguments[2],buildURLPopup.arguments[3],buildURLPopup.arguments[4],buildURLPopup.arguments[5])
else openPopup(aU)
}
function buildCompareURL(u,p_sS1,p_sS2,p_sS3,p_sS4,p_sS5){
var valid=true
var symbols="";
if((p_sS1==null||p_sS1.length<1)&&
(p_sS2==null||p_sS2.length<1)&&
(p_sS3==null||p_sS3.length<1)&&
(p_sS4==null||p_sS4.length<1)&&
(p_sS5==null||p_sS5.length<1)){
alert("Please enter at least one symbol.")
return
}
if(containValidCharacterInvalidPosition(p_sS1) ||
   containValidCharacterInvalidPosition(p_sS2) ||
   containValidCharacterInvalidPosition(p_sS3) ||
   containValidCharacterInvalidPosition(p_sS4) ||
   containValidCharacterInvalidPosition(p_sS5)
)
{
alert("The symbol you have entered contains an invalid character. If you are entering a symbol for a preferred stock, use a forward slash (\"/\"). Otherwise, check the information and try again, or use Symbol Lookup to see if a valid symbol exists for the company you are trying to find.")
return
}
if (isForeignSymbol(p_sS1))
{
	symbols=p_sS1+ ", " ;
	valid=false
}
if (isForeignSymbol(p_sS2))
{
	symbols=symbols + p_sS2 + ", " ;
	valid=false
}
if (isForeignSymbol(p_sS3))
{
	symbols=symbols + p_sS3 + ", ";
	valid=false
}
if (isForeignSymbol(p_sS4))
{
	symbols=symbols + p_sS4+ ", ";
	valid=false
}
if (isForeignSymbol(p_sS5))
{
   symbols=symbols + p_sS5+ ", ";
	valid=false
}

if (valid==false){
	var list  =  symbols.substring(0, symbols.length -2);
	alert(list + ". The symbol you entered is unrecognized or contains invalid characters.  If you are entering a symbol for a preferred stock, use a forward slash (\"/\") instead of a period (\"\.\"). Otherwise, check the information and try again, or use Symbol Lookup to see if a valid symbol exists for the company you are trying to find.");
	return
}
location.href=u+p_sS1+","+p_sS2+","+p_sS3+","+p_sS4+","+p_sS5
}

function buildCompetitorsURL(u,p_sS1)
{
	var valid=true
	var symbols="";
	if(p_sS1==null||p_sS1.length<1)
	{
		alert("Please enter exactly one symbol.");
		return;
	}
	if(containValidCharacterInvalidPosition(p_sS1))
	{
		alert("The symbol you entered contains an invalid character. If you are entering a symbol for a preferred stock, use a forward slash (\"/\").  Otherwise, check the information and try again, or use Symbol Lookup to see if a valid symbol exists for the company you are trying to find");
		return;
	}
	if (isForeignSymbol(p_sS1))
	{
		symbols=p_sS1+ ", " ;
		valid=false;
	}
	if (valid==false)
	{
		var list  =  symbols.substring(0, symbols.length -2);
		alert(list + ". The symbol you entered is unrecognized or contains invalid characters. If you are entereing a symbol for a preferred stock, use a forward slash (\"/\") instead of a period (\"\.\"). Otherwise, check the information and try again, or use the Symbol Lookup to see if a valid symbol exists for the company you are trying to find.");
		return;
	}
	location.href=u+p_sS1;
}

function displayDescription(d){
dw = window.open("", "description",'width=500,height=200,resizable=yes,scrollbars=yes')
dw.document.close()
dw.document.open()
dw.document.write(d)
dw.document.title = 'Company Description'
dw.focus()
}

function trimValue(str)
{
	str = this != window? this : str;
	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}


function onFormSubmit(form){
var valid=true
var symbols;
if (form==null||form.symbols==null){
symbols = document.getElementById('symbols')
}
else{symbols = form.symbols}

if(symbols != null){
	symbols.value = trimValue(symbols.value); 
if(symbols.value.length<1){
alert("Please enter a symbol.")
valid=false
}
else if(symbols==""||symbols==null){
alert("Please enter a symbol first.")
valid=false
}
else if(symbols.value.indexOf(" ")!=-1){
alert("Please enter only one symbol.")
valid=false
}
else if (isForeignSymbol(symbols.value))
{
alert(symbols.value + ". The symbol you entered is unrecognized or contains invalid characters. If you are entering a symbol for a preferred stock, use a forward slash (\"/\") instead of a period (\"\.\"). Otherwise, check the information and try again, or use Symbol Lookup to see if a valid symbol exists for the company you are trying to find.");
valid=false
}
else{
var i = 0
if(symbols.value.length==1){
if(symbols.value.charAt(0)=="-"||
symbols.value.charAt(0)=="/"||
symbols.value.charAt(0)=="."){
valid=false;
}
}
if(symbols.value.charAt(0)=="/"){valid=false};

while (i < symbols.value.length && valid == true){
if(!(isValidCharacter(symbols.value.charAt(i)))) {
valid=false
}
i++
}
if(containValidCharacterInvalidPosition(symbols.value)) {
valid=false
}
if(valid==false){
alert("The symbol you entered contains an invalid character. If you are entering a symbol for a preferred stock, use a forward slash (\"/\").  Otherwise, check the information and try again, or use Symbol Lookup to see if a valid symbol exists for the company you are trying to find.")
}}
}
if(valid==false && form!=null && form.symbols!=null){
form.symbols.select()
form.symbols.focus()
}
return valid
}

function isValidCharacter(character)
{
if((character >= "a" &&
character <= "z") || 
(character >= "A" &&
character <= "Z") ||
(character >= "0" &&
character <= "9") ||
character == "." ||
character == "-" ||
character == "/") {
return true
}
return false
}

function containValidCharacterInvalidPosition(symbolText)
{
for(var i = 0; i < symbolText.length; ++i)
{
if(symbolText.charAt(i) == "-" && i > 0)
{
return true
}
}		
return false
}

function isForeignSymbol(symbolText)
{
for(var i = 0; i < symbolText.length; ++i)
{
if(symbolText.charAt(i) == "." && i > 0)
{
return true
}
}		
return false
}

function handleKeyPress(submitButton, e){
var characterCode
if(e && e.which){
e = e
characterCode = e.which
}
else{
e = e
characterCode = e.keyCode
}	 
if(characterCode == 13){
submitButton.click()
return false
}
if(characterCode == 8){
return true
}
if(!isValidCharacter(String.fromCharCode(characterCode))){
return false
}
return true
}

function dn(){return(document.domain!=null&&document.domain.match(/^.*(\.fmr.com)$/))?RegExp.$1:'.fidelity.com'}

function getCookie(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=dc.indexOf(";",begin)
if(end==-1)end=dc.length
return unescape(dc.substring(begin+prefix.length,end))
}

function deleteCookie(name,path,domain){
path=path?path:'/'
domain=domain?domain:dn()
if(getCookie(name)){
document.cookie=name+"=none"+
((path)?";path="+path:"")+
((domain)?";domain="+domain:"")+
"; expires=Thu, 01-Jan-70 00:00:01 GMT"
}}

function searchArray(ar,str){
for(j=0;j<ar.length;j++)if(ar[j] == str)return true
return false}

var expiry=new Date()
var future=expiry.getTime()+32*24*60*60*1000
expiry.setTime(future)

var rvMax=10
var rvn='rvstk'

// accumulate rv updates in these arrays
// actual writing to cookie is done in commitRV()
var rvSyms=new Array()
var rvPrices=new Array()
var rvDates=new Array()

function rv(sym,price,time){
// at to end of accumulation arrays
rvSyms.push(sym)
rvPrices.push(price)
rvDates.push(time)
}

function commitRV(){
var found=0;
var rvstk;

//find cookie
if(document.cookie){
	var c=document.cookie
	var index=c.indexOf(rvn+"=");
	if(index!=-1){
		index=c.indexOf("=",index)+1;//first character
		var endstr=c.indexOf(";",index);
		if(endstr==-1)endstr=c.length;//last character
		rvstk=unescape(c.substring(index, endstr));
		found=1;
	}
	else found=0;
}
//parse, build arrays
var syms=new Array();
var prices=new Array();
var dates=new Array();
if(1==found && rvstk != 'none')
{
	var pipes = rvstk.split('|');
	syms = pipes[0].split('~');
	prices = pipes[1].split('~');
	dates = pipes[2].split('~');
}//else arrays r empty

//add data from cookie w/ data from rv() calls
//if in list, don't add
var allSyms=new Array();
var allPrices=new Array();
var allDates=new Array();
for(a=0;a<rvSyms.length;a++)
{
	if(!searchArray(syms,rvSyms[a]))
	{
		allSyms.push(rvSyms[a]);
		allPrices.push(rvPrices[a]);
		allDates.push(rvDates[a]);
	}
}

allSyms=allSyms.concat(syms);
allPrices=allPrices.concat(prices);
allDates=allDates.concat(dates);

//trim if 2 many
if(allSyms.length>rvMax) 
{
	allSyms=allSyms.slice(0,rvMax);
	allPrices=allPrices.slice(0,rvMax);
	allDates=allDates.slice(0,rvMax);
}

var cv=escape(allSyms.join("~")+"|"+allPrices.join("~")+"|"+allDates.join("~"));
var nc=rvn+"="+cv+";path=/;domain="+dn()+";expires="+expiry.toGMTString()+";";
document.cookie=nc;
}

deleteCookie('02109POS');
if (getCookie('SC') != null)deleteCookie(rvn)
