function afgetbyid(id) {
  if(document.getElementById)
  { returnVar = document.getElementById(id); }
  else if (document.all)
  { var returnVar = document.all[id]; }
  else if (document.layers)
  { var returnVar = document.layers[id]; }
  return returnVar;
}

function adecodedeg(v)
{
	sgns = Array("ar","ta","ge","ca","le","vi","li","sc","sg","co","aq","pi");
	sn = Math.floor(v / 30);
	dg = v % 30;
	if(sn < 0 || sn > 11) {
	  return dg + "&deg; undef"; 
	}
	return "<td>"+dg+ "&deg;</td><td><img src=\"http://af.cpptea.com/sim/"+sgns[sn]+".png\" /></td>";
}

function adecode(str) {
	v = parseFloat(str);
  if(v < 0) {
    return "";
  }
  deg = Math.floor(v / 3600);
  v -= deg * 3600;
  min = Math.floor(v / 60);
  v -= min * 60;
  sec = v;
  return adecodedeg(deg) + "<td>" + min + "'</td><td>" + Math.round(sec*100)/100 + "\"</td>";
} 

function astrofoxTable(dat) {
	o = afgetbyid("afdiv");
	if(o != null) {
		planets = dat.split("\n");
		res = "<table>";
		for(p in planets) {
			if(planets[p].trim() == "") {
				continue;
			}
			pie = planets[p].split("\t");
			res += "<tr><td><img src=\"http://af.cpptea.com/sim/"+pie[0]+".png\" /></td>" + adecode(pie[1]) + "</tr>\n";
		}
		o.innerHTML = res;
	}
	setTimeout("astrofoxCall()",15000);
}

function astrofoxCall() {
	var req;
	try{
		req = new XMLHttpRequest();
	} catch(e) {
		try{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				return false;
			}
		}
	}
	req.onreadystatechange = function() {
		if(	req.readyState == 4
				&& (req.status==200
						|| window.location.href.indexOf("http")==-1
					)
			) {
			astrofoxTable(req.responseText);
			return;
		}
	}
	req.open('GET', 'sys/afproxy.php', true);
	req.send(null); 
}

astrofoxCall();
