/** \class TeWMS
  * \brief This class implementes the basic set operations that a WMS client will need to exchange data to a WMS server.
  *
  * \sa TeWMSGetCapabilitiesRequest, TeWMSGetCapabilitiesResponse
  *
  */
function TeWMS()
{
	TeWMS.prototype.GetCapabilities = GetCapabilities;
	TeWMS.prototype.GetMap = GetMap;
	TeWMS.prototype.GetFeatureInfo = GetFeatureInfo;
	
    function GetCapabilities(capabilitiesRequest, responseFunction)
	{
		var strGetCapabilities  = capabilitiesRequest.getServerURL();
		var xmlHTTP = TeXMLHTTPFactory.createXMLHTTP();
		
		xmlHTTP.onreadystatechange = function()
		{
		    if(xmlHTTP.readyState == 4)
			{
				if(xmlHTTP.status == 200) {
					if (xmlHTTP.responseXML && xmlHTTP.responseText!="") {
						if(xmlHTTP.responseXML.documentElement)
						{
							var response = new TeWMSGetCapabilitiesResponse();	
							response.readFromXML(xmlHTTP.responseXML);
							responseFunction(response);
						}
						else
							alert("Could not load Capabilities document.");
					}else {
						alert("Endereço inexistente ou indisponível.");
					}
				}
				else if(xmlHTTP.status == 401) {
					responseFunction("ERROR");
					alert("Could not load Map image.");
				}
		    }
		}
	
		/*
            the "open" method of the xmlObj opens a connection to the server (via a specific protocol,
            specified here as "GET" – you can use "POST" and others as well), requests a file (in our case,
            the variable "strGetCapabilities"), and whether JavaScript should handle the request
            synchronously (false) or asynchronously (true, the default). Since this is
            asynchronous Javascript and XML, we will be using the default
            asynchronous method – using since synchronous won't work in this case.
		*/
		var file = "wmsgetcapa.php?minhaurl=" + escape(strGetCapabilities.substring(7));
		//document.getElementById("rodape").innerHTML=file;
		xmlHTTP.open ('GET', file, true);
		xmlHTTP.send ('');
	} 

	//function GetMap(serviceResponse, responseFunction)
	function GetMap(parans, responseFunction)
	{
		parans = "?newBox="+loadBox()+parans;
		var xmlHTTP = TeXMLHTTPFactory.createXMLHTTP();
		
		xmlHTTP.onreadystatechange = function()
		{
			
		    if(xmlHTTP.readyState == 4)
			{
				if(xmlHTTP.status == 200) {
					responseFunction(xmlHTTP.responseText);
				}
				else if(xmlHTTP.status == 401) {
					responseFunction("Could not load Map image.");
					alert("Could not load Map image.");
				}
		    }
		}
		var file = "wmsgetmap.php"+parans;
		xmlHTTP.open ('GET', file, true);
		xmlHTTP.send ('');
	} 
	// Still not implemented.
	function GetFeatureInfo(infoRequest)
	{
	    
	} 
} 

