function shipload()
{
	//alert("ready to go");
	req=false;
	if(window.XMLHttpRequest && !(window.ActiveXObject)){
		xmlDoc = document.implementation.createDocument("", "", null);
		try{
			//alert("create HTTP request");
			req=new XMLHttpRequest();
		}catch(e){
			req=false;
			//alert("failed");
		}
		if(req){
			//alert("now to try and get something");
			req.onreadystatechange=processReqChange;
			// For some reason the above is never excecuted in FireFox
			//alert("after statechang");
			req.open('POST','shipplot.xml',false);
			//alert("after post request "+req.readyState);
			//alert("request status "+req.status);
			//alert("request text "+req.statusText);
			req.setRequestHeader("Content-Type","text/xml");
			req.send(null);
			//alert("after req.send "+req.readyState);
			//alert("request status "+req.status);
			//alert("request text "+req.responseXML);
			processReqChange();
			//req.onreadystatechange=processReqChange;
		}
	}
	else if (window.ActiveXObject)
	{	
		//alert("what?");
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async=false;
		xmlDoc.onreadystatechange = function () {if (xmlDoc.readyState == 4) getships()};
		xmlDoc.load("shipplot.xml");
		return;
	}
}

function processReqChange()
{
	//alert("Did we make it here?");
	if(req.readyState==4){
		if(req.status==200){	// never changes to 200 for local document but why doesn't it get here
			//alert("trying to process");
			xmlDoc=req.responseXML;
			getships();
		}else{
			alert("There was a problem retrieving the XML data:\n"+req.statusText);
		}
	}
}

//function shipload()
//{
//	if (document.implementation && document.implementation.createDocument)
//	{
//		xmlDoc = document.implementation.createDocument("", "", null);
//		xmlDoc.async=false;
//		xmlDoc.onload = getships;
//	}
//	else if (window.ActiveXObject)
//	{
//		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
//		xmlDoc.async=false;
//		xmlDoc.onreadystatechange = function () {if (xmlDoc.readyState == 4) getships()};
//	}
//	else
//	{
//		alert('Your browser can\'t handle this script');
//		return;
//	}
//	xmlDoc.asyn=false;
//	xmlDoc.load("shipplot.xml");
//	return;
//}

function getships()
{
	var x = xmlDoc.getElementsByTagName('ship');
// Ships is the surrounding tag
// ship is for each ship
// contains the info for each ship
	num_ships=x.length;
	mmsi=new Array(num_ships);
	call_sign=new Array(num_ships);
	ship_name=new Array(num_ships);
	ship_length=new Array(num_ships);
	ship_width=new Array(num_ships);
	ship_draught=new Array(num_ships);
	ship_nav=new Array(num_ships);
	ship_type=new Array(num_ships);
	ship_speed=new Array(num_ships);
	ship_course=new Array(num_ships);
	ship_destination=new Array(num_ships);
	ship_eta=new Array(num_ships);
	ship_latitude=new Array(num_ships);
	ship_longitude=new Array(num_ships);
	for (i=0;i<num_ships;i++)
	{
//
// New code to try and be browser independant
//
		//alert(i);
		mmsi[i]=x[i].getElementsByTagName("mmsi")[0].firstChild.nodeValue;
		//alert(mmsi[i]);
		call_sign[i]=x[i].getElementsByTagName("call_sign")[0].firstChild.nodeValue;
		//alert(call_sign[i]);
		ship_name[i]=x[i].getElementsByTagName("ship_name")[0].firstChild.nodeValue;
		//alert(ship_name[i]);
		ship_length[i]=x[i].getElementsByTagName("length")[0].firstChild.nodeValue;
		ship_width[i]=x[i].getElementsByTagName("beam")[0].firstChild.nodeValue;
		ship_draught[i]=x[i].getElementsByTagName("draught")[0].firstChild.nodeValue;
		ship_nav[i]=x[i].getElementsByTagName("nav")[0].firstChild.nodeValue;
		ship_type[i]=x[i].getElementsByTagName("type")[0].firstChild.nodeValue;
		ship_speed[i]=x[i].getElementsByTagName("speed_over_ground")[0].firstChild.nodeValue
		ship_course[i]=x[i].getElementsByTagName("course_over_ground")[0].firstChild.nodeValue
		ship_destination[i]=x[i].getElementsByTagName("destination")[0].firstChild.nodeValue
		ship_eta[i]=x[i].getElementsByTagName("eta_destination")[0].firstChild.nodeValue

		//alert(x[i].childNodes.length);
		for (j=0;j<x[i].childNodes.length;j++)
			{
			//if(j==0){
			//	mmsi[i]=x[i].childNodes[j].firstChild.nodeValue;
			//}
			//if(j==1){
			//	call_sign[i]=x[i].childNodes[j].firstChild.nodeValue;
			//}
			//if(j==2){
			//	ship_name[i]=x[i].childNodes[j].firstChild.nodeValue;
			//}
			//if(j==3){
			//	ship_length[i]=x[i].childNodes[j].firstChild.nodeValue;
			//}
			//if(j==4){
			//	ship_width[i]=x[i].childNodes[j].firstChild.nodeValue;
			//}
			//if(j==5){
			//	ship_draught[i]=x[i].childNodes[j].firstChild.nodeValue;
			//}
			//if(j==6){
			//	ship_nav[i]=x[i].childNodes[j].firstChild.nodeValue;
			//}
			//if(j==7){
			//	ship_type[i]=x[i].childNodes[j].firstChild.nodeValue;
			//}
			//if(j==8){
			//	ship_speed[i]=x[i].childNodes[j].firstChild.nodeValue;
			//}
			//if(j==9){
			//	ship_course[i]=x[i].childNodes[j].firstChild.nodeValue;
			//}
			//if(j==10){
			//	ship_destination[i]=x[i].childNodes[j].firstChild.nodeValue;
			//}
			//if(j==11){
			//	ship_eta[i]=x[i].childNodes[j].firstChild.nodeValue;
			//}
			//if (x[i].childNodes[j].nodeType != 1){
			//	continue;}
			//if(j==12){
				if(x[i].childNodes[j].nodeType==1){
					if(x[i].childNodes[j].nodeName=="track"){
				//var lats=x[i].childNodes.getElementsByTagName("latitude");
				//var lons=x[i].childNodes.getElementsByTagName("longitude");
				var lats=x[i].childNodes[j].getElementsByTagName('latitude');
				var lons=x[i].childNodes[j].getElementsByTagName('longitude');
				//alert(i);
				//alert(lats.length);
				ship_latitude[i]=new Array(lats.length);
				ship_longitude[i]=new Array(lons.length);
				for(k=0; k< lats.length; k++){
					ship_latitude[i][k]=lats[k].firstChild.nodeValue;
					ship_longitude[i][k]=lons[k].firstChild.nodeValue;
					//alert(ship_latitude[i]);
				}
				} // end if track
				} // end if node==1
			//}
		}
	}
	//alert("data Loaded");
return;
}
