function isValidPhone( element, label, isRequired )
{
  testValue = element.value.replace(/[^\-\d]+/g, '' );

  if( element.value.match(/[^\-\d]/) )
  {
    alert( label + " only accepts Numbers and Dashes.  Please enter a value." );
    element.value = testValue;
    element.focus();
    return false;
  }
  element.value = testValue;
  testValue = testValue.replace( /\D+/g, '' );

  /* If element is a required field, check if nothing was entered.  If it isn't required, then return true; */
  if( testValue.length == 0 )
  {
    if( isRequired == true )
    {
      alert( label + " is a required field.  Please Retry." );
      element.focus();
      return false;
    }

    return true;
  }

  /* Test for String Less Than 10 Digits */
  if( testValue.length < 10 )
  {
    alert( label + " must be at least 10 Digits Long.  Please Re-Enter." );
    element.focus();
    return false;
  }

  /* Test for String Greater Than 20 Digits */
  if( testValue.length > 20 )
  {
    alert( label + " cannot be more than 20 Digits.  Please Re-Enter." );
    element.focus();
    return false;
  }

  /* If Processing Reached here, then the field is Valid so return TRUE */
  return true;
}

function hasBannedPatterns( form )
{
  var re_banned_patterns = /(http:\/\/www|http:\/\/|http|www\.|\/\/)/gi;

  // List of Elements to exclude from Validating
  var excludedFields = {
    'referer_url':'referer_url', 'redirect':'redirect'
  };

  // Check to see if other Excluded Elements were passed into the function
  if( arguments.length > 1 )
  {
    excluded_elements = arguments[1];
    type = typeof(excluded_elements);
    if( type.toLowerCase() == 'string' )
      excludedFields[ excludedFields ] = excluded_elements;
    else
    {
      for( exc_index=0; exc_index < excluded_elements.length; exc_index++ )
      {
        excludedFields[ excludedFields ] = excluded_elements[exc_index];
      }
    }
  }

  for( index = 0; index < form.elements.length; index++ )
  {
    element = form.elements[index];  

    if( excludedFields[element.name] ) continue;

    if( element.value.match( re_banned_patterns ) )
    {
      alert(element.name + " Contains Banned Patterns.\n\nPlease don't include URL components (eg: http://www.example.com).\n\n" + element.name + " will now be Reset.");
      element.value = '';
      element.focus();
      return true;
      break;
    }
  }

  return false;
}

function FormValidate(theForm)
{
  if( hasBannedPatterns(theForm) ) return false;
 
  if (theForm.name.value == "")
  {
    alert("Please enter a value for the \"Name\" field.");
    theForm.name.focus();
    return (false);
  }

  if (theForm.name.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"Name\" field.");
    theForm.name.focus();
    return (false);
  }

  if (theForm.contacttelephone.value == "")
  {
    alert("Please enter a value for your Contact Telephone Number.");
    theForm.contacttelephone.focus();
    return (false);
  }
  
  if (theForm.contactemail.value == "")
  {
    alert("Please enter a value for your Contact Email Address.");
    theForm.contactemail.focus();
    return (false);
  }
  
  if (theForm.deliverylocation.value == "")
  {
    alert("Please enter a value for your Delivery Location and Zip Code.");
    theForm.deliverylocation.focus();
    return (false);
  }  
  
  if (theForm.producttypes.value == "")
  {
    alert("Please enter a value for Product Types (ie: tile, cork, laminate, vinyl, carpet).");
    theForm.producttypes.focus();
    return (false);
  }

  if (theForm.finish.value == "")
  {
    alert("Please enter a value for your Finish type.");
    theForm.finish.focus();
    return (false);
  }

  if (theForm.edge.value == "")
  {
    alert("Please enter a value for your Edge type.");
    theForm.edge.focus();
    return (false);
  }
  
  if (theForm.width.value == "")
  {
    alert("Please enter a value for your Width.");
    theForm.width.focus();
    return (false);
  }


  if (theForm.thickness.value == "")
  {
    alert("Please enter a value for your Thickness.");
    theForm.thickness.focus();
    return (false);
  }

  if (theForm.length.value == "")
  {
    alert("Please enter a value for your Length.");
    theForm.length.focus();
    return (false);
  }

  if (theForm.quantity.value == "")
  {
    alert("Please enter a value for your Quantity (SqFt).");
    theForm.quantity.focus();
    return (false);
  }


  if (theForm.timeframe.value == "")
  {
    alert("Please enter a value for your Project time frame.");
    theForm.timeframe.focus();
    return (false);
  }
  
  if (theForm.targetprice.value == "")
  {
    alert("Please enter a value for your Target Price.");
    theForm.targetprice.focus();
    return (false);
  }  
  
  if (theForm.message.value == "")
  {
    alert("Please enter a value for your message.");
    theForm.message.focus();
    return (false);
  }  
  
  if (theForm.copyproofdelivery.value == "")
  {
    alert("Please enter a value for your Copy of Proof of Delivery.");
    theForm.copyproofdelivery.focus();
    return (false);
  }  
  
boolValidPhone = isValidPhone( theForm.phone, "txtPhone", true );
  if ( !boolValidPhone ) 
  return (false);
  
  return (true);
}
