﻿// ******** BEGIN CUSTOM CONFIGURATION ********* //
// things you can change to customize your forums
	
	// images directory
	var imagesDir = properties['general']['filesUrl']+"img/";
	var categoryIconsDir = "";
	var forumsIconsDir = "";
	var interfaceIconsDir = "icones_interface/";
	
	// default icon for the categories (in case there's no custom icon for a category)
	// => custom icons are named : imagesDir/categoryIconsDir/categorie_CATEGORYNAME.png
	var defaultCategoryIcon = "";
	// default icon for the forums (in case there's no custom icon for a forum)
	// => custom icons are named : imagesDir/forumsIconsDir/forum_CATEGORYNAME_FORUMNAME.png
	var defaultForumIcon = "";
	
// ******** END CUSTOM CONFIGURATION ********* //


function changeCategoriesDisplay()
{
	var categories;
	var categoriesId = new Array();
	var categoriesUrl = new Array();
	var cells = new Array();
	var forums = new Array();
	var nbForums = 0;
	var forumsName = new Array();

	// get all categories titles boxes
	categories = getElementsByClass('ubbx_cfrm_cat_tbl', null, null);
	
	// if there are no categories, exit
	if(categories.length == 0)
		return false;

	var node;
	
	var newNode = document.createElement('span');
	newNode.innerHTML = "<br><br>";
	newNode.style.marginTop='0px';

	// *** loop to change categories display *** //

	// for each forum category
	for(var i = 0; i < categories.length; i++)
	{
		categoriesId[i] = categories[i].id.substr(10);
		
		if(properties[''+categoriesId[i]] == null)
			continue;
		
		// add a blank before each category
		if(properties['general']['categoriesSpace'] != null)
			categories[i].parentNode.insertBefore(newNode.cloneNode(true), categories[i]);
		
		// set the width
		if(properties['general']['forumWidth'] != null)
			categories[i].style.width = properties['general']['forumWidth']+"px";
	
		// get the category title table cells
		cells = categories[i].getElementsByTagName('TD');

		// if we want a banner
		if(properties['general']['useBanners'] != null)
		{
			// get the category name (format to remove special chars)
	//		categoriesName[i] = formatImageName(cells[1].firstChild.innerHTML);
			
			// put the banner instead of the link text
			cells[1].firstChild.innerHTML = '<img src="'+imagesDir+'category_'+categoriesId[i]+'.jpg">';
			
			// remove the forum description
			if(cells[1].lastChild.previousSibling != null)
			{
				if(navigator.appName == "Microsoft Internet Explorer")
				{
					cells[1].removeChild(cells[1].lastChild.previousSibling);
					cells[1].removeChild(cells[1].lastChild);
				}
				else cells[1].removeChild(cells[1].lastChild.previousSibling);
			}

			// remove the margins
			cells[1].style.padding = "0px";
			cells[1].style.margin = "0px";
			
			// remove the left (icon) and right (last subject) cells
			cells[2].parentNode.removeChild(cells[2]);
			cells[0].parentNode.removeChild(cells[0]);
		}
		// else if we want an icon
		else
		{
//			cells[0].innerHTML = '<img src="'+imagesDir+'category_'+categoriesId[i]+'.jpg" onerror="this.src='+"'"+defaultCategoryIcon+"'"+'">';
cells[0].innerHTML = '<img src="'+imagesDir+'category_'+categoriesId[i]+'.jpg">';
		}
		
		// set the border
		if(properties[''+categoriesId[i]]['borderColor'] != null)
		{
			categories[i].style.border="solid 1px "+properties[''+categoriesId[i]]['borderColor'];
			categories[i].style.borderBottom="none";
		}
	}
	
		// *** loop to change forums display *** //
	
	// get the categories forums box
	categories = getElementsByClass('ev_com_tbl', null, null);
	// foreach category
	for(var i = 0; i < categories.length; i++)
	{
		if(properties[''+categoriesId[i]] == null)
			continue;

		// set the width
		if(properties['general']['forumWidth'] != null)
			categories[i].style.width = (parseInt(properties['general']['forumWidth'])+2)+"px";
		
		// set the general table outside border
		if(properties[''+categoriesId[i]]['borderColor'] != null)
			categories[i].style.border="solid 1px "+properties[''+categoriesId[i]]['borderColor'];

		// loop for the forums icons
		categoriesContent = getElementsByClass('ev_forum_td_icon', null, categories[i]);
//		alert(categoriesContent.length);
		// foreach forum
		for(var j = 1; j < categoriesContent.length; j++)
		{
			// replace the current image with our own (the onerror sets our default icon, in case we don't have an icon for this forum)
//			categoriesContent[j].innerHTML = '<img src="'+imagesDir+'category_'+categoriesId[i]+'_forums.jpg" onerror="this.src='+"'"+defaultForumIcon+"'"+'">';
			categoriesContent[j].innerHTML = '<img src="'+imagesDir+'category_'+categoriesId[i]+'_forums.jpg">';
			categoriesContent[j].valign="middle"; // center icon vertically (doesn't seem to be working)
			categoriesContent[j].style.textAlign="center";
		}
		
		// loop for the links
		categoriesContent = categories[i].getElementsByTagName("a");
		// foreach forum link, set the color
		if(properties[''+categoriesId[i]]['linkColor'] != null)
			for(var j = 0; j < categoriesContent.length; j++)
				categoriesContent[j].style.color = properties[''+categoriesId[i]]['linkColor'];

		// loop for the dates
		categoriesContent = getElementsByClass('ev_text_timecolor', null, categories[i]);
		// foreach date, change the color
		for(var j = 0; j < categoriesContent.length; j++)
			categoriesContent[j].style.color = '#FFFFFF';
		
		// loop for all the cells 
		categoriesContent = categories[i].getElementsByTagName('TH');
		for(var j = 0; j < categoriesContent.length; j++)
		{
			// set the border
			if(properties[''+categoriesId[i]]['borderColor'] != null)
				categoriesContent[j].style.borderColor=properties[''+categoriesId[i]]['borderColor'];
			// set the text color
			if(properties[''+categoriesId[i]]['textColor'] != null)
				categoriesContent[j].style.color=properties[''+categoriesId[i]]['textColor'];
			// set the background color
			if(properties[''+categoriesId[i]]['bkgColor'] != null)
				categoriesContent[j].style.backgroundColor=properties[''+categoriesId[i]]['bkgColor'];
		}
		
		categoriesContent = categories[i].getElementsByTagName('TD');
		for(var j = 0; j < categoriesContent.length; j++)
		{
			if(properties[''+categoriesId[i]]['borderColor'] != null)
				categoriesContent[j].style.borderColor=properties[''+categoriesId[i]]['borderColor'];
			if(properties[''+categoriesId[i]]['textColor'] != null)
				categoriesContent[j].style.color=properties[''+categoriesId[i]]['textColor'];
			if(properties[''+categoriesId[i]]['bkgColor'] != null)
				categoriesContent[j].style.backgroundColor=properties[''+categoriesId[i]]['bkgColor'];
		}
	}
}

function changeHotTopicIcon()
{
	var icons = getElementsByClass('ev_ubbx_frm_topicicon', null, null);
	for(var i = 1; i < icons.length; i++)
	{
		if(icons[i].childNodes.length == 2 && icons[i].childNodes[1].className == "ubb_hot")
		{
			if(icons[i].firstChild.title == "Pas de nouveau contenu")
				icons[i].firstChild.src = imagesDir+interfaceIconsDir+"icone_nonewmanymessage.png";
			else icons[i].firstChild.src = imagesDir+interfaceIconsDir+"icone_manymessage.png";
			icons[i].firstChild.style.background="none";
			icons[i].firstChild.style.height="32px";
			icons[i].childNodes[1].style.display = "none";
		}
	}
}

function changePostIcon()
{
	var icons = getElementsByClass('ubb_post_icon1', null, null);
	for(var i = 0; i < icons.length; i++)
	{
		icons[i].src = imagesDir+interfaceIconsDir+"icone_sujet.png";
		icons[i].style.height = "24px";
		icons[i].style.width = "24px";
		icons[i].style.background='none';
		icons[i].parentNode.parentNode.style.padding='2px';

	}
}

function changeImages()
{
	var images = document.getElementsByTagName('img');
	for(var i = 0; i < images.length; i++)
	{
		if(images[i].src == "http://forumsforeveryone-fr.ubi.com/groupee_common/platform_images/blank.gif")
		{
			images[i].src = images[i].background;
			images[i].background = "none";
		}
	}
}

function setMDAvatars()
{
	var avatars = getElementsByClass('ev_ubbx_tpc_avatar', null, null);
	
	for(var j = 0; j < avatars.length; j++)
	{
		avatars[j].src = 'http://webtools.fr.ubi.com/forums/MissDecouverte/'+avatars[j].title.substring(9)+'.gif';
	}
}

function getElementsByClass(className,tag,node)
{
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';

	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;

	for (i = 0, j = 0; i < elsLen; i++)
		if(els[i].className == className)
		{
			classElements[j] = els[i];
			j++;
		}

	return classElements;
}

function hide(divId)
{
	if(document.getElementById(divId) != null)
		document.getElementById(divId).style.display='none';
}

function formatImageName(string)
{
	string = string.replace(/(%C3%A9)/g,"e");
	string = string.replace(/(&eacute;)/g,"e");
	string = string.replace(/[éèêë]/g,"e");
	string = string.replace(/à/g,"a");
	string = string.replace(/ \?/g,"");
	string = string.toLowerCase();

	string = string.replace(/\W+/g, "_");

	return string;
	
}

function element(id)
{
	return document.getElementById(id);	
}

function topMenuBar()
{
	var menuTable = element('gs_tab_go').parentNode.parentNode.parentNode;
	
	// put the "welcome / connect / signup" bar on the right of the menu bar
	var newNode = document.createElement('td');
	newNode.innerHTML = element('gs_menu_y_baseline').innerHTML;
	newNode.style.margin='0px';
	newNode.className='eve_tab';
	element('gs_tab_go').parentNode.appendChild(newNode);
	
	// put the menu bar on the whole width of the page, remove its margins, and set its height
	menuTable.style.width ='100%';
	menuTable.style.margin='0px';
	menuTable.style.padding='0px';
	menuTable.style.height='40px';
	
	// for each menubar cell
	var contentArray = menuTable.getElementsByTagName("td");
	for(var i = 0; i < contentArray.length; i++)
	{
		// no new line
		contentArray[i].noWrap = "noWrap";
		// set the background
		contentArray[i].style.backgroundImage='url('+properties['general']['filesUrl']+'bkg_menu.gif)';
		contentArray[i].style.backgroundRepeat='repeat-x';
		// set the height
		contentArray[i].style.height='40px';
		// align vertically
		contentArray[i].style.verticalAlign = 'middle';
		contentArray[i].style.color='#a0a0a0';
		
		// standard width for menu tabs
		if(contentArray[i].className == 'eve_tab')
		{
			contentArray[i].style.width = '100px';
			contentArray[i].style.textAlign = 'center';
		}
		
		// remove the border of the inner menu tabs
		if(contentArray[i].firstChild.style != null) // ie
		{
			contentArray[i].firstChild.style.border='none';
			contentArray[i].firstChild.style.textTransform = 'capitalize';
			contentArray[i].firstChild.style.color='#a0a0a0';
		}
		// ff
		else if(contentArray[i].childNodes[1] != null && contentArray[i].childNodes[1].style != null)
		{
			contentArray[i].childNodes[1].style.border='none';
			contentArray[i].childNodes[1].style.color='#a0a0a0';
		}
	}
	// set the "welcome" bar to take the remaining space
	newNode.style.width = '100%';
	
	// remove the useless divs which put blanks between the menu and the banner
	element('gs_menu_y_baseline').style.visibility='hidden';
	element('eve_bc_top').style.display='none';
	if(element('ev_portal_title_graphic_div') != null)
		element('ev_portal_title_graphic_div').style.display='none';
	
	// take the menu out of the main divs, to put it just after the banner
	element('ev_common_master_div1').parentNode.insertBefore(menuTable, element('ev_common_master_div1'));
	// set the width of the main div
	if(properties['general']['forumWidth'] != null)
		element('ev_common_master_div2').style.width= (parseInt(properties['general']['forumWidth'])+10)+"px";
		
	// put the background of the forums
	document.getElementsByTagName("body")[0].style.backgroundImage = 'url('+properties['general']['filesUrl']+'bkg.gif)';
	document.getElementsByTagName("body")[0].style.backgroundRepeat = 'repeat-x';
	document.getElementsByTagName("body")[0].style.backgroundPosition = '0px 174px';
	document.getElementsByTagName("body")[0].style.margin = '0px';
	document.getElementsByTagName("body")[0].style.padding = '0px';
	document.getElementsByTagName("body")[0].marginheight = 0;
	document.getElementsByTagName("body")[0].marginwidth = 0;
	document.getElementsByTagName("body")[0].topmargin = 0;
	document.getElementsByTagName("body")[0].leftmargin = 0;
	
	if(element('ev_pm_indicator') != null)
		element('ev_pm_indicator').style.width = '200px';
}

	changeCategoriesDisplay();
	
	if(properties['general']['welcomeMenu'] != null)
		topMenuBar();

	if(properties['general']['hideNotify'] != null)
		hide('gs_tab_notify');
	if(properties['general']['hideTools'] != null)
		hide('gs_tab_tools');

/*	
	changeCategoriesDisplay();
	changeHotTopicIcon();
	changePostIcon();
//	changeImages();
*/