function submitRequestForQuote(thisForm) {
  displayError(null);
  if( validateRequiredFields(thisForm) ) {
    var allInputs = getInputValues(thisForm);
  
    jQuery.ajax({
      data: allInputs.join('&'),
      url: thisForm.action,
      type: "POST",
      error: function(request,error) {displayError("An error occurred while sending request.  Please try again later.");},
      success: function(data) {
        jQuery("#requestFormDivId").html(data);
	    setTimeout('closeModalWindow()', 5000);
      }
    });
  }
   
  return false;
}

function validateRequiredFields(thisForm) {
  var sendForm = true;
  jQuery("#requiredInputs", thisForm).each( function() {
	if( $(this).val() == '' ) {
	  sendForm = false;
	  displayError("Invalid value for: " + this.name + ".  Please try again.");
	  return false;
	}
  });
  
  return sendForm;
}

function getInputValues(thisForm) {
  var allInputs = [];
  allInputs.push("rand="+getRandom());
  jQuery(':input', thisForm).each(function() {
	if (this.name != '') {
      if( this.type == 'checkbox' || this.type == 'radio' ) {
        if( this.checked ) {
          allInputs.push(this.name + '=' + encodeURIComponent(this.value));
        }
      }
      else if( this.type == 'select-multiple' ) {
        var name = this.name;
        jQuery('option:selected', this).each( function() {
          if( this.selected == true ) {
            allInputs.push(name + '=' + encodeURIComponent(this.value));
          }
        });
      }
      else {
        allInputs.push(this.name + '=' + encodeURIComponent(this.value));
      }
	}
  });
  
  return allInputs;
}

function getRandom() {
  return new Date().getTime();
}

function closeModalWindow() {
	jQuery("#TB_closeWindowButton").click();
}

function displayError(message) {
  if( message ) {
    jQuery("#errorDivId").html(message).fadeIn("slow");
  }
  else {
	jQuery("#errorDivId").html("").hide();
  }
}