// copyright 2001-2009 DTLink, L.L.C. all rights reserved.
// http://www.formvista.com
//
// for use in event chains.

if ( typeof( fv_ajaxLoadUrl ) == 'undefined' )
	{

function fv_ajaxLoadUrl( parms )
{

var elem = parms.elem;
var href = parms.href;

// if there is a payload, apply the payload to the href to 
// process any optional client side $[var] references.

if ( typeof( $(elem).data( "_fv_payload" ) ) != 'undefined' )
	{
	var payload = $(elem).data( "_fv_payload" );

	// now replace any $[] references in the content with their
	// corresponding values.

	$.each( payload, function(i, val)
		{ 

		exp = "\\$\\[" + i + "\\]";

		href = href.replace( new RegExp( exp, "g" ), val );

		} );

	// remove any template variables left over.

	exp = "\\$\\[.*?\\]";
	href = href.replace( new RegExp( exp, "g" ), "" );

	}

// using a closure to pass through the element.

var ajaxParms = 
	{
	type: 'GET',
	cache: false,

	// callback on success

	success: function( JSONresponse, statusText ) 
		{

		if ( JSONresponse.error != '' )
			{
			alert( JSONresponse.error );
			return false;
			}

		// pass the JSON response on to other callbacks in the chain

		$( elem ).data( "_fv_payload", JSONresponse );

		// check the return code from JSON.

		return fv_continueJSChain( elem );

		},

	// callback on error

	error: function( XMLHttpRequest, textStatus, errorThrown ) 
		{
		alert( "ERROR - " + textStatus );

		return false;
		},

	timeout:   25000,

	// without this, sends and HTTP_ACCEPT header of */*

	dataType: 'json',
	elem: elem,
	url: href
	};

$.ajax( ajaxParms );

return false;

}

	}
