//tools 
//fonctions utiles
if(typeof HTMLElement!="undefined" && ! 
HTMLElement.prototype.insertAdjacentElement)
{ 
    HTMLElement.prototype.insertAdjacentElement = function (where,parsedNode) 
    { 
        switch (where)
        { 
            case 'beforeBegin': 
            this.parentNode.insertBefore(parsedNode,this) 
            break; 
            case 'afterBegin': 
            this.insertBefore(parsedNode,this.firstChild); 
            break; 
            case 'beforeEnd': 
            this.appendChild(parsedNode); 
            break; 
            case 'afterEnd': 
            if (this.nextSibling) 
            this.parentNode.insertBefore(parsedNode,this.nextSibling); 
            else this.parentNode.appendChild(parsedNode); 
            break; 
        } 
    } 

    HTMLElement.prototype.insertAdjacentHTML = function 
    (where,htmlStr) 
    { 
        var r = this.ownerDocument.createRange(); 
        r.setStartBefore(this); 
        var parsedHTML = r.createContextualFragment(htmlStr); 
        this.insertAdjacentElement(where,parsedHTML) 
    } 


    HTMLElement.prototype.insertAdjacentText = function (where,txtStr) 
    { 
        var parsedText = document.createTextNode(txtStr) 
        this.insertAdjacentElement(where,parsedText) 
    } 
}



tools = {

//noter que l'html doit être correctement formaté pour que ca marche (voir createForm)
	pluriel: function(count, zero, singulier,pluriel)
	{
		if(count==0) return zero;
		if(count<=1) return singulier;
		else return pluriel;
	},
	append: function(html)
	{         
		document.body.insertAdjacentHTML('beforeEnd',html);
	},
        
    createForm: function(formname,action,method, formBody) 
	{
		formStr=('<form name="'+formname+'"  id="'+formname+'" action="'+action+'" method="'+method+'">');
		formStr+=(formBody);
		formStr+=("</form>");
		//correctement formatté, on peut tout écrire
		tools.append(formStr);				
    },
	
	submitForm: function(formname,action,method, formBody) 
	{
	
            tools.createForm(formname,action,method,formBody);
            document.forms[formname].submit();
    },

    bar: function() {
		document.write('bar');
    }
};
