$j(document).ready(function($) {
  
  // set global defaults for UI dialogs
  $.extend($.ui.dialog.prototype.options, {
    autoOpen: false,
    modal: true,
    resizable: false,
    draggable: false,    
    width: 580,
    closeOnEscape: false,
    show: { effect: 'fade', duration: 1000 },
    hide: { effect: 'fade', duration: 1000 },  
    position: 'center',
    open: function(event, ui){
      $(".ui-dialog-titlebar-close").hide(); // hide dialog close X 
      $(this).parent(".ui-dialog").find(":focus").blur(); // un-focus "OK" button
    }   
  });
  
  
  $.ajaxSetup({
   
    // process ajax return string
    dataFilter: function(data, type) {
      return data.replace('while(1);', '');
    },
    
    // global ajax error handler
    error: function(jqXHR, exception) {
      if (jqXHR.status === 0) {
         // window.location.replace('/public/15.cfm?jqXHR=0');
          //alert('Not connect.\n Verify Network.');
      } else if (jqXHR.status == 404) {
          window.location.replace('/notfound.cfm?jqXHR=404');
          //alert('Requested page not found. [404]');
      } else if (jqXHR.status == 403) {
        window.location.replace('/public/23.cfm?jqXHR=403');
        //alert('Forbidden [403].');
      } else if (jqXHR.status == 500) {
          window.location.replace('/public/15.cfm?jqXHR=500');
          //alert('Internal Server Error [500].');
      } else if (exception === 'parsererror') {
          window.location.replace('/public/15.cfm?jqXHR=parsererror');
          //alert('Requested JSON parse failed.');
      } else if (exception === 'timeout') {
          window.location.replace('/public/15.cfm?jqXHR=timeout');
          //alert('Time out error.');
      } else if (exception === 'abort') {
          window.location.replace('/public/15.cfm?jqXHR=abort');
          //alert('Ajax request aborted.');
      } else {
          window.location.replace('/public/15.cfm?jqXHR=uncaught');
          //alert('Uncaught Error.\n' + jqXHR.responseText);
      }
    }
       
  });
  
  // initialize custom tipped skin
  jQuery.extend(Tipped.Skins, {
    'goxCustom' : {
      border: { size: 4, color: '#363636' },
      background: '#5f5f5f',
      radius: { size: 6, position: 'border' },
      shadow: false,    
      hook: { target: 'righttop', tooltip: 'leftbottom' },
      maxWidth: 230      
    }
  });  
  
  // initialize tipped  
  Tipped.create(".create-tooltip", {
    skin: 'goxCustom'
  });
  
  // set cb init's
  if ($j("#tos").length > 0) {
    $j("#tos").colorbox();
  }
  
  if ($j("#privacy").length > 0) {
    $j("#privacy").colorbox();
  }  
  
  if ($j("a.goxBox").length > 0) {
    $j("a.goxBox").colorbox();
  }
  
  // apply form field highlighting on focus
  if ($j(".highlightme").length > 0) {
    $j(".highlightme").highlightinput();
  }
  
  // set buttons to jq style
  if ($j(".jqButton").length > 0) {
    $j( "input:submit, input:button, button", ".jqButton" ).button();
  }
  
  if ($j(".callsearch").length > 0) {
    $j( "input:submit, input:button, button", ".jqButton" ).button();
  }  
  
  if ($j(".SearchContainer").length > 0) {
    $j( "input:submit" ).button();
  }    

  if ($j(".dlSearchContainer").length > 0) {
    $j( "input:submit", ".dlSearchContainer" ).button();
  }  
  
  // set fileinfo display page download button to jq style
  if ($j(".dnow").length > 0) {
    $j( "button", ".dnow" ).button();
  }
  
  // set fileinfo terms page download button to jq style
  if ($j(".fileTerms").length > 0) {
    $j( "input:submit", ".fileTerms" ).button();
  }   
  
  // set fileinfo download page download button to jq style
  if ($j(".fileDownload").length > 0) {
    $j( "button", ".fileDownload" ).button();
  }   

  // utilising fadeToggle to show/hide .content DIV in search depts
  if ($j("#searchAdv").length > 0) {
    $j("#searchAdv").click(function(){
      $j(".searchToggle").fadeToggle();
    });
  }; 
  
  if ($j(".loadShipping").length > 0) {
    // hide 'Is Shipping same as Billing' table on page load
    $('.loadShipping div').hide();
    
    // show/hide Shipping table based upon Select
    $("#shippingLoad").change(function(){
      var value = $(this).val();
      var theDiv = $(".billing" + value);
      $(theDiv).fadeIn('slow');
      $(".loadShipping div[class!=billing" + value + "]").fadeOut('slow');
      $(theDiv).siblings("#showShippingNo").css("display", "block");
    });
  };
  
  // bottom tabs for home page
  $(function($) {
    $( "#tabs" ).tabs();
    $( ".tabs-bottom .ui-tabs-nav, .tabs-bottom .ui-tabs-nav > *" )
      .removeClass( "ui-corner-all ui-corner-top" )
      .addClass( "ui-corner-bottom" );
  });  
  
  // clear out blockui plugin default styling 
  //$.blockUI.defaults.css = {};   
  
  // blockui default message
  $.blockUI.defaults.message = "<h1>just a moment...</h1>";
  $.blockUI.defaults.css.backgroundColor = '#000'; 
  $.blockUI.defaults.css.border = 'none'; 
  $.blockUI.defaults.css.color = 'white'; 
  $.blockUI.defaults.css.opacity = 0.5; 
  $.blockUI.defaults.css.padding = '15px'; 
  
});
  
// apply form field highlighting on focus
(function($) {
  $.fn.highlightinput = function() {
    var elm = this;
    return this.each(function(index, element) {
      $(element).focusin(function() {
        $(this).addClass("ui-state-highlight");
      });
      $(element).focusout(function() {
        $(this).removeClass("ui-state-highlight");
      });
    });
  };
})(jQuery);

function reset_html(id) {
  $j('#'+id).html($j('#'+id).html());
};
