﻿// JScript File

// Controls UI for AdvancedQuerySearch.aspx

window.onload = function() 
{

setupUnloader();
criteriaChange(document.getElementById('criteria'));
window.onload = null;
};

function setupUnloader() {

	// Set the current unloader to a string.
	
	var currUnloader = window.onunload;
	// Create a new unloader, including this one.
	var newUnloader = function() {
		if (currUnloader) {currUnloader();}
		g_criteriaEntryLabel = null;
		
	}
	window.onunload = newUnloader;
}


// Stores the labels for the criteriaInput boxes.
var g_criteriaEntryLabel = [];
// Available fields: 0, 1, isNumeric, isDate, isRadio, stored1, stored2,isChkbx,isChkbx2
g_criteriaEntryLabel['city'] = {0: 'Enter City:<br /><br />Type in a single city name or for multiple cities use a comma separated list.<br /><br />Note:&nbsp;&nbsp;Based on location address not tax district.<br /><br />Example: Lakeland, Winter Haven', isNumeric: false, regexp: /^(?:([A-Z ]+)([ ]?,[ ]?)?)*$/i,regexpFailed: 'Please enter a city name.'};
g_criteriaEntryLabel['dor_cd'] = { 0: 'Select <a href="DORUseCodes.aspx" target="_blank">Use Code Group:</a>', 1: '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;And/Or <br /> Enter <a href="../showLookupTable.aspx?table=dor" target="_blank">DOR Use Code</a>:<br /><br />Type in a single DOR Use Code, Partial code, or for multiple DOR Use Codes use a comma separated list.<br /><br />Example: 1%, 0001, 0002', isNumeric: false, regexp: /^((%)?\d+(%|%,|%, |,|, )?)*$/i, regexpFailed: 'Please enter digits, %, and commas only for DOR Use Code.', isChkBx: true, isOptional2: true };
g_criteriaEntryLabel['acreage'] = {0: 'From:', 1: 'To:', isNumeric: false, regexp: /^([0-9\.\,\$]+)$/, regexpFailed: 'Please enter a size in acres.'};
g_criteriaEntryLabel['heat_ar'] = {0: 'From:', 1: 'To:<br /><br />Type Range in Square Feet.', isNumeric: true, regexp: /^([0-9\,\$]+)$/, regexpFailed: 'Please enter a size in square feet.'};
g_criteriaEntryLabel['act_ar'] = {0: 'From:', 1: 'To:<br /><br />Type Range in Square Feet.', isNumeric: true, regexp: /^([0-9\,\$]+)$/, regexpFailed: 'Please enter a size in square feet.'};
g_criteriaEntryLabel['nh_cd'] = {0: 'Enter <a href="../showLookupTable.aspx?table=nhcd" target="_blank">NHBD No</a>:<br /><br />Type in a single NBHD No or for multiple NBHD No use a comma separated list.<br /><br />Example: 000387, 000388', isNumeric: false, regexp: /^(([\d]+)([\.]{1})([\d]{2})([ ]?,[ ]?)?)*$/, regexpFailed: 'Please enter the NBHD No, be sure to include the decimal point.'};
g_criteriaEntryLabel['name'] = {0: 'Enter Owner Name:', isNumeric: false};
g_criteriaEntryLabel['parcelid'] = {0: 'From:', 1: 'To:', isNumeric: false, isOptional2: true};
g_criteriaEntryLabel['accountid'] = {0: 'From:', 1: 'To:', isNumeric: false, isOptional2: true};
g_criteriaEntryLabel['or_bk'] = {0: 'Sale Book:', isNumeric: false};
g_criteriaEntryLabel['or_pg'] = {0: 'Sale Page:', isNumeric: false};
g_criteriaEntryLabel['dos'] = {0: 'From:', 1: 'To:', isNumeric: false, isDate: true, stored1: ''};
g_criteriaEntryLabel['price'] = {0: 'From:', 1: 'To:', isNumeric: true};
g_criteriaEntryLabel['qu'] = { 0: 'Yes:', 1: 'No:', isNumeric: false, isRadio: true };
g_criteriaEntryLabel['spcl_dist'] = { 0: 'Enter <a href="../showLookupTable.aspx?table=spcl_dist" target="_blank">Special District Code</a>:', isNumeric: false };
g_criteriaEntryLabel['str'] = {0: 'Enter Street Name:', isNumeric: false};
g_criteriaEntryLabel['str_num'] = {0: 'Enter Street Number:', isNumeric: true};
g_criteriaEntryLabel['sub'] = {0: 'Enter <a href="../showLookupTable.aspx?table=sub" target="_blank">Subdivision Number</a>:', isNumeric: false};
g_criteriaEntryLabel['swimmingpool'] = {0: 'Enter <a href="../showLookupTable.aspx?table=swimmingpool" target="_blank">Swimming Pool Code</a>:', isNumeric: false};
//g_criteriaEntryLabel['tax_dist'] = {0: 'Enter <a href="../showLookupTable.aspx?table=tax_dist" target="_blank">Tax District</a>:', isNumeric: false};
g_criteriaEntryLabel['tax_dist'] = { 0: 'Select <a href="TaxDistCodes.aspx" target="_blank">Tax District Group:</a>', 1: '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;And/Or <br /> Enter <a href="../showLookupTable.aspx?table=tax_dist" target="_blank">Tax District</a>:<br /><br />Type in a single Tax District Code, Partial code, or for multiple Tax District Codes use a comma separated list.<br /><br />Example: 1%, 0001, 0002', isNumeric: false, regexp: /^((%)?\d+(%|%,|%, |,|, )?)*$/i, regexpFailed: 'Please enter digits, %, and commas only for Tax District Code.', isChkBx2: true, isOptional2: true };
g_criteriaEntryLabel['act'] = { 0: 'From:', 1: 'To:<br /><br />Actual age is a real estate appraisal term refering to the number of years that have passed since a specific building improvement was made.', isNumeric: true };
g_criteriaEntryLabel['eff'] = { 0: 'From:', 1: 'To:<br /><br />The estimate given by the appraiser on the physical condition of a building. The actual age of the building may be shorter of longer than its effective age.', isNumeric: true };
g_criteriaEntryLabel['hx'] = {0: 'Yes:', 1: 'No:', isNumeric: false, isRadio: true};

function criteriaChange(selectObj) {

	window.status = selectObj.value;
	
//document.getElementById('hdn_dor').value = selectObj.value;
	// If there are already criteria set then enable the buttons.
	if (document.getElementById('currentCriteria').options.length > 0) {
		// Enable the buttons.
		document.getElementById('btn_edit').disabled = false;
		document.getElementById('btn_remove').disabled = false;
		document.getElementById('btn_removeAll').disabled = false;
	}

	var criteriaEntry1Label = document.getElementById('criteriaEntry1Label');
	var criteriaEntry2Label = document.getElementById('criteriaEntry2Label');
	var criteriaEntry1 = document.getElementById('criteriaEntry1');
	var criteriaEntry2 = document.getElementById('criteriaEntry2');
	var criteriaEntryRadio1 = document.getElementById('criteriaEntryRadio1');
	var criteriaEntryRadio2 = document.getElementById('criteriaEntryRadio2');

    //DOR Use Code
    var criteriaEntryChk1 = document.getElementById('chk01');
	var criteriaEntryChk2 = document.getElementById('chk02');
	var criteriaEntryChk3 = document.getElementById('chk03');
	var criteriaEntryChk4 = document.getElementById('chk04');
	var criteriaEntryChk5 = document.getElementById('chk05');
	var criteriaEntryChk6 = document.getElementById('chk06');
	var criteriaEntryChk7 = document.getElementById('chk07');
	var criteriaEntryChk8 = document.getElementById('chk08');
	var criteriaEntryChk9 = document.getElementById('chk09');
	var criteriaEntryChk10 = document.getElementById('chk10');
	var criteriaEntryChk11 = document.getElementById('chk11');
	var criteriaEntryChk12 = document.getElementById('chk12');
	
	//Tax District Code
	var criteriaEntryTDChk1 = document.getElementById('chkTx01');
	var criteriaEntryTDChk2 = document.getElementById('chkTx02');
	var criteriaEntryTDChk3 = document.getElementById('chkTx03');
	var criteriaEntryTDChk4 = document.getElementById('chkTx04');
	var criteriaEntryTDChk5 = document.getElementById('chkTx05');
	var criteriaEntryTDChk6 = document.getElementById('chkTx06');
	var criteriaEntryTDChk7 = document.getElementById('chkTx07');
	var criteriaEntryTDChk8 = document.getElementById('chkTx08');
	var criteriaEntryTDChk9 = document.getElementById('chkTx09');
	var criteriaEntryTDChk10 = document.getElementById('chkTx10');
	var criteriaEntryTDChk11 = document.getElementById('chkTx11');
	var criteriaEntryTDChk12 = document.getElementById('chkTx12');
	var criteriaEntryTDChk13 = document.getElementById('chkTx13');
	var criteriaEntryTDChk14 = document.getElementById('chkTx14');
	var criteriaEntryTDChk15 = document.getElementById('chkTx15');
	var criteriaEntryTDChk16 = document.getElementById('chkTx16');
	var criteriaEntryTDChk17 = document.getElementById('chkTx17');
	var criteriaEntryTDChk18 = document.getElementById('chkTx18');

	// Hide all the controls and reset the text, we will re-display it later if applicable.
	criteriaEntry1Label.style.display = 'none';
	criteriaEntry2Label.style.display = 'none';
	criteriaEntry1.style.display = 'none';
	criteriaEntry2.style.display = 'none';
	criteriaEntryRadio1.style.display = 'none';
	criteriaEntryRadio2.style.display = 'none';
	displaychkbx('none');
	displaychkbxTD('none');
	
	// Make sure that the selected criteria has data in the g_criteriaEntryLabel array.
	if (g_criteriaEntryLabel[selectObj.value]) {
		// If it has a first label and that label isn't blank then...
		if ((g_criteriaEntryLabel[selectObj.value][0]) && (g_criteriaEntryLabel[selectObj.value][0] != '')) {
			// Set the label text and show it.
			criteriaEntry1Label.innerHTML = g_criteriaEntryLabel[selectObj.value][0] + ' ';
			criteriaEntry1Label.style.display = 'inline';

			if (g_criteriaEntryLabel[selectObj.value].isRadio) {
				if ((g_criteriaEntryLabel[selectObj.value].stored1 == true) || (g_criteriaEntryLabel[selectObj.value].stored1 == 'true')) {
					criteriaEntryRadio1.checked = true;
					criteriaEntryRadio2.checked = false;
				} else {
					criteriaEntryRadio1.checked = false;
					criteriaEntryRadio2.checked = true;
				}
				criteriaEntryRadio1.style.display = 'inline';
				
							
			} 
			else if (g_criteriaEntryLabel[selectObj.value].isChkBx) {
				    if ((g_criteriaEntryLabel[selectObj.value].chkbxStore1 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxStore1 == 'true')) {
					criteriaEntryChk1.checked = true;}
				    if ((g_criteriaEntryLabel[selectObj.value].chkbxStore2 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxStore2 == 'true')) {
					criteriaEntryChk2.checked = true;}
				    if ((g_criteriaEntryLabel[selectObj.value].chkbxStore3 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxStore3 == 'true')) {
					criteriaEntryChk3.checked = true;}
					if ((g_criteriaEntryLabel[selectObj.value].chkbxStore4 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxStore4 == 'true')) {
					criteriaEntryChk4.checked = true;}
					if ((g_criteriaEntryLabel[selectObj.value].chkbxStore5 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxStore5 == 'true')) {
					criteriaEntryChk5.checked = true;}
					if ((g_criteriaEntryLabel[selectObj.value].chkbxStore6 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxStore6 == 'true')) {
					criteriaEntryChk6.checked = true;}
					if ((g_criteriaEntryLabel[selectObj.value].chkbxStore7 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxStore7 == 'true')) {
					criteriaEntryChk7.checked = true;}
					if ((g_criteriaEntryLabel[selectObj.value].chkbxStore8 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxStore8 == 'true')) {
					criteriaEntryChk8.checked = true;}
					if ((g_criteriaEntryLabel[selectObj.value].chkbxStore9 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxStore9 == 'true')) {
					criteriaEntryChk9.checked = true;}
					if ((g_criteriaEntryLabel[selectObj.value].chkbxStore10 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxStore10 == 'true')) {
					criteriaEntryChk10.checked = true;}
					if ((g_criteriaEntryLabel[selectObj.value].chkbxStore11 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxStore11 == 'true')) {
					criteriaEntryChk11.checked = true;}
					if ((g_criteriaEntryLabel[selectObj.value].chkbxStore12 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxStore12 == 'true')) {
					criteriaEntryChk12.checked = true;}
						
			displaychkbx('inline');
			}
			else if (g_criteriaEntryLabel[selectObj.value].isChkBx2) {
			        if ((g_criteriaEntryLabel[selectObj.value].chkbxTDStore1 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxTDStore1 == 'true')) {
					criteriaEntryTDChk1.checked = true;}
				    if ((g_criteriaEntryLabel[selectObj.value].chkbxTDStore2 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxTDStore2 == 'true')) {
					criteriaEntryTDChk2.checked = true;}
				    if ((g_criteriaEntryLabel[selectObj.value].chkbxTDStore3 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxTDStore3 == 'true')) {
					criteriaEntryTDChk3.checked = true;}
					if ((g_criteriaEntryLabel[selectObj.value].chkbxTDStore4 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxTDStore4 == 'true')) {
					criteriaEntryTDChk4.checked = true;}
					if ((g_criteriaEntryLabel[selectObj.value].chkbxTDStore5 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxTDStore5 == 'true')) {
					criteriaEntryTDChk5.checked = true;}
					if ((g_criteriaEntryLabel[selectObj.value].chkbxTDStore6 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxTDStore6 == 'true')) {
					criteriaEntryTDChk6.checked = true;}
					if ((g_criteriaEntryLabel[selectObj.value].chkbxTDStore7 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxTDStore7 == 'true')) {
					criteriaEntryTDChk7.checked = true;}
					if ((g_criteriaEntryLabel[selectObj.value].chkbxTDStore8 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxTDStore8 == 'true')) {
					criteriaEntryTDChk8.checked = true;}
					if ((g_criteriaEntryLabel[selectObj.value].chkbxTDStore9 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxTDStore9 == 'true')) {
					criteriaEntryTDChk9.checked = true;}
					if ((g_criteriaEntryLabel[selectObj.value].chkbxTDStore10 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxTDStore10 == 'true')) {
					criteriaEntryTDChk10.checked = true;}
					if ((g_criteriaEntryLabel[selectObj.value].chkbxTDStore11 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxTDStore11 == 'true')) {
					criteriaEntryTDChk11.checked = true;}
					if ((g_criteriaEntryLabel[selectObj.value].chkbxTDStore12 == true) || (g_criteriaEntryLabel[selectObj.value].chkbxTDStore12 == 'true')) {
					criteriaEntryTDChk12.checked = true;}
					displaychkbxTD('inline');
			}
			else {
				// Reload the stored value.
				if (g_criteriaEntryLabel[selectObj.value].stored1) 
				{
					criteriaEntry1.value = g_criteriaEntryLabel[selectObj.value].stored1;
				} 
				else
				{
					criteriaEntry1.value = '';
				}
				// Show the input box.
				criteriaEntry1.style.display = 'inline';
			}
		}

		// If it has a second label and that label isn't blank then...
		if ((g_criteriaEntryLabel[selectObj.value][1]) && (g_criteriaEntryLabel[selectObj.value][1] != '')) {
			// Set the label text and show it.
			criteriaEntry2Label.innerHTML = g_criteriaEntryLabel[selectObj.value][1] + ' ';
			criteriaEntry2Label.style.display = 'inline';

			if (g_criteriaEntryLabel[selectObj.value].isRadio) {
				criteriaEntryRadio2.style.display = 'inline';
			} else {
				// Reload the stored value.
				if (g_criteriaEntryLabel[selectObj.value].stored2) {
					criteriaEntry2.value = g_criteriaEntryLabel[selectObj.value].stored2;
				} else {
					criteriaEntry2.value = '';
				}
				// Show the input box.
				criteriaEntry2.style.display = 'inline';
			}
		}
	}
}

//SK
function displaychkbx(displaytype)
{
var checkboxtable = document.getElementById('tbcheckbox');
	var criteriaEntryChk1 = document.getElementById('chk01');
	var criteriaEntryChk2 = document.getElementById('chk02');
	var criteriaEntryChk3 = document.getElementById('chk03');
	var criteriaEntryChk4 = document.getElementById('chk04');
	var criteriaEntryChk5 = document.getElementById('chk05');
	var criteriaEntryChk6 = document.getElementById('chk06');
	var criteriaEntryChk7 = document.getElementById('chk07');
	var criteriaEntryChk8 = document.getElementById('chk08');
	var criteriaEntryChk9 = document.getElementById('chk09');
	var criteriaEntryChk10 = document.getElementById('chk10');
	var criteriaEntryChk11 = document.getElementById('chk11');
	var criteriaEntryChk12 = document.getElementById('chk12');
	var chkbxLabel1 = document.getElementById('chkbxLabel1');
	var chkbxLabel2 = document.getElementById('chkbxLabel2');
	var chkbxLabel3 = document.getElementById('chkbxLabel3');
	var chkbxLabel4 = document.getElementById('chkbxLabel4');
	var chkbxLabel5 = document.getElementById('chkbxLabel5');
	var chkbxLabel6 = document.getElementById('chkbxLabel6');
	var chkbxLabel7 = document.getElementById('chkbxLabel7');
	var chkbxLabel8 = document.getElementById('chkbxLabel8');
	var chkbxLabel9 = document.getElementById('chkbxLabel9');
	var chkbxLabel10 = document.getElementById('chkbxLabel10');
	var chkbxLabel11 = document.getElementById('chkbxLabel11');
	var chkbxLabel12 = document.getElementById('chkbxLabel12');
	checkboxtable.style.display = displaytype;
    criteriaEntryChk1.style.display = displaytype;
	criteriaEntryChk2.style.display = displaytype;
	criteriaEntryChk3.style.display = displaytype;
	criteriaEntryChk4.style.display = displaytype;
	criteriaEntryChk5.style.display = displaytype;
	criteriaEntryChk6.style.display = displaytype;
	criteriaEntryChk7.style.display = displaytype;
	criteriaEntryChk8.style.display = displaytype;
	criteriaEntryChk9.style.display = displaytype;
	criteriaEntryChk10.style.display = displaytype;
	criteriaEntryChk11.style.display = displaytype;
	criteriaEntryChk12.style.display = displaytype;
	chkbxLabel1.style.display = displaytype;
	chkbxLabel2.style.display = displaytype;
	chkbxLabel3.style.display = displaytype;
	chkbxLabel4.style.display = displaytype;
	chkbxLabel5.style.display = displaytype;
	chkbxLabel6.style.display = displaytype;
	chkbxLabel7.style.display = displaytype;
	chkbxLabel8.style.display = displaytype;
	chkbxLabel9.style.display = displaytype;
	chkbxLabel10.style.display = displaytype;
	chkbxLabel11.style.display = displaytype;
	chkbxLabel12.style.display = displaytype;


}

//AMW
function displaychkbxTD(displaytype)
{
var checkboxtable = document.getElementById('tbTxDstChkBx');
	var criteriaEntryTDChk1 = document.getElementById('chkTx01');
	var criteriaEntryTDChk2 = document.getElementById('chkTx02');
	var criteriaEntryTDChk3 = document.getElementById('chkTx03');
	var criteriaEntryTDChk4 = document.getElementById('chkTx04');
	var criteriaEntryTDChk5 = document.getElementById('chkTx05');
	var criteriaEntryTDChk6 = document.getElementById('chkTx06');
	var criteriaEntryTDChk7 = document.getElementById('chkTx07');
	var criteriaEntryTDChk8 = document.getElementById('chkTx08');
	var criteriaEntryTDChk9 = document.getElementById('chkTx09');
	var criteriaEntryTDChk10 = document.getElementById('chkTx10');
	var criteriaEntryTDChk11 = document.getElementById('chkTx11');
	var criteriaEntryTDChk12 = document.getElementById('chkTx12');
	var criteriaEntryTDChk13 = document.getElementById('chkTx13');
	var criteriaEntryTDChk14 = document.getElementById('chkTx14');
	var criteriaEntryTDChk15 = document.getElementById('chkTx15');
	var criteriaEntryTDChk16 = document.getElementById('chkTx16');
	var criteriaEntryTDChk17 = document.getElementById('chkTx17');
	var criteriaEntryTDChk18 = document.getElementById('chkTx18');
	
	var chkbxLabel1 = document.getElementById('TxLabel1');
	var chkbxLabel2 = document.getElementById('TxLabel2');
	var chkbxLabel3 = document.getElementById('TxLabel3');
	var chkbxLabel4 = document.getElementById('TxLabel4');
	var chkbxLabel5 = document.getElementById('TxLabel5');
	var chkbxLabel6 = document.getElementById('TxLabel6');
	var chkbxLabel7 = document.getElementById('TxLabel7');
	var chkbxLabel8 = document.getElementById('TxLabel8');
	var chkbxLabel10 = document.getElementById('TxLabel10');
	var chkbxLabel11 = document.getElementById('TxLabel11');
	var chkbxLabel12 = document.getElementById('TxLabel12');
	var chkbxLabel13 = document.getElementById('TxLabel13');
	var chkbxLabel14 = document.getElementById('TxLabel14');
	var chkbxLabel15 = document.getElementById('TxLabel15');
	var chkbxLabel16 = document.getElementById('TxLabel16');
	var chkbxLabel17 = document.getElementById('TxLabel17');
	var chkbxLabel18 = document.getElementById('TxLabel18');
	
	checkboxtable.style.display = displaytype;
    criteriaEntryTDChk1.style.display = displaytype;
	criteriaEntryTDChk2.style.display = displaytype;
	criteriaEntryTDChk3.style.display = displaytype;
	criteriaEntryTDChk4.style.display = displaytype;
	criteriaEntryTDChk5.style.display = displaytype;
	criteriaEntryTDChk6.style.display = displaytype;
	criteriaEntryTDChk7.style.display = displaytype;
	criteriaEntryTDChk8.style.display = displaytype;
	criteriaEntryTDChk9.style.display = displaytype;
	criteriaEntryTDChk10.style.display = displaytype;
	criteriaEntryTDChk11.style.display = displaytype;
	criteriaEntryTDChk12.style.display = displaytype;
	criteriaEntryTDChk13.style.display = displaytype;
	criteriaEntryTDChk14.style.display = displaytype;
	criteriaEntryTDChk15.style.display = displaytype;
	criteriaEntryTDChk16.style.display = displaytype;
	criteriaEntryTDChk17.style.display = displaytype;
	criteriaEntryTDChk18.style.display = displaytype;
	
	chkbxLabel1.style.display = displaytype;
	chkbxLabel2.style.display = displaytype;
	chkbxLabel3.style.display = displaytype;
	chkbxLabel4.style.display = displaytype;
	chkbxLabel5.style.display = displaytype;
	chkbxLabel6.style.display = displaytype;
	chkbxLabel7.style.display = displaytype;
	chkbxLabel8.style.display = displaytype;
	chkbxLabel9.style.display = displaytype;
	chkbxLabel10.style.display = displaytype;
	chkbxLabel11.style.display = displaytype;
	chkbxLabel12.style.display = displaytype;
	chkbxLabel13.style.display = displaytype;
	chkbxLabel14.style.display = displaytype;
	chkbxLabel15.style.display = displaytype;
	chkbxLabel16.style.display = displaytype;
	chkbxLabel17.style.display = displaytype;
	chkbxLabel18.style.display = displaytype;

}


function storeValue(inputObj) 
{
 
	// Get the ID so we know if this is value 1 or 2.
	var thisID = inputObj.id;
	var thisValue = inputObj.checked ? inputObj.checked : inputObj.value;
	var thisNumber = 0;
	
	
	
	
	// Get the current criteria.
	var currCriteria = '';
	if (document.getElementById('criteria'))
	{
		currCriteria = document.getElementById('criteria').value;
	}
	else 
	{
		return false;
	}
	
	//SK
	setChkbxValues(thisID,thisValue,currCriteria);
}

//SK
function setChkbxValues(thisID,thisValue,currCriteria)
{

    if (g_criteriaEntryLabel[currCriteria].isChkBx || g_criteriaEntryLabel[currCriteria].isChkBx2)
    {
        if (thisID) 
        {
		    thisNumber = thisID.substring(thisID.length - 2);
	    }
	    else
	    {
		return false;
	    }
	}
	else
	{
		if (thisID) 
		{
    		thisNumber = thisID.substring(thisID.length - 1);
    		
    	} 
    	else
    	{
		return false;
	    }
	}
	
	if (g_criteriaEntryLabel[currCriteria].isChkBx) 
	{
	    switch (thisNumber)
	    {
	    
            case '01':
	     		  
      		    g_criteriaEntryLabel[currCriteria].chkbxStore1 = thisValue;
       		    break;
    
    	    case'02':
	    
    		    g_criteriaEntryLabel[currCriteria].chkbxStore2 = thisValue;
    		    break;
        	
    	    case '03':
	        
    		    g_criteriaEntryLabel[currCriteria].chkbxStore3 = thisValue;
    	        break;
    	        
    	    case '04':
	        
    		    g_criteriaEntryLabel[currCriteria].chkbxStore4 = thisValue;
    	        break;
    	        
    	    case '05':
	       
    		    g_criteriaEntryLabel[currCriteria].chkbxStore5 = thisValue;
    		    break;
    	    
    	    case '06':
	        
    		    g_criteriaEntryLabel[currCriteria].chkbxStore6 = thisValue;
    	        break;
    	        
    	    case '07':
	       
    		    g_criteriaEntryLabel[currCriteria].chkbxStore7 = thisValue;
    	        break;
    	        
    	    case '08':
	        
    		    g_criteriaEntryLabel[currCriteria].chkbxStore8 = thisValue;
    		    break;
    	    
    	    case '09':
	        
    		    g_criteriaEntryLabel[currCriteria].chkbxStore9 = thisValue;
    		    break;
    	    
    	    case '10':
	        
    		    g_criteriaEntryLabel[currCriteria].chkbxStore10 = thisValue;
    		    break;
    	    
    	    case '11':
	        
    		    g_criteriaEntryLabel[currCriteria].chkbxStore11 = thisValue;
    		    break;
    	    
    	    case '12':
	       
	       	    g_criteriaEntryLabel[currCriteria].chkbxStore12 = thisValue;
	       	    break;
	     }  	  
    }
    else if (g_criteriaEntryLabel[currCriteria].isChkBx2) 
	{
	    switch (thisNumber)
	    {
	    
            case '01':
	     		  
      		    g_criteriaEntryLabel[currCriteria].chkbxTDStore1 = thisValue;
       		    break;
    
    	    case'02':
	    
    		    g_criteriaEntryLabel[currCriteria].chkbxTDStore2 = thisValue;
    		    break;
        	
    	    case '03':
	        
    		    g_criteriaEntryLabel[currCriteria].chkbxTDStore3 = thisValue;
    	        break;
    	        
    	    case '04':
	        
    		    g_criteriaEntryLabel[currCriteria].chkbxTDStore4 = thisValue;
    	        break;
    	        
    	    case '05':
	       
    		    g_criteriaEntryLabel[currCriteria].chkbxTDStore5 = thisValue;
    		    break;
    	    
    	    case '06':
	        
    		    g_criteriaEntryLabel[currCriteria].chkbxTDStore6 = thisValue;
    	        break;
    	        
    	    case '07':
	       
    		    g_criteriaEntryLabel[currCriteria].chkbxTDStore7 = thisValue;
    	        break;
    	        
    	    case '08':
	        
    		    g_criteriaEntryLabel[currCriteria].chkbxTDStore8 = thisValue;
    		    break;
    	    
    	    case '09':
	        
    		    g_criteriaEntryLabel[currCriteria].chkbxTDStore9 = thisValue;
    		    break;
    	    
    	    case '10':
	        
    		    g_criteriaEntryLabel[currCriteria].chkbxTDStore10 = thisValue;
    		    break;
    	    
    	    case '11':
	        
    		    g_criteriaEntryLabel[currCriteria].chkbxTDStore11 = thisValue;
    		    break;
    	    
    	    case '12':
	       
	       	    g_criteriaEntryLabel[currCriteria].chkbxTDStore12 = thisValue;
	       	    break;
	       	
	       case '13':
	       
	       	    g_criteriaEntryLabel[currCriteria].chkbxTDStore13 = thisValue;
	       	    break;
	       	    
	       case '14':
	       
	       	    g_criteriaEntryLabel[currCriteria].chkbxTDStore14 = thisValue;
	       	    break;
	       	    
	       case '15':
	       
	       	    g_criteriaEntryLabel[currCriteria].chkbxTDStore15 = thisValue;
	       	    break;
	       	    
	      case '16':
	       
	       	    g_criteriaEntryLabel[currCriteria].chkbxTDStore16 = thisValue;
	       	    break;
	       	    
	      case '17':
	       
	       	    g_criteriaEntryLabel[currCriteria].chkbxTDStore17 = thisValue;
	       	    break;
	       	    
	      case '18':
	       
	       	    g_criteriaEntryLabel[currCriteria].chkbxTDStore18 = thisValue;
	       	    break;
	     }  	  
    }
    else
	{
	    if (thisNumber == '1') 
	    {
		    g_criteriaEntryLabel[currCriteria].stored1 = thisValue;
		
		    if (g_criteriaEntryLabel[currCriteria].isRadio)
		    {
			    g_criteriaEntryLabel[currCriteria].stored2 = !thisValue;
		    }
	    }
	    else if (thisNumber == '2')
	    {
		    g_criteriaEntryLabel[currCriteria].stored2 = thisValue;
		
		    if (g_criteriaEntryLabel[currCriteria].isRadio) 
		    {
			    g_criteriaEntryLabel[currCriteria].stored1 = !thisValue;
		    }
	    }
	    else
	    {
		    return false;
	    }
    }
}
    
function addCriteria() {
	// Get the current criteria.

	var currCriteriaValue = '';
	var currCriteriaName = '';
	var currCriteriaIsNumeric = false;
	var currCriteriaIsDate = false;
	var currCriteriaIsRadio = false;
	var currCriteriaIsChkbx = false;
	var currCriteriaIsChkbx2 = false;
	var has1 = false;
	var has2 = false;
	var isOptional1 = false;
	var isOptional2 = false;
	if (document.getElementById('criteria')) {
		currCriteriaValue = document.getElementById('criteria').value;
		currCriteriaName = document.getElementById('criteria').options[document.getElementById('criteria').selectedIndex].text;

		if (!g_criteriaEntryLabel[currCriteriaValue]) {return false;}
		
		currCriteriaIsNumeric = g_criteriaEntryLabel[currCriteriaValue].isNumeric;
		currCriteriaIsDate = g_criteriaEntryLabel[currCriteriaValue].isDate;
		currCriteriaIsRadio = g_criteriaEntryLabel[currCriteriaValue].isRadio;
		currCriteriaIsChkbx = g_criteriaEntryLabel[currCriteriaValue].isChkBx;
		currCriteriaIsChkbx2 = g_criteriaEntryLabel[currCriteriaValue].isChkBx2;
		
		if ((g_criteriaEntryLabel[currCriteriaValue][0]) && (g_criteriaEntryLabel[currCriteriaValue][0] != '')) {has1 = true;}
		if ((g_criteriaEntryLabel[currCriteriaValue][1]) && (g_criteriaEntryLabel[currCriteriaValue][1] != '')) {has2 = true;}
		if ((g_criteriaEntryLabel[currCriteriaValue].isOptional1) && (g_criteriaEntryLabel[currCriteriaValue].isOptional1 == true)) {isOptional1 = true;}
		if ((g_criteriaEntryLabel[currCriteriaValue].isOptional2) && (g_criteriaEntryLabel[currCriteriaValue].isOptional2 == true)) {isOptional2 = true;}
	} else {
		return false;
	}
	
	// Get the criteriaInputs
	var criteriaEntry1 = document.getElementById('criteriaEntry1');
	var criteriaEntry2 = document.getElementById('criteriaEntry2');
	var criteriaEntryRadio1 = document.getElementById('criteriaEntryRadio1');
	var criteriaEntryRadio2 = document.getElementById('criteriaEntryRadio2');
	var criteriaEntry1Value = '';
	var criteriaEntry2Value = '';
    var chkbxList='';
    var chkbxList1 = '';
    var chkbxTDList='';
    var chkbxTDList1 = '';
	

	// Add this criteria to the holding list.
	var criteriaHolding = document.getElementById('currentCriteria');
	if (!criteriaHolding) {return false;}

	// Process the values, make sure they are valid.
	// First check it against the custom handler.

	if ((g_criteriaEntryLabel[currCriteriaValue].regexp) && (g_criteriaEntryLabel[currCriteriaValue].regexp != '')) 
	{
		var customRegExp = g_criteriaEntryLabel[currCriteriaValue].regexp;
		var customRegExpErrorMsg = g_criteriaEntryLabel[currCriteriaValue].regexpFailed;

		// If there is an input1 then validate it.
		//SK
	    if (currCriteriaIsChkbx)
	    {
	   
	        for(i=1;i<=12;i++)
	        {
	            if (i<10 )
	            {
        	
	              if (document.getElementById('chk0' + i).checked)
	                 {
	                  chkbxList = chkbxList + document.getElementById('chk0'+ i ).value  + ' - ' + document.getElementById('chk0' + i).checked + ' ';
	                  chkbxList1 = chkbxList1 + ' ' + 'chk0' + i;
		             }
	            }
	            else
	            {
		            if (document.getElementById('chk' + i).checked)
	                {
	                    chkbxList = chkbxList + document.getElementById('chk'+ i ).value  + ' - ' + document.getElementById('chk' + i).checked + ' ';
	                    chkbxList1 = chkbxList1 + ' ' + 'chk' + i;
        		     }
	            }
        		
	        }
    	
	    }
	   //AMW
	 else if (currCriteriaIsChkbx2)
	    {
	   
	        for(i=1;i<=18;i++)
	        {
	            if (i<10 )
	            {
        	
	              if (document.getElementById('chkTx0' + i).checked)
	                 {
	                  chkbxTDList = chkbxTDList + document.getElementById('chkTx0'+ i ).value  + ' - ' + document.getElementById('chkTx0' + i).checked + ' ';
	                  chkbxTDList1 = chkbxTDList1 + ' ' + 'chkTx0' + i;
		             }
	            }
	            else
	            {
		            if (document.getElementById('chkTx' + i).checked)
	                {
	                    chkbxTDList = chkbxTDList + document.getElementById('chkTx'+ i ).value  + ' - ' + document.getElementById('chkTx' + i).checked + ' ';
	                    chkbxTDList1 = chkbxTDList1 + ' ' + 'chkTx' + i;
        		     }
	            }
        		
	        }
    	
	    }
	else 
	{
		 if (has1)
		 {
			var matching = criteriaEntry1.value.match(customRegExp);
			if (!matching)
		   {
				alert(customRegExpErrorMsg);
				criteriaEntry1.focus();
				return false;
			}
			criteriaEntry1Value = criteriaEntry1.value;
		}
		}
				// If there is an input2 then validate it as well.
		if (has2) 
		{
			// Strip all commas and dollar signs.
			var matching = criteriaEntry2.value.match(customRegExp);
			if (!matching)
			 {
				if ((criteriaEntry2.value == '') && (isOptional2))
				{
					// Do nothing, the user is allowed to leave this value blank for this type.
				} else
				{
					alert(customRegExpErrorMsg);
					criteriaEntry2.focus();
					return false;
				}
			}
			criteriaEntry2Value = criteriaEntry2.value;
		}
	
}
	// Now check it against the built-in handler.
	if (currCriteriaIsNumeric) {
		// Validate the input.
		// If there is an input1 then validate it.
		if (has1) {
			// Strip all commas and dollar signs.
			criteriaEntry1.value = criteriaEntry1.value.replace(/,/g,'').replace(/\$/g,'');
			var matching = criteriaEntry1.value.match(/^([\d]+)?([\.]?[\d]+)$/);
			if (!matching) {
				alert('Please enter a valid number.');
				criteriaEntry1.focus();
				return false;
			}
			criteriaEntry1Value = criteriaEntry1.value;
		}
		// If there is an input2 then validate it as well.
		if (has2) {
			// Strip all commas and dollar signs.
			criteriaEntry2.value = criteriaEntry2.value.replace(/,/g,'').replace(/\$/g,'');
			var matching = criteriaEntry2.value.match(/^([\d]+)?([\.]?[\d]+)$/);
			if (!matching) {
				if ((criteriaEntry2.value == '') && (isOptional2)) {
					// Do nothing, the user is allowed to leave this value blank for this type.
				} else {
					alert('Please enter a valid number.');
					criteriaEntry2.focus();
					return false;
				}
			}
			criteriaEntry2Value = criteriaEntry2.value;
		}
	} else if(currCriteriaIsDate) {
		// Validate the input.
		// If there is an input1 then validate it.
		if (has1) {
			// Convert dashes to slashes.
			criteriaEntry1.value = criteriaEntry1.value.replace(/-/g,'/');
			// It isn't pretty, but it will match 2 digit and 4 digit years.
			var matching = criteriaEntry1.value.match(/^([01]?[0-9]{1})\/{1}([0123]?[0-9]{1})\/{1}([12][0-9]{3}|[0-9]{2})$/);
			if (!matching) {
				alert('Please enter a date.');
				criteriaEntry1.focus();
				return false;
			}
			criteriaEntry1Value = criteriaEntry1.value;
		}
		// If there is an input2 then validate it as well.
		if (has2) {
			// Convert dashes to slashes.
			criteriaEntry2.value = criteriaEntry2.value.replace(/-/g,'/');
			// It isn't pretty, but it will match 2 digit and 4 digit years.
			var matching = criteriaEntry2.value.match(/^([01]?[0-9]{1})\/{1}([0123]?[0-9]{1})\/{1}([12][0-9]{3}|[0-9]{2})$/);
			if (!matching) {
				if ((criteriaEntry2.value == '') && (isOptional2)) {
					// Do nothing, the user is allowed to leave this field blank for this type.
				} else {
					alert('Please enter a date.');
					criteriaEntry2.focus();
					return false;
				}
			}
			criteriaEntry2Value = criteriaEntry2.value;
		}
	} else if (currCriteriaIsRadio) {
		criteriaEntry1Value = criteriaEntryRadio1.checked;
		criteriaEntry2Value = '';
		
	}

	
	 else {
		// Alphanumeric, make sure that there is a valid.
		//SK
		if (currCriteriaIsChkbx || currCriteriaIsChkbx2)
		{
		}
		else
		{
		if (has1) 
		{
			criteriaEntry1.value = criteriaEntry1.value.replace(/[|]/g,':');
			if (criteriaEntry1.value == '')
		    {
				alert('Please enter a value.');
				criteriaEntry1.focus();
				return false;
			}
			criteriaEntry1Value = criteriaEntry1.value;
		}
		}
		if (has2) {
			criteriaEntry2.value = criteriaEntry2.value.replace(/[|]/g,':');
			if (criteriaEntry2.value == '') {
				if ((criteriaEntry2.value == '') && (isOptional2)) {
					// Do nothing, the user is allowed to enter a blank value for this type.
				} else {
					alert('Please enter a value.');
					criteriaEntry2.focus();
					return false;
				}
			}
			criteriaEntry2Value = criteriaEntry2.value;
		}
	}
	
	
var criteriaDisplay = '';
//SK
 if (currCriteriaIsChkbx)
 {
     if (criteriaEntry2Value != '')
     {
		    criteriaDisplay = currCriteriaName + ':' + chkbxList + ' and DOR Use Code - ' +  criteriaEntry2Value;
	 } 
	 else 
	 {
		    criteriaDisplay = currCriteriaName + ':' + chkbxList ;
	 }
 }
 else if (currCriteriaIsChkbx2)
 {
     if (criteriaEntry2Value != '')
     {
		    criteriaDisplay = currCriteriaName + ':' + chkbxTDList + ' and Tax District Code - ' +  criteriaEntry2Value;
	 } 
	 else 
	 {
		    criteriaDisplay = currCriteriaName + ':' + chkbxTDList ;
	 }
 }
 else
 {
	if (criteriaEntry2Value != '') {
		criteriaDisplay = currCriteriaName + ':' + criteriaEntry1Value + '-' + criteriaEntry2Value;
	} else {
		criteriaDisplay = currCriteriaName + ':' + criteriaEntry1Value.toString().toUpperCase();
	}
}
	// If this value already exists then select it and remove it before adding it.
	for (var i=0;i<criteriaHolding.options.length;i++) {
		// Get everything before the first pipe, test it against the upcoming value.
		var matchTest = '^' + currCriteriaValue + '\\|';
		if (criteriaHolding.options[i].value.match(matchTest)) {
			// Select this one and then remove it.
			criteriaHolding.selectedIndex = i;
			removeCriteria();
			break;
		}
	}
	
	//SK
	if (currCriteriaIsChkbx)
	{
	criteriaHolding.options[criteriaHolding.options.length] = new Option(criteriaDisplay, currCriteriaValue + '|' + chkbxList1 + '|' + criteriaEntry2Value);
	
	}
	else if (currCriteriaIsChkbx2)
	{
	criteriaHolding.options[criteriaHolding.options.length] = new Option(criteriaDisplay, currCriteriaValue + '|' + chkbxTDList1 + '|' + criteriaEntry2Value);
	
	}
	else
	{
	criteriaHolding.options[criteriaHolding.options.length] = new Option(criteriaDisplay, currCriteriaValue + '|' + criteriaEntry1Value + '|' + criteriaEntry2Value);
	}

	// Clear the values then store them.
	criteriaEntry1.value = '';
	criteriaEntry2.value = '';
	criteriaEntryRadio1.checked = false;
	criteriaEntryRadio2.checked = false;
	
	//SK
	if (currCriteriaIsChkbx)
	{
	 for(i=1;i<=12;i++)
	        {
	            if (i<10 )
	            {
        	
	              if (document.getElementById('chk0' + i).checked)
	                 {
	                  document.getElementById('chk0' + i).checked=false;
	                  storeValue(document.getElementById('chk0' + i));
	                  
		             }
	            }
	            else
	            {
		            if (document.getElementById('chk' + i).checked)
	                {
	                    document.getElementById('chk' + i).checked=false;
	                  storeValue(document.getElementById('chk' + i));
	                 
	                }
	            }
	         }
	                  
	}
	if (currCriteriaIsRadio) {
		storeValue(criteriaEntryRadio1);
		storeValue(criteriaEntryRadio2);
	} else {
		storeValue(criteriaEntry1);
		storeValue(criteriaEntry2);
	}
	
	// Enable the buttons.
	document.getElementById('btn_edit').disabled = false;
	document.getElementById('btn_remove').disabled = false;
	document.getElementById('btn_removeAll').disabled = false;
}



function editCriteria() 
{

    //debugger;
   	var criteriaHolding = document.getElementById('currentCriteria');
	if (!criteriaHolding) {
		return false;
	}
	
	if (criteriaHolding.selectedIndex == -1) {
		alert('Please select a criteria to edit.');
		return false;
	}

	// Get the value, parse it out.  Then set the stored variables for this selected criteria and call the changeCriteria function to modify it.
	var thisValue = criteriaHolding.options[criteriaHolding.selectedIndex].value;
	// Split it up.
	//var matches = thisValue.match(/^([\w]+)[|]{1}([^|]+)[|]{1}([^|]*)/i);
	var matches = thisValue.split('|');
	if (!matches) {return false;}
	if (!g_criteriaEntryLabel[matches[0]]) {return false;}
	
//SK
if (matches[0] == 'dor_cd')
{
     var chkbxList1 = matches[1].split(' ');
     for(j=0;j<=chkbxList1.length;j++)
     {
       setChkbxValues(chkbxList1[j],true,'dor_cd');
     }
	g_criteriaEntryLabel[matches[0]].stored2 = matches[2];
 
}
else if (matches[0] == 'tax_dist')
{
     var chkbxTDList1 = matches[1].split(' ');
     for(j=0;j<=chkbxTDList1.length;j++)
     {
       setChkbxValues(chkbxTDList1[j],true,'tax_dist');
     }
	g_criteriaEntryLabel[matches[0]].stored2 = matches[2];
 
}
else
{
	g_criteriaEntryLabel[matches[0]].stored1 = matches[1];
	g_criteriaEntryLabel[matches[0]].stored2 = matches[2];
}
	
	// Find this criteria in the "Choose Criteria" box and select it.
	var criteriaSelection = document.getElementById('criteria');
	if (!criteriaSelection) {return false;}
	for (var i=0;i<criteriaSelection.options.length;i++) {
		var matchTest = '^' + matches[0] + '$';
		if (criteriaSelection.options[i].value.match(matchTest)) {
			// Select this criteria.
			criteriaSelection.selectedIndex = i;
			break;
		}
	}

	criteriaChange(criteriaSelection);
}

function removeCriteria() {
	var criteriaHolding = document.getElementById('currentCriteria');
	if (!criteriaHolding) {return false;}

	if (criteriaHolding.selectedIndex > -1) {
		criteriaHolding.options[criteriaHolding.selectedIndex] = null;
	}

	// If this is the last criteria then disable the buttons.
	if (criteriaHolding.options.length == 0) {
		document.getElementById('btn_edit').disabled = true;
		document.getElementById('btn_remove').disabled = true;
		document.getElementById('btn_removeAll').disabled = true;
	} else {
		// Select the first entry now.
		criteriaHolding.selectedIndex = 0;
	}
}

function removeAllCriteria() {
	var criteriaHolding = document.getElementById('currentCriteria');
	if (!criteriaHolding) {return false;}
	
	criteriaHolding.options.length = 0;
	
	// Disable the buttons.
	document.getElementById('btn_edit').disabled = true;
	document.getElementById('btn_remove').disabled = true;
	document.getElementById('btn_removeAll').disabled = true;
}

function doSearch() {
   	// Copy everything in the currCriteria box into a form field and submit the form.
    var destinationField = document.getElementById('currCriteriaHolding');
    var currCriteria = document.getElementById('currentCriteria');
    if (currCriteria.options.length == 0) {
        alert('Search cannot be performed, you have not added any criteria.');
        return false;
    }
	if (!destinationField) {return false;}
	
	destinationField.value = combineCriteria();

//	if (document.getElementById(g_recordsPerPageElementName)) {
var t = document.getElementById(g_recordsPerPageElementName);
		//document.getElementById('recordsPerPage').value = document.getElementById(g_recordsPerPageElementName).value;
		document.getElementById('recordsPerPage').value = t.value;
	//}

	var sortBy = document.getElementById(g_sortByElementName);
	var sortByDirection = document.getElementById(g_sortByDirectionElementName);
	if ((sortBy) && (sortByDirection)) {
		if ((sortByDirection.value == '') || (sortByDirection.value == 'ASC')) {
			document.getElementById('sortBy').value = sortBy.value;
		} else {
			document.getElementById('sortBy').value = sortBy.value + ' DESC';
		}
	}
	if (document.getElementsByName('currentIndex')[0] )
	{
   document.getElementsByName('currentIndex')[0].value = '0';
 
   }
   
	document.getElementById('aspnetForm').submit();
}

function combineCriteria() 
{

	var criteriaHolding = document.getElementById('currentCriteria');
	var returnValue = '';
		
	for (var i=0;i<criteriaHolding.options.length;i++) {
		returnValue += criteriaHolding.options[i].value.replace(/~/g,'-').replace(/#/,'') + '#' + criteriaHolding.options[i].text.replace(/~/g,'-').replace(/#/,'') + '~';
	}

	return returnValue;
}

function onCriteriaLoad() {
	var savedCriteriaList = document.getElementById('savedCriteriaList');
	if (!savedCriteriaList) {return false;}
	if (savedCriteriaList.selectedIndex == -1) {return false;}

	thisName = savedCriteriaList[savedCriteriaList.selectedIndex].text;
	// Don't select the first entry.
	if (thisName == 'Select') {return false;}

	// Load the criteria from the cookie.
	thisValue = readCookie('savedCriteria-' + thisName);
	if (thisValue == null) {thisValue = '';}
	
	var criteriaHolding = document.getElementById('currentCriteria');
	// Remove all options
	while (criteriaHolding.options.length > 0) {
		criteriaHolding.options[criteriaHolding.options.length-1] = null;	
	}
	var criteriaArray = thisValue.split('~');
	for (var i=0;i<criteriaArray.length-1;i++) {
		if (criteriaArray[i] != '') {
			var subString = criteriaArray[i].split('#');
			// Add this option to the list.
			criteriaHolding.options[criteriaHolding.options.length] = new Option(subString[1], subString[0]);
		}
	}

	// Enable the buttons.
	document.getElementById('btn_edit').disabled = false;
	document.getElementById('btn_remove').disabled = false;
	document.getElementById('btn_removeAll').disabled = false;

	onCriteriaClose();
}

function onCriteriaDelete() {
	var savedCriteriaList = document.getElementById('savedCriteriaList');
	if (!savedCriteriaList) {return false;}
	if (savedCriteriaList.selectedIndex == -1) {return false;}

	thisName = savedCriteriaList[savedCriteriaList.selectedIndex].text;
	// Don't delete the first entry.
	if (thisName == 'Select') {return false;}

	// Get the name of the selected value.  1) Remove the cookie entry for it, 2) remove it from the namesList, 3) remove it from the select list.
	eraseCookie('savedCriteria-'+ thisName);

	// Rebuild the namesList, don't include the thisName value.
	// Get the names list cookie.
	var namesList = readCookie('savedCriteriaNames');
	
	// Stop if there are no names saved.
	if ((namesList != null) && (namesList != '')) {
		var newNamesList = '';
		var namesListArray = namesList.split('|');
		for (var i=0;i<namesListArray.length-2;i++) {
			if (namesListArray[i] != thisName) {
				newNamesList += namesListArray[i] + '|';
			}
		}
		eraseCookie('savedCriteriaNames');
		createCookie('savedCriteriaNames',newNamesList,360);
	}
	
	// Remove this entry from the select list.
	savedCriteriaList.options[savedCriteriaList.selectedIndex] = null;
}

function onCriteriaSave() {
	// Get the name.
	var saveCriteriaName = document.getElementById('saveCriteriaName');
	if (!saveCriteriaName) {return false;}
	var savedCriteriaList = document.getElementById('savedCriteriaList');
	if (!savedCriteriaList) {return false;}

	// Make sure it isn't a blank name.
	if (saveCriteriaName.value == '') {
		alert('Please specify a name.');
		return false;
	}

	var currCriteria = combineCriteria();

	// Save this to a cookie.
	createCookie('savedCriteria-'+ saveCriteriaName.value, currCriteria, 360);
	
	// Add the name to the namesList
	var namesList = readCookie('savedCriteriaNames');
	if (namesList == null) {namesList = '';}
	eraseCookie('savedCriteriaNames');
	namesList += saveCriteriaName.value + '|';
	
	createCookie('savedCriteriaNames',namesList, 360);
	
	// Add the name to the select list.
	savedCriteriaList.options[savedCriteriaList.options.length] = new Option(saveCriteriaName.value, currCriteria);

	onCriteriaClose();
}

function onCriteriaOpen() {
	populateSavedCriteriaList();

	var saveLoadDisplay = document.getElementById('saveLoadDisplay');
	if (saveLoadDisplay) {
		saveLoadDisplay.style.display = 'block';
	}
}

function onCriteriaClose() {
	var saveLoadDisplay = document.getElementById('saveLoadDisplay');
	if (saveLoadDisplay) {
		saveLoadDisplay.style.display = 'none';
	}
}

function populateSavedCriteriaList() {
	var savedCriteriaList = document.getElementById('savedCriteriaList');
	if (!savedCriteriaList) {return false;}
	
	// Get the names list cookie.
	var namesList = readCookie('savedCriteriaNames');
	
	// Stop if there are no names saved.
	if ((namesList == null) || (namesList == '')) {return false;}
	
	// Clear the options from the select list.
	while (savedCriteriaList.options.length > 0) {
		savedCriteriaList.options[savedCriteriaList.options.length-1] = null;	
	}
	
	// Add the names to the list, use the value for the name as the value of the option.
	var namesListArray = namesList.split('|');
	for (var i=0;i<namesListArray.length-1;i++) {
		if (namesListArray[i] != null) {
			var thisValue = readCookie('savedCriteria-' + namesListArray[i]);
			savedCriteriaList.options[savedCriteriaList.options.length] = new Option(namesListArray[i], thisValue);
		}
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
