/**
 * Function which gets a string and returns it according to id and
 * classes names standards, replacing strange chars and spaces for
 * underscores.
 */
function standardize(str) {
	return replaceDiacritics(Encoder.htmlDecode(str))
		.toLowerCase()
		.replace(/[\s,\/]+/g, '_')
		.replace(/[\(\)]+/g, '')
		.replace(/^_/, '');
}


/**
 * Removes first word of string.
 */
function removeFirstWord(str) {
	return str.substring(str.indexOf(' ') +1);
}


/**
 * Function which removes the main diacritics found in Swedish lang,
 * avoiding the problems that this chars insert when in the id tags
 * of html elements.
 */
function replaceDiacritics(s) {
	var s;

	var diacritics =[
		/[\300-\306]/g, /[\340-\346]/g,  // A, a
		/[\310-\313]/g, /[\350-\353]/g,  // E, e
		/[\314-\317]/g, /[\354-\357]/g,  // I, i
		/[\322-\330]/g, /[\362-\370]/g,  // O, o
		/[\331-\334]/g, /[\371-\374]/g,  // U, u
		/[\321]/g, /[\361]/g, // N, n
		/[\307]/g, /[\347]/g, // C, c
	];

	var chars = ['A','a','E','e','I','i','O','o','U','u','N','n','C','c'];

	for (var i = 0; i < diacritics.length; i++) {
		s = s.replace(diacritics[i],chars[i]);
	}

	return s;
}

/**
 * Strips a string of any HTML tags.
 */
function stripTags(str) {
	if (str)
		return str.replace(/<\/?[^>]+>/gi, '');
	return '';
}

$.extend({URLEncode:function(c){var o='';var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/;
  while(x<c.length){var m=r.exec(c.substr(x));
    if(m!=null && m.length>1 && m[1]!=''){o+=m[1];x+=m[1].length;
    }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);
    o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;},
URLDecode:function(s){var o=s;var binVal,t;var r=/(%[^%]{2})/;
  while((m=r.exec(o))!=null && m.length>1 && m[1]!=''){b=parseInt(m[1].substr(1),16);
  t=String.fromCharCode(b);o=o.replace(m[1],t);}return o;}
});

