var attachmentCount = 1;
var modelAttForm;

function initAttForm(){
	modelAttForm = document.getElementById("attachment0").cloneNode(true);
	attachmentCount = document.getElementsByName("attachmentForm").length;
}

function editChilds( parentNode ){

	if( parentNode.hasChildNodes() ){ 
		var childs = parentNode.childNodes;
		var attr;

		for( var j = 0; j < childs.length; j++ ){
			if( childs[ j ].nodeValue != null ) childs[ j ].nodeValue = childs[ j ].nodeValue.split("0").join( replaceValue );
			attr = childs[ j ].attributes;

			if( childs[ j ].nodeName.toLowerCase() == "input" ) childs[ j ].setAttribute( "value", "" );
;

			if( attr != null )
				for( var i = 0; i < attr.length; i++ ){
					attr[ i ].nodeValue = attr[ i ].nodeValue.split( "0").join( replaceValue );
				}
			editChilds( childs[ j ] );
		}
	}
}

function addAttachment(){
	if( modelAttForm == null ) initAttForm();
	var attachmentForm = modelAttForm.cloneNode( true );
	attachmentForm.setAttribute( "id", "attachment" + (attachmentCount+1) );
	attachmentForm.removeAttribute( "style" );
	replaceValue = attachmentCount+1;
	editChilds( attachmentForm );
	document.getElementById("attachmentForms").appendChild( attachmentForm );
	attachmentCount++;
}

