var successString = "<!--Success-->"	//string that would be in a server's process response on a success

var ajaxTimeout = 8000					//number of milliseconds until the AJAX times out and returns an error

function submitForm(form, onSuccess, result,page)

{

//	button.disabled=true;

	result.innerHTML=getLoadingImageHTML()

	AjaxRequest.submit(

		form,

		{

			'url':page,

			'onSuccess':function(request) 

			 {

				//if we should perform the default action

				if(onSuccess == null)

				{

					result.innerHTML = request.responseText

					//if not success, enable the button

					/*if(!isSuccessMessage(request.responseText))

						button.disabled=false*/

				} 

				else 

				{

					onSuccess(request,result)

				}

			 },

			'onError':function(request){ alert('There was an error contacting the server. Please try again.'); result.innerHTML = "";},

			'timeout':ajaxTimeout,

			'onTimeout':function(request){ alert('The server has not responded in a while. Please try again.'); result.innerHTML = "";}

		}

	);

}



/**

 * Returns a string which includes the HTML and source information of an animation to be shown when something is being processed.

 */

function getLoadingImageHTML() {

	return '<!--Source of ../images/loading.gif: -->\n<p><img src="..\/images\/loading.gif" alt="Loading..." \/><\/p>'

}



/**

 * Returns the <span> which will say "Loading..." in the top right corner of the page.

 */

function getLoadingTextHTML() {

	return '<span class="loading">Loading...<\/span>'

}



/**

 * Returns whether the message sent by the server is a success message.

 */

function isSuccessMessage(message) {

	return message.indexOf(successString) != -1

}



//needed for AJAX and must be outside of the scope of the functions

var xmlHttpShowLogs			//for showing the logs

var xmlHttpSellItem			//for selling an item



//Returns an HTTP Request object

function GetXmlHttpObject() {

	var objXMLHttp=null

	if (window.XMLHttpRequest) {

		objXMLHttp=new XMLHttpRequest()

	}

	else if (window.ActiveXObject) 	{

		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")

	}

	if (objXMLHttp==null) {

		alert ("Your browser does not support HTTP Request. Please use an update-to-date browser which supports it, such as Internet Explorer 6+, Firefox, Opera, or Safara.")

	}

	return objXMLHttp

}


