function Request() {

    this.xmlSeriliser = new zXMLSerializer();
 
    Request.prototype.mapRequest = function(componentManagerObj, mapObj, startup) {

        var snapObj = componentManagerObj.snapObj;
        var legendObj = componentManagerObj.legendObj;
        var bufferObj = componentManagerObj.bufferObj;
        
        var startImage = false;
        if (startup) {
            startImage = startup;
        }
        var document = this.getRequestDocument(componentManagerObj);
        var map = document.createElement("MAP");
        map.setAttribute("startimage", "" + startImage);
        map.setAttribute("maptype", "" + mapObj.maptype);
        zXPath.selectSingleNode(document, this.XPATH_REQUEST).appendChild(map);
        var envelope = document.createElement("ENVELOPE");
        map.appendChild(envelope);
        envelope.setAttribute("minx", mapObj.minX);
        envelope.setAttribute("miny", mapObj.minY);
        envelope.setAttribute("maxx", mapObj.maxX);
        envelope.setAttribute("maxy", mapObj.maxY);
        var imagesize = document.createElement("IMAGESIZE");
        map.appendChild(imagesize);
        imagesize.setAttribute("width", mapObj.pageWidth);
        imagesize.setAttribute("height", mapObj.pageHeight);
        
        this.setMapClicks(mapObj, document, map);
        this.setSnap(snapObj, document);
        this.setLegend(legendObj, document);
        this.setBuffer(bufferObj, document);
        
        return this.xmlSeriliser.serializeToString(document);
    }
    
    Request.prototype.panRequest = function(componentManagerObj, panDirection) {
        
        var snapObj = componentManagerObj.snapObj;
        
        var document = this.getRequestDocument(componentManagerObj);
        var pan = document.createElement("PAN");
        pan.setAttribute("direction", panDirection);
        zXPath.selectSingleNode(document, this.XPATH_REQUEST).appendChild(pan);
        
        this.setSnap(snapObj, document);
        
        return this.xmlSeriliser.serializeToString(document);
    }
    
    Request.prototype.setMapClicks = function(mapObject, document, mapElement) {
        
        var shapeCollection = mapObject.shapeCollection;
        
        if (!shapeCollection) {
            return;
        }
        
        var length = shapeCollection.length;
        var shape;
        var layer;
        var shapeElement;
        var shapeType;
        var coordinateType;
        var coodListLength;
        var point;
        
        for (var i=0; i<length; i++) {
            shape = shapeCollection[i];
            layer = document.createElement("MAPCLICKS");
            mapElement.appendChild(layer);
            shapeElement = document.createElement("SHAPE");
            layer.appendChild(shapeElement);
            coodListLength = shape.coordList.length;
            
            for (var j=0; j<coodListLength; j++ ) {
                point = document.createElement("POINT");
                shapeElement.appendChild(point);
                point.setAttribute("x", shape.coordList[j][0]); 
                point.setAttribute("y", shape.coordList[j][1]); 
            }
        }
    }
    
    Request.prototype.snapRequest = function(componentManagerObj) {
    
        var document = this.getRequestDocument(componentManagerObj);
        var snapObj = componentManagerObj.snapObj;
        this.setSnap(snapObj, document);
        return this.xmlSeriliser.serializeToString(document);
    }
    
    Request.prototype.setSnap = function(snapObj, document) {
    
        if (snapObj && snapObj.useSnap) {
            var snap = document.createElement("SNAP");
            snap.setAttribute("layerid", snapObj.snapLayer);
            snap.setAttribute("minscale", snapObj.snapLayerMinScale);
            snap.setAttribute("maxscale", snapObj.snapLayerMaxScale);
            zXPath.selectSingleNode(document, this.XPATH_REQUEST).appendChild(snap);
        }
    }
    
    Request.prototype.toolRequest = function(componentManagerObj) {
    
        var toolObj = componentManagerObj.toolObj;
        var snapObj = componentManagerObj.snapObj;
        var legendObj = componentManagerObj.legendObj;
        var document = this.getRequestDocument(componentManagerObj);
        
        this.setToolRequest(toolObj, snapObj, legendObj, document);
        
        return this.xmlSeriliser.serializeToString(document);
    }
    
    Request.prototype.setToolRequest = function(toolObj, snapObj, legendObj, document) {
        
        var tool = document.createElement("TOOLBAR");
        var type;
        switch (toolObj.getAttribute(toolObj.toolBarObj.TOOL_ATTR_BUTTON_TYPE)) {
            case "ToolbarModeButton":
                type = document.createElement("MODE");
                type.setAttribute("drawmode", toolObj.getAttribute("DrawMode"));
                break;
            case "ToolbarCommandButton":
                type = document.createElement("COMMAND");
                this.setLegend(legendObj, document);
                break;
        }
        tool.appendChild(type);
        type.setAttribute("id", toolObj.id);
        type.setAttribute("commandname", toolObj.getAttribute(toolObj.toolBarObj.TOOL_ATTR_COMMAND_NAME));
        zXPath.selectSingleNode(document, this.XPATH_REQUEST).appendChild(tool);
        
        this.setSnap(snapObj, document);
        
    }
    
    Request.prototype.TOCRefreshRequest = function(componentManagerObj) {
        
        var toolObj = componentManagerObj.toolObj;
        var TOCObj = componentManagerObj.TOCObj;
        var document = this.getRequestDocument(componentManagerObj);
        var toc = document.createElement("TOC");
        zXPath.selectSingleNode(document, this.XPATH_REQUEST).appendChild(toc);
        
        var layerList = TOCObj.layerList;
        var length = layerList.length;
        var layer;
        var currentLayer;
        for (var i=0; i<length; i++) {
            currentLayer = layerList[i];
            if (currentLayer.getAttribute("asktype").toUpperCase() == "LAYER") {
                layer = document.createElement("LAYERS");
                toc.appendChild(layer);
                layer.setAttribute("id", currentLayer.getAttribute("asklayerid"))
                layer.setAttribute("visible", currentLayer.isVisible.toString());
            }
        }
        
        this.setToolRequest(toolObj, null, null, document);
        return this.xmlSeriliser.serializeToString(document);
    }
    
    Request.prototype.TOCActiveLayerRequest = function(componentManagerObj) {
        
        var toolObj = componentManagerObj.toolObj;
        var TOCObj = componentManagerObj.TOCObj;
        var document = this.getRequestDocument(componentManagerObj);
        var toc = document.createElement("TOC");
        zXPath.selectSingleNode(document, this.XPATH_REQUEST).appendChild(toc);
        
        var activeLayer = document.createElement("ACTIVELAYER");
        toc.appendChild(activeLayer);
        activeLayer.setAttribute("id", TOCObj.activeLayerId);
        
        this.setToolRequest(toolObj, null, null, document);
        return this.xmlSeriliser.serializeToString(document);
    }
    
    
    Request.prototype.zoomRequest = function(zoomObj, componentManagerObj) {
        
        var legendObj = componentManagerObj.legendObj;
        var document = this.getRequestDocument(componentManagerObj);
        var zoom = document.createElement("ZOOM");
        var snapObj = componentManagerObj.snapObj;
        
        zXPath.selectSingleNode(document, this.XPATH_REQUEST).appendChild(zoom);
        zoom.setAttribute("id", zoomObj.id);
        
        if (zoomObj.activeStepValue) {
            var step = document.createElement("STEP");
            zoom.appendChild(step);
            step.setAttribute("value", zoomObj.activeStepValue);
        }
        if (zoomObj.scaleValue) {
            var scale = document.createElement("SCALE");
            zoom.appendChild(scale);
            scale.setAttribute("value", zoomObj.scaleValue);
        }
        
        this.setLegend(legendObj, document);
        this.setSnap(snapObj, document);     
        
        return this.xmlSeriliser.serializeToString(document);
    }
    
    Request.prototype.legendRequest = function(componentManagerObj) {
        
        var document = this.getRequestDocument(componentManagerObj);
        legendObj = componentManagerObj.legendObj;
        this.setLegend(legendObj, document);
        
        return this.xmlSeriliser.serializeToString(document);
    }
    
    Request.prototype.setLegend = function(legendObj, document) {
    
        if (legendObj && legendObj.visible) {
            var legend = document.createElement("LEGEND");
            zXPath.selectSingleNode(document, this.XPATH_REQUEST).appendChild(legend);
            
            legend.setAttribute("width", legendObj.legendImageObj.width);
            legend.setAttribute("height", legendObj.legendImageObj.height);
        }
    }
    
    Request.prototype.setBuffer = function(bufferObj, document) {
    
        if (bufferObj && bufferObj.doBuffer) {
            var buffer = document.createElement("BUFFER");
            zXPath.selectSingleNode(document, this.XPATH_REQUEST).appendChild(buffer);
            
            buffer.setAttribute("type", bufferObj.type);
            buffer.setAttribute("distance", bufferObj.distance);
            buffer.setAttribute("unit", bufferObj.unit);
            buffer.setAttribute("targetlayer", bufferObj.targetLayer);
        }
    }
    
    Request.prototype.measureModeRequest = function(componentManagerObj, mode) {
        
        var document = this.getRequestDocument(componentManagerObj);
        var measure = document.createElement("MEASURE");
        measure.setAttribute("mode", mode);
        zXPath.selectSingleNode(document, this.XPATH_REQUEST).appendChild(measure);
        return this.xmlSeriliser.serializeToString(document);
    }
    
    Request.prototype.customRequest = function(requestString) {
        
        var document = this.document;
        var custom = document.createElement("CUSTOM");
        zXPath.selectSingleNode(document, this.XPATH_REQUEST).appendChild(custom);
        var cdataSection = document.createCDATASection(requestString);
        custom.appendChild(cdataSection);
    }
    
    Request.prototype.getXMLString = function() {
        return this.xmlSeriliser.serializeToString(this.document);
    }
    
    Request.prototype.getRequestDocument = function(componentManagerObj) {
        var document = zXmlDom.createDocument();
        var request = document.createElement(this.ELEM_REQUEST);
        document.appendChild(request);
        var drawMode = document.createElement("DRAWMODE");
        request.appendChild(drawMode);
        drawMode.setAttribute("mode", componentManagerObj.mapObj.drawMode);
        this.document = document;
        return this.document;
    }
    
    this.ELEM_REQUEST = "ASKREQUEST";
    this.XPATH_REQUEST = "/" + this.ELEM_REQUEST;
    this.document = null;
}
