
        
        function validateFormWithLeadValidation() {
            //alert('validating');
            var status = false;
            
            validateForm();
            
            if (document.MM_returnValue == true) {
            
                //alert('contacting ServiceObjects');
                status = validatesubmit_form();
             }
            
                //alert('returned status is ' + status);
            return status;
        }
        
        
        function getInputParams(code) {
            var tmp = null;
        
            if (code != null && code != 'email')
                tmp = document.getElementsByName( code );
                
            return tmp;
        }
        
        
        function addErrorMessage(paramID, errormsg) {
        
            try {
                if (paramID != null && errormsg != null) {

                    var nodeID = paramID + "Error";
                    //alert('id is ' + nodeID);
                    var node = document.getElementById( nodeID );
                    node.innerHTML = errormsg;
                }
            }
            catch(ex) {
               alert('EXCEPTION: ' + ex);
            }
        }
        
        
        function removeChildrenFrom(nodeID) {
        
            var node = document.getElementById( nodeID );
            if (node != null) {
            
                while (node.hasChildNodes()) {
                
                    node.removeChild(node.firstChild);
                }// end while.
            }// end if.
        }
        
        
        function leadValidationErrorHandler(errors) {
            //alert('errors are ' + errors);
            
            var errorStatus = true;
            var errormsg = '';
            
            var input;

            var certaintyThreshold = parseInt( document.forms[0].certaintyThreshold.value  );
            var validationCountThreshold = parseInt( document.forms[0].validationCountThreshold.value  );

            //alert('certainty threshold is ' + certaintyThreshold);
            //alert('count threshold ' + validationCountThreshold);
            
            var overallCertainty = parseInt( errors['overall.certainty'] );
            //alert('overall.certainty is ' + overallCertainty);
            
            

            var validationCount = parseInt( document.forms[0].validationCount.value );
            validationCount = validationCount + 1;
            //alert('validationCount is ' + validationCount);
            document.forms[0].validationCount.value = validationCount + "";
            
            
            if (overallCertainty < certaintyThreshold && validationCount < validationCountThreshold) {
            
                // Reset Error Boxes
                var length = document.forms[0].elements.length;
                for (i=0; i<length; i++) {

                    document.forms[0].elements[i].style.border= "0px solid red";
                }// end for.
                
                removeChildrenFrom("firstnameError");
                removeChildrenFrom("address1Error");
                removeChildrenFrom("phone_numError");
				removeChildrenFrom("emailError");

                
                
                var errorCode1 = errors['warning.code1'];
                //alert('warning.code1 is ' + errorCode1);

                var errorCode1Desc = errors['warning.description1'];
                //alert('warning.description1 is ' + errorCode1Desc);

                if (errorCode1Desc != null && errorCode1Desc != '')
                    errormsg += errorCode1Desc + '<br>';

                var errorCode1Param = errors[ errorCode1 ];
                //alert('errorCode1Param is ' + errorCode1Param);

                if (validationCount < 2 || errorCode1Param != null && (errorCode1Param == 'phone_num' 
					|| errorCode1Param == 'firstname' || errorCode1Param == 'address1' || errorCode1Param == 'email')) {
                
                    addErrorMessage( errorCode1Param, errorCode1Desc );
                    input = getInputParams( errorCode1Param );
                    if (input != null) {

                        input[0].style.border= "2px solid red"; 
                        errorStatus = false;
                        ////alert('setting error here!');
                    }// end if.
                }// end if.

                var errorCode2 = errors['warning.code2'];
                //alert('warning.code2 is ' + errorCode2);

                var errorCode2Desc = errors['warning.description2'];
                //alert('warning.description2 is ' + errorCode2Desc);

                if (errorCode2Desc != null && errorCode2Desc != '')
                    errormsg += errorCode2Desc + '<br>';

                var errorCode2Param = errors[ errorCode2 ];
                //alert('errorCode2Param is ' + errorCode2Param);


                if (validationCount < 2 || errorCode2Param != null && (errorCode1Param == 'phone_num' 
					|| errorCode1Param == 'firstname' || errorCode1Param == 'address1' || errorCode1Param == 'email')) {
                
                    addErrorMessage( errorCode2Param, errorCode2Desc );
                    input = getInputParams( errorCode2Param );
                    if (input != null)
                        input[0].style.border= "2px solid red"; 
                }// end if.

                var errorCode3 = errors['warning.code3'];
                //alert('warning.code3 is ' + errorCode3);

                var errorCode3Desc = errors['warning.description3'];
                //alert('warning.description3 is ' + errorCode3Desc);

                if (errorCode3Desc != null && errorCode3Desc != '')
                    errormsg += errorCode3Desc + '<br>';

                var errorCode3Param = errors[ errorCode3 ];
                //alert('errorCode3Param is ' + errorCode3Param);



                if (validationCount < 2 || errorCode3Param != null && (errorCode1Param == 'phone_num' 
					|| errorCode1Param == 'firstname' || errorCode1Param == 'address1' || errorCode1Param == 'email')) {
                
                    addErrorMessage( errorCode3Param, errorCode3Desc );
                    input = getInputParams( errorCode3Param );
                    if (input != null)
                        input[0].style.border= "2px solid red"; 
                }// end if.


                if (errorStatus == false) {                   
                    
					if(validationCount == 1){
						document.getElementById('leadValidationDisclaimer').innerHTML = "<font color='blue'><b>To ensure your contact information is correct all records are verified with the USPS.</b></font>";
					} else if(validationCount == 2) {
						document.getElementById('leadValidationDisclaimer').innerHTML = "<font color='blue'><b>All records are verified with the USPS.</b></font>";
					}
                }
            }// end if.
            
            
            return errorStatus;
        }