function numcheck(sText) {
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;
    
	for (var i = 0; i < sText.length && IsNumber == true; i++)  { 
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1)  {
			IsNumber = false;
		}
	}
	return IsNumber;
}

function allow_alpha(val) {
    var retval = false;
    
    if (val) {
        var allowed = /^[a-zA-Z-\.]+$/;
        retval = allowed.test(val);
    }
    return retval;
}

function allow_alphanumeric(val) {
    var retval = false;
    
    if (val) {
        var allowed = /^[0-9a-zA-Z\-\.]+$/;
        retval = allowed.test(val);
    }
    return retval;
}

function allow_alpha_space(val) {
    var retval = false;
    
    if (val) {
        var allowed = /^[a-zA-Z\s\-\.]+$/;
        retval = allowed.test(val);
    }
    return retval;
}

function allow_alphanumeric_space(val) {
    var retval = false;
    
    if (val) {
        var allowed = /^[0-9a-zA-Z\s\-\.]+$/;
        retval = allowed.test(val);
    }
    return retval;
}

function allow_special_alphanumeric_space(val) {
    var retval = false;
    
    if (val) {
        var allowed = /^[0-9a-zA-Z\s\-\&\#\%\+\,\'\.]+$/;
        retval = allowed.test(val);
    }
    return retval;
}

function allow_address(val) {
    var retval = false;
    
    if (val) {
        var allowed = /^[0-9a-zA-Z\s\-\#\&\.]+$/;
        retval = allowed.test(val);
    }
    return retval;
}

function trim(id_name) {
    if (id_name) {
        var field = document.getElementById(id_name);
        field.value = field.value.replace(/^\s+|\s+$/g,"");
    }
}

//check to see there are no consecutive dashes
function has_a_dash(val) {
    var retval = true;
    var letter = '';
    
    if (val) {
        for (var i = 0; i < val.length; i++) {
			letter = val.charAt(i);
            if (letter == '-') {
                if (i !== 0) {
                    //check previous letter
                    if (letter == val.charAt(i-1)) {
                        //this is a consecutive dash
                        retval = false;
                        break;
                    }
                }
            }
        }
    }
    return retval;
}

function daysInFebruary(year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31;
		if (i == 4 || i == 6 || i == 9 || i == 11) {
            this[i] = 30;
        }
		if (i == 2) {
            this[i] = 29;
        }
   } 
   return this
}

//in the case of picking dates - the form locks down the correct year
//however we need to further check the date itself. if the applicant has a bday
//where their bday is this year but the month has not occurred yet we want to prevent this
function check_for_minor(month, day, year) {
    var retval = Array(false,'MM','DD','YYYY');
    var msg = Array();
    var i = 0;//msg index
    
    if (numcheck(month) && numcheck(day) && numcheck(year)) {
        var date_obj = new Date();
        var valid_year = date_obj.getFullYear() - 18;
        if (valid_year == year) {
            //we need to do further checking
            var this_day = date_obj.getDate();
            var this_month = date_obj.getMonth();
            var js_month = month - 1; // because months in JS start with 0
            
            //alert('this_month '+this_month+' this_day '+this_day+' valid_year '+valid_year);
            if (js_month < this_month) {
                //valid birth date
                retval[0] = true;
                retval[1] = month;
                retval[2] = day ;
                retval[3] = year;
            } else if (js_month == this_month) {
                if (day < this_day) {
                    //valid birth date
                    retval[0] = true;
                    retval[1] = month;
                    retval[2] = day ;
                    retval[3] = year;
                } else if (day == this_day) {
                    //today is their bday; valid birth date
                    retval[0] = true;
                    retval[1] = month;
                    retval[2] = day ;
                    retval[3] = year;
                } else {
                    //this birthday has not occurred yet
                    retval[1] = month ;
                    retval[3] = year;
                    
                    msg[i] = "Lo siento, pero su fecha de nacimiento: " + month + "/" + day + "/" + year + ", no se ha producido todav&iacute;a. Usted debe ser en la actualidad por lo menos 18 a&ntilde;os para solicitar.";
                    i++;
                    msg[i] = "I am sorry, but your birth date: " + month + "/" + day + "/" + year + ", has not occured yet. You must be currently at least 18 years old to apply.";
                    i++;
                }
            } else {
                //this birthday has not occurred yet
                retval[2] = day ;
                retval[3] = year;
                
                msg[i] = "Lo siento, pero su fecha de nacimiento: " + month + "/" + day + "/" + year + ", no se ha producido todav&iacute;a. Usted debe ser en la actualidad por lo menos 18 a&ntilde;os para solicitar.";
                i++;
                msg[i] = "I am sorry, but your birth date: " + month + "/" + day + "/" + year + ", has not occured yet. You must be currently at least 18 years old to apply.";
                i++;
            }
        } else {
            //other validation places this within range
            retval[0] = true;
            retval[1] = month;
            retval[2] = day ;
            retval[3] = year;
        }
    } else {
        //not numeric - trigger date reset
        msg[i] = 'Esta fecha no es v&acute;lida. El mes, d&iacute;a y a&ntilde;o debe ser todos los n&uacute;meros.';
        i++;
        msg[i] = 'This date is invalid. The month, day and year must be all numbers.';
        i++;
    }
    
    if (msg[0]) {
        //alert(msg);
        var title = "Error de la Aplicaci&oacute;n:";
        var content = "<div style='text-align:center;'>";
        for (var k=0; k < msg.length; k++) {
            content += "<div style='text-align:left;'>" + msg[k] + "</div>";
        }
        content += "</div>";
        content += "<div style='clear:both;text-align:center;'>";
        //content += "<img style='border:0px solid red;' src='images/alert_logo.jpg' alt='This Has Been A <?php echo $SITE_LOGIN_NAME;?> Tip' title='This Has Been A <?php echo $SITE_LOGIN_NAME;?> Tip'/>";
        content += "</div>";
        
        $.alerts.okButton = '&nbsp;OK&nbsp;';
        jError(content, title);
    }
    return retval;
}

//Take day, month and year from string to create a Date object.
//Compare day, month and year with day, month and year extracted
//from the Date object. If they aren't the same, than the input date is not valid.
function validate_date(month, day, year, max, min) {
    var retval = Array(false,'MM','DD','YYYY');
    var msg = Array();
    var i = 0;//msg index
    
    if (numcheck(month) && numcheck(day) && numcheck(year)) {
        var objDate = new Date();  // date object initialized from the txtDate string
        var max_year = new Date();
        var min_year = new Date();
        var mSeconds; // milliseconds from txtDate
        var max_secs;
        var min_secs;
        var js_month = month - 1; // because months in JS start with 0
        var reset_year = new Date().getFullYear();
        var calc_max = reset_year - max;
        var calc_min = reset_year - min;
        if (max == '') {
            max = 80;
        }
        if (min == '') {
            min = 18;
        }
        
        objDate.setFullYear(year, js_month, day);
        max_year.setFullYear(calc_max, js_month, day);
        min_year.setFullYear(calc_min, js_month, day);
        
        // test year range
        //alert('secs='+objDate +'\nmin='+ min_year +'\nmax='+ max_year);
        if (objDate >= max_year && objDate <= min_year) {
            // convert txtDate to the milliseconds
            mSeconds = (new Date(year, js_month, day)).getTime();
            max_secs = (new Date(calc_max, js_month, day)).getTime();
            min_secs = (new Date(calc_min, js_month, day)).getTime();
            
            // set the date object from milliseconds
            objDate.setTime(mSeconds);
            max_year.setTime(max_secs);
            min_year.setTime(min_secs);
            
            // if there exists difference then date isn't valid
            if (objDate.getMonth() == js_month) {
                if (objDate.getDate() == day) {
                    if (objDate.getFullYear() == year) {
                        retval[0] = true;
                        retval[1] = month;
                        retval[2] = day ;
                        retval[3] = year;
                    } else {
                        //trigger year reset
                        retval[1] = 'MM';//set month blank
                        retval[2] = 'DD';//set day blank
                        retval[3] = reset_year;
                        msg += 'Esta fecha no existe.\n';
                        msg += 'This date does not exist\n';
                    }
                } else {
                    //trigger day reset
                    retval[1] = month;
                    retval[2] = 'DD';
                    retval[3] = year;
                    msg[i] = 'Esta fecha no existe.\n';
                    i++;
                    msg[i] = 'This date does not exist\n';
                    i++;
                }
            } else {
                //trigger month reset
                retval[1] = 'MM';
                retval[2] = day;
                retval[3] = year;
                msg[i] = 'Esta fecha no existe.\n';
                i++;
                msg[i] = 'This date does not exist\n';
                i++;
            }
        } else {
            //not in range - trigger year reset
            retval[1] = month;
            retval[2] = '01';
            retval[3] = reset_year;
            msg[i] = 'Esta fecha no existe.\n';
            i++;
            msg[i] = 'This date does not exist\n';
            i++;
        }
    } else {
        //not numeric - trigger date reset
        msg[i] = 'Esta fecha no es va\'lida. El mes, d&iacute;a y a&ntilde;o debe ser todos los n&uacute;meros.\n';
        i++;
        msg[i] = 'This date is invalid. The month, day and year must be all numbers.\n';
        i++;
    }
    
    if (msg[0]) {
        //alert(msg);
        var title = "Error de la Aplicaci&oacute;n:";
        var content = "<div style='text-align:center;'>";
        for (var k=0; k < msg.length; k++) {
            content += "<div style='text-align:left;'>" + msg[k] + "</div>";
        }
        content += "</div>";
        content += "<div style='clear:both;text-align:center;'>";
        //content += "<img style='border:0px solid red;' src='images/alert_logo.jpg' alt='This Has Been A <?php echo $SITE_LOGIN_NAME;?> Tip' title='This Has Been A <?php echo $SITE_LOGIN_NAME;?> Tip'/>";
        content += "</div>";
        
        $.alerts.okButton = '&nbsp;OK&nbsp;';
        jError(content, title);
    }
    return retval;
}

//This function disables Letters and allows only numbers
function numbersonly(e) {
    var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8) {
        //if the key isn't the backspace key (which we should allow)
		if (unicode<48||unicode>57) {
            //if not a number
            return false //disable key press
        }
    }
}

function getHTTPObject() {
    var xmlhttp;
    if (window.XMLHttpRequest) {
        // code for Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
        if (xmlhttp.overrideMimeType) {
            xmlhttp.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) {
        // code for IE
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                //alert('microsift ajax failed');
            }
        }
    } else {
      //alert("Your browser does not support XMLHTTP!");
    }
    
    return xmlhttp;
}

var http = getHTTPObject(); // We create the HTTP Object
var http2 = getHTTPObject(); // We create the HTTP Object
var http3 = getHTTPObject(); // We create the HTTP Object



function handle_residence_year_dropdown() {
    if (http2.readyState == 4) {
        if (http2.status == 200) {
            var dropdown = http2.responseText.split('[-]');
            var dropdown_month = document.getElementById("residence_date_month");
            var dropdown_day = document.getElementById("residence_date_day");
            var dropdown_year = document.getElementById("residence_date_year");
            //alert(dropdown[2]);
            
            //clear div for our new dropdown
            dropdown_month.innerHTML = '';
            dropdown_day.innerHTML = '';
            dropdown_year.innerHTML = '';
            
            dropdown_month.innerHTML = dropdown[0];
            dropdown_day.innerHTML = dropdown[1];
            dropdown_year.innerHTML = dropdown[2];
        }
    }
}

function residence_check_date_dropdown() {
    var url = "lib/get_residence_date_dropdown.php";
    var birth_month = document.getElementById('bd_month').value;
    var birth_day = document.getElementById('bd_day').value;
    var birth_year = document.getElementById('bd_year').value;
    var res_day = document.getElementById('residence_date_d').value;
    var res_month = document.getElementById('residence_date_m').value;
    var res_year = document.getElementById('residence_date_y').value;
    
	var params = "?&birth_year=" + birth_year;
	params += "&birth_month=" + birth_month + "&birth_day=" + birth_day;
	params += "&res_year=" + res_year + "&res_month=" + res_month + "&res_day=" + res_day;
	params += "&rand=" + Math.random();
	//alert(url+params);
    
    if (window.ActiveXObject) {
        //damn ie 6 users
        http3.onreadystatechange = function () {}
        http3.onreadystatechange = handle_residence_check_date_dropdown;
        //alert('ie6_trigger');
    } else {
        http3.onreadystatechange = function() { handle_residence_check_date_dropdown(); }
    }
    http3.open("GET",url+params,true);
	http3.send(null);
}

function handle_residence_check_date_dropdown() {
    if (http3.readyState == 4) {
        if (http3.status == 200) {
            var dropdown = http3.responseText.split("[-]");
			var dropdown_month = document.getElementById("residence_date_month");
            var dropdown_day = document.getElementById("residence_date_day");
            //alert('dropdown= '+dropdown);
            
            if (dropdown[2] != 'valid_date') {
                //display date choice error
                alert(dropdown[2]);
                
                //clear div for our new dropdown
                if (dropdown[0]) {
                    dropdown_month.innerHTML = '';
                    dropdown_month.innerHTML = dropdown[0];
                }
                
                if (dropdown[1]) {
                    dropdown_day.innerHTML = '';
                    dropdown_day.innerHTML = dropdown[1];
                }
            }
            http3.onreadystatechange = function () {}
            http3.abort();
        }
    }
}

function handleABA() {
    if (http.readyState == 4) {
        if (http.responseText.indexOf('invalid') == -1) {
            // Split the comma delimited response into an array
            results = http.responseText.split("|");
            
            var aba = document.getElementById("aba");
            var b_name = document.getElementById('bank_name');
            var b_tel = document.getElementById('bank_tel');
            
			//alert(results);
            if (results[0]) {
                aba.className = "inputselect LV_valid_field";
                aba.style.borderColor = "#00CC00";
                
                b_name.value = results[0];
                b_tel.value = results[1];
                
                //handle jquery
                bank_tel.disable();
                bank_name.disable();
                bank_tel.enable();
                bank_name.enable();
                b_name.style.backgroundColor = '#FFF';
                b_name.style.borderColor = '#00CC00';
                b_tel.style.backgroundColor = '#FFF';
                b_tel.style.borderColor = '#00CC00';
                document.getElementById('bank_name_error').innerHTML = '';
                document.getElementById('bank_tel_error').innerHTML = '';
            } else {
                //http://www.brainjar.com/js/validation/
                
                //WE DO NOT KNOW THIS ABA SO LET US PERFORM THE MATH VALIDATION FOR THIS NUMBER...
                // Run through each digit and calculate the total.
                if (numcheck(aba.value)) {
                    if (aba.value.length == 9) {
                        bank_tel.disable();
                        bank_name.disable();
                        bank_tel.enable();
                        bank_name.enable();
                        document.getElementById('bank_name_error').innerHTML = '';
                        document.getElementById('bank_tel_error').innerHTML = '';
                        
                        var total = 0;
                        for (i = 0; i < aba.value.length; i += 3) {
                            //The Checksum Algorithm
                            total += parseInt(aba.value.charAt(i), 10) * 3 +  parseInt(aba.value.charAt(i + 1), 10) * 7 +  parseInt(aba.value.charAt(i + 2), 10);
                        }
                        
                        // If the resulting sum is an even multiple of ten (but not zero),
                        // the aba routing number is good.
                        if (total == 0 || total % 10 != 0) {
                            //trigger error
                            //var title = "Application Tip:";
                            var title = "Aplicaci&oacute;n Consejo:";
                            var msg = "<div style='text-align:center;'>";
                            //msg += "This ABA/Routing Number is UNKNOWN by our system.<br/><br/>It will be accepted with this application but ";
                            msg += "Esto ABA / N&uacute;mero de Ruta Bancaria es desconocido por nuestro sistema.";
                            msg += "<br/><br/>";
                            msg += "Se acept&oacute; esta solicitud, pero ";
                            //msg += "there will be a <span style='text-decoration:underline;'>lower chance</span> of lenders funding you your ";
                            msg += "habr&aacute; un <span style='text-decoration:underline;'>menor probabilidad</span. ";
                            //msg += "requested <span style='text-decoration:underline;'>loan amount</span>. Please review this field before proceeding.";
                            msg += "de los prestamistas que su financiaci&oacute;n solicitada <span style='text-decoration:underline;'>importe del pr&eacute;stamo</span>. ";
                            msg += "Por favor revise este campo antes de proceder.";
                            msg += "</div>";
                            msg += "<div style='clear:both;text-align:center;'>";
                            //msg += "<img style='border:0px solid red;' src='images/alert_logo.jpg' alt='This Has Been A <?php echo $SITE_LOGIN_NAME;?> Tip' title='This Has Been A <?php echo $SITE_LOGIN_NAME;?> Tip'/>";
                            msg += "</div>";
                            
                            $.alerts.okButton = '&nbsp;Entiendo que tengo un desconocido ABA / N&uacute;mero de Ruta Bancaria&nbsp;';
                            jAlert(msg, title);
                        }
                    }
                }
            }
        }
    }
}

function updateABA() {
	if (http) {
		var abaValue = document.getElementById("aba").value;
		var url = "lib/aba.php";
		var param = "?param=";
        
		http.open("GET", url + param + escape(abaValue), true);
		http.onreadystatechange = handleABA;
		http.send(null);
	}
}

function handleUpdateEmployerCityState() {
	if (http2.readyState == 4) {
		if (http2.responseText.indexOf('invalid') == -1) {
			// Split the comma delimited response into an array
			var results = http2.responseText.split("|");
            var employer_zipcode = document.getElementById('employer_zipcode');
            var employer_city_input = document.getElementById('employer_city_input');
            var actual_employer_city = document.getElementById('employer_city');
            var employer_state_input = document.getElementById('employer_state_input');
            var actual_employer_state = document.getElementById('employer_state');
            var employer_city_error = document.getElementById('employer_city_input_error');
            //var employer_state_error = document.getElementById('employer_state_input_error');
            var employer_zipcode_error = document.getElementById('employer_zipcode_error');
            
            if (employer_zipcode.value.length == 5) {
                if (employer_zipcode.value == '00000') {
                    employer_zipcode_error.innerHTML = 'Esto no es un c&oacute;digo postal v&aacute;lido.';
                    employer_zipcode.style.backgroundColor = '#FFFF99';
                    employer_zipcode.style.borderColor = '#FF0000';
                } else {
                    employer_zipcode_error.innerHTML = '';
                    employer_zipcode.style.backgroundColor = '#FFF';
                    employer_zipcode.style.borderColor = '#00CC00';
                }
            }
            
            if (results[0]) {
                employer_city_input.value = results[0];
                actual_employer_city.value = results[0];
                
                //handle jquery live validation
                if (typeof employer_city != 'undefined') {
                    employer_city.disable();
                }
                employer_city_error.innerHTML = '';
                //green
                employer_city_input.style.backgroundColor = '#FFF';
                employer_city_input.style.border = '1px solid #00CC00';
                employer_city_input.disabled = true;
                employer_city_error.style.height = '0px';
                employer_city_error.style.lineHeight = '0px';
            } else {
                if (!employer_city_input.value.replace(/^\s+|\s+$/g,"")) {
                    employer_city_input.value = '';
                    actual_employer_city.value = '';
                } else {
                    //leave the existing values; we may not know this city
                }
                employer_city_input.disabled = false;
                
                //handle jquery live validation
                if (typeof employer_city != 'undefined') {
                    employer_city.enable();
                }
                //employer_city_error.innerHTML = '';
                ////default color
                ////the default color is to correct when a city and/or state error is triggered and then the zipcode is added
                //employer_city_input.style.border = '1px inset threedface';
                style_name_error('employer_city_input','employer city');
            }
            
            if (results[1]) {
                employer_state_input.value = results[1];
                actual_employer_state.value = results[1];
                
                //handle jquery live validation
                if (typeof employer_state != 'undefined') {
                    employer_state.disable();
                }
                //employer_state_error.innerHTML = '';
                //green
                employer_state_input.style.backgroundColor = '#FFF';
                employer_state_input.style.border = '1px solid #00CC00';
                employer_state_input.disabled = true;
            } else {
                if (!employer_state_input.value.replace(/^\s+|\s+$/g,"")) {
                    employer_state_input.value = '';
                    actual_employer_state.value = '';
                } else {
                    //leave the existing values; we may not know this state
                }
                employer_state_input.disabled = false;
                
                //handle jquery live validation
                if (typeof employer_state != 'undefined') {
                    employer_state.enable();
                }
                //employer_state_error.innerHTML = '';
                ////default color
                ////the default color is to correct when a city and/or state error is triggered and hten the zipcode is added
                //employer_state_input.style.border = '1px inset threedface';
                style_state_error('employer_state_input', 'employer state');
            }
		}
	}
}

function handleUpdateCityState() {
	if (http2.readyState == 4) {
		if (http2.responseText.indexOf('invalid') == -1) {
			// Split the comma delimited response into an array
			var results = http2.responseText.split("|");
            var zipcode = document.getElementById('zipcode');
            var home_city = document.getElementById('city_input');
            var actual_city = document.getElementById('city');
            var home_state = document.getElementById('state_input');
            var actual_state = document.getElementById('state');
            var city_error = document.getElementById('city_input_error');
            //var state_error = document.getElementById('state_input_error');
            var zipcode_error = document.getElementById('zipcode_error');
            
            if (zipcode.value.length == 5) {
                if (zipcode.value == '00000') {
                    zipcode_error.innerHTML = 'Esto no es un c&oacute;digo postal v&aacute;lido.';
                    zipcode.style.backgroundColor = '#FFFF99';
                    zipcode.style.borderColor = '#FF0000';
                    zipcode_error.style.height = '16px';
                    zipcode_error.style.lineHeight = '14px';
                } else {
                    zipcode_error.innerHTML = '';
                    zipcode.style.backgroundColor = '#FFF';
                    zipcode.style.borderColor = '#00CC00';
                    zipcode_error.style.height = '0px';
                    zipcode_error.style.lineHeight = '0px';
                }
            }
            
            if (results[0]) {
                home_city.value = results[0];
                actual_city.value = results[0];
                
                //handle jquery live validation
                if (typeof city_input != 'undefined') {
                    city_input.disable();
                }
                
                city_error.innerHTML = '';
                //green
                home_city.style.backgroundColor = '#FFF';
                home_city.style.border = '1px solid #00CC00';
                home_city.disabled = true;
                city_error.style.height = '0px';
                city_error.style.lineHeight = '0px';
            } else {
                if (!home_city.value.replace(/^\s+|\s+$/g,"")) {
                    home_city.value = '';
                    actual_city.value = '';
                } else {
                    //leave the existing values; we may not know this city
                }
                home_city.disabled = false;
                
                //handle jquery live validation
                if (typeof city_input != 'undefined') {
                    city_input.enable();
                }
                
                style_name_error('city_input','city',false,true);
            }
			
            if (results[1]) {
                home_state.value = results[1];
                actual_state.value = results[1];
                
                //handle jquery live validation
                if (typeof state_input != 'undefined') {
                    state_input.disable();
                }
                //state_error.innerHTML = '';
                //green
                home_state.style.backgroundColor = '#FFF';
                home_state.style.border = '1px solid #00CC00';
                home_state.disabled = true;
            } else {
                if (!home_state.value.replace(/^\s+|\s+$/g,"")) {
                    home_state.value = '';
                    actual_state.value = '';
                } else {
                    //leave the existing values; we may not know this state
                }
                home_state.disabled = false;
                
                //handle jquery live validation
                if (typeof state_input != 'undefined') {
                    state_input.enable();
                }
                
                style_state_error('state_input', 'state');
            }
		}
	}
}

function updateCityState(type) {
	if (http2) {
        if (type == "home") {
            var zipValue = document.getElementById("zipcode").value;
            if (zipValue === '' || zipValue.length != 5 || zipValue == '00000') {
                document.getElementById("zipcode").style.backgroundColor = '#FFFF99';
            }
        } else {
            if (type == "employer") {
                var zipValue = document.getElementById("employer_zipcode").value;
                if (zipValue === '' || zipValue.length != 5 || zipValue == '00000') {
                    document.getElementById("employer_zipcode").style.backgroundColor = '#FFFF99';
                }
            } else {
                var zipValue = document.getElementById("zipcode").value;
                if (zipValue === '' || zipValue.length != 5 || zipValue == '00000') {
                    document.getElementById("zipcode").style.backgroundColor = '#FFFF99';
                }
            }
        }
		var url = "lib/getCityState.php";
		var param = "?param=" + escape(zipValue);
        zipValue = zipValue.replace(/^\s+|\s+$/g,"");
        //alert(url+param);
        
        
        http2.open("GET", url + param, true);
        if (type == "home") {
            http2.onreadystatechange = handleUpdateCityState;
        } else {
            if (type == "employer") {
                http2.onreadystatechange = handleUpdateEmployerCityState;
            } else {
                http2.onreadystatechange = handleUpdateCityState;
            }
        }
        http2.send(null);
	}
}

function stopped_typing(){
	var retval = true;
	return retval;
}

var sec = 500;
var TimerRunning = false;
var TimerID = '';

function StopTimer(){
	if(TimerRunning){
		clearTimeout(TimerID);
	}
	TimerRunning = false;
}

function StartTimer(func,param,seconds) {
    var arg_list = '';
	StopTimer();
	
    if (typeof seconds == 'undefined') {
        seconds = sec;
    }
    //alert('index type ' + param instanceof Array);
    //alert('param type ' + typeof param);
	TimerRunning = true;
    if (param && param instanceof Array) {
        //check for an array
        for (var i=0; i < param.length; i++) {
            arg_list += '"' + param[i] + '"';
            
            if (i != (param.length - 1)) {
                arg_list += ',';
            }
        }
        //alert('list ' + arg_list);
        TimerID = setTimeout(func + '(' + arg_list + ')', seconds);
    } else if (param && typeof param != 'undefined') {
        //check for a string
        TimerID = setTimeout(func + '("' + param + '")', seconds);
    } else {
        TimerID = setTimeout(func + "()", seconds);
    }
}

function capletters(id) {
	var elem = document.getElementById(id);
	elem.value = elem.value.toUpperCase();
}

function validate_email(email) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var retval = false;
    if (reg.test(email) != false) {
        retval = true;
    }
    return retval;
}

function return_param(param) {
    return param;
}

function address_verification(address) {
    if (address) {
        if (http) {
            var url = "lib/address_verification.php";
            var param = "?addr=";
            
            http.open("GET", url + param + escape(address), true);
            http.onreadystatechange = handle_address_verification;
            http.send(null);
        }
    }
}

/**
 * this check absolutely cannot be used to check zipcodes. our zipcode lookup
 * is not subscription based and is not up to date enough to know when values such as
 * '11111' are legitimate or not. Values like '22222' is a real US zipcode.
 **/
function numeric_test_validator(val,max) {
    var retval = true;
    var invalid_seq0 = Array();
    var invalid_seq1 = Array();
    var area_code = val.substr(0,3);
    var invalid = Array();
    var digit = '';
    //create invalid values
    
    if (typeof max == 'undefined') {
        max = val.length;
    }
    
    //no 1 based sequential values
    for(var i=1; i <=  max; i++) {
        invalid_seq1 += i.toString();
    }
    invalid[0] = invalid_seq1;
    //no zero based sequential values
    for(var i=0; i < max; i++) {
        invalid_seq0 += i.toString();
    }
    invalid[1] = invalid_seq0;
    //"common" fake data
    invalid[2] = '1234567890';
    invalid[3] = '987654321';
    invalid[4] = '9876543210';
    invalid[5] = '0987654321';
    var index = invalid.length;
    
    //no values all the same
    for(var i=0; i <= 9; i++) {
        digit = '';
        for(var k=0; k < max; k++) {
            digit += i.toString();
        }
        invalid[index] = digit;
        index++;
        if (val.length >= 5) {
            invalid[index] = area_code.toString() + digit.substr(3).toString();
            index++;
        }
    }
    //alert(invalid);
    //search array
    for(var i=0; i <= invalid.length; i++) {
        if (val == invalid[i]) {
            //alert('val '+val+' invalid_val '+invalid[i]+ ' i '+i);
            retval = false;
        }
    }
    
    return retval;
}

/**
 * this function checks for the north american fictional numbers
 *Despite the widespread usage of NXX "555" for fictional telephone numbers -
 * today, the only such numbers specifically reserved for fictional use are
 * "555-0100" through "555-0199", with the remaining "555" numbers released for actual assignment
 **/
function is_fictional_phone_number(num) {
    var retval = false;
    
    var min = 5550100;
    var max = 5550199;
    var phone = num.substr(3);
    
    if (phone && numcheck(phone)) {
        if (phone >= min && phone <= max) {
            retval = true;
        }
    }
    return retval;
}



var generic_max = 50;
var first_name_min = 2;
var first_name_max = generic_max;
var last_name_min = 2;
var last_name_max = generic_max;
var address1_min = 5;
var address1_max = generic_max;
var city_input_min = 3;
var city_input_max = generic_max;

var account_number_min = 5;
var account_number_max = generic_max;
var bank_name_min = 3;
var bank_name_max = generic_max;

var employer_name_min = 3;
var employer_name_max = generic_max;
var employer_address_min = address1_min;
var employer_address_max = address1_max;
var employer_city_input_min = city_input_min;
var employer_city_input_max = city_input_max;

var drivers_license_min = 5;
var drivers_license_max = generic_max;

//Numeric with a length range limit
function style_numeric_range_error(id_name, alt_text) {
    if (id_name) {
        var field = document.getElementById(id_name);
        if (typeof alt_text == 'undefined' || (typeof alt_text == 'boolean' && alt_text == false) || (typeof alt_text == 'string' && alt_text == 'false')) {
            var alt_text = id_name.replace('_', ' ');
        }
        var field_error = document.getElementById(id_name + '_error');
        var lcase_text = alt_text.toLowerCase();
        var name_array = alt_text.split(' ');
        var ucase_text = '';
        for (var i=0; i < name_array.length; i++) {
            ucase_text += name_array[i].substr(0, 1).toUpperCase() + name_array[i].substr(1).toLowerCase() + ' ';
        }
        ucase_text = ucase_text.replace(/^\s+|\s+$/g,"");//trim whitespace
        var min = eval(id_name + '_min');
        var max = eval(id_name + '_max');
        //alert('id_name '+id_name+'\nfield '+field+'\nfield_error '+field_error+'\nlcase_text '+lcase_text+'\nucase_text '+ucase_text+'\nmin '+ min+'\nmax '+ max);
        
        if (field && field.value !== ''){
            if (field.value.length <= max && field.value.length >= min && numcheck(field.value)) {
                //this error is not covered by jquery validation; we need to mimic
                if (!numeric_test_validator(field.value, field.value.length)) {
                    field_error.innerHTML = '';
                    field_error.innerHTML = ucase_text + ' Es un N&uacute;mero No Autorizado';
                    //field_error.innerHTML = ucase_text + ' is an Unauthorized Number.';
                    field.style.backgroundColor = '#FFFF99';
                    field.style.border = '1px solid #FF0000';
                } else {
                    field.value = field.value.replace(/^\s+|\s+$/g,"");//trim whitespace
                    //field.style.borderColor = 'green';
                    field_error.innerHTML = '';
                    field.style.backgroundColor = '#FFF';
                    field.style.border = '1px solid #00CC00';
                }
            } else {
                field_error.innerHTML = '';
                field.style.backgroundColor = '#FFFF99';
                field.style.border = '1px solid #FF0000';
            }
        } else {
            field_error.innerHTML = '';
            field.style.backgroundColor = '#FFFF99';
            field.style.border = '1px solid #FF0000';
        }
    }
}

//Numeric with exact length
function style_numeric_error(id_name, length, alt_text) {
    if (id_name && length) {
        var field = document.getElementById(id_name);
        if (typeof alt_text == 'undefined' || (typeof alt_text == 'boolean' && alt_text == false) || (typeof alt_text == 'string' && alt_text == 'false')) {
            alt_text = id_name.replace('_', ' ');
        }
        var field_error = document.getElementById(id_name + '_error');
        var lcase_text = alt_text.toLowerCase();
        var name_array = alt_text.split(' ');
        var ucase_text = '';
        for (var i=0; i < name_array.length; i++) {
            ucase_text += name_array[i].substr(0, 1).toUpperCase() + name_array[i].substr(1).toLowerCase() + ' ';
        }
        ucase_text = ucase_text.replace(/^\s+|\s+$/g,"");//trim whitespace
        
        if (field && field.value !== '' && field.value.length == length){
            if (field.value.length == length && numcheck(field.value)) {
                //this error is not covered by jquery validation; we need to mimic
                if (!numeric_test_validator(field.value, length)) {
                    field_error.innerHTML = '';
                    field_error.innerHTML = ucase_text + ' Es un N&uacute;mero No Autorizado';
                    //field_error.innerHTML = ucase_text + ' is an Unauthorized Number.';
                    field.style.backgroundColor = '#FFFF99';
                    field.style.border = '1px solid #FF0000';
                } else {
                    field.value = field.value.replace(/^\s+|\s+$/g,"");//trim whitespace
                    //field.style.borderColor = 'green';
                    field_error.innerHTML = '';
                    field.style.backgroundColor = '#FFF';
                    field.style.border = '1px solid #00CC00';
                }
            } else {
                field_error.innerHTML = '';
                field.style.backgroundColor = '#FFFF99';
                field.style.border = '1px solid #FF0000';
            }
        } else {
            field_error.innerHTML = '';
            field.style.backgroundColor = '#FFFF99';
            field.style.border = '1px solid #FF0000';
        }
    }
}

//Phone number checking
function style_phone_error(id_name, alt_text, js_check) {
    var length = 10;
    if (id_name) {
        var field = document.getElementById(id_name);
        if (typeof alt_text == 'undefined' || (typeof alt_text == 'boolean' && alt_text == false) || (typeof alt_text == 'string' && alt_text == 'false')) {
            alt_text = id_name.replace('_', ' ');
        }
        
        if (typeof js_check == 'undefined') {
            js_check = false;
        }
        var field_error = document.getElementById(id_name + '_error');
        var lcase_text = alt_text.toLowerCase();
        var name_array = alt_text.split(' ');
        var ucase_text = '';
        for (var i=0; i < name_array.length; i++) {
            ucase_text += name_array[i].substr(0, 1).toUpperCase() + name_array[i].substr(1).toLowerCase() + ' ';
        }
        ucase_text = ucase_text.replace(/^\s+|\s+$/g,"");//trim whitespace
        
        if (field && field.value !== ''){
            if (field.value.length == length && numcheck(field.value)) {
                //this error is not covered by jquery validation; we need to mimic
                if (!numeric_test_validator(field.value, length)) {
                    field_error.innerHTML = '';
                    field_error.innerHTML = ucase_text + ' Es un N&uacute;mero No Autorizado';
                    //field_error.innerHTML = ucase_text + ' is an Unauthorized Number.';
                    field.style.backgroundColor = '#FFFF99';
                    field.style.border = '1px solid #FF0000';
                    if (js_check) {
                        field_error.style.height = '28px';
                        field_error.style.lineHeight = '14px';
                    }
                } else {
                    field.value = field.value.replace(/^\s+|\s+$/g,"");//trim whitespace
                    //north american numebering plan => +1-NPA-NXX-xxxx(subscriber #)
                    //NUMBERING PLAN AREA CODE - NPA
                    var npa_1 = field.value.substr(0,1);
                    var npa_2 = field.value.substr(1,1);
                    var npa_3 = field.value.substr(2,1);
                    if (npa_1 >= 2 && npa_1 <= 9) {
                        if (npa_2 >= 0 && npa_2 <= 8) {
                            if (npa_3 >= 0 && npa_3 <= 9) {
                                //WE HAVE A VALID AREA CODE AT THIS POINT
                                //CENTRAL OFFICE EXCAHNGE CODE - NXX
                                var nxx_1 = field.value.substr(3,1);
                                var nxx_2 = field.value.substr(4,1);
                                var nxx_3 = field.value.substr(5,1);
                                if (nxx_1 >= 2 && nxx_1 <= 9) {
                                    if ((nxx_2 >= 0 && nxx_2 <= 9) && (nxx_3 >= 0 && nxx_3 <= 9)) {
                                        if (nxx_2 == 1 && nxx_3 == 1) {
                                            //the last two digits of NXX cannot both be 1, to avoid confusion with the N11 codes
                                            field_error.innerHTML = ucase_text + ' Prefijo es un N&uacute;mero no autorizado (4, 5 y 6 n&uacute;mero de la izquierda).';
                                            //field_error.innerHTML = ucase_text + ' Prefix Is An Unauthorized Number (4th, 5th & 6th Number From the Left).';
                                            field.style.backgroundColor = '#FFFF99';
                                            field.style.border = '1px solid #FF0000';
                                            if (js_check) {
                                                field_error.style.height = '42px';
                                                field_error.style.lineHeight = '14px';
                                            }
                                        } else {
                                            //WE HAVE A VALID PHONE NUMBER PREFIX
                                            //all other subscriber number have no range - so let us search for fictional numbers
                                            if (is_fictional_phone_number(field.value)) {
                                                field_error.innerHTML = ucase_text + ' Es un N&uacute;mero No Autorizado';
                                                field.style.backgroundColor = '#FFFF99';
                                                field.style.border = '1px solid #FF0000';
                                                if (js_check) {
                                                    field_error.style.height = '28px';
                                                    field_error.style.lineHeight = '14px';
                                                }
                                            } else {
                                                //COMPLETELY VALID PHONE NUMBER
                                                //field.style.borderColor = 'green';
                                                field_error.innerHTML = '';
                                                field.style.backgroundColor = '#FFF';
                                                field.style.border = '1px solid #00CC00';
                                                if (js_check) {
                                                    field_error.style.height = '0px';
                                                    field_error.style.lineHeight = '0px';
                                                }
                                            }
                                        }
                                    } else {
                                        //jquery validator will catch this
                                        field_error.innerHTML = '';
                                        field.style.backgroundColor = '#FFFF99';
                                        field.style.border = '1px solid #FF0000';
                                        if (js_check) {
                                            field_error.style.height = '0px';
                                            field_error.style.lineHeight = '0px';
                                        }
                                    }
                                } else {
                                    field_error.innerHTML = ucase_text + ' Prefijo es un N&uacute;mero no autorizado (4, 5 y 6 n&uacute;mero de la izquierda).';
                                    //field_error.innerHTML = ucase_text + ' Prefix Is An Unauthorized Number (4th, 5th & 6th Number From the Left).';
                                    field.style.backgroundColor = '#FFFF99';
                                    field.style.border = '1px solid #FF0000';
                                    if (js_check) {
                                        field_error.style.height = '42px';
                                        field_error.style.lineHeight = '14px';
                                    }
                                }
                            } else {
                                //jquery validator will catch this
                                field_error.innerHTML = '';
                                field.style.backgroundColor = '#FFFF99';
                                field.style.border = '1px solid #FF0000';
                                if (js_check) {
                                    field_error.style.height = '0px';
                                    field_error.style.lineHeight = '0px';
                                }
                            }
                        } else {
                            //field_error.innerHTML = ucase_text + ' Has An Invalid Area Code.';
                            field_error.innerHTML = ucase_text + ' Tiene un C&oacute;digo no V&aacute;lido &Aacute;rea.';
                            field.style.backgroundColor = '#FFFF99';
                            field.style.border = '1px solid #FF0000';
                            if (js_check) {
                                field_error.style.height = '12px';
                                field_error.style.lineHeight = '14px';
                            }
                        }
                    } else {
                        //field_error.innerHTML = ucase_text + ' Has An Invalid Area Code.';
                        field_error.innerHTML = ucase_text + ' Tiene un C&oacute;digo no V&aacute;lido &Aacute;rea.';
                        field.style.backgroundColor = '#FFFF99';
                        field.style.border = '1px solid #FF0000';
                        if (js_check) {
                            field_error.style.height = '12px';
                            field_error.style.lineHeight = '14px';
                        }
                    }
                }
            } else {
                field_error.innerHTML = '';
                field.style.backgroundColor = '#FFFF99';
                field.style.border = '1px solid #FF0000';
                if (js_check) {
                    field_error.style.height = '0px';
                    field_error.style.lineHeight = '0px';
                }
            }
        } else {
            field_error.innerHTML = '';
            field.style.backgroundColor = '#FFFF99';
            field.style.border = '1px solid #FF0000';
            if (js_check) {
                field_error.style.height = '0px';
                field_error.style.lineHeight = '0px';
            }
        }
    }
}

//Name
function style_name_error(id_name, alt_text, numbers, js_check) {
    if (id_name) {
        var field = document.getElementById(id_name);
        if (typeof alt_text == 'undefined' || (typeof alt_text == 'boolean' && alt_text == false) || (typeof alt_text == 'string' && alt_text == 'false')) {
            alt_text = id_name.replace('_', ' ');
        }
        if (typeof js_check == 'undefined') {
            js_check = false;
        }
        
        var field_error = document.getElementById(id_name + '_error');
        var lcase_text = alt_text.toLowerCase();
        var name_array = alt_text.split(' ');
        var ucase_text = '';
        for (var i=0; i < name_array.length; i++) {
            ucase_text += name_array[i].substr(0, 1).toUpperCase() + name_array[i].substr(1).toLowerCase() + ' ';
        }
        ucase_text = ucase_text.replace(/^\s+|\s+$/g,"");//trim whitespace
        var min = eval(id_name + '_min');
        var max = eval(id_name + '_max');
        //alert('id_name '+id_name+'\nfield '+field.value+'\nfield_error '+field_error+'\nlcase_text '+lcase_text+'\nucase_text '+ucase_text+'\nmin '+ min+'\nmax '+ max);
        
        if (field && field.value !== ''){
            field.value = field.value.replace(/^\s+|\s+$/g,"");//trim whitespace
            if(field.value.length <= max && field.value.length >= min) {
                //this error is not covered by jquery validation; we need to mimic
                if (!numeric_test_validator(field.value, field.value.length)) {
                    field_error.innerHTML = '';
                    field_error.innerHTML = 'El ' + ucase_text + ' Es un Falso Conjunto de los N&uacute;meros.';
                    //field_error.innerHTML = 'The ' + ucase_text + ' is a False Set of Numbers.';
                    field.style.backgroundColor = '#FFFF99';
                    field.style.border = '1px solid #FF0000';
                    if (js_check) {
                        field_error.style.height = '28px';
                        field_error.style.lineHeight = '14px';
                    }
                } else {
                    if (typeof numbers == 'undefined' || (typeof numbers == 'boolean' && numbers == false) || (typeof numbers == 'string' && numbers == 'false')) {
                        var char_check = allow_alpha_space(field.value);
                    } else {
                        var char_check = allow_alphanumeric_space(field.value);
                    }
                    
                    if (char_check) {
                        if (has_a_dash(field.value)) {
                            //field.style.borderColor = 'green';
                            field_error.innerHTML = '';
                            field.style.backgroundColor = '#FFF';
                            field.style.border = '1px solid #00CC00';
                            if (js_check) {
                                field_error.style.height = '0px';
                                field_error.style.lineHeight = '0px';
                            }
                        } else {
                            field_error.innerHTML = ucase_text + " Contiene M&uacute;ltiples V&aacute;lido Gui&oacute;n (-) Personajes.";
                            //field_error.innerHTML = ucase_text + " Contains Multiple Invalid Dash (-) Characters.";
                            field.style.backgroundColor = '#FFFF99';
                            field.style.border = '1px solid #FF0000';
                            if (js_check) {
                                field_error.style.height = '28px';
                                field_error.style.lineHeight = '14px';
                            }
                        }
                    } else {
                        field_error.innerHTML = ucase_text + " Contiene Car&aacute;cter Inesperado(s). Si No Quitan los Caracteres Especiales.";
                        //field_error.innerHTML = ucase_text + " Contains Unexpected Character(s). Please Remove Special Characters.";
                        field.style.backgroundColor = '#FFFF99';
                        field.style.border = '1px solid #FF0000';
                        if (js_check) {
                            field_error.style.height = '38px';
                            field_error.style.lineHeight = '14px';
                        }
                    }
                }
            } else {
                field_error.innerHTML = '';
                field.style.backgroundColor = '#FFFF99';
                field.style.border = '1px solid #FF0000';
                if (js_check) {
                    field_error.style.height = '0px';
                    field_error.style.lineHeight = '14px';
                }
            }
        } else {
            field_error.innerHTML = '';
            field.style.backgroundColor = '#FFFF99';
            field.style.border = '1px solid #FF0000';
            if (js_check) {
                field_error.style.height = '0px';
                field_error.style.lineHeight = '0px';
            }
        }
    }
}

//Employer Name - this function has reduced validation than the style_name_error function
function style_employer_name_error(id_name, alt_text) {
    if (id_name) {
        var field = document.getElementById(id_name);
        if (typeof alt_text == 'undefined' || (typeof alt_text == 'boolean' && alt_text == false) || (typeof alt_text == 'string' && alt_text == 'false')) {
            alt_text = id_name.replace('_', ' ');
        }
        var field_error = document.getElementById(id_name + '_error');
        var lcase_text = alt_text.toLowerCase();
        var name_array = alt_text.split(' ');
        var ucase_text = '';
        for (var i=0; i < name_array.length; i++) {
            ucase_text += name_array[i].substr(0, 1).toUpperCase() + name_array[i].substr(1).toLowerCase() + ' ';
        }
        ucase_text = ucase_text.replace(/^\s+|\s+$/g,"");//trim whitespace
        var min = eval(id_name + '_min');
        var max = eval(id_name + '_max');
        //alert('id_name '+id_name+'\nfield '+field+'\nfield_error '+field_error+'\nlcase_text '+lcase_text+'\nucase_text '+ucase_text+'\nmin '+ min+'\nmax '+ max);
        
        if (field && field.value !== ''){
            field.value = field.value.replace(/^\s+|\s+$/g,"");//trim whitespace
            if(field.value.length <= max && field.value.length >= min) {
                field.value = field.value.replace(/^\s+|\s+$/g,"");//trim whitespace
                if (allow_special_alphanumeric_space(field.value)) {
                    if (has_a_dash(field.value)) {
                        //field.style.borderColor = 'green';
                        field_error.innerHTML = '';
                        field.style.backgroundColor = '#FFF';
                        field.style.border = '1px solid #00CC00';
                    } else {
                        field_error.innerHTML = ucase_text + " Contiene M&uacute;ltiples V&aacute;lido Gui&oacute;n (-) Personajes.";
                        //field_error.innerHTML = ucase_text + " Contains Multiple Invalid Dash (-) Characters.";
                        field.style.backgroundColor = '#FFFF99';
                        field.style.border = '1px solid #FF0000';
                    }
                } else {
                    field_error.innerHTML = ucase_text + " Contiene Car&aacute;cter Inesperado(s). Si No Quitan los Caracteres Especiales.";
                    //field_error.innerHTML = ucase_text + " Contains Unexpected Character(s). Please Remove Special Characters.";
                    field.style.backgroundColor = '#FFFF99';
                    field.style.border = '1px solid #FF0000';
                }
            } else {
                field_error.innerHTML = '';
                field.style.backgroundColor = '#FFFF99';
                field.style.border = '1px solid #FF0000';
            }
        } else {
            field_error.innerHTML = '';
            field.style.backgroundColor = '#FFFF99';
            field.style.border = '1px solid #FF0000';
        }
    }
}

//Address
function style_address_error(id_name,alt_text,js_check){
	var field = document.getElementById(id_name);
    if (typeof alt_text == 'undefined' || (typeof alt_text == 'boolean' && alt_text == false) || (typeof alt_text == 'string' && alt_text == 'false')) {
        alt_text = id_name.replace('_', ' ');
    }
    if (typeof js_check == 'undefined') {
        js_check = false;
    }
    var field_error = document.getElementById(id_name + '_error');
	var lcase_text = alt_text.toLowerCase();
    var name_array = alt_text.split(' ');
    var ucase_text = '';
    for (var i=0; i < name_array.length; i++) {
        ucase_text += name_array[i].substr(0, 1).toUpperCase() + name_array[i].substr(1).toLowerCase() + ' ';
    }
    ucase_text = ucase_text.replace(/^\s+|\s+$/g,"");//trim whitespace
    var min = eval(id_name + '_min');
    var max = eval(id_name + '_max');
    //alert('id_name '+id_name+'\nfield '+field+'\nfield_error '+field_error+'\nlcase_text '+lcase_text+'\nucase_text '+ucase_text+'\nmin '+ min+'\nmax '+ max);
    
	if (field && field.value !== '') {
		if(field.value.length <= max && field.value.length >= min) {
            //trim field
            field.value = field.value.replace(/^\s+|\s+$/g,"");
            
            var field_check = field.value.split(' ');
            //redefine value
            field.value = '';
            for (var i=0; i < field_check.length; i++) {
                //skip empty strings
                if (field_check[i]) {
                    //trim each string
                    field.value += field_check[i].replace(/^\s+|\s+$/g,"");
                    if (i != (field_check.length - 1)) {
                        //if it is not the last string add a space
                        field.value += ' ';
                    }
                }
            }
            field_check = field.value.split(' ');
            
            //alert(address1_check + ' ' + address1_check.length);
            if (field_check == field.value || field_check.length < 2) {
                field_error.innerHTML = '';
                field_error.innerHTML = 'Un Formato Incorrecto, un N&uacute;mero de Direcci&oacute;n, Nombre y Sufijo CON Espacios Es Necesario, i.e. "123 River Ave.".';
                //field_error.innerHTML = 'Formatted Incorrectly; an Address Number, Name and Suffix WITH Spaces is Required, i.e. "123 River Ave.".';
                field.style.backgroundColor = '#FFFF99';
                field.style.border = '1px solid #FF0000';
                if (js_check) {
                    field_error.style.height = '58px';
                    field_error.style.lineHeight = '14px';
                }
            } else {
                if (field.value.length <= max && field.value.length >= min) {
                    //this error is not covered by jquery validation; we need to mimic
                    if (!numeric_test_validator(field.value, field.value.length)) {
                        field_error.innerHTML = '';
                        field_error.innerHTML = 'El ' + ucase_text + ' Es un Falso Conjunto de los N&uacute;meros.';
                        //field_error.innerHTML = 'The ' + ucase_text + ' is a False Set of Numbers.';
                        field.style.backgroundColor = '#FFFF99';
                        field.style.border = '1px solid #FF0000';
                        if (js_check) {
                            field_error.style.height = '28px';
                            field_error.style.lineHeight = '14px';
                        }
                    } else {
                        if (allow_address(field.value)) {
                            if (has_a_dash(field.value)) {
                                //acct.style.borderColor = 'green';
                                field_error.innerHTML = '';
                                field.style.backgroundColor = '#FFF';
                                field.style.border = '1px solid #00CC00';
                                field_error.style.height = '0px';
                                field_error.style.lineHeight = '0px';
                            } else {
                                field_error.innerHTML = ucase_text + " Contiene M&uacute;ltiples V&aacute;lido Gui&oacute;n (-) Personajes.";
                                //field_error.innerHTML = ucase_text + " Contains Multiple Invalid Dash (-) Characters.";
                                field.style.backgroundColor = '#FFFF99';
                                field.style.border = '1px solid #FF0000';
                                if (js_check) {
                                    field_error.style.height = '28px';
                                    field_error.style.lineHeight = '14px';
                                }
                            }
                        } else {
                            field_error.innerHTML = ucase_text + " Contiene Car&aacute;cter Inesperado(s). Si No Quitan los Caracteres Especiales.";
                            //field_error.innerHTML = ucase_text + " Contains Unexpected Character(s). Please Remove Special Characters.";
                            field.style.backgroundColor = '#FFFF99';
                            field.style.border = '1px solid #FF0000';
                            if (js_check) {
                                field_error.style.height = '58px';
                                field_error.style.lineHeight = '14px';
                            }
                        }
                    }
                } else {
                    field_error.innerHTML = '';
                    field.style.backgroundColor = '#FFFF99';
                    field.style.border = '1px solid #FF0000';
                    if (js_check) {
                        field_error.style.height = '0px';
                        field_error.style.lineHeight = '0px';
                    }
                }
            }
		} else {
            field_error.innerHTML = '';
			field.style.backgroundColor = '#FFFF99';
			field.style.border = '1px solid #FF0000';
            if (js_check) {
                field_error.style.height = '0px';
                field_error.style.lineHeight = '0px';
            }
		}
	} else {
        field_error.innerHTML = '';
		field.style.backgroundColor = '#FFFF99';
		field.style.border = '1px solid #FF0000';
        if (js_check) {
            field_error.style.height = '0px';
            field_error.style.lineHeight = '0px';
        }
	}
}

//Driver's License #
function style_drivers_license_error(id_name, alt_text) {
    if (id_name) {
        var field = document.getElementById(id_name);
        if (typeof alt_text == 'undefined' || (typeof alt_text == 'boolean' && alt_text == false) || (typeof alt_text == 'string' && alt_text == 'false')) {
            alt_text = id_name.replace('_', ' ');
        }
        var field_error = document.getElementById(id_name + '_error');
        var lcase_text = alt_text.toLowerCase();
        var name_array = alt_text.split(' ');
        var ucase_text = '';
        for (var i=0; i < name_array.length; i++) {
            ucase_text += name_array[i].substr(0, 1).toUpperCase() + name_array[i].substr(1).toLowerCase() + ' ';
        }
        ucase_text = ucase_text.replace(/^\s+|\s+$/g,"");//trim whitespace
        var min = eval(id_name + '_min');
        var max = eval(id_name + '_max');
        //alert('id_name '+id_name+'\nfield '+field+'\nfield_error '+field_error+'\nlcase_text '+lcase_text+'\nucase_text '+ucase_text+'\nmin '+ min+'\nmax '+ max);
        
        if (field && field.value !== ''){
            field.value = field.value.replace(/^\s+|\s+$/g,"");//trim whitespace
            if(field.value.length <= max && field.value.length >= min) {
                //this error is not covered by jquery validation; we need to mimic
                if (!numeric_test_validator(field.value, field.value.length)) {
                    field_error.innerHTML = '';
                    field_error.innerHTML = 'El ' + ucase_text + ' Es un Falso Conjunto de los N&uacute;meros.';
                    //field_error.innerHTML = 'The ' + ucase_text + ' is a False Set of Numbers.';
                    field.style.backgroundColor = '#FFFF99';
                    field.style.border = '1px solid #FF0000';
                } else {
                    field.value = field.value.replace(/^\s+|\s+$/g,"");//trim whitespace
                    if (allow_alphanumeric_space(field.value)) {
                        if (has_a_dash(field.value)) {
                            //field.style.borderColor = 'green';
                            field_error.innerHTML = '';
                            field.style.backgroundColor = '#FFF';
                            field.style.border = '1px solid #00CC00';
                        } else {
                            field_error.innerHTML = ucase_text + " Contiene M&uacute;ltiples V&aacute;lido Gui&oacute;n (-) Personajes.";
                            //field_error.innerHTML = ucase_text + " Contains Multiple Invalid Dash (-) Characters.";
                            field.style.backgroundColor = '#FFFF99';
                            field.style.border = '1px solid #FF0000';
                        }
                    } else {
                        field_error.innerHTML = ucase_text + " Contiene Car&aacute;cter Inesperado(s). Si No Quitan los Caracteres Especiales.";
                        //field_error.innerHTML = ucase_text + " Contains Unexpected Character(s). Please Remove Special Characters.";
                        field.style.backgroundColor = '#FFFF99';
                        field.style.border = '1px solid #FF0000';
                    }
                }
            } else {
                field_error.innerHTML = '';
                field.style.backgroundColor = '#FFFF99';
                field.style.border = '1px solid #FF0000';
            }
        } else {
            field_error.innerHTML = '';
            field.style.backgroundColor = '#FFFF99';
            field.style.border = '1px solid #FF0000';
        }
    }
}

var STATES_LOOKUP = Array(
   "AK",
   "ALASKA",
   "AL",
   "ALABAMA",
   "AR",
   "ARKANSAS",
   "AZ",
   "ARIZONA",
   "CA",
   "CALIFORNIA",
   "CO",
   "COLORADO",
   "CT",
   "CONNECTICUT",
   "DC",
   "DISTRICT OF COLUMBIA",
   "D.C.",
   "DIST. OF COLUMBIA",
   "DE",
   "DELAWARE",
   "FL",
   "FLORIDA",
   "GA",
   "GEORGIA",
   "HI",
   "HAWAII",
   "IA",
   "IOWA",
   "ID",
   "IDAHO",
   "IL",
   "ILLINOIS",
   "IN",
   "INDIANA",
   "KS",
   "KANSAS",
   "KY",
   "KENTUCKY",
   "LA",
   "LOUISIANA",
   "MA",
   "MASSACHUSETTS",
   "MD",
   "MARYLAND",
   "ME",
   "MAINE",
   "MI",
   "MICHIGAN",
   "MN",
   "MINNESOTA",
   "MO",
   "MISSOURI",
   "MS",
   "MISSISSIPPI",
   "MT",
   "MONTANA",
   "NC",
   "NORTH CAROLINA",
   "N CAROLINA",
   "N. CAROLINA",
   "ND",
   "NORTH DAKOTA",
   "N. DAKOTA",
   "N DAKOTA",
   "NE",
   "NEBRASKA",
   "NH",
   "NEW HAMPSHIRE",
   "NJ",
   "NEW JERSEY",
   "NM",
   "NEW MEXICO",
   "NV",
   "NEVADA",
   "NY",
   "NEW YORK",
   "OH",
   "OHIO",
   "OK",
   "OKLAHOMA",
   "OR",
   "OREGON",
   "PA",
   "PENNSYLVANIA",
   "RI",
   "RHODE ISLAND",
   "SC",
   "SOUTH CAROLINA",
   "S. CAROLINA",
   "S CAROLINA",
   "SD",
   "SOUTH DAKOTA",
   "S. DAKOTA",
   "S DAKOTA",
   "TN",
   "TENNESSEE",
   "TX",
   "TEXAS",
   "UT",
   "UTAH",
   "VA",
   "VIRGINIA",
   "VT",
   "VERMONT",
   "WA",
   "WASHINGTON",
   "WI",
   "WISCONSIN",
   "WV",
   "WEST VIRGINIA",
   "W. VIRGINA",
   "W VIRGINIA",
   "WY",
   "WYOMING"
);

//State
function style_state_error(id_name, alt_text) {
    if (id_name) {
        var field = document.getElementById(id_name);
        field.value.toUpperCase();
        if (typeof alt_text == 'undefined' || (typeof alt_text == 'boolean' && alt_text == false) || (typeof alt_text == 'string' && alt_text == 'false')) {
            var alt_text = id_name.replace('_', ' ');
        }
        //var field_error = document.getElementById(id_name + '_error');
        var lcase_text = alt_text.toLowerCase();
        var name_array = alt_text.split(' ');
        var ucase_text = '';
        for (var i=0; i < name_array.length; i++) {
            ucase_text += name_array[i].substr(0, 1).toUpperCase() + name_array[i].substr(1).toLowerCase() + ' ';
        }
        ucase_text = ucase_text.replace(/^\s+|\s+$/g,"");//trim whitespace
        //alert('id_name '+id_name+'\nfield '+field+'\nfield_error '+field_error+'\nlcase_text '+lcase_text+'\nucase_text '+ucase_text);
        
        if (field && field.value !== '') {
            if (field.value.length == 2) {
                var found = 0;
                for(var i = 0; i < STATES_LOOKUP.length; i++) {
                    if(STATES_LOOKUP[i] == field.value) {
                        found++;
                    }
                }
                if (found) {
                    //acct.style.borderColor = 'green';
                    //field_error.innerHTML = '';
                    field.style.backgroundColor = '#FFF';
                    field.style.border = '1px solid #00CC00';
                } else {
                    //field_error.innerHTML = '';
                    field.style.backgroundColor = '#FFFF99';
                    field.style.border = '1px solid #FF0000';
                }
            } else {
                //field_error.innerHTML = '';
                field.style.backgroundColor = '#FFFF99';
                field.style.border = '1px solid #FF0000';
            }
        } else {
            //field_error.innerHTML = '';
            field.style.backgroundColor = '#FFFF99';
            field.style.border = '1px solid #FF0000';
        }
    }
}
