var last_type = 'all';
var last_categories = '';

/* ----------------------------------- */
function jobsByType(type) {

	last_type = type;
	display('jobs', 'none');
	display('loading', 'block');

	if ($('filter_'+type).className != 'active') { className = 'active'; } else { className = ''; }
	changeClass('filter_all', '');
	changeClass('filter_job', '');
	changeClass('filter_gig', '');
	changeClass('filter_tmp', '');
	changeClass('filter_'+type, className);

	showList();
	
}
/* ----------------------------------- */
function toggleCategory(category) {
	display('jobs', 'none');
	display('loading', 'block');
	
	if ($('category_'+category).className != 'off') { className = 'off'; } else { className = ''; }
	changeClass('category_'+category, className);
	
	categories = '0-';
	for (var i=0; i<all_categories.length; i++) {
		if ($('category_'+all_categories[i]).className != 'off') {
			categories += all_categories[i] + '-';
		}
	}
	last_categories = categories;

	self.setTimeout("showList();", 750);
}

/* ----------------------------------- */
function gencode() {
	code_aff = $('code_aff').value;
	if (code_aff=='') {
		alert('Please enter your affiliate ID');
		$('code_aff').focus();
		return;
	}
	code_target = $('code_target').value;
	if (code_target!='') { code_target = '/'+code_target; }

	code_type = $('code_type').value;
	code_no = $('code_no').value;
	
	$('codegen').value = '<!-- start FatFreeJobs listings -->\n<script src="'+site_url+'feeds/js/'+code_type+'/'+code_aff+'/'+code_no+code_target+'" type="text/javascript" charset="utf-8"></script>\n<!-- end FatFreeJobs listings -->';
}

/* ----------------------------------- */
function lost_pass(pp_txn) {
	if (pp_txn == '') {
		alert('Please enter your Order ID and click this link again to generate your new password.');
	} else {
		new Ajax.Request(site_url_rel+'jobs/lost_pass/'+pp_txn, { onComplete:function(t) { alert(t.responseText) }});
	}
}

/* ----------------------------------- */
function showList() {
	new Ajax.Updater('jobs', site_url_rel+'jobs/show_list/'+last_type+'/'+last_categories, { onComplete:function(request) {
		display('jobs', 'block');
		display('loading', 'none');
	}});
}

/* ----------------------------------- */
/*         General Functions           */
/* ----------------------------------- */
function countChar(element, hint_element) {
	obj = document.getElementById(element);
	var mlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : '';

	text = obj.value;
	
	if (obj.getAttribute && obj.value.length>mlength) {
		obj.value = obj.value.substring(0, mlength);
	} else {
		document.getElementById(hint_element).innerHTML = (mlength-text.length);
	}
}
/* ----------------------------------- */

function flash(timeout) {
	if (!timeout) { timeout = 5000; }
	self.setTimeout("Effect.Fade('flash')", timeout);
}
function flashIT() {
	Effect.Fade('flash');
}
function re_flash() {
	Effect.BlindDown('flash');
	flash();	
}
/* ----------------------------------- */
function rusure(msg, url) {
	if (confirm(msg)) location.href = url;
}
/* ----------------------------------- */
function toggle(element, style) {
	if ($(element).style.display != 'none') style = 'none';
	alert(style);
	display(element, style);
}

/* ----------------------------------- */
function display(element, style) {
	eval("$('" + element + "').style.display = style;");	
}

/* ----------------------------------- */
function changeClass(element, className) {
	eval("$('" + element + "').className = className;");	
}

/* ----------------------------------- */
function markFormField(element) {
	if ($(element)) $(element).style.background = '#D2E4B8';
}

/* ----------------------------------- */
function clearFormMark(element) {
	if ($(element)) $(element).style.background = 'transparent';
}

/* ----------------------------------- */
function change_city(id) {
	if (!id=="") {
		document.location.href = '/jobs/city_switch/'+id;
	}
}
