String.prototype.endsWith = function(str)
{return (this.match(str+"$")==str)}

ProgressSender = function (action, method) {
	this.parameters = [];
	this.action = action;
	this.method = method;
	this.names = [];
};

ProgressSender.prototype.setParam = function (name, value) {
	if (value == null)
		this.parameters.push({name: name, value: ''});
	else
		this.parameters.push({name: name, value: value});
	this.names.push(name);
};

ProgressSender.prototype.request = function () {
	var form = this.buildForm ();
	document.body.appendChild (form);
	form.submit();
};

ProgressSender.prototype.buildForm = function () {
	var form = document.createElement('form');
	form.setAttribute('action' , this.action);
	form.setAttribute('method' , this.method);
	
	for(var i=0;i<this.parameters.length;i++){
		form.appendChild (this.createHidden(this.parameters[i].name, this.parameters[i].value));
	}
	
	return form;
};

ProgressSender.prototype.createHidden = function (name, value) {
	var input = document.createElement('input');
	input.setAttribute('type', 'hidden');
	input.value = value;
	input.setAttribute('name' , name);
	input.style.display = 'none';
	return input;
};

ProgressSender.prototype.saveParamsSession = function (action, fn,back_url ) {
	jQuery.post(
		action ,
		{	params : this.parameters,
			back_url: back_url ? back_url : location.href
		},
		function (data) {
			if (fn) {
				fn(data);
			}
		}
	);
};
