// Extensio del objecte camp per guardar la correspondencia amb el nom en la BDs

function CampE(nom, DBname, valor, tipus, options) {
   this.size = 5;
   this.name = new String(nom);
   this.DBname = new String(DBname);
   this.value = new String(valor);
   this.type = new String(tipus);
   this.options = new String(options);
   
   return this;
}


function ConstruirCampsFormulari() {
   var strCamps
   var intCamp
   var camps = new Camps();
   var valor=new String();
   var re;
	
   strCamps="";	
   //Per cada element de camps, concatenar $nom|valor del camp en el formulari
   for (intCamp=1;intCamp<=camps.size;intCamp++) {
      if (intCamp!=1) strCamps+="$";
      if (camps[intCamp].value!="") {
      	// Si el valor requereix cometes es posen
	if (camps[intCamp].type=="text" || camps[intCamp].type=="EMail") {
		valor=camps[intCamp].value;
		re=/'/g;
		valor=valor.replace(re,"''");
		strCamps+=camps[intCamp].DBname + "|'" + valor + "'";
	} else if (camps[intCamp].type=="date") {
		strCamps+=camps[intCamp].DBname + "|Convert(datetime,'" + camps[intCamp].value + "',103)"; // dd/mm/yyyy
	} else if (camps[intCamp].type=="hour") {
		strCamps+=camps[intCamp].DBname + "|Convert(datetime,'" + camps[intCamp].value + ":00" + "',108)"; // hh:mm:ss
	} else {
		strCamps+=camps[intCamp].DBname + "|" + camps[intCamp].value; 
	}
      } else {
      	strCamps+=camps[intCamp].DBname + "|NULL";
      }
   }
   return(strCamps);
}


