function str_replace(search, replace, subject) {
    return subject.split(search).join(replace);
}
system = "";

function resetForm() {
	document.getElementById('job_career_level').selectedIndex = -1;
	document.getElementById('job_contract_type').selectedIndex = -1;
	document.getElementById('job_educational_level').selectedIndex = -1;
	document.getElementById('job_occ_field').selectedIndex = -1;
	document.getElementById('job_occ_field_group').selectedIndex = -1;
	document.getElementById('job_city').selectedIndex = -1;
	document.getElementById('job_region').selectedIndex = -1;
	document.getElementById('company_id').selectedIndex = -1;
	document.getElementById('job_country').selectedIndex = -1;
	document.getElementById('job_experience').selectedIndex = -1;
	document.getElementById('job_sector').selectedIndex = -1;
	if (document.getElementById('search_ext'))
		document.getElementById('search_ext').value = ''
}

var options = {
    script:system+"search.php?",
    varname:"input",
    json:false,
    shownoresults:false,
    maxresults:6,
    callback: function (obj) {
		job_id = obj.job_id;
		job_usage_sites = obj.job_usage_sites;
		job_career_level = obj.job_career_level;
		job_contract_type = obj.job_contract_type;
		job_region = obj.job_region;
		job_educational_level = obj.job_educational_level;
		job_occ_field = obj.job_occ_field;
		job_occ_field_group = obj.job_occ_field_group;
		company_id = obj.company_id;
		
		document.getElementById("is_live").value='true';
		document.getElementById('job_id').value=job_id;
		
		for (i = 0; i<document.getElementById('job_city').length; i++) {
		    value = document.getElementById('job_city').options[i].value;
			if (value==job_usage_sites)
				document.getElementById('job_city').selectedIndex = i;
		}
		for (i = 0; i<document.getElementById('job_career_level').length; i++) {
		    value = document.getElementById('job_career_level').options[i].value;
			if (value==job_career_level)
				document.getElementById('job_career_level').selectedIndex = i;
		}
		for (i = 0; i<document.getElementById('job_contract_type').length; i++) {
		    value = document.getElementById('job_contract_type').options[i].value;
			if (value==job_contract_type)
				document.getElementById('job_contract_type').selectedIndex = i;
		}
		for (i = 0; i<document.getElementById('job_region').length; i++) {
		    value = document.getElementById('job_region').options[i].value;
			if (value==job_region) {
				document.getElementById('job_region').selectedIndex = i;
			}
		}
		for (i = 0; i<document.getElementById('job_educational_level').length; i++) {
		    value = document.getElementById('job_educational_level').options[i].value;
			if (value==job_educational_level)
				document.getElementById('job_educational_level').selectedIndex = i;
		}
		for (i = 0; i<document.getElementById('job_occ_field').length; i++) {
		    value = document.getElementById('job_occ_field').options[i].value;
			if (value==job_occ_field)
				document.getElementById('job_occ_field').selectedIndex = i;
		}
		for (i = 0; i<document.getElementById('job_occ_field_group').length; i++) {
		    value = document.getElementById('job_occ_field_group').options[i].value;
			if (value==job_occ_field_group)
				document.getElementById('job_occ_field_group').selectedIndex = i;
		}
		for (i = 0; i<document.getElementById('company_id').length; i++) {
		    value = document.getElementById('company_id').options[i].value;
			if (value==company_id)
				document.getElementById('company_id').selectedIndex = i;
		}
		
		if (document.getElementById("search_form")) { /* Normale Suche */
			document.getElementById('search_form').action = '/suche';			
			document.getElementById("search_form").submit();
		}
		else if (document.getElementById("search_form2")) {  /* Erweiterte Suche */
			document.getElementById('search_form2').action = '/suche';
			document.getElementById("search_form2").submit();
		}
	}
};
var options2 = {
	script:system+"search.php?location=true&",
	varname:"input",
	json:false,
	shownoresults:false,
	maxresults:6,
	callback: function (obj) {		
		job_usage_sites = obj.job_usage_sites;
		job_region = obj.job_region;
				
		document.getElementById("is_live").value='true';			
		
		for (i = 0; i<document.getElementById('job_city').length; i++) {
			value = document.getElementById('job_city').options[i].value;
			if (value==job_usage_sites) {
				document.getElementById('job_city').selectedIndex = i;
			}
		}
		for (i = 0; i<document.getElementById('job_region').length; i++) {
			value = document.getElementById('job_region').options[i].value;
			if (value==job_region) {
				document.getElementById('job_region').selectedIndex = i;
			}
		}
		
		if (document.getElementById("search_form")) { /* Normale Suche */
			document.getElementById('search_form').action = '/suche';
			document.getElementById("search_form").submit();
		}
		else if (document.getElementById("search_form2")) {  /* Erweiterte Suche */
			document.getElementById('search_form2').action = '/suche';
			document.getElementById("search_form2").submit();
		}
	}
};
var as_json1 = new bsn.AutoSuggest('search1', options);
var as_json2 = new bsn.AutoSuggest('search2', options2);
