//Validate All Errors for the FromTo fields.
function VAL_FT(source, args) {
	
    //Get misc variables needed
    var validateItems = source.getAttribute("ValidateItems")
    var arrValidation = validateItems.split(",")
    var whichField = source.getAttribute("WhichField")
    var uniquePosition = source.getAttribute("UniquePosition")
    var currentField = document.getElementById(uniquePosition + whichField)
    var dataType = source.getAttribute("DataType")

    //Get text boxes and span tag objects
    var fromField = document.getElementById(uniquePosition + "From")
    var toField = document.getElementById(uniquePosition + "To")
    //The values of this attribute will always be either "From" or "To"
    var messageSpanTag = source
    var otherFieldMessageSpanTag
    if (whichField == "From") {
        //_sprCstm is the prefix that is used for the custom validation control
        otherFieldMessageSpanTag = document.getElementById("sprCstm" + uniquePosition + "To")
    } else {        
        otherFieldMessageSpanTag = document.getElementById("sprCstm" + uniquePosition + "From")
    }
    
    var errorMessageId
    
    for (var i=0; i < arrValidation.length; i++) {
        switch (arrValidation[i]) {
            case "ValidData":
                if (!ValidateData(currentField, dataType)) {
                    args.IsValid = false
                    DisplayFromToErrorMessage(messageSpanTag, otherFieldMessageSpanTag, "InvalidData")
                    return
                }
                break;
            case "Minimum":
                if (currentField.value != "") {
                    if (!ValidateMinimumValue(currentField.value, dataType, source.getAttribute("Minimum"))) {
                        args.IsValid = false
                        DisplayFromToErrorMessage(messageSpanTag, otherFieldMessageSpanTag, "Minimum")
                        return
                    }
                }
                break;
            case "Maximum":
                if (currentField.value != "") {
                    if (!ValidateMaximumValue(currentField.value, dataType, source.getAttribute("Maximum"))) {
                        args.IsValid = false
                        DisplayFromToErrorMessage(messageSpanTag, otherFieldMessageSpanTag, "Maximum")
                        return
                    }
                }
                break;            
            case "GreaterThan":
                if (ValidateGreaterThanValue(fromField.value, toField.value, dataType)) {
                
                 //   alert(otherFieldMessageSpanTag.innerText  + "   ==?  " + arrAllErrors[messageSpanTag.id + "GreaterThan"])
                    
                    args.IsValid = true
                    //Remove the error from the "other field" only if there is the "GreaterThan" error. 
                    //This means that the user probably mistyped the date and is correcting it.
                    if (otherFieldMessageSpanTag.innerHTML == arrAllErrors[messageSpanTag.id + "GreaterThan"]) {
                        otherFieldMessageSpanTag.innerHTML = ""   
                    }
                } else {
                    args.IsValid = false
                    DisplayFromToErrorMessage(messageSpanTag, otherFieldMessageSpanTag, "GreaterThan")
                    return
                }
                
                break;
            case "BothFieldsRequired":
                //This validation is only performed when the page is submitted (or a client callback is performed)
                //This boolean value is a global variable and is set elsewhere on the page.
                if (specialValidationBeforeSubmit == true) {
                    // This makes sure that if one field is populated, the both need to be populated!
                    if (fromField.value != "" || toField.value != "") {
                        if (fromField.value == "" || toField.value == "") {
                            args.IsValid = false
                            DisplayFromToErrorMessage(messageSpanTag, otherFieldMessageSpanTag, "BothFieldsRequired")
                        }
                    }
                }
                break;
            case "Required":
                //This validation is only performed when the page is submitted (or a client callback is performed)
                //This boolean value is a global variable and is set elsewhere on the page.
                if (specialValidationBeforeSubmit == true) {                
                    if (currentField.value.length == 0 ) {
                        args.IsValid = false
                        DisplayFromToErrorMessage(messageSpanTag, otherFieldMessageSpanTag, "Required")
                        return
                    }
                }
                break;   
            default:
                alert("Invalid validation check in ValidateAllErrorsForFromTo: " + arrValidation[i])
        }
    }
}

function DisplayFromToErrorMessage(messageSpanTag, otherFieldMessageSpanTag, messageCode) {

	 //Clear out the error message in the other field, if there is one. For example, if this error is happening
	 //on the "From" field, then remove the error message from the "To" field.  We do this because we only
	 //want to display 1 error for both fields.
	 if (otherFieldMessageSpanTag != null) {
	 otherFieldMessageSpanTag.innerHTML = "" 
	 } 
	
	 //Display the error by looking up the message in the array that was initially
	 // This function is in the ClientErrorMasterManager control (ClientErrorMasterManager.js)
	var errorMessage = GetErrorFromClientErrorMasterManager(messageSpanTag.id + messageCode)
	messageSpanTag.innerHTML = errorMessage	
  
	if (messageSpanTag.innerHTML == "undefined") {
    	alert ("error is undefined in DisplayFromToErrorMessage: " + messageSpanTag.id + "   / messageCode: " + messageCode)
	}
}

function ValidateGreaterThanValue (fromValue, toValue, dataType) {
     var dataIsValid = true;
 
    //Only validate if both fields have been entered
    if (fromValue != "" && toValue != "") {
        //dataIsValid = ValidateMinimumValue(fromValue, dataType, toValue)    
        
        switch (dataType) {
            case "Date":
                var date1 = new Date(fromValue)
                var date2 = new Date(toValue)     
                if (date1 > date2) {
                    dataIsValid = false
                }
                break;   
            case "Numeric":    
            case "DollarInThousands": 
            case "NumericWith2Decimals":
            case "WholeDollar":
            case "Dollar":   
               var lowNum = new Number(fromValue)
               var highNum = new Number(toValue)
               if (lowNum > highNum) {
                    dataIsValid = false
               }            
               break;
            case "AlphaNumeric":
               //If numbers, then compare numbers:
               if (isNaN(fromValue) || isNaN(toValue)) {
                    if (fromValue.toLowerCase() > toValue.toLowerCase()) {
                        dataIsValid = false
                    }
               } else {
                    //This is a recursive call which would be called only once!
                    dataIsValid = ValidateGreaterThanValue(fromValue, toValue, "Numeric")
               }
               break;
            default:
                alert ("Data type not handled for ValidateGreaterThanValue function: " + dataType)
            break;                                    
        }
    }
    return dataIsValid
}

function ValidateData(textBox, dataType) {

    var dataIsValid = false;
    
    switch (dataType) {
        case "Date":
            ReformatDate(textBox, "")
            dataIsValid = DateIsValid(textBox)
            break;
        case "Numeric":
        case "DollarInThousands":        
        case "WholeDollar":
            if (!isNaN(textBox.value)) {
                dataIsValid = true
            }
            break;
        case "NumericWith2Decimals":
        case "Dollar":
            if (!isNaN(textBox.value)) {
                if (NumberOfDecimalPlaces(textBox.value) <= 2) {
                    dataIsValid = true
                }
            }   
            break;
        default:
            alert ("Data type not handled for ValidateData function: " + dataType)
            break;
    }
    
    return dataIsValid

}

function NumberOfDecimalPlaces(val) {
    var numberOfDecimals = 0
    var pos = val.indexOf(".")
    if (pos > -1) {
        numberOfDecimals = val.length - pos - 1
    }
    return numberOfDecimals
}



function ValidateMinimumValue(textBoxValue, dataType,  minValue) {

    var dataIsValid = true;

    switch (dataType) {
        case "Date":
            var date1 = new Date(textBoxValue)
            var date2 = new Date(minValue)     
            if (textBoxValue != "") {
                if (date1 < date2) {
                    dataIsValid = false
                }
            }        
            break;
        case "Numeric":
        case "NumericWith2Decimals":
        case "DollarInThousands":
        case "WholeDollar":
        case "Dollar": 
            var num1 = Number(textBoxValue)
            var num2 = Number(minValue)        
            if (num1 < num2) {
                dataIsValid = false
            }
            break;
        default:
            alert ("Invalid dataType in ValidateMinimumValue: " + dataType)
            break;
    }    
    return dataIsValid
}

function ValidateMaximumValue(textBoxValue, dataType,  maxValue) {

    var dataIsValid = true;

    switch (dataType) {
        case "Date":
            if (textBoxValue != "") {
                var date1 = new Date(textBoxValue)
                var date2 = new Date(maxValue)
                if (date1 > date2) {
                    dataIsValid = false
                }
            }        
            break;
        case "Numeric":
        case "NumericWith2Decimals":
        case "DollarInThousands":
        case "WholeDollar":
        case "Dollar": 
            //alert(textBoxValue + "  >? " + maxValue)
            var num1 = Number(textBoxValue)
            var num2 = Number(maxValue)
            if (num1 > num2) {
                dataIsValid = false
            }        
            break;    
        default:
            alert ("Invalid dataType in ValidateMaximumValue: " + dataType)
            break;
    }    
    return dataIsValid
}

// This function returns the reference to the from textboxes based off the
// id of the validator.
function  GetFromTextboxFieldFromValidatorName(validatorId) {
    //Get a reference to the custom validator span tag
    var CustomValidationTag = document.getElementById(validatorId)
    //Get the id of the control which is validated.  This will always end with "To"
    var ControlId = GetPropertyFromElement(CustomValidationTag, "controltovalidate")
    
    if (ControlId.substr(ControlId.length - 2, 2) == "To") {
        // Change the last 2 characters of the id from  "To" to "From". This is the id of the first date field.
       fromControlId = ControlId.substr(0, ControlId.length - 2) + "From"
    } else {
       fromControlId = ControlId
    } 
 
     var fromControl = document.getElementById(fromControlId)

    return fromControl
}


// This function returns the reference to the from textboxes based off the
// id of the validator.
function  GetToTextboxFieldFromValidatorName(validatorId) {
    //Get a reference to the custom validator span tag
    var CustomValidationTag = document.getElementById(validatorId)
    //Get the id of the control which is validated.  This will always end with "To"
    var ControlId = GetPropertyFromElement(CustomValidationTag, "controltovalidate")
    
    if (ControlId.substr(ControlId.length - 3, 4) == "From") {
        // Change the last 2 characters of the id from  "To" to "From". This is the id of the first date field.
       toControlId = ControlId.substr(0, ControlId.length - 3) + "To"
    } else {
       toControlId = ControlId
    } 
 
     var toControl = document.getElementById(toControlId)

    return toControl
}



// This function returns the reference to the from textboxes based off the
// id of the validator.
function  GetFromToTextboxFieldsFromValidatorName(validatorId, fromTextbox, toTextBox) {
    //Get a reference to the custom validator span tag
    var CustomValidationTag = document.getElementById(validatorId)
    //Get the id of the control which is validated.  This will always end with "To"
    var toDateControlId = GetPropertyFromElement(CustomValidationTag, "controltovalidate")
    
    // Change the last 2 characters of the id from  "To" to "From". This is the id of the first date field.
    var fromDateControlId = toDateControlId.substr(toDateControlId.length - 2) + "From"
    
    var toDate = document.getElementById(toDateControlId)
    var fromDate = document.getElementById(fromDateControlId)

}

// This function returns the element of the dropdown control.
function GetRollingCountTextboxFieldFromValidatorName(validatorId) {
    //Get a reference to the custom validator span tag
    var CustomValidationTag = document.getElementById(validatorId)
    //Get the id of the control which is validated.  This will always end with "Dur"
    var ControlId = GetPropertyFromElement(CustomValidationTag, "controltovalidate")
    
    var rollingCount
    if (ControlId.substr(ControlId.length - 3, 3) == "Dur") {
        // Change the last 2 characters of the id from  "To" to "From". This is the id of the first date field.
       rollingCountId = ControlId.substr(0, ControlId.length - 3) + "RollCnt"
    } else {
        alert ("Invalid controlId. It needs to end in Dur. It is: " + validatorId)
       rollingCountId = ControlId
    } 
 
     var rollingCount = document.getElementById(rollingCountId)

    return rollingCount
}


// This function returns the element of the dropdown control.
function GetRollingCountDurationFieldFromValidatorName(validatorId) {
    //Get a reference to the custom validator span tag
    var CustomValidationTag = document.getElementById(validatorId)
    //Get the id of the control which is validated.  This will always end with "Dur"
    var ControlId = GetPropertyFromElement(CustomValidationTag, "controltovalidate")
    if (ControlId.substr(ControlId.length - 3, 3) == "Dur") {
        // Change the last 2 characters of the id from  "To" to "From". This is the id of the first date field.
       durationId = ControlId.substr(0, ControlId.length - 3) + "Dur"
    } else {
        alert ("Invalid controlId. It needs to end in Dur. It is: " + validatorId)
       durationId = ControlId
    } 
 
     var duration = document.getElementById(durationId)

    return duration
}


function ValidateNumericGreaterThanOrText(source,args)  {

 // text boxes
   var toField = GetToTextboxFieldFromValidatorName(source.id)
   var fromField =  GetFromTextboxFieldFromValidatorName(source.id)
   
   args.IsValid = true
    
   if ( !isNaN(fromField.value) && !isNaN(toField.value)) {
        if (toField.value < fromField.value) {
            args.IsValid = false
        }
    }
    
}

function  VAL_RollingDropdown(source,args) {

    var rollingCount = GetRollingCountTextboxFieldFromValidatorName(source.id)
    var duration = GetDropdownSelectedValue(GetRollingCountDurationFieldFromValidatorName(source.id))
    
    // If one of the values is populated and the other isn't then the fields are not valid.
    if (rollingCount.value == "" && duration != "") {
        args.IsValid = false    
    }
    if (rollingCount.value != "" && duration == "") {
        args.IsValid = false
    }
    
}


// This function validates a checkbox list.  However, .Net Validators does not work with checkboxes, so
// we fool it to think that it's validating a simple textbox.  We first get the name of the checkbox list.
// The name is the value of the textbox.  So, first we get that and then we can get a reference to 
// the checkboxes.

 function ValidateRequiredCheckboxList(source, args) {
    args.IsValid = true;
        
    // Get the name of the parent element of the checkbox list.
    var nameOfControlToValidate=document.getElementById(source.controltovalidate).value;
    // Get a reference to the parent
    var control = document.getElementById(nameOfControlToValidate);
    // CROSSBROWSER - NOTE: THE .all IS IE ONLY. IT IS REPLACED BY getElementsByTagName("..")
    // Get an array of all the checkboxes.
    var col = control.getElementsByTagName("INPUT");
    
    //This validation is only performed when the page is submitted (or a client callback is performed)
    //This boolean value is a global variable and is set elsewhere on the page.
    if (specialValidationBeforeSubmit == false) {
        return true;
    }                
    if ( col != null ) {
        for ( var i = 0; i < col.length; i++ ) {
            if ( col[i].checked ) {
                args.IsValid = true;
                return true
            }
        }
        args.IsValid = false;
    }       
    return false
}

// NOTE: This function is not used anywhere.
function ValidateStatusGroup(reqValidatorForCheckboxList) {
    var val = reqValidatorForCheckboxList.controltovalidate;
    var col = eval(document.getElementById(val)).all;

    //This validation is only performed when the page is submitted (or a client callback is performed)
    //This boolean value is a global variable and is set elsewhere on the page.
    if (specialValidationBeforeSubmit == false) {
        return true;
    }                

    if ( col != null ) {
        for ( i = 0; i < col.length; i++ ) {
            if (col[i].tagName == "INPUT") {
                //Look for input controls with an attribut searchType=checkbox.
                //Inputs without this attribute are the Group checkboxes.
                if (col[i].searchType != null && col[i].searchType == "checkbox") {
                    if ( col[i].checked ) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
    //CROSSBROWSER - ADDED
    return false
}


function ValidateQuickAddTextbox(source, args) {
    //This validation is only performed when the page is submitted (or a client callback is performed)
    //The specialValidationBeforeSubmit boolean value is a global variable and is set to true
    //when the Next button is clicked.

    if (specialValidationBeforeSubmit == false) {
        args.IsValid = true;
    }                
	else {
		if (args.Value == '') {
			args.IsValid = true;
		}
		else {
			args.IsValid = false;
		}
	}
}

function ValidateStatusGroupCheckbox(source, args) {
    //This validation is only performed when the page is submitted (or a client callback is performed)
    //The specialValidationBeforeSubmit boolean value is a global variable and is set to true
    //when the Next button is clicked.

    args.IsValid = false;
    return;

    if (specialValidationBeforeSubmit == false) {
        args.IsValid = true;
    }                
	else {
		if (args.Value == '') {
			args.IsValid = true;
		}
		else {
			args.IsValid = false;
		}
	}
}

function ValidateInvalidCode(source, args) {
    //This validation is NOT performed when the page is submitted.
    //This validation is done when the Quick Add button is clicked and results
    //are returned to the callback function.
    //The specialValidationBeforeSubmit boolean value is a global variable and is set to true
    //when the Next button is clicked.

    if (specialValidationBeforeSubmit == true) {
        args.IsValid = true;
    }                
	else {
		var uniqPos = source.getAttribute('UniqPos');
		var xmlNodeName = GetXmlNodeName(uniqPos);
		var hidId = 'hidInv' + xmlNodeName;
		var hidCtrl = document.getElementById(hidId);
		
		if (hidCtrl.value == 'callback') {
			if (args.Value == '') {
				args.IsValid = true;
			}
			else {
				args.IsValid = false;
			}
		}
		else {
			args.IsValid = true;
		}
	}
}

function ValidateRequiredMlsareaOrSchoolDistrict(source, args) {
    //This validation is NOT performed when the page is submitted.
    //This validation is done when the Lookup button is clicked.
    //The specialValidationBeforeSubmit boolean value is a global variable and is set to true
	//when the Next button is clicked.

    if (specialValidationBeforeSubmit == true) {
        args.IsValid = true;
    }                
	else {
		//Check MLSArea element in the search criteria.  Validation is true if MLSArea has data.
		if (objCriteriaForEdit.GetTextValue('/Search/MLSArea/Value') != '') {
	        args.IsValid = true;
	        return;
        }
		
		//Check SchoolDistrict element in the search criteria.  Validation is true if SchoolDistrict has data.
		if (objCriteriaForEdit.GetTextValue('/Search/SchoolDistrict/Value') != '') {
	        args.IsValid = true;
	        return;
        }

        //Nothing found then validation failed		
		args.IsValid = false;
	}

}

function ValidateAccessLevel(source, args) {
    //This validation is NOT performed when the page is submitted.
    //This validation is done when the Quick Add button is clicked and results
    //are returned to the callback function.
    //The specialValidationBeforeSubmit boolean value is a global variable and is set to true
    //when the Next button is clicked.

    if (specialValidationBeforeSubmit == true) {
        args.IsValid = true;
    }                
	else {
		var hidObj = null;
		if (source.id.indexOf('CompanyCode') > -1) {
			// Get the hidden error flag for CompanyCode
			hidObj = document.getElementById('hidInvAccessCompanyCode');
		}
		else if (source.id.indexOf('OfficeCode') > -1) {
			// Get the hidden error flag for OfficeCode
			hidObj = document.getElementById('hidInvAccessOfficeCode');
		}
		if (hidObj != null) {
			if (hidObj.value != '') {
				args.IsValid = false;
				// Reset the hidden error flag
				hidObj.value = '';
			}
			else {
				args.IsValid = true;
			}
		}
	}
}

function MapCoordinateValidation(source, args) {

	//Get the uniqueposition of the control from the validator attribute
	var unqPos = source.getAttribute("UniquePosition")
	var coords = document.getElementById('M'+unqPos)
	var singleOption = document.getElementById("rdo1_" + unqPos)	
		
	args.IsValid = true;

	// Do not validate the map coordinate if the single option
	// is selected.
	if (singleOption.checked == true) {
		return
	}

	if (coords.value != "") {
		//split the string
		var arr = coords.value.split(",")

		//traverse the string
	    for (var i=0; i < arr.length; i++) {
	    	if (arr[i] != "") {
				//run a regular expression    	
				// The first expression matches:  N999A99 
				// The 2nd expression after the "|" operator matches: 9999A1
				var matches = arr[i].match(/^([NK][0-9]{3}[A-Z][0-9]{2})$|^([0-9]{4}[A-K][1-7])$/ig)
				if (matches == null) {
					args.IsValid = false;
				}				
	    	}
	    }	
	}	
}

//Validate whether the date & time are < 30 days
function DateTimeField30DaysMax(source, args) {
	args.IsValid = true
	
	date = document.getElementById( source.getAttribute("dateTextbox",""))
	
	if (date.value !="") {
		if	(Date.parse(date.value) ) {
			var dt = new Date(date.value)
			
			var now = new Date()
			var todayMinus30 = new Date()
			//Note: Really use 31 days because we assume the day starts at midnight.
			//31 days =  1000ms * 60sec * 60min * 24hrs * 31days
			todayMinus30.setTime(now.getTime() - 1000*60*60*24*31)
			if (dt <  todayMinus30)  {
				args.IsValid = false;
			}			
		}
	}
}

function ValidateRequiredCompanyOrOffice(source, args) {
    //This validation is NOT performed when the page is submitted.
    //This validation is done when the Lookup button is clicked.
    //The specialValidationBeforeSubmit boolean value is a global variable and is set to true
    //when the Next button is clicked.

    if (specialValidationBeforeSubmit == true) {
        args.IsValid = true;
    }                
	else {
		//Check ListingCompanyCodeForInventory element in the search criteria.
		//Validation is true if ListingCompanyCodeForInventory has data.
		var companyFieldName = source.attributes['CompanyFieldName'].value;
		if (objCriteriaForEdit.GetTextValue('/Search/' + companyFieldName + '/Value') != '') {
	        args.IsValid = true;
	        return;
        }

		//Check ListingOfficeCodeForInventory element in the search criteria.
        //Validation is true if ListingOfficeCodeForInventory has data.
        var officeFieldName = source.attributes['OfficeFieldName'].value;
		if (objCriteriaForEdit.GetTextValue('/Search/' + officeFieldName + '/Value') != '') {
	        args.IsValid = true;
	        return;
        }

        //Nothing found then validation failed		
		args.IsValid = false;
	}

}

function ValidateRequiredCompany(source, args) {

    if (specialValidationBeforeSubmit != true) 
    {
        if (searchCompanyList.length > 0) 
        {
        	var values = objCriteriaForEdit.GetArrayWithTextValues('/Search/' + source.attributes['FieldName'].value + '/Value');

            if (values.length > 0) {

                for(var i=0; i < values.length; i++) 
                {
                    var valueFound = false;
                    for (var k=0; k < searchCompanyList.length; k++) 
                        if (searchCompanyList[k] == values[i])
                        {
                            valueFound = true;
                            break;
                        }

                    if (!valueFound) 
                    {
	                    args.IsValid = false;
                        return;
                    }
                }
            }
        }

    }
    
    args.IsValid = true;

}

function ValidateRequiredOffice(source, args) {

    if (specialValidationBeforeSubmit != true) 
    {
        if (searchOfficeList.length > 0) 
        {
        	var values = objCriteriaForEdit.GetArrayWithTextValues('/Search/' + source.attributes['FieldName'].value + '/Value');

            if (values.length > 0) {
                for(var i=0; i < values.length; i++) 
                {
                    var valueFound = false;
                    for (var k=0; k < searchOfficeList.length; k++) 
                        if (searchOfficeList[k] == values[i])
                        {
                            valueFound = true;
                            break;
                        }

                    if (!valueFound) 
                    {
	                    args.IsValid = false;
                        return;
                    }
                }
            }
        }
    }
    
    args.IsValid = true;

}

function ValidateRequiredMember(source, args) {

    if (specialValidationBeforeSubmit != true) 
    {
        if (searchMemberList.length > 0) 
        {
        	var values = objCriteriaForEdit.GetArrayWithTextValues('/Search/' + source.attributes['FieldName'].value + '/Value');

            if (values.length > 0) {
                for(var i=0; i < values.length; i++) 
                {
                    var valueFound = false;
                    for (var k=0; k < searchMemberList.length; k++) 
                        if (searchMemberList[k] == values[i])
                        {
                            valueFound = true;
                            break;
                        }

                    if (!valueFound) 
                    {
	                    args.IsValid = false;
                        return;
                    }
                }
            }
        }
    }
    
    args.IsValid = true;
}

function ValidateRequiresMarketAnalysisAccess(source, args) {
    //Nothing found then validation failed		
	args.IsValid = false;
}

function ValidateZipCode(source, args) {
	var multiZipCodes = /^(?:\d{5}|[, ])+$/;
	/* reTest description from the inside out:
	 * \d{5} - any time there are numbers (\d), we want exactly five of them
	 * [, ] - allow commas and spaces
	 *	(?: | ) - search for either digits OR comma/space; "?:" means that 
	 *		these parentheses are used only for grouping--don't memorize matches
	 *	^ and $ are beginning and end of string, respectively; in this way, we
	 *		force match on the entire string
	 *	/ and / are the regular expression literal delimiters
	 *	All other characters besides numeric digits, commas, and spaces are
	 *		disallowed.
	 */
	
	args.IsValid = multiZipCodes.test(args.Value);
}//ValidateZipCode()

//When a location is entered make sure a distance is entered
function ValidateRadiusDistance(source, args) {
	args.IsValid = true;
	if (specialValidationBeforeSubmit) {
		var searchField = source.attributes['SearchField'].value;
		var radiusNode = objCriteriaForEdit.SelectFirstNode('/Search/' + searchField);
		if (radiusNode == null) {
			args.IsValid = false;
		}
		else {
			var locationAttr = radiusNode.getAttributeNode('LocationText');
			if (locationAttr != null) {
				var locationValue = locationAttr.value;
				if (locationValue != null && locationValue != '') {
					var distanceAttr = radiusNode.getAttributeNode('Distance');
					if (distanceAttr == null) {
						args.IsValid = false;
					}
					else {
						var distanceValue = distanceAttr.value;
						if (distanceValue == null || distanceValue == '') {
							args.IsValid = false;
						}
					}
				}
			}
		}
	}
	return;
}

//When a distance is entered make sure a location is enetered
function ValidateRadiusLocation(source, args) {
	args.IsValid = true;
	if (specialValidationBeforeSubmit) {
		var searchField = source.attributes['SearchField'].value;
		var radiusNode = objCriteriaForEdit.SelectFirstNode('/Search/' + searchField);
		if (radiusNode == null) {
			args.IsValid = false;
		}
		else {
			var distanceAttr = radiusNode.getAttributeNode('Distance');
			if (distanceAttr != null) {
				var distanceValue = distanceAttr.value;
				if (distanceValue != null && distanceValue != '') {
					var locationAttr = radiusNode.getAttributeNode('LocationText');
					if (locationAttr == null) {
						args.IsValid = false;
					}
					else {
						var locationValue = locationAttr.value;
						if (locationValue == null || locationValue == '') {
							args.IsValid = false;
						}
					}
				}
			}
		}
	}
	return;
}

function ValidateRadiusFormatAndRange(source, args) {
	args.IsValid = true;
	var searchField = source.attributes['SearchField'].value;
	var control = GetFieldObject(searchField);
	var distanceInput = GetRadiusDistanceInputControl(control);
	if (distanceInput != null) {
		var distanceValue = distanceInput.value;
		//Ensure decimal format according to DistanceFormatPattern
		var format = source.attributes['Format'].value;
		if (format != null && format != '') {
			if (!eval(format).test(parseFloat(distanceValue))) {
				args.IsValid = false;
				return;
			}
		}
		//Ensure minimum value is within the range
		var min = source.attributes['Min'].value;
		if (min != null && min != '' && !isNaN(min)) {
			if ((distanceValue * 1.0) < (min * 1.0)) {
				args.IsValid = false;
				return;
			}
		}
		//Ensure minimum value is within the range
		var max = source.attributes['Max'].value;
		if (max != null && max != '' && !isNaN(max)) {
			if ((distanceValue * 1.0) > (max * 1.0)) {
				args.IsValid = false;
				return;
			}
		}
	}
	return;
}
