
var xmldoc;
var LiborList;
var RepQuotesList;
var BufferSize;   //news buffer size
var OptionsList;
var MajorList;
var CrossList;
var NormalColor;
var DecreaseColor;//quotes 
var IncreaseColor; //quotes 
var XMLPath;
var StaticQuote;
//var ILSTimeZone=3;

Init();
/******************************************************************************************************/
//
/******************************************************************************************************/
function Init()
{
xmldoc = new ActiveXObject("microsoft.xmldom");
xmldoc.async=false;

StaticQuote='USDILS';
MajorList='EURUSD,'+StaticQuote+',GBPUSD,USDCAD,USDCHF,USDJPY,AUDUSD,NZDUSD';
CrossList='USDARS,USDBRL,USDMXN,USDCLP,USDVEB,USDPAB,USDUYU,EURGBP,EURCHF,GBPCHF,GBPJPY,EURJPY,CHFJPY,USDNOK,USDSEK,USDZAR,USDINR';
LiborList='USD,EUR,GBP,JPY,CHF';
RepQuotesList='USDILS,EURILS,GBPILS,JPYILS,CHFILS,SALILS,CADILS,AUDILS';
OptionsList='USDILS';
BufferSize=4;
DecreaseColor='red';
IncreaseColor='green';
NormalColor='0030c9';
CreateGUI();
setInterval(Update,30000);
Update();
}
/******************************************************************************************************/
//create new chart according to combo selected value
/******************************************************************************************************/
function ChangeSrc()
{
window.location="main.asp?Ver="+ sVer.innerText +"&Type=3&Param="+event.srcElement.innerText;
}
/******************************************************************************************************/
//
/******************************************************************************************************/
function CreateGUI()
{
//var tempArray;
var i;
var j;
var oRow;
var oCell;
var HeadArr;
var RowsArr;
var IDsArr;
var oSection;

/********************/
//create QuotesTbl GUI
/********************/
RowsArr=MajorList.split(',');
CreateSectionOrange(0,0,215,'Major Cross Currencies','QuotesTbl',RowsArr,null,RowsArr);
for (i=1;i<QuotesTbl.rows.length-1;i++)
	{
	oCell=QuotesTbl.rows[i].cells[0];
	oCell.attachEvent("onmousedown",ChangeSrc);
	with(oCell.style)
		{
		textDecoration='underline';
		cursor='hand';
		}
	}

/********************/
//create CrossTbl GUI
/********************/
RowsArr=CrossList.split(',');
CreateSectionOrange(225,0,462,'Other Cross Currencies','CrossTbl',RowsArr,null,RowsArr);


if (sVer.innerText == "1")//end build gui for ver 1
	return;

/***********************************/
//create RepRatesTbl GUI
/***********************************/
IDsArr=RepQuotesList.split(",");
HeadArr=new Array('Currency','Rate','Change %');
RowsArr=new Array('USD','EUR','GBP','JPY','CHF','SAL','CAD','AUD');
oSection=CreateSection(630,0,173,210,'ILS rates','RepRatesTbl',HeadArr,RowsArr,IDsArr,"eng");



//create flags gif's
HeadArr=new Array('usd','eur','gbp','jpy','chf','sal','cad','aud');
for (i=1;i<RepRatesTbl.rows.length;i++)
	{
	//RepRatesTbl.rows[i].cells[0].dir='ltr';
	//RepRatesTbl.rows[i].cells[0].align='right';
	//oSection.all[1].rows[i].cells[0].style.paddingLeft
	oCell=RepRatesTbl.rows[i].cells[0];
	oCell.innerHTML='<img src=Graphics/flags/'+HeadArr[i-1]+'.gif><span>  &nbsp '+RowsArr[i-1]+'</span>';
	oCell.style.textAlign='left';
	oCell.style.paddingLeft='4px';

		//node=document.createElement("IMG");
		//node.src='Graphics/flags/'+HeadArr[i-1]+'.gif';
	//oCell.appendChild(node);
	}




/********************/
//create OptionsTbl GUI
/********************/
IDsArr=OptionsList.split(",");
HeadArr=new Array('Symbol','Bid','Ask')
RowsArr=OptionsList.split(",");
CreateSection(815,0,54,210,'Options','OptionsTbl',HeadArr,RowsArr,IDsArr,"eng");



}

/******************************************************************************************************/
//
/******************************************************************************************************/
function CreateSectionOrange(Top,Left,Height,Title,TblId,RowsArr,HeadArr,RowsIdArr)
{
var node,node1;
var CellWidth;
if (HeadArr == null)
	HeadArr=new Array('Symbol','Bid','Ask','Time <font style="font:bold 8px ariel;">(GMT)</font>');
var Width=208;
//create container div
node=document.createElement("DIV");
with(node.style)
	{
	//backgroundColor='red';
	position='absolute';
	top=Top+'px';
	left=Left+'px';
	width=Width+'px';
	height=Height+'px';
	overflow='auto';
	}
LeftContainer.appendChild(node);
		
//create Title
node1=document.createElement("IMG");
node1.src='Graphics/BlueCorner.gif';
with(node1.style)
	{
	position='absolute';
	top='0px';
	zIndex=4;
	height='14px';
	font='bold 13px ariel';
	}
node.appendChild(node1);

node1=document.createElement("DIV");
//node1.style.top='1px';
node1.style.width=Width;
node1.innerText=Title;
node1.className='SectionTitle';
node.appendChild(node1);	
	
//create table
node1=document.createElement("TABLE");
node1.id=TblId;
node1.cellSpacing=0;
node1.cellPadding=0;
node1.width='100%';
//node1.border=1;
with(node1.style)
	{
	//backgroundColor='blue';
	position='absolute';
	top='14px';
	left='0px';
	width=Width;
	}
node.appendChild(node1);


CellWidth=Width/HeadArr.length;
//alert(CellWidth)

//create table header
oRow=eval(TblId).insertRow();
with(oRow.style)
	{
	//position='absolute';
	//top='-1px';
	height='20px';
	textAlign='center';
	color='white';
	backgroundColor='#a5a5c1';
	font='bold 13px ariel';

	}
for (i=0;i<HeadArr.length;i++)
	{
	oCell=oRow.insertCell();
	oCell.innerHTML=HeadArr[i];
	
	with(oCell.style)
		{
		
		if (HeadArr[i].indexOf("Time") != -1)
			width='60px';
		else
			width='40px';
		font='bold 11px ariel';
		}
	}

//create table rows
for (i=0;i<RowsArr.length;i++)
	{
	oRow=eval(TblId).insertRow();
	oRow.id=RowsIdArr[i];
		with(oRow.style)
			{
			textAlign='center';
			height='20px';
			font='normal 11px ariel';
			backgroundColor='#edeeee';
			
			}
	for (j=0;j<HeadArr.length;j++)
		{
		oCell=oRow.insertCell();
		if (j == 0)
			{
			oCell.innerText=RowsArr[i];
			oCell.width='50px';
			}
		else
			oCell.innerText='----';
		}
	}

//bottom line
oRow=eval(TblId).insertRow();
with(oRow.style)
	{
	//textAlign='center';
	paddingLeft='3px';
	height='20px';
	font='bold 11px ariel';
	backgroundColor='#edeeee';
	}
oCell=oRow.insertCell();
oCell.colSpan=HeadArr.length;
oCell.innerText='* Delayed 1 minute';		
}
/******************************************************************************************************/
//
/******************************************************************************************************/
function Update()
{
var root;
var i,j;
var tempMainArr;var tempArr1;
//load data
xmldoc.load(RTGatewayURL + "DataSup.aspx?Quotes=" + MajorList + ',' + CrossList + "&QuotesDelay=60&Options=" + OptionsList + "&CurrQuotes=" + RepQuotesList + "&TimeZones=Tel-Aviv&StaticQuote="+StaticQuote);
//alert(xmldoc.xml)
if (xmldoc.xml == '')
	return;
root = xmldoc.documentElement.childNodes;
for (i=0;i<root.length;i++)
	{
	switch(root.item(i).nodeName)
		{
		case "Quotes":
		case "StaticQuote":
			tempMainArr=root.item(i).text.split("*^");
			for (j=0;j<tempMainArr.length;j++)
				{
				tempArr1=tempMainArr[j].split(",")
				q=new Quote(tempArr1[1],tempArr1[2],tempArr1[3],tempArr1[4],tempArr1[5],tempArr1[6],tempArr1[7],tempArr1[8],tempArr1[9],tempArr1[10],tempArr1[11])
				UpdateQuote(q);
				UpdateCross(q);
				}
		break;
		case "CurrQuotes":
		if (sVer.innerText == "1")//skip for ver 1
				continue;
			tempMainArr=root.item(i).text.split("*^")
			for (j=0;j<tempMainArr.length;j++)
				{
				tempArr1=tempMainArr[j].split(",")
				q=new CurrQuote(tempArr1[1],tempArr1[2],tempArr1[3],tempArr1[4],tempArr1[5])
				UpdateRepQuotes(q)
				}
		break;

		case "Options":
			if (sVer.innerText == "1")//skip for ver 1
				continue;
			tempMainArr=root.item(i).text.split("*^")
			for (j=0;j<tempMainArr.length;j++)
				{
				tempArr1=tempMainArr[j].split(",");
				
				q=new Option(tempArr1[1],tempArr1[2],tempArr1[3],tempArr1[4],tempArr1[5],tempArr1[7],tempArr1[8],tempArr1[9]);
				UpdateOptions(q)
				}
		
		break;
		case "Libor":
			/*tempMainArr=root.item(i).text.split("*^")
			for (j=0;j<tempMainArr.length-1;j++)
				{
				tempArr1=tempMainArr[j].split("|")
				for (k=0;k<tempArr1.length;k++)
					{
					tempArr2=tempArr1[k].split(",")
					q=new Libor(tempArr2[0],tempArr2[1],tempArr2[2],tempArr2[3]);
					UpdateLibor(q)
					}
				}*/
		break;
		
		/*case "TimeZones": //getting israel time zone
			tempMainArr=root.item(i).text.split("|");
			if (tempMainArr.length > 2)
				{
				if (isNaN(tempMainArr[1]))
					ILSTimeZone=parseInt(tempMainArr[1]);
				
				}
		break;*/
		}	
	}


}
/******************************************************************************************************/
//
/******************************************************************************************************/
function UpdateTime(strTimeDiv,Time,ShowMonth)
{
var TimeDiv=eval(strTimeDiv);
var oTime=new Date(Time);
oTime.setHours(oTime.getHours());//+ILSTimeZone
var sTime=oTime.toString();
var tmpArr=sTime.split(" ");
//alert(tmpArr)
if (ShowMonth)
	sTime=tmpArr[2]+"-"+tmpArr[1]+"-"+tmpArr[5]+" "+tmpArr[3];
else
	sTime=tmpArr[3];

//alert(TimeDiv.MaxTime)
if (TimeDiv.MaxTime == 'none')
	{
	TimeDiv.MaxTime=Time;
	TimeDiv.innerText=sTime
	}
else
	{
	var oTimeMax=new Date(TimeDiv.MaxTime);
	if (oTime > oTimeMax)
		{
		TimeDiv.MaxTime=Time;
		TimeDiv.innerText=sTime;
		}
	}


}
/******************************************************************************************************/
//
/******************************************************************************************************/
function UpdateRepQuotes(oCurrQuote)
{
var oRow=eval("RepRatesTbl").all(oCurrQuote.symbol);
if (oRow == null) return;

oRow.cells[1].innerText=oCurrQuote.value;
oRow.cells[1].style.color=oCurrQuote.color;
oRow.cells[2].innerText=oCurrQuote.change;

UpdateTime('RepRatesTblTime',oCurrQuote.time,true);
}
/******************************************************************************************************/
//
/******************************************************************************************************/
function UpdateOptions(oOptions)
{
var oRow=eval("OptionsTbl").all(oOptions.symbol);
if (oRow == null) return;

oRow.cells[1].innerText=oOptions.bid;
oRow.cells[2].innerText=oOptions.ask;

UpdateTime('OptionsTblTime',oOptions.time,true);
}
/******************************************************************************************************/
//
/******************************************************************************************************/
function UpdateLibor(oLibor)
{
var oRow=eval("LiborTbl").all(oLibor.symbol);
if (oRow == null) return;

switch(oLibor.interval)
	{
	case '6':
		oRow.cells[2].innerText=oLibor.value;
	break;
	case '8':
		oRow.cells[1].innerText=oLibor.value;
	break;
	case '14':
		oRow.cells[0].innerText=oLibor.value;
	break;
	}
//update time
UpdateTime('LiborTblTime',oLibor.time,true);
}
/******************************************************************************************************/
//
/******************************************************************************************************/
function UpdateCross(oQuote)
{
var oRow=eval("CrossTbl").all(oQuote.symbol);
if (oRow == null) return;

oRow.cells[1].innerText=oQuote.bid;
oRow.cells[2].innerText=oQuote.ask;

oRow.cells[1].style.color=oQuote.color;
oRow.cells[2].style.color=oQuote.color;

var oTime=oQuote.time.toString();
oRow.cells[3].innerText=GetTimeFormat(oQuote.time,false);//oTime.substring(oTime.indexOf(':')-2,oTime.lastIndexOf(':')+3);
oRow.cells[3].title=oTime.replace("UTC ","")+" (GMT)";
oRow.cells[3].style.cursor='default';
}

/******************************************************************************************************/
//
/******************************************************************************************************/
function UpdateQuote(oQuote)
{
var oRow=eval("QuotesTbl").all(oQuote.symbol);
if (oRow == null) return;

oRow.cells[1].innerText=oQuote.bid;
oRow.cells[2].innerText=oQuote.ask;

oRow.cells[1].style.color=oQuote.color;
oRow.cells[2].style.color=oQuote.color;

oRow.cells[3].innerText=GetTimeFormat(oQuote.time,false);

var oTime=oQuote.time.toString();
oRow.cells[3].title=oTime.replace("UTC ","")+" (GMT)";
oRow.cells[3].style.cursor='default';
}
/******************************************************************************************************/
//
/******************************************************************************************************/
function GetTimeFormat(oDate,bShowDate)
{
var H=oDate.getHours();
var h=(oDate.getHours() < 13)?H : H-12;
var mi=(oDate.getMinutes() < 10)?"0"+oDate.getMinutes() : oDate.getMinutes();
var s=(oDate.getSeconds() < 10)?"0"+oDate.getSeconds() : oDate.getSeconds();
var AmPm=(oDate.getHours() > 12)?"PM":"AM";
var sTime=oDate.toString()
if (sVer.innerText == "1")
	{
	if (bShowDate)
		return h+":"+mi+":"+s+" "+AmPm;
	else
		return h+":"+mi+":"+s+" "+AmPm;
	
	}
else
	{
	return sTime.substring(sTime.indexOf(':')-2,sTime.lastIndexOf(':')+3);
	}

}
/******************************************************************************************************/
//
/******************************************************************************************************/
function CreateSection(Top,Left,Height,Width,Title,TblId,HeadArr,RowsArr,IDsArr,Lang)
{
var node,node1;
var CellWidth;

//create container div
node=document.createElement("DIV");
with(node.style)
	{
	backgroundColor='white';
	position='absolute';
	top=Top+'px';
	left=Left+'px';
	width=Width+'px';
	height=Height+'px';
	border='solid 1px #887bf4';
	overflow='auto';
	}
LeftContainer.appendChild(node);

//create Title
node1=document.createElement("DIV");
node1.innerText=Title;
//node1.dir='rtl';
with(node1.style)
	{
	backgroundColor='#8989f0';//#0000ff#9b9bf3
	position='absolute';
	top='0px';
	left='0px';
	width=(Width-2)+'px';
	height='17px';
	font='bold 13px ariel';
	color='white';
	paddingLeft='2px';
	border='outset 1px ';
	}
node.appendChild(node1);

//time
node1=document.createElement("DIV");
node1.id=TblId+'Time';
node1.MaxTime='none';

with(node1.style)
	{
	//backgroundColor='red';
	width='100%';
	position='absolute';
	top='0px';
	left='0px';
	height='15px';
	textAlign='right';
	font='bold 11px ariel';
	color='white';
	paddingTop='1px';
	paddingRight='2px';
	}
node.appendChild(node1);



	
	
//create table div
node1=document.createElement("TABLE");
node1.id=TblId;
node1.cellSpacing=0;
node1.cellPadding=0;
//node1.border=1;
with(node1.style)
	{
	position='absolute';
	top='17px';
	left='0px';
	width=Width-3;
	}
node.appendChild(node1);



CellWidth=Width/HeadArr.length;
//alert(CellWidth)

//create table header
oRow=eval(TblId).insertRow();
oRow.style.height='17px';
for (i=0;i<HeadArr.length;i++)
	{
	oCell=oRow.insertCell();
	oCell.innerText=HeadArr[i];
	with(oCell.style)
		{
		width=CellWidth;
		color=NormalColor;
		font='bold 12px ariel';
		textAlign='center';
		}
	}



//create table rows
for (i=0;i<RowsArr.length;i++)
	{
	oRow=eval(TblId).insertRow();
	oRow.id=IDsArr[i];
	oRow.style.height='17px';

	if (i%2 == 0) oRow.style.backgroundColor='#e7efef';
	else oRow.style.backgroundColor='#f7fbff';
	for (j=0;j<HeadArr.length;j++)
		{
		oCell=oRow.insertCell();
		with(oCell.style)
			{
			color=NormalColor;
			font='normal 12px ariel';
			textAlign='center';
			}
		
		//if (TblId == 'QuotesTbl' || TblId == 'OptionsTbl')SymbolLocation=0;
		//else SymbolLocation=HeadArr.length-1;
			
			
			SymbolLocation=0;
		if (j == SymbolLocation)
			{
			//alert(RowsArr[i])
			oCell.innerText=RowsArr[i];
			oCell.width='90px';
			
			if (Lang == "heb")
				{
				oCell.style.textAlign='right';
				oCell.style.paddingRight='5px';
				}
			}
		else
			oCell.innerText='----';
		}
	}

return node;
}

/********************************************************************************************/
//Quote
/*********************************************************************************************/
function Quote(symbol,bid,ask,bank,city,open,high,low,time,change,color)
{
var oTime=new Date(time)
//if (color == "Black")
	//color=NormalColor;

this.symbol=symbol;
this.bid=bid;
this.ask=ask;
this.bank=bank;
this.city=city;
this.open=open
this.high=high;
this.low=low;
this.time=oTime;
this.change=change;
this.color=color;
}
/********************************************************************************************/
//CurrQuote
/*********************************************************************************************/
function CurrQuote(symbol,value,time,change,color)
{
var oTime=new Date(time)
if (color == "Black")
	color=NormalColor;

this.symbol=symbol;
this.value=value;
this.time=oTime;
this.change=change;
this.color=color;
}
/********************************************************************************************/
//Option
/*********************************************************************************************/
function Option(symbol,bid,ask,bank,city,high,low,time)
{
var oTime=new Date(time)

this.symbol=symbol;
this.bid=bid;
this.ask=ask;
this.bank=bank;
this.city=city;
this.high=high;
this.low=low;
this.time=oTime;
}
/********************************************************************************************/
//Libor
/*********************************************************************************************/
function Libor(symbol,interval,value,time)
{
var oTime=new Date(time)

this.symbol=symbol;
this.interval=interval;
this.value=value;
this.time=oTime;
}

