﻿// ******** BEGIN CUSTOM CONFIGURATION ********* //
// things you can change to customize your forums
	
	// images directory
	var imagesDir = "http://media.ubi.com/es/Portal_IMAGINA_SER/FORUM/";
	
	// default icon for the categories (in case there's no custom icon for a category)
	// => custom icons are named : imagesDir/categorie_CATEGORYNAME.png
	var defaultCategoryIcon = "http://forumsforeveryone-es.ubi.com/groupee_common/styles/images/cat_content_on.gif ";
	// default icon for the forums (in case there's no custom icon for a forum)
	// => custom icons are named : imagesDir/forum_CATEGORYNAME_FORUMNAME.png
	var defaultForumIcon = "http://forumsforeveryone-es.ubi.com/groupee_common/styles/images/forum_content_on.gif";
	
	// background colors for each category
	var bkgColorsArray = new Array();

	// border colors for each category
	var borderColorsArray = new Array();
	borderColorsArray["vamos_a_conocernos"] = "ca5196";
	borderColorsArray["es_importante_que_sepas..."] = "d518ff";
	borderColorsArray["tus_juegos"] = "ffabcc";
	borderColorsArray["tus_cosas"] = "d52585";
	
	// text colors for each category
	var textColorsArray = new Array();
	textColorsArray["vamos_a_conocernos"] = "ca5196";
	textColorsArray["es_importante_que_sepas..."] = "9000a1";
	textColorsArray["tus_juegos"] = "ff99cc";
	textColorsArray["tus_cosas"] = "d52585";
	
// ******** END CUSTOM CONFIGURATION ********* //


function changeCategoriesDisplay()
{
	var categories;
	var categoriesName = new Array();
	var categoriesUrl = new Array();
	var links = 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(categories.length == 0)
		return false;

	var node;
		// *** loop to change categories display *** //
		
	// for each forum category
	for(var j = 0; j < categories.length; j++)
	{
		// get the first element		
		if(categories[j].firstChild.innerHTML)
			node = categories[j].firstChild; // IE
		else node = categories[j].childNodes[1]; // firefox
		
		// can't remember what this is for...
		node.firstChild.style.height = '41px';
		node.firstChild.style.padding = '0px;';
		node.firstChild.style.margin = '0px;';
		node.firstChild.style.overflow = 'hidden';
		node.firstChild.style.border = 'none';
		node.style.border = 'none';

		// get the text of the link of the category (the category name)
		links = getElementsByClass('ubbx_cfrm_com_title_link', null, categories[j]);

		// get the category name (format to remove special chars)
		categoriesName[j] = formatImageName(links[0].innerHTML);

		// get the url of the category
		categoriesUrl[j] = links[0].href;
		// remove the link (as we'll replace it with an image)
//		links[0].innerHTML = "";
		// change the link color
		if(textColorsArray[categoriesName[j]] != null)
			links[0].style.color = textColorsArray[categoriesName[j]];
		
		// change the category title box layout
//		if(bkgColorsArray[categoriesName[j]] != null)
//			categories[j].style.backgroundColor = '#'+bkgColorsArray[categoriesName[j]];
		categories[j].style.backgroundColor = "white";
/*		categories[j].style.backgroundImage = 'url('+imagesDir+'categorie_bkg.jpg)';
		categories[j].style.backgroundRepeat = 'repeat-x';
		categories[j].style.height = '39px';
		categories[j].style.border = 'none';*/
		if(textColorsArray[categoriesName[j]] != null)
		{
			categories[j].style.border="solid 2px #"+textColorsArray[categoriesName[j]];
			categories[j].style.borderBottom="solid 1px #"+textColorsArray[categoriesName[j]];
		}
	}

	// loop for the category icons
	categories = getElementsByClass('ubbx_cfrm_cat_icon', null, null);
	// and change them
	for(var j = 0; j < categories.length; j++)
		categories[j].innerHTML = '<a href="'+categoriesUrl[j]+'"><img src="'+imagesDir+'categorie_'+categoriesName[j]+'.png" onerror="this.src='+"'"+defaultCategoryIcon+"'"+'"></a>';
	
		// *** loop to change forums display *** //
		
	// get the categories forums box
	categories = getElementsByClass('ev_com_tbl', null, null);
	// foreach category
	var forumIterator = 0;
	for(var j = 0; j < categories.length; j++)
	{
		// change the background and border color of the category
		if(bkgColorsArray[categoriesName[j]] != null)
			categories[j].style.backgroundColor="#000000";
		if(borderColorsArray[categoriesName[j]] != null)
			categories[j].style.borderColor ="#"+borderColorsArray[categoriesName[j]];

		// get the text of the links of the forums of this category (their name)
		forums = getElementsByClass('ubbx_cfrm_com_title_link', null, categories[j]);
		// foreach forum
		for(var i = 0; i < forums.length; i++)
		{
			// get the forum name and format it (for the image)
			forumsName[nbForums] = formatImageName(forums[i].innerHTML);
			// count the forums
			nbForums++;
		}

		// loop for the forums icons
		categoriesContent = getElementsByClass('ev_forum_td_icon', null, categories[j]);
		// foreach forum
		for(var k = 1; k < categoriesContent.length; k++)
		{
			// 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[k].innerHTML = '<img src="'+imagesDir+'categorie_'+categoriesName[j]+'.png" onerror="this.src='+"'"+defaultForumIcon+"'"+'">';
			categoriesContent[k].valign="middle";
			categoriesContent[k].style.textAlign="center";
			forumIterator++;
		}
		
		// loop for the links
		categoriesContent = categories[j].getElementsByTagName("a");
		// foreach forum link, set the color
		if(textColorsArray[categoriesName[j]] != null)
			for(var k = 0; k < categoriesContent.length; k++)
				categoriesContent[k].style.color = '#'+textColorsArray[categoriesName[j]];

		// loop for the dates
		categoriesContent = getElementsByClass('ev_text_timecolor', null, categories[j]);
		// foreach date, change the color
		for(var k = 0; k < categoriesContent.length; k++)
			categoriesContent[k].style.color = '#FFFFFF';

		// IE
		if(categories[j].firstChild.innerHTML)
		{
			node = categories[j].firstChild;

			// loop for the borders and bkg
			// foreach row
			for(var i=0; i < node.childNodes.length; i++)
				// foreach cell
				for(var k=0; k < node.childNodes[i].childNodes.length; k++)
				{
					if(borderColorsArray[categoriesName[j]] != null)
						node.childNodes[i].childNodes[k].style.borderColor="#"+borderColorsArray[categoriesName[j]];
					if(textColorsArray[categoriesName[j]] != null)
						node.childNodes[i].childNodes[k].style.color="#"+textColorsArray[categoriesName[j]];
				}
		}
		// firefox
		else
		{
			node = categories[j].childNodes[1];

			// loop for the borders and bkg
			// foreach row
			for(var i=0; i < node.childNodes.length; i=i+2)
				// foreach cell
				for(var k=1; k < node.childNodes[i].childNodes.length-1; k++)
				{
					if(borderColorsArray[categoriesName[j]] != null)
						node.childNodes[i].childNodes[k].style.borderColor="#"+borderColorsArray[categoriesName[j]];
					if(textColorsArray[categoriesName[j]] != null)
						node.childNodes[i].childNodes[k].style.color="#"+textColorsArray[categoriesName[j]];
				}
		}
	}
}


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,"u");
	string = string.replace(/í/g,"i");
	string = string.replace(/ \?/g,"");
	string = string.replace(/[¿¡!]/g,"");
	string = string.toLowerCase();
	string = string.replace(/\s/g, "_");

	return string;
	
}

function processModifications()
{
	hide('gs_tab_notify');
	hide('gs_tab_tools');
	
	changeCategoriesDisplay();
//	changeHotTopicIcon();
//	changePostIcon();
//	changeImages();

}