function ajax_updater(url, params, element_id, type) {
	$.ajax({
		type: ((type == "post") ? "post" : "get"),
		processData: true,
		url: url,
		data: params,
		cache: false,
		success: function(data) {
			$("#" + element_id).html(data);
		}
	});
}

function array_unique(arrayName) {
	var newArray = new Array();
	label:for(var i = 0; i < arrayName.length; i++) {
		for (var j = 0; j < newArray.length; j++) {
			if (newArray[j] == arrayName[i])
				continue label;
		}
		newArray[newArray.length] = arrayName[i];
	}
	return newArray;
}

function checkEnter(e){ //e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable

	if (e && e.which) { //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	} else {
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}

	if (characterCode == 13) { //if generated character code is equal to ascii 13 (if enter key)
		document.forms[0].submit(); //submit the form
		return false;
	} else {
		return true;
	}
}

function currencyFormat(strValue) {
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue * 100 + 0.50000000001);
	intCents = dblValue % 100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue / 100).toString();
	if (intCents < 10)
		strCents = "0" + strCents;
	for (var i = 0; i < Math.floor((dblValue.length - (1 + i)) / 3); i++)
		dblValue = dblValue.substring(0, dblValue.length - (4 * i + 3)) + ',' + dblValue.substring(dblValue.length - (4 * i + 3));
	return (((blnSign) ? '' : '-') + '$' + dblValue + '.' + strCents);
}

function currencyFormat2(amount) {
	var i = parseFloat(amount);
	if (isNaN(i)) {
		i = 0.00;
	}
	var minus = '';
	if (i < 0) {
		minus = '-';
	}
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if (s.indexOf('.') < 0) {
		s += '.00';
	}
	if (s.indexOf('.') == (s.length - 2)) {
		s += '0';
	}
	s = minus + s;
	return '$' + s;
}

function cursor_wait() {
  document.body.style.cursor = "wait";
}

function cursor_clear() {
  document.body.style.cursor = "default";
}

function digits(val) {
	if (val.length > 0) {
		var valo = new String();
		var numero = "0123456789.";
		var chars = val.split("");
		for (i = 0; i < chars.length; i++) {
			if (numero.indexOf(chars[i]) != -1)
				valo += chars[i];
		}
		return valo;
	} else {
		return '';
	}
}

function highlight(item, is_true) {
	item.className = (is_true) ? 'error' : '';
}

function highlight_id(id, is_true) {
	highlight(document.getElementById(id), is_true);
}

function in_array_count(needle, haystack) {
	var key = "";
	var count = 0;
	for (key in haystack) {
		if (haystack[key] == needle) {
			count++;
		}
	}
	return count;
}

function is_email(str) {
	var regex = /^[a-z0-9\._-]+@([a-z0-9_-]+\.)+[a-z]{2,6}$/i;
	return regex.test(str);
}

function is_int(x) {
	var y = parseInt(x);
	if (isNaN(y)) return false;
	return x==y && x.toString() == y.toString();
}

function is_valid_date(s) {
	var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
	if (re.test(s)) {
		var d = s.split("/");
		var da = new Date(s);
		return da.getMonth() + 1 == d[0] && da.getDate() == d[1] && da.getFullYear() == d[2];
	} else {
		return false;
	}
}

function left(str, n){
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
		return String(str).substring(0, n);
}

function ltrim(s) {
	var l = 0;
	while (l < s.length && s[l] == ' ')
		l++;
	return s.substring(l, s.length);
}

function rtrim(s) {
	var r = s.length -1;
	while (r > 0 && s[r] == ' ')
		r -= 1;
	return s.substring(0, r + 1);
}

function setfocus(s) {
	document.getElementById(s).focus();
}

function show_dialog(titre, contents, x) {
	if (!(x > 0)) {
		x = "auto";
	}
	$("#dialog").html(contents);
	$("#dialog").data("title.dialog", titre);
	$("#dialog").data("width.dialog", x);
	
	var dia = $("#dialog").dialog({
		title: titre,
		closeOnEscape: true,
		bgiframe: true,
		modal: true,
		resizable: true,
		draggable: true,
		width:x,
		buttons: {
			Ok: function() {
				$(this).dialog('close');
			}
		}
	});

	if (!dia.dialog('isOpen')) {
		dia.dialog('open');
	}
}

function trim(s) {
	return rtrim(ltrim(s));
}