/* functions for search box */
function submitForm(formId) {
 document.getElementById(formId).submit();
}

function clearquery(id,text) {
 if(!document.getElementById(id)) return false;
 if (document.getElementById(id).value == text) {
	document.getElementById(id).value = "";
 }
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
/* stripe table rows */
$(document).ready(function(){
$("table tr").mouseover(function() {$(this).addClass("over");}).mouseout(function() {$(this).removeClass("over");});
$("table tr:even").addClass("alt");
});


/* no table styles */
$(document).ready(function(){
$("div.vt_table_no_styles table tr").mouseover(function() {$(this).removeClass("over");}).mouseout(function() {$(this).removeClass("over");});
$("div.vt_table_no_styles table tr:even").removeClass("alt");
});


// show left tab open by default
$(document).ready(function() {
	$("div[class*='vt_tc_']").hide();	
	$("div[@name*='TabNav']").hide();
	$("div[class*='vt_tc_1']").show();	
	$("div[@name='TabNav1']").show();
	$('.vt_tc_l1').show();
	$("div[@name='leftTabNav1']").show();
});

//show and hide the left and right tab functions
$(document).ready(function() {					   
   // left tab group, do this when clicked
   $('.vt_ltab_1, .vt_ltab_2').click(function(){
     $(this).parent().parent().parent().find('.vt_tc_l1').show();
	 	 $(this).parent().parent().parent().find('.vt_tc_r1').hide();
		 $(this).parent().parent().parent().find("div[@name='rightTabNav1']").hide();
		 $(this).parent().parent().parent().find("div[@name='leftTabNav1']").show();	 
	});
   
   // right tab group
    $('.vt_rtab_1,.vt_rtab_2').click(function(){
     	$(this).parent().parent().parent().find('.vt_tc_l1').hide();
	 		$(this).parent().parent().parent().find('.vt_tc_r1').show();
	 		$(this).parent().parent().parent().find("div[@name='rightTabNav1']").show();
	 		$(this).parent().parent().parent().find("div[@name='leftTabNav1']").hide();	
   	});
	
 });

// show and hide for multi tab group
$(document).ready(function() {			   
	//tab group 1
	$('.vt_tab_1a, .vt_tab_1b, .vt_tab_1c, .vt_tab_1d').click(function(){
		$(this).parent().parent().parent().find("div[class*='vt_tc_']").hide();	
		$(this).parent().parent().parent().find("div[@name*='TabNav']").hide();
		$(this).parent().parent().parent().find("div[class*='vt_tc_1']").show();	
		$(this).parent().parent().parent().find("div[@name='TabNav1']").show();
	});
   
	//tab group 2
	$('.vt_tab_2a, .vt_tab_2b, .vt_tab_2c, .vt_tab_2d').click(function(){
		$(this).parent().parent().parent().find("div[class*='vt_tc_']").hide();	
		$(this).parent().parent().parent().find("div[@name*='TabNav']").hide();
		$(this).parent().parent().parent().find("div[class*='vt_tc_2']").show();	
		$(this).parent().parent().parent().find("div[@name='TabNav2']").show();
	});
	
   //tab group 3
   $('.vt_tab_3a, .vt_tab_3b, .vt_tab_3c, .vt_tab_3d').click(function(){
		$(this).parent().parent().parent().find("div[class*='vt_tc_']").hide();	
		$(this).parent().parent().parent().find("div[@name*='TabNav']").hide();
		$(this).parent().parent().parent().find("div[class*='vt_tc_3']").show();	
		$(this).parent().parent().parent().find("div[@name='TabNav3']").show(); 
	});
   
   //tab group 4
   $('.vt_tab_4a, .vt_tab_4b, .vt_tab_4c, .vt_tab_4d').click(function(){
		$(this).parent().parent().parent().find("div[class*='vt_tc_']").hide();	
		$(this).parent().parent().parent().find("div[@name*='TabNav']").hide();
		$(this).parent().parent().parent().find("div[class*='vt_tc_4']").show();	
		$(this).parent().parent().parent().find("div[@name='TabNav4']").show();
	});
 });

//ability to choose which tab to have open on page load
//Example: apage.html#opentab=2
var winloc = window.location.toString();
var tabchoice = winloc.search(/#opentab=/i);
if(tabchoice > 0){
	// get the tab number to open
	tabchoice = tabchoice + 9;
	var tabToOpen = winloc.substring(tabchoice, winloc.length);
	if (tabToOpen > 0 ){
		$(document).ready(function(){
			// check for existance of element
			if($("div[@name='TabNav"+tabToOpen+"']").length > 0){
				$("div[class*='vt_tc_']").hide();	
				$("div[@name*='TabNav']").hide();
				$("div[class*='vt_tc_"+tabToOpen+"']").show();	
				$("div[@name='TabNav"+tabToOpen+"']").show();
			}
			// for two tabbed, we have different styles
			if((tabToOpen == 1) && $("div[@name='leftTabNav1']").length > 0){
				$("div[class*='vt_tc_r1']").hide();	
				$("div[@name='rightTabNav1']").hide();
				$("div[class*='vt_tc_l1']").show();	
				$("div[@name='leftTabNav1']").show();
			}else if ((tabToOpen == 2) && $("div[@name='rightTabNav1']").length > 0){
				$("div[class*='vt_tc_l1']").hide();	
				$("div[@name='leftTabNav1']").hide();
				$("div[class*='vt_tc_r1']").show();	
				$("div[@name='rightTabNav1']").show();
			}else if ($("div[@name='leftTabNav1']").length > 0){
				// case where there is a two column and more than two columns on same page
				// and the reference is to the third column, default to first tab on 2 col
				$("div[class*='vt_tc_r1']").hide();	
				$("div[@name='rightTabNav1']").hide();
				$("div[class*='vt_tc_l1']").show();	
				$("div[@name='leftTabNav1']").show();
			}
	 });
	}
}

// slide down for quicklinks
$(document).ready(function() {
   // show quicklinks
   $('#vt_ql_link').css('display', 'block');
   
   // left tab grup this when clicked
   $('#vt_ql_link').click(function(){
     $('#vt_ql_list').slideToggle('fast'); 
	});
	
});
/* equalizes columns */
(function($) {
  $.fn.equalizeCols = function(children){
    var child = Array(0);
    if (children) child = children.split(",");
    var maxH = 0;
    this.each(
      function(i) 
      {
        if (this.offsetHeight>maxH) maxH = this.offsetHeight;
      }
    ).css("height", "auto").each(
      function(i)
      {
        var gap = maxH-this.offsetHeight;
        if (gap > 0)
        {
          t = document.createElement('div');
          $(t).attr("class","fill").css("height",gap+"px");
          if (child.length > i)
          {
            $(this).find(child[i]).children(':last-child').after(t);
          } 
          else 
          {
            $(this).children(':last-child').after(t);
          }
        }
      }  
    );
    
  }
})(jQuery);