// FUNCIONS QUE AFEGEIXEN CAMPS INPUT EN UN FORMULARI
var numero = 1;
var numele_songs = 1;
var numele_components = 1;
 
function modificar_num(components,songs){
	numele_components = components;
	numele_songs = songs;
}
 
// Funcions comunes
c= function (tag) { return document.createElement(tag); } // Crea un element
d = function (id) { return document.getElementById(id); } // Retorna un element en base al id
e = function (evt) { return (!evt) ? event : evt; } // Retorna l'event
f = function (evt) { return evt.srcElement ?  evt.srcElement : evt.target; } // Retorna l'objecte que genera l'event
 
afegir_song = function () {
   numele_songs++;
   container = d('songs'); 
   div = c('DIV');
   div.id = 'song' + (numele_songs);
   label = c('LABEL');
   label.className = 'camp_multiple';
   label.innerHTML = 'Cançó <font color="#999999">(mp3)</font> ';
   image = c('IMG');
   image.src = 'img/obligat.gif';
   field = c('INPUT');   
   field.name = 'song[]';
   field.id = 'name_Req';
   field.title = 'Si us plau adjunteu la cançó';
   field.type = 'file';
   field.size = '40';
   field.style.marginRight = '3px';     
   a = c('A');
   a.name = 'song' + numele_songs;  
   a.href = '#';
   a.title = 'Treu aquest camp del formulari.';
   a.onclick = treure_song;
   a.innerHTML = '[-]';
   container.appendChild(div);
   div.appendChild(label);
   label.appendChild(image);
   div.appendChild(field);
   div.appendChild(a);

text = d('dinamic_text');
   text.innerHTML = '[+]';
   return false;
}
treure_song = function (evt) {
   lnk = f(e(evt));
   div = d(lnk.name);
   div.parentNode.removeChild(div);
   numele_songs--;
   return false;
}
afegir_component = function () {
   numele_components++;
   container = d('components'); 
   div = c('DIV');
   div.id = 'component' + (numele_components);
   label = c('LABEL');
   label.className = 'camp_multiple';
   label.innerHTML = 'Nom ';
   image = c('IMG');
   image.src = 'img/obligat.gif';
   field = c('INPUT');   
   field.name = 'name[]';
   field.id = 'name_Req';
   field.title = 'Si us plau introduïu el nom del component';
   field.type = 'text';
   field.maxlength = '50';
   field.style.marginRight = '10px';  
   field.style.width = '270px';
   a = c('A');
   a.name = 'component' + numele_components;  
   a.href = '#';
   a.title = 'Treu aquest camp del formulari.';
   a.onclick = treure_component;
   a.innerHTML = '[-]';
   label2 = c('LABEL');
   label2.className = 'camp_multiple';
   label2.innerHTML = 'Rol ';
   image2 = c('IMG');
   image2.src = 'img/obligat.gif';
   field2 = c('INPUT');   
   field2.name = 'rol[]';
   field2.id = 'name_Req';
   field2.title = 'Si us plau introduïu el rol del component';
   field2.type = 'text';
   field2.maxlength = '50';
   field2.style.marginRight = '10px';  
   field2.style.width = '270px';
   container.appendChild(div);
   div.appendChild(label);
   label.appendChild(image);
   div.appendChild(field);
   div.appendChild(a);
   div.appendChild(label2);
   label2.appendChild(image2);
   div.appendChild(field2);

   text = d('dinamic_text');
   text.innerHTML = '[+]';
   return false;
}
treure_component = function (evt) {
   lnk = f(e(evt));
   div = d(lnk.name);
   div.parentNode.removeChild(div);
   numele_components--;
   return false;
}

function treure_item(nom){
   div = d(nom);
   div.parentNode.removeChild(div);
   numele_components--;
   return false;
}
