window.onload = function () {
  dhtmlHistory.initialize();
  dhtmlHistory.addListener(historyChange);
        	      	
  jobvana_page = new states();
	jobvana_page.build();
  
  conn_popup = new conn_icon();
  
}


function states() {
	
  if (typeof states._initialized == "undefined") {
    
  	states.prototype.build = function () {   
  	
  	  dash_loader = new jobvana();
      dash_loader.build();
     
      if (document.getElementById("chooser_list")) {
       // service_loader = new service_chooser();
       // service_loader.dynamic = false;  //turn off ajax loading
       // service_loader.build();
        //set functions that need to be processed by history
       // dash_loader.set_history_functions(service_loader);
      }
      
  	  if (document.getElementById("search_go_button")) {
        YAHOO.util.Event.addListener("search_go_button", "click", this.process_search, this, true);
      }
  	}
	
  	states.prototype.process_search = function() {
		  if (document.getElementById("search_term").value.length > 0) {
        var search_url = "/search?";   
        
        search_url = search_url+"searchterm="+ document.getElementById("search_term").value+"&";
        
        if (document.getElementById("country_id")) {
          search_url = search_url+"country_id="+document.getElementById("country_id").value+"&";
        }
        if (document.getElementById("state_id")) {
          search_url = search_url+"state_id="+document.getElementById("state_id").value+"&";
        }
        if (document.getElementById("city_id")) {
          search_url = search_url+"city_id="+document.getElementById("city_id").value+"&";
        }
    
        if (document.getElementById("gen_cat_id")) {
          search_url = search_url+"gen_cat_id="+document.getElementById("gen_cat_id").value+"&";
        }
        if (document.getElementById("ser_cat_id")) {
          search_url = search_url+"ser_cat_id="+document.getElementById("ser_cat_id").value+"&";
        }
        if (document.getElementById("sub_cat_id")) {
          search_url = search_url+"sub_cat_id="+document.getElementById("sub_cat_id").value+"&";
        }
        
        location.href = search_url;
		  
		  } else {    
		   this.error_tip = new YAHOO.widget.Overlay("error_tip", {context:["search_term","tl","bl"], visible:false, width:"220px", zIndex:1500 });
       this.error_tip.setBody("<div class='error_message'>Please enter a search term.</div>"); 
       this.error_tip.render(document.body); 
       this.error_tip.show();
       YAHOO.util.Event.addListener("search_term", "keypress", this.hide_error, this, true);
       YAHOO.util.Event.addListener("search_term", "blur", this.hide_error, this, true);
     }
    }
    
     states.prototype.hide_error = function () {
       YAHOO.util.Event.removeListener("search_term", "keypress", this.hide_error);
       YAHOO.util.Event.removeListener("search_term", "blur", this.hide_error);
       this.error_tip.hide();
     }
    
     states.prototype.change_state = function () {
      if (document.getElementById("category_url")){
        dash_loader.passed_in_url_vars = "&category_url="+document.getElementById("category_url").value;
      }
      dash_loader.load_dash('locations','stateselect');
    }

	  states._initialized = true;
  } 
}