var jobSearch; function jobSearchLoad(){ var current = window.onload; window.onload = function(){ current(); jobSearch = new JobSearch(); } } function JobSearch (){ } JobSearch.prototype.uniqueArrayVals = function (myarray) { var r = new Array(); o:for(var i = 0, n = myarray.length; i < n; i++) { for(var x = 0, y = r.length; x < y; x++) { if(r[x]==myarray[i]) { continue o; } } r[r.length] = myarray[i]; } return r; } JobSearch.prototype.functions = ""; JobSearch.prototype.industries = ""; JobSearch.prototype.countries = ""; JobSearch.prototype.regions = ""; JobSearch.prototype.locations = ""; JobSearch.prototype.submit = function(id){ var form = document.getElementById(id); this.countries = this.cleanVar(this.countries); //--form.appendChild(this.hiddenElement('functions', this.functions)); form.appendChild(this.hiddenElement('industries', this.industries)); form.appendChild(this.hiddenElement('countries', this.countries)); form.appendChild(this.hiddenElement('regions', this.regions)); form.appendChild(this.hiddenElement('locations', this.locations)); form.submit(); } JobSearch.prototype.hiddenElement = function(id, value){ var input = document.createElement('input'); input.id = id; input.name = id; input.type = 'hidden'; input.value = value.substring(0, (value.length - 1)); return input; } JobSearch.prototype.cleanVar = function(stringvar){ var stringvar = stringvar.split(','); stringvar = this.uniqueArrayVals(stringvar); return stringvar.join(','); } JobSearch.prototype.jfunction = function (e){ if(e.checked){ this.check(e, "functions", "jf"); this.functions = this.functions + e.id.replace("cb_jf","") + ","; } else if(!e.checked){ this.uncheck(e.id, "functions", "jf"); this.functions = this.functions.replace(e.id.replace("cb_jf","")+",", ""); } } JobSearch.prototype.industry = function (e){ if(e.checked){ this.check(e, "industries", "in"); this.industries = this.industries + e.id.replace("cb_in","") + ","; } else if(!e.checked){ this.uncheck(e.id, "industries", "in"); this.industries = this.industries.replace(e.id.replace("cb_in","")+",", ""); } } JobSearch.prototype.check = function (e, selected, prefix){ selection = '' +'-'+e.title+'
'; document.getElementById('selected_'+selected).innerHTML = document.getElementById('selected_'+selected).innerHTML + selection; } JobSearch.prototype.uncheck = function (id, selected, prefix){ selection = document.getElementById("sp_"+id); if(document.getElementById(id)) document.getElementById(id).checked = false; if(selected == "industries") this.industries = this.industries.replace(id.replace("cb_in","")+",", ""); document.getElementById('selected_'+selected).removeChild(selection); } JobSearch.prototype.suggestFunction = function (string){ this.suggest("list_functions", "tbl=tb_job_function&pk=job_function_id&def=description&type=jf&val="+string+"&oc=jfunction&cur="+this.functions); } JobSearch.prototype.suggestIndustry = function (string){ this.suggest("list_industries", "tbl=tb_industry&pk=industry_id&def=description&type=in&val="+string+"&oc=industry&cur="+this.industries); } JobSearch.prototype.suggest = function (element, query){ var inlineAjax = new InlineAjax(); inlineAjax.requestObject.onreadystatechange = function(){ if(inlineAjax.requestObject.readyState == 4){ document.getElementById(element).innerHTML = inlineAjax.requestObject.responseText; }} url = "/packages/Search/includes/checkbox_suggest.php?" + query; inlineAjax.requestObject.open("GET",url,true); inlineAjax.requestObject.send(null); } JobSearch.prototype.country = function (element){ this.countries = this.cleanVar(this.countries); if(element.checked){ this.countries = this.countries + element.value + ","; //this.countries = this.countries + element.id.replace("cb_co","") + ","; }else if(!element.checked){ this.countries = this.countries.replace(""+element.value+",", ""); } this.regionLookup(); } JobSearch.prototype.region = function (element){ if(element.checked){ this.regions = element.value; } else if(!element.checked){ this.regions = this.regions.replace(""+element.id.value+",", ""); } this.locationLookup(); } JobSearch.prototype.locale = function (element){ if(element.checked){ this.locations = this.locations + element.id.replace("cb_lc","") + ","; } else if(!element.checked){ this.locations = this.locations.replace(""+element.id.replace("cb_lc","")+",", ""); } } JobSearch.prototype.regionLookup = function (){ this.countries = this.cleanVar(this.countries); var JSO = this; var inlineAjax = new InlineAjax(); inlineAjax.requestObject.onreadystatechange = function(){ if(inlineAjax.requestObject.readyState == 4){ JSO.regions = ""; document.getElementById("list_regions").innerHTML = inlineAjax.requestObject.responseText; var region_list = document.getElementById("list_regions").getElementsByTagName("input"); for(key in region_list){ if(region_list[key].checked){ JSO.region(region_list[key]); }}; if(JSO.regions.length == ""){ JSO.locationLookup(); } } } query = "tbl=tb_region&pk=region_id&dis=description&type=rg&def=country_id&vals="+this.countries+"&oc=region&cur="+this.regions; url = "/packages/Search/includes/checkbox_lookup.php?" + query; inlineAjax.requestObject.open("GET",url,true); inlineAjax.requestObject.send(null); } JobSearch.prototype.locationLookup = function (){ var JSO = this; var inlineAjax = new InlineAjax(); inlineAjax.requestObject.onreadystatechange = function(){ if(inlineAjax.requestObject.readyState == 4){ JSO.locations = ""; document.getElementById("list_locations").innerHTML = inlineAjax.requestObject.responseText; var location_list = document.getElementById("list_locations").getElementsByTagName("input"); for(key in location_list){ if(location_list[key].checked){ JSO.locale(location_list[key]); }}; } } query = "tbl=tb_location&pk=location_id&dis=description&type=lc&def=region_id&vals="+this.regions+"&oc=locale&cur="+this.locations; url = "/packages/Search/includes/checkbox_lookup.php?" + query; inlineAjax.requestObject.open("GET",url,true); inlineAjax.requestObject.send(null); } JobSearch.prototype.suggestCountry = function (string){ this.countries = this.cleanVar(this.countries); this.suggest("list_countries", "tbl=tb_country&pk=country_id&def=description&type=co&val="+string+"&oc=country&cur="+this.countries); } JobSearch.prototype.suggestRegion = function (string){ this.countries = this.cleanVar(this.countries); this.suggest("list_regions", "tbl=tb_region&pk=region_id&def=description&type=rg&val="+string+"&oc=region&cur="+this.regions+"&chk=country_id"+"&vals="+this.countries); } JobSearch.prototype.suggestLocation = function (string){ this.suggest("list_locations", "tbl=tb_location&pk=location_id&def=description&type=lc&val="+string+"&oc=locale&cur="+this.locations+"&chk=region_id"+"&vals="+this.regions); } JobSearch.prototype.locationSuggest = function (element, query){ var inlineAjax = new InlineAjax(); inlineAjax.requestObject.onreadystatechange = function(){ if(inlineAjax.requestObject.readyState == 4){ document.getElementById(element).innerHTML = inlineAjax.requestObject.responseText; }} url = "/packages/Search/includes/location_suggest.php?" + query; inlineAjax.requestObject.open("GET",url,true); inlineAjax.requestObject.send(null); }