var $j = jQuery.noConflict();

$j(function(){


  // Ensure that if a button is clicked in the iframe, that the window is scrolled to the top
  $j('#machform_iframe').click(function(){
    window.scrollTo(0,0);
  });
  
  // Hide the country and address 2 fields
  $j('#machform_iframe').load(function(){
    var iframe = $j(this).contents();
    iframe.find('#li_4_div_2, #li_4_div_6').hide();

    // Preload form field values from query string
    $j.each($j.query.get(), function(key, value) {
        var field = iframe.find('#'+key)
        field.val(unescape(value));
    });
  });
  
  // Examine the query string to see if an error occured
  var error = $j.query.get('error');
  if (error) $j('#machform_error').show().text(unescape(error));

});
