function attachmentFields()
{
	fields = new Array();
	for (var i = 0; i < document.portfolio.elements.length; i++) {
		if (document.portfolio.elements[i].type == 'file' &&
			document.portfolio.elements[i].name.substr(0, 6) == 'photo_') 
		{
			fields[fields.length] = document.portfolio.elements[i];
		}
	}
return fields;
}
	
function attachmentChanged()
{
	var usedFields = 0;
	var fields = attachmentFields();

	for (var i = 0; i < fields.length; i++) {
		if (fields[i].value.length > 0) {
			usedFields++;
		}
	}
	
	if(fields.length > 1)
	{
		if(fields[fields.length - 1].value.length > 0)
			usedFields = fields.length;
	}
	
	if (usedFields == fields.length) 
	{
		
		var lastRow = document.getElementById('credit_' + usedFields);
		if (lastRow) 
		{
			var newRow = document.createElement('tr');
			var td = document.createElement('td');
			newRow.appendChild(td);
			td.setAttribute("align", "right");
			var b = document.createElement('b');
			td.appendChild(b);
			b.appendChild(document.createTextNode('Photo ' + (usedFields + 1) + ' :'));
			td = document.createElement('td');
			newRow.appendChild(td);
			td.setAttribute("align", "left");
			var file = document.createElement('input');
			file.setAttribute("type", "file");
			file.setAttribute("id", 'photo_' + (usedFields + 1));
			td.appendChild(file);
			file.setAttribute("name", 'photo_' + (usedFields + 1));
			file.setAttribute("id", 'photo_' + (usedFields + 1));
			file.onchange = function() { attachmentChanged(); };
			file.setAttribute("size", 25);
			lastRow.parentNode.parentNode.parentNode.insertBefore(newRow, lastRow.parentNode.parentNode.nextSibling);
			var newRow2 = document.createElement('tr');
			var td2 = document.createElement('td');
			newRow2.appendChild(td2);
			td2.setAttribute("align", "right");
			var b2 = document.createElement('b');
			td2.appendChild(b2);
			b2.appendChild(document.createTextNode('Photo ' + (usedFields + 1) + ' credit:'));
			td2 = document.createElement('td');
			newRow2.appendChild(td2);
			td2.setAttribute("align", "left");
			var text = document.createElement('input');
			text.setAttribute("type", "text");
			text.setAttribute("size", "52");
			text.setAttribute("maxlength", "50");
			text.setAttribute("name",  'credit_' + (usedFields + 1));
			text.setAttribute("id", 'credit_' + (usedFields + 1));
			td2.appendChild(text);
			newRow.parentNode.insertBefore(newRow2, newRow.nextSibling);
			document.getElementById('nb_photo').value = usedFields + 1;
		}
	}
}

function isArray(obj) {
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}

function affiche_desc()
{
	document.getElementById('see_detail').style.visibility = 'hidden';
	document.getElementById('description_detail').style.display = 'block';
	document.getElementById('description_detail').style.visibility = 'visible';
}
