		function popupWindow (URL,formName,idField,nameField)   { 			
			eval("page = window.open(URL+'&formName='+formName+'&idField='+idField+'&nameField='+nameField, '1', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=500,left = 0,top = 0');");
			if (page.opener == null) page.opener = self;
			page.focus();
			
		}
		
		function popupAjuda (URL)   { 			
			eval("page = window.open(URL, '1','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=650,height=500,left = 0,top = 0');");
			if (page.opener == null) page.opener = self;
			page.focus();
			
		}

		
		function updateParent(formName,idField,nameField,idValue,nameValue) {
			//variables:
			//   formName: nom del formulari que ha d'actualitzar a la finestra mare
			//   idField: nom del camp de id (normalment numčric) que ha d'actualitzar
			//   nameField: nom del camp de text que ha d'actualtizar
			//   idValue: valor que cal posar al camp numčric
			//   nameValue: valor que cal posar al camp de text
			
			var oForm = opener.document.forms[formName];
		    oForm.elements[idField].value = idValue;
		    oForm.elements[nameField].value = nameValue;
		    
		    self.close();
		    return false;
		}		
	
		function updateParentSelect(formName,idField,nameField,idValue,nameValue) {
			//variables:
			//   formName: nom del formulari que ha d'actualitzar a la finestra mare
			//   idField: nom del camp de id (normalment numčric) que ha d'actualitzar
			//   nameField: nom del camp de text que ha d'actualtizar
			//   idValue: valor que cal posar al camp numčric
			//   nameValue: valor que cal posar al camp de text
			var oForm = opener.document.forms[formName];
			var nuevo2= opener.document.createElement('OPTION');
			
			nuevo2.text=nameValue;
			nuevo2.value=idValue;
			nouElement(oForm.elements[idField].options,nuevo2);

		    self.close();
		    return false;
		}
	
		//función para ańadir elemento usando DOM1 y DOM2
		function nouElement(id,valor) {
			//id és l'objecte on cal afegir, i valor es el que cal afegir
			try {
				id.add(valor,null);
			}
			// ... And if that doesn't work use the IE-only method
			catch (e) {
				id.add(valor,id.length);
			}	  
		}

		//funció per eliminar una opcio d'un select. 
		function treureOpcio(opcio) {
			//variables:
			//  opcio: nom del camp del que volem treure l'opció. El sistema mantindrą totes les opcions menys la seleccionada
			var i;
			for(i=opcio.options.length-1;i>=0;i--) {
				if(opcio.options[i].selected)
				opcio.remove(i);
			}			
		}
		
		function isNum(numstr) {
			// Return immediately if an invalid value was passed in
			if (numstr+"" == "undefined" || numstr+"" == "null" || numstr+"" == "")	
			return false;
			var isValid = true;
			var decCount = 0;		// number of decimal points in the string
		
			// convert to a string for performing string comparisons.
			numstr += "";	
			
			// Loop through string and test each character. If any
			// character is not a number, return a false result.
			// Include special cases for negative numbers (first char == '-')
			// and a single decimal point (any one char in string == '.').   
			for (i = 0; i < numstr.length; i++) 
			{
				// track number of decimal points
				if (numstr.charAt(i) == ".") decCount++;
				if (!((numstr.charAt(i) >= "0") && (numstr.charAt(i) <= "9") || 
					(numstr.charAt(i) == "-") || (numstr.charAt(i) == "."))) 
				{
					isValid = false;
					break;
				} 
				else if ((numstr.charAt(i) == "-" && i != 0) ||
						 (numstr.charAt(i) == "." && numstr.length == 1) ||
						 (numstr.charAt(i) == "." && decCount > 1)) 
				{
					isValid = false;
					break;
				}	         	         	       
			} // END for   
			return isValid;
		}

		//funcions per moure elements dins un select box
		//agafat de http://www.tomred.net/index.php/JavaScript_Reorder_option_elements_of_an_HTML_select
		function moveUp(selectId) {
			//variables:
			//selectId: nom del camp del que volem treure l'opció. El sistema mantindrą totes les opcions menys la seleccionada
			var selectList = document.getElementById(selectId);
			var selectOptions = selectList.getElementsByTagName('option');
			for (var i = 1; i < selectOptions.length; i++) {
				var opt = selectOptions[i];
				if (opt.selected) {
					selectList.removeChild(opt);
					selectList.insertBefore(opt, selectOptions[i - 1]);
				}
			   }
		}

		function moveDown(selectId) {
			//selectId: nom del camp del que volem treure l'opció. El sistema mantindrą totes les opcions menys la seleccionada
			var selectList = document.getElementById(selectId);
			var selectOptions = selectList.getElementsByTagName('option');
			for (var i = selectOptions.length - 2; i >= 0; i--) {
				var opt = selectOptions[i];
				if (opt.selected) {
				   var nextOpt = selectOptions[i + 1];
				   opt = selectList.removeChild(opt);
				   nextOpt = selectList.replaceChild(opt, nextOpt);
				   selectList.insertBefore(nextOpt, opt);
				}
			   }
		}
	
