/**
 *
 *
 * The LexisNexis Professional API implementor employs a verb interface the same
 * as the Rosetta URL API. Setting the verb paramater dictates which Professional
 * API that MQ hits. There are the following verbs available:
 *
 *		- apisearch
 *      - apibrowse
 *      - hushlogin
 *      - logout
 *      - source
 *      - sourcelist
 * @constructor
 * @private
 */
function LNProfImp()
{
	throw new Error("LNProfImp is a static class. Do not instantiate.");
}

LNProfImp.DEFAULT_DOMAIN = "web.lexis-nexis.com/professional/";

LNProfImp.DEFAULT_VERB     = "apisearch";

// Create API Matrix
// The matrix is used to cast object elements into those used by the API.
LNProfImp.matrix          = new Object();

// Filter out MQ fields that we don't want in the query string
LNProfImp.matrix.pwd           = -1;
LNProfImp.matrix.uid           = -1;
LNProfImp.matrix.domain        = -1;
LNProfImp.matrix.protocol      = -1;
LNProfImp.matrix.lastName      = -1;
LNProfImp.matrix.firstName     = -1;
LNProfImp.matrix.companyName   = -1;
LNProfImp.matrix.ssn           = -1;
LNProfImp.matrix.streetAddress = -1;
LNProfImp.matrix.city          = -1;
LNProfImp.matrix.state         = -1;
LNProfImp.matrix.zip           = -1;
LNProfImp.matrix.apinoadf      = -1;

LNProfImp.matrix.verb          = -1;
LNProfImp.matrix.TOCTarget     = -1;	


// Describe which field names you need to cast into other values
// specific to the API.
LNProfImp.matrix.client          = "clientid";
LNProfImp.matrix.originationCode = "ORIGINATION_CODE";
LNProfImp.matrix.search          = "searchTerm";
LNProfImp.matrix.sort            = "sortby";

LNProfImp.matrix.fromDate        = "dateFrom";
LNProfImp.matrix.toDate          = "dateTo";
LNProfImp.matrix.after           = "dateRelative";


/**
 * This matric
 */
LNProfImp.submit = function(chunnel)
{
	LNProfImp._preprocessor(chunnel);
	
	var linker = LNProfImp.getLink(chunnel);

	// prompt("", linker)

	// If no target, set the target for the same window.
	if (!Truth.isTrue(chunnel.getTarget()))
	{
		chunnel.target = "_self";
	}
	
	var w;

	if (Truth.isTrue(chunnel.getPWD()))
	{
		var aT = "https://" + LNProfImp.DEFAULT_DOMAIN + "hushlogin";
 		aT = aT + "?USER_ID=" + chunnel.getUID();
 		aT = aT + "&PASSWORD=" + chunnel.getPWD();
 		if (Truth.isTrue(chunnel.get("keep")))
 		{
 			aT = aT + "&keep=" + chunnel.get("keep");
 		}
 		if (Truth.isTrue(chunnel.get("language")))
 		{
 			aT = aT + "&language=" + chunnel.get("language");
 		}
 		
 		if (chunnel.get("verb") == "hushlogin")
 		{
 			if (Truth.isTrue(chunnel.get("redirect")))
 			{
 				aT = aT + "&redirect=" + escape(chunnel.get("redirect"));
 			}
 		}
 		else
 		{
			aT = aT + "&redirect=" + escape(linker);
			
		}
		// prompt("", aT);
		w = window.open(aT, chunnel.target, NEW_WINDOW_FEATURES);
	}
	else
	{
		// prompt("", linker);
		// And send it on its merry way
		w = window.open(linker, chunnel.target, NEW_WINDOW_FEATURES);
	}
};

/**
 * Take any actions that need to be made on the MQ object before it gets
 * submitted to its specific API.
 */
LNProfImp._preprocessor =  function(chunnel)
{
	if (!Truth.isTrue(chunnel.get("verb")))
	{
		chunnel.set("verb", "apisearch")
	}
	return chunnel;
};

LNProfImp.getLink = function(chunnel)
{
	var domain = LNProfImp.DEFAULT_DOMAIN;

	if (Truth.isTrue(chunnel.getDomain()))
	{
		domain = chunnel.domain;
	}

	var action;

	if (Truth.isTrue(chunnel.override))
	{
		action = chunnel.override;
	}
	else
	{
		var verb = LNProfImp.DEFAULT_VERB;
		if (Truth.isTrue(chunnel.get("verb")))
		{
			verb = chunnel.get("verb");
		}

		action = chunnel.protocol + "//" + domain + verb;

	}
	
	var r = action + "?" + SearchImplementor.getQueryString(chunnel, LNProfImp.matrix);

	return r;

};
