// =============================================================
//
// Copyright (c) 2000-2003 GE Smallworld. All Rights Reserved.
//
// =============================================================

var hcfRoot = top;

// -----------------  Target Object ------------
function Target_deprecated() {
   this.frame = null;
   this.openWindow = false;
   this.windowName = '';
   this.windowWidth = 100;
   this.windowHeight = 100;
   
   // setup methods
   this.setupTarget = Target_deprecated_setupTarget;
}

function Target_deprecated_setupTarget()
{
   // Return ths target of this request.  If the target is
   // a window, then the window is first opened.

   // setup result
   var result = null;
  
   if (this.openWindow == true)
   {
      openDialog('about:blank', this.windowWidth, this.windowHeight,'', this.windowName);
      result = this.windowName;
   }
   else
   {
      result = this.frame.name;
   }
   //alert(result);
   return result;
}      
   
   
// -----------------  Request Object ------------
function Request_deprecated() {
   // first setup methods
   this.execute = Request_deprecated_execute;
   this.registerParameter = Request_deprecated_registerParameter;
   this.parameterString = Request_deprecated_parameterString;
   this.registerRequest = Request_deprecated_registerRequest;
   this.requestString = Request_deprecated_requestString;
   this.transformString = Request_deprecated_transformString;
  
   // setup default properties
   this.stylesheet = '';
   this.popUpName = '';
   this.popUpWidth = 0;
   this.popUpHeight = 0;
   this.anchor = '';
   
   // setup target
   this.target = new Target_deprecated();

   // --------  setup requests ---------
   this.requestCount = 0;
   this.registeredRequests = new Array(MAX_REQUESTS);

   this.requestCount = 0;


   // --------  setup parameters ---------
   this.parameterCount = 0;
   this.registeredParameters = new Array(MAX_PARAMS);
  
   for (x=0;x<MAX_PARAMS;x++) 
	   this.registeredParameters[x] = new Array(2);


   // setup charset
   aCharset = document.charset;
   
	if (aCharset == null || 
       aCharset == '' || 
       aCharset === undefined) {
       
      this.charset = 'UTF-8';
   }
   
   // ie does not define this.charset but Mozilla does
   if (this.charset != undefined) {
      this.registerParameter('swldy_input_encoding', this.charset);
      this.registerParameter('swldy_output_encoding', this.charset);
   }   
}


// -----------------  Execute ------------
function Request_deprecated_execute(aBatchForm) {

   // HCF 2.1 works with SIAS server mode IAS 2.1.0, 
   // so set that up here
   this.registerParameter("swldy_server_type", GLOBAL_CONTEXT.serverType);   
   this.registerParameter("version", GLOBAL_CONTEXT.serverVersion); 
   
   // now say that we want to use wmt exceptions  
   this.registerParameter("exceptions", "wms_ias_xml");   

   // get parameters
   aParams = this.parameterString();
   
   if (aParams != '') {
   	  //set up action
      aBatchForm.action = aBatchForm.action + '?' + aParams;

      if (this.anchor != '') {
      	aBatchForm.action = aBatchForm.action + '#' + this.Anchor;
      }
   }

   aBatchForm.target = this.target.setupTarget();

   // get request
   aRequest = this.requestString();
   
   //set up request
   aBatchForm.elements.command.value = aRequest;
   
   // get transform
   aTransform = this.transformString();
   
   if (aTransform != '') {
      aBatchForm.elements.transform.value = aTransform;
   }

   //now submit form
   aBatchForm.submit();
}


// ---------  Transform Handling ------------
function Request_deprecated_transformString() {
   var result = '';
   
   if (this.stylesheet != '') {
      result = '<transforms>' +
                  '<transform>' + 
                     '<name>xsl_transform</name>'+
                     '<stylesheet>' + this.stylesheet + '</stylesheet>'+
                     '<output_format>' + GLOBAL_CONTEXT.outputFormat + '</output_format>' + 
                     '<output_mode>' + GLOBAL_CONTEXT.outputMode + '</output_mode>' + 
                  '</transform>' +
               '</transforms>';
   }            
            
   return result;
}
     
     
// ---------  Parameter Handling ------------
function Request_deprecated_registerParameter(aParamName, aParamValue) {

	if (this.parameterCount + 1 == MAX_PARAMS) {
		alert(hcfRoot.MAX_PARAMS_ERROR_MESSAGE + aParamName + '> could not be registered.');
		return;
	}
	
	for (var i=0;i < this.parameterCount;i++) {
		if(this.registeredParameters[i][0] == aParamName) {
			this.registeredParameters[i][1] = aParamValue;
			return;
		}
	}
   
	this.registeredParameters[this.parameterCount][0] = aParamName;
   //aParamValue = aParamValue.replace(' ','%20');
	this.registeredParameters[this.parameterCount][1] = aParamValue;
	
	this.parameterCount = this.parameterCount + 1;
}


function Request_deprecated_parameterString() {
	// Creates a parameter string that can be sent to
	// server as part of the requested action

	// locally declare i
	var result = '';
	
	for (var i=0; i < this.parameterCount; i++) {
		result = result + 
					 this.registeredParameters[i][0] + 
					 '=' +
					 this.registeredParameters[i][1];
		if (i < this.parameterCount - 1)
         result = result + '&';
	}
	return result;
}
           

// ---------  Request Handling ------------
function Request_deprecated_registerRequest(requestString) {
	if (this.requestCount + 1 == MAX_REQUESTS) {
		alert(hcfRoot.MAX_REQUESTS_ERROR_MESSAGE + aRequest + '> could not be registered.');
		return;
	}
	
   // by default the index of this request will be equal to the
   // current request count
   index = this.requestCount;

   //increment request count since this is a new request
   this.requestCount = this.requestCount + 1;
	
	// now save request string
	this.registeredRequests[index] = requestString;
}	


function Request_deprecated_requestString() {
	var result = '<requests>';
   
	for (var i = 0; i < this.requestCount; i++)  {
		result += this.registeredRequests[i];
	}
   
	result += '</requests>';
   
	return result;
}

