      var i;
      var t;
      var scc=0;
      var amt="0.00" ;
      var idx = -1;

   function showselect( w, display, ordered ) {
           t="";
           var p="";
           var sc=0;
           for ( i = 1;i < w.options.length;i++)
            {
            if ( w.options[i].selected )
               {
               if ( sc > 0 )
                  {
                  p = ", ";
                  }
               t = t + p + w.options[i].value;
               sc = sc + 1;
               }

            }
            if ( sc == 0 )
               {
               w.options[0].selected=true;
               }
            else
               {
               w.options[0].selected=false;
               }
            document.getElementById(display).value=t;
            document.getElementById(ordered).value=t;

            scc = sc;
           }



  function showselectcnt( w , ordered, search_state) {
        document.getElementById(ordered).value=document.getElementById(search_state).value;
    }


// valid email
function checkEmail( text )
   {
   var goodEmail = text.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
   return( goodEmail );
   }


// The social validator
// returns true if social is invalid
function social() {
 var bool= false;
 var social = document.order_form.ssn_check_input.value;

 if(social.length != 9 && social.length != 11)
 {
   bool= true;
 }

       if(social=="000000000" || social=="000-00-0000")
        {
         bool= true;
        }

        if(social.length == 9)
        {
                for (var i = 0; i<social.length; i++)
                {
                        var oneChar = social.charAt(i)
                        if (oneChar < "0" || oneChar > "9")
                        {
                                        bool= true;
                                break;
                        }
                        else
                        {
                                var part1 = social.substring(0,3)
                                var part2 = social.substring(3,5)
                                var part3 = social.substring(5,9)
                                document.order_form.ssn_check_input.value=part1 + "-" + part2 + "-" + part3
                                document.order_form.applicant_ssn.value=part1 + "-" + part2 + "-" + part3
                        }
                }
        }

        if(social.length == 11)
        {
                if (social.charAt(3) != "-" || social.charAt(6) != "-")
                {
                             bool= true;
                }
                else
                {
                        if (social.indexOf("-") != 3 )
                        {
                                      bool= true;
                        }
                        else if (social.indexOf("-",4) != 6)
                        {
                                        bool= true;
                        }
                        else if (social.indexOf("-",7) != -1)
                        {
                                        bool= true;
                        }
                        else for (var i = 0; i<social.length; i++)
                        {
                        var oneChar = social.charAt(i)
                        if (oneChar < "0" || oneChar > "9")
                                {
                                        if (social.charAt(3) != "-" || social.charAt(6) != "-")
                                        {
                                                 bool= true;
                                                break;
                                        }
                                }
                        }
                }
        }

 if (bool== true)
        {
        document.order_form.applicant_ssn.focus();
        }
return  bool ;
}
//end of social validator//


//DOB validator //
function isValidDate(dateStr) {

// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables

        var datePat = /^(\d{2})(\/|-)(\d{2})\2(\d{4})$/;

// To require a 4 digit year entry, use this line instead:
// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

        var matchArray = dateStr.match(datePat); // is the format ok?

        if (matchArray == null)
        {
                alert("Date is not in a valid format.\nPlease re-enter the date of birth (mm-dd-yyyy).")
                document.order_form.applicant_dob.value = "";
                return false;
        }

        month = matchArray[1]; // parse date into variables
        day = matchArray[3];
        year = matchArray[4];

        if (month < 1 || month > 12)
        { // check month range
                alert("Month must be between 1 and 12.\nPlease re-enter the date of birth.");
                document.order_form.applicant_dob.value = "";
                return false;
        }

        if (day < 1 || day > 31)
        {
                alert("Day must be between 1 and 31.\nPlease re-enter the date of birth.");
                document.order_form.applicant_dob.value = "";
                return false;
        }
        if (year < 1800)
        {
                alert("Year must be in usuable range.");
                document.order_form.applicant_dob.value = "";
                return false;
        }
        if ((month==4 || month==6 || month==9 || month==11) && day==31)
        {
                alert("Month "+month+" doesn't have 31 days.\nPlease re-enter the date of birth.")
                document.order_form.applicant_dob.value = "";
                return false;
        }

        if (month == 2)
        { // check for february 29th
                var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
                if (day>29 || (day==29 && !isleap))
                {
                        alert("February " + year + " doesn't have " + day + " days.\nPlease re-enter the date of birth.");
                        document.order_form.applicant_dob.value = "";
                        return false;
                }
        }
        if (document.order_form.applicant_dob.value == ""        )
                {
  //              document.order_form.applicant_fname.focus();
                document.order_form.applicant_dob.focus();
                }
        return true;  // date is valid
}
                //  End of DOB validator


function validCrimSearch(type) {
 var bool=true;
 var msg;
 if (type=="CRIM_STATE") {
  if (document.order_form.search_state.value.length==0) {
     msg="You must select a state.";
     bool=false;
  }
 } else if (type=="CRIM_COUNTY") {
   if(document.order_form.search_county_state.value.length==0) {
    msg="You must select a state.";
    bool=false;
   } else if (document.order_form.countyordered.value.length==0) {
    msg="You must enter a county to be searched.";
    bool=false;
   }
 }
 if (!bool) {
  alert(msg);  }
return bool;
}



function isValidObject(objToTest) {
if (objToTest == null || objToTest == undefined) {
return false;
}
return true;
}

function oneCrimStateSearch() {
 var bool=false;
 var valid=true;
 // if (document.order_form.criminal_order_type.value.length>0) {
    valid=validCrimSearch(document.order_form.criminal_order_type.value);
    if (valid) {
      bool=true;
    }
 // }
 if (!bool) {
  if (valid) { alert("You must select at least one search."); }
 }
 return bool;
}


function oneSearch() {
 var bool=false;
 var valid=true;
// if (document.order_form.ssnverification.checked)  {
//  bool=true;
// }
/*
 if (document.order_form.eviction.checked)  {
  if (document.order_form.eviction_order_type.value.length>0) {
    valid=validEvicSearch(document.order_form.eviction_order_type.value);
    if (valid) {
      bool=true;
    }
   }
 }
 */
// if (document.order_form.criminal.checked)  {
  if (document.order_form.criminal_order_type.value.length>0) {
    valid=validCrimSearch(document.order_form.criminal_order_type.value);
    if (valid) {
      bool=true;
    }
   }
 //}
 if (!bool) {
  if (valid) { alert("You must select at least one search."); }
 }
 return bool;
}

var statecount = 0;
var stateSelected = false;


// outputs false if ssn is empty
function checkSSNSearch() {
        if (document.order_form.ssnverification.checked)  {
             if (!check_empty(document.order_form.ssn_check_input.value))  {
                  return false;
             }
        }
        return true;
 }



// this needs to work for ssn check
// this needs to work for packages
function checkAppForm() {
      var ssn=0;
      var q = "Please correct the following:\n";
      var validity = true; // assume valid
      if  (isValidObject(document.order_form.ssn_check_input)) {
          if (!checkSSNSearch()) {
                q += '-  SSN is required.\n';
                validity = false;
                elsenum=0;
           } else if (document.order_form.ssnverification.checked) {
             if (social()) {
                 q += '-  SSN Format is invalid.\n';
                 validity = false;
             }
           }
      }
      if ( !validity ) {
           alert(q);
           return validity;
      }
      return validity;
}



function validate_form(pack) {
      var ssn=0;
      if  (isValidObject(document.order_form.ssn_check_input)) {
           ssn=1;
      }
        var q = "Please correct the following:\n";
        var validity = true; // assume valid
        var gotoitem=null;
        var elsenum=1;
        if ((!check_empty(document.order_form.applicant_fname.value)) || (!check_empty(document.order_form.applicant_lname.value)))
                {
                q += '-  Full Name is required.\n';
                validity = false;
                }
// ONLY IF NOT PACKAGE
        if ((pack==1) && (ssn==1)) {
        //    document.order_form.ssnverification.checked=true;
        }
        if ((pack==0) || (ssn==1)) {
//         if (!checkSSNSearch()) {
//                q += '-  SSN is required.\n';
//                validity = false;
 //               elsenum=0;
 //        }
        }
        if ((elsenum==1) && (ssn==1)) {
         if (document.order_form.ssnverification.checked) {
           if (social()) {
                q += '-  SSN Format is invalid.\n';
                validity = false;
           }
         }
        }
       // END ONLY IF NOT PACKAGE
        if (!check_empty(document.order_form.applicant_dob.value))
                {
                q += '-  Date of Birth is required.\n';
                validity = false;
                }
        if (document.order_form.email.value!=document.order_form.confemail.value)
                {
                q += '-  Email Addresses Do Not Match.\n';
                validity = false;
                }

        else if ( !checkEmail( document.order_form.email.value ))
               {
                q += '-  Email is not a valid email address.\n';
                document.order_form.delivery_email.value="";
                validity = false;
               }
        else
                {
                document.order_form.delivery_email.value=document.order_form.email.value;
                }
        
        if ( !check_street_address( document.order_form.applicant_address_street.value )) {
                q += '-  Applicant street is invalid. Only alphanumeric and spaces.\n';
                validity = false;
        }
if ( !check_city_address( document.order_form.applicant_address_city.value )) {
                q += '-  Applicant city is invalid.\n';
                validity = false;
        }
if ( !check_state_address( document.order_form.applicant_address_state.value )) {
                q += '-  Applicant state is invalid.\n';
                validity = false;
        }
if ( !check_zip_address( document.order_form.applicant_address_zip.value )) {
                q += '-  Applicant zip code is invalid.\n';
                validity = false;
        }

        if ( !validity )
                {
                alert(q);
//                if ( gotoitem!=null ) gotoitem.focus();
                return validity;
                }
        return validity;
        }

var button_on=true;


function submitStateForm() {
   var pack=0;
 if ( validate_form(pack) ) {
  if (oneCrimStateSearch()) {
     if (checkAppForm()) {
        button_on = false;
        document.order_form.submit();
     }
  }
 }
}

function submitForm() {
   var pack=0;
   var woapp=0;

   if (button_on == true) {
      if  (isValidObject(document.order_form.PACKAGE_ID)) {
           pack=1;
      }
      if  (isValidObject(document.order_form.applicant_id)) {
           woapp=1;
      }
      if (woapp==1) {
          if (oneSearch()) {
             if (checkAppForm()) {
               button_on = false;
               document.order_form.submit();
             }
          }
      } else if ( validate_form(pack) )
         {
         if (pack==0){
             if (oneSearch()) {
               button_on = false;
               document.order_form.submit();
               }
         }
        else {
               button_on = false;
               document.order_form.submit();
        }
      }
   }
}



function check_empty(text) {
  return (text.length > 0); // returns false if empty
}

function check_email(address) {
  if ((address == "")
    || (address.indexOf ('@') == -1)
    || (address.indexOf ('.') == -1))
      return false;
  return true;
}


function check_street_address(street) {
	if ((street=="") ||
		(street.length==0) ||
		(street.match(/[\<\>!@\$%^&\*]+/i))) {
			return false;
		}
 return true;	
}

function check_city_address(city) {
	if ((city=="") ||
		(city.length==0) ||
		(city.match(/[\<\>!@#\$%^&\*,]+/i))) {
			return false;
		}
 return true;		
}

function check_state_address(state) {
	if ((state=="") ||
		(state.length!=2)) {
			return false;
		}
 return true;	
}
function check_zip_address(zip) {
	if ((zip=="") ||
		(zip.length!=5) ||
		(!zip.match(/^[0-9]+$/)) ||
		(zip=="00000")||
		(zip=="99999")) { return false;}
		return true;
}
<!-- Begin
function toForm() {
document.order_form.applicant_fname.focus();
}
//  End -->