
function updateSelect(url, model, col, field, value){
    var pars = col + '=' + value + '&model=' + model + '&column=' + col + '&field=' + field;
    var myAjax = new Ajax.Updater(field,
                                  url,
                                  {
                                      method: 'get',
                                      parameters: pars
                                  }
                                  );
	
}


function submitListOrder(url, list){
	if (!list) list = 'table_sort';
	Modalbox.show('<img src="'+baseUrl+'/media/images/ajax_loading.gif" style="display:block;margin:auto;">', {'title': 'Loading ...', width: document.viewport.getWidth(), height: document.viewport.getHeight()});
	var myAjax = new Ajax.Request(url, {
	      method: "post",
	        onSuccess : function(resp) { setTimeout(function() {
	        	Modalbox.hide();
	        	window.location.reload( true );
	        }, 300); },
            parameters: {data:Sortable.serialize(list)}
          });
	
}


function submitFormWithParams(form){
	// nao preparado para funcionar sem mod_rewrite
	var params = Form.serialize(form, true);
	var url = form.action;
	var urlArray = new Array();
	var query = url.split("/");
	for (i=5; i<query.length; i+=2) {
		if (query[i]+1) urlArray[query[i]] = query[i+1]; 
	}
	for (var param in params){
		if ($(param).value){
			if (isNumber($(param).value) && $(param).value > 0){
				urlArray[param] = $(param).value;
			} else if (!isNumber($(param).value) && $(param).value.length > 0){
				urlArray[param] = $(param).value;
			} else if (urlArray[param]){
				delete urlArray[param];
			}
		} else {
			if (urlArray[param]){
				delete urlArray[param];
			}
		}
	}
	var url = '/'+query[3]+'/'+query[4]+'/';
	for(key in urlArray){
		if (urlArray.hasOwnProperty(key) && urlArray[key]) url += key+'/'+urlArray[key]+'/';
	}
	document.location=url;
	return false;
}


function showModalBox(link, title, filter){
	if (filter){
		link += '&filter='+filter;
		var optionsFilter = filter.split(",");
		optionsFilter.each(function(optionFilter){
			link += '&'+optionFilter+'='+$(optionFilter).value;		
		});
	}
	Modalbox.show(link, {'title': title, 'evalScripts': true});
}

function updateCP(name){
	$(name).value = $(name + '_cp1').value+'-'+$(name + '_cp2').value;
}
function isNumber(numero){
	var CaractereInvalido = false;

	for (i=0; i < numero.length; i++){
		var Caractere = numero.charAt(i);
		if(Caractere != "." && Caractere != "," && Caractere != "-"){
			if (isNaN(parseInt(Caractere))) CaractereInvalido = true;
		}
	}
	return !CaractereInvalido;
}