var message;
//var destination;

function CopyChange(elementName, intLimit) {
	var objControl = null;
	var intLength = 0;

	objControl = new getObj(elementName).obj;
	intLength = objControl.value.length;

	objControl = new getObj(elementName + 'AvailChars').obj;
	objControl.innerHTML = intLimit - intLength;
};

function getStateCounties(county_id, all) {
	var objControl = null;
	// source
	objControl = new getObj('StateID').obj;
	state_id = (objControl.options[objControl.selectedIndex]).value;
	// destination
	objControl = new getObj('CountyID').obj;
	ajaxStateCounties(objControl, state_id, county_id, all);
};

function submitForm(dir) {
	if (dir=="N") {
		if (isValidForm()) {
			var objControl = null;

			objControl = new getObj('frmDiscrepancyReport').obj;
			//frmDiscrepancyReport.action = 'discrepancy_report_' + destination + '.asp';
			frmDiscrepancyReport.submit();
		} else {
			alert(message);
		};
	} else {
		frmDiscrepancyReport.submit();
	};
};

function setWizPage(display, validate) {
	setPage(display, 'WizPageToDisplay');
	//destination = display;
	setPage(validate, 'WizPageToValidate');
};

function setPage(pageNumber, controlName) {
	var objControl = null;
	objControl = new getObj(controlName).obj;
	objControl.value = pageNumber;
};

function isValidForm() {
	var isValid = true;
	var objControl = null;
	message = '';

	objControl = new getObj('WizPageToValidate').obj;
	intWizardPageToValidate = objControl.value;

	switch(intWizardPageToValidate) {
		case '1': // EMail
			isValid = isValidWizardPage1();
			break;
		case '2': // User
			isValid = isValidWizardPage2();
			break;
		case '3': // Discrepancy
			isValid = isValidWizardPage3();
			break;
		case '4': // Summary
			isValid = isValidWizardPage4();
			break;
		case '4': // Save
			isValid = isValidWizardPage5();
			break;
		default:
			alert('Unknown wizard page number [' + intWizardPageToValidate + ']');
			break;
	};
	
	if (!isValid) {
		return false;
	} else {
		return true;
	};
};

function addMessage(str) {
	if (message != '') {
		message += '\n';	
	};
	message += str;
};

///////////////////////////////////////////////////////////////////////////////
// PAGES //////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

function isValidWizardPage1() { // Personal
	var isValid = true;
	var message = '';

	objControl = new getObj('EMail').obj;
	strCache = trim(objControl.value);
	objControl.value = strCache;
	if (strCache == '') {
		isValid = false;
		addMessage('E-Mail address is a required field.');
	} else {
		if (strCache.length <= 100) {
			if (!isEMail(strCache)) {
				isValid = false;
				addMessage('Please enter a valid E-Mail address.');
			};
		} else {
			isValid = false;
			addMessage('E-Mail Address is limited to 100 characters.');
		};
	};

	return isValid;
};

function isValidWizardPage2() { // Other Occupants
	var isValid = true;
	var message = '';

	objControl = new getObj('FirstName').obj;
	strCache = trim(objControl.value);
	objControl.value = strCache;
	if (strCache == '') {
		isValid = false;
		addMessage('First Name is a required field.');
	} else {
		if (strCache.length > 50) {
			isValid = false;
			addMessage('First Name is limited to 50 characters.');
		};
	};
	
	objControl = new getObj('LastName').obj;
	strCache = trim(objControl.value);
	objControl.value = strCache;
	if (strCache == '') {
		isValid = false;
		addMessage('Last Name is a required field.');
	} else {
		if (strCache.length > 50) {
			isValid = false;
			addMessage('Last Name is limited to 50 characters.');
		};
	};

	objControl = new getObj('Phone').obj;
	strCache = trim(objControl.value);
	objControl.value = strCache;
	if (strCache != '') {
		if (strCache.length <= 20) {
			if (strCache.length >= 10) {
				if (!isPhoneNumber(strCache)) {
					isValid = false;
					addMessage('Please enter a valid Phone [(nnn) nnn-nnnn].');
				};
			} else {
				isValid = false;
				addMessage('Phone must contain at least 10 digits.');
			};
		} else {
			isValid = false;
			addMessage('Phone [(nnn) nnn-nnnn] is limited to 20 characters.');
		};
	};
	
	objControl = new getObj('CompanyName').obj;
	strCache = trim(objControl.value);
	objControl.value = strCache;
	if (strCache == '') {
		isValid = false;
		addMessage('Company Name is a required field.');
	} else {
		if (strCache.length > 100) {
			isValid = false;
			addMessage('Company Name is limited to 100 characters.');
		};
	};
	
	objControl = new getObj('StateID').obj;
	strCache = objControl.value;
	if (strCache == '') {
		isValid = false;
		addMessage('State is a required field.');
	};
	
	objControl = new getObj('CountyID').obj;
	strCache = objControl.value;
	if (strCache == '') {
		isValid = false;
		addMessage('County is a required field.');
	};
	
	objControl = new getObj('CRN').obj;
	strCache = trim(objControl.value);
	objControl.value = strCache;
	if (strCache == '') {
		isValid = false;
		addMessage('CRN is a required field.');
	} else {
		if (strCache.length > 15) {
			isValid = false;
			addMessage('CRN is limited to 15 characters.');
		};
	};
	
	objControl = new getObj('DiscrepancyTypeID').obj;
	strCache = objControl.value;
	if (strCache == '') {
		isValid = false;
		addMessage('Discrepancy Type is a required field.');
	} else { // PARSE OUT THE CATEGORY TYPE AND STORE IT
		var strCat
		var strText = document.frmDiscrepancyReport.DiscrepancyTypeID.options[document.frmDiscrepancyReport.DiscrepancyTypeID.selectedIndex].text;
		if (strText.indexOf("Image") >= 0) {
			strCat = "Image";
		} else {
			strCat = "Plant";
		};
		
		objControl = new getObj('DiscrepancyTypeCategory').obj;
		objControl.value = strCat
	};

	return isValid;
};

function isValidWizardPage3() { // Vehicles
	var isValid = true;
	var message = '';
	var strDiscrepancyTypeCategory
	
	objControl = new getObj('StateID').obj;
	strCache = objControl.value;
	if (strCache == '') {
		isValid = false;
		addMessage('State is a required field.');
	};
	
	objControl = new getObj('CountyID').obj;
	strCache = objControl.value;
	if (strCache == '') {
		isValid = false;
		addMessage('County is a required field.');
	};
	
	objControl = new getObj('DiscrepancyTypeCategory').obj;
	strDiscrepancyTypeCategory = objControl.value;
	
	if (strDiscrepancyTypeCategory != 'Image') { // DISCREPANCY_CATEGORY_PLANT
	
		objControl = new getObj('PlantMapNumber').obj;
		strCache = trim(objControl.value);
		objControl.value = strCache;
		if (strCache != '') {
			if (strCache.length > 15) {
				isValid = false;
				addMessage('Plant Map Number is limited to 15 characters.');
			};
		};
	
		objControl = new getObj('PlantOfficialRecordNumber').obj;
		strCache = trim(objControl.value);
		objControl.value = strCache;
		if (strCache != '') {
			if (strCache.length > 15) {
				isValid = false;
				addMessage('Plant Official Record Number is limited to 15 characters.');
			};
		};

		objControl = new getObj('PlantPolicyStarterNumber').obj;
		strCache = trim(objControl.value);
		objControl.value = strCache;
		if (strCache != '') {
			if (strCache.length > 20) {
				isValid = false;
				addMessage('Plant Policy Starter Number is limited to 20 characters.');
			};
		};
	
		objControl = new getObj('PlantLegalDescription').obj;
		strCache = trim(objControl.value);
		objControl.value = strCache;
		if (strCache != '') {
			if (strCache.length > 255) {
				isValid = false;
				addMessage('Plant Legal Description is limited to 255 characters.');
			};
		};
	
		objControl = new getObj('PlantTaxID').obj;
		strCache = trim(objControl.value);
		objControl.value = strCache;
		if (strCache != '') {
			if (strCache.length > 20) {
				isValid = false;
				addMessage('Plant Tax ID is limited to 20 characters.');
			};
		};
		
		objControl = new getObj('DiscrepancyDescription').obj;
		strCache = trim(objControl.value);
		objControl.value = strCache;
		if (strCache == '') {
			isValid = false;
			addMessage('Discrepancy Description is a required field.');
		} else {
			if (strCache.length > 255) {
				isValid = false;
				addMessage('Discrepancy Description is limited to 255 characters.');
			};
		};
		
	} else { // DISCREPANCY_CATEGORY_IMAGE
	
		objControl = new getObj('ImageTypeID').obj;
		strCache = objControl.value;
		if (strCache == '') {
			isValid = false;
			addMessage('Image Type is a required field.');
		};
	
		objControl = new getObj('ImageNumber').obj;
		strCache = trim(objControl.value);
		objControl.value = strCache;
		if (strCache == '') {
			isValid = false;
			addMessage('Image Number is a required field.');
		} else {
			if (strCache.length > 20) {
				isValid = false;
				addMessage('Image Number is limited to 20 characters.');
			};
		};
	
		objControl = new getObj('ImageDetails').obj;
		strCache = trim(objControl.value);
		objControl.value = strCache;
		if (strCache != '') {
			if (strCache.length > 255) {
				isValid = false;
				addMessage('Image Details is limited to 255 characters.');
			};
		};
	
	};

	return isValid;
};

function isValidWizardPage4() { // References
	var isValid = true;
	var message = '';
	
	// none

	return isValid;
};

function isValidWizardPage5() { // Emergency
	var isValid = true;
	var message = '';

	// none

	return isValid;
};

function doOverlib() {
	var strText = '';
	var strDiscrepancyType = '';
	var objControl = null;

	var strDiscrepancyType = document.frmDiscrepancyReport.DiscrepancyTypeID.options[document.frmDiscrepancyReport.DiscrepancyTypeID.selectedIndex].text;
	switch(strDiscrepancyType) {
		case 'Select':
			strText = "Select a discrepancy type from the following options";
			break;
		case 'Property Account Information (Plant)':
			strText = 'Any error, omission, or misinformation regarding property accounts such as:  incorrect or missing ‘From’ or ‘To’ property Pointers, an incorrect vacate date, errant cross reference information, or multiple ‘open’ (competing) property accounts describing identical property boundaries';
			break;
		case 'Map Account (Plant)':
			strText = 'Any Map account error, omission, or misinformation identified in Subdivision Lookup or elsewhere in TitlePoint/TitlePoint Express';
			break;
		case 'Map Image (Image)':
			strText = 'Any illegible, incorrect, mis-indexed, or unavailable Map image';
			break;
		case 'Official Record Document Posting (Plant)':
			strText = 'Any error, omission, or misinformation related to the Plant’s posting of an Officially Recorded document originating from the County Recorder’s Office';
			break;
		case 'Official Record Document Image (Image)':
			strText = 'Any illegible, incorrect, mis-indexed, or unavailable Officially Recorded Document image originating from the County Recorder’s Office';
			break;
		case 'Court Case Posting (Plant)':
			strText = 'Any error, omission, or misinformation related to the Plant’s posting of Filed Court case data as distinct from an Officially Recorded Document';
			break;
		case 'Court Case Image (Image)':
			strText = 'Any illegible, incorrect, mis-indexed, or unavailable Filed Court case image as distinct from an Officially Recorded Document image';
			break;
		case 'Policy or Starter Posting (Plant)':
			strText = 'Any error, omission, or misinformation related to the Plant’s posting of a Title Policy or Starter';
			break;
		case 'Policy or Starter Image (Image)':
			strText = 'Any illegible, incorrect, mis-indexed, or unavailable Title Policy or Starter';
			break;
		case 'Assessment Record Posting (Plant)':
			strText = 'Any error, omission, or misinformation related to the Plant’s posting of assessment Information such as Local, Rural, or Utility Improvement District liens';
			break;
		case 'Office Information Request (Plant)':
			strText = 'A request for the Plant to create an ‘Office Information’ posting on a specified legal description(s)';
			break;
		case 'Other (Plant)':
			strText = 'Any additional Plant discrepancy related to Property Insight’s administration of Plant data not otherwise specified';
			break;
		case 'Other (Image)':
			strText = 'Any additional Image discrepancy not otherwise specified';
			break;
		default:
			strText = 'No help available for this item.';
			break;
	};

	strText = '<span class="">' + strText + '</span>';
	
	return overlib(strText, CAPTION, 'Help: Discrepancy Type<br />' + strDiscrepancyType, FGCOLOR, 'lightblue', BGCOLOR, 'darkblue', HEIGHT, 50, ABOVE, LEFT, WIDTH, 350, OFFSETX, 10, OFFSETY, 60);
};