function trim(str) {
	if ((str==null) || (str=="")) {
		return "";
	} else {
		return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	}
}


function count_words(srcId, targetId) {
	var text = $("#"+srcId).val();
	var target = $("#"+targetId);

	var nbWords = 0;
	if (text!=null && text!="") {
		var words = trim(text).split(" ");
		for (i in words) {
			if (trim(words[i]) != "") {
				nbWords++;
			}
		}
	}

	if (nbWords == 1) {
		target.html("1 mot");
	} else if (nbWords > 1) {
		target.html(nbWords + " mots");
	} else {
		target.html("");
	}
}

function setValue(id, value) {
	var element = document.getElementById(id);
	// alert(id + ":" + element.value);
	element.value = value;
	// alert(id + ":" + element.value);
}

function gup(name) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function changeTab() {
    var tab = gup('tab');
	if (tab != "") {
		document.getElementById("tabber").tabber.tabShow(tab);
 	}
}
