
function dataDate(edcuid,dateString,mapElement,mapObject){
    //if(_debug)_debug.log("initializing dataDate with edcuid="+edcuid+" dateString="+dateString);
    this.edcuid=edcuid
    this.date=dateString;
    this.name=dateString;
    this.hidden=1;
    this.toggleButton=new toggleButton(this.date,this);
    this.data=null;
    //
    // 1 june 2005, rewriting to explore displaying individual points
    // rather than a large image

    // 17 june 2005.  pulled in to dataDate declaration to get around
    // this aliasing, and to adhere to new loadXMLDoc callback behavior
    var self=this;
    this.display=function(req,div){
	var dataObject;
	var jsonText=req.responseText;
	var statusText=req.statusText;
	if(jsonText){
	    dataObject= eval('(' + jsonText + ')');
	}
	if(self.data){ // already have data, am refetching/refreshing
	    //if(_debug)_debug.log("in dataDate.display, calling reCenter data");
	    // if self.data already exists, overwrite it
	    self.data.open();
	}else{
	    //if(_debug)_debug.log("in dataDate.display, creating new dataView");
	    self.data=new gpsDataArrayBuilder(dataObject,mapObject.div,mapObject);
	    self.data.refresh();

	    GEvent.addListener(mapObject, "zoom",function(){self.data.refresh();});
	    GEvent.addListener(mapObject, "maptypechanged",function(){self.data.refresh();});
	    GEvent.addListener(mapObject, "moveend",function(){self.data.refresh();});
	}
    };
}

dataDate.prototype.toString=function(){
    return "edcuid="+this.edcuid+" date="+this.date;
};
dataDate.prototype.showMyself=function(){
    //if(_debug)_debug.log("entering dataDate.showMyself");
    this.hidden=0;
    this.toggleButton.htmlObj.className="show";
    //if already have data, show it on map
    if(this.data){
	this.data.open();
    }else{
        //fetch dates information from server, pass along handler to
	//create on return
	var url=actionRoot+"/getdata?value(edcuid)="+this.edcuid+"&value(date)="+this.date+"&value(scale)=16";
	//if(_debug)_debug.log("dataDate, url is "+url);
	loadXMLDoc(url,this.display,this.toggleButton.htmlObj.getElementsByTagName('a')[0]);
    }
};
dataDate.prototype.hideMyself=function(){
    //if already have data, blank it
    this.toggleButton.htmlObj.className="";
    if(this.data && this.hidden==0){
	this.data.remove();
	this.hidden=1;
    }
};


function gpsdevice(dataObject,mapElement,mapObject){
    this.id=dataObject.id;
    this.name=dataObject.name;
    this.toggleButton=new toggleButton(this.name,this);
    this.dates=new Array();
    this.ul=null;
    var self=this;
    this.display=function(req,ul){
	var jsonText=req.responseText;
	var statusText=req.statusText;
	var dataObject;
	if(jsonText){
	    dataObject= eval('(' + jsonText + ')');
	}
	if(dataObject.datesList && dataObject.edcuid==self.id){
	    //if(_debug)_debug.log("in gpsdevice.display for a list of dates "+dataObject.datesList.length);
	    // got a list of dates, create nodes for each
	    for(var i=0;i<dataObject.datesList.length;i++){
		self.dates.push(new dataDate(self.id,dataObject.datesList[i],mapElement,mapObject));
		ul.appendChild(self.dates[i].toggleButton.htmlObj);
	    }
	}
    };
}
gpsdevice.prototype.toString=function(){
        return "edcuid="+this.id+",name="+this.name;
};
gpsdevice.prototype.showMyself=function(){
    //if already have dates, show them, otherwise fetch then show them
    if(this.ul){
    }else{
	//fetch dates information from server, pass along handler to
	//create on return
	var url=actionRoot+"/getdates?value(edcuid)="+this.id;
	//if(_debug)_debug.log("in gpsdevice.showMyself(), fetching "+url);
	this.ul=document.createElement("ul");
	this.toggleButton.htmlObj.appendChild(this.ul);
	loadXMLDoc(url,this.display,this.ul);
    }
};
gpsdevice.prototype.rescale=function(){
    //if(_debug)_debug.log("entering gpsdevice.rescale with list length"+this.dates.length);
    for(var i=0;i<this.dates.length;i++){
	this.dates[i].rescale();
    }
};
gpsdevice.prototype.remove=function(){
    //if(_debug)_debug.log("entering gpsdevice.hideCanvasStuff with list length"+this.dates.length);
    for(var i=0;i<this.dates.length;i++){
	this.dates[i].remove();
    }
};

var deviceblock;
function get_gps_deviceblock(container,mapElement,mapObject){
    deviceblock=new devices(container,mapElement,mapObject);
    //mapCanvas.addRescaleListener(deviceblock);
};

function devices(element,mapElement,mapObject){
    this.container=$(element);
    this.deviceList=new Array();
    this.ul=null;
    var self=this;
    this.display=function(req,ul){
	var dataObject;
	var jsonText=req.responseText;
	var statusText=req.statusText;
	if(jsonText){
	    dataObject= eval('(' + jsonText + ')');
	}
	if(dataObject){
	    // got a list of edcus, create nodes for each
	    for(var i=0;i<dataObject.length;i++){
		self.deviceList.push(new gpsdevice(dataObject[i],mapElement,mapObject));
		ul.appendChild(self.deviceList[i].toggleButton.htmlObj);
	    }
	}
    };
    this.fetchDevices();
}

devices.prototype.fetchDevices=function(){
    //fetch dates information from server, pass along handler to
    //create on return
    var url=actionRoot+"/getedcus";
    this.ul=document.createElement("ul");
    this.container.appendChild(this.ul);
    loadXMLDoc(url,this.display,this.ul);
};
devices.prototype.rescale=function(){
    //if(_debug)_debug.log("entering devices.rescale with list length"+this.deviceList.length);
    for(var i=0;i<this.deviceList.length;i++){
	this.deviceList[i].rescale();
    }
};
devices.prototype.hideCanvasStuff=function(){
    //if(_debug)_debug.log("entering devices.hideCanvasStuff with list length"+this.deviceList.length);
    for(var i=0;i<this.deviceList.length;i++){
	this.deviceList[i].remove();
    }
};
