// ************************************************************************************ //
//
// 
// ************************************************************************************ //

/* ************************************************************************** */
// Global parameters
/* ************************************************************************** */
var _FORM_SUBMIT_ENDPOINT = "./classes/ContactSubmission.php";

/* ************************************************************************** */
function submitForm( arg_string )
{
	//alert(arg_string);
	// TODO error checking (nulls, illegal chars, etc)
	var _args = arg_string.split("#|#");
	var _params = new Hash();
	for (var i = 0 ; i < _args.length ; i++)
	{
		if(_args[i] && _args[i].length > 0)
		{
			var _val = stripSpaces(_args[i]);
			var _pair = _args[i].split(":");
			if(_pair.length == 2)
			{
				_params[stripSpaces(_pair[0])] = stripSpaces(_pair[1]);
			}
		}
	}
	new Ajax.Request(_FORM_SUBMIT_ENDPOINT, 
					{ 
						method: 'post', 
						parameters: _params,
						onComplete: function(t) 
						{
	        				contactResponse(t.responseText);
	    				}
						
					}
					);

}

function contactResponse( str )
{
	var _swf = document.getElementById("whiterhinoswf");
	var i = 0;
	if(str == "SUCCESS")
	{
		_swf.submissionPassed("Thank you for your submission");
	}
	else if(str.indexOf("ERROR") == 0)
	{
		_swf.submissionFailed(str.slice(6));
	}
	else
	{ 
		_swf.submissionFailed(str);
	}
}

function stripSpaces( str ) 
{
	if(str && str.length > 0)
	{
    	return  str.replace(/^\W+/,'').replace(/\W+$/,'');
	}	
}