
var boolIgnoreFormClick = false;
var contextMenus = new Array();

//main method to be called whenever the form is clicked
function FormClicked()
{
	ClearForm();
	boolIgnoreFormClick = false;
}

//clears the form when the user clicks anywhere on it other than on a context menu
function ClearForm()
{
	if(!boolIgnoreFormClick)
	{		
		for(var x=0; x<contextMenus.length; x++)
			CloseContextMenu(contextMenus[x]);
		
		if(gfPop != null)
			gfPop.fHideCal();
			
		document.getElementById("masterBreadCrumbPanel").style.zIndex = 101;
		document.getElementById("masterContentPanel").style.zIndex = 102;
	}
}

//resize left div
function ResizeLeftDiv()
{
    var leftDiv = document.getElementById("idLeftToolbarFill");
    var rightDiv = document.getElementById("masterContentPanel");
    
    var ldHgt = leftDiv.clientHeight;
    var rdHgt = (rightDiv.clientHeight + 120);
    var pgHgt = document.body.clientHeight;
    
    //alert(leftDiv.clientHeight + "<" + rightDiv.clientHeight + "::" + document.body.clientHeight);

    //resize the left div if it is less than the right div OR if its bigger than the right div BUT still larger than the page height
    if(ldHgt < rdHgt || (ldHgt > rdHgt && rdHgt > pgHgt))
    {
        //alert(leftDiv.clientHeight);
        leftDiv.style.height = rdHgt + "px";
        //alert(leftDiv.clientHeight);
    }    
}


//used by various text fields that need to post back when the enter key is pressed
function ClickButton(e, buttonid)
{ 
    //this code works in both IE and Firefox
    var intKey = (window.Event) ? e.which : e.keyCode;
    if (intKey == 13) 
    { //enter key
        var bt = document.getElementById(buttonid); 
	    if(bt != null)
	    {
		    if (typeof bt == 'object')
		    { 
                bt.click(); 
            }
        }
        return false;
    }
    return true;
}

//launches the passed context menu and remembers that it is open so it can be managed
function LaunchContextMenu (id)
{
	var contextMenu = document.getElementById(id);
	var breadCrumb = document.getElementById("masterBreadCrumbPanel");
	var mainContent = document.getElementById("masterContentPanel");
	if(contextMenu != null)
	{
		contextMenus[contextMenus.length] = contextMenu;
		
		if (contextMenu.style.visibility == 'hidden') {
    		// Show menu
    		ClearForm();
    		contextMenu.style.visibility = 'visible';
    		breadCrumb.style.zIndex = 1;
    		mainContent.style.zIndex = 1;
		} else {
    		// Hide menu
    		ClearForm();
    		CloseContextMenu(contextMenu);
    		breadCrumb.style.zIndex = 101;
    		mainContent.style.zIndex = 102;
		}
	}
	boolIgnoreFormClick = true;
	return false;
}

//closes the passed context menu (div)
function CloseContextMenu(menu)
{
	menu.style.visibility = 'hidden';
}

var oldColor = new Array();
var HIGHLIGHT_ROW_COLOR = '#5B8DBF';

//mouse over highlight table row
function HighlightRow(rowToHighlightId) 
{
	var rowToHighlight = document.getElementById(rowToHighlightId);
	oldColor[rowToHighlightId] = rowToHighlight.style.backgroundColor;
	rowToHighlight.style.backgroundColor = HIGHLIGHT_ROW_COLOR;
}

//mouse out unhighlight table row
function UnHighlightRow(rowToUnHighlightId) 
{
	var rowToUnHighlight = document.getElementById(rowToUnHighlightId);
	rowToUnHighlight.style.backgroundColor = oldColor[rowToUnHighlightId];
}

//toggles the visibile/hidden visibility of two passed controls
function ToggleVisibility(idToShow, idToHide)
{
	var ctlToShow = document.getElementById(idToShow);
	var ctlToHide = document.getElementById(idToHide);
	
	if(ctlToShow != null && ctlToHide != null)
	{
		ctlToShow.style.visibility = "visible";
		ctlToHide.style.visibility = "hidden";
	}
	
	return true;
}

//Toggles the block/none display of two passed controls
function ToggleDisplay(idToShow, idToHide)
{
	var ctlToShow = document.getElementById(idToShow);
	var ctlToHide = document.getElementById(idToHide);
	
	if(ctlToShow != null && ctlToHide != null)
	{
		ctlToShow.style.display = "block";
		ctlToHide.style.display = "none";
	}
	
	return true;
}

//Called whenever a body loads on the page...updates the scroll position (replaces the need to use smartnavigation)
function ScrollIt(xId, yId)
{
	var x = document.getElementById(xId);
	var y = document.getElementById(yId);
	if(x != null && y != null)
		window.scrollTo(x.value, y.value);
}

//whenever the page is scrolled, the coordinates of the scroll position is saved here
//used in coordination with ScrollIt to manage the scroll position on the page
function SetCoords(xId, yId)
{
	var myPageX;
	var myPageY;
    if(document.all)
    {
		myPageX = document.body.scrollLeft;
		myPageY = document.body.scrollTop;
	}
    else
    {
		myPageX = window.pageXOffset;
		myPageY = window.pageYOffset;
	}
	
	var x = document.getElementById(xId);
	var y = document.getElementById(yId);
	if(x != null && y != null)
	{
		x.value = myPageX;
		y.value = myPageY;
	}
}

//used to disable a post button after its been clicked
function DisableControl(controlId)
{
	document.getElementById(controlId).disabled = true;
}

//calls the disable button function after an interval. This
//allows ASP.Net to post back first. 
function DisableControl_SetTimeout(controlId)
{
	setTimeout("DisableControl('" + controlId + "')", 100);
}

//Custom validation for the trans/reg Status - Sold form
function CustomValidateStatusSold(requiredFieldArray, jobOrderId)
{
	if(ValidateRequiredStrings(requiredFieldArray))
	{
		var jobOrderTB = document.getElementById(jobOrderId);
		if(IsInteger(TrimString(jobOrderTB.value)))
		{
			return true;
		}
		else
		{
			alert("The Job Order Number must be a round number.");
			return false;
		}
	}
	return false;
}

//Custom validation for the transformer replace screen
function CustomValidateTransformerReplace(requiredFieldArray, compNumId, validateCompNumId)
{
	if(ValidateRequiredStrings(requiredFieldArray))
	{
		var compNumberTB = document.getElementById(compNumId);
		var compNumberVerTB = document.getElementById(validateCompNumId);

		if(compNumberTB != null && compNumberVerTB != null)
		{
			if(TrimString(compNumberTB.value) != TrimString(compNumberVerTB.value))
			{
				alert("Transformer Company Number #2 has changed and has not been successfully validated. Please click the validate button before clicking the replace button.");
				return false;
			}
			else
			{
				return true;
			}
		}
		else
		{
			alert("DEBUG MSG - Cannot validate form because the company number control cannot be located.");
			return false;
		}
	}
	return false;
}

//Custom validation for the structure to structure span lengths
function CustomValidateStructureSpanLength(spanLengthId)
{
	if(ValidateRequiredStringValue(spanLengthId))
	{
		var spanCtrl = document.getElementById(spanLengthId);
		if(spanCtrl != null)
		{
			if(IsInteger(spanCtrl.value))
			{
				return true;
			}
			else
			{
				alert("The Span Length must be a valid whole number. Please update it or cancel the edit.");
				return false;
			}
		}
		else
		{
			alert("DEBUG MSG - Cannot validate form because the span length control cannot be located.");
			return false;
		}
	}
	else
	{
		alert("The Span Length cannot be blank. Please update it to a valid number or cancel the edit.");
		return false;
	}
}

//Custom validation for the test edit screen for the Transformers and Regulators
function CustomValidateOilTest(requiredFieldArray, typeId, ppmId)
{	
	if(ValidateRequiredStrings(requiredFieldArray))
	{
		return CustomValidateOilTestTypeAndPPM(typeId, ppmId);
	}
	else
	{
		return false;
	}
	return true;
}

//custom validation for the test type and ppm levels of the transformer/regulator test screens
function CustomValidateOilTestTypeAndPPM(typeId, ppmId)
{	
	var typeDD = document.getElementById(typeId);
	var ppmTB = document.getElementById(ppmId);
	
	if(typeDD != null && ppmTB != null)
	{
		if(IsInteger(TrimString(ppmTB.value)))
		{
			if(typeDD.value == "S")
			{
				if(TrimString(ppmTB.value) != "49" && TrimString(ppmTB.value) != "51" && TrimString(ppmTB.value) != "501")
				{
					alert("If the test type is a Screen Test, the PPM can only be 49, 51, or 501. Please update the PPM and re-submit.");
					return false;
				}
			}
			if(typeDD.value == "R")
			{
				if(TrimString(ppmTB.value) != "0")
				{
					alert("If the test type is a Retrofill, the PPM must be 0. Please update the PPM and re-submit.");
					return false;
				}
			}
			if(typeDD.value == "L")
			{
				if(ppmTB.value < 0 || ppmTB.value > 999)
				{
					alert("If the test type is a Lab Test, the PPM must be between 0 and 999. Please update the PPM and re-submit.");
					return false;
				}
			}
		}
		else
		{
			alert("The PPM must be valid integer value between 0 and 999. Please correct and re-submit.");
			return false;
		}
	}
	else
	{
		alert("DEBUG MSG - Cannot validate form because either TestType or PPM value is null.");
		return false;
	}
	return true;
}

//custom validation for the transformer and regulator install screen
function CustomValidateInstallTransReg(gridCdId, distRefId, matTktId, coLocId, coLocVerifyId, reqFieldArray, reqMatTktFieldArray)
{
	if(ValidateRequiredStringValue(matTktId))
	{
		if(!ValidateRequiredStringsWithCustomMessage(reqMatTktFieldArray, "When the Material Ticket # is populated..."))
		{
			return false;
		}
	}
	else
	{
		if(!ValidateRequiredStrings(reqFieldArray))
		{
			return false;
		}
	}
	if(ValidateRequiredStringValue(coLocId))
	{
		var coLocTB = document.getElementById(coLocId);
		var coLocVTB = document.getElementById(coLocVerifyId);
	
		if(coLocTB != null && coLocVTB != null)
		{
			if(TrimString(coLocTB.value) != TrimString(coLocVTB.value))
			{
				alert("The Company Use Location Id value has changed and has not been validated. Please click the validate button before saving your changes.");
				return false;
			}
		}
	}
	else
	{
		if(!ValidateRequiredStringValue(distRefId))
		{
			alert("The Pole/Mounting number is required if a Company Use Location Id is not specified.\n\nPlease enter a Pole/Mounting number and attempt to save again.");
			return false;
		}
	}
	
	var gridCdTB = document.getElementById(gridCdId);
	if(gridCdTB != null)
	{
		if(TrimString(gridCdTB.value).length != 5)
		{
			alert("The Map # must be 5 characters, ex. CE05D");
			return false;
		}
	}
	else
	{
		alert("DEBUG MSG: Cannot validate form because a control cannot be found on this page!");
		return false;
	}
	
	return true;
}

//custom validation for all property transfer screens
function CustomValidatePropertyTransfer(gridCdId, distRefId, coLocId, coLocVerifyId, reqFieldArray)
{

	if(!ValidateRequiredStrings(reqFieldArray))
	{
		return false;
	}
	
	if(ValidateRequiredStringValue(coLocId))
	{
		var coLocTB = document.getElementById(coLocId);
		var coLocVTB = document.getElementById(coLocVerifyId);
	
		if(coLocTB != null && coLocVTB != null)
		{
			if(TrimString(coLocTB.value) != TrimString(coLocVTB.value))
			{
				alert("The Company Use Location Id value has changed and has not been validated. Please click the validate button before saving your changes.");
				return false;
			}
		}
		else
		{
			alert("DEBUG MSG: Cannot validate form because a control cannot be found on this page!");
			return false;
		}
	}
	else
	{
		if(!ValidateRequiredStringValue(distRefId))
		{
			alert("The Company Use Location Id is required for this record because a pole/pad number was not specified at the time of installation.\n\nPlease enter a Company Use Location Id and attempt to save again.");
			return false;
		}
	}
	
	var gridCdTB = document.getElementById(gridCdId);
	if(gridCdTB != null)
	{
		if(TrimString(gridCdTB.value).length != 5)
		{
			alert("The Map # must be 5 characters, ex. CE05D");
			return false;
		}
	}
	else
	{
		alert("DEBUG MSG: Cannot validate form because a control cannot be found on this page!");
		return false;
	}
	
	return true;
}

//Custom validation for the installation of capacitor
function CustomValidateInstallCapacitor(gridCdId, woCheckBoxId, moCheckBoxId, woTextBoxId, moTextBoxId, 
										poleCheckBoxId, subCheckBoxId, poleFieldArray, subFieldArray,
										subTextBoxId, subVerifyId)
{
	var woCB = document.getElementById(woCheckBoxId);
	var moCB = document.getElementById(moCheckBoxId);
	
	if(woCB.checked)
	{
		if(ValidateRequiredStringValue(woTextBoxId) == false)
		{
			alert("The Work Order # is required when the corresponding radio button is checked.");
			return false;
		}
	}
	else
	{
		if(moCB.checked)
		{
			if(ValidateRequiredStringValue(moTextBoxId) == false)
			{
				alert("The Misc. Order Id is required when the corresponding radio button is checked.");
				return false;
			}
		}
	}
	
	var poleCB = document.getElementById(poleCheckBoxId);
	var subCB = document.getElementById(subCheckBoxId);
	
	if(poleCB.checked)
	{
		if(ValidateRequiredStrings(poleFieldArray))
		{		
			var gridCdTB = document.getElementById(gridCdId);
			if(gridCdTB != null)
			{
				if(TrimString(gridCdTB.value).length != 5)
				{
					alert("The Map # must be 5 characters, ex. CE05D");
					return false;
				}
				else
				{
					return true; 
				}
			}
			else
			{
				alert("DEBUG MSG: Cannot validate form because a control cannot be found on this page!");
				return false;
			}
		}
		else
		{
			return false;
		}
	}
	else
	{
		if(subCB.checked)
		{
			if(ValidateRequiredStrings(subFieldArray))
			{
				var subTB = document.getElementById(subTextBoxId);
				var subVTB = document.getElementById(subVerifyId);
			
				if(subTB != null && subVTB != null)
				{
					if(TrimString(subTB.value) == TrimString(subVTB.value))
					{
						return true;
					}
					else
					{
						alert("The Substation Id value has changed and has not been validated. Please click the validate button before saving your changes.");
						return false;
					}
				}
			} 
			else
			{
				return false;
			}
		}
	}
	
}

//Custom validation for the search asset form (shared by xfr, reg, and cap)
function CustomValidateSearchAssetForm(compNumId, serialId)
{
	if(ValidateRequiredStringValue(compNumId) || ValidateRequiredStringValue(serialId))
	{
		var compNumTB = document.getElementById(compNumId);
		var serialTB = document.getElementById(serialId);
		/*
		if(TrimString(compNumTB.value) == "%")
		{
			alert("The wildcard '%' can only be used in combination with other characters. Please update the Company Number to include other search characters.");
			return false;
		}
		if(TrimString(serialTB.value) == "%")
		{
			alert("The wildcard '%' can only be used in combination with other characters. Please update the Serial Number to include other search characters.");
			return false;
		}
		*/
		if(TrimString(compNumTB.value).length < 4 && compNumTB.value.indexOf("%") > -1)
		{
			alert("When using the wildcard '%', please provide at least 3 other valid search characters. Otherwise the returned values will be too large for the web request to handle.");
			return false;
		}
		if(TrimString(serialTB.value).length < 4 && serialTB.value.indexOf("%") > -1)
		{
			alert("When using the wildcard '%', please provide at least 3 other valid search characters. Otherwise the returned values will be too large for the web request to handle.");
			return false;
		}
		return true;
	}
	else
	{
		alert("Either Company Number or Serial Number must be populated before clicking the Locate button.");
		return false;
	}
}

//Custom validation for the search asset form (shared by xfr, reg, and cap)
function CustomValidateSearchAssetByLocForm(compNumId, serialId)
{
	if(ValidateRequiredStringValue(compNumId) || ValidateRequiredStringValue(serialId))
	{
		var compNumTB = document.getElementById(compNumId);
		var serialTB = document.getElementById(serialId);
		
		if(TrimString(compNumTB.value).length < 4 && compNumTB.value.indexOf("%") > -1)
		{
			alert("When using the wildcard '%' for Pole/Pad Number, please provide at least 3 other valid search characters. Otherwise the returned values will be too large for the web request to handle.");
			return false;
		}
		if(TrimString(serialTB.value).length < 2 && serialTB.value.indexOf("%") > -1)
		{
			alert("When using the wildcard '%' for Company Use Location Id, please provide at least 2 other valid search characters. Otherwise the returned values will be too large for the web request to handle.");
			return false;
		}
		return true;
	}
	else
	{
		alert("Either Pole/Pad Number or Company Use Location Id must be populated before clicking the Locate button.");
		return false;
	}
}

//Custom validation for the Transformer/Regulator Add/Edit Form
function CustomValidateTransRegForm(requiredFieldArray, integerFieldArray, sinId, sinValidatedId, compNumId, reqLength, warrantyId)
{
	if(ValidateRequiredStrings(requiredFieldArray))
	{
		if(ValidateIntegerFields(integerFieldArray))
		{
			var companyNumber = document.getElementById(compNumId);
			if(companyNumber != null)
			{
				if(TrimString(companyNumber.value).length != reqLength)
				{
					alert("The Company # must be exactly " + reqLength + " characters long. Please correct and re-submit.");
					return false;
				}
				else
				{				
					var sinControl = document.getElementById(sinId);
					var sinValidate = document.getElementById(sinValidatedId);
					
					if(sinControl != null && sinValidate != null)
					{
						//alert("sinControl='" + sinControl.value + "', sinValidate='" + sinValidate.value + "'");
						if(TrimString(sinControl.value) == TrimString(sinValidate.value))
						{
							var warrantyControl = document.getElementById(warrantyId);
							if(warrantyControl != null)
							{
								if(TrimString(warrantyControl.value).length <= 100)
								{
									return true;
								}
								else
								{
									alert("The warranty description can only be 100 characters long. Please update this field to be a shorter value.");
									return false;
								}
							}
							else
							{
								alert("DEBUG MSG: Cannot validate form because the warranty control cannot be found on this page!");
								return false;								
							}
						}
						else
						{
							alert("The S.I.N. value has changed and has not been validated. Please click the validate button before saving your changes.");
							return false;
						}
					}
					else
					{
						alert("DEBUG MSG: Cannot validate form because a control cannot be found on this page!");
						return false;
					}
				}
			}
			else
			{
				alert("DEBUG MSG: Cannot validate form because a control cannot be found on this page!");
				return false;
			}
		}
	}
	
	return false;
}

//validates an array of controls to make sure that their value properties are integers
//to use pass a multi-dimensional array in the following format - 
// [['control1Id', 'Control1 Name for Display'], ['control2Id', 'Control2 Name for Display],...] 
function ValidateIntegerFields(integerFieldArray)
{
	var integerFields = "";
	
	for (var i = 0; i < integerFieldArray.length; i++) 
	{ 		
		var controlId = integerFieldArray[i][0]; 
		var integerValueControl = document.getElementById(controlId);
		
		if(integerValueControl != null)
		{
			if(integerValueControl.value.length > 0)
			{
				if(!IsInteger(integerValueControl.value))
				{
					integerFields += "\n     -" + integerFieldArray[i][1]; 
				}
			}
		}
		else
		{
			alert("DEBUG MSG: Cannot validate " + controlId + " has an integer because the control cannot be found on this page!");
		}
	} 
	
	if(integerFields == "")
	{
		return true;
	}
	else
	{
		alert("The following fields must be integer (numeric) values with no punctuation." + integerFields);
		return false;
	}
}

//validates an array of required controls to make sure that their value properties are not empty
//to use pass a multi-dimensional array in the following format - 
// [['control1Id', 'Control1 Name for Display'], ['control2Id', 'Control2 Name for Display],...] 
function ValidateRequiredStrings(requiredFieldArray)
{
	return ValidateRequiredStringsWithCustomMessage(requiredFieldArray, "");
}

function ValidateRequiredStringsWithCustomMessage(requiredFieldArray, customMessage)
{
	var requiredFields = "";
	
	for (var i = 0; i < requiredFieldArray.length; i++) 
	{ 		
		var controlId = requiredFieldArray[i][0]; 
		if(!ValidateRequiredStringValue(controlId))
			requiredFields += "\n     -" + requiredFieldArray[i][1]; 
	} 
	
	if(requiredFields == "")
	{
		return true;
	}
	else
	{
		var messageToDisplay = "";
		if(customMessage.length > 0)
		{
			messageToDisplay = customMessage + "\n\n";
		}
		alert(messageToDisplay + "The following fields are required:" + requiredFields);
		return false;
	}
}

//validates that the control with the passed id has a non empty value
function ValidateRequiredStringValue(controlId)
{
	var stringValueControl = document.getElementById(controlId);
	if(stringValueControl == null)
	{
		alert("DEBUG MSG: Cannot validate " + controlId + " because the control cannot be found on this page!");
		return false;
	} 
	else 
	{
		if(TrimString(stringValueControl.value) == "")
			return false;
	}
	return true;
}

//Trims any leading spaces off of the front and end of a string 
function TrimString(sInString) 
{
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}

//clears the value from any control that supports the value property
function ClearValueForControl(controlId)
{
	var stringValueControl = document.getElementById(controlId);
	if(stringValueControl != null)
	{
		stringValueControl.value = "";
	} 
	return false;
}

//validates a number to see if its a double value returns a bool
function IsDouble(sText)
{
	var validChars = "0123456789.";
	var isValid = true;
	var character;
	
	for(var i=0; i<sText.length && isValid==true; i++) 
	{
		character = sText.charAt(i); 
		if(validChars.indexOf(character) == -1) 
		{
			isValid = false;
		}
	}
	
	return isValid;
}

//validates a number to see if its an integer value returns a bool
function IsInteger(sText)
{
	var validChars = "0123456789";
	var isValid = true;
	var character;
	
	for(var i=0; i<sText.length && isValid==true; i++) 
	{
		character = sText.charAt(i); 
		if(validChars.indexOf(character) == -1) 
		{
			isValid = false;
		}
	}
	
	return isValid;
}

//expand or collapses a div panel depending on the current state of the panel (block/none)
//also updates a plus/minus image accordingly
function ExpandCollapsePanel(panelId, imageId)
{
	var panel = document.getElementById(panelId);
	var image = document.getElementById(imageId);
	
	if(panel != null)
	{	
		if (panel.style.display == 'none') 
		{
    		// Show panel
    		panel.style.display = 'block';
    		
    		if(image != null)
    		{
    			image.src = image.src.replace("Plus","Minus");
    			image.src = image.src.replace("plus","minus");
    		}
		} 
		else 
		{
    		// Hide panel
    		panel.style.display = 'none';
    		
    		if(image != null)
    		{
    			image.src = image.src.replace("Minus","Plus");
    			image.src = image.src.replace("minus","plus");
    		}
		}
	}
	
	ResizeLeftDiv();
	
	return false;
}

//pops up a confirmation for a deletion before posting back to the server
function confirmDelete(message) 
{
	if(message=="")
	{
		message = "Are you sure you want to permanently delete this item?";
	}
	
	if (confirm(message)) 
	{
		return true;
	} 
	else 
	{
		// do nothing
		return false;
	} 
}

//launchs a new small window to display the MAPPS rejection code for the passed Id
function LaunchRejectionCode(rejectionId)
{
	window.open("CoordinatorRejectionDesc.aspx?ID=" + rejectionId, "RejectionWindow", "height=115,width=260,resizable=no,menubar=no,toolbar=no,status=no");
	return false;
}

//launches a new IE window to display the passed report
function ShowReport(report)
{	
	window.open(report, "_blank", "");
	return false;
}

//launches a new IE window to display the help system
function ShowSageHelp(helpAddress)
{	
	window.open(helpAddress, "sagehelpwindow", "menubar=no,toolbar=no,status=no,resizable=yes");
	return false;
}

//updates the padmount inspection form based on inspection type selection
function InspectionTypeToggle(specificPad, distRefId, taxId, mapId)
{
	var distRefTB = document.getElementById(distRefId);
	var taxDD = document.getElementById(taxId);
	var mapTB = document.getElementById(mapId);

	if(distRefTB != null && taxDD != null && mapTB != null)
	{
		if(specificPad == true)
		{
			distRefTB.disabled = false;
			distRefTB.readonly = false;
			distRefTB.style.backgroundColor = "#FFFFFF";
			
			taxDD.disabled = true;
			taxDD.style.backgroundColor = "#CCCCCC";
			mapTB.disabled = true;
			mapTB.value = "";
			mapTB.style.backgroundColor = "#CCCCCC";
		}
		else
		{
			distRefTB.disabled = true;
			distRefTB.style.backgroundColor = "#CCCCCC";
			distRefTB.value = "";
			
			taxDD.disabled = false;
			taxDD.style.backgroundColor = "#FFFFFF";
			mapTB.disabled = false;
			mapTB.style.backgroundColor = "#FFFFFF";
		}
	}
	
	return true;
}

//validates the input for the PadMount inspection form
function CustomValidateInspection(padRadioId, reqFieldArray1, reqFieldArray2, gridCdId)
{
	var padRadio = document.getElementById(padRadioId);
	if(padRadio != null)
	{ 
		if(padRadio.checked)
		{
			return ValidateRequiredStrings(reqFieldArray1);
		}
		else
		{
			if(ValidateRequiredStrings(reqFieldArray2))
			{
				var gridCdTB = document.getElementById(gridCdId);
				if(TrimString(gridCdTB.value).indexOf("%") > -1)
				{
					alert("The chosen Map Grid Code must either be 5 digits for a 1/4 mile grid or 4 digits for a 1 mile grid and cannot include a '%'.\n\nPlease correct and re-submit.");
					return false;
				}
				if(TrimString(gridCdTB.value).length >= 4)
				{
					return true;
				}
				else
				{
					alert("The chosen Map Grid Code must either be 5 digits for a 1/4 mile grid or 4 digits for a 1 mile grid.\n\nPlease correct and re-submit.");
					return false;
				}
			}
			else
			{
				return false;
			}
		}
	}
	else
	{
		alert("DEBUGMSG - Could not get a handle on the pad # radio.");
	}
	return false;
}

function validateHelpDeskForm(reqFieldArray, issueTypeId, appId, sessID, objectId)
{ 
	var type = document.getElementById(issueTypeId);
	var application = document.getElementById(appId);
	var sessionID = document.getElementById(sessID);
	var objID = document.getElementById(objectId);
	
	if(type != null && application != null && sessionID != null && objID != null)
	{		
		if(ValidateRequiredStrings(reqFieldArray))
		{
			if(type.value == "Problem / Error" && (application.value == "GIS - ArcFM" || application.value == "GIS - Designer" || application.value == "Mobile - ArcFM Redliner"))
			{
				if(TrimString(sessionID.value).length == 0)
				{
					alert("You have indicated that there is a possible bug within an editing application. Please enter the session/WR ID where this bug is being seen so the GIS team can attempt to replicate the issue. Also if available, please be sure to enter a feature class (i.e. TransformerBank) and the object id of the record that is causing the problem. ");
					return false;
				}
			}
			
			var notInts = "";
			if(TrimString(sessionID.value).length > 0)
			{
				if(!IsInteger(TrimString(sessionID.value)))
					notInts += "\n   Session ID";
			}
			if(TrimString(objID.value).length > 0)
			{
				if(!IsInteger(TrimString(objID.value)))
					notInts += "\n   Object ID";
			}
			
			if(notInts.length > 0)
			{
				alert("Please ensure you have entered only a numeric value in the following fields:\n" + notInts);
				return false;
			}
			
			return true;																					
		}
		else
		{
			return false;
		}
	} 
	else
	{
		alert("Cannot locate all required controls on form... aborting.");
		return false;
	}
}

function HelpDeskQueryListBox(listBoxId, queryBoxId)
{
	var listBox = document.getElementById(listBoxId);
	var queryBox = document.getElementById(queryBoxId);
	if(listBox != null && queryBox != null)
	{
		if(TrimString(queryBox.value).length > 0)
		{
			queryBox.value = TrimString(queryBox.value) + " " + listBox.value;
		}
		else
		{
			queryBox.value = listBox.value;
		}
	}
}

var selectedHdField = "-1";
function HelpDeskDisableListBox(fieldListBox, listBoxId)
{
	if(fieldListBox.value != selectedHdField)
	{
		var listBox = document.getElementById(listBoxId);
		if(listBox != null)
		{
			while(listBox.options.length > 0)
				listBox.options[0] = null;
				
			listBox.style.backgroundColor = "#EEEEEE";
			
			listBox.disabled = true;
		}
	}
}

function UpdateDropDownForValidValue(dropdownId)
{
    var dd = document.getElementById(dropdownId);
    if(dd != null)
    {
        if(dd.options[dd.selectedIndex].text.charAt(0) != "[")
        {
            for(var i=(dd.length - 1); i>=0; i--)
            {
                if(dd.options[i].text.charAt(0) == "[")
                {
                    dd.options[i] = null;
                }
            }
        }
        dd.style.color = "black";
    }
}

function ValidateProfileForm(baseFieldArray, worker1Id, worker1Other, worker2Id, worker2Other, firstName1, child1Array, firstName2, child2Array, firstName3, child3Array, firstName4, child4Array, firstName5, child5Array)
{
    if(ValidateRequiredStrings(baseFieldArray))
    {
        if(document.getElementById(worker1Id).value == "Other")
        {
            if(!ValidateRequiredStringValue(worker1Other))
            {
                alert("You have selected a Worker #1 of 'Other' and you must populate the worker's name before you can save.\n\nPlease enter the person's name who will be working in place of the father.");
                return false;
            }
        }
        if(document.getElementById(worker2Id).value == "Other")
        {        
            if(!ValidateRequiredStringValue(worker2Other))
            {
                alert("You have selected a Worker #2 of 'Other' and you must populate the worker's name before you can save.\n\nPlease enter the person's name who will be working in place of the mother.");
                return false;
            }
        }
        
        if(ValidateRequiredStringValue(firstName1))
            if(!ValidateRequiredStringsWithCustomMessage(child1Array, "You have entered a First Name for Child #1, the following fields are also required:"))
                return false;
                
        if(ValidateRequiredStringValue(firstName2))
            if(!ValidateRequiredStringsWithCustomMessage(child2Array, "You have entered a First Name for Child #2, the following fields are also required:"))
                return false;
        
        if(ValidateRequiredStringValue(firstName3))
            if(!ValidateRequiredStringsWithCustomMessage(child3Array, "You have entered a First Name for Child #3, the following fields are also required:"))
                return false;
                
        if(ValidateRequiredStringValue(firstName4))
            if(!ValidateRequiredStringsWithCustomMessage(child4Array, "You have entered a First Name for Child #4, the following fields are also required:"))
                return false;
                
        if(ValidateRequiredStringValue(firstName5))
            if(!ValidateRequiredStringsWithCustomMessage(child5Array, "You have entered a First Name for Child #5, the following fields are also required:"))
                return false;                                                
    }
    else
        return false;
}

function ToggleWorkerTextBox(workerDDId, workerTBId)
{
    if(document.getElementById(workerDDId).value == "Other")
    {
        document.getElementById(workerTBId).readOnly = false;
        document.getElementById(workerTBId).style.backgroundColor = "White";       
    }
    else
    {
        document.getElementById(workerTBId).readOnly = true;
        document.getElementById(workerTBId).style.backgroundColor = "#CCCCCC";       
        document.getElementById(workerTBId).value = "";
    }

    return false;
}

function SignTheDisclaimer(signDDId, signedById, signedOnId, signedName, signedDate)
{
    if(document.getElementById(signDDId).value == "Y")
    {
        document.getElementById(signedById).value = signedName;
        document.getElementById(signedOnId).value = signedDate;
    }
    else
    {
        document.getElementById(signedById).value = "";
        document.getElementById(signedOnId).value = "";
    }
}

function ChangePassword(requiredArr, newPass1Id, newPass2Id)
{
    if(ValidateRequiredStrings(requiredArr))
    {
        if(document.getElementById(newPass1Id).value == document.getElementById(newPass2Id).value)
            return true;
        else
        {
            alert("Your New Password does not match the Confirmation New Password.\n\nPlease correct and re-save.");
            return false;
        }
    }
    return false;
}
