var tabs= {
showGainers: function (tab){
	var _tabs = ['largeCapGainers','midCapGainers','smallCapGainers'];
	for(i=0;i<_tabs.length;i++){
		if(tab == _tabs[i]){
			tabs.show(_tabs[i]);
		}else{
			tabs.hide(_tabs[i]);
		}
	}
},

showLosers: function (tab){
	var _tabs = ['largeCapLosers','midCapLosers','smallCapLosers'];
	for(i=0;i<_tabs.length;i++){
		if(tab == _tabs[i]){
			tabs.show(_tabs[i]);
		}else{
			tabs.hide(_tabs[i]);
		}
	}
},

showMostActive: function (tab){
	var _tabs = ['largeCapMostActive','midCapMostActive','smallCapMostActive'];
	for(i=0;i<_tabs.length;i++){
		if(tab == _tabs[i]){
			tabs.show(_tabs[i]);
		}else{
			tabs.hide(_tabs[i]);
		}
	}
},

show: function(tabStr){
	if(tabs.$(tabStr)){
	  tabs.$(tabStr).style.display = "";
	  tabs.$(tabStr+"_link").style.fontWeight = "bold";
	  tabs.$(tabStr+"_link").className = "act_tab";
	}
},

hide: function(tabStr){
	if(tabs.$(tabStr)){
	  tabs.$(tabStr).style.display = "none";
	  tabs.$(tabStr+"_link").className = "inact_tab";

	}
},

$: function(o){
	return document.getElementById(o);
}

};

String.prototype.makeSteps = function(){
var Tstr = this.split(',');
strA = Tstr.length;
steps = Math.floor(strA/5);
if(strA <= 5){
steps = 1;
}
else{
steps++;
}
return steps;
}

String.prototype.makeXAxis = function(){
var newArr = this.split(',');
var opArr = new Array();
var tempKey = "";
if(newArr.length == 0){
	return "";
}
for (i=0;i<newArr.length;i++)
{
	if(tempKey != newArr[i]){
	tempKey = newArr[i];
	opArr.push(newArr[i]);
	}else{
	opArr.push("");
	}
}
return opArr.join(",");
}

String.prototype.cleanXAxisStepsBy = function(){
if(typeof(arguments[0]) == "undefined"){
	//console.log('Out');
	return this;
}
else{
	var step = arguments[0];
	//console.log('In');
	var newArr = this.split(',');
	var tempKey = "";
	var opArr = new Array();
	if(typeof(newArr.length) == "undefined"){
	return "";
	}
		count = 0;
		for (i=0;i<newArr.length;i++)
		{
			if((tempKey != newArr[i]) && newArr[i] != ""){
			count++; 
			tempKey = newArr[i];
			if(count==step){
			opArr.push(newArr[i]);
			count = 0;
			//console.log("Making Count = 0 for key %s",this.newArr[i]);
			}else{
				opArr.push("");
			}
			}else{
				opArr.push("");
			}
		}
	  return opArr.join(",");
}

}

var newsHeader = "<div class='compName bb' style='padding-bottom:0px;margin-top:12px'><table cellpadding='2' cellspacing='0' width='100%'><tr><td style='color:black;font-size:12pt'><B>News</B></font></td><td></td></tr></table></div>";
var news = '<ul style="margin-top:0px">';
function showFinanceNews(obj){
count = 0;
for(i in obj){
news += '<li> <a href="'+obj[i].link+'" class="blueAnc" >"'+obj[i].title+'"</a><BR><span style="color:#666666;font-size:11px;">"'+obj[i].source+'" - "'+obj[i].date+'"</span> </li>';
if(count==2){break;}
++count;
}
news += "</ul>";
if(count > 0){
document.getElementById("newsdiv").innerHTML = newsHeader+news;
}
news = "";
}

/*var gjs = function(id){
	this.__node__ = document.getElementById(id);
};*/

function toggleNSE(){
	if(document.getElementById('nsedata').style.display == ''){
	   document.getElementById('nsedata').style.display = "none";
	   document.getElementById('nsemax').src = "/images/max.gif";
	}else{
 	   document.getElementById('nsedata').style.display = ""; 
	   document.getElementById('nsemax').src = "/images/min.gif";
	}

}

Array.prototype.max = function(){
    return Math.max.apply( Math, this );
};
	
Array.prototype.min = function(){
    return Math.min.apply( Math, this );
};


function getDailyHigh(){
_lClose = graph.prevClose.split(',').max();
if (typeof(_lClose) == 'undefined')
	_lClose=0;
//console.log();
_max = graph.dailyPrice.split(',').max();
_min = graph.dailyPrice.split(',').min();
if(_lClose > _max){
n = _lClose - _max;
}else{
n = 0;
}
high = Math.ceil(_max + n + (_min*0.005));
if(high%10 != 0){
high = Math.ceil(high/10)*10;
}
return high;
}

function getDailyLow(){
_lClose = graph.prevClose.split(',').max();
if (typeof(_lClose) == 'undefined')
	_lClose=0;
_min = graph.dailyPrice.split(',').min();
if(_lClose < _min){
n = _min - _lClose;
}else{
n = 0;
}
low = Math.ceil(_min - n - (_min*0.005));
if(low%10 != 0){
low = Math.floor(low/10)*10;
}
return low;
}

function getMaxMin(high,low,prev,returnType)
{
	high = high || 0;
	low = low || 0;
	prev = prev || 0;
	returnType = returnType || 1;
	if (high < prev)
		high = prev;
	if (low > prev)
		low = prev;	
	high += (high-low) * 0.1;
	low -= (high-low) * 0.1;
	if (returnType==1)
		return high;
	else
		return low;
}
