$(document).ready(function(){
	$("form").submit(function(){return false;});
});

function setErrorsField(errors, style){	
	var classStyle = (style == undefined ? '.msg-error' : style);	
	if(errors.message != undefined)
		$(classStyle).append(errors.message);
	else
		for(i in errors){	
			if($(classStyle).html() == '')
				$(classStyle).append(errors[i].message);
			else
				$(classStyle).append("<br />"+errors[i].message);
		}

	$(classStyle).fadeIn("slow", function(){
		setTimeout(function(){
			$(classStyle).fadeOut("slow");
		}, 5000);
	});
}

String.prototype.montaCombo = function(url, param, selectedIndex, functionCallback){
	comboName = this;
	objectCombo = document.getElementById(comboName);
	for(var j = objectCombo.length; j > 0 ; j--)
		objectCombo.remove(j);

	if(param != undefined){
		paramSelectedIndex = param + "";
		if(paramSelectedIndex.substr(0,1) != "{")
			selectedIndex = param;
	}

	$.post(url, param, function(data){
		for(var i = 0 ; i < data.montaCombo.length ; i++) {
			var value      =  data.montaCombo[i].value;
			var optionName =  data.montaCombo[i].optionName;

		    if(optionName!=false)
		       objectCombo.options[objectCombo.options.length] = new Option (optionName, value, true, true);
		}
		if(selectedIndex != undefined)
			objectCombo.value = selectedIndex;
		else
			objectCombo.value = "";				
		
		if ($.isFunction(functionCallback))
			functionCallback();
	}, 'json');	
}
