/*<![CDATA[*/

function BigName(smol_name)
{
  big = smol_name.toUpperCase()
  big = big.substring(0,3) + "/" + big.substring(3);
  return big;
}

function alertContents(http_request) {
var xml;
var quote='<tr style="background:#C1E99E"><th>Symbol</th><th>Bid</th><th>Ask</th></tr>';
try {
if ((http_request.readyState == 4) && (http_request.status == 200)) {
    xml=http_request.responseXML.getElementsByTagName('quote');
    for (i=0; i<xml.length; i++) {
        ask=xml[i].firstChild.nodeValue;
        sp=ask.indexOf(" ");
        if (sp>0){
          if (ask.substring(0,1)=='u'){
            updown='class="up"';
          }
          else if(ask.substring(0,1)=='d') {
            updown='class="down"';
          }
          else
            updown=' ';
          bid=ask.substring(1,sp);
          ask=ask.substring(sp+1);
          cur=xml[i].attributes.getNamedItem("n").nodeValue;
          k= 1+(i-Math.floor(i/2)*2);
          quote +=  '<tr class="td' + k +'"><td ' + updown+'>' +BigName(cur)+'</td><td ' + updown+'>'+bid +'</td><td ' + updown+'>'+ask +'</td></tr>';
        }
    }
    document.getElementById('quote').innerHTML = quote;
  }
}
catch( e ) {}
}

function makeRequest(url,data) {
var http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
  http_request = new XMLHttpRequest();
}
else if (window.ActiveXObject) { // IE
  try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch (e) {
    try {
      http_request = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {}
  }
}
if (!http_request) {
  alert('Невозможно создать экземпляр класса XMLHTTP ');
  return false;
}
http_request.onreadystatechange = function() { alertContents(http_request); };
http_request.open('POST', url, true);
http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http_request.send(data);
}

function doQuotes(){
  clearTimeout(timeoutID);
  t=10000;
  if(is_quote){
    if(Date-is_quote>5*1000*60) t=30000;
    if(Date-is_quote>10*1000*60) t=60000;
    if(Date-is_quote>15*1000*60) t=180000;
  }
  else{
    is_quote=new Date();
  }
  makeRequest('fquotes.php',Math.floor(Math.random() * 10000000));
  if (document.getElementById('quote'))
    timeoutID=setTimeout(function() { doQuotes(); }, t);
}

function initOnLoad(sElementName) {
	var oElement = (sElementName == "body") ? document[sElementName] :
		document.getElementById(sElementName);
	if(oElement != null && typeof(oElement) != "undefined") { doQuotes(); }
	else {
    if(!is_quote){
      setTimeout(function() { initOnLoad(sElementName); }, 0);
    }
  }
}
var is_quote=0, timeoutID=0;
initOnLoad("quote");
window.onload = doQuotes;

/*]]>*/




