 /******************************************************************************
  * 
  * Handles the winnowing of careers on the search results page.
  *
  * 
  * 
  *******************************************************************************/
	
	var career_winnow = {};
	
  career_winnow.second_back= false;
  
  
	career_winnow.toggle_enlisted = function(boo)
	{
		
		if(boo){
			$("#fs-enlisted-officer").show();
    }
    else{
      $("#fs-enlisted-officer").hide()
    }
	}
	
	career_winnow.get_data_string = function(loc)
	{
		
		page = 0;
		term = $("#qs_term").val();
                csMilOnly = core.get_check_box_yes("rdShow");
		csSalary = $("#cs-salary").val();
		csDegree = $("#cs-degree").val();
                csInDemand = core.get_check_box_yes("cs-in-demand");
                csIndustry = $("#cs-industry").val();
                csMajor = $("#cs-major").val();
                csIntData = core.get_check_box_yes("cs-int-data");
                csIntPeople = core.get_check_box_yes("cs-int-people");
                csIntThings = core.get_check_box_yes("cs-int-things");
                csTypeArtistic = core.get_check_box_yes("cs-type-artistic");
                csTypeConventional = core.get_check_box_yes("cs-type-conventional");
                csTypeEnterprising = core.get_check_box_yes("cs-type-enterprising");
                csTypeInvestigative = core.get_check_box_yes("cs-type-investigative");
                csTypeRealistic = core.get_check_box_yes("cs-type-realistic");
                csTypeSocial = core.get_check_box_yes("cs-type-social");
                csFamily = $("#cs-family").val();
                csEnlisted= $("#cs-enlisted").val();
                
		
		d = "term="+term+"&cs-enlisted="+csEnlisted+"&cs-family="+csFamily+"&cs-major="+csMajor+"&cs-mil-only="+csMilOnly+"&page="+page+"&cs-salary="+csSalary+"&cs-degree="+csDegree+"&cs-industry="+csIndustry+"&cs-int-data="+csIntData+"&cs-int-people="+csIntPeople+"&cs-int-things="+csIntThings+"&cs-in-demand="+csInDemand+"&cs-type-artistic="+csTypeArtistic+"&cs-type-enterprising="+csTypeEnterprising+"&cs-type-conventional="+csTypeConventional+"&cs-type-investigative="+csTypeInvestigative+"&cs-type-realistic="+csTypeRealistic+"&cs-type-social="+csTypeSocial;
                
		return d;
	}
	
        career_winnow.run_search = function()
        {
            var d = career_winnow.get_data_string();
		
            core.basic_ajax("/Ajax/careerWinnow", d+"&layout=ajax", "html", "#div-cs-results", "<div class='refresh-message'><img src='/img/ui/l-anim.gif' alt='loading' /><p>Refreshing your career results...</p></div>");
       
            $.address.value(d);
            career_winnow.second_back = true;
        }

/****************************************** ON PAGE LOAD *****************************************/
$(function(){
   
	
	$(".input-winnow").change(function(){
            career_winnow.run_search();
	});
        
  $(".input-winnow-cbox").click(function(){
        career_winnow.run_search();
	});
        
  $("#rdShow").click(function(){
			
      career_winnow.toggle_enlisted($(this).attr('checked'));  
			career_winnow.run_search();
     
	});
        
        
        
         
    $.address.externalChange(function(event) {
          
          var d_ar = new Array;
          var ajax_params = $.address.value();
          var was_reloaded = false;
					var d = "";
          var q = null;
					var mil_boo = false;
         
          if(ajax_params != "/"){
            d = (ajax_params.substring(1, ajax_params.length));
            core.basic_ajax("/Ajax/careerWinnow", d+"&layout=ajax", "html", "#div-cs-results", "<div class='refresh-message'><img src='/img/ui/l-anim.gif' alt='loading' /><p>Refreshing your career results...</p></div>");
            career_winnow.second_back = true;
            was_reloaded = true;
          }else{
            
            if(career_winnow.second_back){
              href_ar = window.location.href.split("?");
              d_ar =(href_ar[1].split("#"));
              d=d_ar[0]
              core.basic_ajax("/Ajax/careerWinnow", d+"&layout=ajax", "html", "#div-cs-results", "<div class='refresh-message'><img src='/img/ui/l-anim.gif' alt='loading' /><p>Refreshing your career results...</p></div>");
              was_reloaded = true;
            } 
          }
          
          //reset winnow forms
          if(was_reloaded)
          {
            d = d.replace(/-/g, "_");
            q = $.parseQuery(d);
            mil_boo = core.reset_checkbox(q.cs_mil_only);
						
            $("#cs-salary").val((!q.cs_salary) ? "xx" : q.cs_salary);
            $("#cs-degree").val((!q.cs_degree) ? "xx" : q.cs_degree);
            $("#cs-industry").val((!q.cs_industry) ? "xx" : q.cs_industry);
						$("#cs-in-demand").attr("checked", core.reset_checkbox(q.cs_in_demand));
						$("#ss-soc").attr("checked", core.reset_checkbox(q.ss_soc));
						$("#ss-hbcu").attr("checked", core.reset_checkbox(q.ss_hbcu));
						$("#ss-tc").attr("checked", core.reset_checkbox(q.ss_tc));
            $("#cs-int-data").attr("checked", core.reset_checkbox(q.cs_int_data));
						$("#cs-int-people").attr("checked", core.reset_checkbox(q.cs_int_people));
						$("#cs-int-things").attr("checked", core.reset_checkbox(q.cs_int_things));
            $("#rdShow").attr("checked", mil_boo);
            $("#cs-type-artistic").attr("checked", core.reset_checkbox(q.cs_type_artistic));
						$("#cs-type-conventional").attr("checked", core.reset_checkbox(q.cs_type_conventional));
						$("#cs-type-enterprising").attr("checked", core.reset_checkbox(q.cs_type_enterprising));
            $("#cs-type-investigative").attr("checked", core.reset_checkbox(q.cs_type_investigative));
						$("#cs-type-realistic").attr("checked", core.reset_checkbox(q.cs_type_realistic));
						$("#cs-type-social").attr("checked", core.reset_checkbox(q.cs_type_social));
						$("#cs-enlisted").val((!q.cs_enlisted) ? "xx" : q.cs_enlisted);
						
						//en or officer
						career_winnow.toggle_enlisted(mil_boo);
            
          }
    });
        
        

});
