Q:

Why is this setTimeout not working & related question inside

I have this script on a page of mine and the setTimeout function never fires. It's just an alert right now but i'm just testing it out. I'm doing a meta refresh on the page just after it if that's any clue, but i've also given that a 10 sec delay so the page isn't refreshed before it's supposed to trigger.
Also, the related question: If I run a javascript with a delay of, say, 10 seconds (with setTimeout) and in that javascript I try to modify a design element that's not on the page when the setTimeout is declared but will be by the time the script is fired. Will it work?
<script language=javascript>

var xmlhttp_get_memento;    
function loop_alerte(){
    setTimeout( function() {
        alert("timeout");
    }, 5000);
    xmlhttp_get_memento = new XMLHttpRequest();
    if (xmlhttp_get_memento==null)
    {
        alert ("Browser does not support HTTP Request (1)");
        return;
    }   
    var url="crm/ajax/get_mementos.php";
    url=url+"?sid="+Math.random();
    xmlhttp_get_memento.onreadystatechange=function() {
        if (xmlhttp_get_memento.readyState == 4) {  
            alert(xmlhttp_get_memento.responseText);                                        
            schimbare_tip_cursor("default");
        }
        else{
            schimbare_tip_cursor("progress");
        }
    };

xmlhttp_get_memento.open("GET",url,true);
xmlhttp_get_memento.send(null);
}

loop_alerte();
</script>';

A:

Your setTimeout looks good, so there's probably something else that's wrong. Have you tried using a javascript debugger to see if you get any errors?
As for your second question, yes, that shouldn't be any problem, as the anonymous function inside the setTimout won't be evaluated until it runs. Live sample here: http://jsbin.com/afonup/2/edit Both with and without jQuery.

