

var	OutLineColor='#5087D7';
var arrMonthDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var TabWidth=192;
var IfpHeadersArray = new Array('Description',(322+TabWidth)+'px');
var HOLHeadersArray = new Array('Location','118px','Holiday',(175+TabWidth)+'px');
var EVENTHeadersArray = new Array('Time','60px','Location','55px','Description',(175+TabWidth)+'px');
var INDHeadersArray = new Array('Time','60px','Location','55px','Description',TabWidth+'px','Previous','55px','Forecast','55px','Actual','55px');
var ObjNames = new Array('IFP','Events','Holidays','Indicators'); 
var BGColor = 'white';//	#DADADA		
var BGColorArr = new Array(BGColor,BGColor,BGColor,BGColor);//BGColor of tags //'#005826','#FDB913','#FF0000'
var ILSTimeZone=2;

var MonthArr=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")



InitCombo();  


//*****************************************************************************************
//InitCombo
//*****************************************************************************************
function InitCombo()
{
var oFromDate;
var oToDate;

var strDate;
var oCurDate;
var i;
strDate=ServerTimeDiv.innerText;
oCurDate=new Date(strDate)
oFromDate=new Date(oCurDate-1000*60*60*24*30);
oToDate=new Date(Date.parse(oCurDate)+1000*60*60*24*6);

//set year
for(i=oFromDate.getFullYear();i<=oToDate.getFullYear();i++)
	{
	oOption = document.createElement("OPTION");
	oOption.text=i;
	oOption.value=i;
	Years.add(oOption);
	}
//set month
oCurDate.setMonth(oFromDate.getMonth())
for(i=1;i<=3;i++)
	{
	oOption = document.createElement("OPTION");
	oOption.text=MonthArr[oCurDate.getMonth()];
	oOption.value=oCurDate.getMonth()+1;
	Months.add(oOption);
	oCurDate.setMonth(oCurDate.getMonth()+1)
	}
//set date
for(i=1;i<=31;i++)
	{
	oOption = document.createElement("OPTION");
	oOption.text=i;
	oOption.value=i;
	Days.add(oOption);
	}

oCurDate=new Date(strDate)
ChgDateCombos(oCurDate.getDate(),oCurDate.getMonth()+1,oCurDate.getFullYear())

strDate=ChangeTimeFormat(oCurDate.getDate(),(oCurDate.getMonth()+1),oCurDate.getFullYear());
LoadData(strDate);
}
//*****************************************************************************************
//the function loaded the data to the main calendare array.
//*****************************************************************************************
function LoadData(strDate)
{
var MainArray;
var	strData='';
var xmldoc = new ActiveXObject("microsoft.xmldom");
xmldoc.async=false;
var oDate=new Date(strDate);
var Elem;


strDate=ChangeTimeFormat(oDate.getDate(),(oDate.getMonth()+1),oDate.getFullYear());
//alert(strDate)
ChgDateCombos(oDate.getDate(),(oDate.getMonth()+1),oDate.getFullYear());
xmldoc.load(RTGatewayURL + "DataSup.aspx?Calendar=" + strDate + "&TimeZones=Tel-Aviv");
//alert(xmldoc.xml)

//getting IL time zone
Elem=xmldoc.getElementsByTagName("TimeZones");
if (Elem.item(0) == null)
	{
	NoDataMsg();
	return;
	}
tmpArr=Elem.item(0).text.split("|");
if (tmpArr.length > 2)
	{
	if (!isNaN(tmpArr[1]))
		ILSTimeZone=parseInt(tmpArr[1]);
	}

//getting calendar data
Elem=xmldoc.getElementsByTagName("Calendar");
if (Elem.item(0) == null)
	{
	NoDataMsg();
	return;
	}
strData=Elem.item(0).text;
if (strData	!= '' && strData != '^^^')
	{
	EventsTab.style.fontSize='12px';
	EventsTab.style.fontFamily='ariel';	
	MainArray=strData.split('^');
	ChgDateCombos(oDate.getDate(),(oDate.getMonth()+1),oDate.getFullYear())
	GetRemarksText(MainArray);	
	}
else
	{
	ChgDateCombos(oDate.getDate(),(oDate.getMonth()+1),oDate.getFullYear());
	NoDataMsg();
	}
}
//*****************************************************************************************
//
//*****************************************************************************************
function NoDataMsg()
{
EventsTab.style.fontSize='15px'
EventsTab.style.fontFamily='ariel';			
EventsTab.innerHTML='<BR>'
EventsTab.innerHTML+='No events found for the selected date'
}
//*****************************************************************************************
//
//*****************************************************************************************
function LoadNewData()
{
var strDate;
EventsTab.innerHTML='';
if (Days.value != '' && Months.value != '' && Years.value != '')
	{
	strDate=ChangeTimeFormat(Days.value,Months.value,Years.value)
	LoadData(strDate)
	}
}
//*****************************************************************************************
//ChgDateCombos
//*****************************************************************************************
function ChgDateCombos(Day,Month,Year)
{
var i;
//change date
for (i=0;i<Days.length;i++)
	{
	if (Days.all[i].value == Day)
		Days.all[i].selected=true;
	}
//change month
for (i=0;i<Months.length;i++)
	{
	if (Months.all[i].value == Month)
		Months.all[i].selected=true;
	}
//change year
for (i=0;i<Years.length;i++)
	{
	if (Years.all[i].value == Year)
		Years.all[i].selected=true;
	}
}
//*****************************************************************************************
//change days combo according to month
//*****************************************************************************************
function ChangeMonth()
{
var monthDays = arrMonthDays[Months.value-1];
var lastDay;
lastDay=Days.selectedIndex;

//alert(monthDays)
Days.innerHTML='';
for(i=1;i<=monthDays;i++)
	{
	oOption = document.createElement("OPTION");
	oOption.text=i;
	oOption.value=i;
	Days.add(oOption);
	}
i--;
if (lastDay+1 <= i) Days.selectedIndex=lastDay;
else Days.selectedIndex = i-1;
}
//*****************************************************************************************
//CreateTables
//*****************************************************************************************
function CreateTables(TempArr,TableID,TagColor)
{
node =document.createElement('BR');
EventsTab.appendChild(node); 
node =document.createElement('BR');
EventsTab.appendChild(node); 

//creating tag
nd=document.createElement('Span');
nd.style.borderColor = OutLineColor;
//nd.align = "left";
with(nd.style)
	{
	width='80px';
	paddingLeft='5px';;
	fontWeight='bold';
	letterSpacing='1px';
	color = '#003663';
	backgroundColor = BGColor;
	border='groove 1px black';
	borderBottom='';
	}
nd.innerText =TableID;
EventsTab.appendChild(nd); 

//creating table on span	
nd=SetStyleProperties('Table','','','','','',BGColor,'','',OutLineColor,'');
nd.id= TableID+'Table';
nd.style.zIndex=2;
nd.border=1;
nd.noWrap = true;
nd.style.borderCollapse='collapse';
EventsTab.appendChild(nd); 

//creating TBody
nd=document.createElement('TBODY');
nd.id=TableID+'TBody';	
nd.style.borderColor = OutLineColor;
eval(TableID+'Table').appendChild(nd); 


//creating table THead    
oRow = document.createElement('TR');
for(i=0;i<TempArr.length;i+=2)
	{
	oCell =document.createElement('TD');
	oCell.style.borderColor = OutLineColor;
		node = SetStyleProperties("SPAN",'','','','20px',TempArr[i+1],'','','','','10px')
		node.innerText =TempArr[i];
		with(node.style)
			{
			fontWeight=700;
			color = '#003663';
			paddingTop='3px';
			if (i>4)textAlign='center';
			else paddingLeft='5px';
			}
	oCell.appendChild(node);
		
	oRow.appendChild(oCell);
	}
eval(TableID+'TBody').appendChild(oRow); 
}
/*********************************************************************************************/
//CreateRow
/********************************************************************************************/
function CreateRow(strId,TempArr,SizeArr,CheckTimeFlag)
{	
var i;
var str;

//create row
var oRow = document.createElement("TR");
with(oRow.style)
	{
	fontSize='11px'
	fontFamily='ariel';
	borderColor = OutLineColor;
	}

//holidays table switch location and holiday
if (strId == 'Holidays')
	{
	str=TempArr[0];
	TempArr[0]=TempArr[1];
	TempArr[1]=str;
	}
//create cells
for (i=0,j=1;i<TempArr.length;i++,j+=2)
	{
	oCell = document.createElement("TD");	
	with(oCell.style)
		{
		height='20px';
		paddingLeft='5px';
		borderColor = OutLineColor;
		}
		//node = SetStyleProperties("SPAN",'','','','20px',(parseInt(SizeArr[j])-10)+'px','','','','','11px')
		
		node = SetStyleProperties("SPAN",'','','','',(parseInt(SizeArr[j])-10)+'px','','','','','11px')
		if (CheckTimeFlag && i == 0)
			node.innerText=ILTime(TempArr[i]);
		else	
			node.innerText=TempArr[i];
			with(node.style)
				{
				color = '#003663';
				paddingTop='3px';
				overflow='hidden';
				//forecast,prev,actual
				if (i>2)textAlign='center';
				}
	oCell.appendChild(node);
	oRow.appendChild(oCell);
	}	

eval(strId+'TBody').appendChild(oRow);
}
//*****************************************************************************************
//
//*****************************************************************************************
function ILTime(strTime)
{
var oDate =new Date('1/1/2002 '+strTime)
var h;
var m;
if (strTime == '')
	return '-------';
if (strTime.search(':') == -1)
	return '-------';
if (isNaN(oDate))
	return '-------';


//oDate.setHours(oDate.getHours())//+ILSTimeZone //use GMT
h=oDate.getHours();
h=(h > 12)?h-12:h;
m=oDate.getMinutes();
var AmPm=(oDate.getHours() > 12)?"PM":"AM";

if (h < 10) h='0'+h;
if (m < 10) m='0'+m;

if (sVer.innerText == "1")
	{
	return h+':'+m+' '+AmPm;
	}
else
	{
	return h+':'+m;
	}	



}
/********************************************************************************************/
//ChangeTimeFormat
/*********************************************************************************************/
function ChangeTimeFormat(date,month,year)
{
var monthName=new Array("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
date=parseInt(date);
month=parseInt(month);
year=parseInt(year);
return date+" "+monthName[month]+" "+year;
}
/*********************************************************************************************/
//GetRemarksText
/********************************************************************************************/
function GetRemarksText(MainArray)
{	
EventsTab.innerHTML='';

//IFP	
if(MainArray[3]!= '')
	{
	CreateTables(IfpHeadersArray,ObjNames[0],BGColorArr[0]);	
	IFPArray = MainArray[3].split('~');
	IFPArray=new Array('(IFP) '+IFPArray[0])
	CreateRow(ObjNames[0],IFPArray,IfpHeadersArray,false);
	}

//HOLIDAYS	
if(MainArray[2]!= '')
	{
	CreateTables(HOLHeadersArray,ObjNames[2],BGColorArr[2]);	
	HOLArray = MainArray[2].split('|');
	for(i=0;i<(HOLArray.length-1);i++)
		{
		HOLArray1 =	HOLArray[i].split('~');
		CreateRow(ObjNames[2],HOLArray1,HOLHeadersArray,false);
		}
	}		

//EVENTS
if(MainArray[1]!= '')
	{
	var	strEvents =	MainArray[1];
	var	strEvent;
	var	HoursArray = new Array();		
	var	EVENTArray;
	
	CreateTables(EVENTHeadersArray,ObjNames[1],BGColorArr[1]);
	EVENTArray = strEvents.split('|');
	for(i=0;i<(EVENTArray.length-1);i++)
		HoursArray[i] =	EVENTArray[i].substring(0,EVENTArray[i].indexOf('~'));

	for(i=0;i<HoursArray.length;i++)
		{
		intPosition	= strEvents.indexOf(HoursArray[i]);
		intPosition1 = strEvents.indexOf('|',intPosition);
		strEvent = strEvents.substring(intPosition,intPosition1);
		strEvents =	strEvents.substring(0,intPosition) + strEvents.substring(intPosition1+1,strEvents.length)
		EVENTArray = strEvent.split('~');
		CreateRow(ObjNames[1],EVENTArray,EVENTHeadersArray,true);
		}					
	}
		
//INDICATORS 
if(MainArray[0]!= '')
	{	
	var	INDArray;
	HoursArray = new Array();
	var	strINDs	= MainArray[0];
	var	strIND;
	CreateTables(INDHeadersArray,ObjNames[3],BGColorArr[3]);
	INDArray = strINDs.split('|');
	for(i=0;i<(INDArray.length-1);i++)
		{
		HoursArray[i] =	INDArray[i].substring(0,5);
		}

	HoursArray.sort();
						
	for(i=0;i<(HoursArray.length);i++)
		{	
		intPosition	= strINDs.indexOf(HoursArray[i]);
		intPosition1 = strINDs.indexOf('|',intPosition);
		strIND = strINDs.substring(intPosition,intPosition1);
		strINDs	= strINDs.substring(0,intPosition) + strINDs.substring(intPosition1+1,strINDs.length);
		INDArray = strIND.split('~');
		CreateRow(ObjNames[3],INDArray,INDHeadersArray,true);
		}
	}


}
//*****************************************************************************************
//SetStyleProperties
//*****************************************************************************************
function SetStyleProperties(ObjType,sPosition,sTop,sLeft,sHeight,sWidth,sBackgroundColor,sBorderStyle,sBorderWidth,sBorderColor,sFontSize)
{
objName	= document.createElement(ObjType);
with(objName.style)
	{
	top	= sTop;
	left = sLeft;
	position = sPosition;
	height = sHeight;
	width =	sWidth;
	backgroundColor	= sBackgroundColor;
	//border
	borderStyle	= sBorderStyle;
	borderWidth	= sBorderWidth;
	borderColor	= sBorderColor;
	//font
	fontSize = sFontSize;
	fontFamily = 'ariel';
	}
return(objName);
}

