$import("com.dowjones.mouse")
$import("com.dowjones.utils.objDimensions")
$import("com.dowjones.utils.SimpleDateFormat")

com.dowjones.rolloverQuotes={
	suppress:(navigator.userAgent.indexOf('MSIE 5.23; Mac')>-1),useIframe:(navigator.userAgent.toLowerCase().indexOf('safari')==-1&&navigator.userAgent.indexOf('Mac')==-1),inProgress:false,inProgressTimer:null,attempts:0,rolloverParent:null,type:"",symbol:"",timer:null,chartPrefix:"http://chart.bigcharts.com/custom/wsj-com/charts/commodities/chart.asp?size=2&style=2101&type=256&mocktick=1",container:null,
	containerDoc:function(){
		var o=null
		if(this.useIframe){
			if(typeof document.frames!='undefined'){
				o=document.frames['rqTip'].document
			}else if(typeof com.dowjones.rolloverQuotes.container.contentDocument!='undefined'){
				o=$('rqTip').contentDocument
			}else if(typeof com.dowjones.rolloverQuotes.container.contentWindow!='undefined'){
				o=$('rqTip').contentWindow
			}
		}else{
			o=document
		}
		return o
	},
	containerBody:function(){;return (this.useIframe)?((typeof this.containerDoc()=='object')?this.containerDoc().body:this.containerDoc()):this.container;},
	createPanel:function(){
		if(this.useIframe){
			this.container=document.createElement('iframe')
			this.container.src='/static_html_files/blank.htm'
			this.container.marginWidth='0'
			this.container.marginHeight='0'
			this.container.hspace='0'
			this.container.vspace='0'
			this.container.frameBorder='0'
			this.container.scrolling='no'
		}else{
			this.container=document.createElement('div')
		}
		this.container.id='rqTip'
		this.container.style.display='none'
		this.container.style.margin='0px'
		this.container.style.padding='0px'
		this.container.style.borderColor='#000'
		this.container.style.borderStyle='solid'
		this.container.style.borderWidth='1px'
		this.container.style.position='absolute'
		this.container.style.left='0px'
		this.container.style.top='0px'
		this.container.style.width='250px'
		this.container.style.height='1px'
		document.body.appendChild(this.container)
	},
	inPopup:function(){;return (com.dowjones.mouse.x>com.dowjones.utils.objDimensions.left(this.container)&&com.dowjones.mouse.x<(com.dowjones.utils.objDimensions.left(this.container)+com.dowjones.utils.objDimensions.width(this.container))&&com.dowjones.mouse.y>com.dowjones.utils.objDimensions.top(this.container)&&com.dowjones.mouse.y<(com.dowjones.utils.objDimensions.top(this.container)+this.containerBody().scrollHeight));},
	show:function(n,s,t){
		if(this.suppress){;return true;}
		t=(t)?t:'usstock'
		this.rolloverParent=n
		this.symbol=s
		this.type=t
		window.clearTimeout(this.timer)
		if($('rqTip')==null)
			this.createPanel()
		if(this.container==null)
			this.container=$('rqTip')
		if(this.useIframe){
			if(this.containerBody()==null){
				this.timer=setTimeout("com.dowjones.rolloverQuotes.showagain()",100)
				return true
			}
		}
		if(this.containerBody().childNodes.length<1){
			if(this.useIframe){;var n=this.containerDoc().createElement('link');n.rel='stylesheet';n.type='text/css';n.href='/j20type.css';this.containerBody().appendChild(n);}
			var n=this.containerDoc().createElement('div');n.id='rqContent';this.containerBody().appendChild(n);
			var n=this.containerDoc().createElement('div');n.id='rqContentHeadlines';this.containerBody().appendChild(n)
			var n=this.containerDoc().createElement('div');n.id='rqPromo';this.containerBody().appendChild(n)
			if(this.useIframe){;this.containerDoc().onmouseover=function(){;parent.window.clearTimeout(parent.com.dowjones.rolloverQuotes.timer);};this.containerDoc().onmouseout=function(){;parent.com.dowjones.rolloverQuotes.hidelater();};}else{;this.containerBody().onmouseover=function(){;window.clearTimeout(com.dowjones.rolloverQuotes.timer);};this.containerBody().onmouseout=function(){;com.dowjones.rolloverQuotes.hidelater();};}
		}
		this.containerDoc().getElementById('rqContent').innerHTML='<div class="p14 bold" style="padding:8px 0px 8px 0px;background-color:#789BCE;color:#FFF;border-bottom:1px solid #000;" align="center">Loading, please wait ...</div>'
		this.containerDoc().getElementById('rqContentHeadlines').innerHTML='<div class="p11" style="background-color:#EFF3F7;padding:10px;"><img src="/img/loading.gif"></div>'
		this.containerDoc().getElementById('rqPromo').style.display='none'
		setTimeout("com.dowjones.rolloverQuotes.adjustheight()",100)
		this.container.style.top=(com.dowjones.utils.objDimensions.top(this.rolloverParent)+com.dowjones.utils.objDimensions.height(this.rolloverParent))+"px"
		this.container.style.left=(com.dowjones.utils.objDimensions.left(this.rolloverParent)+60)+"px"
		this.container.style.display='block'
		this.fetch()
	},
	showagain:function(){;this.show(this.rolloverParent,this.symbol,this.type);},
	hide:function(){;window.clearTimeout(this.timer);if($('rqTip').style.display=='block'){;if(!this.inPopup()){;$('rqTip').style.display="none";window.clearTimeout(this.timer);}else{;this.hidelater();};};},
	hidelater:function(t){;if(this.suppress){;return true;};window.clearTimeout(this.timer);this.timer=setTimeout("com.dowjones.rolloverQuotes.hide()",1000);},
	fetch:function(){
		if(!this.inProgress) {
			this.inProgress=true
			this.attempts=0
			QUOTEJSON={data:null,callback:function(){
				com.dowjones.rolloverQuotes.attempts++
				var chartingURL=((!this.data.etf)?'/quotes/stock_charting.html?symbol='+this.data.s+'&type=usstock&mod=mdc_rolloverquotes':'/public/quotes/etf_charting.html?issue_type=ETF&chartingPage=dynamic&&Symb='+this.data.s+'&mod=mdc_rolloverquotes')
				var div=com.dowjones.rolloverQuotes.containerDoc().getElementById('rqContent')
				if(div){
					div.innerHTML='<div class="p14 bold" style="padding:8px 0px 8px 0px;background-color:#789BCE;color:#FFF;border-bottom:1px solid #000;" align="center">'+this.data.n.toUpperCase()+'</div><div class="p11" style="background-color:#EFF3F7;padding:10px 10px 0px 10px;"><div><img name="rqChartImage" src="'+com.dowjones.rolloverQuotes.chartPrefix+'&symb='+this.data.s+'&time=1dy&frequency=1min&uf=8192" width="220" height="116" border="0" alt="stock chart"/></div><div style="border-top:1px solid #789BCE;padding:2px 0px 3px 0px;"><a id="l1" style="text-decoration: none;color:#F93;" href="'+com.dowjones.rolloverQuotes.chartPrefix+'&symb='+this.data.s+'&time=1dy&frequency=1min&uf=8192" onclick="document.rqChartImage.src=this.href;document.getElementById(\'l1\').style.color=document.getElementById(\'l2\').style.color=document.getElementById(\'l3\').style.color=document.getElementById(\'l4\').style.color=document.getElementById(\'l5\').style.color=\'#0253b7\';document.getElementById(\'l1\').style.color=\'#F93\';return false">1 Day</a> | <a id="l2" style="text-decoration: none;" href="'+com.dowjones.rolloverQuotes.chartPrefix+'&symb='+this.data.s+'&time=10dy&frequency=15min" onclick="document.rqChartImage.src=this.href;document.getElementById(\'l1\').style.color=document.getElementById(\'l2\').style.color=document.getElementById(\'l3\').style.color=document.getElementById(\'l4\').style.color=document.getElementById(\'l5\').style.color=\'#0253b7\';document.getElementById(\'l2\').style.color=\'#F93\';return false">10 Days</a> | <a id="l3" style="text-decoration: none;" href="'+com.dowjones.rolloverQuotes.chartPrefix+'&symb='+this.data.s+'&time=1mon&frequency=1day" onclick="document.rqChartImage.src=this.href;document.getElementById(\'l1\').style.color=document.getElementById(\'l2\').style.color=document.getElementById(\'l3\').style.color=document.getElementById(\'l4\').style.color=document.getElementById(\'l5\').style.color=\'#0253b7\';document.getElementById(\'l3\').style.color=\'#F93\';return false">1 Month</a> | <a id="l4" style="text-decoration: none;" href="'+com.dowjones.rolloverQuotes.chartPrefix+'&symb='+this.data.s+'&time=3mon&frequency=1day" onclick="document.rqChartImage.src=this.href;document.getElementById(\'l1\').style.color=document.getElementById(\'l2\').style.color=document.getElementById(\'l3\').style.color=document.getElementById(\'l4\').style.color=document.getElementById(\'l5\').style.color=\'#0253b7\';document.getElementById(\'l4\').style.color=\'#F93\';return false">3 Months</a> | <a id="l5" style="text-decoration: none;" href="'+com.dowjones.rolloverQuotes.chartPrefix+'&symb='+this.data.s+'&time=1yr&frequency=1day" onclick="document.rqChartImage.src=this.href;document.getElementById(\'l1\').style.color=document.getElementById(\'l2\').style.color=document.getElementById(\'l3\').style.color=document.getElementById(\'l4\').style.color=document.getElementById(\'l5\').style.color=\'#0253b7\';document.getElementById(\'l5\').style.color=\'#F93\';return false">1 Year</a></div><div class="bold" style="border-bottom:1px solid #789BCE;border-top:1px solid #789BCE;padding:3px 0px 2px 0px;margin-bottom:5px;"><img src="/img/loginArrow.gif"/> <a href="'+chartingURL+'" target="_parent">Go to Interactive Charting</a></div><table width="230" cellpadding="0" cellspacing="0" border="0" class="p10" style="color:#333;"><tr><td valign="top" colspan="3">'+com.dowjones.utils.SimpleDateFormat.format(this.data.d,"MM/dd/yy h:mm a")+' EST</td><td valign="top" align="right" style="padding-bottom:5px;">'+this.data.e+'</td></tr><tr><td>Last</td><td align="right">Change</td><td align="right">% Change</td><td align="right">Volume</td></tr><tr><td class="p13 bold" style="color:#000;">'+this.data.l+'</td><td align="right" class="p13 bold change'+((this.data.c.substring(0,1)=="-")?"Neg":"Pos")+'">'+this.data.c+'</td><td align="right" class="p13 bold change'+((this.data.c.substring(0,1)=="-")?"Neg":"Pos")+'">'+this.data.p+'</td><td align="right" class="p13 bold" style="color:#000;">'+this.data.v+'</td></tr></table></div>'
					var div=com.dowjones.rolloverQuotes.containerDoc().getElementById('rqPromo')
					div.innerHTML='<div class="p11" style="background-color:#EFF3F7;padding:5px 10px 10px 10px;"><div style="margin-top:5px;padding:5px 0px 0px 10px;border-top:1px solid #789BCE;background-image: url(/img/orange_bullet.gif);background-repeat: no-repeat;background-position: 0px 10px;"><b>Full Research: </b><a href="/quotes/news.html?type=usstock&symbol='+this.data.s+'&mod=mdc_rolloverquotes" target="_parent">Company News</a> | <a href="/quotes/pr.html?type=usstock&symbol='+this.data.s+'&mod=mdc_rolloverquotes" target="_parent">Press Releases.</a></div><div style="padding-left:10px;background-image: url(/img/orange_bullet.gif);background-repeat: no-repeat;background-position: 0px 5px;"><a href="/pznsetup/sub/pvemail/setup.html?mod=mdc_rolloverquotes" target="_parent">Get Price and Volume Alerts</a><b> on this Stock</b></div></div>'
					div.style.display='block'
				}else{;if(com.dowjones.rolloverQuotes.attempts<5){;setTimeout("QUOTEJSON.callback()",100);}else{;com.dowjones.rolloverQuotes.showagain();};}
			}}
			QUOTEHEADLINEJSON={data:null,callback:function(){
				var temp=""
				if(this.data.length>0){
					temp=temp+'<div class="p11" style="background-color:#EFF3F7;padding:5px 10px 0px 10px;"><div style="border-top:1px solid #789BCE;padding-top:5px;"><b>Latest News:</b></div>'
					for(var a=0;a<this.data.length;a++){;temp=temp+'<div class="p10" style="color:#333;">'+com.dowjones.utils.SimpleDateFormat.format(this.data[a].d,"NNN. d")+'&nbsp;<a href="'+this.data[a].l+'?mod=mdc_rolloverquotes" target="_parent" class="p10">'+this.data[a].h+'</a></div>';}
					temp=temp+'</div>'
				}
				var div=com.dowjones.rolloverQuotes.containerDoc().getElementById('rqContentHeadlines')
				if(div){
					if(QUOTEJSON.data==null){
						com.dowjones.rolloverQuotes.containerDoc().getElementById('rqContent').innerHTML='<div class="p14 bold" style="padding:8px 0px 8px 0px;background-color:#789BCE;color:#FFF;" align="center">Sorry</div>'
						temp='<div class="p11" style="background-color:#EFF3F7;padding:10px;">Unfortunately this service is unavailable temporally, please try later.</div>'
					}
					div.innerHTML=temp
					div.style.display=(this.data.length>0)?'block':'none';
					com.dowjones.rolloverQuotes.adjustheight()
					setTimeout("com.dowjones.rolloverQuotes.adjustheight()",100)
					setTimeout("com.dowjones.rolloverQuotes.adjustheight()",500)
					com.dowjones.rolloverQuotes.inProgress=false
				}else{;if(com.dowjones.rolloverQuotes.attempts<5){;setTimeout("QUOTEHEADLINEJSON.callback()",100);}else{;com.dowjones.rolloverQuotes.showagain();};}
			}}
			SetCookie("CRS","","1m-");SetCookie("CRT","","1m-");$import("/public/quotes/json.html?type="+this.type+"&symbol="+this.symbol+"&r="+new Date().getTime(),'rcq',((this.useIframe)?false:true))
		}else{;window.clearTimeout(this.inProgressTimer);this.inProgressTimer=setTimeout("com.dowjones.rolloverQuotes.fetch()",100);}
	},
	adjustheight:function(){
		this.container.style.height="0px";this.container.style.height=(this.containerBody().scrollHeight)+"px"
		if(((com.dowjones.utils.objDimensions.top(this.container)-((typeof window.pageYOffset!='undefined')?window.pageYOffset:((typeof document.documentElement!='undefined')?document.documentElement.scrollTop:document.body.scrollTop)))+com.dowjones.utils.objDimensions.height(this.container))>((navigator.userAgent.indexOf("Mac")>0)?((typeof window.innerHeight!='undefined')?window.innerHeight:document.body.clientHeight):((typeof window.innerHeight!='undefined')?window.innerHeight:((document.documentElement)?document.documentElement.clientHeight:document.body.offsetHeight)))){
			this.container.style.top=((((navigator.userAgent.indexOf("Mac")>0)?((typeof window.innerHeight!='undefined')?window.innerHeight:document.body.clientHeight):((typeof window.innerHeight!='undefined')?window.innerHeight:((document.documentElement)?document.documentElement.clientHeight:document.body.offsetHeight)))-com.dowjones.utils.objDimensions.height(this.container))+((typeof window.pageYOffset!='undefined')?window.pageYOffset:((typeof document.documentElement!='undefined')?document.documentElement.scrollTop:document.body.scrollTop))-4)+"px"
		}
	}
}
