jQuery(document).ready(function() {
   // hide comment list
  jQuery('#hide_installer_comment').click(function() {
  	jQuery('#installer_comment').hide(400);
    });
  // toggles the slickbox on clicking the noted link
  jQuery('#show_installer_comment').click(function() {
  	jQuery('#installer_comment').show(400);
    });

  var button;

  /*jQuery('form').submit(function() {
    button = jQuery(this).find('input[type=submit]');
    button.attr('disabled', true);
    this.submit();
  });*/
	
	jQuery('.disable_on_click').bind('click', function(){
		
		jQuery(this).before('<input type="hidden" name="' + jQuery(this).attr('name') + '" value="post" />');
		
		jQuery(this).attr('disabled', true);
		
		jQuery(this).parents('form').submit();
	});
	
	
	jQuery('#campaign').bind('change', function(event, undefined) {
		var val = jQuery(this).val();
		var limit_months = jQuery("#campaign option:selected").attr('rel');
		
		if (limit_months !== undefined) {
			jQuery('#sub_cycle').attr('value', limit_months);
			jQuery('#sub_cycle').attr('disabled', 'disabled');
			jQuery('#sub_cycle').removeAttr('name');
			jQuery('#sub_cycle_hidden').attr('value', limit_months);
			jQuery('#sub_cycle_hidden').attr('name', 'company[cycle]');
		}
		else {
			jQuery('#sub_cycle').removeAttr('disabled');
			jQuery('#sub_cycle').attr('name', 'company[cycle]');
			jQuery('#sub_cycle_hidden').removeAttr('name');
		}
	});

	jQuery('#edit_campaign').bind('change', function(event, undefined) {
		var val = jQuery(this).val();
		var limit_months = jQuery("#edit_campaign option:selected").attr('rel');
		
		if (limit_months !== undefined) {
			jQuery('#edit_month').attr('value', limit_months);
			jQuery('#edit_month').attr('disabled', 'disabled');
			jQuery('#edit_month_hidden').attr('value', limit_months);
		}
		else {
			jQuery('#edit_month').removeAttr('disabled');
		}
	});
	
});
