jQuery(window).load(function() {
  
  function resizeWindow() {
    $('div#wrapper').css('height', $(window).height() - 40);
    $('div#right').css('margin-top', ($(window).height() - $('div#right').height())/2 );
    $('div#left').css('margin-top', ($(window).height() - $('div#left').height())/2 - 58);
  }
  
  $(window).resize(function() {
    resizeWindow();
  });

    resizeWindow();

    
  $('.over').mouseover(function() {
     $(this).data('original_src', $(this).attr('src'));
     if ($(this).attr('src').indexOf('off') > 0) {
       $(this).attr('src', $(this).attr('src').replace('off','on'));
     }
  }).mouseout(function() {
    $(this).attr('src', $(this).data('original_src'));
  });
  
  $('img#reset').click(function() {
    $('div.error_message').stop();
    $('div.error_message').fadeOut();
    $('#name').val('');
    $('#email').val('');
    $('#phone').val('');
    $('#address').val('');
    $('#city').val('');
    $('#state').val('');
    $('#zip').val('');
    $('#comment').val('');
    $('#size').val('');
    $('#price').val('');
    $('#how').val('');
    
  })
  
  
  $('img#send').click(function() {
    if ($('#name').val() == '' || $('#email').val() == '' ) {
      $('div.error_message').stop();
      $('div.error_message').fadeIn(250, function() {
        $(this).animate({opacity: 1}, 5000, function() {
          $(this).fadeOut();
        })
      });
    }
    else if (validateEmail($('#email').val()) == false) {
      $('div.error_message').stop();
      $('div.error_message').fadeIn(250, function() {
        $(this).animate({opacity: 1}, 5000, function() {
          $(this).fadeOut();
        })
      });
    }
    else {
      $('form').submit();
    }
    
  }) 
  
  //checkboxes
  $('#broker_represented').click(function() {
    if ($(this).attr('checked') == true) { //checked
      $('#is_broker').attr('checked', false);
      $('#broker_represented_text').show();
      $('#is_broker_text').hide();
      $('#broker_represented_text').focus();
      $('#broker_represented_text').select();
      $('div.broker_represented_instructions').show();
      $('div.is_broker_instructions').hide();
    }
    else { //unchecked
      $('#broker_represented_text').hide();
      $('#is_broker_text').hide();
      $('div.broker_represented_instructions').hide();
      $('div.is_broker_instructions').hide();
    }
  }) 
  
  $('#is_broker').click(function() {
    if ($(this).attr('checked') == true) { //checked
      $('#broker_represented').attr('checked', false);
      $('#broker_represented_text').hide();
      $('#is_broker_text').show();
      $('#is_broker_text').focus();
      $('#is_broker_text').select();
      $('div.broker_represented_instructions').hide();
      $('div.is_broker_instructions').show();
    }
    else { //unchecked
      $('#broker_represented_text').hide();
      $('#is_broker_text').hide();
      $('div.broker_represented_instructions').hide();
      $('div.is_broker_instructions').hide();
    }
  });
  
  if ($('#broker_represented').attr('checked') == true) { //checked
    $('#is_broker').attr('checked', false);
    $('#broker_represented_text').show();
    $('#is_broker_text').hide();
    $('div.broker_represented_instructions').show();
    $('div.is_broker_instructions').hide();
  }
  
  if ($('#is_broker').attr('checked') == true) { //checked
    $('#broker_represented').attr('checked', false);
    $('#broker_represented_text').hide();
    $('#is_broker_text').show();
    $('div.broker_represented_instructions').hide();
    $('div.is_broker_instructions').show();
  }


  
    
  // contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
  function validateEmail(value) {
			return  /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(value);  
  }

});

