// JavaScript Document
// <script language="JavaScript"  type="text/javascript">

var cUnitText = "Select District or Bankruptcy Court";
var cDivText = "Select St. Croix or St. Thomas";
var cNameText = '(Last Name, First Name)\nPartial names are acceptable.\ne.g., "Frank," will get you Frankenstein and Frankenfurter,\n but "Frank," (note the comma) will get you\nonly parties with the last name Frank.';
var cDateText = "(mm/dd/yyyy)";


function printPage(lLandscapeSuggested) {
	if (lLandscapeSuggested) 
		alert("This report looks best in Landscape Mode.\nChoose Preferences, Landscape to set.");
	print();
}

function sf() {
	document.f.division.focus();
	return true;
}

function switchToBK() {
	var oFrame = window.frameElement;
	if (oFrame == null) {oFrame = window};
	oFrame.src = "Bankruptcy.html";
	return true;
}


function switchTo(cNewPage) {
	var oFrame = window.frameElement;
	if (oFrame == null) {oFrame = window};
	oFrame.src = cNewPage+".html";
	return true;
}
// script

function lookAt(p, o) {
//	alert("You clicked " + p + "!");
//	var cSelected = '{background-color:darkblue;text-align:center;width:95px;color="#ffffff";font-size:small;font-family:arial,sans-serif;font-style:bold;}';
//    var cUnselected = '{background-color:#CCCC99;text-align:center;width:95px;color="#ffffff";font-size:smaller;font-family:arial,sans-serif;cursor:pointer;cursor:hand;}';
	f.queryType.value = p;

	btnFindCase.style.color = (p == "btnFindCase" ? "darkblue" : "#666666");
	btnCalendar.style.color = (p == "btnCalendar" ? "darkblue" : "#666666");
	btnActivity.style.color = (p == "btnActivity" ? "darkblue" : "#666666");
	btnJudgment.style.color = (p == "btnJudgment" ? "darkblue" : "#666666");

	trFindCase.style.display = (p == "btnFindCase" ? "" : "none");
	trCalendar.style.display = (p == "btnCalendar" ? "" : "none");
	trActivity.style.display = (p == "btnActivity" ? "" : "none");
	trJudgment.style.display = (p == "btnJudgment" ? "" : "none");

	sf();
	return true;
}

function c(p,l,e) {
	var f=document.f;
	if (f.action && document.getElementById) 
		{var hf=document.getElementById("hf");
		if (hf) 
			{var t = "<input type=hidden name=tab value="+l+">";
			hf.innerHTML=t;}
//		f.action = 'http://'+p;
		f.action = p;
		e.cancelBubble=true;
		f.submit();
		return false;
		}
	return true;
}

	
function showControls() {
//	alert("Hello from showControls(), f.queryType.value = " + f.queryType.value);
//	if (f.queryType.value == "btnFindCase") {
//		dcChoices.style.display = (cChoice == "DC") ?  "" : "none";
//		bkChoices.style.display = (cChoice == "BK") ?  "" : "none";

//	}  
	if (f.queryType.value == "btnActivity") {
		cBranch = f.branch.value;
		cChoice = f.optView.value;
		
<!--		BKJudge.style.display = (cBranch == "BK") ? "" : "none"; -->
		//	division.style.display = (cBranch == "DC") ? "" : "none";
		dateRange.style.display = (cChoice == "M" || cChoice == "P") ? "none" : "";
		if (cBranch == "DC") {
			DCJudge.style.display = "" ;
			nosSpan.style.display = (cChoice == "M" || cChoice == "D") ? "none" : "";
		}
	}
	return true;
}


function transform(xmlIsland, xslDocName){ 
	var xslDoc=new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
	var rsltDoc=new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
	var xslTemplate=new ActiveXObject("MSXML2.XSLTemplate");
//	xslDoc.load(xslIsland.XMLDocument);
    xslDoc.validateOnParse = false;
    xslDoc.async = false;
	xslDocName = "http://156.122.38.244/pacer/XSL/"+xslDocName+".xsl";
//	xslDocName = "htt/XSL/"+xslDocName+".xsl";
//	alert("Loading " + xslDocName);
	xslDoc.load(xslDocName);
	xslTemplate.stylesheet=xslDoc;
	var xslProc=xslTemplate.createProcessor();
	xslProc.input=xmlIsland.XMLDocument;
	xslProc.output=rsltDoc;
	if (arguments.length > 2 && 
		arguments.length % 2 == 0){
		for (var i=0;
			i < Math.floor((arguments.length)/2)-1;
			i++){	
			paramName=arguments[2*i+2];
			paramValue=arguments[2*i+3];
			xslProc.addParameter(paramName,paramValue);
			}
		}
	xslProc.transform();
	return rsltDoc;
}


function showRecords(templateName){
	var xmlDiv = window.caseInfo;
	var htmlDoc = transform(xmlDiv,  templateName);
	if (htmlDoc.xml == null)
		htmlDoc.xml = "No results.";
    window.results.innerHTML=htmlDoc.xml;
}



//************************************************
// Parses ALL text fields in a form to  upper case
//************************************************
function parseUpperCase( formObject )
{
	for (i = 0; i <= formObject.length - 1; i++) 
	{
		if ((formObject.elements[i].type == "text") || (formObject.elements[i].type == "textarea" || (formObject.elements[i].type == "password")) )
		{
			formObject.elements[i].value = formObject.elements[i].value.toUpperCase();
		}
	}

	return formObject;
}

//**********************************************
// Date Validation
//**********************************************

function checkdate(objName) {
	var datefield = objName;

	if (chkdate(objName) == false) {
		datefield.select();
		alert("That date is invalid.  Please try again.");
		datefield.focus();
		return false;
	}
	else {
	return true;
	}
}

function chkdate(objName) {
	var strDatestyle = "US"; //United States date style
	//var strDatestyle = "EU";  //European date style
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var datefield = objName;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array("1","2","3","4","5","6","7","8","9","10","11","12");
	strDate = datefield.value;

	if (strDate.length < 1) {
		return true;
	}

	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);

			if (strDateArray.length != 3) {
				err = 1;
				return false;
			}
			else {
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}

			booFound = true;
		}
	}

	if (booFound == false) {
		if (strDate.length>5) {
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
	}

	if (strYear.length == 2) {
		strYear = '20' + strYear;
	}

	// US style
	if (strDatestyle == "US") {
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}

	intday = parseInt(strDay, 10);

	if (isNaN(intday)) {
		err = 2;
		return false;
	}

	intMonth = parseInt(strMonth, 10);

	if (isNaN(intMonth)) {
		for (i = 0;i<12;i++) {
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
			}
		}

		if (isNaN(intMonth)) {
			err = 3;
			return false;
		}
	}

	intYear = parseInt(strYear, 10);

	if (isNaN(intYear)) {
		err = 4;
		return false;
	}

	if (intMonth>12 || intMonth<1) {
		err = 5;
		return false;
	}

	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
		err = 6;
		return false;
	}

	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
		err = 7;
		return false;
	}

	if (intMonth == 2) {

		if (intday < 1) {
			err = 8;
			return false;
		}

		if (LeapYear(intYear) == true) {

			if (intday > 29) {
				err = 9;
				return false;
			}
		}
		else {

			if (intday > 28) {
				err = 10;
				return false;
			}
		}
	}

	if (strDatestyle == "US") {
		datefield.value = strMonthArray[intMonth-1] + "/" + intday + "/" + strYear;
	}
	else {
		datefield.value = intday + "/" + strMonthArray[intMonth-1] + "/" + strYear;
	}

	return true;
}

function LeapYear(intYear) {

	if (intYear % 100 == 0) {

		if (intYear % 400 == 0) { 
			return true; 
		}
	}
	else {

		if ((intYear % 4) == 0) { 
			return true; 
		}
	}

	return false;
}

function doDateCheck(from, to) {

	if (Date.parse(from.value) <= Date.parse(to.value)) {
		alert("The dates are valid.");
	}
	else {

		if (from.value == "" || to.value == "") 
			alert("Both dates must be entered.");
		else 
			alert("To date must occur after the from date.");
	}
}


//**********************************************
// functions used for navigating the calendar
//**********************************************
function getCalendar( cNavigate, fDate )
{

//Declare Variables

	//a text version of dSubject
	cSubjectDate = "";

//Decide what the User is asking us to do
	if (cNavigate == "today")
	{
		dSubject = new Date();
	}
	else if (cNavigate == "up")
	{
		dSubject.setDate(dSubject.getDate() + 1);
	} 
	else if (cNavigate == "down")
	{
		dSubject.setDate(dSubject.getDate() - 1);
	} 
	else
	{
		dSubject = StringToDate(fDate.Date.value);
	}
	
//Create the date string

	//Save a string version of the date
	cSubjectDate = DateToString(dSubject);

//Display Send the date to the appropriate frame
	//display the new calendar in the bottom frame
	parent.frames[1].location.replace("Calendar.wj?Date=" + cSubjectDate );
	
//Echo the date in the form field
	//echo the date in the date field on the form
	fDate.Date.value = cSubjectDate;
	
} //getCalendar()

function DateToString(dDate)
{
	//Takes a Javascript Date object and parses it to a string in a mm/dd/yyyy format
	cDate = (dDate.getMonth() + 1) + "/" + dDate.getDate() + "/" + dDate.getFullYear();

	return cDate;

}	//DateToString()


function StringToDate(cDate)
{
//Takes a String Date in a MM/dd/yyyy format and creates a javascript date object
//This function performs no validation however the date object in javascript will 
//message things into a valid date.

	oDate = new Date()
	tDate = cDate.split("/")

	oDate.setMonth(tDate[0]-1)
	oDate.setDate(tDate[1])
	oDate.setYear(tDate[2])

	return oDate

}//StringToDate()


function MM_reloadPage(init) {  
  // reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}


	function idfocus(loginForm)		// put focus in login ID field
	{ document.forms[0].loginid.focus(); }
	
	function getCookie(Name)
	{
		var search = Name + "="
		var RetStr = ""
		var offset = 0
		var end    = 0
		if (document.cookie.length > 0)
			{
			offset = document.cookie.indexOf(search)
			if (offset != -1)
				{
				offset += search.length
				end = document.cookie.indexOf(";", offset)
				if (end == -1)
				end = document.cookie.length
				RetStr = unescape(document.cookie.substring(offset, end))
				}
			}
		return (RetStr)
	}
	
	function setStatus(msg)
	{
		status.innerText = msg;

//		if (navigator.appName == "Netscape")
//			{ window.status = msg; }	// Explorer puts up dialog for this
//		var uidcookie = getCookie("uid");
//		var uid = uidcookie.substring(0,4);
//		if (uidcookie.length > 4)		// minimum is 4 of ID + 1 of passwd
//			{
//			var msg = "You are already logged in as\n\n   " + uid + "\n\n";
//			msg += "Is that OK?";
//			if (confirm(msg))
//	/			{ window.location.pathname = "reports.html"; }
//			}

	}
	// end script hiding -->
	
	function ShowLastup() 	// write document last updated string
	{
		var update = new Date(document.lastModified);
		var theMonth = update.getMonth() + 1;
		var theDate = update.getDate();
		var theYear = update.getYear();
		var theHour = update.getHours();
		var theMinutes = update.getMinutes();
		var minute = new String(theMinutes);
		var hour = new String(theHour);
		if (hour.length < 2)	// add leading zero if needed
			hour = "0" + hour;
		if (minute.length < 2)	// add leading zero if needed
			minute = "0" + minute;
		if (theYear >= 0 && theYear < 31)
			theYear += 100;	// Changed after y2k testing         
		document.writeln("<FONT SIZE=-2>");
		document.writeln("<I>Form 100 last updated: " + theMonth + "/" + theDate +
			"/" + (theYear+1900) + " " + hour + ":" + minute + "</I>")
		document.writeln("</FONT>");
	}




function storeState(theForm, expDays){
  parseUpperCase(theForm);
  expTime="";
  if(expDays){
    expTime = new Date((new Date()).getTime() + expDays * 86400000);
    expTime = "expires="+expTime.toGMTString();
  }
  cState = "";
  elem = theForm.elements;
  for(i=0;i<elem.length;i++){
 	if(elem[i].name){
      eName = elem[i].name;
      eType = elem[i].type.substr(0,4);
      if(eType=="text"){
        cState += "t:"+eName+":"+escape(elem[i].value)+"$";
      }
      if(eType=="sele"){
        opt = elem[i].options;
        for(j=0;j<opt.length;j++){
          if(opt[j].selected==true){
            cState += "s:"+eName+":"+escape(opt[j].value)+"$";
          }
        }
      }
      if((eType=="radi" || eType=="chec") && elem[i].checked){
        cState += "c:"+eName+":"+escape(elem[i].value)+"$";
      }
    }
  }
  document.cookie="_ff=$"+cState+";path=/;"+expTime;
}

function returnState(){
  fVal = document.cookie.split("_ff=");
  try {
  if(fVal.length==2){
    theForm = document.forms[0];
    cVal = (fVal[1]+";").split(";")[0].split("$")
    for(i=1;i<cVal.length-1;i++){
      ePart = cVal[i].split(":");
      eVal = unescape(ePart[2]);
      elem = theForm[ePart[1]];
      if(elem.length){
        if(ePart[0]=="s"){
          opt=elem.options;
          for(j=0;j<opt.length;j++){
            if(opt[j].value==eVal)opt[j].selected=true;
          }
        } else
        for(j=0;j<elem.length;j++){
          if(elem[j].value==eVal) elem[j].checked=true;
        }
      } else {
        if(ePart[0]=="c") elem.checked = true;
        else elem.value = eVal;
      }
    }
  }
  }  // try
  catch (e) {
  }
}
