/**
 * Please use ppcmixed2/ppccpwd77 as id/pwd for uk/legal.
 *
 * http://www.lexisnexis.com/uk/legal/api/version1/sr?csi=267991&sr=police and legal&hd=t
 * @constructor
 * @private
 */
function UrlApiPubRecImp()
{
	throw new Error("UrlApiPubRecImp is a static class. Do not instantiate.");
}

UrlApiPubRecImp.DEBUG            = true;

UrlApiPubRecImp.DEFAULT_DOMAIN       = "www.lexisnexis.com";
UrlApiPubRecImp.DEFAULT_NEXIS_DOMAIN = "w3.nexis.com";
//UrlApiPubRecImp.DEFAULT_DOMAIN       = "cdc1-www.lexisnexis.com";
//UrlApiPubRecImp.DEFAULT_NEXIS_DOMAIN = "cdc1-www.lexisnexis.com";
UrlApiPubRecImp.DEFAULT_ADAPTION     = "uk";
UrlApiPubRecImp.DEFAULT_TYPE         = "legal";
UrlApiPubRecImp.DEFAULT_API_VERSION  = "api";
UrlApiPubRecImp.DEFAULT_VERB         = "sr";

// Create API Matrix
// The matrix is used to cast object elements into those used by the API.
UrlApiPubRecImp.matrix          = new Object();

// Filter out MQ fields that we don't want in the query string

UrlApiPubRecImp.matrix.adaption   = -1;
UrlApiPubRecImp.matrix.domain     = -1;
UrlApiPubRecImp.matrix.protocol   = -1;
UrlApiPubRecImp.matrix.type       = -1;
UrlApiPubRecImp.matrix.apiVersion = -1;
UrlApiPubRecImp.matrix.verb       = -1;
UrlApiPubRecImp.matrix.searchtype = -1;
UrlApiPubRecImp.matrix.TOCTarget     = -1;	

UrlApiPubRecImp.matrix.host       = -1;


UrlApiPubRecImp.matrix.pwd    = -1;
UrlApiPubRecImp.matrix.uid    = -1;
// UrlApiPubRecImp.matrix.pwd    = "pw";
// UrlApiPubRecImp.matrix.uid    = "ui";

// These fields don't exist in Rosetta
UrlApiPubRecImp.matrix.maxdocs  = -1;
UrlApiPubRecImp.matrix.zone     = -1;
UrlApiPubRecImp.matrix.citation = -1;
UrlApiPubRecImp.matrix.prod     = -1;


// Describe which field names you need to cast into other values
// specific to the API.

UrlApiPubRecImp.matrix.originationCode = "ORIGINATION_CODE";
UrlApiPubRecImp.matrix.client = "pi";
UrlApiPubRecImp.matrix.search = "query";

UrlApiPubRecImp.matrix.source = "csi";
UrlApiPubRecImp.matrix.sort   = "so";

// DOSSIER FIELDS
UrlApiPubRecImp.matrix.ticker = "tr";
UrlApiPubRecImp.matrix.name   = "nm";

// api.universe/search/searchform
UrlApiPubRecImp.matrix.id     = -1;
UrlApiPubRecImp.matrix.authToken       = "uisToken";

/**
 * Takes a chunnel object and submits it. The last step in the journey
 * of a chunnel object before it becomes a LN search result.
 */
UrlApiPubRecImp.submit = function(chunnel)
{
    //Workaround for sites that are incorrectly setting the actual parameters rather than the generic uid and pwd fields.
    if (((Truth.isTrue(chunnel.get("ui"))) || (Truth.isTrue(chunnel.get("pw")))) && (chunnel.get("verb") != "activate"))
    {
        chunnel.uid = chunnel.get("ui");
        chunnel.pwd = chunnel.get("pw");
        chunnel.set("ui", "");
        chunnel.set("pw", "");
    }
    
    if ((Truth.isTrue(chunnel.uid)) || (Truth.isTrue(chunnel.pwd)))
        chunnel = SearchImplementor.tokenize(chunnel);

	try
	{

        
		// Preprocessor needs to convert generic after field 
		// to XLink's relativedate field
		UrlApiPubRecImp.preprocessor(chunnel);

		// If no target, set the target for the same window.	
		if (!Truth.isTrue(chunnel.target))
		{
			chunnel.target = "_self";
		}
		
		if (chunnel.get("verb") == "au")
		{
			UrlApiPubRecImp._submitAu(chunnel);
			return;
		}
		
		var linker = UrlApiPubRecImp.getLink(chunnel);
		
		if (!Truth.isTrue(chunnel.pwd) || Truth.isTrue(chunnel.override)) 
		{
			var w = window.open(linker, chunnel.target, NEW_WINDOW_FEATURES); 
		}
		else
		{
			var f = "<form method='post' action='";
			f += linker;
			f += "' id='masterQueryDynaForm' name='masterQueryDynaForm' target='";
			f += chunnel.target;
			f += "'>";
			f += FormUtil.getHiddenFieldVal('ui', chunnel.getUID());
			f += FormUtil.getHiddenFieldVal('pw', chunnel.getPWD());
			f += FormUtil.getHiddenFieldVal('rm', chunnel.get("rm"));
			f += "</form>";

			SearchImplementor.submitDiv(f);
		}
		
		chunnel = null;
	}
	catch(ex)
	{
		if (UrlApiPubRecImp.DEBUG)
		{
			alert(ex.message)
		}
	}
};

UrlApiPubRecImp.libfileToCSI = function(libfile)
{
	if (libfile.lastIndexOf(";") != -1) {
		var http = new HttpRequest();
		http.setTarget(MasterQuery.baseURL + "getCSI.asp");
		http.setForm(new URLBuilder("libfile", libfile))
		var csi = http.get();
		if (csi)
		{
			return csi;
		}		
	} 
	return libfile;
}

/**
 * Submit using the authentication verb
 */
UrlApiPubRecImp._submitAu =  function(chunnel)
{

    chunnel.setProtocol("https:")

	var f = "<form method='get' action='";
	f += UrlApiPubRecImp.getLink(chunnel);
	f += "' id='masterQueryDynaForm' name='masterQueryDynaForm' target='";
	f += chunnel.target;
	f += "'>";
	f += FormUtil.getHiddenFieldVal('ui', chunnel.getUID());
	f += FormUtil.getHiddenFieldVal('pw', chunnel.getPWD());
	// f += FormUtil.getHiddenFieldVal('rt', chunnel.get("rt"));
	// f += FormUtil.getHiddenFieldVal('rm', chunnel.get("rm"));
	// f += FormUtil.getHiddenFieldVal('pi', chunnel.getClient());
	
	f += "</form>";
	
	SearchImplementor.submitDiv(f);
}

UrlApiPubRecImp._submitSo =  function(chunnel)
{
	window.open(UrlApiPubRecImp.getVerbPath(chunnel), 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.
 */
UrlApiPubRecImp.preprocessor =  function(chunnel)
{
    var stateList = new Array();
    //State Abbreviations
    stateList[0] = "AL";
	stateList[1] = "AK";
	stateList[2] = "AZ";
	stateList[3] = "AR";
	stateList[4] = "CA";
	stateList[5] = "CO";
	stateList[6] = "CT";
	stateList[7] = "DE";
	stateList[8] = "DC";
	stateList[9] = "FL";
	stateList[10] = "GA";
	stateList[11] = "GU";
	stateList[12] = "HI";
	stateList[13] = "ID";
	stateList[14] = "IL";
	stateList[15] = "IN";
	stateList[16] = "IA";
	stateList[17] = "KS";
	stateList[18] = "KY";
	stateList[19] = "LA";
	stateList[20] = "ME";
	stateList[21] = "MD";
	stateList[22] = "MA";
	stateList[23] = "MI";
	stateList[24] = "MN";
	stateList[25] = "MS";
	stateList[26] = "MO";
	stateList[27] = "MT";
	stateList[28] = "NE";
	stateList[29] = "NV";
	stateList[30] = "NH";
	stateList[31] = "NJ";
	stateList[32] = "NM";
	stateList[33] = "NY";
	stateList[34] = "NC";
	stateList[35] = "ND";
	stateList[36] = "OH";
	stateList[37] = "OK";
	stateList[38] = "OR";
	stateList[39] = "PA";
	stateList[40] = "PR";
	stateList[41] = "RI";
	stateList[42] = "SC";
	stateList[43] = "SD";
	stateList[44] = "TN";
	stateList[45] = "TX";
	stateList[46] = "UT";
	stateList[47] = "VT";
	stateList[48] = "VA";
	stateList[49] = "VI";
	stateList[50] = "WA";
	stateList[51] = "WV";
	stateList[52] = "WI";
	stateList[53] = "WY";

    var stateSourceList = new Array(new Array(54), new Array(54));
    //Old Person Sources
    stateSourceList[0][0] = "314663";
    stateSourceList[0][1] = "314658";
    stateSourceList[0][2] = "314669";
    stateSourceList[0][3] = "314666";
    stateSourceList[0][4] = "314673";
    stateSourceList[0][5] = "314675";
    stateSourceList[0][6] = "314678";
    stateSourceList[0][7] = "314684";
    stateSourceList[0][8] = "314681";
    stateSourceList[0][9] = "314687";
    stateSourceList[0][10] = "314690";
    stateSourceList[0][11] = "314692";
    stateSourceList[0][12] = "314695";
    stateSourceList[0][13] = "314711";
    stateSourceList[0][14] = "314713";
    stateSourceList[0][15] = "314715";
    stateSourceList[0][16] = "314709";
    stateSourceList[0][17] = "314717";
    stateSourceList[0][18] = "314719";
    stateSourceList[0][19] = "314721";
    stateSourceList[0][20] = "314727";
    stateSourceList[0][21] = "314725";
    stateSourceList[0][22] = "314723";
    stateSourceList[0][23] = "314729";
    stateSourceList[0][24] = "314731";
    stateSourceList[0][25] = "314736";
    stateSourceList[0][26] = "314734";
    stateSourceList[0][27] = "314821";
    stateSourceList[0][28] = "314748";
    stateSourceList[0][29] = "314758";
    stateSourceList[0][30] = "314751";
    stateSourceList[0][31] = "314753";
    stateSourceList[0][32] = "314756";
    stateSourceList[0][33] = "314761";
    stateSourceList[0][34] = "314742";
    stateSourceList[0][35] = "314745";
    stateSourceList[0][36] = "314763";
    stateSourceList[0][37] = "314765";
    stateSourceList[0][38] = "314767";
    stateSourceList[0][39] = "314769";
    stateSourceList[0][40] = "314772";
    stateSourceList[0][41] = "314829";
    stateSourceList[0][42] = "314777";
    stateSourceList[0][43] = "314782";
    stateSourceList[0][44] = "314786";
    stateSourceList[0][45] = "314788";
    stateSourceList[0][46] = "314790";
    stateSourceList[0][47] = "314796";
    stateSourceList[0][48] = "314792";
    stateSourceList[0][49] = "314794";
    stateSourceList[0][50] = "314798";
    stateSourceList[0][51] = "314802";
    stateSourceList[0][52] = "314800";
    stateSourceList[0][53] = "314804";

    //Old Business sources
    stateSourceList[1][0] = "314661";
    stateSourceList[1][1] = "314652";
    stateSourceList[1][2] = "314668";
    stateSourceList[1][3] = "314665";
    stateSourceList[1][4] = "314671";
    stateSourceList[1][5] = "314674";
    stateSourceList[1][6] = "314677";
    stateSourceList[1][7] = "314683";
    stateSourceList[1][8] = "314680";
    stateSourceList[1][9] = "314685";
    stateSourceList[1][10] = "314688";
    stateSourceList[1][11] = "314691";
    stateSourceList[1][12] = "314694";
    stateSourceList[1][13] = "314710";
    stateSourceList[1][14] = "314712";
    stateSourceList[1][15] = "314714";
    stateSourceList[1][16] = "314708";
    stateSourceList[1][17] = "314716";
    stateSourceList[1][18] = "314718";
    stateSourceList[1][19] = "314720";
    stateSourceList[1][20] = "314726";
    stateSourceList[1][21] = "314724";
    stateSourceList[1][22] = "314722";
    stateSourceList[1][23] = "314728";
    stateSourceList[1][24] = "314730";
    stateSourceList[1][25] = "314735";
    stateSourceList[1][26] = "314733";
    stateSourceList[1][27] = "314738";
    stateSourceList[1][28] = "314747";
    stateSourceList[1][29] = "314757";
    stateSourceList[1][30] = "314750";
    stateSourceList[1][31] = "314752";
    stateSourceList[1][32] = "314754";
    stateSourceList[1][33] = "314760";
    stateSourceList[1][34] = "314739";
    stateSourceList[1][35] = "314743";
    stateSourceList[1][36] = "314762";
    stateSourceList[1][37] = "314764";
    stateSourceList[1][38] = "314766";
    stateSourceList[1][39] = "314768";
    stateSourceList[1][40] = "314770";
    stateSourceList[1][41] = "314773";
    stateSourceList[1][42] = "314775";
    stateSourceList[1][43] = "314780";
    stateSourceList[1][44] = "314783";
    stateSourceList[1][45] = "314787";
    stateSourceList[1][46] = "314789";
    stateSourceList[1][47] = "314795";
    stateSourceList[1][48] = "314791";
    stateSourceList[1][49] = "314793";
    stateSourceList[1][50] = "314797";
    stateSourceList[1][51] = "314801";
    stateSourceList[1][52] = "314799";
    stateSourceList[1][53] = "314803";

    for (var i=0; i<54;i++)
    {
        if ((chunnel.getSource() == stateSourceList[0][i]) || (chunnel.getSource() == stateSourceList[1][i]))
            chunnel.set("State", stateList[i]);
    }
    
	if (!Truth.isTrue(chunnel.get("glba")))
	{
		chunnel.set("glba", "7");
	}
	if (!Truth.isTrue(chunnel.get("dppa")))
	{
		chunnel.set("dppa", "7");
	}
	if (!Truth.isTrue(chunnel.get("goto")))
	{
		chunnel.set("goto", "results");
	}
	if (!Truth.isTrue(chunnel.get("adaption")))
	{
		chunnel.set("adaption", UrlApiPubRecImp.DEFAULT_ADAPTION);
	}
	
	format = "us";
	
	if (chunnel.get("adaption") != "nexis")
	{
		format = "uk";
	}

	chunnel = LNParser.convertDateToQuery(chunnel, format);
	
	if (Truth.isTrue(chunnel.getSort()))
	{
		chunnel.setSort("da");
	}
	
	if (Truth.isTrue(chunnel.pwd))
	{
		// not working for auth
		// chunnel.protocol = "https:";
	}
	
	if (!Truth.isTrue(chunnel.get("type")))
	{
		chunnel.set("type", UrlApiPubRecImp.DEFAULT_TYPE);
	}
	
	if (!Truth.isTrue(chunnel.get("verb")))
	{
		chunnel.set("verb", UrlApiPubRecImp.DEFAULT_VERB);
	}
	
	//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
	// Auto-convert libfile to CSI numbers
	
	chunnel.setSource(UrlApiPubRecImp.libfileToCSI(chunnel.getSource()));
	
	//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
	// LEXSEE & LEXSTAT
	
	var type = chunnel.getSearchtype();
	
	switch(type)
	{
		case "get":
		case "lexsee":
		case "lxe":
		case "lexstat":
		
			// Make sure that the source isn't already set
			if (!Truth.isTrue(chunnel.getSource())) 
			{
				// http://psc744:6060/ssdf/guide/dynmff/bin/dynmff.pl?type=library&csi=12660&lvl=3
				// Source: MEGA
				// chunnel.setSource("12660")
				chunnel.setSource("138150")
				// 
			}
			break;
	
		default:
			break;
	}
	
	//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
	// CUI BUILDER CITATION
	
	// &citation=1+us+1
	if (Truth.isTrue(chunnel.get("citation")))
	{
		if (!Truth.isTrue(chunnel.getSource()) && !Truth.isTrue(chunnel.getSearch()))
		{
			chunnel.setSearch(chunnel.get("citation"))
			chunnel.setSource("12660")
		} 
	}
	
	//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
	// Nexis searchforms
	
	if (chunnel.get("id")) 
	{

		chunnel.set("verb", "sf")
		
		switch(chunnel.get("id"))
		{
			// Power Search
			case "-99":
				chunnel.set("sfi", "US00NBGenSrch");
				break;
			// US Reports // Company Profile Page
			case "1928":
				chunnel.set("sfi", "US02NBCmpSrch");
				break;
			// SEC Filings
			case "1940":
			case "2378":
				chunnel.set("sfi", "US02NBSECFilSrch");
				break;
			// Mergers & Acquisitions 
			case "1945":
				chunnel.set("sfi", "US02NBMergAcqSrch");
				break;
			// Business Locator/Assets
			case "1930":
				chunnel.set("sfi", "US04NBBusLocSrch");
				break;
			// Asset Locator
			case "2515":
				chunnel.set("sfi", "US04NBAssetLocSrch");
				break;
			// Bankruptcy Filings
			case "1375":
			case "2517":
				chunnel.set("sfi", "US04NBBankrupSrch");
				break;	
			// Judgments
			case "2519":
				chunnel.set("sfi", "US04NBJudLiensSrch");
				break;
			// Licenses
			case "2522":
				chunnel.set("sfi", "US04NBLicensesSrch");
				break;
			// Civil &amp; Criminal Filings
			case "2523":
				chunnel.set("sfi", "US04NBCivCrimSrch");
				break;	
			// D&B
			case "2524":
				chunnel.set("sfi", "US02NBDunBradSrch");
				break;
			// Motor Vehicles Registrations 
			case "2727":
				chunnel.set("sfi", "US04NBDriverSrch");
				break;
			// Motor Vehicle Registrations
			case "2729":
				chunnel.set("sfi", "US04NBMotVehSrch");
				break;
			// General News 
			case "2888":
				chunnel.set("sfi", "US01NBSimplSrch");
				break;
			// Edgar - SEC Real Time Filings
			case "2911":
				chunnel.set("sfi", "US02NBEdgarSrch");
				break;
		}
	}

	return chunnel;
};




/**
 * Returns the link that is the target for the API call.
 * This can be used as the action for a form or as the location
 * for a called to window.open.
 *
 * The query string is return based upon the chunnel values filtered 
 * through the implementor's matrix
 */
UrlApiPubRecImp.getLink = function(chunnel)
{
    var xml
    xml = UrlApiPubRecImp.getXML(chunnel);
    chunnel.setSearch(xml);
    chunnel.set("ssl", "t");

	var qs = SearchImplementor.getQueryString(chunnel, UrlApiPubRecImp.matrix);
	
	if (Truth.isTrue(qs))
	{
		return UrlApiPubRecImp.getVerbPath(chunnel) + "?" + qs;
	}
	else
	{
		return UrlApiPubRecImp.getVerbPath(chunnel);
	}
};

/**
 * Returns the link that is the target for the API call.
 * This can be used as the action for a form or as the location
 * for a called to window.open.
 *
 * The query string is return based upon the chunnel values filtered 
 * through the implementor's matrix
 */
UrlApiPubRecImp.getVerbPath = function(chunnel)
{
	var domain = UrlApiPubRecImp.DEFAULT_DOMAIN;

	if (chunnel.domain && chunnel.domain !== "") 
	{
		domain = chunnel.domain;
	}
	
	if (chunnel.domain !== "" && chunnel.get("adaption") == "nexis")
	{
		domain = UrlApiPubRecImp.DEFAULT_NEXIS_DOMAIN;
	}

	if (chunnel.domain && chunnel.domain !== "") 
	{
		domain = chunnel.domain;
	}
	
	if (Truth.isTrue(chunnel.override))
	{
		return chunnel.override;
	}
	else
	{
		var adaption = chunnel.get("adaption")
		
		if (adaption == "nexis")
		{
			adaption = "new"
		}
		
	    chunnel.setProtocol("https:");

		var adLink = chunnel.protocol + "//" + domain + "/" + adaption;
	
		if (chunnel.get("adaption") != "nexis")
		{
			adLink += "/" + chunnel.get("type")
		}
		
		if (chunnel.get("verb") == "home")
		{
			return adLink + "/home/home.do";
		}
		else
		{
			var apiVersion = UrlApiPubRecImp.DEFAULT_API_VERSION;
			
			if (chunnel.get("verb") == "accessGW") {
				var apiVersion = "api";
			}
			
			if (Truth.isTrue(chunnel.get("apiVersion")))
			{
				apiVersion = chunnel.get("apiVersion");
			}

			return adLink + "/" + apiVersion + "/" + chunnel.get("verb");	
		}
	}
};

UrlApiPubRecImp.getXML = function(chunnel)
{
	var xml = '<fieldList>';
	xml += UrlApiPubRecImp.checkPRMAField("Fname", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("Lname", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("Mname", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("Street", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("City", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("Zip", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("Radius", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("Phone", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("SSN", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("DOB", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("AgeLow", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("AgeHigh", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("Terms", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("aliasLName", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("RelFName1", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("RelFname2", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("RelFName2", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("PrevCity", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("PrevState1", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("PrevState2", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("UsePhonetics", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("Cname", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("FEIN", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("ParcelId", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("Vin", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("Plate", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("Make", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("Model", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("License", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("Hull", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("Vname", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("OfficialNumber", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("AircraftNumber", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("CaseNumber", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("FilingDate", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("Status", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("PRMAType", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("Assets", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("Liabilities", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("DocumentNumber", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("AccNumber", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("LicNumber", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("FullName", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("OtherName", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("Country", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("County", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("FilingNumber", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("FilingJurisdiction", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("PRMADomain", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("IssuedState", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("Trade", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("LoanAmount", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("LoanAmountOperator", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("LoanAmountHighValue", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("SalePrice", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("SalePriceOperator", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("SalePriceHighValue", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("LandValue", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("LandValueOperator", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("LandValueHighValue", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("TaxAmount", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("TaxAmountOperator", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("TaxAmountHighValue", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("PRMASource", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("BooleanMode", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("UseNicknames", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("StrictMatch", chunnel);
	xml += UrlApiPubRecImp.checkPRMAField("PRMASearchType", chunnel);
	xml += UrlApiPubRecImp.checkPRMAField("FindRegisteredAgents", chunnel);
    xml += UrlApiPubRecImp.checkPRMAField("InspectedSiteName", chunnel);

    if ((xml == '<fieldList>') || (xml == '<fieldList><field name="BooleanMode">True</field>'))
    {
        chunnel.set("goto", "form");
    }

    xml += UrlApiPubRecImp.checkPRMAField("State", chunnel);

    //alert(xml + '</fieldList>');

    return xml + '</fieldList>';
};

UrlApiPubRecImp.checkPRMAField = function(name, chunnel)
{
    var booleanSourceList = new Array(24);
    //Sources which accept the Terms field
    booleanSourceList[0] = "314679";
    booleanSourceList[1] = "314682";
    booleanSourceList[2] = "314689";
    booleanSourceList[3] = "314023";
    booleanSourceList[4] = "314696";
    booleanSourceList[5] = "314697";
    booleanSourceList[6] = "314699";
    booleanSourceList[7] = "314700";
    booleanSourceList[8] = "314737";
    booleanSourceList[9] = "314827";
    booleanSourceList[10] = "314749";
    booleanSourceList[11] = "314825";
    booleanSourceList[12] = "314784";
    booleanSourceList[13] = "314785";
    booleanSourceList[14] = "314813";
    booleanSourceList[15] = "314814";
    booleanSourceList[16] = "314816";
    booleanSourceList[17] = "314817";
    booleanSourceList[18] = "314844";
    booleanSourceList[19] = "314819";
    booleanSourceList[20] = "314820";
    booleanSourceList[21] = "314822";
    booleanSourceList[22] = "314823";
    booleanSourceList[23] = "314473";

    var isBoolSource = false;
    
    for (var j=0; j<24;j++)
    {
        if ((chunnel.getSource() == booleanSourceList[j]))
        {
            isBoolSource = true;
            break;
        }
    }
    if (!isBoolSource && (name == "Terms"))
    {
   	    eval("UrlApiPubRecImp.matrix." + name + "     = -1;")
        return "";
    }
            
    var finalName = name;

    if (finalName.search("PRMA") == 0)
        finalName = finalName.slice(4);
    
    var val;
    val = "";
    if (Truth.isTrue(chunnel.get(name))) 
    {
	    val = UrlApiPubRecImp.getPRMAField(chunnel.get(name), finalName);
	    eval("UrlApiPubRecImp.matrix." + name + "     = -1;")
    }
    if (Truth.isTrue(chunnel.get(name.toLowerCase()))) 
    {
	    val = UrlApiPubRecImp.getPRMAField(chunnel.get(name.toLowerCase()), finalName);
	    eval("UrlApiPubRecImp.matrix." + name.toLowerCase() + "     = -1;")
    }
    if (Truth.isTrue(chunnel.get(name.toUpperCase()))) 
    {
	    val = UrlApiPubRecImp.getPRMAField(chunnel.get(name.toUpperCase()), finalName);
	    eval("UrlApiPubRecImp.matrix." + name.toUpperCase() + "     = -1;")
    }
    if ((name.toUpperCase() == "TERMS") && (val != ""))
    {
	    val = val + UrlApiPubRecImp.getPRMAField("True", "BooleanMode");
	    UrlApiPubRecImp.matrix.BooleanMode     = -1;
    }

    return val
}
UrlApiPubRecImp.getPRMAField = function(value, name)
{
    if (name != "DOB" && name != "LoanAmountOperator" && name != "TaxAmountOperator" && name != "LandValueOperator" && name != "SalePriceOperator")
	    value = value.replace(/[^a-zA-Z0-9*!_:/()\-]/g, " ");
	
	return '<field name="' + name + '">' + value + '</field>';

};

