var geomaxXMLDefinition = new function(){
    this.LOCATE_EVENT = 'location';
    this.IDLE = 'idle';
    this.IGNITION_ON = 'ignitionOn';
    this.REDRAW = 'redraw';
    this.DRAW_POLYLINE = 'polyline';
    this.ONLINE = 'online';
    this.MESSAGE_EVENT = 'message';
    this.ADD_OVERLAYS = 'addMapOverlays';
    this.ZOOM_LEVEL = 'zoomLevel';
    this.GET_BOUNDS = 'bounds';
    this.FINISH_LOADING = 'finishLoading';
}

var geomaxXMLHandler = function() {
    var eventHandler = new Hashtable(geomaxXMLDefinition.NUM_EVENTS);
    
    return {
        addGeomaxEventListener : function(type, changeFunction){
            eventHandlerList = eventHandler.get(type);
            if(eventHandlerList == null){
                eventHandlerList = new Vector();
                eventHandler.put(type, eventHandlerList);
            }
            
            eventHandlerList.addElement(changeFunction);
        },
        processXML : function(ajax){
            var defined = true;
            try{
                defined = (ajax != undefined);
            }catch(e){
                defined = false;
            }

            if(defined){
                if( ajax.readyState == 4){
                    var xml = null;
                    try{
                        xml = ajax.responseXML;
                    }catch(e){}

                    if(xml){
                        xml = xml.getElementsByTagName('xml')[0];
                        for(xmlCounter = 0; xmlCounter < xml.childNodes.length; xmlCounter++){
                            var nodeName = xml.childNodes[xmlCounter].nodeName;
                            var node = xml.childNodes[xmlCounter];
                            var eventID = node.getAttribute("id");
                            var eventHandlerList = eventHandler.get(nodeName);
                            if(eventHandlerList){
                                //make sure we are listening for this one
                                for(eventHandlerCounter = 0; eventHandlerCounter < eventHandlerList.getSize(); eventHandlerCounter++){
                                    var handlerFunction = eventHandlerList.getElementAt(eventHandlerCounter);
                                    handlerFunction(new EventObject(eventID, node));
                                }
                            }/*else{
                                    alert("ignoring " + nodeName);
                            }*/
                        }
                    }//if              
                }//if
            }//if
        }
    };
}();

function GeomaxAutoRefresh(varName){
    this.requestGenerator = null;
    this.DELAY = 5000;
    this.stop = false;
    this.variableName = varName;
    this.first = true;
    this.delayStart = true;

    this.setRequestGenerator = function(paramFunction){
        this.requestGenerator = paramFunction;
    };

    this.run = function(){
        try{
            if(this.requestGenerator && !this.stop){
                window.setTimeout( this.variableName + '.run();', this.DELAY);
                if(this.first && this.delayStart){
                    this.first = false;
                }else{
                    this.requestGenerator();
                }
            }
        }catch(e){
          alert(e);        
        }
    };

    this.setRunnable = function(bool){
        this.stop = bool;
    };

    this.setDelay = function(delay){
        this.DELAY = delay;
    };
    
    this.delayStart = function(delayStart){
        this.delayStart = delayStart;
    };

    this.getDelay = function(){
        return this.DELAY;
    };
}


/////////////////////////////////////////////////////////////////////
// OBJECTS
/////////////////////////////////////////////////////////////////////
function EventObject(id, xml){ 
    this.id = id;
    this.xml = xml;
    this.getAttribute = getAttribute;
}

function getAttribute(name){
    return this.xml.getAttribute(name);
}
