String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g,'');};

/**
 * Obre una finestra shadowbox amb el mapa de google map
 * @param latitud Latitud 
 * @param longitud Longitud
 * @return void
 */
function openGoogleMaps(latitud, longitud){
	Shadowbox.open({
		player: 'html',
		content: '',
		height: 500,
		width: 700,
		options: {
			onFinish: function(item){
				if(GBrowserIsCompatible()){
					var body = document.getElementById(Shadowbox.contentId());
					var map = new GMap2(body);
					if (latitud == undefined || latitud == "") {
						latitud = 37.4419;
					}
					if (longitud == undefined || longitud == "") {
						longitud = -122.1419;
					}
					map.setCenter(new GLatLng(latitud,longitud ), 13);
					map.addOverlay(new GMarker(new GLatLng(latitud, longitud)));
					map.addControl(new GSmallMapControl());
					map.addControl(new GMapTypeControl());
				}
			}	
		}
	});
}
function wopen(url, name, w, h)
{
  // Fudge factors for window decoration space.
  // In my tests these work well on all platforms & browsers.
  w += 32;
  h += 96;
  wleft = (screen.width - w) / 2;
  wtop = (screen.height - h) / 2;
  // IE5 and other old browsers might allow a window that is
  // partially offscreen or wider than the screen. Fix that.
  // (Newer browsers fix this for us, but let's be thorough.)
  if (wleft < 0) {
    w = screen.width;
    wleft = 0;
  }
  if (wtop < 0) {
    h = screen.height;
    wtop = 0;
  }
  var win = window.open(url,
    name,
    'width=' + w + ', height=' + h + ', ' +
    'left=' + wleft + ', top=' + wtop + ', ' +
    'location=no, menubar=no, ' +
    'status=no, toolbar=no, scrollbars=yes, resizable=no');
  // Just in case width and height are ignored
  win.resizeTo(w, h);
  // Just in case left and top are ignored
  win.moveTo(wleft, wtop);
  win.focus();
}
// Afegeix un missatge d'error al panel d'error
function addError(message) {
	jQuery('#tucarroya_portlets_errors_panel')[0].innerHTML = message;
	jQuery('#tucarroya_portlets_errors_panel').show();
}

//Afegeix un missatge d'error al panel d'error
function clearError() {
	jQuery('#tucarroya_portlets_errors_panel').hide();
	jQuery('#tucarroya_portlets_errors_panel')[0].innerHTML = "";
}
