<!--

/************************************
**	doccontext.js                  **
**                                 **
*************************************/

// Document header truncating system:
// 
// If the text of the header is too long to fit in the frame between images, it
// will be automatically truncated from last part and will be given a ... line. 
// The entire text (header) will display as they hover on ...
//
// This JavaScript file is called from doccontext.wl

function displayTruncatedTitle(strLine,gifBase){

	// Get the header for future use.

	var strAgain;
	strAgain = strLine;

// ============================================================
// If the string is too long, chop some off
// ============================================================	
	endingposition = lastletterindex(strLine);
	if(endingposition >= strLine.length) {
		findLastWords = -1;
	} else {
		findLastWords = strLine.lastIndexOf(" ", endingposition);
	}
	// Time to chop those words off now
	if (findLastWords != -1){
		strLine = strLine.slice(0, findLastWords);
	}	
// ===========================================================
// Show the full string if the it wraps as ALT in image
//============================================================
		
		// Modal dialog does not refresh itself in IE 5.5 and less.
		// For this reason, some documents in the link viewer truncates 
		// only 1 or 2 characters as we can not get the correct calcuation
		// of the length of the headers and window. So, we are not showing
		// any image ALT hover for those cases.
	document.write(strLine);	
	if (findLastWords != -1) {
		// Remove uneccessary white space
		strAgain = strAgain.replace(/\s+/g, " ");
		
		document.write("<img border='0' src='"+gifBase+"/images/dot.gif' Alt=");
		document.write('"' + strAgain + '"');
		document.write("Title=" + '"' + strAgain + '"');
		document.write("width='28' height='8'>");
	}
}
	
	
function lastletterindex(strLine) {

//============================================================
// widthOfWindow = how wide the window is in pixels
//============================================================
	
	// IE with Windows
	if (navigator.appName == 'Microsoft Internet Explorer'){
		widthOfWindow = parseInt(document.body.offsetWidth);
	}	
	// Netscape or other browsers
	else{
		widthOfWindow = parseInt(window.innerWidth);
		}

	// The center <TD> is 74% of the width.
	widthOfWindow = widthOfWindow*74/100;
		
	var pixelsOfLetter = pixelsofletter(strLine);
		
	var findLastWords;
	var lastLetterIndex;
	
	
		// Find the end of the last word that fits
		// IE with Windows OS
		if (navigator.appName == 'Microsoft Internet Explorer' && (navigator.platform.toLowerCase().indexOf("mac") == -1)){
			lastLetterIndex=(parseInt(widthOfWindow / pixelsOfLetter)-2);
		}
	
		// Netscape 4.x
		else if (((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4) && (parseInt(navigator.appVersion) < 5) )){
			lastLetterIndex=(parseInt(widthOfWindow / pixelsOfLetter)-3);
		}
	
		// Microsoft Internet Explorer with MAC
		else if (navigator.appName == 'Microsoft Internet Explorer' && (navigator.platform.toLowerCase().indexOf("mac") == 0)){
			lastLetterIndex=(parseInt(widthOfWindow / pixelsOfLetter)-3);
		}
	
		//Netscape 6.x & other browsers.
		else{
			lastLetterIndex=(parseInt(widthOfWindow / pixelsOfLetter)-3);
		}		
	return lastLetterIndex;
}


function pixelsofletter(strLine) {
	//============================================================
// pixelsOfLetter determines how many pixels are used per character 
// in calculations below. it probably can use some tweaking
//============================================================
	strLine = strLine.replace(/&nbsp/g, ' ');
	// Microsoft Internet Explorer with Windows
	if (navigator.appName == 'Microsoft Internet Explorer' && (navigator.platform.toLowerCase().indexOf("mac") == -1)){
		
		// Default pixel size
		pixelsOfLetter = 7.1;      //Usally higher value for Internet Explorer
		
		// Some documents have weird pixel size, we need to do some special
		// calculation for this. We are using regular expression here.
		var regExpSct12 = /Parents v./gi; 
		regExpSct12 = strLine.match(regExpSct12);
		if (regExpSct12 != null){
			pixelsOfLetter = 8.1;
		}
		
		var regExpSct12 = /AND ANSWERS:/gi; 
		regExpSct12 = strLine.match(regExpSct12);
		if (regExpSct12 != null){
			pixelsOfLetter = 8.1;
		}
		
		//case:103 S.Ct 3492
		var regExpSct3492 = /v. Norris/gi; 
		regExpSct3492 = strLine.match(regExpSct3492);
		if (regExpSct3492 != null){
			pixelsOfLetter = 7.7;
		}
		
		//case:US-ORDERS
		var regExpJury = /OF CRIMINAL PROCEDURE/gi; 
		regExpJury = strLine.match(regExpJury);
		if (regExpJury != null){
			pixelsOfLetter = 8.4;
		}
	}
	
	// Netscape 4.x
	else if (((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4) && (parseInt(navigator.appVersion) < 5) )){
		pixelsOfLetter = 6.9;      //assume 5.5 pixels/letter
		
		// Some documents have weird pixel size, we need to do some special
		// calculation for this. We are using regular expression here.
		var regExpSct12 = /Parents v./gi; 
		regExpSct12 = strLine.match(regExpSct12);
		if (regExpSct12 != null){
			pixelsOfLetter = 8.5;
		}
		
		//case:103 S.Ct 3492
		var regExpSct3492 = /v. Norris/gi; 
		regExpSct3492 = strLine.match(regExpSct3492);
		if (regExpSct3492 != null){
			pixelsOfLetter = 7.4;
		}
		
		//case:US-ORDERS
		var regExpJury = /OF CRIMINAL PROCEDURE/gi; 
		regExpJury = strLine.match(regExpJury);
		if (regExpJury != null){
			pixelsOfLetter = 8.4;
		}
			
		//case:100 S.Ct 1
		var regExp100Sct1 = /of State of cal./gi; 
		regExp100Sct1 = strLine.match(regExp100Sct1);
		if (regExp100Sct1 != null){
			pixelsOfLetter = 8.5;
		}
	}
	
	// Microsoft Internet Explorer with MAC
	else if (navigator.appName == 'Microsoft Internet Explorer' && (navigator.platform.toLowerCase().indexOf("mac") == 0)){
	
		// Default pixel size
		pixelsOfLetter = 7.8;      //Usally higher value for Internet Explorer
		
		// Some documents have weird pixel size, we need to do some special
		// calculation for this. We are using regular expression here.
		var regExpSct12 = /Parents v./gi; 
		regExpSct12 = strLine.match(regExpSct12);
		if (regExpSct12 != null){
			pixelsOfLetter = 9.6;
		}
		
		//case:103 S.Ct 3492
		var regExpSct3492 = /v. Norris/gi; 
		regExpSct3492 = strLine.match(regExpSct3492);
		if (regExpSct3492 != null){
			pixelsOfLetter = 9.4;
		}
		
		//case:US-ORDERS
		var regExpJury = /OF CRIMINAL PROCEDURE/gi; 
		regExpJury = strLine.match(regExpJury);
		if (regExpJury != null){
			pixelsOfLetter = 9.4;
		}
	}
	
	//Netscape 6.x or other browsers
	else{
		pixelsOfLetter = 7.4;      //assume 5.5 pixels/letter
		
		// Some documents have weird pixel size, we need to do some special
		// calculation for this. We are using regular expression here.
		var regExpSct12 = /Parents v./gi; 
		regExpSct12 = strLine.match(regExpSct12);
		if (regExpSct12 != null){
			pixelsOfLetter = 8.5;
		}
		
		//case:103 S.Ct 3492
		var regExpSct3492 = /v. Norris/gi; 
		regExpSct3492 = strLine.match(regExpSct3492);
		if (regExpSct3492 != null){
			pixelsOfLetter = 8.9;
		}
		
		//case:100 S.Ct 1
		var regExp100Sct1 = /of State of cal./gi; 
		regExp100Sct1 = strLine.match(regExp100Sct1);
		if (regExp100Sct1 != null){
			pixelsOfLetter = 8.5;
		}
	}
	return pixelsOfLetter;
}
	
function cutitdown2(p, gifBase) {
		var children = p.childNodes;
		var nextSib = p.nextSibling;
		var shorten = 0;
		if (nextSib) {
			var nextId = nextSib.getAttribute("id");
			if (nextId=="next") {
			shorten = 18 + 15;
			}
			if (nextId=="proposed") {
			shorten=8;
			}
			if (nextId=="prior") {
			shorten=5;
			}
		}
		
		var trunc = p.innerHTML;
		var outer = p.outerHTML;
		var len = lastletterindex(trunc)-shorten;
		var noHTML = '';
		var totalCharCount = 0;
		var done = 0;
		for (var i = 0; i < p.childNodes.length; i++) {
			var childCount = 0;
			if(done == 0) {
				if (children[i].nodeType == 3 /*Node.TEXT_NODE*/) {
					childCount = children[i].nodeValue.length;
					noHTML += children[i].nodeValue;
					if(childCount+totalCharCount >= len) {
	 					children[i].nodeValue = children[i].nodeValue.substring(0, len-totalCharCount);
   						children[i].nodeValue = children[i].nodeValue.replace(/\w+$/, '');
						done=1;
					}
					
				}
				if (children[i].nodeType == 1 /*Node.TAG*/) {
					childCount = children[i].innerHTML.length;
					noHTML += children[i].innerHTML;
					if(childCount+totalCharCount >= len) {
	 					children[i].innerHTML = children[i].innerHTML.substring(0, len-totalCharCount);
   						children[i].innerHTML = children[i].innerHTML.replace(/\w+$/, '');
						done=1;
					}
				}
				totalCharCount +=childCount;
			} else {
				if(children[i].nodeType == 1) { 
					noHTML += children[i].innerHTML;
					children[i].innerHTML = ''; 
				}
				if(children[i].nodeType == 3) { 
					noHTML += children[i].nodeValue;
					children[i].nodeValue = ''; 
				}	
			}
		}
		/* Add an ellipses to the end and make it a link that expands
			the paragraph back to its original size */
		if(done==1) {
			p.innerHTML += '&nbsp;<img alt="'+noHTML+'" title="'+noHTML+'" src="'+gifBase+'/images/dot.gif" />';
		}
}

function loadit2(gifBase) {
	window.onresize = reloadIt;
	for(var num=1;num<=4;num++){
		var titleSpan = document.getElementById("headerTitleTruncate"+num);
		if (titleSpan) {
				cutitdown2(titleSpan,gifBase);
		}
	}
}

// ============================================================
// On resizing the window reload to adjust the scaled text
// ============================================================

		function reloadIt(){
			window.location.reload();
		}
// -->

if(typeof(Sys) !== "undefined") {
	Sys.Application.notifyScriptLoaded();
}