var district_contacts = {
    count : 0,
    fileCount : 0,

    init : function() {
        district_contacts.count = document.getElementById('district_additional').childNodes.length;
        district_contacts.atLeastOneIng();
    },
    atLeastOneIng : function() {
        if(document.getElementById('district_additional').getElementsByTagName('div').length) return;
		district_contacts.addIng();
    },
    addIng : function(el) {
        if(el) while(el.className != 'parent-sel') el = el.parentNode;
        var div = district_contacts.searchProto();
        el ? el.parentNode.insertBefore(div, el.nextSibling) :
            document.getElementById('district_additional').appendChild(div);
    },
    rmIng : function(el) {
        while(el.className != 'parent-sel') el = el.parentNode;
        el.parentNode.removeChild(el); 
        setTimeout(district_contacts.atLeastOneIng, 500);
    },
    searchProto : function() {
        var proto = document.getElementById('districtcontacts').firstChild.cloneNode(true);
        var count = district_contacts.count++;
        var fileCount = school_contacts.fileCount++;
        proto.innerHTML = proto.innerHTML.replace(/\%n/g, count);
        proto.innerHTML = proto.innerHTML.replace(/\%f/g, fileCount);
        return proto;
    },
	

	// define a custom method on the string class to trim leading and training spaces
	trim : function() { 
		return this.replace(/^\s+|\s+$/g, '');
	}


};
eTool.add(window, 'load', district_contacts.init, false);