function saveRoute(appUrlRoot,selfUrl,circuit)  {
	var self = this;
	self.appUrlRoot = appUrlRoot;
	self.selfUrl = selfUrl;
	self.circuit = circuit;

	this.save = function(but)  {
		frmSave.runData.value = runData.toJSONString(); 
		frmSave.name.value = frmRideName.name.value;
		updateRTEs();
		
		var errMsg = '';
		with (frmSave) {
			if (name.value == '')
				errMsg += 'Please enter a unique name for this ride. (i.e. 2007-03-12 Home Loop)\n\n';
			if (runData.value == '')
				errMsg += 'There is no route data\n\n';
			if (notes.value == '')
				errMsg += 'Please enter some comments for this ride.\n\n';
		}
		if (errMsg == '') {
			var urlValues = self.selfUrl+'?fuseAction=common.saveRide';
			but.disabled = true;
			self.displayProgress("<br><br><br><table align=\'center\'><tr><td class=\'mapButton\'>Saving Route....</td></tr><tr><td align=\'center\'><img align=\'middle\' src=\'"+self.appUrlRoot+"/images/saving.gif\'</td></tr></table>");
			DWREngine.showDebug = false;		
			DWREngine.setFailOver(self.saveFailed);
			DWREngine._httpMethod = "POST";			
			DWREngine.execute(self.routeSaved, urlValues,self.formElementsToString(frmSave));
		}
		else
			alert(errMsg);
	}

	this.displayProgress = function ( theHTML ){
		var progressDiv = document.getElementById('progressDiv');
		if (!progressDiv) {
			progressDiv = document.createElement('div');
		}
		var myWidth;
		var myHeight;
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
		progressDiv.id = 'progressDiv';
		progressDiv.style.backgroundColor='aliceblue';
		progressDiv.style.border = '2px outset midnightblue';
		progressDiv.style.position = 'absolute';
		progressDiv.style.width = '500px';
		progressDiv.style.padding = '5px';
		progressDiv.style.zIndex='100';
		progressDiv.style.height = '200px';
		progressDiv.overflow = 'auto';
		progressDiv.style.top = parseInt((myHeight-100)/2)+'px';
		progressDiv.style.left = parseInt((myWidth-500)/2)+'px';
		progressDiv.innerHTML = theHTML;
			
		//Write the console to the screen and assume focus
		document.body.appendChild(progressDiv);
		
	}

	this.routeSaved = function (retObj) {
		if (retObj.success != 0) { 
			var theUrl = self.appUrlRoot+"/"+self.selfUrl+"?fuseAction="+self.circuit+".viewDBRide&rideID="+retObj.success;
			var x = "<table width='100%' style='font-size: 9pt;'>";
			x += "<tr><td align='right'><a href='javascript:removeProgressDiv();'>Close (X)</a></td></tr>";
			x += "<tr><td>&nbsp;</td></tr>";
			x += "<tr><td class='mapButton' style='text-align:center'>Your route has been saved...</td></tr>";
			x += "<tr><td>&nbsp;</td></tr>";
			x += "<tr><td class='mapButton' style='text-align:center'>Feel free to share the link to it below with your friends</td></tr>";
			x += "<tr><td>&nbsp;</td></tr>";
			x += "<tr><td align='center'><a href='"+theUrl+"'>"+theUrl+"</a></tr>";
			x += "</table>";
			document.getElementById('progressDiv').innerHTML = x;
			frmRideName.butSave.disabled = false;
		}
		else
			self.saveFailed(retObj);
	}

	this.saveError = function (msg,detail) {
			var x = "<table width='100%' style='font-size: 9pt;'>";
			x += "<tr><td align='right'><a href='javascript:removeProgressDiv();'>Close (X)</a></td></tr>";
			x += "<tr><td>&nbsp;</td></tr>";
			x += "<tr><td class='mapButton' style='text-align:center'>"+msg+"</td></tr>";
			if (detail) {
				x += "<tr><td>&nbsp;</td></tr>";
				x += "<tr><td style='text-align:left;font-size : 8pt;'>"+detail+"</td></tr>";
			}
			x += "</table>";
			document.getElementById('progressDiv').innerHTML = x;
	}

	this.saveFailed = function (retObj) {
		frmRideName.butSave.disabled = false;
		if (retObj && retObj != 'undefined')
			if (retObj.englishmessage.length > 0)
				self.saveError(retObj.englishmessage);
			else
				self.saveError("Sorry, I was unable to save your route due to the following error:",retObj.errormessage);
		else
			self.saveError("Sorry, I was unable to save your route.  Please try again.");
	}

	this.formElementsToString = function (fromForm) {
		var ret = "";
		var ix = 0;
				
		for ( ix = 0;ix < fromForm.elements.length;ix++) {
			var theName = fromForm.elements[ix].name;
			var theValue = fromForm.elements[ix].value;
			if (theName == 'name' || theName == 'notes')
				theValue = URLEncode(theValue);
			ret = ret + theName + '=' + theValue + '&';
		}
		return ret;
	}
}

removeProgressDiv = function () {
	x = document.getElementById('progressDiv');
	document.body.removeChild(x);
}


