// JavaScript Document
var chartInd = ""
var ajaxDiv = ""
var prevLink = "none"
var headerImg = "images/header_animated_1.png"
function bmaOnlineTrade() 
{
var w=657;
var h=377; 
var left = (screen.width/2)-(657/2);
var top = (screen.height/2)-(377/2);
window.open("http://www.bmatrade.com/checkavailibility.asp","NewWindow","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=657, height=377, top=150, left=150");
}

function randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}

function get_symbolperformance(tkr)
{
	document.getElementById('symbol_per_chart').src = "symbol_performance.asp?tkr=" + tkr
}
function ChangChart(ind, rnd)
{	
	//img = document.getElementById('chartImg');
	//img.src = "Images/Loading.gif";
	document.getElementById('KseChart').innerHTML = "<BR><BR><BR><BR><img src='images/chart-loader.gif' align='center' width='150px' height='28px' />&nbsp;&nbsp;&nbsp;"
	document.getElementById('1').style.background='url("images/tab_bg.gif")';
	document.getElementById('2').style.background='url("images/tab_bg.gif")';
	document.getElementById('3').style.background='url("images/tab_bg.gif")';
	document.getElementById('4').style.background='url("images/tab_bg.gif")';
	chartInd = ind
	document.getElementById(ind).style.background='url("images/tab_bg_selected.gif")';
	url = "aspAjax.asp?opt=indexchart&ind=" + ind + "&rnd=" + rnd
	//alert(url)
	getAjax(url, 'KseChart')

}
function DisplayTicker()
{ 
	getAjax('xmlliveprices.asp?o=MarketTickers&random='+ randomString() , 'mktTicker');
//	getAjax('ticker_ajax.asp?random='+ randomString() , 'mktTicker');
	setTimeout('DisplayTicker()',25000) 
} 
function UpdateLivePrice()
{
	getAjax('aspajax.asp?opt=LivePrice', 'DivLivePrices');
	setTimeout('UpdateLivePrice()',20000) 
}
function DisplayChart()
{ 
	if (chartInd == "") chartInd = 1;
	ChangChart(chartInd, randomString());
	
	setTimeout('DisplayChart()',20000) 
} 
function equide_open() {
msg=window.open("eguide/eguide.html","NewWindow","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=725,height=525");
}
function getCalendar(mon, yr, div, lnk)
{
	document.getElementById(div).innerHTML = "<BR><BR><img src='images/chart-loader.gif' />"
	if (prevLink != "none") 
	{
		document.getElementById(prevLink).style.color = '#FFFFFF';
	}
	
	document.getElementById(lnk).style.color='#000000';
	url = "calendarajax.asp?mon=" + mon + "&yr=" + yr
	getAjax(url, div);
	prevLink = lnk;
	
	
}

function changeHeaderImage()
{
	img = document.getElementById("img_header")
	
	if (headerImg=='images/header_animated_1.png')
	{
		headerImg='images/header_animated_2.png'
	} else
	{
		headerImg='images/header_animated_1.png'
	}
	img.src=headerImg;
	setTimeout('changeHeaderImage()',500)
}
////////////////////////////////Ajax Script//////////////////////////////////////
function getAjax(url, div)
{
ajaxDiv = div;
xmlhttp=null;
if (window.XMLHttpRequest)
  {// code for Firefox, Opera, IE7, etc.
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=state_Change;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
}

function state_Change()
{
if (xmlhttp.readyState==4)
  {// 4 = "loaded"
  if (xmlhttp.status==200)
    {// 200 = "OK"
			document.getElementById(ajaxDiv).innerHTML=xmlhttp.responseText;		
			//alert(url)
	}
  else
    {
    //alert(":" + xmlhttp.statusText);
    }
  }
}

