// caseDetail.js

function winPopup(type,id) { 
	 var url = "/lx1/caselaw/freecaselaw?action=FCLRedirectCapture&module=L&loc=fclfull&FCLRedirectURL=";
     var rurl = escape("http://web.lexis.com/xchange/search/xlinkweb.asp?searchType=" + type + "&search=" + id + "&loc=LEX1FREE");
     url = url + rurl;
     window.open(url, 'LexisNexisbyCreditCard');
}	

function openWin(isln) { 
	window.open("http://www.martindale.com/marhub/isln/"+isln+"?PRV=LEO",""); 
}

function detail(docID, handle, limit, totalCount, searchTerm, juri, citation, source) {
var url="/lx1/caselaw/freecaselaw?action=FCLRetrieveCaseDetail&caseID="+docID+"&format=FULL&resultHandle="+handle+"&pageLimit="+limit+"&xmlgTotalCount="+totalCount;
var cst = URLEncode(searchTerm);
if( cst != null && cst.length > 0 )
{    
url +="&combinedSearchTerm="+ cst+"&juriName=" + escape(juri)+"&sourceFile="+source;
}
else
{
url+= "&citation="+escape(citation);
}
window.location=url;
}

function URLEncode(searchTerm)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < searchTerm.length; i++ ) {
		var ch = searchTerm.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for
 return encoded;
}

