var new_text;
var anim_type = 0;
var load_timeout = null;
var cur_page =".";
var div_id = 'contents';

function log(text) {
//    document.getElementById('history').innerHTML += text+"<br>";
}

function rnd(n) {
    return Math.ceil(n *  Math.random());
}

function doneGetPage(text) {
    load_timeout = null;
    if (text=='A') text = new_text;
    document.getElementById(div_id).innerHTML=text;
    var redirect = document.getElementById('_redirect');
    if (redirect != null) {
        cur_page = window.location.href;
        doGetPage(redirect.innerHTML);
        window.location = "#"+redirect.innerHTML.substr(site_len+1);
        return;
    }
    try { var flag_links = document.getElementById('new_flag_links').innerHTML; } catch(e) {}
    try {
        var menu_links = document.getElementById('new_menu_contents').innerHTML;
        document.getElementById('menu_contents').innerHTML = menu_links;
    } catch (e) {}
    try {
        document.title=document.getElementById('new_window_title').innerHTML;
    } catch (e) {}
    fix.fixLinks();
    try { document.getElementById('flag_links').innerHTML = flag_links; } catch(e) {}
    try { var onload = document.getElementById('new_on_load').innerHTML; eval(onload); } catch(e) {}
    anim_type = rnd(5.);
    cur_page = window.location.href;
}

function doGetPage(page) {
    if (load_timeout != null) {
        clearTimeout(load_timeout);
        load_timeout = null;
    }
    var xmlhttp = getHTTPObject();
    if (page.indexOf("/photo/")!=-1 && cur_page.indexOf("/photo/")!=-1) {
        div_id = 'photo';
        xmlhttp.open("GET", "/"+site+page+"?ajax=photo",true);
    } else {
        div_id = 'contents';
//        if (page.indexOf("/recherche")!=-1) {
//            xmlhttp.open("GET", "/"+site+page+"&ajax",true);
//        } else {
            xmlhttp.open("GET", "/"+site+page+"?ajax",true);
//        }
        document.getElementById(div_id).innerHTML='<div class="loading">Loading...</div>';
    }
    xmlhttp.send(null);
}

