
  
  var timeout_for_closing_quick_form_div;
  
  // function that refresh an image upon the image id :)
  // here is used only for the captcha image, but can be used anywhere :)
  function refresh_image( image_id ) {
    
    var image_src = $( '#' + image_id ).attr( 'src' );
    if( image_src != null ) {
      var pos = image_src.indexOf( '?' );
      if( pos >= 0 ) {
        image_src = image_src.substr( 0, pos );
      }
      var date = new Date();
      image_src = image_src + '/' + date.getTime();
      $( '#' + image_id ).attr( 'src', image_src );
      
      $('.search_narrow_r').val( '' );
    }
  }
  
  function toggle_quick_form() {
    
    var form_div_wrapper_width = $('.quick_form_div_wrapper').css('width');
    if( form_div_wrapper_width == '85px' ) {
      $('.quick_form_div').css( 'display', 'block' );
      $('.quick_form_div_wrapper').animate( { width: '406px', 'min-height': '540px' }, 300 );
    } else if( form_div_wrapper_width == '406px' ) {
      quick_form_close();
    }
  }
  
  function quick_form_close() {
    $("#quick_form_name").val("");
    $("#quick_form_phone").val("");
    $("#quick_form_email").val("");
    $("#quick_form_zip").val("");
    $("#quick_form_message").val("");
    $("#quick_form_captcha").val("");
    $(".quick_form_field_error").remove();
    $('.quick_form_div_wrapper').animate( { width: '85px', 'min-height': '184px' }, 300 );
    timeout_for_closing_quick_form_div = setTimeout( "$('.quick_form_div').css( 'display', 'none' );", 300 );
  }
  
  function hide_quick_form_div() {
    $('.quick_form_div').css( 'display', 'none' );
    clearTimeout( timeout_for_closing_quick_form_div );
  }
  
  function the_quick_form_submit() {
    
    $.post(
      fullpath + $("#quick_form").attr("action"),
      {
        quick_form_name: $("#quick_form_name").val(),
        quick_form_phone: $("#quick_form_phone").val(),
        quick_form_email: $("#quick_form_email").val(),
        quick_form_zip: $("#quick_form_zip").val(),
        quick_form_message: $("#quick_form_message").val(),
        quick_form_captcha: $("#quick_form_captcha").val(),
        quick_form_submit: $("#quick_form_submit").val(),
        is_ajax_request: 1
      },
      function( data ) {
        $("#quick_form_div").html( data );
        if( data.indexOf( 'quick_field_success_message' ) > -1 ) {
          $('.quick_form_div_wrapper').css( 'width', '720px' );
          $('.quick_form_div').css( 'width', 'auto' );
        }
        refresh_image( "captcha_image" );
      }
    );
  } 

