/* tabs.js */
var sw_skins = [];

function sw_get_skin( p_uid ) {
	var skin_parts = sw_skins[p_uid].match(/^sw_s([0-9]+)_$/);
	return skin_parts[1];
}

function sw_switch_tab(p_uid, p_block_id, p_new_id) {
	var old_id = 0;
	var title_obj_old = document.getElementById( p_uid +"tabtitle_"+p_block_id+'_'+old_id);
	var tab_obj_old = document.getElementById( p_uid +"tab_"+p_block_id+'_'+old_id);
	while ( title_obj_old ) {
		title_obj_old.className = sw_skins[p_uid] +"tabtitle "+ sw_skins[p_uid] +"back";
		tab_obj_old.className = sw_skins[p_uid] +"tab_hidden";
		old_id++;
		title_obj_old = document.getElementById( p_uid +"tabtitle_"+p_block_id+'_'+old_id);
		tab_obj_old = document.getElementById( p_uid +"tab_"+p_block_id+'_'+old_id);
	}
	var title_obj_new = document.getElementById( p_uid +"tabtitle_"+p_block_id+'_'+p_new_id);
	var tab_obj_new = document.getElementById( p_uid +"tab_"+p_block_id+'_'+p_new_id);
	title_obj_new.className = sw_skins[p_uid] +"tabtitle";
	tab_obj_new.className = sw_skins[p_uid] + "tab_visible";
	try
	{
		mode_obj = document.getElementById( p_uid +"tab_selected_"+p_block_id);
		mode_obj.value = p_new_id;
	}
	catch ( e )	{}
	
}

function sw_tabbed_to_front( p_content_id ) {
	var content_obj = document.getElementById( p_content_id );
	if ( content_obj ) {
		var level = 0;
		var found = false;
		while ( !found && level < 4 ) {
			if ( (content_obj.className.indexOf('tab_hidden') >= 0) ||
				(content_obj.className.indexOf('tab_visible') >= 0)
			) {
				var id_parts = content_obj.id.match(/^(.+)tab_([0-9]+)_([0-9]+)$/);
				sw_switch_tab( id_parts[1], id_parts[2], id_parts[3] );
			} else {
				if ( (content_obj.parentNode != null) && 
					(content_obj.parentNode.tagName != 'body')
				) {
					content_obj = content_obj.parentNode;
				} else {
					level = 1000;
				}
			}
			level++;
		}
	}
	
}
