
/**
 * submit the form
 */
function submitForm(id){
	$('form#' + id).submit();
}

/**
 * trims the string
 */
var trim = function(aString) {
	return aString.replace(/(?:^\s+|\s+$)/g, "");
}

/**
 * Include the file at the end of the <head> tag
 */
var includeJs = function(url) {
	var scriptElt = document.createElement('script');
	scriptElt.setAttribute('type', 'text/javascript');
	scriptElt.setAttribute('src', url);
	$(scriptElt).appendTo('head');
}

/**
 * Make row highlight in a table
 *
 * @param tableElt the <table> node
 * @param classOdd the odd rows class
 * @param classEven the even rows class
 * @param skipFirstRow 'true' if the first row must be skipped,
 * else 'false'
 */
function makeRowHighlight(tableElt, classOdd, classEven, skipFirstRow) {
	if (tableElt) {
		var expression = 'tbody > tr';

		// if no tbody has been found, we will search for
		// <tr> tags
		if ($('tbody', tableElt).size() <= 0) {
			expression = 'tr';
			
			// if skipFirstRow parameter is set to true, we have to ignore the first
			// row of the table
			if (skipFirstRow == 'true') {
				expression += ':gt(0)';
			}
		}

		$(expression, tableElt).each(function (i) {
			//Odd
			if ((i % 2) != 0) {
				if ($(this).hasClass(classEven)) {
					$(this).removeClass(classEven);
				}
				$(this).addClass(classOdd);
			} else {
				//Even
				if ($(this).hasClass(classOdd)) {
					$(this).removeClass(classOdd);
				}
				$(this).addClass(classEven);
			}
			i++;
		});
	}
}

