/* Retorna un objecte etiqueta a partir de 
   l'identificador depenent del navegador */
function getObj(name) {
  if (document.getElementById) {
this.obj= document.getElementById(name);
    this.style=document.getElementById(name).style;
this.obj.charset='UTF-8';
  }
 else if (document.all) {
    this.obj = document.all[name];
    this.style = document.all[name].style;
  }
  else if (document.layers) {
    this.obj = document.layers[name];
    this.style = document.layers[name];
  }
}

/* Retorna un objecte ajax depenent 
   del sistema operatiu i el navegador */
function ajax() {
   req = false;
   if (window.XMLHttpRequest) {
      req = new XMLHttpRequest();
      if (req.overrideMimeType) {
         req.overrideMimeType('text/xml');
      }
   }
   else {
      if (window.ActiveXObject) {
         isIE = true;
         req = new ActiveXObject('Microsoft.XMLHTTP');
      }
   }
   return req;
}

function trim(valor) { 
   primerBlanco = /^ /
   ultimoBlanco = / $/
   variosBlancos = /[ ]+/g
	variosBlancos = /^[\s\t\r\n]+|[\s\t\r\n]+$/g
   valor = valor.replace (variosBlancos," ");
   return valor;
};

function llargadaIntro(textarea,label) {
	var ret = trim(textarea.value);
	var el=document.getElementById(label);
	if (ret.length>=225) {
		ret=ret.slice(0,224);
		el.innerHTML='225';
	} else {
		el.innerHTML=ret.length;	
	}
	textarea.value=ret;
}

function viewElement(element) {
	var el = new getObj(element);
	if (el.style.display=='') {
		el.style.display='none';
	}
	else {
		el.style.display=''
	}
}

//Obre un cuadre modal per els events del calendari
function newWindow(URL,W,H,S) {
 S='YES'
 A=((screen.width)/2)-W/2;
 B=((screen.height)/2)-H/2;
 if (window.showModalDialog) {
 var caracteristicas = 'dialogTop='+B+'px;dialogLeft='+A+'px;dialogWidth='+W+'px;' + 'dialogHeight='+H+'px;center=yes;help=no;font-family:Arial;';
 window.showModalDialog(URL, 'modal', caracteristicas);
 }
 else {
 var caracteristicas = 'height='+H+', width='+W+', toolbar=0, directories=0,' +
 'status=0, linemenubar=0, modal=yes, left='+A+', top='+B+', dialog=yes,' +
 'resizable=no, scrollbars='+S+', status=no,toolbar=no,menubar=no,location=no';
 finestra = window.open(URL,null,caracteristicas);
 finestra.focus();
 }
}