// addTab
// ---
// adds a video tab

function ajaxTab( theForm )
{
	// if no tab is being passed, return an alert
	
	if( theForm.tab.value == "" )
	{
		alert("You must select a tab");
		return false;
	}
	
	var ajaxURL = '_tab.php?ajax=1&video_id='+escape(theForm.video_id.value)+'&tab_id='+escape(theForm.tab.value);
	ajax.open('get', ajaxURL,true);
	ajax.onreadystatechange = tabResponse;
	ajax.send(null);
}

// tabResponse
// ---
// receives response from posting a tab and shows a success message

function tabResponse()
{
	if( defaultResponse(ajax) )
	{
		toggleSuccess('addtabbox',true);
	}
}

// selectTab
// ---
// sets a tab as the selected tab, passing a message to the map
// and switching the image with a highlighted version

function selectTab( img, tab_id )
{
	document.getElementById('flashmap').SetVariable('tab_id', tab_id);
	unhighlightTabs();
	highlightTab( img );
}

// highlightTab
// ---
// switch a tab image with it's highlighted version

function highlightTab( image )
{
	results = image.src.match(/^(.*)(\.[a-z]+)$/);
	if( results != null )
	{
		image.src = results[1] + "_selected" + results[2];
	}
}

function unhighlightTabs()
{
	var tabs = document.getElementById('tabs');
	for( var i=0;i<tabs.childNodes.length;i++ )
	{
		if( tabs.childNodes[i].className == "tab" )
		{
			var tab = tabs.childNodes[i];
			for( var j=0;j<tab.childNodes.length;j++)
			{
				if( tab.childNodes[j].tagName == "IMG" )
				{
					results = tab.childNodes[j].src.match(/^(.*)_selected(\.[a-z]+)$/);
					if( results != null )
					{
						tab.childNodes[j].src = results[1] + results[2];
					}
				}
			}// end for
		}
	}//end for
}