/*
  Wrapper Functions
*/
function $(e) {
  try { return document.getElementById(e); } catch( x ) {return null;}
}
function $F(e) {
  try { return document.getElementById(e).value; } catch( x ) {return null;}
}
function $ev(a,b,c,d,e) {
  YAHOO.util.Event.addListener(a,b,c,d,e);
}
function $evR(a,b,c) {
  YAHOO.util.Event.removeListener(a,b,c);
}
function $ac(a,b) {
  YAHOO.util.Dom.addClass(a,b);
}
function $rc(a,b) {
  YAHOO.util.Event.removeClass(a,b);
}
function $LD(dash, tab) {
  dash_loader.load_dash(dash, tab);
}
function $JSON(a) {
  return YAHOO.lang.JSON.parse(a);
} 
function $obj(a) {
  eval("dash_loader.child_obj[dash_loader.current_tab]."+a);
}
function $VARS( str ) {
	dash_loader.passed_in_url_vars = str;
}


/*
*
* Bragadoo Site Object
*
*/
function jobvana(){
//count that refers to the tabs[] array position
this.current_tab = 0;

//width of tab overlay
this.tab_width = "500px";

//children object
this.child_obj = [];

//objects containg the tab/dash overlays
this.tab_links = [];
this.tabs = [];
this.dashs;

//object holder that hold that last good dash and tab that was loaded
this.last_dash = "";
this.last_tab  = "";

this.no_message_cleaning = false;

//original vars used to process an hashless back button
this.original_dash = "ns";
this.original_tab = "ns";
this.original_tab_count = "ns";

//can be swithed off to disable dashboard/tab history recording
this.set_dash_history = true;
this.set_tab_history  = true;

//can be set to force the visible tab
this.visbile_tab = 'na';

this.response_start = '';
this.response_end = '';
  
this.response_e_start = '';
this.response_e_end = '';

//var used to hold any URL vars that need to be passed to a dashboard/panel
this.passed_in_url_vars = "";
this.perm_in_url_vars = "";

//var used to hold any URL vars that need to be passed to a dashboard/panel
this.search_ids = [];

//dynamic add loading arrays
this.ad_ids = [];

//functions that can be passed in an called from the history setup
this.history_functions = [];

//can bet set to true to bypass the loading of a cached panel
this.skip_cache = false;

this.ads_loaded = false;

this.page_change = false;

//post form value can be set here for a post form
this.post_form = null;

this.default_post_code = "Saving...";

//user to redirect tab changes to an href for nono history supporting browsers
this.redirect_href = null;

//this message is displayed to any disabled user who tries to send a message
this.MESSAGING_DISSABLED_MESSAGE = "<br/><p>We have detected suspicious activity on your account.<br>Your message sending has been disabled and our editors are reviewing your messages.<br>If you feel you have received this message in error, please email help@bragadoo.net</p>";  

  if (typeof jobvana._initialized == "undefined") {
    
    
    /**
		*
		* Initial Dash and Paneling build
		*
		*/
		jobvana.prototype.build = function () { 
 
		  //setup the login/signup form
		  if ($("ls_pop")) $ev("ls_pop", "click", this.show_signup_pop, this);
		  
		  //setup the search box
		  var search = new search_obj();
      search.build();

		  //setup the left menu links
		  if ($("lenu")){
  		  this.left_divs  = $("lenu").getElementsByTagName("div");
        var left_links = $("lenu").getElementsByTagName("a");
        $ev(left_links, "click", this.menu_click, this); 
		  }    
		  
		  //get the logged in user UID
		  if ($F("jobvana_uid") != "NA"){
		    this.jobvana_uid = $F("jobvana_uid"); 
		    //show a recent popup signup the welcome email.
  		  var popcookie = getCookie("popup_signup");
  		  if (popcookie == "three"){
  		    YAHOO.util.Get.script(
    				add_js_file("/www/js/signup_popup.js"), {
    					onSuccess: function() {
    					  signup_popup_form = new signup_popup();
    					  signup_popup_form.create_recent_signup();
    				  }, scope:this
    				}
  		    );
          deleteCookie('popup_signup'); 
        } 
		  } else {
		    this.jobvana_uid = "NA";
		  }
		  
		  this.ajax  = new ajaxtester(); this.ajax.test();
		  this.popup = new dialog(); this.popup.build();
			this.tooltip = new tooltip();
			this.tooltip.build();
			this.checker = new checker();
	    
			
			var signup_pop_js_code = getCookie("signup_pop_js_code"); 
		  if (signup_pop_js_code.length > 0){
		     eval(signup_pop_js_code)
		     deleteCookie('signup_pop_js_code'); 
	    } 
 

			//only start the dash panel system if it finds the tabs div
			if ($("dash_module")) {
        if (location.hash){
          this.passed_in_url_vars =  historyStorage.hold_history_historyData.history_url_vars;
          this.perm_in_url_vars =  historyStorage.hold_history_historyData.history_perm_url_vars;
          original_Hash = dhtmlHistory.getCurrentLocation();
          original_Hash = original_Hash.split("/");
          this.visbile_tab = original_Hash[2];
          this.get_dash_content(original_Hash[1], original_Hash[2]);        
          historyStorage.hold_history_newLocation = "";
          historyStorage.hold_history_historyData = "";
        }else{
          this.start();          
        }
      }
		}

		
		/*
    *
    * Process a menu click
    *
    */
    jobvana.prototype.menu_click = function (e, obj) {
      for(i=0; i < obj.left_divs.length; i++) obj.left_divs[i].className = "lenu_1";
      this.parentNode.className = "sel";
      var parts = this.id.split("_");
      $LD(parts[0],parts[1]);
    }
    
    
		/**
		*
		* Start processing the loaded dash/tabs
		*
		*/
		jobvana.prototype.start = function () {  
 
		  //destory an old child object if loader has been started
		  if (typeof(this.child_obj[this.current_tab]) != "undefined" && this.child_obj[this.current_tab] != null){
		    this.child_obj[this.current_tab] = null;
		  }
		  
		  if ($("tabs")){
        try {
       	  this.tab_links = $("tabs").getElementsByTagName("a");
       	  $ev(this.tab_links, "click", this.tab_click, this); 
      	}
      	catch( x ) {
      	  this.load_dash('error','jserror');
      	  return; //break out
      	}   
    	}   
    	
      eval($F("dash_text"));

      this.animate_tab();
		}
	
		
		/**
		*
		* Setup a dashboard overlay
		* string dash
		*
		*/
		jobvana.prototype.setup_dash = function (dash) {
	    this.dashs = new YAHOO.widget.Module(dash, { /*zIndex: 3000,*/ visible: false/*, width:this.tab_width*/});
      this.dashs.render();
      this.dashs.show();
      if (this.original_dash == "ns") this.original_dash = dash;
		}
		
		
		/**
		*
		* Setup a tab overlay
		* int count, string tab, bool vis
		*
		*/
		jobvana.prototype.setup_tab = function (count, tab, vis) {
		  //console.log(count+" | "+tab+" | "+vis);
		  this.tabs[tab] = new YAHOO.widget.Module(tab, { /*zIndex: 4000,*/ visible: false/*, width:this.tab_width*/});
      
      if (vis) {
        if (this.original_tab == "ns") this.original_tab = tab;
        //if (this.original_tab_count == "ns") this.original_tab_count = count;
        this.current_tab = tab; //set tab count for the first time
        this.loadChildObject();
        this.tabs[tab].setBody(""); //clear body object on initial visible tab otherwise yui dupes the body
      }

      //set the count number for changing tabs
      this.tabs[tab].tab_count = count; 
      //this.tabs[tab].render(); 
      
      if (vis) {  
        //console.log("show: "+tab);
        this.tabs[tab].show();
      } 
		}
		
		
		/**
		*
		* Change the visible tab within a dashboard
		* event e, class_object obj
		*
		*/
		jobvana.prototype.tab_click = function (e, obj) {
		  obj.redirect_href = this.href;
		  tab = this.id.replace(/tab_/,"");
		  obj.change_tab(tab);
		}
		jobvana.prototype.changePanel = function (tab) {   
      this.change_tab(tab);
		}
		jobvana.prototype.change_tab = function (tab) {
		  if (dhtmlHistory.isSupported){
  		  if (tab != this.current_tab) {   
  		    if(typeof(this.tabs[tab]) != "undefined") {
      		  //turn off tab
      		  if (elem = $("l_"+this.current_tab)) elem.className = 'g_tab'; 	
      			   			
      			//run childs unload function
      			if(typeof(this.child_obj[this.current_tab]) != "undefined"){ 
              if (this.child_obj[this.current_tab].un_load) { 
                this.child_obj[this.current_tab].un_load();
              }
      			}  
              
      			//hide tab content and get new content
      		  if(typeof(this.tabs[this.current_tab]) != "undefined") this.tabs[this.current_tab].hide();
      		          
      		  if ($("loading"))	$("loading").innerHTML = '<img src="/www/images/ajax-loader-48.gif" border="0" class="m10" alt="Loading..." />';
      		       
      		  clearTimeout(this.post_message_timout);   
            clearTimeout(this.post_message_timout1);
           
            this.clear_postholder();  
      	       		  
            //destroy and postmessage_objs
      		  try {postmessage_obj.close_overlay(); postmessage_obj = null;} catch(x) {} 
          	
      		  this.current_tab = tab; //reset tab count if a tab has been changed
      		 
      		  this.tab_history();
      		  
      		  if (this.skip_cache == true){
      		    this.get_tab_content(this.current_tab);
      		    this.skip_cache = false; //reset to false to re-enable caching
      		  }else{
        		  if (this.tabs[this.current_tab].body != null){ 
        		    this.loadChildObject();  
          			this.animate_tab();
        		  }else{
        		    this.get_tab_content(this.current_tab);
        		  }
      		  }
      		  
      		  //activate new tab
      		  if (elem = $("l_"+this.current_tab)) elem.className = 'sel';

    			}else {
    			  //throw error
    			  this.passed_in_url_vars = "dasherror="+this.dashs.id+"&panelerror="+tab;
    			  this.load_dash('error','jserror');
  			  }//end if(typeof(this.tabs[tab]) != "undefined") {
  		  }
		  }else{ //no history backup
		    if (this.redirect_href != null){
		      if (this.passed_in_url_vars.length > 0 || this.perm_in_url_vars.length > 0 ){
		        window.location.href = this.redirect_href+"?"+this.passed_in_url_vars+"&"+this.perm_in_url_vars;
		      }else{
		        window.location.href = this.redirect_href;
		      }
		      this.redirect_href == null;
		    }else{
		      window.location.href = "?dash="+this.dashs.id+"&tab="+tab+"&"+this.passed_in_url_vars+"&"+this.perm_in_url_vars;
		    }
		  }
		}
		

		jobvana.prototype.setNoMessageCleaning = function() {
			this.no_message_cleaning = true;
		}
		
		/**
		*
		* RELOAD the CURRENT tab within a dashboard
		*
		*/
		jobvana.prototype.reload_tab = function () {
		  if (dhtmlHistory.isSupported){
		    
		    //create event to run after tab hide
		    var after_hide_func = function (e, z, obj) {		      
					if ( !obj.no_message_cleaning ) {
						clearTimeout(obj.post_message_timout);
						clearTimeout(obj.post_message_timout1);
						 
						obj.clear_postholder();  
					}
					
					//run childs unload function
    			if(typeof(obj.child_obj[obj.current_tab]) != "undefined"){ 
            if (obj.child_obj[obj.current_tab].un_load) { 
              obj.child_obj[obj.current_tab].un_load();
            }
    			}  
      			
					obj.no_message_cleaning = false;
    
    		  obj.tab_history(); 
    		   
    		  //keep track of the page on the current tab
    		  if (!obj.page_change){
      		  if (typeof(obj.child_obj[obj.current_tab]) != "undefined" && obj.child_obj[obj.current_tab] != null){
        		  if (typeof(obj.child_obj[obj.current_tab].current_page) != "undefined" && obj.child_obj[obj.current_tab].current_page != null){
        		    dash_loader.passed_in_url_vars += "&page="+obj.child_obj[obj.current_tab].current_page;
        		  }
      		  }
    		  } else {
    		    obj.page_change = false;
    		  }
    		  
    		  obj.get_tab_content(obj.current_tab);
		      //remove hide event after run
    		  obj.tabs[obj.current_tab].hideEvent.unsubscribe(after_hide_func);
		    }
		    
  			//set event to run after hide
				this.tabs[this.current_tab].hideEvent.subscribe(after_hide_func,this);
        //hide tab content and get new content 
				var is_visible = this.tabs[this.current_tab].cfg.getProperty( "visible" );
				if ( is_visible ) this.tabs[this.current_tab].hide();
				else after_hide_func( null, null, this );
  		  
				if ($("loading"))	$("loading").innerHTML = '<img src="/www/images/ajax-loader-48.gif" border="0" class="m10" alt="Loading..." />';
				 
		  }else{  //no history backup
		    window.location.href = "?dash="+this.dashs.id+"&tab="+this.current_tab+"&"+this.passed_in_url_vars+"&"+this.perm_in_url_vars;
		  }
		}
		
		
		/**
		*
		* Change a page on the CURRENT tab within a dashboard
		*
		*/
		jobvana.prototype.change_page = function(e, obj) {
		  page_num = this.id.replace(/p_/,"");
		  
		  if (typeof(obj.child_obj[obj.current_tab].current_page) != "undefined"){ 
		    obj.child_obj[obj.current_tab].current_page = page_num;
		  }
		  
		  obj.page_change = true;
      dash_loader.passed_in_url_vars = "&page="+page_num;
      dash_loader.reload_tab();
		}
		
		
		/**
		*
		* Sets the history object for a loaded tab. Called in reload_tab and change_tab
		* object history_obj
		*
		*/
		jobvana.prototype.tab_history = function () { 
		  if (dhtmlHistory.isSupported){
  		  var unique_time = new Date().getTime();
  		  if (this.set_tab_history){ 
    		  history_data = new history_obj();
    		  history_data.set_unique_id(unique_time);
    		  history_data.set_dash(this.dashs.id);
          history_data.set_tab(this.current_tab);
          history_data.set_tab_count(this.tabs[this.current_tab].tab_count);  
          history_data.set_history_url_vars(this.passed_in_url_vars); 
          history_data.set_history_perm_url_vars(this.perm_in_url_vars);
          for (var i in this.search_ids) { 
          	history_data.set_search_ids(i, this.search_ids[i]);
          }
           
          this.search_ids = [];
          
          dhtmlHistory.add("/"+this.dashs.id+"/"+this.current_tab+"/"+unique_time, history_data);
        } else {
    		  this.set_tab_history = true; //turn back ON tab history if its off
    		}
		  }
		}
		
		
		/**
		*
		* Process a history hash call from  function historyChange(newLocation, historyData) on page.ild
		* object history_obj
		*
		*/
		jobvana.prototype.process_history = function (history_obj) {
		  if (dhtmlHistory.isSupported){
  		  if (typeof history_obj == "object" && history_obj != null){ //alert('1');
  		    //set passed vars held in the history object
  		    this.passed_in_url_vars = history_obj.history_url_vars;
  		    this.perm_in_url_vars   = history_obj.history_perm_url_vars;
  		    if (this.dashs.id != history_obj.dash){ //alert('2');
  		      this.set_dash_history = false; //turn off dash history for one load_dash
    		    this.load_dash(history_obj.dash, history_obj.tab);
    		  } else if (this.dashs.id == history_obj.dash){ //alert('3');
    		    this.set_tab_history = false; //turn off tab history for one change_tab
    		    if (this.current_tab != history_obj.tab){ //alert('4');
    		      this.change_tab(history_obj.tab);
    		    } else {
    		      this.reload_tab(); //alert('5');
    		    }
    		  } 
  		  } else {
    		  if (this.dashs.id != this.original_dash){ //alert('6');
    		    this.set_dash_history = false; //turn off dash history for one load_dash
  		      this.load_dash(this.original_dash, this.original_tab);
  		    }else if (this.current_tab != this.original_tab){ //alert('7');
  		      this.set_tab_history = false; //turn off tab history for one change_tab
  		      this.change_tab(this.original_tab); 
  		    } else {  //alert('8');
  		      //hashless with no history object (basically the originial tab to show for a url)
    		    this.set_tab_history = false; //turn off tab history for one change_tab
    		    //run a childs reload function to process code before a reload
    		    if (typeof(this.child_obj[this.current_tab]) != "undefined"){
    		      if (this.child_obj[this.current_tab].reload_func) this.child_obj[this.current_tab].reload_func();
    		    }  
    		    this.reload_tab();
  		    }   
    		}
    	  // show the values stored
        for (var i in this.history_functions) {
         	this.history_functions[i].process_history(history_obj);
        }
  		}
		}
		
		
		/**
		*
		* Process a history hash call from  function historyChange(newLocation, historyData) on page.ild
		* object history_obj
		*
		*/
		jobvana.prototype.set_history_functions = function (obj) {
		  this.history_functions[obj.name] = obj;
		}

		/**
		*
		* Send a GET ajax call to the Panel Library to get panel content
		* string tab
		*
		*/
		jobvana.prototype.get_tab_content = function (tab) {
		  if (typeof(this.tab_call) == "undefined") this.tab_call = new send_call(this, "panel");
			this.tab_call.set_call("show_panel");
			var pass_vars = new Array();
			pass_vars["tab"] = tab;
			if ($("user_id")) pass_vars["id"] = $F("user_id");
			this.tab_call.set_url_vars(pass_vars);		
			this.tab_call.urlVars = this.tab_call.urlVars+"&"+this.passed_in_url_vars+"&"+this.perm_in_url_vars;  
      //include child perm urlvars
      try {
			  for (x in this.child_obj[this.current_tab].child_url_vars){
			    this.tab_call.urlVars += "&"+x+"="+this.child_obj[this.current_tab].child_url_vars[x];
			  } 
  	  } catch(x) {}     
			this.passed_in_url_vars = ""; //reset url vars to empty;
			this.tab_call.set_nojax_var('&panelnojax=true');
			this.tab_call.send(this.ajax.ajax_support);
		}
		
		
		/**
		*
		* Change the visible dashboard
		* string dash, string tab
		*
		*/
		jobvana.prototype.load_dash = function (dash, tab) {
		  if (dhtmlHistory.isSupported){	
	    
		    //run childs unload function
		    try {
    			if (this.child_obj[this.current_tab] != null || typeof(this.child_obj[this.current_tab]) != "undefined"){     
            if (this.child_obj[this.current_tab].un_load) { 
              this.child_obj[this.current_tab].un_load();
            }
    			}
  			} catch(x) {}  

  			try {
  			  this.tabs[this.current_tab].hide();
  			  this.dashs.hide();
  			} catch(x) {}     

  			if ($("dash_module"))	$("dash_module").innerHTML = '<img src="/www/images/ajax-loader-48.gif" border="0" class="m10" alt="Loading..." />';
  		
  			//reset current tab count (backup reset in case it isnt reset while changing dash)
  			this.current_tab = tab;
		
  			this.clear_postholder(); 
  
        //destroy and postmessage_objs
      	try {postmessage_obj.close_overlay(); postmessage_obj = null;} catch(x) {}     
   	
  			if (dhtmlHistory.isSupported){
          if (this.set_dash_history){
            var unique_time = new Date().getTime();
            history_data = new history_obj();
            history_data.set_unique_id(unique_time);
      		  history_data.set_dash(dash);
            history_data.set_tab(tab);
            history_data.set_tab_count(0);
            history_data.set_history_url_vars(this.passed_in_url_vars); 
            history_data.set_history_perm_url_vars(this.perm_in_url_vars); 
            dhtmlHistory.add("/"+dash+"/"+tab+"/"+unique_time, history_data)
          } else {
            this.set_dash_history = true; //turn back ON dash history if its off
          }
        }
        
        //get the new dashboard content
        
        this.get_dash_content(dash, tab);
      }else{  //no history backup
        if (this.redirect_href != null){
		      if (this.passed_in_url_vars.length > 0 || this.perm_in_url_vars.length > 0 ){
		        window.location.href = this.redirect_href+"?"+this.passed_in_url_vars+"&"+this.perm_in_url_vars;
		      }else{
		        window.location.href = this.redirect_href;
		      }
		      this.redirect_href == null;
		    }else{
		      window.location.href = "?dash="+dash+"&tab="+tab+"&"+this.passed_in_url_vars+"&"+this.perm_in_url_vars;
		    }
		  }
		}
		
		
		/**
		*
		* Send a GET ajax call to the Dashboard Library to get dshboard content
		* string dash, string tab
		*
		*/
		jobvana.prototype.get_dash_content = function (dash, tab) {
		  if (typeof(this.dash_call) == "undefined") this.dash_call = new send_call(this, "dashboard");
			this.dash_call.set_call("show_dash");
			var pass_vars = new Array();

			pass_vars["dash"] = dash;
			pass_vars["tab"] = tab;
      if ($("user_id")) pass_vars["id"] = $F("user_id");			
			this.dash_call.set_url_vars(pass_vars);	
			this.dash_call.urlVars = this.dash_call.urlVars+"&"+this.passed_in_url_vars+"&"+this.perm_in_url_vars; 
			this.passed_in_url_vars = ""; //reset url vars to empty;
			this.dash_call.set_nojax_var('&dashnojax=true');
			this.dash_call.send(this.ajax.ajax_support);
		}
		

		/**
		*
		* Animate the vertical tab height during dash/tab changes
		*
		*/
		jobvana.prototype.animate_tab = function () { 
		  try {
		    if ($("loading"))	$("loading").innerHTML = '';
        this.tabs[this.current_tab].show(); 
        scroll(0,0);
  		  
         //load ads on first animate
        if (!this.ads_loaded) this.load_ads();
         //run childs after animate function
    		 
		  }catch (x) { }
		}
		

		/**
		*
		* Receives an Ajax or onload based response from the Dashboard/Panel Library 
		* string response_text, string call
		*
		*/
		jobvana.prototype.return_call = function (response_text, call) {
		  switch(call){ 
        case "show_panel": 
          try { m = $JSON(response_text); }
  				catch (x) { 
            $(this.current_tab).innerHTML = "";
      		  this.tabs[this.current_tab].setBody(response_text);
      			this.tabs[this.current_tab].render();
      			this.loadChildObject();  
      			this.animate_tab(); return;
    			}
    			//load error if not kicked out of function in catch
    			this.passed_in_url_vars = "dasherror="+m.dash+"&panelerror="+m.panel;
  				this.load_dash('error','jserror');
        break; 
        case "show_dash": 
          try { m = $JSON(response_text); }
  				catch (x) { 
  				   $("dash_module").innerHTML = response_text;
             this.start(); return;
  				}
  				//load error if not kicked out of function in catch
  				this.passed_in_url_vars = "dasherror="+m.dash+"&panelerror="+m.panel;
  				this.load_dash('error','jserror');
        break; 
		  }
		}
		

		/**
		*
		* Try and load a tab specific JS file and create the child_obj js Object
		*
		*/
  	jobvana.prototype.loadChildObject = function () { 
  	  //load assoicate header with panel in myadmin
  	  if ($("header_title")){
  	    if ($(this.current_tab+"_title_holder")) $("header_title").innerHTML = $(this.current_tab+"_title_holder").innerHTML;
      }
          
      //load extra data
      if ($("tab_extra")){
  			if ($(this.current_tab+"_tab_extra")){
  			  $("tab_extra").innerHTML = $(this.current_tab+"_tab_extra").innerHTML;
  			} else {
  			  $("tab_extra").innerHTML = "";
  			}
  		}
  	  //check for a <span id=""no_child_TABNAME"></span> if it cant find one then load the child js otherwise do nothing
  	  //adding a <span id=""no_child_TABNAME"></span> can be used to stop child_obj creation on a tab if it is not needed
  	  if ($("no_child_"+this.current_tab) == null || typeof($("no_child_"+this.current_tab)) == "undefined"){ 
    		var setLoaded = function() {}      
    		var loadChild = function() { 
    			try {
    			  //create child_obj
     				eval("this.child_obj['"+this.current_tab+"'] = new "+this.current_tab+"(); if (this.child_obj['"+this.current_tab+"'].build) { this.child_obj['"+this.current_tab+"'].build(); } ");   				
     				//load page number events
    		    this.setup_page_numbers();
    		    this.setup_all_none();
    		    
    		    if(typeof(this.child_obj[this.current_tab]) != "undefined"){
              if (this.child_obj[this.current_tab].afterAnimate) {
                 this.child_obj[this.current_tab].afterAnimate();
              }
        	  } 
    			}
    			catch( x ) {}
    		};

    		//get child script
    		var script = add_js_file('/www/js/panels/'+this.current_tab+'.js');
    		if (typeof(this.child_obj[this.current_tab]) != "undefined" && this.child_obj[this.current_tab] != null){
    		  if (this.child_obj[this.current_tab].name != this.current_tab){//stop a reload of the exact same child that is loaded
    		  	YAHOO.util.Get.script( script, { onSuccess: loadChild, onTimeout: setLoaded, onFailure: setLoaded, scope: this } );  
    		  } else {
    		    if (this.child_obj[this.current_tab].build) this.child_obj[this.current_tab].build();  //if same tab was reloaded just run build
    		    //load page number events
    		    this.setup_page_numbers();
    		    this.setup_all_none();
    		  }
    		}else{
    		 
    		  //load first child object on page load 
    		  YAHOO.util.Get.script( script, { onSuccess: loadChild, onTimeout: setLoaded, onFailure: setLoaded, scope: this } );  
    		}
      } else {
        this.setup_page_numbers();
        this.setup_all_none();
      }
      
      //set last good dash vars for a error restore
      if (this.dashs.id != "error"){
        this.last_dash = this.dashs.id;
        this.last_tab  = this.current_tab;
    	}
  	}
  	
  	
  	
  	/**
		*
		* Attaches the change page events to the 1 2 3 4 5 >> links on the page
		* By default uses this objects change_page function.  
		* Will automatically override to a childs change_page function if it exists
		*
		*/
		jobvana.prototype.setup_page_numbers = function () {
      if ($("pagination_options_"+this.current_tab)) { 
        var page_numbers_t = $("pagination_options_"+this.current_tab).getElementsByTagName("a");
        if (typeof(this.child_obj[this.current_tab]) != "undefined" && this.child_obj[this.current_tab] != null){ 
          if (this.child_obj[this.current_tab].change_page){ //override to child change_page function if present
            $ev(page_numbers_t, "click", this.child_obj[this.current_tab].change_page, this);
          }else{
            $ev(page_numbers_t, "click", this.change_page, this);
          }
        }else{
          $ev(page_numbers_t, "click", this.change_page, this);
        }
      }
      if ($("pagination_options_"+this.current_tab+"_b")) {
        var page_numbers_b = $("pagination_options_"+this.current_tab+"_b").getElementsByTagName("a");
        if (typeof(this.child_obj[this.current_tab]) != "undefined" && this.child_obj[this.current_tab] != null){ 
          if (this.child_obj[this.current_tab].change_page){ //override to child change_page function if present
            $ev(page_numbers_b, "click", this.child_obj[this.current_tab].change_page, this);
          }else{
            $ev(page_numbers_b, "click", this.change_page, this);
          }
        }else{
          $ev(page_numbers_b, "click", this.change_page, this);
        }
      }
		}
		
		
		/**
		*
		* Attaches the selectAll/None events to and select all links or buttons
		* By default uses this objects selectAll/None function.  
		* Will automatically override to a childs selectAll function if it exists
		*
		*/
		jobvana.prototype.setup_all_none = function () {
      if ($(this.current_tab+"_all")) {
        if (typeof(this.child_obj[this.current_tab]) != "undefined" && this.child_obj[this.current_tab] != null){ 
          if (this.child_obj[this.current_tab].selectAll){ //override to child setup_all_none function if present
            $ev(this.current_tab+"_all", "click", this.child_obj[this.current_tab].selectAll, this);
          }else{
            $ev(this.current_tab+"_all", "click", this.selectAll, this);
          }
        }else{
          $ev(this.current_tab+"_all", "click", this.selectAll, this);
        }
      }
      if ($(this.current_tab+"_none")) {
        if (typeof(this.child_obj[this.current_tab]) != "undefined" && this.child_obj[this.current_tab] != null){ 
          if (this.child_obj[this.current_tab].selectNone){ //override to child setup_all_none function if present
            $ev(this.current_tab+"_none", "click", this.child_obj[this.current_tab].selectNone, this);
          }else{
            $ev(this.current_tab+"_none", "click", this.selectNone, this);
          }
        }else{
          $ev(this.current_tab+"_none", "click", this.selectNone, this);
        }
      }
		}
		  	
  	
		/**
		*
		* Posting process POST call by a child obj.
		* string fc (frontcontroller to call),  string call (call to make)
		*
		*/
		jobvana.prototype.child_post = function (fc, call) {  
			this.tabs[this.current_tab].hide(); 

		  this.write_postholder('<div class="mb10 mt10 bld">'+this.default_post_code+'</div>');
			 
			this.post_call = new post_call(this.child_obj[this.current_tab], fc); 
			this.post_call.set_call(call); 
			//set form if this.post_form is set
			if (this.post_form != null){
				this.post_call.set_form(this.post_form)
				this.post_form = null;
			} 
			this.post_call.post(); 
		}
	
  	
  	/**
		*
		* Process run by a child_obj after a ajax post has returned
		* string post_code,  Button post_button 
		*
		*/
  	jobvana.prototype.child_post_return = function (post_code,post_button) { 
  	  
  	  if (typeof(post_button) != "undefined") post_button.disabled=false; 
  	
      this.write_postholder('<div class="mb10 mt10 bld">'+post_code+'</div>');      
     
  	  var thisc = this;
  	  this.post_message_timout = setTimeout(
					function() {
						 thisc.tabs[thisc.current_tab].show();
						 this.post_message_timout1 = setTimeout(
      					function() {
      						  thisc.clear_postholder();  
      					},
      			5000);
					},
			1000);
  	}
  		
  	    
  	/**
		*
		* Posting process GET call by a child obj.
		* string fc (frontcontroller to call),  string call (call to make)
		*
		*/
  	jobvana.prototype.child_get = function (fc, call, pass_vars) {  
       this.tabs[this.current_tab].hide(); 
  
       this.write_postholder('<div class="mb10 mt10 bld">Saving...</div>');
       
       this.send_call = new send_call(this.child_obj[this.current_tab], fc); 
   		 this.send_call.set_call(call);
  		 this.send_call.set_url_vars(pass_vars);
  		 this.send_call.send(dash_loader.ajax.ajax_support);
  	}
  	
  	
  	jobvana.prototype.write_postholder = function (code) {
  	  if ($("post_holder")){
    	  $("post_holder").style.display = "block";
    	  $("post_holder").innerHTML = code;
    	}
  	}
  	
  	jobvana.prototype.clear_postholder = function () {
  	  if ($("post_holder")){
    	  $("post_holder").style.display = "none";
    	  $("post_holder").innerHTML = '';
    	}
  	}
  	

  	jobvana.prototype.clear_tab_cache = function (tab) {
  	   if (typeof(this.tabs[tab]) != "undefined") this.tabs[tab].body = null;
  	   if (typeof(this.child_obj[tab]) != "undefined") this.child_obj[tab] = null;
  	}
  	
  
  	/**
		*
		* Transfer the page to the myadmin new message form or change the dashboard
		* int new_message_uid
		*
		*/
		jobvana.prototype.send_message = function(uid) {  
		  dash_loader.passed_in_url_vars = "&id="+uid;
			dash_loader.load_dash("sendmessage","messageform");
		}
				      
	  
	  /**
		*
		* Load Advertisements
		*
		*/
	  jobvana.prototype.load_ads = function() { 
	    for (var i in this.ad_ids) {
	      if ($(i)) {
	        $(i).src="http://www.jobvanaads.com/www/delivery/afr.php"+this.ad_ids[i];
	      }
	    }
		  this.ads_loaded = true;
	  }  
	  

	  /*
	  *
	  * Selects all the checkboxes on a tab
	  *
	  */
	  jobvana.prototype.selectAll = function(e, obj) { 
	    try {
     	  var elements = $(obj.current_tab+"_cn").getElementsByTagName("input");
  			for (var i = 0; i < elements.length; i++)	elements[i].checked = true;
    	}
    	catch( x ) {
    	  obj.load_dash('error','jserror');
    	}
		}
		

		/*
	  *
	  * DESelects all the checkboxes on a tab
	  *
	  */
		jobvana.prototype.selectNone = function(e, obj) { 
			try {
     	  var elements = $(obj.current_tab+"_cn").getElementsByTagName("input");
  			for (var i = 0; i < elements.length; i++) elements[i].checked = false;
    	}
    	catch( x ) {
    	  obj.load_dash('error','false');
    	}
		}
		
		
		/* 
       Add the signup process
    */
    jobvana.prototype.show_signup_pop = function () {
      YAHOO.util.Get.script(
				add_js_file("/www/js/signup_popup.js"), {
					onSuccess: function() {
					  signup_pop = new signup_popup();  
					  signup_pop.initial_body = '<br/>If you already have an account on Bragadoo.com then <a href="javascript:void(0);" onclick="signup_pop.get_login_form(); return false;">click here to log in.</a><br/><br/>Don\'t have an account? <a href="javascript:void(0);" onclick="signup_pop.get_signup_form(); return false;">Join now for free.</a><br/><br/>';					  
					  signup_pop.build();
				  }, scope:this
				}
	    );
    }
    
    
    /* 
       Add the signup process to a riht ad click
    */
    jobvana.prototype.ad_click = function (code) {
      if ($F("jobvana_uid") == "NA"){
        YAHOO.util.Get.script(
  				add_js_file("/www/js/signup_popup.js"), {
  					onSuccess: function() {
  					  signup_pop = new signup_popup();
  					  signup_pop.build("location.href = \'"+code+"\'");
  				  }, scope:this
  				}
  	    );
      }else{
         location.href = code;
      }
    }
    
    
    
	  //END
    jobvana._initialized = true;
  } 
}
