var money_register = "http://www.iwon.com/home/partner_registration_form?external=true&return_url=";
var money_home = "/home.html";
var money_cookie_jsp = "/jsp/common/setmoneycookie.jsp";

function FrameThis ()  
{
	if (top.frames.length != 0)  
	{
		top.location = document.URL
    }
}

function getCookie (name) 
{
	var cname = name + "=";
    var clen = document.cookie.length;
    var cbegin = 0;
    while (cbegin < clen) 
	{
		var vbegin = cbegin + cname.length;
        if (document.cookie.substring(cbegin, vbegin) == cname) 
		{ 
			var vend = document.cookie.indexOf (";", vbegin);
            if (vend == -1) vend = clen;
            return unescape(document.cookie.substring(vbegin, vend));
        }
        cbegin = document.cookie.indexOf(" ", cbegin) + 1;      
        if(cbegin == 0) cbegin = clen;
    }
    return null;
}


			// drop down menu navigation
function go(box) 
{
				var val = box.options[box.selectedIndex].value;
				if (val != "") {
					window.location.href = val;
				}
}

function pick(form, box) 
{
	var val = box.options[box.selectedIndex].value;
	if (val != "") 
	{
		form.submit();
	}
}
			
function stripText(oldChar, newChar, str) {
	if (str.indexOf(oldChar) > -1){
		var start = 0;
		var strLen = str.length;
		var oldCharLen = oldChar.length;
		var testRes = -1;
		var tempStr = "";
		var x = 0;
		while (x < 1) {
			oldCharIndex = str.indexOf(oldChar, start);
			if (start < strLen){
				if (tempStr != "") {
					tempStr = tempStr + newChar;
				}	
				if (oldCharIndex != -1) { 
					tempStr = tempStr + str.substring(start, oldCharIndex);
				} else  {
					tempStr = tempStr + str.substring(start, strLen);
					x = 1;
				}
				start = (oldCharIndex + oldCharLen);
			} else {
				x = 1;
			}
		}
		return tempStr;
	} else {
		return str;
	}
}

function get_random () {
   var axel = Math.random() + "";
   var rord = axel * 1000000000000000000;
   return rord;
}

var RMAX=20;
var RANDS = new Array();
for (var i=0; i<RMAX; i++) {
   RANDS[i]=get_random(); 
}

function get_rand (index) {
   return RANDS[index];
}

function SymbolSearchOnClick() {	
	if ( document.symbol_search_form.symbol_search_text.value == "" ) {
		alert("Symbol search box is empty, please enter proper symbols.");
		return false;
	}
	else if ( document.symbol_search_form.symbol_search_text.value.length > 200 ) {
		alert("Symbol search box can't contain more than 200 characters.");
		return false;
	} else {
		sl = document.symbol_search_form.symbol_search_select.selectedIndex;
			
		if (sl != -1)  {
			document.cookie = "search_item=" + escape(document.symbol_search_form.symbol_search_select.options[sl].value);
			if ( document.symbol_search_form.symbol_search_select.options[sl].value == "short" ) {
				document.symbol_search_form.action = "/jsp/qt/short.jsp";
				document.symbol_search_form.submit();
			} else if ( document.symbol_search_form.symbol_search_select.options[sl].value == "fundamentals" ) {
				document.symbol_search_form.action = "/jsp/qt/fund.jsp";
				document.symbol_search_form.submit();
			} else if ( document.symbol_search_form.symbol_search_select.options[sl].value == "long" ) {
			    document.symbol_search_form.action = "/jsp/qt/long.jsp";
				document.symbol_search_form.submit();
			} else if ( document.symbol_search_form.symbol_search_select.options[sl].value == "news" ) {
			    document.symbol_search_form.action = "/jsp/nw/newsheadlinebysymbol.jsp";
			    document.symbol_search_form.submit();
			} else if ( document.symbol_search_form.symbol_search_select.options[sl].value == "chart" ) {
			    document.symbol_search_form.action = "/jsp/ct/bigchart.jsp";
				document.symbol_search_form.submit();
			} else if ( document.symbol_search_form.symbol_search_select.options[sl].value == "research" ) {
			    document.symbol_search_form.action = "/jsp/rs/summary.jsp";
			    document.symbol_search_form.submit();
			} else if ( document.symbol_search_form.symbol_search_select.options[sl].value == "at_a_glance" ) {
			    document.symbol_search_form.action = "/jsp/qt/ataglance.jsp?time=0";
			    document.symbol_search_form.submit();
			} else if ( document.symbol_search_form.symbol_search_select.options[sl].value == "board" ) {
			    document.symbol_search_form.action = "/jsp/common/board.jsp?";
			    document.symbol_search_form.submit();
			} else if ( document.symbol_search_form.symbol_search_select.options[sl].value == "5day" ) {
			    document.symbol_search_form.action = "/jsp/rs/quoteview.jsp?";
			    document.symbol_search_form.submit();
			}
		}
	}
	return true;
}

function getSelectedItem() {
}

function setSymbolSearch(value) {
	for ( var i = 0; i < document.symbol_search_form.symbol_search_select.options.length; i++ )
	{
		if ( value == document.symbol_search_form.symbol_search_select.options[i].value )
		{
			document.symbol_search_form.symbol_search_select.selectedIndex = i; 
			break;
		}			
	}
}


function setCookie (name, value) {  
	var argv = setCookie.arguments;  
	var argc = setCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
		((path == null) ? "" : ("; path=" + path)) +  
		((domain == null) ? "" : ("; domain=" + domain)) +    
		((secure == true) ? "; secure" : "");
}

function deleteCookie (name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = getCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function getUserNum() {
	var user_num;
	
	user_num = getCookie("user_num");

	if (user_num != null)
		return user_num;
	else
		return "";
}

function isUserLogin() {
	if ( getUserNum() != "" )
	{
		return true;
	}	
	else
		return false;
}

function isUserHasPortfolioCookie() {
	if ( getCookie("money_pf_names") == null )
		return false;

	if ( getCookie("money_pf_ids") == null )
		return false;

	return true;
}

function isUserPersonalized() {
	if (getCookie("money_ps") == null)
		return false;
	
	return true;	
}

function forceLogin(url) {
	if ( getUserNum() == "" )
	{
		window.location = money_register + url;
	}
}

function frontpage_autologin() {
	if ( isUserLogin() && !isUserHasPortfolioCookie() )
	{
		var exp = new Date(); 
		
		window.location = money_cookie_jsp + "?time=" + exp.getTime();	
	}
}

function openGloss() {	
	window.open('http://www.iwon.com/home/money/gloss','wndw','WIDTH=400,HEIGHT=450,scrollbars=yes');
}

function eMail_Friend( width, height ) {
  	 var refer_page_url = escape(document.URL);
	 var http_path = "http://www.iwon.com/bd.redir?redir=http://mailit.iwon.com/emailarticle/EmailArticle.jsp&alias=/alias/emailarticle/EmailArticle";
	 var refer_page_title = escape(document.title);
	 var send_jsp = http_path + "&AU=" + refer_page_url + "&AT=" + refer_page_title;
	 var xposition=0; 
	 var yposition=0;
	 var browser_name = navigator.appName;
	 if (browser_name.indexOf("WebTV") != -1) { 
	 	alert('Email-This-Page-to-a-Friend not supported for WebTV. We apologize for any inconvenience.');
		return;
	 }
	 if (parseInt(navigator.appVersion) >= 4 ){
		xposition = (screen.width - width) / 2;
		yposition = (screen.height - height) / 2;
	}
	args = "width=" + width + "," + "height=" + height + "," + "location=0," + "menubar=0," + "resizable=1," + "scrollbars=1," + "status=0," + "titlebar=0," + "toolbar=0," + "hotkeys=0," + "screenx=" + xposition + "," + "screeny=" + yposition + "," + "left=" + xposition + "," + "top=" + yposition;

  	window.open( send_jsp ,"eMail_popup", args);
  }
var emailUpdate="";
function emailUpdatePopup(pageToLoad,winName,width,height,center) {
	xposition=0; yposition=0;
	if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
		xposition = (screen.width - width) / 2;
		yposition = (screen.height - height) / 2;
	}
	args = "width=" + width + "," + "height=" + height + "," + "location=0," + "menubar=0," + "resizable=0," + "scrollbars=0," + "status=0," + "titlebar=0," + "toolbar=0," + "hotkeys=0," + "screenx=" + xposition + "," + "screeny=" + yposition + "," + "left=" + xposition + "," + "top=" + yposition;
	window.open(pageToLoad,winName,args);
	return null;
 }

function launchjagfn(ID) {
  window.open("http://www.jagfn.com/images/webcast/specmovie.cfm?affil=" + ID,"jagsetup","height=375,width=270,resizable");
}

function launchsplash(ID) {
  window.open("http://www.jagfn.com/images/webcast/splash.cfm?affil=" + ID,"splash","height=480,width=750,resizable");
}
// ---- from ads.js -----------------------------
var adSite1 = "http://ads.iwon.com";
var adSite2 = "http://ads2.iwon.com";
var pageIDRand = Math.round(Math.random() * 10000000000) + "";

var re;
re = /\./g;


function AdInfo(pct, width, height, aamsz, site, area, pos) {
	this.pct = pct;
	this.width= width;
	this.height= height;
	this.aamsz = aamsz;
	this.site= site;
	this.area= area;
	this.pos = pos;
}


adArry = new Object();
adArry.IWON_MONEY_TOP 			=[new AdInfo(50,468,60,"468x60","iwon","money","top"),
					  new AdInfo(101,728,90,"728x90","iwon","money","top") ];
adArry.IWON_MONEYMARKET_TOP 		=[new AdInfo(50,468,60,"468x60","iwon","money.market","top"),
					  new AdInfo(101,728,90,"728x90","iwon","money.market","top") ];
adArry.IWON_MONEYPORTFOLIOMYMONEY_TOP	=[new AdInfo(50,468,60,"468x60","iwon","money.portfolio.mymoney","top"),
					  new AdInfo(101,728,90,"728x90","iwon","money.portfolio.mymoney","top") ];
adArry.IWON_MONEYNEWS_TOP 		=[new AdInfo(50,468,60,"468x60","iwon","money.news","top"),
					  new AdInfo(101,728,90,"728x90","iwon","money.news","top") ];
adArry.IWONREUTERS_MONEYNEWSRT_TOP	=[new AdInfo(50,468,60,"468x60","iwon.reuters","money.news.rt","top"),
					  new AdInfo(101,728,90,"728x90","iwon.reuters","money.news.rt","top") ];
adArry.IWON_MONEYPORTFOLIO_TOP		=[new AdInfo(50,468,60,"468x60","iwon","money.portfolio","top"),
					  new AdInfo(101,728,90,"728x90","iwon","money.portfolio","top") ];
adArry.IWON_MONEYRESEARCH_TOP		=[new AdInfo(50,468,60,"468x60","iwon","money.research","top"),
					  new AdInfo(101,728,90,"728x90","iwon","money.research","top") ];
adArry.IWONZACKS_MONEYRESEARCHZACKS_TOP	=[new AdInfo(50 ,468,60,"468x60","iwon.zacks","money.research.zacks","top"),
					  new AdInfo(101,728,90,"728x90","iwon.zacks","money.research.zacks","top") ];
adArry.IWONCCBN_MONEYRESEARCH_TOP	=[new AdInfo(50,468,60,"468x60","iwon.ccbn","money.research","top"),
					  new AdInfo(101,728,90,"728x90","iwon.ccbn","money.research","top") ];
adArry.IWONVALIDEA_MONEYRESEARCH_TOP	=[new AdInfo(50,468,60,"468x60","iwon.validea","money.research","top"),
					  new AdInfo(101,728,90,"728x90","iwon.validea","money.research","top") ];


function doAd() {
        <!-- Hide from old browsers
        window.name="parentwin";
	vartype = typeof doAdData;
	if (vartype != "undefined") {
		if (doAdData.write == true ) {
        		random = Math.round(Math.random() * 10000000000);
        		parms = "acc_random=" + random + "/site=" + doAdData.site + "/area=" + doAdData.area + "/aamsz=" + doAdData.size + "/pageID=" + pageIDRand;
			document.write("<table align=left cellpadding=6 cellspacing=0 border=0 bgcolor=ffffff width=" + (4 + doAdData.width)  + " height=" + (4 + doAdData.height) + "><tr><td><table width=100% cellpadding=2 cellspacing=0 border=0 bgcolor=6699ff><tr><td>");
			if (navigator.appName.indexOf("Netscape") > -1 ) {
        			document.write('<SCR');
        			document.write('IPT SRC="' + adSite1 + '/jserver/' + parms + '">');
        			document.write('</SCR');
        			document.write('IPT>');
			} else {
				writeAdIFrame(doAdData.width, doAdData.height, doAdData.size, doAdData.site, doAdData.area, doAdData.pos);
			}
			document.write("</td></tr></table></td></tr></table>");
		}
	}
        // End Hide -->
}

function getAdParms(site,area,pos) {
	<!-- Hide from old browsers
	var s,a;
	s = site.replace(re,"");
	a = area.replace(re,"");
	pct = Math.round(Math.random() * 100);
	adInfo = adArry[s+'_'+a+'_'+pos];
	for (i=0; i<adInfo.length;i++) {
		if (pct < adInfo[i].pct) {
			return adInfo[i];
		}
	}
	// End Hide -->
}


function writeAd(width, height, size, site, area, pos) {
        <!-- Hide from old browsers
        random = Math.round(Math.random() * 10000000000);
       	parms = "acc_random=" + random + "/site=" + site + "/area=" + area + "/aamsz=" + size + "/pos=" + pos + "/file=2/pageID=" + pageIDRand;
	if (navigator.appName.indexOf('Netscape') > -1 || (navigator.appName.indexOf('Internet Explorer') > -1 && parseInt(navigator.appVersion) >= 4)) {
        	document.write('<SCR' + 'IPT SRC="' + adSite1 + '/jserver/' + parms + '"></SCR' + 'IPT>');
	} else {
        	document.write('<IFRAME SRC=' + adSite1 + '/hserver/' + parms );
        	document.write(' NORESIZE SCROLLING=NO HSPACE=0 VSPACE=0 FRAMEBORDER=0 border=0 MARGINHEIGHT=0 MARGINWIDTH=0 WIDTH=' + width + ' HEIGHT=' + height + '>');
        	document.write('</IFRAME>');
	}
        // End Hide -->
}
function writeAdtoproll(width, height, size, site, area, pos) {
        <!-- Hide from old browsers
        random = Math.round(Math.random() * 10000000000);
       	parms = "acc_random=" + random + "/site=" + site + "/area=" + area + "/aamsz=" + size + "/pos=" + pos + "/pageID=" + pageIDRand;
	if (navigator.appName.indexOf('Internet Explorer') > -1 && parseInt(navigator.appVersion) >= 4) {
        	document.write('<SCR' + 'IPT SRC="' + adSite1 + '/jserver/' + parms + '"></SCR' + 'IPT>');
	} else {
	}
        // End Hide -->
}

function writeAdIFrame(width, height, size, site, area, pos) {
        <!-- Hide from old browsers
        window.name="parentwin";
        random = Math.round(Math.random() * 10000000000);
        parms = "acc_random=" + random + "/site=" + site + "/area=" + area + "/aamsz=" + size + '/pos=' + pos + "/pageID=" + pageIDRand;
        document.write('<IFRAME SRC=' + adSite1 + '/hserver/' + parms );
        document.write(' NORESIZE SCROLLING=NO HSPACE=0 VSPACE=0 FRAMEBORDER=0 border=0 MARGINHEIGHT=0 MARGINWIDTH=0 WIDTH=' + width + ' HEIGHT=' + height + '>');
        document.write('</IFRAME>');
        // End Hide -->
}

function writeAdScriptSrc(width, height, size, site, area, pos) {
        <!-- Hide from old browsers
        window.name="parentwin";
        random = Math.round(Math.random() * 10000000000);
        target = "/site=" + site + "/area=" + area + "/aamsz=" + size + "/pageID=" + pageIDRand;
        document.write('<SCR' + 'IPT SRC="' + adSite1 + '/jserver/acc_random=' + random + target + '"></SCR' + 'IPT>');
        // End Hide -->
}

function writeAdHrefImg(width,height,site,area,pos) {
        <!-- Hide from old browsers
        window.name="parentwin";
        r = Math.round(Math.random() * 10000000000);
        parms = "/acc_random=" + r + "/site=" + site + "/area=" + area + "/aamsz=" + width + "x" + height + "/pos=" + pos + "/ord=" + r + "/pageID=" + pageIDRand;
        document.write('<a href="' + adSite2 + '/accipiter/adclick' + parms + '"><img src=' + adSite2 + '/accipiter/iserver'+ parms + ' border=0 width=' + width + ' height=' + height + ' align=absmiddle></a>');
        // End Hide -->
}

