/*
var ns4 = (document.layers)? true:false
var ns6 = (!document.all && document.getElementById)? true:false
var ie4 = (document.all)? true:false
*/

function visitRedirect() {
	var visitTick = document.freerpt.textfield.value;
	document.freerpt.action = "http://members.morningstar.com/prism/stockreport/StockReport_Free_landing.html?referid=A1819&symbol=" + visitTick;
	document.freerpt.submit();
}

function freeRpt(sType) {
	var visitTick;
	if (sType == "Stock") {
		visitTick = document.freeRptStock.stockTicker.value;
		document.freeRptStock.action = "http://members.morningstar.com/prism/stockreport/StockReport_Free_landing.html?referid=A1819&symbol=" + visitTick;
		document.freeRptStock.submit();
	}
	else if (sType == "Fund") {
		visitTick = document.freeRptFund.fundTicker.value;
		document.freeRptFund.action = "http://members.morningstar.com/prism/stockreport/StockReport_Free_landing.html?referid=A1819&symbol=" + visitTick;
		document.freeRptFund.submit();	
	}
	
}

function findarticleRedirect() {
	if (document.forms[2].findarticle.options[document.forms[2].findarticle.selectedIndex].value != "^")
	parent.location = document.forms[2].findarticle.options[document.forms[2].findarticle.selectedIndex].value;
}


function searchRedirect() { 
	var srctext=document.forms[4].srctext.value;
	var linkad="http://search.morningstar.com/se/s97is.dll?Action=FilterSearch&Filter=SocFilter.filt&SrcRadio=1&";
	linkad=linkad+"SrcText="+escape(srctext);
	linkad=linkad+"&hsection=Conversation4";
	window.location=linkad;
}
 
function openPlayerSelection(windowURL) {
if (navigator.appName=="Microsoft Internet Explorer") {
	resizeParam = 0;
} else {
	resizeParam = 1;
}
	windowURL = windowURL + "?hsection=Videos&ck=t";
	playerSelectWin = window.open(windowURL,'playerSelectWin','toolbar=no,titlebar=no,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable='+resizeParam+',width=320,height=480,top=20,left=10');
} 
 

var mstarScreen=null;	//will point to popup window
						//used in function openMstarScreen() and function closeMstarScreen()

//open a popup window for morningstar screen
//iWhich=0 for fund
//iWhich=1 for stock
function openMstarScreen(iWhich)
{
	if (iWhich==0)	//fund
		mstarScreen = window.open('http://screen.morningstar.com/mstarScreens/chooseFundScreen.html?hsection=ToolsFStrat',
				'mstarScreen',
				'menubar=yes,scrollbars=yes,status=yes,width=642,height=325');
	else if (iWhich==1)	//stock
		mstarScreen = window.open('http://screen.morningstar.com/mstarScreens/chooseStockScreen.html?hsection=ToolsSStrat',
				'mstarScreen',
				'menubar=yes,scrollbars=yes,status=yes,width=642,height=325');
	else
		alert("Unknown command");
}

//close the popup window for morningstar screen
function closeMstarScreen()
{
	if (mstarScreen)
	{
		mstarScreen.close();
		mstarScreen=null;
	}
}

//when
function ChangeArchive(form) {
	var v_index = form.value;
	if (v_index != "")
	{	document.forms[2].action = "/doc/article/article_archive";	//"/CoverPages/article_Archive";
		document.forms[2].submit();
	}
	else              
	{ return false;	}	
}

//for the Investing Classroom popup
function openUnivWin(windowName) {
if ((navigator.appVersion.indexOf("Mac") != -1)) {
	newWindow = window.open(windowName, 'newWindow','toolbar=no,location=no,menubar=no,width=475,height=550,scrollbars=yes,resizable=no');
} else {
	newWindow = window.open(windowName, 'newWindow','toolbar=no,location=no,menubar=no,width=494,height=550,top=0,left=0,scrollbars=yes,resizable=no');
}}

function open_TourWin(url) {
	var winargs = "toolbar=no,directories=no,menubar=no,status=no,resizable=yes,scrollbars=yes,width=640,height=570,screenX=200,screenY=100,left=100,top=0";
	var childWin=window.open(url,'Tour',winargs);
}

function open_premTour(url) {
	var winargs = "toolbar=no,directories=no,menubar=no,status=no,resizable=no,scrollbars=no,width=600,height=600,screenX=200,screenY=100,left=100,top=0";
	var childWin=window.open(url,'Tour',winargs);
}

function openWinOptions(url, width, height, toolbar, directories, menubar, status, resizable, scrollbars, screenx, screeny, left, top) {
	var winargs = "toolbar=" + toolbar + ",directories=" + directories + ",menubar=" + menubar + ",status=" + status + ",resizable=" + resizable + ",scrollbars=" + scrollbars + ",width=" + width + ",height=" + height + ",screenX=" + screenx + ",screenY=" + screeny + ",left=" + left + ",top=" + top;
	var childWin=window.open(url,'NewWinOpts',winargs);
}

function openNewWin(url, width, height) {
	var winargs = "toolbar=no,directories=no,menubar=no,status=no,resizable=yes,scrollbars=yes,width=" + width + ",height=" + height + ",screenX=200,screenY=100,left=100,top=0";
	var childWin=window.open(url,'NewWin',winargs);
}

function openWinClassroom(catID) {
    winargs="toolbar=no,scrollbars=yes,status=no,resizable=yes,width=603,height=500";
    if (catID == "Stock")
    	window.open('http://news.morningstar.com/classroom2/home.asp?colId=80&CN=COM','ClassRoom', winargs);  
    else if (catID == "Fund")
    	window.open('http://news.morningstar.com/classroom2/home.asp?colId=76&CN=COM','ClassRoom', winargs);  
    else if (catID == "Bond")
    	window.open('http://news.morningstar.com/classroom2/home.asp?colId=167&CN=COM','ClassRoom', winargs);      	    	
    else if (catID == "Portfolio")
    	window.open('http://news.morningstar.com/classroom2/home.asp?colId=138&CN=COM','ClassRoom', winargs);    
    else if (catID == "Catalog")
    	window.open('http://news.morningstar.com/classroom2/rewards.asp','ClassRoom', winargs);   
    else if (catID == "Handbook")
    	window.open('http://news.morningstar.com/classroom2/handbook.asp','ClassRoom', winargs);
    else
    	window.open('http://news.morningstar.com/classroom2/home.asp?colId=80&CN=COM','ClassRoom', winargs);              	      	    
    return;
}


function ClearField(fid)
{
	document.getElementById(fid).value="";
}

function checkPortFields()
{
	var tickers="";
	var portName = document.getElementById("portName").value;
	if (trim(portName) == "" || portName.length > 20 || portName == "Enter Name") 
	{
		alert ("You must provide a portfolio name with 1-20 characters.");
		return;
	}
	
	for (var i=1; i<=10; i++)
	{
		var ticker=document.getElementById("portTicker"+i).value;
		if (trim(ticker) != "" && trim(ticker) != "Enter Ticker")  
		{
			tickers += ticker;
			tickers += ",";
		}
	}

	if (tickers == "")
	{
		alert ("Portfolio does not include any holdings.");
		return;
	}
	
	document.portEntryForm.action = "http://portfolio.morningstar.com/Newport/Reg/HomepageAddPortfolio.aspx?PortName=" + portName + "&Tickers=" + tickers + "&referid=A2873";
	document.portEntryForm.submit();	
	
	
}

function getXMLHTTP()
{
	var A=null;
	try{
		A=new ActiveXObject("Msxml2.XMLHTTP")
	}
	catch(e){
		try{
			A=new ActiveXObject("Microsoft.XMLHTTP")
		}
		catch(oc){
			A=null
		}
	}
	if(!A && typeof XMLHttpRequest != "undefined") {
		A=new XMLHttpRequest()
	}
	return A
}
		
function setContent(url, symbol)
{
	var xmlhttp=getXMLHTTP();
	xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) 
			{		
				try{	
					document.getElementById(symbol).innerHTML = xmlhttp.responseText;	
				}catch (e){
					}
			}
		}
	xmlhttp.open("GET",url,true);		
	xmlhttp.send(null);
}

function chgPFsection(secNum, keyword, symbol, ad) {
	if (!document.getElementById) return false;
	 	
	for (var i = 1; i <= 3; i++)
	{
		document.getElementById("TabPF"+i).className = "nav1";	
	}
	document.getElementById("TabPF"+secNum).className = "nav1on";
	
	var url = "/hpWebService/GetPersonalFinance.aspx?section=" + secNum +"&keyword=" + keyword +"&ad=" + ad;
	setContent(url, symbol);	
	
}


function chgBlockXml(xml, xsl, ckey, symbol) {
	if (!document.getElementById) return false;
		
	var url = "/hpWebService/GetXmlTransform.aspx?ckey=" + ckey + "&xml=" + xml +"&xsl=" + xsl;
	setContent(url, symbol);		
}


function chgNewsRptLayer(layerNum) {
	if (!document.getElementById) return false;
		
	for (var i = 1; i <= 3; i ++)
	{
		document.getElementById("TabNewsRpt"+i).className = "nav1";			
		document.getElementById("NewsRptLayer"+i).style.display = "none";		
	}
	
	document.getElementById("TabNewsRpt"+layerNum).className = "nav1on";		
	document.getElementById("NewsRptLayer"+layerNum).style.display = "block";
	
}


function chgRptBlock(section) {
	if (!document.getElementById) return false;
	
	node = document.getElementById("NewsRptLayer1");
	if (node.childNodes.length > 0) {
		for (var i=0; i<node.childNodes.length; i++) {
	   		var child = node.childNodes[i];			
			if (child.nodeName.toUpperCase() == "DIV"){ 
	   			var child = node.childNodes[i];
				child.style.display = "none";
			}		
		}
		
	}
	document.getElementById("NewsRptLayer1"+section).style.display="block";
		 			
}

function gotoStockFVChart()
{
	if (sUserType != "S")
	{
		alert ("Fair Value chart is a feature for premium members");
		return;
	}
	
	var linkurl = "http://tools.morningstar.com/charts/Mcharts.aspx?options=V";	
	parent.location = linkurl;
}

var exitURL="";
var refreshURL = unescape(window.location);


function loadAd()
{
	var adcontain1Node = document.getElementById("adcontain1");
	if (adcontain1Node.childNodes.length > 0) {
		for (var i=0; i<adcontain1Node.childNodes.length; i++) {	
			var child =adcontain1Node.childNodes[i];
			if (child.nodeName.toUpperCase() == "DIV") {
				child.innerHTML = document.getElementById("ad1Content").innerHTML;
				document.getElementById("ad1Content").innerHTML = "";
				break;
			}
						
		}			
	}
	
	document.getElementById("AdRectangle").innerHTML = document.getElementById("AdRectangleContent").innerHTML;
	document.getElementById("AdRectangleContent").innerHTML = "";	
	document.getElementById("AdSkyscraper").innerHTML = document.getElementById("AdSkyscraperContent").innerHTML;	
	document.getElementById("AdSkyscraperContent").innerHTML = "";
	
}
function come()
{
	//GET exit URL FOR survey test 6/12/2007
var links = document.links;  
//alert(links.length);  
  for (var i=0; i<links.length; i++) {                 
    var dl = links[i];
    if (dl.onclick == null || dl.onclick=="")
    {
	    dl.onclick = function(){
	   exitURL = this.href;  
	    };
    }    
   }
	setTimeout( "refresh()",  240*1000 );   
 }
function go() {
	//alert(exitURL);
	//alert(vGroup+exitURL);
	if ( exitURL =="" && vGroup=="1")
  {	
     // location.href = 'http://questionweb.com/15494'; }
  window.open('http://www.mstarbisurvey.com/', ''); 
 }		
 
}
function refresh()
{
    //  This version of the refresh function will cause a new
    //  entry in the visitor's history.  It is provided for
    //  those browsers that only support JavaScript 1.0.
    //
    exitURL = refreshURL;
    window.location.href = refreshURL;
}

/*
function AdjustPosition()
{
       var adholderId = "ad1,ad1sm,AdRectangle,AdSkyscraper";
       var adId = "ad1Content,ad1Content,AdRectangleContent,AdSkyscraperContent";
       
       var adholderArray = adholderId.split(",");
       var adArray = adId.split(",");
       
       for(var i = 0; i < adholderArray.length; i++)
       {
       		id  = adholderArray[i];
                obj = findObj(id);
                if (obj != null && obj != "undefined")
                {
			ax = getX(obj);
       			ay = getY(obj);
       			
       			id2 = adArray[i];
       			obj2 = findObj(id2);

		       	obj2.style.left = ax + "px";;
       			obj2.style.top = ay + "px";

       			obj2.style.display = "block";     
       		}
       	}
}



// get position of an object on the page
function getX(obj)
{
	var x = 0;
	var o = obj;
	while (o.offsetParent)
	{
	   x += o.offsetLeft;
	   o = o.offsetParent;
	}
	 return x;
}
function getY(obj)
{
	 var y = 0;
	 var o = obj;
	 while (o.offsetParent)
	 {
	     y += o.offsetTop;
	     o = o.offsetParent;
	 }
	 return y;
}

function findObj(divID) {
    if( ns4) { //Netscape layers
        return document.layers[divID];
    }
    if( ns6 ) { //DOM; IE5, NS6, Mozilla, Opera
        return document.getElementById(divID); 
    }
    if(ie4 ) { //Proprietary DOM; IE4
        return document.all[divID]; 
    }
    if( document[divID] ) { //Netscape alternative
        return document[divID]; 
    }
    return false;
}
*/

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function gotoBMW()
{
	window.location.href ="http://news.morningstar.com/BMWNet/buildout/home.aspx?pgid=hpstockpicks";
}