function Validate(){
	var MinVal, MaxVal
	var frm = document.frmSearch
	var bCriteria = false;

	MinVal=frm.txtCredName.value;
	if (MinVal!=""){
		bCriteria=true;
		if (ValidateName(MinVal)==false){
			alert("Invalid characters in name!");
			return false;
		}
	}
	
	MinVal=frm.txtClaimNum.value;
	if (MinVal!=""){
		bCriteria=true;
		if (ValidateClaim(MinVal)==false){
			alert("Invalid Claim Number!");
			return false;
		}
	}
	
	MinVal=frm.MinClaim.value;
	MaxVal=frm.MaxClaim.value;
	if (MinVal!=""){
		bCriteria=true;
		if (!ValidateAmount(MinVal)){
			alert("Minimum Claim Amount must be a positive dollar amount.  Exclude currency symbols and commas.");
			return;
		}	
		else if (ValidateSQLAmount(MinVal)==false){
			alert("Minimum Claim Amount is outside of the range allowed by this system!");
			return;
		}
	}
	if (MaxVal!=""){
		bCriteria=true;
		if (!ValidateAmount(MaxVal)){
			alert("Maximum Claim Amount must be a positive dollar amount.  Exclude currency symbols and commas.");
			return;
		}
		else if (ValidateSQLAmount(MaxVal)==false){
			alert("Maximum Claim Amount is outside of the range allowed by this system!");
			return;
		}
		if (MinVal!=""){
			if (parseFloat(MinVal) > parseFloat(MaxVal)){
				alert("Minimum Claim Amount cannot be greater than Maximum Claim Amount!");
				return;
			}
		}
	}
	
	if (frm.cboFDate.value != "") {
		MinVal=frm.cboFDate.value 
	}
	else {
		MinVal = "//"
	}
	
	if ( frm.cboTDate.value != "" ) {
		MaxVal=frm.cboTDate.value 
	} 
	else {
		MaxVal = "//"
	}
	
		
	
	if (MinVal!="//"){
		bCriteria=true;
		if (!checkValidDate(MinVal)){   //ValidateDate
			//alert("Start Date must contain a month, date, and 4-digit year!");
			alert("Incorrect start date format. Please enter a date in the format mm/dd/yyyy or use the date picker to select a date.");
			return;
		}
		else if (ValidateSQLDate(MinVal)==false){
			alert("Start Date is outside of the range allowed by this system!");
			return;
		}
   
   
	}
	if (MaxVal!="//"){
		bCriteria=true;
		if (!checkValidDate(MaxVal)){  //ValidateDate
			alert("Incorrect end date format. Please enter a date in the format mm/dd/yyyy or use the date picker to select a date.");
			return;
		}
		else if (ValidateSQLDate(MaxVal)==false){
			alert("End Date is outside of the range allowed by this system!");
			return;
		}
		if (MinVal!="//"){
			if (Date.parse(MinVal) > Date.parse(MaxVal)){
				alert("End Date is earlier than Start Date!");
				return;
			}
		}
	}
	
	
	var dList = "";
	dList = GetSelectedItem();
	dList = dList.slice(0, -1);
		
	//alert ("validate Debtor List: " + dList);
	
	document.getElementById("hDebtorList").value = dList
		
		
	if (dList != "")
	{
		//bCriteria=true;
		frm.hDebtorList.value = dList
		//alert("Debtor List=" + frm.hDebtorList.value);
	}
	else
	{
		alert("You must select at least one debtor from the list.");
		return;
	}
		
		
	if (frm.cboNature.value != ""){bCriteria=true;}
	
	if (frm.cboSchedule.value != ""){bCriteria=true;}
	
	if (!bCriteria){
		alert("Please enter some search criteria!");
		return;
	}
	
	frm.submit()
}


function checkValidDate(dateStr) {
    // dateStr must be of format month day year with either slashes
    // or dashes separating the parts. Some minor changes would have
    // to be made to use day month year or another format.
    // This function returns True if the date is valid.
    var slash1 = dateStr.indexOf("/");
    //if (slash1 == -1) { slash1 = dateStr.indexOf("-"); }
    // if no slashes or dashes, invalid date
    if (slash1 == -1) { return false; }
    var dateMonth = dateStr.substring(0, slash1)
    var dateMonthAndYear = dateStr.substring(slash1+1, dateStr.length);
    var slash2 = dateMonthAndYear.indexOf("/");
    //if (slash2 == -1) { slash2 = dateMonthAndYear.indexOf("-"); }
    // if not a second slash or dash, invalid date
    if (slash2 == -1) { return false; }
    var dateDay = dateMonthAndYear.substring(0, slash2);
    var dateYear = dateMonthAndYear.substring(slash2+1, dateMonthAndYear.length);
    if ( (dateMonth == "") || (dateDay == "") || (dateYear == "") ) { return false; }
    // if any non-digits in the month, invalid date
    for (var x=0; x < dateMonth.length; x++) {
        var digit = dateMonth.substring(x, x+1);
        if ((digit < "0") || (digit > "9")) { return false; }
    }
    // convert the text month to a number
    var numMonth = 0;
    for (var x=0; x < dateMonth.length; x++) {
        digit = dateMonth.substring(x, x+1);
        numMonth *= 10;
        numMonth += parseInt(digit);
    }
    if ((numMonth <= 0) || (numMonth > 12)) { return false; }
    // if any non-digits in the day, invalid date
    for (var x=0; x < dateDay.length; x++) {
        digit = dateDay.substring(x, x+1);
        if ((digit < "0") || (digit > "9")) { return false; }
    }
    // convert the text day to a number
    var numDay = 0;
    for (var x=0; x < dateDay.length; x++) {
        digit = dateDay.substring(x, x+1);
        numDay *= 10;
        numDay += parseInt(digit);
    }
    if ((numDay <= 0) || (numDay > 31)) { return false; }
    // February can't be greater than 29 (leap year calculation comes later)
    if ((numMonth == 2) && (numDay > 29)) { return false; }
    // check for months with only 30 days
    if ((numMonth == 4) || (numMonth == 6) || (numMonth == 9) || (numMonth == 11)) { 
        if (numDay > 30) { return false; } 
    }
    // if any non-digits in the year, invalid date
    for (var x=0; x < dateYear.length; x++) {
        digit = dateYear.substring(x, x+1);
        if ((digit < "0") || (digit > "9")) { return false; }
    }
    // convert the text year to a number
    var numYear = 0;
    for (var x=0; x < dateYear.length; x++) {
        digit = dateYear.substring(x, x+1);
        numYear *= 10;
        numYear += parseInt(digit);
    }
    // Year must be a 2-digit year or a 4-digit year
    //if ( (dateYear.length != 2) && (dateYear.length != 4) ) { return false; }
    // if 2-digit year, use 50 as a pivot date
    //if ( (numYear < 50) && (dateYear.length == 2) ) { numYear += 2000; }
    //if ( (numYear < 100) && (dateYear.length == 2) ) { numYear += 1900; }
    
    // Incident 16506 - Only allow 4  digit years on search page; even previous search page only allowed 4 digit years
    // Year must be a 4-digit year
    if ( dateYear.length != 4 ) { return false; }
    
    if ((numYear <= 0) || (numYear > 9999)) { return false; }
    // check for leap year if the month and day is Feb 29
    if ((numMonth == 2) && (numDay == 29)) {
        var div4 = numYear % 4;
        var div100 = numYear % 100;
        var div400 = numYear % 400;
        // if not divisible by 4, then not a leap year so Feb 29 is invalid
        if (div4 != 0) { return false; }
        // at this point, year is divisible by 4. So if year is divisible by
        // 100 and not 400, then it's not a leap year so Feb 29 is invalid
        if ((div100 == 0) && (div400 != 0)) { return false; }
    }
    // date is valid
    return true;
}



function GetSelectedItem() 
{
		len = document.frmSearch.ddlDebtors.length
		//alert( len + " items in the debtor list.");
		i = 0
		chosen = ""
		for (i = 0; i < len; i++) {
			if (document.frmSearch.ddlDebtors[i].selected)
				chosen = chosen + document.frmSearch.ddlDebtors[i].value + ","
		}
		//alert("Debtors selected: " + chosen)
		return chosen
}
	

function popDates(p_sType){
	var frm = document.frmSearch;
	var month, day, year;
	var maxDay;
	switch (p_sType){
		case "F":
			month = frm.cboFMonth;
			day = frm.cboFDay;
			year = frm.txtFYear;
			break;
		case "T":
			month = frm.cboTMonth;
			day = frm.cboTDay;
			year = frm.txtTYear;
			break;
		default:
			alert("Unknown date parameter!");
			return;
	}
	
	switch (parseInt(month.value)){
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			maxDay = 31;
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			maxDay = 30;
			break;
		case 2:
			if (year.value == "" 
			|| parseInt(year.value)%400==0
			|| (parseInt(year.value)%4==0 && parseInt(year.value)%100!=0)
			)
			{
				maxDay = 29;
			} 
			else 
			{
				maxDay = 28;
			}
			break;
		default:
			return;
	}
	if (day.length < (maxDay + 1)){
		for (var i=day.length; i < (maxDay + 1); i++){
			day.options[i] = new Option (i.toString(), i.toString());
		}
	} else if (day.length > (maxDay + 1)){
		for (var i=(maxDay + 1); i < day.length;) {
			day.options[i] = null;
		}
	}
}


		
function ValidateGlobalSearch(){
	var MinVal, MaxVal;
	var frm = document.frmSearch;
	var bCriteria = false;

	// Court Docket Number validation
	MinVal=frm.txtCourtDocNumList.value;
	if (MinVal!=""){
		bCriteria=true;
		if (ValidateClaim(MinVal)==false){
			alert("Please enter a valid Court Docket # value or range. e.g. 1,3,5-7");
			HighlightControl(frm.txtCourtDocNumList,true);
			return false;
		}
	}
	
	// Date Filed From and To
	if (frm.cboFDate.value != "") 
		MinVal=frm.cboFDate.value; 
	else 
		MinVal = "//";
	
	if ( frm.cboTDate.value != "" ) 
		MaxVal=frm.cboTDate.value ;
	 
	else 
		MaxVal = "//";
	
	if (MinVal!="//"){
		bCriteria=true;
		if (!checkValidDate(MinVal)){   //ValidateDate
			//alert("Start Date must contain a month, date, and 4-digit year!");
			alert("Please enter a date in the format mm/dd/yyyy or use the date picker to select a date.");
			HighlightControl(frm.cboFDate,true);
			return;
		}
		else if (ValidateSQLDate(MinVal)==false){
			alert("Not a valid date range.");
			HighlightControl(frm.cboFDate,true);
			return;
		}
	}
	if (MaxVal!="//"){
		bCriteria=true;
		if (!checkValidDate(MaxVal)){  //ValidateDate
			alert("Please enter a date in the format mm/dd/yyyy or use the date picker to select a date.");
			//frm.cboTDate.focus();
			HighlightControl(frm.cboTDate,true);
			return;
		}
		else if (ValidateSQLDate(MaxVal)==false){
			alert("Not a valid date range");
			HighlightControl(frm.cboTDate,true);
			return;
		}
		if (MinVal!="//"){
			if (Date.parse(MinVal) > Date.parse(MaxVal)){
				alert("Not a valid date range");
				HighlightControl(frm.cboFDate,true);
				return;
			}
		}
	}
	
	// Case Filed Date From and To
	if (frm.cboCFDate.value != "") 
		MinVal=frm.cboCFDate.value ;
	else 
		MinVal = "//";
	
	if ( frm.cboCTDate.value != "" ) 
		MaxVal=frm.cboCTDate.value; 
	else 
		MaxVal = "//";
	
	if (MinVal!="//"){
		bCriteria=true;
		if (!checkValidDate(MinVal)){   //ValidateDate
			//alert("Start Date must contain a month, date, and 4-digit year!");
			alert("Please enter a date in the format mm/dd/yyyy or use the date picker to select a date.");
			HighlightControl(frm.cboCFDate,true);
			return;
		}
		else if (ValidateSQLDate(MinVal)==false){
			alert("Not a valid date range. ");
			HighlightControl(frm.cboCFDate,true);
			return;
		}
	}
	
	if (MaxVal!="//"){
		bCriteria=true;
		if (!checkValidDate(MaxVal)){  //ValidateDate
			alert("Please enter a date in the format mm/dd/yyyy or use the date picker to select a date.");
			HighlightControl(frm.cboCTDate,true);
			return;
		}
		else if (ValidateSQLDate(MaxVal)==false){
			alert("Not a valid date range.");
			HighlightControl(frm.cboCTDate,true);
			return;
		}
		if (MinVal!="//"){
			if (Date.parse(MinVal) > Date.parse(MaxVal)){
				alert("Not a valid date range.");
				HighlightControl(frm.cboCFDate,true);
				return;
			}
		}
	}
	
	// Document Name validation
	/*
	MinVal=frm.txtDocName.value;
	if (MinVal!=""){
		bCriteria=true;
		if (ValidateName(MinVal)==false){
			alert("Invalid characters in name!");
			HighlightControl(frm.txtDocName,true);
			return false;
		}
	}
	*/
	
	// Case Name validation - at least one must be selected
	var dList = "";
	dList = GetSelectedCases();
	dList = dList.slice(0, -1);
		
	document.getElementById("hCaseList").value = dList
		
	if (dList != "")
	{
		bCriteria=true;
		frm.hCaseList.value = dList
	}
	else
	{
		alert("Please select a Case Name value or the All Cases checkbox.");
		HighlightControl(frm.dCaseName,true);
		//document.frmSearch.dCaseName[0].selected = true;
		return;
	}
	
	// Jurisdiction List
	var jList = "";
	jList = GetSelectedJurisdiction();
	//alert("jList=" + jList);
	jList = jList.slice(0, -1);
		
	document.getElementById("hJurisdictionList").value = jList
	bCriteria=true;
	frm.hJurisdictionList.value = jList
	
	//alert(jList);
	if (jList == "")
	{
		if (frm.chkJurisdictions.checked == false)
		{
			alert("No Jurisdiction has been selected. Please select either Search All or a specific Jurisdiction.");
			HighlightControl(frm.dJurisdiction,true);
			//document.frmSearch.dJurisdiction[0].selected = true;
			return;
		}
	}
		
	// Check that some criteria is selected.. which it should be since only requirement is the Case Name
	if (!bCriteria){
		alert("Please enter some search criteria!");
		return;
	}
	
	//Remember data
	//RememberData();
	
	// Submit the form
	frm.submit();
}
function GetSelectedCases() 
{
		len = document.frmSearch.dCaseName.length
		//alert( len + " items in the case list.");
		i = 0
		chosen = ""
		for (i = 0; i < len; i++) {
			if (document.frmSearch.dCaseName[i].selected)
				chosen = chosen + document.frmSearch.dCaseName[i].value + ","
		}
		//alert("Cases selected: " + chosen)
		return chosen
}
function GetSelectedJurisdiction() 
{
		len = document.frmSearch.dJurisdiction.length
		//alert( len + " items in the jurisdiction list.");
		i = 0
		chosen = ""
		for (i = 0; i < len; i++) {
			if (document.frmSearch.dJurisdiction[i].selected)
				chosen = chosen + document.frmSearch.dJurisdiction[i].value + ","
		}
		//alert("Cases selected: " + chosen)
		return chosen
}
function RememberData() { 
	var strURLParams = "";

		// save the data already input on the screen
		alert("handlechange");
		// encodeURIComponent  decodeURIComponent 
		if ( document.getElementById("txtCourtDocNumList").value != "") strURLParams = strURLParams + "&TCDNL=" + encodeURIComponent(document.getElementById("txtCourtDocNumList").value.trim());
		if ( document.getElementById("cboFDate").value != "") strURLParams = strURLParams + "&FD=" + document.getElementById("cboFDate").value.trim();
		if ( document.getElementById("cboTDate").value != "") strURLParams = strURLParams + "&TD=" + document.getElementById("cboTDate").value.trim();
		if ( document.getElementById("txtDocName").value != "") strURLParams = strURLParams + "&TDName=" + encodeURIComponent(document.getElementById("txtDocName").value.trim());
		
		if ( document.getElementById("dJurisdiction").value != "") strURLParams = strURLParams + "&JURIS=" + document.getElementById("dJurisdiction").value;
		if ( document.getElementById("dJudge").value != "") strURLParams = strURLParams + "&JUDGE=" + document.getElementById("dJudge").value;
		if ( document.getElementById("dJointAdmin").value != "") strURLParams = strURLParams + "&JOINT=" + document.getElementById("dJointAdmin").value;
		if ( document.getElementById("dFiledDebtors").value != "") strURLParams = strURLParams + "&FDEBT=" + document.getElementById("dFiledDebtors").value;
		
		if ( document.getElementById("cboCFDate").value != "") strURLParams = strURLParams + "&CFD=" + document.getElementById("cboCFDate").value.trim();
		if ( document.getElementById("cboCTDate").value != "") strURLParams = strURLParams + "&CTD=" + document.getElementById("cboCTDate").value.trim();
		strURLParams = strURLParams + "&CC=" + document.getElementById("chkCases").checked ;
		strURLParams = strURLParams + "&CJ=" + document.getElementById("chkJurisdictions").checked ;
		
		var dList = "";
		dList = GetSelectedCases();
		document.getElementById("hCaseList").value = dList;
		
		strURLParams = strURLParams + "&CN=" + dList;
		
		var jList = "";
		jList = GetSelectedJurisdiction();
		document.getElementById("hJurisdictionList").value = jList;
		
		strURLParams = strURLParams + "&JL=" + jList;
		alert ("strURLParams=" + strURLParams);
		
		//var e;
		
		//the following takes care of the window.event.srcElement.value in IE issues.
		
		window.location.href="docsearch.asp?SH=1&CATV=" +  strURLParams ; 
		alert ("window.location.href=" + window.location.href);
}