/*******************************************************************/
/*  validate Request a free sample Form -                                                */
/*******************************************************************/
function valRequest()
{  
//    alert  ("in vaRequest!") ;

    if (document.getElementById("_db_rq_type").value == "Contact") {
        if ( document.forms[0]._db_rq_toWhom.selectedIndex  == 0 ) {
            alert ("Please tell us who you want to contact!") ;
            document.forms[0]._db_rq_toWhom.focus() ;
            return false ;
        }
    }

    
    document.getElementById("_db_rq_company").value = trim(document.getElementById("_db_rq_company").value) ;
    if ( document.getElementById("_db_rq_company").value.length  == 0 ) {
       alert ("Company is required!") ;
       document.getElementById("_db_rq_company").focus() ;
       return false ;
    }
    
    document.getElementById("_db_rq_firstName").value = trim(document.getElementById("_db_rq_firstName").value) ;
    if ( document.getElementById("_db_rq_firstName").value.length  == 0 ) {
       alert ("First Name is required!") ;
       document.getElementById("_db_rq_firstName").focus() ;
       return false ;
    }
    
    document.getElementById("_db_rq_lastName").value = trim(document.getElementById("_db_rq_lastName").value) ;
    if ( document.getElementById("_db_rq_lastName").value.length  == 0 ) {
       alert ("Last Name is required!") ;
       document.getElementById("_db_rq_lastName").focus() ;
       return false ;
    }

    document.getElementById("_db_rq_address1").value = trim(document.getElementById("_db_rq_address1").value) ;
    if ( document.getElementById("_db_rq_address1").value.length  == 0 ) {
       alert ("Address is required!") ;
       document.getElementById("_db_rq_address1").focus() ;
       return false ;
    }
    
    document.getElementById("_db_rq_city").value = trim(document.getElementById("_db_rq_city").value) ;
    if ( document.getElementById("_db_rq_city").value.length  == 0 ) {
       alert ("City is required!") ;
       document.getElementById("_db_rq_city").focus() ;
       return false ;
    }
/*    
    if ( document.forms[0]._db_aud_state.selectedIndex  == 0 ) {
       alert ("Please select a State!") ;
       document.forms[0]._db_aud_state.focus() ;
       return false ;
    }    
*/    
    document.getElementById("_db_rq_zip").value = trim(document.getElementById("_db_rq_zip").value) ;
    if ( document.getElementById("_db_rq_zip").value.length  < 5 ) {
       alert ("Zip Code is invalid or blank!") ;
       document.getElementById("_db_rq_zip").focus() ;
       return false ;
    }
    
    

    document.getElementById("_db_rq_email").value = trim(document.getElementById("_db_rq_email").value) ;
    if ( document.getElementById("_db_rq_email").value.length  == 0 ) {
       alert ("Email Adress is required!") ;
       document.getElementById("_db_rq_email").focus() ;
       return false ;
    }
    
    document.getElementById("_db_rq_telephone").value = trim(document.getElementById("_db_rq_telephone").value) ;
    if ( document.getElementById("_db_rq_telephone").value.length  == 0 ) {
       alert ("Telophone Number is required!") ;
       document.getElementById("_db_rq_telephone").focus() ;
       return false ;
    }
    
    if (document.getElementById("_db_rq_type").value == "Contact") {
        document.getElementById("_db_rq_message").value = trim(document.getElementById("_db_rq_message").value) ;
        if ( document.getElementById("_db_rq_message").value.length  == 0 ) {
            alert ("What message do you want to send!") ;
            document.getElementById("_db_rq_message").focus() ;
            return false ;
        }   
    }
    
   return true ;
}

/*******************************************************************/
/*  validate Quote a free sample Form -                                                */
/*******************************************************************/
function valQuote()
{  
    if ( document.forms[0]._db_quo_idProduct.selectedIndex  == 0 ) {
            alert ("Please tell us what product you wish a quote for!") ;
            document.forms[0]._db_quo_product.focus() ;
            return false ;
    }
    
    if ( document.forms[0]._db_quo_idContainers.selectedIndex  == 0 ) {
            alert ("Please select a container size for this product!") ;
            document.forms[0]._db_quo_idContainers.focus() ;
            return false ;
    }
       
    document.getElementById("_db_quo_quantity").value = trim(document.getElementById("_db_quo_quantity").value) ;
    
    if ( document.getElementById("_db_quo_quantity").value.length  == 0 ) {
       alert ("Quantity is blank!") ;
       document.getElementById("_db_quo_quantity").focus() ;
       return false ;
    }
    
   if ( isNaN(document.getElementById("_db_quo_quantity").value)) {
       alert ("Quantity is not numeric!") ;
       document.getElementById("_db_quo_quantity").focus() ;
       return false ;
   }
     var x = Number(document.getElementById("minQty").value) ;
     var y = Number(document.getElementById("_db_quo_quantity").value) ;
     

    if ( y < x ) {
       alert ("Quantity requested, " + y +", is below minimum quantity for this container size, " + x + "!") ;
       document.getElementById("_db_quo_quantity").focus() ;
       return false ;
   }
     
    document.getElementById("_db_quo_company").value = trim(document.getElementById("_db_quo_company").value) ;
    if ( document.getElementById("_db_quo_company").value.length  == 0 ) {
       alert ("Company is required!") ;
       document.getElementById("_db_quo_company").focus() ;
       return false ;
    }
    
    document.getElementById("_db_quo_firstName").value = trim(document.getElementById("_db_quo_firstName").value) ;
    if ( document.getElementById("_db_quo_firstName").value.length  == 0 ) {
       alert ("First Name is required!") ;
       document.getElementById("_db_quo_firstName").focus() ;
       return false ;
    }
    
    document.getElementById("_db_quo_lastName").value = trim(document.getElementById("_db_quo_lastName").value) ;
    if ( document.getElementById("_db_quo_lastName").value.length  == 0 ) {
       alert ("Last Name is required!") ;
       document.getElementById("_db_quo_lastName").focus() ;
       return false ;
    }

    document.getElementById("_db_quo_address1").value = trim(document.getElementById("_db_quo_address1").value) ;
    if ( document.getElementById("_db_quo_address1").value.length  == 0 ) {
       alert ("Address is required!") ;
       document.getElementById("_db_quo_address1").focus() ;
       return false ;
    }
    
    document.getElementById("_db_quo_city").value = trim(document.getElementById("_db_quo_city").value) ;
    if ( document.getElementById("_db_quo_city").value.length  == 0 ) {
       alert ("City is required!") ;
       document.getElementById("_db_quo_city").focus() ;
       return false ;
    }
/*    
    if ( document.forms[0]._db_aud_state.selectedIndex  == 0 ) {
       alert ("Please select a State!") ;
       document.forms[0]._db_aud_state.focus() ;
       return false ;
    }    
*/    
    document.getElementById("_db_quo_zip").value = trim(document.getElementById("_db_quo_zip").value) ;
    if ( document.getElementById("_db_quo_zip").value.length  < 5 ) {
       alert ("Zip Code is invalid or blank!") ;
       document.getElementById("_db_quo_zip").focus() ;
       return false ;
    }
    
    

    document.getElementById("_db_quo_email").value = trim(document.getElementById("_db_quo_email").value) ;
    if ( document.getElementById("_db_quo_email").value.length  == 0 ) {
       alert ("Email Adress is required!") ;
       document.getElementById("_db_quo_email").focus() ;
       return false ;
    }
    
    document.getElementById("_db_quo_telephone").value = trim(document.getElementById("_db_quo_telephone").value) ;
    if ( document.getElementById("_db_quo_telephone").value.length  == 0 ) {
       alert ("Telophone Number is required!") ;
       document.getElementById("_db_quo_telephone").focus() ;
       return false ;
    }
    
    document.getElementById("_db_quo_idContainers").disabled = false ;
    
   return true ;
}


/*******************************************************************/
/*  trim - trims a string                                          */
/*******************************************************************/
function trim(StrIn)
{
    var z = -1 ;
    for (i = 0 ; i < StrIn.length ; i++) {
      if (StrIn.substr(i,1) != " ") {
        z = i ;
        break ;
      }
    }
    

    if (z == -1) {
     StrIn = "" ;
    }else {
      StrIn = StrIn.substr(z) ;
      z = 0 ;
      for (i = StrIn.length - 1 ; i > 0 ; i--) {
        if (StrIn.substr(i,1) != " ") {
          z = i ;
          break ;
        }
      }
    }
    StrIn = StrIn.substr(0,z+1) ;
    
    return StrIn ;
}

