function toggle_search_filter(filter_name)
{
	if ($('div#'+filter_name).hasClass('filter_title_enabled'))
	{
		//disable the filter
		$('div#'+filter_name).removeClass('filter_title_enabled');
		$('div#'+filter_name).addClass('filter_title_disabled');
		$('div#'+filter_name+'_contents').removeClass('filter_contents_enabled');
		$('div#'+filter_name+'_contents').addClass('filter_contents_disabled');
	}
	else if ($('div#'+filter_name).hasClass('filter_title_disabled'))
	{
		//enable the filter
		$('div#'+filter_name).removeClass('filter_title_disabled');
		$('div#'+filter_name).addClass('filter_title_enabled');
		$('div#'+filter_name+'_contents').removeClass('filter_contents_disabled');
		$('div#'+filter_name+'_contents').addClass('filter_contents_enabled');
	}
}


function expand_more_filters(filter_name)
{
	$('div#'+filter_name+'_contents div.extra_filter_entry').css('display', 'block');
	$('div#'+filter_name+'_contents div.filter_more_link').css('display', 'none');
}


function toggle_url_field()
{
	if ($('select#manage_applicants').val()==376)
	{
		$('div#post_single_job_apply_url').css('display', 'none');
	}
	else
	{
		$('div#post_single_job_apply_url').css('display', 'block');
	}
}


function gather_sort_ids(experience_selector, education_selector, experience_form_field, education_form_field)
{
	$(experience_form_field).val('');
	$(experience_selector).each(function() 
	{
		if ($(experience_form_field).val()!='')
		{
			$(experience_form_field).val($(experience_form_field).val()+'-'+$(this).val());
		}
		else
		{
			$(experience_form_field).val($(this).val());
		}
	});

	$(education_form_field).val('');	
	$(education_selector).each(function() 
	{
		if ($(education_form_field).val()!='')
		{
			$(education_form_field).val($(education_form_field).val()+'-'+$(this).val());
		}
		else
		{
			$(education_form_field).val($(this).val());
		}
	});
}


function process_fb_popup()
{
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++)
	{
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	if (vars['page']=='register_seeker' && vars['action']=='import_profile' && vars['is_popup']=='1')
	{
		window.opener.location.href = window.location.href.replace("&is_popup=1", "");
	}
	window.close();
}


function is_profile_subsection_enabled(subform_container, entries_table, display_control_field, main_button)
{
	/*if($(entries_table).length==0)
	{
		//the subsection doesn't have entries, display its subform
		$(subform_container).css('display', 'block');
		$(main_button).css('display', 'none');
	}
	else
	{*/
		//the subsection has entries but still may need to be displayed
		if ($(display_control_field).val()==1)
		{
			//user is working with the subsection, display it
			$(subform_container).css('display', 'block');
			$(main_button).css('display', 'none');
		}
		else 
		{
			//hide the subsection
			$(subform_container).css('display', 'none');
			$(main_button).css('display', 'block');
		}
	//}
}


function map_date_to_wj_id1(date_str, alt)
{
	data = new Array();
	data[360] = 'Present'; data[361] = 'January'; data[362] = 'February'; data[363] = 'March'; data[364] = 'April'; data[365] = 'May';
	data[366] = 'June'; data[367] = 'July'; data[368] = 'August'; data[369] = 'September'; data[370] = 'October'; data[371] = 'November'; data[372] = 'December';

	if (alt)
	{
		return data[date_str];
	}
	else
	{
		return data.indexOf(date_str);
	}
}


function map_date_to_wj_id2(date_str, alt)
{
	data = new Array();
	data[37] = 'January'; data[38] = 'February'; data[39] = 'March'; data[40] = 'April'; data[41] = 'May'; data[42] = 'June'; 
	data[43] = 'July'; data[44] = 'August'; data[45] = 'September'; data[46] = 'October'; data[47] = 'November'; data[48] = 'December';
	
	if (alt)
	{
		return data[date_str];
	}
	else
	{
		return data.indexOf(date_str);
	}
}


function wj_toggle_search_tabs(enable_t, disable_t)
{
	$('div.search_results_left_tab_subtab_'+enable_t).removeClass('search_results_subtab_disabled');			
	$('div.search_results_left_tab_subtab_'+disable_t).addClass('search_results_subtab_disabled');
	$('div.search_results_left_tab_'+enable_t).css('display', 'block');			
	$('div.search_results_left_tab_'+disable_t).css('display', 'none');			
}


function wj_toggle_q_type(enable_q)
{
	//first disable all q types
	$('div.q_yn_box').addClass('q_type_disabled');
	$('div.q_yn_box').removeClass('q_type_enabled');
	$('div.q_sdrop_box').addClass('q_type_disabled');
	$('div.q_sdrop_box').removeClass('q_type_enabled');
	$('div.q_mdrop_box').addClass('q_type_disabled');
	$('div.q_mdrop_box').removeClass('q_type_enabled');
	
	//enable now
	$('div.q_'+enable_q+'_box').addClass('q_type_enabled');
	$('div.q_'+enable_q+'_box').removeClass('q_type_disabled');
}


function q_do_delete_answer(target)
{
	target = $(target).parent().parent().parent().parent();
	section_target = target.parent();
	target.remove();
	$("div.q_score_s_answers_left", section_target).css("visibility", "hidden");
	$("div.q_score_sdrop_left", section_target).css("visibility", "hidden");
	$("div.q_score_s_answers_left:first", section_target).css("visibility", "visible");
	$("div.q_score_sdrop_left:first", section_target).css("visibility", "visible");
}


function q_do_add_answer(target, section)
{
	target = $(target).parent().parent().parent();
	new_html = '<div class="q_sdrop_section">'+section.html()+'</div>';
	new_html = $(new_html);
	$("input", new_html).val("");
	$("option:selected", new_html).removeAttr("selected");	
	target.before(new_html);
	$("div.q_score_s_answers_left", target.parent()).css("visibility", "hidden");
	$("div.q_score_sdrop_left", target.parent()).css("visibility", "hidden");
	$("div.q_score_s_answers_left:first", target.parent()).css("visibility", "visible");
	$("div.q_score_sdrop_left:first", target.parent()).css("visibility", "visible");
	//section.insertBefore(target);
}


function q_do_add_answer2(target, section)
{
	target = $(target).parent().parent().parent();
	new_html = '<div class="q_mdrop_section">'+section.html()+'</div>';
	new_html = $(new_html);
	$("input", new_html).val("");
	$("option:selected", new_html).removeAttr("selected");	
	target.before(new_html);
	$("div.q_score_s_answers_left", target.parent()).css("visibility", "hidden");
	$("div.q_score_sdrop_left", target.parent()).css("visibility", "hidden");
	$("div.q_score_s_answers_left:first", target.parent()).css("visibility", "visible");
	$("div.q_score_sdrop_left:first", target.parent()).css("visibility", "visible");
	//section.insertBefore(target);
}

function post_job_questionnaire_click()
{
	if ($('input#questionnaire_open').val()=='1')
	{
		$("h1.post_single_job_questionnaire_h1").addClass('open_questionnaire_section');
		$("div#post_single_job_questionnaire_box").addClass('open_questionnaire_section');
	}
	else
	{
		$("h1.post_single_job_questionnaire_h1").removeClass('open_questionnaire_section');
		$("div#post_single_job_questionnaire_box").removeClass('open_questionnaire_section');
	}
}

function do_add_question_button()
{
	if ($('input#add_question_open').val()=='1')
	{
		$("div#q_main_add_box").addClass('open_add_question_section');
	}
	else
	{
		$("div#q_main_add_box").removeClass('open_add_question_section');
	}
}

function form_section_do_show(what) 
{
	$('div.register_seeker2_div_'+what).css('display', 'block');
	$('div.register_seeker2_div_'+what+'_errors').css('display', 'block');
	$('div.add_'+what+'_main_button').css('display', 'none');
	$('input#display_'+what).val('1');
}

function htmlspecialchars_decode (string, quote_style) {
    var optTemp = 0,
        i = 0,
        noquotes = false;
    if (typeof quote_style === 'undefined') {
        quote_style = 2;
    }
    string = string.toString().replace(/&lt;/g, '<').replace(/&gt;/g, '>');
    var OPTS = {
        'ENT_NOQUOTES': 0,
        'ENT_HTML_QUOTE_SINGLE': 1,
        'ENT_HTML_QUOTE_DOUBLE': 2,
        'ENT_COMPAT': 2,
        'ENT_QUOTES': 3,
        'ENT_IGNORE': 4
    };
    if (quote_style === 0) {
        noquotes = true;
    }
    if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
        quote_style = [].concat(quote_style);
        for (i = 0; i < quote_style.length; i++) {
            // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
            if (OPTS[quote_style[i]] === 0) {
                noquotes = true;
            } else if (OPTS[quote_style[i]]) {
                optTemp = optTemp | OPTS[quote_style[i]];
            }
        }
        quote_style = optTemp;
    }
    if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
        string = string.replace(/&#0*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
        // string = string.replace(/&apos;|&#x0*27;/g, "'"); // This would also be useful here, but not a part of PHP
    }
    if (!noquotes) {
        string = string.replace(/&quot;/g, '"');
    }
    // Put this in last place to avoid escape being double-decoded
    string = string.replace(/&amp;/g, '&');

    return string;
}


function bind_edit_seeker_keyboard_submits()
{
	$("form input[type=text]").bind('keypress', function(e){
	   if ( e.keyCode == 13 ) {
	       $(this).closest("div.register_seeker2_profile_div").find("div.save_section_button_submit input.save_section_button").click();
	       return false;
	   }
	});
}


