/**
 * Generic functions
 * @author Jerome Vidry
 */

/**
 * Global parameters
 */
var lang = 'fr';
var frTxt = Array('Formes', 'Dimensions');
var enTxt = Array('Shapes', 'Dimensions');
var translations = Array(frTxt, enTxt);
var frUnity = "''";
var enUnity = "''";

/**
 * Dimensions correspondances
 */
var dimensionsNames = Array(
	'13.875 x 79',
	'14 x 64',
	'14 x 80',
	'15.65625 x 39.78125',
	'20 x 36',
	'20 x 64',
	'20 x 80',
	'21.15625 x 57.25',
	'21.625 x 9.75',
	'22 x 12',
	'22 x 36',
	'22 x 48',
	'22 x 64',
	'22 x 80',
	'22 x 9',
	'7.5 x 18.5',
	'7 x 52.375',
	'7 x 64',
	'8 x 12',
	'8 x 36',
	'8 x 48',
	'8 x 6',
	'8 x 80',
	'9 x 64'
);

var dimensionsValues = Array(
	'13 7/8 x 79',
	'14 x 64',
	'14 x 80',
	'15 21/32 x 39 25/32',
	'20 x 36',
	'20 x 64',
	'20 x 80',
	'21 5/32 x 57 1/4',
	'21 5/8 x 9 3/4',
	'22 x 12',
	'22 x 36',
	'22 x 48',
	'22 x 64',
	'22 x 80',
	'22 x 9',
	'7 1/2 x 18 1/2',
	'7 x 52 3/8',
	'7 x 64',
	'8 x 12',
	'8 x 36',
	'8 x 48',
	'8 x 6',
	'8 x 80',
	'9 x 64'
);

var picsExceptions = Array(
	'Plis-en-J_articleVisuelPhotos.jpg',
	'Couvercle-de-PVC_articleVisuelPhotos.jpg'
);

var h4Exceptions = Array();
h4Exceptions[0] = Array('Collection Novasecure+ : parce que la sécurité, c’est joliment important !', 50);
h4Exceptions[1] = Array('Novasecure collection: Beautifully secure-because security is vitally important!', 50);
h4Exceptions[2] = Array('Stores horizontaux rétractables entre le verre', 75);
h4Exceptions[3] = Array('Test de cyclage des stores rétractables en laboratoire', 70);
h4Exceptions[4] = Array('Horizontal raise/lower blinds between the glass', 70);
h4Exceptions[5] = Array('Laboratory cycle test for the retractable blinds', 70);

var knownExtensions = Array('avi', 'flv', 'mpeg', 'doc', 'docx', 'xls', 'xlsx', 'gif', 'jpg', 'jpeg', 'png', 'pdf');

var iconsPath = '/design/fr/images/';

/**
 * Converts the references' array to an HTML table
 * 
 * @param Array params Array of references
 * @param Dom Object destElt Container which will store the result
 */
function refArray2Table(params, destElt, nbColsMax, tableWidth){
	// Loads texts
	if (lang == 'fr'){
		var texts = translations[0];
		var unity = frUnity;
	}else{
		var texts = translations[1];
		var unity = enUnity;
	}
	
	var data = params['data'];
	var dataTitles = params['titles'];
	var dataImages = params['images'];
	var dataLabels = params['labels'];
	if (typeof nbColsMax == 'undefined') {
		var nbColsMax = 4;
	}
	var nbRows = dataLabels.length;
	var nbCols = dataTitles.length - 1;
	
	// Calcs the number of tables to display (depends on the number of columns VS the number
	// of dimensions)
	var nbTables = parseInt(nbCols / nbColsMax);
	var mod = nbCols % nbColsMax;
	
	if(mod > 0){
		nbTables++;
	}
	
	// Calcs the columns' width
	var pct = parseInt(100 / (nbColsMax + 1));
	var pctWidth = pct + '%';
	
	var iTables = 0;
	var iCols = 0;
	
	// Builds the tables
	while(iTables < nbTables){
		var startCol = iTables * nbColsMax + 1;
		var endCol = startCol + nbColsMax - 1;
		var last = 1;
		
		// Builds the table
		var table = document.createElement("table");
		var body = document.createElement("tbody");
		
		if (typeof tableWidth != 'undefined') {
			//table.setAttribute('style', 'width:' + tableWidth + 'px');
			table.style.width = tableWidth + 'px';
		}
		
		// Image main cell
		var rowImage = document.createElement("tr");
		var cell = document.createElement("td");
		cell.appendChild(document.createTextNode(texts[0]));
		cell.setAttribute('width', pctWidth);
		//cell.setAttribute('style', 'border-left:1px solid #000000;border-right:1px solid #000000;border-top:1px solid #000000');
		cell.style.borderLeft = '1px solid #000000';
		cell.style.borderRight = '1px solid #000000';
		cell.style.borderTop = '1px solid #000000';
		cell.className = 'borderPrint';
		rowImage.appendChild(cell);
		
		// Title main cell
		var rowTitle = document.createElement("tr");
		var cell = document.createElement("td");
		cell.appendChild(document.createTextNode(texts[1]));
		//cell.setAttribute('style', 'border-left:1px solid #000000;border-right:1px solid #000000;background-color:#D7D7D9');
		cell.style.borderLeft = '1px solid #000000';
		cell.style.borderRight = '1px solid #000000';
		cell.className = 'borderPrint';
		cell.style.backgroundColor = '#D7D7D9';
		rowTitle.appendChild(cell);
		
		// Builds the first 2 lines (dimensions and image)
		var noStyleCol = Array();
		
		for(k = startCol ; k <= endCol ; k++){
			if (k <= nbCols) {
				if (typeof dataTitles[k] != 'undefined') {
					noStyleCol[k] = false;
					
					// Image
					var cell = document.createElement("td");
					var img = document.createElement("img");
					img.src = dataImages[k];
					cell.appendChild(document.createTextNode(''));
					var tmp = cell.firstChild;
					cell.replaceChild(img, tmp);
					//cell.setAttribute('class', 'border-right');
					cell.setAttribute('width', pctWidth);
					//cell.setAttribute('style', 'border-top:1px solid #000000;align:center');
					cell.style.borderRight = '1px solid #000000';
					cell.style.borderTop = '1px solid #000000';
					cell.style.textAlign = 'center';
					cell.className = 'borderPrint';
					rowImage.appendChild(cell);
					
					// Label
					var label = getDimensionForDisplay(dataTitles[k]);
					
					// Sets the sup values
					var tmpLabel = label.split(' x ');
					var tmpLabel1 = tmpLabel[0].split(' ');
					var tmpLabel2 = tmpLabel[1].split(' ');
					
					// If sup values, there's a ' '
					if(tmpLabel1.length  > 1){
						label = tmpLabel1[0] + '<sup>' + tmpLabel1[1] + '</sup>' + unity;
					}else{
						label = tmpLabel1 + unity;
					}
					if(tmpLabel2.length > 1){
						label += ' x ' + tmpLabel2[0] + '<sup>' + tmpLabel2[1] + '</sup>' + unity;
					}else{
						label += ' x ' + tmpLabel2 + unity;
					}
					
					var cell = document.createElement("td");
					var span = document.createElement("span");
					span.innerHTML = label;
					span.style.whiteSpace = 'nowrap';
					cell.appendChild(document.createTextNode(''));
					var tmp = cell.firstChild;
					cell.replaceChild(span, tmp);
					//cell.appendChild(document.createTextNode(dataTitles[k]));
					
					//cell.setAttribute('style', 'background-color:#D7D7D9');
					//cell.setAttribute('class', 'border-right');
					cell.style.borderRight = '1px solid #000000';
					cell.className = 'borderPrint';
					cell.style.backgroundColor = '#D7D7D9';
					rowTitle.appendChild(cell);
				}
			}else{
				// When no dimension
				noStyleCol[k] = true;
				
				// Image
				var cell = document.createElement("td");
				cell.setAttribute('width', pctWidth);
				rowImage.appendChild(cell);
				
				// Label
				var cell = document.createElement("td");
				rowTitle.appendChild(cell);
			}
		}
		body.appendChild(rowImage);
		body.appendChild(rowTitle);
		
		// Adds rows
		for(i = 1 ; i < nbRows ; i++){
			// Row
			var hasValues = false;
			
			if (typeof data[i] != 'undefined') {
				var row = document.createElement("tr");
				var cell = document.createElement("td");
				var rowMod = i % 2;
				var label = displayLanguage(dataLabels[i]);
				
				label = label.replace('Low E + Argon', 'Low&nbsp;E&nbsp;+&nbsp;Argon');
				
				var labelSpan = document.createElement('span');
				labelSpan.innerHTML = label;
				cell.appendChild(labelSpan);
				//cell.setAttribute('class', 'border-right');
				cell.style.borderRight = '1px solid #000000';
				cell.className = 'borderPrint';
					
				if(rowMod == 0){
					//cell.setAttribute('bgcolor', '#F5F5F6');
					cell.style.backgroundColor = '#F5F5F6';
				}
				
				if (i == (nbRows - 1) || !hasNextLine(data, i, startCol, endCol, nbRows)) {
					//cell.setAttribute('style', 'border-bottom:1px solid #000000;border-left:1px solid #000000');
					cell.style.borderBottom = '1px solid #000000';
					cell.style.borderLeft = '1px solid #000000';
					cell.className = 'borderPrint';
				} else {
					//cell.setAttribute('style', 'border-left:1px solid #000000');
					cell.style.borderLeft = '1px solid #000000';
				}
				row.appendChild(cell);
				
				// Gets the max column number with data in order to display properly
				var maxColData = 0;
				for(j = startCol; j <= endCol; j++){
					if (typeof data[i] != 'undefined' && typeof data[i][j] != 'undefined' && data[i][j] != '') {
						maxColData = i;
					}
				}
				
				// Adds the columns with references
				for (j = startCol; j <= endCol; j++) {
					if (j <= nbCols) {
						if (typeof data[i] != 'undefined' && typeof data[i][j] != 'undefined' && data[i][j] != '') {
							var cell = document.createElement("td");
							var text = displayLanguage(data[i][j]);
							
							// If nothing, sets a default value
							if(text == ''){
								text = '-';
							}
							
							// Gets the translation
							cell.appendChild(document.createTextNode(text));
							hasValues = true;
						} else if (hasValues === true || i <= maxColData) {
							// No value in the column, but other values in the row
							var cell = document.createElement("td");
							cell.appendChild(document.createTextNode('-'));
						}
						//cell.setAttribute('class', 'border-right');
						cell.style.borderRight = '1px solid #000000';
						cell.className = 'borderPrint';
						
						if (i == (nbRows - 1) || !hasNextLine(data, i, startCol, endCol, nbRows)) {
							//cell.setAttribute('style', 'border-bottom:1px solid #000000');
							cell.style.borderBottom = '1px solid #000000';
						}
					} else {
						// Empty column
						var cell = document.createElement("td");
						cell.appendChild(document.createTextNode(''));
					}
					
					if(noStyleCol[j] === false && rowMod == 0){
						//cell.setAttribute('bgcolor', '#F5F5F6');
						cell.style.backgroundColor = '#F5F5F6';
					}
					row.appendChild(cell);
				}
				
				// If there are values for the line, adds it to the Dom
				if(hasValues === true){
					body.appendChild(row);
					last = i;
				}
			}
		}
		
		// If the last line number is under the max, adds the border
		if (last < (nbRows - 1)) {
			//table.setAttribute('style', 'border-bottom:1px solid #000000');
		}
		
		table.appendChild(body);
		table.setAttribute('class', 'fiches-techniques');
		table.setAttribute('cellspacing', '0');
		table.setAttribute('cellpadding', '0');
		
		// For IE7 not to add spacing between the cells
		table.style.borderCollapse = 'collapse';
		
		// Adds the table to the container
		destElt.appendChild(table);
		
		iTables++;
	}
}

/**
 * Checks if the current line has a line after
 * 
 * @param Array data Table's data
 * @param int i Current line
 * @param int startCol Start column
 * @param int endCol End column
 * @return bool
 */
function hasNextLine(data, i, startCol, endCol, nbRows){
	var hasValue = false;
	
	for(var k = i + 1 ; k <= nbRows ; k++){
		for(var j = startCol ; j <= endCol ; j++){
			if(typeof data[k][j] != 'undefined'){
				hasValue = true;
			}
		}
	}
	return(hasValue);
}

/**
 * Builds the dimensions' pics' lis
 * 
 * @param Array params Array of references
 * @param Dom Object destElt Container which will store the result
 */
function refArray2DimPics(params, destElt){
	var data = params['data'];
	var dataTitles = params['titles'];
	var dataImages = params['images'];
	var nbCols = dataTitles.length - 1;
	
	// Builds the tables
	for (var i = 1 ; i <= nbCols ; i++) {
		var li = document.createElement("li");
		var img = document.createElement("img");
		img.src = dataImages[i];
		li.appendChild(document.createTextNode(''));
		var tmp = li.firstChild;
		li.replaceChild(img, tmp);
		destElt.appendChild(li);
	}
}

/**
 * Function : dump()
 * Arguments: The data - array,hash(associative array),object
 *	The level - OPTIONAL
 * Returns  : The textual representation of the array.
 * This function was inspired by the print_r function of PHP.
 * This will accept some data as the argument and return a
 * text that will be a more readable version of the
 * array/hash/object that is given.
 * Docs: http://www.openjs.com/scripts/others/dump_function_php_print_r.php
 */
function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "	";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

/**
 * Gets the dimension which will be displayed
 * 
 * @param string name Name from ezPublish
 * @return string
 */
function getDimensionForDisplay(name){
	var j = -1;
	var result = '';
	name = trim(name);
	name = name.replace(',', '.');
	name = name.replace(',', '.');
	
	for(var i = 0 ; i < dimensionsNames.length ; i++){
		if(dimensionsNames[i] == name){
			j = i;
			break;
		}
	}
	
	if(j > -1){
		result = dimensionsValues[j];
	}
	
	// Debug
	if(result == ''){
		alert('No match form : ' + name);
	}
	return(result);
}

/**
 * Builds the lang links (FR / EN)
 */
function setLangLinks(){
	var tags = document.getElementsByClassName('langLink');
	var url = document.location.href;
	var tmp = url.split('http://');
	var tmp = tmp[1].split('/');
	var domain = tmp[0];
	var lang = tmp[1];
	var langFound = false;
	
	if (tmp[1] == 'fr') {
		val = 'en';
		langFound = true;
	}else if(tmp[1] == 'en'){
		val = 'fr';
		langFound = true;
	}else{
		val = 'fr';
	}
	
	var result = 'http://' + domain + '/' + val + '/';
	
	for(var j = 2 ; j < tmp.length ; j++){
		var val = tmp[j];
		result += val;
		
		if(j < tmp.length - 1){
			result += '/';
		}
	}
	
	for(var i = 0 ; i < tags.length ; i++){
		document.getElementById(tags[i].id).href = result;
	}
}

/**
 * Adapts te line-height to make sIFR displayed properly
 * 
 * @param string className Elt's class or tag (h1, h2...)
 * @param int nbCharsLine Number of chars per line max
 * @param int lineHeight Height for 1 line text
 */
function sIFRAdapt(className, nbCharsLine, lineHeight){
	if (className.length == 2) {
		var tags = document.getElementsByTagName(className);
	} else {
		var tags = document.getElementsByClassName(className);
	}
	var height = lineHeight;
	
	for (var i = 0; i < tags.length; i++) {
		var str = stripTags(tags[i].innerHTML);
		var len = str.length;
		
		// More than 2 lines
		//alert(len);
		if (len > nbCharsLine) {
			var nb = parseInt(len / nbCharsLine);
			var mod = len % nbCharsLine;
			
			if (mod > 0) {
				nb++;
			}
			//alert(nb);
			height = lineHeight * nb;
		}else if(len <= nbCharsLine){
			height = lineHeight;
		}
		//alert(height);
		
		// Exceptions
		for(var j = 0 ; j < h4Exceptions.length ; j++){
			//alert(str +'=='+ h4Exceptions[j][0]);
			var tmp = str.split(h4Exceptions[j][0]);
			if(tmp.length > 1){
				height = h4Exceptions[j][1];
			}
		}
		
		tags[i].style.lineHeight = height + 'px';
	}
}

/**
 * Sets a specific height for some pictures in the page Article
 * 
 * @param int height Image's height
 */
function picturesExceptions(height){
	var pics = document.getElementsByTagName('img');
	
	// Deals with the right elements
	for(var i = 0 ; i < pics.length ; i++){
		var tmp = pics[i].src.split('/');
		var file = tmp[tmp.length - 1];
		
		for(var j = 0 ; j < picsExceptions.length ; j++){
			if(trim(picsExceptions[j]) == file){
				pics[i].parentNode.style.textAlign = 'right';
				pics[i].height = height;
			}
		}
	}
}

/**
 * Extract the right translation from a multilingual string (pattern : "FR / EN")
 * If elt is set, it will receive the result
 * If not, the value is returned
 * 
 * @param string string Multilingual string
 * @param DOM Object elt Container
 */
function displayLanguage(string, elt){
	var tmp = string.split('/');
	var result = '';
	
	if(lang == 'fr'){
		var i = 0;
	}else{
		var i = 1;
	}
	
	if(typeof tmp[i] == 'undefined'){
		//alert('No translation in "' + lang + '" for "' + string + '"');
		
		if(i == 0){
			i = 1;
		}else{
			i = 0;
		}
		
		if(typeof tmp[i] == 'undefined'){
			//alert('No translation found for "' + string + '"');
		}else{
			result = trim(tmp[i]);
		}
	}else{
		result = trim(tmp[i]);
	}
	
	if (null != elt) {
		elt.innerHTML = result;
	}else{
		return(result);
	}
}

function stripTags(strMod) {
	if(arguments.length<3) strMod=strMod.replace(/<\/?(?!\!)[^>]*>/gi, '');
	else{
		var IsAllowed=arguments[1];
		var Specified=eval("["+arguments[2]+"]");
		if(IsAllowed){
			var strRegExp='</?(?!(' + Specified.join('|') + '))\b[^>]*>';
			strMod=strMod.replace(new RegExp(strRegExp, 'gi'), '');
		}else{
			var strRegExp='</?(' + Specified.join('|') + ')\b[^>]*>';
			strMod=strMod.replace(new RegExp(strRegExp, 'gi'), '');
		}
	}
	return strMod;
}

document.getElementsByClassName = function(class_name) {
	var docList = this.all || this.getElementsByTagName('*');
	var matchArray = new Array();

	/*Create a regular expression object for class*/
	var re = new RegExp("(?:^|\\s)"+class_name+"(?:\\s|$)");
	for (var i = 0; i < docList.length; i++) {
		if (re.test(docList[i].className) ) {
			matchArray[matchArray.length] = docList[i];
		}
	}

	return matchArray;
}

function sortOrdersBy(field){
	document.customer_list.sort_by.value = field;
	document.customer_list.submit();
}

function getDifferenceImage(section){
	switch(section){
		case 'Thermacrystal':
				result = 'thermacrystal';
		break;
		
		case 'Serigraphie':
		case 'Silkscreen':
			result = 'serigraphie';
		break;
		
		case 'Thermoformee':
		case 'Thermoformed':
			result = 'thermoformee';
		break;
		
		case 'Guillotine':
		case 'Venting-Units':
			result = 'guillotine';
		break;
		
		case 'Stores-integres':
		case 'Raise-Lower-Mini-Blinds':
			result = 'stores-integres';
		break;
		
		case 'Intimite':
		case 'Total-Privacy-Collection':
			result = 'intimite';
		break;
		
		case 'Verre-clair':
		case 'Clear-Glass':
			result = 'verre-clair';
		break;
		
		case 'Carrelage':
		case 'Internal-Grill':
			result = 'carrelage';
		break;
		
		default:
			result = 'vitrail';
		break;
	}
	return(result);
}

function getDifferenceLinks(section){
	switch(section){
		case 'Thermacrystal':
			if(lang == 'en'){
				result = 'of-the-Thermacrystal-collection';
			}else{
				result = 'de-la-collection-Thermacrystal';
			}
		break;
		
		case 'Serigraphie':
			result = 'des-verres-serigraphies';
		break;
		
		case 'Silkscreen':
			result = 'of-silkscreened-doorglass';
		break;
		
		case 'Thermoformee':
			result = 'des-verres-thermoformes';
		break;
		
		case 'Thermoformed':
			result = 'of-thermoformed-glass';
		break;
		
		case 'Guillotine':
			result = 'des-fenetres-a-guillotine';
		break;
		
		case 'Venting-Units':
			result = 'Benefits-of-Novatech-s-venting-doorglass-units';
		break;
		
		case 'Stores-integres':
			result = 'du-store-integre-retractable';
		break;
		
		case 'Raise-Lower-Mini-Blinds':
			result = 'of-the-integrated-raise-lower-mini-blind';
		break;
		
		case 'Venting-Units':
			result = 'Benefits-of-Novatech-s-venting-doorglass-units';
		break;
		
		case 'Intimite':
			result = 'des-verres-rainures';
		break;
		
		case 'Total-Privacy-Collection':
			result = 'Benefits-of-V-grooved-decorative-doorglass';
		break;
		
		case 'Verre-clair':
		case 'Carrelage':
			result = 'du-verre-clair-et-des-carrelages';
		break;
		
		case 'Clear-Glass':
		case 'Internal-Grill':
			result = 'of-clear-glass-doorglass-and-internal-grills';
		break;
		
		case 'Stained-glass':
			result = 'of-stained-glass-doorglass';
		break;
		
		default:
			result = 'des-vitraux';
		break;
	}
	return(result);
}

function setLineHeight(tag, lineHeight){
	var elts = document.getElementsByTagName(tag);
	
	for(var i = 0 ; i < elts.length ; i++){
		elts[i].style.lineHeight = lineHeight;
	}
}

/**
 * Executes a command when the user presses enter
 * 
 * @param string
 *				type Type of action (form submission, function call,
 *				redirection)
 * @param string
 *				action Action to perform
 * @param ev
 *				Event
 */
function chkEnter(type, action, ev) {
	 if (window.event) {
		// IE
		e = window.event;
		var code = e.keyCode;
	} else {
		// Others
		var code = ev.keyCode;
	}

	if (code == 13) {
		if (type == 'form') {
			eval('document.' + action).submit();
		} else if (type == 'function') {
			eval(action);
		} else if (type == 'url') {
			document.location = action;
		}
	}
}

function disableEnterKey(e){
	var key;	 
	
	if (window.event) {
		key = window.event.keyCode; //IE
	} else {
		key = e.which; //firefox
	}	 
	
	return (key != 13);
}

function BuildFoldersLinks(){
	var tags = document.getElementsByClassName('mediaFolder');
	var url = document.location.href;
	var tmp = url.split('/');
	var parentLink = '';
	
	// Checks if we need a parent link
	var tmpParent = url.split('/Photos-Medias/');
	
	if(tmpParent.length == 2){
		var tmpParent2 = tmpParent[1].split('/');
		
		for(var i = 0 ; i < tmpParent2.length - 3 ; i++){
			if(tmpParent2[i] != ''){
				parentLink +=  '/' + tmpParent2[i];
			}
		}
		document.getElementById('aParentLink').href = tmpParent[0] + '/Photos-media' + parentLink + '/(extranet)/1';
		document.getElementById('parentLink').style.display = 'inline';
	}
	
	for(var i = 0 ; i < tags.length ; i++){
		var folder = trim(tags[i].rel);
		var testSpace = folder.split(' ');
		
		// Replaces ' ' by '-' for ezPublish compatibility
		while(testSpace.length > 1){
			folder = folder.replace(' ', '-');
			testSpace = folder.split(' ');
		}
		
		folder = folder.replace(/à/g,"a");
		folder = folder.replace(/â/g,"a");
		folder = folder.replace(/â/g,"a");
		folder = folder.replace(/æ/g,"e");
		folder = folder.replace(/é/g,"e");
		folder = folder.replace(/ê/g,"e");
		folder = folder.replace(/ë/g,"e");
		folder = folder.replace(/è/g,"e");
		folder = folder.replace(/é/g,"e");
		folder = folder.replace(/ï/g,"i");
		folder = folder.replace(/ô/g,"o");
		folder = folder.replace(/ù/g,"u");
		folder = folder.replace(/û/g,"u");
		folder = folder.replace(/ç/g,"c");
		folder = folder.replace(/Á/g,"A");
		folder = folder.replace(/Â/g,"A");
		folder = folder.replace(/Æ/g,"E");
		folder = folder.replace(/È/g,"E");
		folder = folder.replace(/É/g,"E");
		folder = folder.replace(/Ê/g,"I");
		folder = folder.replace(/Ï/g,"I");
		folder = folder.replace(/Ô/g,"O");
		folder = folder.replace(/Ù/g,"U");
		folder = folder.replace(/Û/g,"U");
		folder = folder.replace(/Ç/g,"C");
		
		url = url.replace('/(extranet)/1', '');
		folder += '/(extranet)/1';
		
		if(tmp[tmp.length - 1] == ''){
			tags[i].href = url + folder;
		}else{
			tags[i].href = url + '/' + folder;
		}
	}
}

function buildFilesIcons(){
	var tags = document.getElementsByClassName('fileIcon');
	
	for (var i = 0; i < tags.length; i++) {
		var id = tags[i].id;
		var tmp = id.split('_');
		var a = document.getElementById('fileLink_' + tmp[1]);
		var src = a.href;
		var maxWidth = a.rel;
		
		var ext = getExtension(src);
		
		if(ext == 'img'){
			var dimensions = getImgSize(src);
			
			tags[i].src = src;
			
			if(dimensions[0] > dimensions[1]){
				tags[i].width = maxWidth;
			}else{
				tags[i].height = maxWidth;
			}
		}else if(in_array(ext, knownExtensions)){
			tags[i].src = iconsPath + 'icon_' + ext + '.gif';
		}else{
			tags[i].src = iconsPath + 'icon_default.gif';
		}
	}
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function replacesSeps(){
	var tags = document.getElementsByClassName('labelMedia');
	
	for (var i = 0; i < tags.length; i++) {
		var tmp1 = trim(tags[i].innerHTML);
		var tmp = tmp1.split('_');
		
		while(tmp.length > 1){
			tags[i].innerHTML = tags[i].innerHTML.replace('_', ' ');
			tmp = tags[i].innerHTML.split('_');
		}
	}
	
	for (var i = 0; i < tags.length; i++) {
		var tmp1 = trim(tags[i].innerHTML);
		var tmp = tmp1.split('-');
		
		while(tmp.length > 1){
			tags[i].innerHTML = tags[i].innerHTML.replace('-', ' ');
			tmp = tags[i].innerHTML.split('-');
		}
	}
}

function getExtension(src){
	var tmp = src.split('.');
	var max = tmp.length - 1;
	var ext = tmp[max];
	
	/* To display a thumb with the actual images
		if (tmp[max] == 'gif' ||
			tmp[max] == 'jpg' ||
			tmp[max] == 'jpeg' ||
			tmp[max] == 'png') {
			ext = 'img';
		}
	*/
	
	return(ext);
}

function getImgSize(imgSrc){
	var dimensions = Array();
	var newImg = new Image();
	newImg.src = imgSrc;
	
	dimensions[0] = newImg.width;
	dimensions[1] = newImg.height;
	
	return(dimensions);
}

function  in_array (needle, haystack, argStrict) {
	// Checks if the given value exists in the array 
	//
	// version: 911.718
	// discuss at: http://phpjs.org/functions/in_array
	// +	original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +	improved by: vlado houba
	// +	input by: Billy
	// +	bugfixed by: Brett Zamir (http://brett-zamir.me)
	// *	example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
	// *	returns 1: true
	// *	example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
	// *	returns 2: false
	// *	example 3: in_array(1, ['1', '2', '3']);
	// *	returns 3: true
	// *	example 3: in_array(1, ['1', '2', '3'], false);
	// *	returns 3: true
	// *	example 4: in_array(1, ['1', '2', '3'], true);
	// *	returns 4: false
	var key = '', strict = !!argStrict;
	
	if (strict) {
		for (key in haystack) {
			if (haystack[key] === needle) {
				return true;
			}
		}
	} else {
		for (key in haystack) {
			if (haystack[key] == needle) {
				return true;
			}
		}
	}
	
	return false;
}

function updateDesignExample(cpt){
	var elt = document.getElementById('aThumb_' + cpt);
	
	if(elt != null){
		document.getElementById('photoExample').src = elt.rel;
		
		// HIdes all the descriptions
		var tags = document.getElementsByClassName('exampleDescription');
		
		for (var i = 0; i < tags.length; i++) {
			tags[i].style.display = 'none';
		}
		document.getElementById('spanExample_' + cpt).style.display = 'block';
	}else{
		document.getElementById('divDesignExamples').style.display = 'none';
	}
}

function cleanInput(elt, defaultText){
	var text = elt.value;
	
	if(text == defaultText){
		elt.value = '';
	}
}

function restoreInput(elt, defaultText){
	var text = elt.value;
	
	if(text == ''){
		elt.value = defaultText;
	}
}

/**
 * Equivalent of PHP html_encode function
 * Replaces the characters by HTML entities
 * 
 * @param string str String to be decoded
 * @return string
 */
function HTMLEncode(str){
	var div = document.createElement('div');
	var text = document.createTextNode(str);
	
	div.appendChild(text);
	
	var result = div.innerHTML;
	
	return(result);
}

/**
 * Equivalent of PHP html_decode function
 * Replaces HTML entities by real character
 * 
 * @param string str String to be decoded
 * @return string
 */
function HTMLDecode(str){
	var result = "";
	
	if (str == null) {
	  	return;
	  }

	var l = str.length;

	for (var i=0; i<l; i++){
		var ch = str.charAt(i);

		if (ch == '&'){
			var semicolonIndex = str.indexOf(';', i+1);
		
		if (semicolonIndex > 0){
				var entity = str.substring(i + 1, semicolonIndex);
				
				if (entity.length > 1 && entity.charAt(0) == '#'){
					if (entity.charAt(1) == 'x' || entity.charAt(1) == 'X')
						ch = String.fromCharCode(eval('0'+entity.substring(1)));
					else
						ch = String.fromCharCode(eval(entity.substring(1)));
				}else{
					switch (entity){
						case 'quot': ch = String.fromCharCode(0x0022); break;

						case 'amp': ch = String.fromCharCode(0x0026); break;

						case 'lt': ch = String.fromCharCode(0x003c); break;

						case 'gt': ch = String.fromCharCode(0x003e); break;

						case 'nbsp': ch = String.fromCharCode(0x00a0); break;

						case 'iexcl': ch = String.fromCharCode(0x00a1); break;

						case 'cent': ch = String.fromCharCode(0x00a2); break;

						case 'pound': ch = String.fromCharCode(0x00a3); break;

						case 'curren': ch = String.fromCharCode(0x00a4); break;

						case 'yen': ch = String.fromCharCode(0x00a5); break;

						case 'brvbar': ch = String.fromCharCode(0x00a6); break;

						case 'sect': ch = String.fromCharCode(0x00a7); break;

						case 'uml': ch = String.fromCharCode(0x00a8); break;

						case 'copy': ch = String.fromCharCode(0x00a9); break;

						case 'ordf': ch = String.fromCharCode(0x00aa); break;

						case 'laquo': ch = String.fromCharCode(0x00ab); break;

						case 'not': ch = String.fromCharCode(0x00ac); break;

						case 'shy': ch = String.fromCharCode(0x00ad); break;

						case 'reg': ch = String.fromCharCode(0x00ae); break;

						case 'macr': ch = String.fromCharCode(0x00af); break;

						case 'deg': ch = String.fromCharCode(0x00b0); break;

						case 'plusmn': ch = String.fromCharCode(0x00b1); break;

						case 'sup2': ch = String.fromCharCode(0x00b2); break;

						case 'sup3': ch = String.fromCharCode(0x00b3); break;

						case 'acute': ch = String.fromCharCode(0x00b4); break;

						case 'micro': ch = String.fromCharCode(0x00b5); break;

						case 'para': ch = String.fromCharCode(0x00b6); break;

						case 'middot': ch = String.fromCharCode(0x00b7); break;

						case 'cedil': ch = String.fromCharCode(0x00b8); break;

						case 'sup1': ch = String.fromCharCode(0x00b9); break;

						case 'ordm': ch = String.fromCharCode(0x00ba); break;

						case 'raquo': ch = String.fromCharCode(0x00bb); break;

						case 'frac14': ch = String.fromCharCode(0x00bc); break;

						case 'frac12': ch = String.fromCharCode(0x00bd); break;

						case 'frac34': ch = String.fromCharCode(0x00be); break;

						case 'iquest': ch = String.fromCharCode(0x00bf); break;

						case 'Agrave': ch = String.fromCharCode(0x00c0); break;

						case 'Aacute': ch = String.fromCharCode(0x00c1); break;

						case 'Acirc': ch = String.fromCharCode(0x00c2); break;

						case 'Atilde': ch = String.fromCharCode(0x00c3); break;

						case 'Auml': ch = String.fromCharCode(0x00c4); break;

						case 'Aring': ch = String.fromCharCode(0x00c5); break;

						case 'AElig': ch = String.fromCharCode(0x00c6); break;

						case 'Ccedil': ch = String.fromCharCode(0x00c7); break;

						case 'Egrave': ch = String.fromCharCode(0x00c8); break;

						case 'Eacute': ch = String.fromCharCode(0x00c9); break;

						case 'Ecirc': ch = String.fromCharCode(0x00ca); break;

						case 'Euml': ch = String.fromCharCode(0x00cb); break;

						case 'Igrave': ch = String.fromCharCode(0x00cc); break;

						case 'Iacute': ch = String.fromCharCode(0x00cd); break;

						case 'Icirc': ch = String.fromCharCode(0x00ce ); break;

						case 'Iuml': ch = String.fromCharCode(0x00cf); break;

						case 'ETH': ch = String.fromCharCode(0x00d0); break;

						case 'Ntilde': ch = String.fromCharCode(0x00d1); break;

						case 'Ograve': ch = String.fromCharCode(0x00d2); break;

						case 'Oacute': ch = String.fromCharCode(0x00d3); break;

						case 'Ocirc': ch = String.fromCharCode(0x00d4); break;

						case 'Otilde': ch = String.fromCharCode(0x00d5); break;

						case 'Ouml': ch = String.fromCharCode(0x00d6); break;

						case 'times': ch = String.fromCharCode(0x00d7); break;

						case 'Oslash': ch = String.fromCharCode(0x00d8); break;

						case 'Ugrave': ch = String.fromCharCode(0x00d9); break;

						case 'Uacute': ch = String.fromCharCode(0x00da); break;

						case 'Ucirc': ch = String.fromCharCode(0x00db); break;

						case 'Uuml': ch = String.fromCharCode(0x00dc); break;

						case 'Yacute': ch = String.fromCharCode(0x00dd); break;

						case 'THORN': ch = String.fromCharCode(0x00de); break;

						case 'szlig': ch = String.fromCharCode(0x00df); break;

						case 'agrave': ch = String.fromCharCode(0x00e0); break;

						case 'aacute': ch = String.fromCharCode(0x00e1); break;

						case 'acirc': ch = String.fromCharCode(0x00e2); break;

						case 'atilde': ch = String.fromCharCode(0x00e3); break;

						case 'auml': ch = String.fromCharCode(0x00e4); break;

						case 'aring': ch = String.fromCharCode(0x00e5); break;

						case 'aelig': ch = String.fromCharCode(0x00e6); break;

						case 'ccedil': ch = String.fromCharCode(0x00e7); break;

						case 'egrave': ch = String.fromCharCode(0x00e8); break;

						case 'eacute': ch = String.fromCharCode(0x00e9); break;

						case 'ecirc': ch = String.fromCharCode(0x00ea); break;

						case 'euml': ch = String.fromCharCode(0x00eb); break;

						case 'igrave': ch = String.fromCharCode(0x00ec); break;

						case 'iacute': ch = String.fromCharCode(0x00ed); break;

						case 'icirc': ch = String.fromCharCode(0x00ee); break;

						case 'iuml': ch = String.fromCharCode(0x00ef); break;

						case 'eth': ch = String.fromCharCode(0x00f0); break;

						case 'ntilde': ch = String.fromCharCode(0x00f1); break;

						case 'ograve': ch = String.fromCharCode(0x00f2); break;

						case 'oacute': ch = String.fromCharCode(0x00f3); break;

						case 'ocirc': ch = String.fromCharCode(0x00f4); break;

						case 'otilde': ch = String.fromCharCode(0x00f5); break;

						case 'ouml': ch = String.fromCharCode(0x00f6); break;

						case 'divide': ch = String.fromCharCode(0x00f7); break;

						case 'oslash': ch = String.fromCharCode(0x00f8); break;

						case 'ugrave': ch = String.fromCharCode(0x00f9); break;

						case 'uacute': ch = String.fromCharCode(0x00fa); break;

						case 'ucirc': ch = String.fromCharCode(0x00fb); break;

						case 'uuml': ch = String.fromCharCode(0x00fc); break;

						case 'yacute': ch = String.fromCharCode(0x00fd); break;

						case 'thorn': ch = String.fromCharCode(0x00fe); break;

						case 'yuml': ch = String.fromCharCode(0x00ff); break;

						case 'OElig': ch = String.fromCharCode(0x0152); break;

						case 'oelig': ch = String.fromCharCode(0x0153); break;

						case 'Scaron': ch = String.fromCharCode(0x0160); break;

						case 'scaron': ch = String.fromCharCode(0x0161); break;

						case 'Yuml': ch = String.fromCharCode(0x0178); break;

						case 'fnof': ch = String.fromCharCode(0x0192); break;

						case 'circ': ch = String.fromCharCode(0x02c6); break;

						case 'tilde': ch = String.fromCharCode(0x02dc); break;

						case 'Alpha': ch = String.fromCharCode(0x0391); break;

						case 'Beta': ch = String.fromCharCode(0x0392); break;

						case 'Gamma': ch = String.fromCharCode(0x0393); break;

						case 'Delta': ch = String.fromCharCode(0x0394); break;

						case 'Epsilon': ch = String.fromCharCode(0x0395); break;

						case 'Zeta': ch = String.fromCharCode(0x0396); break;

						case 'Eta': ch = String.fromCharCode(0x0397); break;

						case 'Theta': ch = String.fromCharCode(0x0398); break;

						case 'Iota': ch = String.fromCharCode(0x0399); break;

						case 'Kappa': ch = String.fromCharCode(0x039a); break;

						case 'Lambda': ch = String.fromCharCode(0x039b); break;

						case 'Mu': ch = String.fromCharCode(0x039c); break;

						case 'Nu': ch = String.fromCharCode(0x039d); break;

						case 'Xi': ch = String.fromCharCode(0x039e); break;

						case 'Omicron': ch = String.fromCharCode(0x039f); break;

						case 'Pi': ch = String.fromCharCode(0x03a0); break;

						case ' Rho ': ch = String.fromCharCode(0x03a1); break;

						case 'Sigma': ch = String.fromCharCode(0x03a3); break;

						case 'Tau': ch = String.fromCharCode(0x03a4); break;

						case 'Upsilon': ch = String.fromCharCode(0x03a5); break;

						case 'Phi': ch = String.fromCharCode(0x03a6); break;

						case 'Chi': ch = String.fromCharCode(0x03a7); break;

						case 'Psi': ch = String.fromCharCode(0x03a8); break;

						case 'Omega': ch = String.fromCharCode(0x03a9); break;

						case 'alpha': ch = String.fromCharCode(0x03b1); break;

						case 'beta': ch = String.fromCharCode(0x03b2); break;

						case 'gamma': ch = String.fromCharCode(0x03b3); break;

						case 'delta': ch = String.fromCharCode(0x03b4); break;

						case 'epsilon': ch = String.fromCharCode(0x03b5); break;

						case 'zeta': ch = String.fromCharCode(0x03b6); break;

						case 'eta': ch = String.fromCharCode(0x03b7); break;

						case 'theta': ch = String.fromCharCode(0x03b8); break;

						case 'iota': ch = String.fromCharCode(0x03b9); break;

						case 'kappa': ch = String.fromCharCode(0x03ba); break;

						case 'lambda': ch = String.fromCharCode(0x03bb); break;

						case 'mu': ch = String.fromCharCode(0x03bc); break;

						case 'nu': ch = String.fromCharCode(0x03bd); break;

						case 'xi': ch = String.fromCharCode(0x03be); break;

						case 'omicron': ch = String.fromCharCode(0x03bf); break;

						case 'pi': ch = String.fromCharCode(0x03c0); break;

						case 'rho': ch = String.fromCharCode(0x03c1); break;

						case 'sigmaf': ch = String.fromCharCode(0x03c2); break;

						case 'sigma': ch = String.fromCharCode(0x03c3); break;

						case 'tau': ch = String.fromCharCode(0x03c4); break;

						case 'upsilon': ch = String.fromCharCode(0x03c5); break;

						case 'phi': ch = String.fromCharCode(0x03c6); break;

						case 'chi': ch = String.fromCharCode(0x03c7); break;

						case 'psi': ch = String.fromCharCode(0x03c8); break;

						case 'omega': ch = String.fromCharCode(0x03c9); break;

						case 'thetasym': ch = String.fromCharCode(0x03d1); break;

						case 'upsih': ch = String.fromCharCode(0x03d2); break;

						case 'piv': ch = String.fromCharCode(0x03d6); break;

						case 'ensp': ch = String.fromCharCode(0x2002); break;

						case 'emsp': ch = String.fromCharCode(0x2003); break;

						case 'thinsp': ch = String.fromCharCode(0x2009); break;

						case 'zwnj': ch = String.fromCharCode(0x200c); break;

						case 'zwj': ch = String.fromCharCode(0x200d); break;

						case 'lrm': ch = String.fromCharCode(0x200e); break;

						case 'rlm': ch = String.fromCharCode(0x200f); break;

						case 'ndash': ch = String.fromCharCode(0x2013); break;

						case 'mdash': ch = String.fromCharCode(0x2014); break;

						case 'lsquo': ch = String.fromCharCode(0x2018); break;

						case 'rsquo': ch = String.fromCharCode(0x2019); break;

						case 'sbquo': ch = String.fromCharCode(0x201a); break;

						case 'ldquo': ch = String.fromCharCode(0x201c); break;

						case 'rdquo': ch = String.fromCharCode(0x201d); break;

						case 'bdquo': ch = String.fromCharCode(0x201e); break;

						case 'dagger': ch = String.fromCharCode(0x2020); break;

						case 'Dagger': ch = String.fromCharCode(0x2021); break;

						case 'bull': ch = String.fromCharCode(0x2022); break;

						case 'hellip': ch = String.fromCharCode(0x2026); break;

						case 'permil': ch = String.fromCharCode(0x2030); break;

						case 'prime': ch = String.fromCharCode(0x2032); break;

						case 'Prime': ch = String.fromCharCode(0x2033); break;

						case 'lsaquo': ch = String.fromCharCode(0x2039); break;

						case 'rsaquo': ch = String.fromCharCode(0x203a); break;

						case 'oline': ch = String.fromCharCode(0x203e); break;

						case 'frasl': ch = String.fromCharCode(0x2044); break;

						case 'euro': ch = String.fromCharCode(0x20ac); break;

						case 'image': ch = String.fromCharCode(0x2111); break;

						case 'weierp': ch = String.fromCharCode(0x2118); break;

						case 'real': ch = String.fromCharCode(0x211c); break;

						case 'trade': ch = String.fromCharCode(0x2122); break;

						case 'alefsym': ch = String.fromCharCode(0x2135); break;

						case 'larr': ch = String.fromCharCode(0x2190); break;

						case 'uarr': ch = String.fromCharCode(0x2191); break;

						case 'rarr': ch = String.fromCharCode(0x2192); break;

						case 'darr': ch = String.fromCharCode(0x2193); break;

						case 'harr': ch = String.fromCharCode(0x2194); break;

						case 'crarr': ch = String.fromCharCode(0x21b5); break;

						case 'lArr': ch = String.fromCharCode(0x21d0); break;

						case 'uArr': ch = String.fromCharCode(0x21d1); break;

						case 'rArr': ch = String.fromCharCode(0x21d2); break;

						case 'dArr': ch = String.fromCharCode(0x21d3); break;

						case 'hArr': ch = String.fromCharCode(0x21d4); break;

						case 'forall': ch = String.fromCharCode(0x2200); break;

						case 'part': ch = String.fromCharCode(0x2202); break;

						case 'exist': ch = String.fromCharCode(0x2203); break;

						case 'empty': ch = String.fromCharCode(0x2205); break;

						case 'nabla': ch = String.fromCharCode(0x2207); break;

						case 'isin': ch = String.fromCharCode(0x2208); break;

						case 'notin': ch = String.fromCharCode(0x2209); break;

						case 'ni': ch = String.fromCharCode(0x220b); break;

						case 'prod': ch = String.fromCharCode(0x220f); break;

						case 'sum': ch = String.fromCharCode(0x2211); break;

						case 'minus': ch = String.fromCharCode(0x2212); break;

						case 'lowast': ch = String.fromCharCode(0x2217); break;

						case 'radic': ch = String.fromCharCode(0x221a); break;

						case 'prop': ch = String.fromCharCode(0x221d); break;

						case 'infin': ch = String.fromCharCode(0x221e); break;

						case 'ang': ch = String.fromCharCode(0x2220); break;

						case 'and': ch = String.fromCharCode(0x2227); break;

						case 'or': ch = String.fromCharCode(0x2228); break;

						case 'cap': ch = String.fromCharCode(0x2229); break;

						case 'cup': ch = String.fromCharCode(0x222a); break;

						case 'int': ch = String.fromCharCode(0x222b); break;

						case 'there4': ch = String.fromCharCode(0x2234); break;

						case 'sim': ch = String.fromCharCode(0x223c); break;

						case 'cong': ch = String.fromCharCode(0x2245); break;

						case 'asymp': ch = String.fromCharCode(0x2248); break;

						case 'ne': ch = String.fromCharCode(0x2260); break;

						case 'equiv': ch = String.fromCharCode(0x2261); break;

						case 'le': ch = String.fromCharCode(0x2264); break;

						case 'ge': ch = String.fromCharCode(0x2265); break;

						case 'sub': ch = String.fromCharCode(0x2282); break;

						case 'sup': ch = String.fromCharCode(0x2283); break;

						case 'nsub': ch = String.fromCharCode(0x2284); break;

						case 'sube': ch = String.fromCharCode(0x2286); break;

						case 'supe': ch = String.fromCharCode(0x2287); break;

						case 'oplus': ch = String.fromCharCode(0x2295); break;

						case 'otimes': ch = String.fromCharCode(0x2297); break;

						case 'perp': ch = String.fromCharCode(0x22a5); break;

						case 'sdot': ch = String.fromCharCode(0x22c5); break;

						case 'lceil': ch = String.fromCharCode(0x2308); break;

						case 'rceil': ch = String.fromCharCode(0x2309); break;

						case 'lfloor': ch = String.fromCharCode(0x230a); break;

						case 'rfloor': ch = String.fromCharCode(0x230b); break;

						case 'lang': ch = String.fromCharCode(0x2329); break;

						case 'rang': ch = String.fromCharCode(0x232a); break;

						case 'loz': ch = String.fromCharCode(0x25ca); break;

						case 'spades': ch = String.fromCharCode(0x2660); break;

						case 'clubs': ch = String.fromCharCode(0x2663); break;

						case 'hearts': ch = String.fromCharCode(0x2665); break;

						case 'diams': ch = String.fromCharCode(0x2666); break;

						default: ch = ''; break;
					}
				}
				i = semicolonIndex;
			}
		}
		result += ch;
	}
	return result;
}

function removeSpecialCharacters(str){
	var r = str;
	r = r.replace(new RegExp(/[àáâãäå]/g),"a");
	r = r.replace(new RegExp(/æ/g),"ae");
	r = r.replace(new RegExp(/ç/g),"c");
	r = r.replace(new RegExp(/[èéêë]/g),"e");
	r = r.replace(new RegExp(/[ìíîï]/g),"i");
	r = r.replace(new RegExp(/ñ/g),"n");	    
	r = r.replace(new RegExp(/[òóôõö]/g),"o");
	r = r.replace(new RegExp(/œ/g),"oe");
	r = r.replace(new RegExp(/[ùúûü]/g),"u");
	r = r.replace(new RegExp(/[ýÿ]/g),"y");
	
	r = r.replace(new RegExp(/[ÀÁÂÃÄÅ]/g),"A");
	r = r.replace(new RegExp(/[ÈÉÊË]/g),"E");
	r = r.replace(new RegExp(/[ìíîï]/g),"I");
	r = r.replace(new RegExp(/Ñ/g),"N");	    
	r = r.replace(new RegExp(/[ÒÓÔÕÖ]/g),"O");
	r = r.replace(new RegExp(/[ÙÚÛÜ]/g),"U");
	r = r.replace(new RegExp(/[&]/g),"");
	//r = r.replace(new RegExp(/[.]/g),"");
	
	return(r);
}

function string2ezURL(str){
	var tmp = str.split(' ');
	while(tmp.length > 1){
		str = str.replace(' ', '-');
		var tmp = str.split(' ');
	}
	str = removeSpecialCharacters(str);
	
	var tmp = str.split('--');
	while(tmp.length > 1){
		str = str.replace('--', '-');
		var tmp = str.split('--');
	}
	
	// To replace the last character if that's a '.'
	var lastChar = str.substr(str.length - 1, 1);
	if(lastChar == '.'){
		str = str.substr(0, str.length - 1);
	}
	
	return(str);
}

function addOnFocusToA(){
	var as = document.getElementsByTagName('a');
	
	for(var i  =0 ; i < as.length ; i++){
		if (window.addEventListener) { // Mozilla, Netscape, Firefox
			as[i].addEventListener('focus', function(){
				if (this.blur) 
					this.blur()
			}, false);
		}else{
			as[i].attachEvent('focus', function(){
				if (this.blur) 
					this.blur()
			}, false);
		}
	}
}
