
// subscribes a function to the window.onload event
// addLoadEvent(openNewsPopup)
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

// returns the width of an element
function getWidth(id){
 		var elm = document.getElementById(id);
 		if (elm==null) return 0;
 		return parseInt(elm.style.clip.width||elm.offsetWidth||elm.style.pixelWidth||elm.clientWidth||0)  
}

// opens popup window
// <a href="page.aspx" onclick="return openWindow(this.href, 'newwindow', 250, 400, true)">link</a>
function openWindow(URL, name, width, height, scrollbar) {
	var strScrollbar = scrollbar ? 'yes' : 'no';
	window.open(URL,name,'scrollbars='+ strScrollbar +',width=' + width + ',height=' + height);
	return false;
}

// checks/unchecks all checkboxes in the form with a particular prefix
function setCheckStates(frmid, prefix, checked)
{
	var frm = document.getElementById(frmid);
        if (frm==null) return false;
	for (var i=0; i<frm.elements.length; i++){
		var e = frm.elements[i];
		if (e.type=='checkbox' && (e.name.indexOf(prefix)>-1)){
			e.checked = checked;
		}		
	}
}


/* TICKER */
Ticker = function()
{
	var me = this;
	this.pause = false;
	this.speed = 2;
	this.source = 'ticker';
	this._obj = '';
	this.offset = 0;
		
	this.start = function()
	{
		this._obj = document.getElementById(this.source);
		if (this._obj==null) return false;
		
		var content = this._obj.innerHTML;
		this._obj.innerHTML = '<table width="100%" cellpadding="0" cellspacing="0" id="news_content"><tr><td nowrap="nowrap" align="right">'+ content +'</td></tr></table>';
		this._obj.style.display = 'block';
		this._obj.offset = getWidth('news_content');
		var width = this._obj.scrollWidth + this._obj.offsetWidth + 600;
		this._obj.offset = getWidth('news_content');
		this._obj.innerHTML = '<table cellpadding="0" cellspacing="0" width="' + width +'" id="news_content"><tr><td align="center" nowrap="nowrap" width=100%>' + content +'</td></tr></table>';
		
		this._obj.onmouseover = function() { me.pause = true; }
		this._obj.onmouseout = function() { me.pause = false; }
		
		this.tick();
	}
	
	// call back
	this.tick = function()
	{	
		if (!me.pause){
			var remainWidth = me._obj.scrollWidth - me._obj.offsetWidth;
			me._obj.scrollLeft += me.speed;
			if (me._obj.scrollLeft >= remainWidth) me._obj.scrollLeft = 0;		
		}
		window.setTimeout(me.tick, 20);
	}
	
}

/* SITEMAP */
function ToggleSMNode(objLink)
{
	// open or close?
	if (objLink.active){
		// close
		objLink.active = false;
		DisplayLink(objLink, 'none');
		objLink.className ='plus';
	}else{
		// open
		objLink.active = true;
		DisplayLink(objLink, 'block');
		objLink.className ='minus';
	}
	return false;
}

function ToggleCatNode(objLink)
{
	// it's open as default
	if (objLink.active==null){
		objLink.active = true;
	}
	
	// open or close?
	if (objLink.active){
		// close
		objLink.active = false;
		DisplayLink(objLink, 'none');
		objLink.className ='plus';
	}else{
		// open
		objLink.active = true;
		DisplayLink(objLink, 'block');
		objLink.className ='minus';
	}
	return false;
}

function DisplayLink(objLink, display)
{
		var objListItem = objLink.parentNode;
		if ((objLink.parentNode.className=='sm-categorytitle') || (objLink.parentNode.className=='sm-title')){
			var objContainerDiv = objLink.parentNode.parentNode
			
			//for (var item in objLink.parentNode.getElementsByTagName('div')){
			//	var objChildDiv = document.getElementById(item);
			//	if (objChildDiv!=null)alert('not null!!')
			//}
			
			for (var strDivID in objContainerDiv.getElementsByTagName('div')){
				var objChildDiv = document.getElementById(strDivID);
				if (objChildDiv!=null){
					objChildDiv.style.display = display;
				}
			}
		} else {
			for (var strChildListID in objListItem.getElementsByTagName('ul')){
				var objChildList = document.getElementById(strChildListID);
				if (objChildList!=null){
					if (objChildList.parentNode == objListItem){
						objChildList.style.display = display;
					}
				}
			}				
		}
}

function goTo() { 

   var sE = null, url; 
   if(document.getElementById) { 
       sE = document.getElementById('navigation_dropdown'); 
   } else if(document.all) { 
       sE = document.all['navigation_dropdown']; 
   } 
   if(sE && (url = sE.options[sE.selectedIndex].value)) { 
       location.href = url; 
   } 
} 



function StockData(tp, pc, nm)
{
  	this.tradingperc = tp; 
	this.percchange = pc;
	this.name = nm;
}

function StockTicker(div)
{
	var me = this;
  this.count = 0;
	this.timer = '';
	this.data = new Array();
  this.obj = document.getElementById(div);
	if (this.obj==null) return false;
		
  this.draw = function()
  {
  	 if (me.count>=me.data.length) me.count = 0;
  		me.obj.innerHTML = "<span>" + me.data[me.count].name + "</span>" + me.data[me.count].tradingperc + ' (' + me.data[me.count].percchange + '%)';
  		me.count++;
  }
		
  this.start = function()
  {
			me.draw();
  		window.setInterval(me.draw,2000);
  }

  this.addData = function(obj) 
	{
			me.data[me.data.length] = obj;
  }
		
}


function disableSearchFields()
{
	document.forms[0].ddlFromMonth.disabled = !(document.forms[0].ddlFromMonth.disabled);
	document.forms[0].ddlFromYear.disabled = !(document.forms[0].ddlFromYear.disabled);
	document.forms[0].ddlToMonth.disabled = !(document.forms[0].ddlToMonth.disabled);
	document.forms[0].ddlToYear.disabled = !(document.forms[0].ddlToYear.disabled);
}


function openProduct(media, title, url, win)
{
	
	if (win=='popup'){
		// webtrends
		dcsTrk('WT.cg_n=A_Content&WT.cg_s=Content item&WT.pc=&WT.pn_gr='+media+'&WT.ti='+title,'','');
		// open the window
		openWindow(url, 'newwindow', 751, 570, true);
	}else{
		//webtrends - opens window
		dcsTrk('WT.cg_n=A_Content&WT.cg_s=Content item&WT.pc=&WT.pn_gr='+media+'&WT.ti='+title,url,win);
	}
	
	return false;
}

