
var SdEcHitListSimilarEntities = {};		// public  global identifiers
var $_EcHitListSimilarEntities = {};		// private global identifiers

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

$_EcHitListSimilarEntities.loadSimilarAuthors = function (elementId)
{
	var label = SdEcValues.getTranslation("Similar Authors");
	$_EcHitListSimilarEntities.loadSimilarEntities(elementId, "author", "getSimilarAuthors", label);	// "SIMILAR-AUTHORS");
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

$_EcHitListSimilarEntities.loadSimilarTitles = function (elementId)
{
	var label = SdEcValues.getTranslation("Similar Titles");
	$_EcHitListSimilarEntities.loadSimilarEntities(elementId, "title", "getSimilarTitles", label);	// "SIMILAR-TITLES");
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

$_EcHitListSimilarEntities.loadSimilarEntities = function (elementId, entity, subroutine, label)
{
	var ord     = SdEcSpecifics.getSpecific(elementId,  "ord");
	var downGif = SdEcSpecifics.getSpecific(elementId, "dgif");
	var wc_url  = SdEcSpecifics.getSpecific(elementId, "wurl");
	var session = SdEcSpecifics.getSpecific(elementId, "wses");
	var isbns   = SdEcSpecifics.getSpecific(elementId, "isbn");

	var isbn=isbns.split(",")[0];

	var urla = SdEcSpecifics.getSpecific(elementId, "urla");
	var urlt = SdEcSpecifics.getSpecific(elementId, "urlt");
	var prof = SdEcSpecifics.getSpecific(elementId, "prof");
	var pswd = SdEcSpecifics.getSpecific(elementId, "pswd");

	if (isbn != isbns)
	{
		urla = urla.replace(isbns,isbn);
		urlt = urlt.replace(isbns,isbn);
	}

	// fixup url -- substitute (parameter, property and/or attribute) values
	// for the {holes} in the url template -- add proxy prefix

	urla = SdCommon.proxify(urla);
	urlt = SdCommon.proxify(urlt);

	var element = document.getElementById(elementId);

	var arrowNode  = document.createElement("img");
	arrowNode.setAttribute("src",downGif);
	arrowNode.alt = SdEcValues.getTranslation("Expand Icon");	// "Action Image";

	var anchorNode = document.createElement("a");
	anchorNode.id = "novelist_similar_" + entity + "_link" + ord;
	var hrefAsText = "javascript:" + subroutine + "("
		+ "'" +   ord   + "'" + "," 
//		+ (subroutine == "getSimilarTitles" ? "'" + wc_url  + "'" + "," : "")
//		+ (subroutine == "getSimilarTitles" ? "'" + session + "'" + "," : "")
		+ "'" + wc_url  + "'" + ","
		+ "'" + session + "'" + ","
		+ "'" + isbn    + "'" + "," 
		+ "'" + urla    + "'" + ","
		+ "'" + urlt    + "'" + "," 
		+ "'" + prof    + "'" + "," 
		+ "'" + pswd    + "'" + ")";
	anchorNode.setAttribute("href", hrefAsText);
	
	var textNode = document.createTextNode(label);

	anchorNode.appendChild( arrowNode);
	anchorNode.appendChild(  textNode);
	element   .appendChild(anchorNode);
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SdEcEngine.registerTypeHandler("hit-list-similar-authors", $_EcHitListSimilarEntities.loadSimilarAuthors);
SdEcEngine.registerTypeHandler("hit-list-similar-titles" , $_EcHitListSimilarEntities.loadSimilarTitles );


