$(document).ready(function() {
reason = $(document).getUrlParam("reason");  
//alert(reason);
showfields(reason);
        $("input[name*='reason']").click(function() {
	
            reason = $(this).val();
	    //console.log(reason)
           // $('#Message').html(reason);
	   //we know what the reason for contact is.
	//we must change the company field name, and swap the appropriate fields.

	showfields(reason);
	
});

    
    });
    
    
function showfields(reason){
	if (reason == 'press') {
	$('#comments_label').html("Comments/Request");
	
	  $('#company_name').html("Publication");
	
	$('#offstage #deadline-newsletter').swap('form #deadline-newsletter-Placeholder');
	$('form #deadline-newsletter').fadeIn('slow').css("font-weight",  "bold");
	$('#offstage #address-fields').swap('form #address-fields-Placeholder');


	  $('form #address-fields').fadeOut();
	  
	  
	  $('#offstage #address-fields-Placeholder').swap('form #address-fields');
	  $('#offstage #account-reports-Placeholder').swap('form #account-reports');
	 $('form #account-reports').fadeOut(); 
	 
	 $('form #safety-interest').fadeOut();
	 $('#offstage #safety-interest-Placeholder').swap('form #safety-interest');
	 
	  
	  $('#state_p').fadeIn('slow'); 
	  $('#job_title').hide(); 
	  //console.log('really ought to be hiding the job_title here');
		
	}else if (reason == 'loss_runs') {
	$('#comments_label').html("Comments/Request");
	  $('#company_name').html("Agency/Company Name");
	 $('#offstage #address-fields').swap('form #address-fields-Placeholder');
	 $('#offstage #account-reports').swap('form #account-reports-Placeholder');
	 $('form #address-fields').fadeIn('slow');
	 $('form #account-reports').fadeIn('slow');
	 $('#state_p').fadeOut(); 
	  $('#job_title').fadeIn('slow'); 
	  
	  
	 $('form #safety-interest').fadeOut();
	 $('#offstage #safety-interest-Placeholder').swap('form #safety-interest');
	
	$('form #deadline-newsletter').fadeOut();
	$('#offstage #deadline-newsletter-Placeholder').swap('form #deadline-newsletter');
	
	  
	}else if (reason == 'safety') {
	  $('#comments_label').html("Comments/Other Safety Materials Request");
	  $('#company_name').html("Company Name");
	 $('#offstage #address-fields').swap('form #address-fields-Placeholder');
	 $('form #account-reports').fadeOut('slow');
	 $('#offstage #account-reports-Placeholder').swap('form #account-reports');
	 $('form #address-fields').fadeIn('slow');
	 
	 $('#offstage #safety-interest').swap('form #safety-interest-Placeholder');
	 $('form #safety-interest').fadeIn('slow');
	 
	 
	 
	 
	  $('#state_p').hide(); 
	  $('#job_title').fadeIn('slow'); 
	  
	  	$('form #deadline-newsletter').fadeOut('slow');
	$('#offstage #deadline-newsletter-Placeholder').swap('form #deadline-newsletter');
	
	}else if (reason == 'brochures') {
	$('#company_name').html("Company Name");
	  $('#comments_label').html("List brochures and quantities requested");
	 $('#offstage #address-fields').swap('form #address-fields-Placeholder');
	 $('form #account-reports').fadeOut('slow');
	 $('#offstage #account-reports-Placeholder').swap('form #account-reports');
	 $('form #address-fields').fadeIn('slow');
	 
	  
	 $('form #safety-interest').fadeOut();
	 $('#offstage #safety-interest-Placeholder').swap('form #safety-interest');
	 
	 
	 
	  $('#state_p').hide(); 
	  $('#job_title').fadeIn('slow'); 
	  
	  	$('form #deadline-newsletter').fadeOut('slow');
	$('#offstage #deadline-newsletter-Placeholder').swap('form #deadline-newsletter');
	}else{
	$('#comments_label').html("Comments/Request");
	if (reason == 'bill') {
	$('#comments_label').html("Question");
	}
	  $('#company_name').html("Company Name");
	  //$('#offstage #pressPlaceholder').swap('form #press');
	  $('form #address-fields').fadeOut('slow');
	  $('#offstage #address-fields-Placeholder').swap('form #address-fields');
	  $('#offstage #account-reports-Placeholder').swap('form #account-reports');
	  $('form #address-fields').fadeOut('slow');
	  
	  
	 $('form #safety-interest').fadeOut();
	 $('#offstage #safety-interest-Placeholder').swap('form #safety-interest');
	  
	  $('#state_p').hide(); 
	  $('#job_title').fadeIn('slow'); 
	  
  	$('form #deadline-newsletter').fadeOut('slow');
	$('#offstage #deadline-newsletter-Placeholder').swap('form #deadline-newsletter');
	}
}
	

    
    
jQuery.fn.swap = function(b){
try{
   b = jQuery(b)[0];
   var a = this[0];
   var t = a.parentNode.insertBefore(document.createTextNode(''), a);
   b.parentNode.insertBefore(a, b);
   t.parentNode.insertBefore(b, t);
   t.parentNode.removeChild(t);
   return this;
   }
   catch(err){
   //don't fail if there is nothing to swap with
   }
};