var ESLinkInterfaceUrl = "http://energizedseller.com/ESLinkInterface.ashx";

var _reqObject = null;

// create XMLHttpRequest request
function createXMLHttpRequest()
{
	if ( window.XMLHttpRequest ) // IE7 and other modern browsers
	{
		try { return new window.XMLHttpRequest(); }
		catch(e) { alert("window.XMLHttpRequest failed" + e.message); }
	}
	else // old IE
	{
		try { return new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) {}
		try { return new ActiveXObject("Microsoft.XMLHTTP"); }
		catch (e) {alert("Your browser doesn't support functions necessary for complete Aliveguide interaction.\n"
			+ "Internet Explorer 6+ and Firefox 2+ have been tested and are recommended.\n\n" + e.message);}
	}
}


function FileDownload(fileID)
{
	if (!_reqObject) _reqObject = createXMLHttpRequest();
	if (!_reqObject) return;

	/* send to ESLinkInterface */
	_reqObject.open("GET", ESLinkInterfaceUrl + "?op=download&fileid=" + fileID, false);
	_reqObject.send( null );
	
	if(_reqObject.responseText)
	{
		var pair = GetNVPair(_reqObject.responseText);

		if (pair[0].toLowerCase() == 'url')
		{   // redirect to returned url
			if (pair[1])
				window.location = pair[1];
		}

		if (pair[0].toLowerCase() == 'msg')
		{	// show message
			if (pair[1])
				alert(pair[1]);
		}

		if (pair[0].toLowerCase() == 'fdmodal')
		{	// show modal dialog
			var str = pair[1];
			Telligent_Modal.Open(str, 450, 250, null);
		}
    	}
}

// splits the input at the first '=' character and returns the two halves in an array.
function GetNVPair(input)
{
	var result = new Array(2);
	var pos = input.indexOf('=');
	if (pos > 0){
		result[0] = input.slice(0, pos);
		result[1] = input.substring(++pos);}
	return result;
}