var timerID = 0;

function getRequest(){
	request = null;
	//Mozilla-based browsers
	if(window.XMLHttpRequest){
		request = new XMLHttpRequest();
	} else if (window.ActiveXObject){
		request=new ActiveXObject("Msxml2.XMLHTTP");
		if (! request){
			request=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return request;
}

function refreshSpot(){
	//the request could still be null if neither ActiveXObject
	//initializations succeeded
	request = getRequest();
	if(request){
		refreshSpot__(request);
	}
}
function refreshLastQuarterQuote(){
	//the request could still be null if neither ActiveXObject
	//initializations succeeded
	request = getRequest();
	if(request){
		refreshSpot_(request);
	}
}

function refreshQuotes(){
	//the request could still be null if neither ActiveXObject
	//initializations succeeded
	request = getRequest();
	if(request){
		refreshQuotes_(request);
	}
}

function refreshQuotes_(xmlhttp){
	xmlhttp.open('GET', '/e2w/relay.php?script=quotes.php&w=190&h=130&instruments=ENOQ1-11+ENOQ2-11+ENOQ3-11+ENOQ4-11+ENOQ1-12+ENOYR-11+ENOYR-12', true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			setContent(xmlhttp.responseText);
			timerID  = setTimeout("refreshQuotes()", 60000);
		}
	};
	xmlhttp.send(null);
}
function company_news(max, off){
	//the request could still be null if neither ActiveXObject
	//initializations succeeded
	request = getRequest();
	if(request){
		company_news_(request, max, off);
	}
}

function company_news_(xmlhttp, max, off){
	url = '/e2w/relay.php?script=rss.php&out=0&off='+off+'&type=1&url=http%3A%2F%2Fintstream.com/company_news.rss&max='+max
	xmlhttp.open('GET', url,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			setCompanyNews(xmlhttp.responseText);
		}
	};
	xmlhttp.send(null);
}

function setCompanyNews(content){
	if (document.all){
		companyNews.innerHTML=content;
		
	}
	else if (document.getElementById){
		document.getElementById("companyNews").innerHTML=content;
	}
}

function readMessage(indx){
	//the request could still be null if neither ActiveXObject
	//initializations succeeded
	request = getRequest();
	if(request){
		read_message_(request, indx);
	}
}

function read_message_(xmlhttp, indx){
	url = '/e2w/relay.php?script=rss.php&out=0&off='+indx+'&type=3&url=http%3A%2F%2Fintstream.com/company_news.rss&max=1';
	xmlhttp.open('GET', url,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			setCompanyNews(xmlhttp.responseText);
		}
	};
	xmlhttp.send(null);
}

function refreshSpot_(xmlhttp){
	xmlhttp.open('GET', '/e2w/relay.php?script=quote_last.php&w=190&h=130&instrument=__synthetic/__quarter/__i_NORDPOOL&n=Front+quarter', true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			setFrontProduct(xmlhttp.responseText);
			timerID  = setTimeout("refreshLastQuarterQuote()", 60000);
		}
	};
	xmlhttp.send(null);
}

function refreshSpot__(xmlhttp){
	xmlhttp.open('GET', '/e2w/relay.php?script=quote_spot.php&w=190&h=130&instrument=System+Price/System+Price+Daily+Average&n=System spot', true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			setSpot(xmlhttp.responseText);
			timerID  = setTimeout("refreshSpot()", 60000);
		}
	};
	xmlhttp.send(null);
}

function setFrontProduct(content){
	if (document.all){
		frontProduct.innerHTML=content;
	}
	else if (document.getElementById){
		document.getElementById("frontProduct").innerHTML=content;
	}
}

function setSpot(content){
	if (document.all){
		systemSpot.innerHTML=content;
	}
	else if (document.getElementById){
		document.getElementById("systemSpot").innerHTML=content;
	}
}

function setContent(content){
	if (document.all){
		number.innerHTML=content;
	}
	else if (document.getElementById){
		document.getElementById("number").innerHTML=content;

	}
}

function startTimer(){
	timerID  = setTimeout("refreshLastQuarterQuote()",  100);
	timerID  = setTimeout("refreshSpot()",  100);
	timerID  = setTimeout("refreshQuotes()",  100);
}

function stopTimer(){
	clearTimeout(timerID);
	timerID = null;
}

 
function updateChartByFile(o, file) {
       var FCObject = (navigator.appName.indexOf("Microsoft") !=-1 && !window.opera) ? window[o] : document[o];
       FCObject.SetVariable('_root.xml_file', file);
}

