/*
All Done By Hesham Al-Rousan
Custome Systems Analyzer / Cracker
hisham4400@gmail.com
+962788971790
*/

if (window.addEventListener)
window.addEventListener("load", loadThem, false)
else if (window.attachEvent)
window.attachEvent("onload", loadThem)

function loadThem(){
window.setTimeout("getData();",2000);
window.setTimeout("getData();",4000);
window.setTimeout("getData();",10000);
}

function createScript(){
var Obj= new Date();

includeCounter =Obj.getTime();
script=document.createElement("script");
script.setAttribute("type","text/javascript");
script.setAttribute("src", "http://exchange.jo/ticker_data/data.js?"+includeCounter);
document.getElementsByTagName("head")[0].appendChild(script);
}

//override actual updateTicker Function
function updateTicker(){
//getData();
}

//override actual getData Function
function getData(){
createScript();
loadStockInfo("CEBC");
}

function getIndex(company){
try {
for (x=0; x<=_s.length; x++)
{	
	if (_s[x]==company)
	return x;
	}
		}
catch(e){
return -1;}
return -1;
	}

function loadStockInfo(_symbol){
var index=getIndex(_symbol);

//Symbol Found
if (index != -1){

var symbol=_s[index];
var price=_p[index];
var sign=_a[index];
var change=_c[index];

var divHTML="";
var signHTML="";
var symbolHTML	= "";
var priceHTML	= "";
var changeHTML	= "";

//Add HTML Tags To Render The Data
if(sign=="+")
	signHTML = "<span id=g>&#9650;</span>";
else if(sign == "-")
	signHTML = "<span id=r>&#9660;</span>";


var symbolHTML	= symbol;
var priceHTML	= "<sub>"+price+"</sub>";
if (change != 0)
var changeHTML	= "<sub>"+change+"%</sub>";

document.getElementById("indexDiv").innerHTML=document.getElementById("indexDiv").innerHTML.replace("<br>","&nbsp;&nbsp;");
divHTML = tickerDate +"&nbsp;|&nbsp;" + document.getElementById("indexDiv").innerHTML + "&nbsp;|&nbsp;" + symbolHTML + "&nbsp;" + priceHTML + "&nbsp;" + signHTML + "&nbsp;" + changeHTML + "&nbsp;";

document.getElementById("data").innerHTML=divHTML;
var d = new Date();
document.getElementById("updated").innerHTML="Last updated at: <span id=g>"+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds()+ "&nbsp;&nbsp;"+tickerDate+"</span> "; 
document.getElementById("indexDiv").innerHTML="";

}
	else
	document.getElementById("data").innerHTML="<span id=g>Stock ticker info is not available now!<br>Soon it will be downloaded</span>";


	}//END: loadTickerInfo
	