
function update_messages() {
    function message_callback(php_output) {
        document.getElementById("message_count").innerHTML = php_output;
    }
    x_ajax_message_count(false, message_callback);
}
function update_clock() {
    function clock_callback(php_output) {
        document.getElementById("clock_div").innerHTML = php_output;
    }
    x_ajax_clock(false, clock_callback);
}
function update_captcha(id) {
    document.getElementById("captcha_" + id).innerHTML = "<div class=\"cap_holder\"><br \/><br \/>Updating image ...<br \/><\/div>";
    function update_captcha_callback(php_output) {
        document.getElementById("captcha_" + id).innerHTML = php_output;
    }
    x_ajax_captcha(id, update_captcha_callback);
}
function make_sure(message) {
    if (confirm(message)) {
        return true;
    }
    else {
        return false;
    }
}
function change_font_size() {
    var dindex = document.getElementById("font_size").selectedIndex;
    var val = document.getElementById("font_size")[dindex].value;
    document.getElementById("body_tag").style.fontSize = val;
}
function hide_help(div) {
    new Effect.Fade(div, {duration: 1});
}
function show_help2(div) {
    if (document.getElementById(div).style.display != 'none') {
        new Effect.BlindUp(div, {duration: 1});
    }
    else {
        new Effect.BlindDown(div, {duration: 1});
    }
}
function show_help(div) {
    new Effect.Appear(div, {duration: 1});
}
function do_intro(step) {
    new Effect.Appear("intro_" + step, {duration: 2});
}
function show_demos() {
    function show_demo_div() {
        new Effect.Appear("demo_menu");
        document.getElementById("demo_link").style.color = '#1e6da8';
    }
    document.getElementById("demo_menu").innerHTML = '<h3>Demos</h3><br /><div style="font-style: italic; color: #135C94; font-weight: bold; font-size: 120%; margin-left: 20px;" id="cart_link"><a href="#" onclick="start_cart(); return false;">Shopping Cart</a><br /><a href="#" onclick="start_gallery(); return false;">Image Gallery</a><br /></div>';
    new Effect.Fade("content_inner", {afterFinish: show_demo_div});
}
function start_gallery() {
        function gallery_callback(output) {
            document.getElementById("inside_content_2").innerHTML = output;
            new Effect.Appear("inside_content_2", {from: 0.0, to: 1, duration: .1, afterFinish: show_gallery_start});
        }
        x_ajax_get_image_gallery(false, gallery_callback);
        new Effect.Fade("demo_menu");
}
function show_catalog() {
    document.getElementById("cart_link").innerHTML = "Loading catalog...";
    function show_catalog_callback(output) {
        function print_catalog() {
            document.getElementById("content_inner").innerHTML = output;
            new Effect.Appear("content_inner");
        }
        new Effect.Fade("demo_menu", {afterFinish: print_catalog});
    }
    x_ajax_get_catalog(false, show_catalog_callback);
    //document.location.href="/catalog/";
}
function start_cart() {
        document.getElementById("cart_outer").style.display = 'none';
        function show_cart(output) {
            document.getElementById("cart_outer").innerHTML = output;
            new Effect.BlindDown("cart_outer", {delay: .7, duration: 1});
        }
        x_ajax_get_cart(false, show_cart);
        //document.getElementById("cart_link").style.color = "#666";
        //document.getElementById("cart_link").innerHTML = "Setting up shopping cart...";
}
function add_to_cart(id) {
    function update_cart(output) {
        document.getElementById("cart_outer").innerHTML = output;
        new Effect.Fade("cart", {duration: .2});
        new Effect.Appear("cart", {duration: .2, delay: .2});
        new Effect.Fade("cart", {duration: .2, delay: .4});
        new Effect.Appear("cart", {duration: .2, delay: .6});
    }
    if (document.getElementById("qty_" + id)) {
        var dropdownIndex = document.getElementById("qty_" + id).selectedIndex;
        var qty_val = document.getElementById("qty_" + id)[dropdownIndex].value;
    }
    else {
        var qty_val = 1;
    }
    x_ajax_add_to_cart(id, qty_val, update_cart);
}
function update_cart_item(id) {
    function update_cart_callback(output) {
        document.getElementById("inside_content_2").innerHTML = output; 
    }
    if (document.getElementById("qty_" + id)) {
        var qty_val = document.getElementById("qty_" + id).value;
    }
    else {
        var qty_val = 1;
    }
    x_ajax_update_cart_item(id, qty_val, update_cart_callback);
}
function delete_cart_item(id) {
    function delete_cart_callback(output) {
        document.getElementById("inside_content_2").innerHTML = output; 
    }
    x_ajax_delete_cart_item(id, delete_cart_callback);
}
function show_detail(img_src) {
    var previous_link = '';
    var next_link = '';
    var image_title = '';
    if (document.getElementById(img_src + '_prev')) {
        var previous_image_name = document.getElementById(img_src + '_prev').value;
        var previous_link = '<a href="#" title="Previous Image" onclick="get_previous_image(\'' + previous_image_name + '\'); return false;">Previous</a>';
    }
    if (document.getElementById(img_src + '_next')) {
        var next_image_name = document.getElementById(img_src + '_next').value;
        var next_link = '<a href="#" title="Next Image" onclick="get_next_image(\'' +  next_image_name + '\'); return false;">Next</a>';
    }
    if (document.getElementById(img_src + '_title')) {
        var image_title = document.getElementById(img_src + '_title').value;
    }
    if (document.getElementById('image_detail').style.display =='none') {
        new Effect.Appear("back_screen", {delay: 0, duration: .0, from: 0.0, to: 0.7, afterFinish: show_image_detail()});
    }
    function show_image_detail() {
        var detailhtml = '<div style="position: absolute; z-index: 103; background-color: #eeeeee;"><a href="#" onclick="hide_detail();hide_backscreen(); return false;"><img style="width: border: none;" src="/gallery/' + img_src + '" /><div id="title_bar" style="z-index: 120; height: 35px; background-color: #666;  opacity: 1;"><table width="95%" align="center"><tr><td style="align: left; width: 1%;" >' + previous_link + '</td><td align="center" style="color: white; align: center;">' + image_title + '</td><td style="align: right; width: 1%;" >' + next_link + '</td></tr></table></div></a></div>';
        document.getElementById('inner_image').innerHTML = detailhtml;
        new Effect.Appear("image_detail", {delay: .1, duration: .6, from: 0.0, to: 1});
        //new Effect.Appear("title_bar", { delay: .1, duration: .6, from: 0.0, to: 0.8});
    }
}
function get_previous_image(prev_image) {
    function switch_image() {
        show_detail(prev_image);
    }
    new Effect.Fade("image_detail", {delay: 0, duration: .6, afterFinish: switch_image});
}
function get_next_image(next_image) {
    function switch_image() {
        show_detail(next_image);
    }
    new Effect.Fade("image_detail", {delay: 0, duration: .6, afterFinish: switch_image});

}
function show_content_preview() {
    document.getElementById("page_preview").style.display = 'block';
}
function hide_content_preview() {
    document.getElementById("page_preview").style.display = 'none';
}
function hide_detail() {
    new Effect.Fade("image_detail", {delay: .0, duration: .3});
}
function hide_backscreen() {
    new Effect.Fade("back_screen", {delay: .0, duration: 0.0});
}
function show_gallery_start() {
    var max = document.getElementById("image_page_count").value;
    for (i = 0; i < max; i++) {
        new Effect.Appear('image_preview_' +i,{delay:(i*.6)} );
    }
}
function hide_cart_view() {
    function do_after_hide() {
        document.getElementById("cart_view").innerHTML = '';
        document.getElementById("back_screen").style.display = 'none';
    }
    new Effect.BlindUp("cart_view", {duration: .6, afterFinish: do_after_hide});
}
    
function view_cart() {
    function show_cart_view(php_output) {
        new Effect.Appear("back_screen", {duration: .3, to: .8});
        document.getElementById("cart_view").innerHTML = php_output;
        new Effect.BlindDown("cart_view", {duration: .5, delay: .5});
    }
    x_ajax_view_cart(false, show_cart_view);
}
function define_word(word) {
    function print_definition(php_output) {
        if (document.getElementById('glossary_div').style.display == 'none') {
            document.getElementById('glossary_div').innerHTML = php_output;
            new Effect.Fade("", {delay: .3, duration: .4});
            new Effect.Appear("glossary_div", {delay: .3, duration: .4});
        }
    }
    x_ajax_get_definition(word, print_definition);
}
function autocomplete_value() {
    var input = document.getElementById("message_to").value;
    function autocomplete_callback(php_output) {
        document.getElementById("message_suggest").innerHTML = php_output;
    }
    x_ajax_autocomplete('user', input, autocomplete_callback);
}
function do_tour_step(mode) {
    var cnt = 0;
    function tour_callback(output) {
        if (output == 0) {
            document.getElementById("tour_message").innerHTML = '<div><h3>Out of Moves after ' + cnt + '<small> mode (' + mode + ')</small></h3><a onclick="do_tour_step(1); return false;" onmouseover="this.style.cursor=\'pointer\'">Start over (mode 1)</a><br /><a onclick="do_tour_step(2); return false;" onmouseover="this.style.cursor=\'pointer\'">Start over (mode 2)</a><br /><a onclick="do_tour_step(3); return false;" onmouseover="this.style.cursor=\'pointer\'">Start over (mode 3)</a></div>';
        }
        else {
            cnt++;
            document.getElementById("tour_div").innerHTML = output;
            x_ajax_do_tour(mode, tour_callback);
        }
    }
    x_ajax_do_tour(mode, tour_callback);
}
function select_value(input, field, src) {
    document.getElementById(field).value = input;
    document.getElementById(src).innerHTML = '';
}
var delay = 1000;
var timerID = null;
var secs = 0;
function start_timer() {
    secs = secs + 1;
    if (image_gallery && (secs == 1)) {show_gallery_start(); }
    //if (intro && ((secs -1 ) % 2 == 0 && secs < 8)) { do_intro((secs - 1)); }
    if (message_check && secs % 30 == 0) { update_messages(); }
              timerID = self.setTimeout("start_timer()", delay)
}
