// Create first and last list classes

function  firstLastList() {
	if(!document.getElementsByTagName) return false;

	var ul = document.getElementsByTagName("ul");

	for (var i = 0; i < ul.length; i++ )
	{
		var li = ul[i].getElementsByTagName("li");
		if (!li.length) continue;
		li[0].className += " first";
		li[li.length-1].className += " last";
	}

	var ol = document.getElementsByTagName("ol");

	for (var i = 0; i < ol.length; i++ )
	{
		var li = ol[i].getElementsByTagName("li");
		if (!li.length) continue;
		li[0].className += " first";
		li[li.length-1].className += " last";
	}
}

// Show & Hide Tabs
function showTab(obj) {
	if(!document.getElementsByTagName) return false;
	var tab = obj.parentNode;
	if (tab.className.search(/selected/) != -1 || tab.className.search(/first-selected/) != -1 || tab.className.search(/last-selected/) != -1) return false;
	var tabs = obj.parentNode.parentNode;
	var tab_content = obj.parentNode.parentNode.parentNode;
	
	
	var content_number = 0;
	
	tabs = tabs.getElementsByTagName("li");
	
	for ( var i = 0; i < tabs.length; i++ )
	{
		
		if (tabs[i].className.search(/first-selected/) != -1)
		{
			if (tabs[i].className == "first-selected")
			{
				tabs[i].className = tabs[i].className.replace(/first-selected/i, "");
			}
			else {
				tabs[i].className = tabs[i].className.replace(/first-selected/i, "");
			}
		}
		if (tabs[i].className.search(/last-selected/) != -1)
		{
			if (tabs[i].className == "last-selected")
			{
				tabs[i].className = tabs[i].className.replace(/last-selected/i, "");
			}
			else {
				tabs[i].className = tabs[i].className.replace(/ last-selected/i, "");
			}
		}
		if (tabs[i].className.search(/selected/) != -1)
		{
			if (tabs[i].className == "selected")
			{
				tabs[i].className = tabs[i].className.replace(/selected/i, "");
			}
			else {
				tabs[i].className = tabs[i].className.replace(/ selected/i, "");
			}
		}
		
		if (tabs[i] == tab )
		{
			content_number = i;
		}
	}
	
	tab_content = tab_content.getElementsByTagName("div");
	
	var contentArray = new Array();
	var content_counter = 0;
	
	for (var i = 0; i < tab_content.length; i++)
	{
		
		if ( tab_content[i].className.search(/tab-content/) != -1 )
		{
		
			if (tab_content[i].className == "tab-content")
			{
				tab_content[i].className = tab_content[i].className.replace(/selected/i, "");
			}
			else {
				tab_content[i].className = tab_content[i].className.replace(/ selected/i, "");
			}
			
			contentArray[content_counter] = i;
			
			content_counter++;
		}
	}
	
	
	if (tab_content[contentArray[content_number]].className == "selected")
	{	
		tab_content[contentArray[content_number]].className = "selected";
	}
	else {
		tab_content[contentArray[content_number]].className += " selected";	
	}
	
	
	if (tab.className.search(/first/) != -1 )
	{
		if (tab.className == "")
		{
			tab.className == "first-selected";	
		}
		else {
			tab.className += " first-selected";
		}
	}
	else if ( tab.className.search(/last/) != -1)
	{
		if (tab.className == "")
		{
			tab.className == "last-selected";	
		}
		else {
			tab.className += " last-selected";
		}
	}
	else
	{
		if (tab.className == "")
		{
			tab.className == "selected";	
		}
		else {
			tab.className += " selected";
		}
	}
}

function  tagChild() {
	if(!document.getElementsByTagName) return false;
	var ul = document.getElementsByTagName("ul");
	for (var i = 0; i < ul.length; i++ )
	{
		var li = ul[i].getElementsByTagName("li");
		if (!li.length) continue;
		li[0].className += " first";
		li[li.length-1].className += " last";
	}
	
	var ol = document.getElementsByTagName("ol");
	for (var i = 0; i < ol.length; i++ )
	{
		var li = ol[i].getElementsByTagName("li");
		if (!li.length) continue;
		li[0].className += " first";
		li[li.length-1].className += " last";
	}
}

// Open links in a new window

function openWindow() {
	if (!document.getElementsByTagName) return false;
	
	var links = document.getElementsByTagName("a");
	
	for ( var i = 0; i < links.length; i++ )
	{
		if (links[i].className.search(/open-window/) != -1)
		{
			links[i].onclick = function() {
				if(!document.getElementById) return true;
				//open a new window with the anchors url
				window.open(this.getAttribute("href"));
				return false;
			}
		}
	}
}

// Stripe tables

// This function is need to work around 
// a bug in IE related to element attributes
function hasClass(obj) {
	
	var result = false;
	
	if (obj.getAttributeNode("class") != null) {
		result = obj.getAttributeNode("class").value;
		}
		return result;
		} 

onload = function() {
	stripeTable ()
	};

function stripeTable() {
	
	var even = true;
	var tables = document.getElementsByTagName("table");	
	
	for(x=0;x!=tables.length;x++){
		table = tables[x];
		if (! table) { return; }
		
		var tbodies = table.getElementsByTagName("tbody");
		
		for (var h = 0; h < tbodies.length; h++) {
			var trs = tbodies[h].getElementsByTagName("tr");
			
			for (var i = 0; i < trs.length; i++) {
				
				for (var i = 0; i < trs.length; i += 2) {
					trs[i].className += "odd";
				}
			}
		}
	}
}

// Choose search criteria

function assignURL()  {
   for( i = 0; i < document.vtsearchform.url.length;i++)    {
   if( document.vtsearchform.url[ i ].checked ) document.vtsearchform.action =  document.vtsearchform.url[ i ].value;
	  document.vtsearchform.submit();
	  }
   }

// Clear search query

function clearquery(id) {
	if(!document.getElementById(id)) return false;
	if (document.getElementById(id).value == "Enter your search here")
	{
		document.getElementById(id).value = "";
	}
}

// Submit search form

function submitForm(formId) {
	document.getElementById(formId).submit();
}

// Event handlers

function addLoadEvent(func) {
	var oldOnLoad = window.onload
	if (typeof window.onload != 'function') 
	{
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldOnLoad();
			func();
		}
	}
}

addLoadEvent(firstLastList);
addLoadEvent(openWindow);
