//+***********************************************************************************************+
// Object to access the MRC (Maplet Remote Control)
//
// Copyright (C)2000-2003 by Netsolut GmbH
// $Revision: 1.1 $ $Date: 2005/01/24 13:27:16 $
//


// create like
// map24Control = CRemoteControl( mid, sid, "java", imageid, mrcframe )
// map24Control = CRemoteControl( mid, sid, "cgi", imageid, mrcframe )
// map24Control = CRemoteControl( mid, sid, "reload", url, mrcframe )  <-- NOT IMPLEMENTED TILL NOW
function CRemoteControl()
{
	// protected variables
	this.DEBUG = false;
	
	// private variables
	this._host = "maptp.map24.com";
	this._interface = "/map24/webservices1.4";
	this._debugFrame = null;
	this._debugTextarea = null;
	this._type = "java";
	this._reloadImage = null;
	this._reloadURL = null;
	this._reloadFrame = null;
	this._mid = null;
	this._sid = null;
	this._cgiBase = "?cgi=Map24RenderEngine&action=renderMapImage";
	this._cgiMapWidth = 500;
	this._cgiMapHeight = 400;
	this._mrcBase = "?cgi=Map24MapletRemoteControl&action=mapletRemoteControl";
	this._cmdList = null;
	this._cmdIndex = 0;
	this._signPassword = null;
	this._signIP = null;
	this._serviceID = null;
	this._findFrameStartAt = top;

	// public methods to manage groups
	this.groupNew = CRemoteControl_groupNew;
	this.groupAddObject = CRemoteControl_groupAddObject;
	this.groupRemoveObject = CRemoteControl_groupRemoveObject;
	this.groupRemove = CRemoteControl_groupRemove;
	this.groupDismiss = CRemoteControl_groupDismiss;

	// public methods to manage layer
	this.layerNew = CRemoteControl_layerNew;
	this.layerAddObject = CRemoteControl_layerAddObject;
	this.layerRemoveObject = CRemoteControl_layerRemoveObject;
	this.layerRemove = CRemoteControl_layerRemove;
	this.layerDismiss = CRemoteControl_layerDismiss;
	
	// public methods to manage map-objects
	this.addLocation = CRemoteControl_addLocation;
	this.addText = CRemoteControl_addText;
	this.addRoute = CRemoteControl_addRoute;
	this.remove = CRemoteControl_remove;
	
	// public methods to manage the visibility of layers, groups and objects
	this.show = CRemoteControl_show;
	this.showInLayer = CRemoteControl_showInLayer;
	this.showInGroup = CRemoteControl_showInGroup;
	this.showAll = CRemoteControl_showAll;
	this.showAllInLayer = CRemoteControl_showAllInLayer;
	this.showAllInGroup = CRemoteControl_showAllInGroup;
	this.hide = CRemoteControl_hide;
	this.hideInLayer = CRemoteControl_hideInLayer;
	this.hideInGroup = CRemoteControl_hideInGroup;
	this.hideAll = CRemoteControl_hideAll;
	this.hideAllInLayer = CRemoteControl_hideAllInLayer;
	this.hideAllInGroup = CRemoteControl_hideAllInGroup;

	// public methods to move the viewport
	this.move = CRemoteControl_move;
	this.moveTo = CRemoteControl_moveTo;
	this.panTo = CRemoteControl_panTo;
	this.centerAbove = CRemoteControl_centerAbove;
	this.zoom = CRemoteControl_zoom;
	this.zoomTo = CRemoteControl_zoomTo;

	// public common methods
	this.setHost = CRemoteControl_setHost;
	this.setInterface = CRemoteControl_setInterface;
	this.setViewPortArea = CRemoteControl_setViewPortArea;
	this.signRequest = CRemoteControl_signRequest;
	this.execute = CRemoteControl_execute;
	this.commit = CRemoteControl_commit;
	this.rollback = CRemoteControl_rollback;

	// public utility methods
	this.findFrameStartAt = CRemoteControl_findFrameStartAt;
	this.findFrame = CRemoteControl_findFrame;
	this.appendLink = CRemoteControl_appendLink;
	this.getTime = CRemoteControl_getTime;
	this.escape = CRemoteControl_escape;
	this.trim = CRemoteControl_trim;

	// public debug methods
	this.enableDebug = CRemoteControl_enableDebug;
	this.disableDebug = CRemoteControl_disableDebug;
	this.notice = CRemoteControl_notice;





	// -------------- CONSTRUCTOR --------------------
	// CRemoteControl( mid, sid, "java", imageid[, mrcframe] )
	// CRemoteControl( mid, sid, "cgi", imageid[, mrcframe] )
	// CRemoteControl( mid, sid, "reload", url, mrcframe ) <-- NOT IMPLEMENTED TILL NOW
	this.CRemoteControl = CRemoteControl_CRemoteControl;
	this.CRemoteControl( CRemoteControl.arguments );
	function CRemoteControl_CRemoteControl( args )
	{
		if( args.length < 4 )
		{
			// UPS
		} else
		{
			if( args.length == 4 ) args[4] = null;
			this._mid = args[0];
			this._sid = args[1];
			if( args[2]=="reload" || args[2]=="RELOAD" )
			{
				this._reloadImage = null;
				this._reloadURL = args[3];
				this._reloadFrame = args[4];
				this._type = "reload";
			} else
			if( args[2]=="cgi" || args[2]=="CGI" )
			{
				this._reloadImage = args[3];
				this._reloadURL = this._cgiBase;
				this._reloadFrame = args[4];
				this._type = "cgi";
			} else
			{
				this._reloadImage = args[3];
				this._reloadURL = this._mrcBase;
				this._reloadFrame = args[4];
				this._type = "java";
			}
		}
		this._cmdList = new Array();
		this._cmdIndex = 0;
	}





	// groupNew( name )
	function CRemoteControl_groupNew( name )
	{
		var request = "&cmd"+this._cmdIndex+"=ADDGROUP";
		request += "&id"+this._cmdIndex+"="+this.escape(this.trim(name))+"mobid=";
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// groupAddObject( name, id )
	function CRemoteControl_groupAddObject( name, id )
	{
		var request = "&cmd"+this._cmdIndex+"=ADDGROUP";
		request += "&id"+this._cmdIndex+"="+this.escape(this.trim(name));
		request += "&mobid"+this._cmdIndex+"="+this.escape(this.trim(name))+"|"+this.escape(this.trim(id));
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// groupRemoveObject( name, id )
	function CRemoteControl_groupRemoveObject( name, id )
	{
		var request = "&cmd"+this._cmdIndex+"=REMOVE";
		request += "&id"+this._cmdIndex+"="+this.escape(this.trim(name));
		request += "&mobid"+this._cmdIndex+"="+this.escape(this.trim(id));
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// groupRemove( name )
	function CRemoteControl_groupRemove( name )
	{
		var request = "&cmd"+this._cmdIndex+"=REMOVE";
		request += "&mobid"+this._cmdIndex+"="+this.escape(this.trim(name));
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// groupDismiss( name )
	function CRemoteControl_groupDismiss( name )
	{
		this.groupNew(name);
		this.remove(name);
		return;
	}





	// layerNew( name )
	function CRemoteControl_layerNew( name )
	{
		var request = "&cmd"+this._cmdIndex+"=ADDLAYER";
		request += "&id"+this._cmdIndex+"="+this.escape(this.trim(name))+"mobid=";
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// layerAddObject( name, id )
	function CRemoteControl_layerAddObject( name, id )
	{
		var request = "&cmd"+this._cmdIndex+"=ADDLAYER";
		request += "&id"+this._cmdIndex+"="+this.escape(this.trim(name));
		request += "&mobid"+this._cmdIndex+"="+this.escape(this.trim(name))+"|"+this.escape(this.trim(id));
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// layerRemoveObject( name, id )
	function CRemoteControl_layerRemoveObject( name, id )
	{
		var request = "&cmd"+this._cmdIndex+"=REMOVE";
		request += "&id"+this._cmdIndex+"="+this.escape(this.trim(name));
		request += "&mobid"+this._cmdIndex+"="+this.escape(this.trim(id));
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// layerDelete( name )
	function CRemoteControl_layerRemove( name )
	{
		var request = "&cmd"+this._cmdIndex+"=REMOVE";
		request += "&mobid"+this._cmdIndex+"="+this.escape(this.trim(name));
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// layerDismiss( name )
	function CRemoteControl_layerDismiss( name )
	{
		this.layerNew(name);
		this.remove(name);
		return;
	}





	// addLocation( id, x, y, description )
	// addLocation( id, x, y, description, logo_url )
	// addLocation( id, x, y, description, logo_url, symbol )
	// addLocation( id, x, y, description, logo_url, symbol, url )
	// addLocation( id, x, y, description, logo_url, symbol, url, target )
	function CRemoteControl_addLocation()
	{
		var request = "&cmd"+this._cmdIndex+"=ADD";
		switch( CRemoteControl_addLocation.arguments.length )
		{
		case 8: request += "&target_frame"+this._cmdIndex+"=" + this.escape(this.trim(CRemoteControl_addLocation.arguments[7]));
		case 7: request += "&url"+this._cmdIndex+"=" + this.escape(this.trim(CRemoteControl_addLocation.arguments[6]));
		case 6: request += "&symbol_id"+this._cmdIndex+"=" + this.trim(CRemoteControl_addLocation.arguments[5]);
		case 5:	if( (CRemoteControl_addLocation.arguments[4] != "") &&
					(CRemoteControl_addLocation.arguments[4] != null) )
				{
					request += "&logo_url"+this._cmdIndex+"=" + this.escape(this.trim(CRemoteControl_addLocation.arguments[4]));
				}
		case 4: if( (CRemoteControl_addLocation.arguments[3] != "") &&
					(CRemoteControl_addLocation.arguments[3] != null) )
				{
					request += "&description"+this._cmdIndex+"=" + this.escape(this.trim(CRemoteControl_addLocation.arguments[3]));
				}
				request += "&y"+this._cmdIndex+"=" + this.trim(CRemoteControl_addLocation.arguments[2]);
				request += "&x"+this._cmdIndex+"=" + this.trim(CRemoteControl_addLocation.arguments[1]);
				request += "&id"+this._cmdIndex+"=" + this.escape(this.trim(CRemoteControl_addLocation.arguments[0]));
				this._cmdList[this._cmdIndex++] = request;
		}
		return;
	}

	// addText( id, x, y, text )
	function CRemoteControl_addText( id, x, y, text )
	{
		var request = "&cmd"+this._cmdIndex+"=ADD";
		request += "&id"+this._cmdIndex+"=" + this.escape(this.trim(id));
		request += "&x"+this._cmdIndex+"=" + this.trim(x);
		request += "&y"+this._cmdIndex+"=" + this.trim(y);
		request += "&text"+this._cmdIndex+"=" + this.escape(this.trim(text));
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// addRoute( id, rid )
	function CRemoteControl_addRoute( id, rid )
	{
		var request = "&cmd"+this._cmdIndex+"=ADD";
		request += "&id"+this._cmdIndex+"=" + this.escape(this.trim(id));
		request += "&routeid"+this._cmdIndex+"=" + this.escape(this.trim(rid));
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// remove( id )
	function CRemoteControl_remove( id )
	{
		var request = "&cmd"+this._cmdIndex+"=REMOVE";
		request += "&mobid"+this._cmdIndex+"="+this.escape(this.trim(id));
		this._cmdList[this._cmdIndex++] = request;
		return;
	}






	// show( id )
	function CRemoteControl_show( id )
	{
		var request = "&cmd"+this._cmdIndex+"=ENABLE";
		request += "&mobid"+this._cmdIndex+"="+this.escape(this.trim(id));
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// showInLayer( id, layer )
	function CRemoteControl_showInLayer( id, layer )
	{
		var request = "&cmd"+this._cmdIndex+"=ENABLE";
		request += "&mobid"+this._cmdIndex+"="+this.escape(this.trim(id));
		request += "&layer"+this._cmdIndex+"="+this.escape(this.trim(layer));
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// showInGroup( id, group )
	function CRemoteControl_showInGroup( id, group )
	{
		var request = "&cmd"+this._cmdIndex+"=ENABLE";
		request += "&mobid"+this._cmdIndex+"="+this.escape(this.trim(id));
		request += "&group"+this._cmdIndex+"="+this.escape(this.trim(group));
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// showAll()
	// showAll( except )
	function CRemoteControl_showAll()
	{
		var request = "&cmd"+this._cmdIndex+"=HIDE";
		if( CRemoteControl_showAll.arguments.length >= 1 )
		{
			request += "&mobid"+this._cmdIndex+"="+this.escape(this.trim(CRemoteControl_showAll.arguments[0]));
		} else {
			request += "&mobid"+this._cmdIndex+"=";
		}
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// showAllInLayer( layer )
	// showAllInLayer( layer, except )
	function CRemoteControl_showAllInLayer( layer )
	{
		var request = "&cmd"+this._cmdIndex+"=HIDE";
		request += "&layer"+this._cmdIndex+"="+this.escape(this.trim(layer));
		if( CRemoteControl_showAllInLayer.arguments.length >= 2 )
		{
			request += "&mobid"+this._cmdIndex+"="+this.escape(this.trim(CRemoteControl_showAllInLayer.arguments[1]));
		} else {
			request += "&mobid"+this._cmdIndex+"=";
		}
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// showAllInGroup( group )
	// showAllInGroup( group, except )
	function CRemoteControl_showAllInGroup( group )
	{
		var request = "&cmd"+this._cmdIndex+"=HIDE";
		request += "&group"+this._cmdIndex+"="+this.trim(group);
		if( CRemoteControl_showAllInGroup.arguments.length >= 2 )
		{
			request += "&mobid"+this._cmdIndex+"="+this.escape(this.trim(CRemoteControl_showAllInGroup.arguments[1]));
		} else {
			request += "&mobid"+this._cmdIndex+"=";
		}
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// hide( id )
	function CRemoteControl_hide( id )
	{
		var request = "&cmd"+this._cmdIndex+"=DISABLE";
		request += "&mobid"+this._cmdIndex+"="+this.escape(this.trim(id));
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// hideInLayer( id, layer )
	function CRemoteControl_hideInLayer( id, layer )
	{
		var request = "&cmd"+this._cmdIndex+"=DISABLE";
		request += "&mobid"+this._cmdIndex+"="+this.escape(this.trim(id));
		request += "&layer"+this._cmdIndex+"="+this.escape(this.trim(layer));
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// hideInGroup( id, group )
	function CRemoteControl_hideInGroup( id, group )
	{
		var request = "&cmd"+this._cmdIndex+"=DISABLE";
		request += "&mobid"+this._cmdIndex+"="+this.escape(this.trim(id));
		request += "&group"+this._cmdIndex+"="+this.escape(this.trim(group));
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// hideAll()
	// hideAll( except )
	function CRemoteControl_hideAll()
	{
		var request = "&cmd"+this._cmdIndex+"=SHOW";
		if( CRemoteControl_hideAll.arguments.length >= 1 )
		{
			request += "&mobid"+this._cmdIndex+"="+this.escape(this.trim(CRemoteControl_hideAll.arguments[0]));
		} else {
			request += "&mobid"+this._cmdIndex+"=";
		}
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// hideAllInLayer( layer )
	// hideAllInLayer( layer, except )
	function CRemoteControl_hideAllInLayer( layer )
	{
		var request = "&cmd"+this._cmdIndex+"=SHOW";
		request += "&layer"+this._cmdIndex+"="+this.trim(layer);
		if( CRemoteControl_hideAllInLayer.arguments.length >= 2 )
		{
			request += "&mobid"+this._cmdIndex+"="+this.escape(this.trim(CRemoteControl_hideAllInLayer.arguments[1]));
		} else {
			request += "&mobid"+this._cmdIndex+"=";
		}
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// hideAllInGroup( group )
	// hideAllInGroup( group, except )
	function CRemoteControl_hideAllInGroup( group )
	{
		var request = "&cmd"+this._cmdIndex+"=SHOW";
		request += "&group"+this._cmdIndex+"="+this.trim(group);
		if( CRemoteControl_hideAllInGroup.arguments.length >= 2 )
		{
			request += "&mobid"+this._cmdIndex+"="+this.escape(this.trim(CRemoteControl_hideAllInGroup.arguments[1]));
		} else {
			request += "&mobid"+this._cmdIndex+"=";
		}
		this._cmdList[this._cmdIndex++] = request;
		return;
	}





	// move( direction )
	function CRemoteControl_move( direction )
	{
		var request = "&cmd"+this._cmdIndex+"=NAV";
		switch( direction )
		{
		case "NORTH":
		case "NORTH_EAST":
		case "EAST":
		case "SOUTH_EAST":
		case "SOUTH":
		case "SOUTH_WEST":
		case "WEST":
		case "HOME":
		case "BACK":
		case "FORWARD":	request += "&nav"+this._cmdIndex+"="+this.trim(direction);
						this._cmdList[this._cmdIndex++] = request;
		}
		return;
	}

	// moveTo( x, y )
	// moveTo( x, y, width )
	// moveTo( x, y, width, borderPercent )
	function CRemoteControl_moveTo()
	{
		var request = "&cmd"+this._cmdIndex+"=MOV";
		switch( CRemoteControl_moveTo.arguments.length )
		{
		case 4:	if( typeof CRemoteControl_moveTo.arguments[3] == "number" )
				{
					if( CRemoteControl_moveTo.arguments[3] >= 0 )
					{
						request += "&clw_per"+this._cmdIndex+"="+this.trim(CRemoteControl_moveTo.arguments[3]);
					}
				}
		case 3:	if( typeof CRemoteControl_moveTo.arguments[2] == "number" )
				{
					if( CRemoteControl_moveTo.arguments[2] >= 50 )
					{
						request += "&clw_min"+this._cmdIndex+"="+this.trim(CRemoteControl_moveTo.arguments[2]);
					}
				}
		case 2:	if( typeof CRemoteControl_moveTo.arguments[1] == "number" && 
					typeof CRemoteControl_moveTo.arguments[0] == "number" )
				{
					request += "&y"+this._cmdIndex+"="+this.trim(CRemoteControl_moveTo.arguments[1]);
					request += "&x"+this._cmdIndex+"="+this.trim(CRemoteControl_moveTo.arguments[0]);
					this._cmdList[this._cmdIndex++] = request;
				}
		}
		return;
	}

	// panTo( px, py )
	function CRemoteControl_panTo( px, py )
	{
		var request = "&cmd"+this._cmdIndex+"=NAV";
		request+= "&nav"+this._cmdIndex+"=PAN";
		if( (typeof px == "number") && (typeof py == "number") )
		{
			request += "&px"+this._cmdIndex+"="+px;
			request += "&py"+this._cmdIndex+"="+py;
			this._cmdList[this._cmdIndex++] = request;
		}
		return;
	}

	// centerAbove( id )
	// centerAbove( id, width )
	// centerAbove( id, width, borderPercent )
	function CRemoteControl_centerAbove()
	{
		var request = "&cmd"+this._cmdIndex+"=MOV";
		switch( CRemoteControl_centerAbove.arguments.length )
		{
		case 3:	if( typeof CRemoteControl_centerAbove.arguments[2] == "number" )
				{
					if( CRemoteControl_centerAbove.arguments[2] >= 0 )
					{
						request += "&clw_per"+this._cmdIndex+"="+this.trim(CRemoteControl_centerAbove.arguments[2]);
					}
				}
		case 2:	if( typeof CRemoteControl_centerAbove.arguments[1] == "number" )
				{
					if( CRemoteControl_centerAbove.arguments[1] >= 50 )
					{
						request += "&clw_min"+this._cmdIndex+"="+this.trim(CRemoteControl_centerAbove.arguments[1]);
					}
				}
		case 1:	request += "&mobid"+this._cmdIndex+"=" + this.escape(this.trim(CRemoteControl_centerAbove.arguments[0]));
				this._cmdList[this._cmdIndex++] = request;
		}
		return;
	}

	// zoom( direction )
	function CRemoteControl_zoom( direction )
	{
		var request = "&cmd"+this._cmdIndex+"=NAV";
		if( direction == "IN" )
		{
			request += "&nav"+this._cmdIndex+"=ZOOMIN";
		} else
		if( direction == "OUT" ) 
		{
			request += "&nav"+this._cmdIndex+"=ZOOMOUT";
		} else
			return;
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// zoomTo( width )
	function CRemoteControl_zoomTo( width )
	{
		var request = "&cmd"+this._cmdIndex+"=MOV";
		if( typeof width == "number" && width >= 50 )
		{
			request += "&clw_min"+this._cmdIndex+"=" + this.trim(width);
			this._cmdList[this._cmdIndex++] = request;
		}
		return;	
	}





	// setHost( newhost )
	function CRemoteControl_setHost( newhost )
	{
		this._host = newhost;
		return;
	}
	
	// setInterface( newinterface )
	function CRemoteControl_setInterface( newinterface )
	{
		if( newinterface.charAt(0)!='/' )
			this._interface = '/'+newinterface;
		else
			this._interface = newinterface;
		return;
	}

	// setViewPortArea( mapWidth, mapHeight )
	function CRemoteControl_setViewPortArea( mapWidth, mapHeight )
	{
		this._cgiMapWidth = mapWidth;
		this._cgiMapHeight = mapHeight;
	}

	// ip-address of this computer is required, because you can't read the ip-address 
	// via javascript, further the file md5.js must be included first, if you want to 
	// use this feature!
	function CRemoteControl_signRequest( password, ip )
	{
		if( this._type=="cgi" )
			this._serviceID = 'C';
		else
			this._serviceID = 'M';
		this._signPassword = password;
		this._signIP = ip;
	}

	// execute the given free command, insert a questionmark for each position where the current 
	// execution-number should be placed, example: execute("MOV", "&nav?=NORTH");
	function CRemoteControl_execute( cmd, args )
	{
		var request = "&cmd"+this._cmdIndex+"="+this.trim(cmd);
		if( typeof args == "string" )
		{
			args = args.replace(/\?/ig,this._cmdIndex);
			if( args.charAt(0)!='&' )
				request += '&'+args;
			else
				request += args;
		}
		this._cmdList[this._cmdIndex++] = request;
		return;
	}

	// for CGI empty-commits are done as well and will work as a "reload" of the image,
	// while for maplet-remote-control nothing will be done in that case
	function CRemoteControl_commit()
	{
		var signThisRequest = null;
		if( this._signPassword!=null && this._signIP!=null )
		{
			var timeStamp = this.getTime();
			signThisRequest = "&time="+timeStamp+"&key="+md5(this._mid+this._signPassword+timeStamp+this._signIP+this._serviceID);
		}
		if( this._cmdList.length > 0 )
		{
			if( this._reloadImage==null )
			{
				// NOT IMPLEMENTED YET
			} else
			{
				var request = "http://"+this._host+this._interface+this._reloadURL;
				request = this.appendLink( request, '&mid='+this._mid+'&sid='+this._sid );
				for( i=0; i < this._cmdIndex; i++ )
				{
					request = this.appendLink( request, this._cmdList[i] );
				}
				if( this._type=="cgi" )
				{
					request = this.appendLink( request, "&iw="+this._cgiMapWidth+"&ih="+this._cgiMapHeight );
				}
				request = this.appendLink( request, "&t="+this.getTime() );
				if( signThisRequest!=null ) request = this.appendLink( request, signThisRequest );
				if( this._reloadFrame!=null )
				{
					var frame = findFrame(this._reloadFrame);
					if( frame!=null )
					{
						if( frame.document.getElementById(this._reloadImage) )
						{
							frame.document.getElementById(this._reloadImage).src = request;
							if( this.DEBUG != false ) this.notice(request);
						}
					}
				} else
				if( document.getElementById(this._reloadImage) )
				{
					document.getElementById(this._reloadImage).src = request;
					if( this.DEBUG != false ) this.notice(request);
				}
			}
			this._cmdList = new Array();
			this._cmdIndex = 0;
		} else
		if( this._type=="cgi" )
		{
			var request = "http://"+this._host+this._interface+this._reloadURL;
			request = this.appendLink( request, '&mid='+this._mid+'&sid='+this._sid );
			request = this.appendLink( request, "&iw="+this._cgiMapWidth+"&ih="+this._cgiMapHeight );
			request = this.appendLink( request, "&t="+this.getTime() );
			if( signThisRequest!=null ) request = this.appendLink( request, signThisRequest );
			if( this._reloadFrame!=null )
			{
				var frame = findFrame(this._reloadFrame);
				if( frame!=null )
				{
					if( frame.document.getElementById(this._reloadImage) )
					{
						frame.document.getElementById(this._reloadImage).src = request;
						if( this.DEBUG != false ) this.notice(request);
					}
				}
			} else
			if( document.getElementById(this._reloadImage) )
			{
				document.getElementById(this._reloadImage).src = request;
				if( this.DEBUG != false ) this.notice(request);
			}
		}
		return;
	}

	// rollback()
	// rollback( steps )
	function CRemoteControl_rollback()
	{
		if( CRemoteControl_rollback.arguments.length >= 1 )
		{
			if( typeof CRemoteControl_rollback.arguments[0] == "number" )
			{
				this._cmdIndex = this._cmdIndex - CRemoteControl_rollback.arguments[0];
				if( this._cmdIndex < 0 ) this._cmdIndex = 0;
			}
		} else
			this._cmdIndex = 0;
	}





	// trim( text )
	function CRemoteControl_trim( text )
	{
		if( typeof text == "string" )
			return text.replace(/\n/ig,"").replace(/\r/ig,"").replace(/^ /i,"").replace(/ $/i,"");
		return text;
	}
	
	// findFrameStartAt( frame )
	// call like map24Control.startFindFrameAt( top.map24Frame ) and NOT like map24Control.startFindFrameAt( "top.map24Frame" )
	function CRemoteControl_findFrameStartAt( frame )
	{
		this._findFrameStartAt = frame;
	}
	
	//	findFrame( frameName )
	//	returns the frame-object with the given name
	function CRemoteControl_findFrame( frameName )
	{
		if( CRemoteControl_findFrame.arguments.length <= 0 ) return null;
		var frameName = CRemoteControl_findFrame.arguments[0];
		var inWindow = this._findFrameStartAt;
		if( CRemoteControl_findFrame.arguments.length > 1 ) inWindow = CRemoteControl_findFrame.arguments[1];
		if( inWindow.frames[frameName] ) return inWindow.frames[frameName];
		var frame = null;
		for( var i=0; i < inWindow.frames.length; i++ )
		{
			frame = this.findFrame( frameName, inWindow.frames[i] );
			if( frame!=null ) return frame;
		}
		return null;
	}

	// getTime()
	function CRemoteControl_getTime()
	{
		var t = new Date();
		return t.getTime();
	}

	// appendLink( link, args )
	function CRemoteControl_appendLink( link, args )
	{
		if( typeof link == "string" &&
			typeof args == "string" )
		{
			if( link.length >= 1 &&
				(link.charAt(link.length-1)!='?' ||
				 link.charAt(link.length-1)!='&') )
			{
				if( link.indexOf('?') >= 0 )
					link += '&';
				else
					link += '?';
			}

			while( args.charAt(0)=='?' || args.charAt(0)=='&' ) args = args.substring(1);
			return link+args;
		}
	}
	
	// escape( string )
	function CRemoteControl_escape( string )
	{
		if( typeof string == "string" )
		{
			var newString = "";
			var hexValues = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
			var i;
			for( i=0; i < string.length; i++ )
			{
				if( string.charCodeAt(i) < 128 )
				{
					newString += escape( string.charAt(i) );
				} else
				{
					if( string.charCodeAt(i) < 256 )
					{
						newString += "%";
						newString += hexValues[(string.charCodeAt(i) >> 4)];
						newString += hexValues[(string.charCodeAt(i) & 15)];
					}
				}
			}
			return newString;
		} else
		{
			return string;
		}
	}





	// enableDebug( textareaID )
	// enableDebug( textareaID, frame )
	function CRemoteControl_enableDebug( textareaID )
	{
		if( CRemoteControl_enableDebug.arguments.length >= 2 )
		{
			this._debugFrame = CRemoteControl_enableDebug.arguments[1];
		} else {
			this._debugFrame = null;
		}
		this._debugTextarea = textareaID
		this.DEBUG = true;
	}
	
	// disableDebug()
	function CRemoteControl_disableDebug()
	{
		this.DEBUG = false;
	}

	// notice( text )
	function CRemoteControl_notice( text )
	{
		if( this.DEBUG && this._debugTextarea )
		{
			var doc = document;
			if( this._debugFrame != null )
			{
				var frame = this.findFrame(this._debugFrame);
				if( !frame ) return;
				doc = frame.document;
			}
			var textarea = doc.getElementById(this._debugTextarea);
			if( textarea )
			{
				textarea.value = textarea.value + text + "\n";
			}
		}
	}
}

