/* --------------------------------------------------------
    Javascript Global Functions
    Filename: js/global.js
   -------------------------------------------------------- */

/* --------------------------------------------------------
    Function:     preload_image()
    Description:  Preloads image in cache
    Params:       @image_name - string
                  @image_src  - string
   -------------------------------------------------------- */

    function preload_image(image_name, image_src) {
        if (document.images) {
            eval(image_name + ' = new Image()');
            eval(image_name + '.src = "' + image_src + '"');
        }
    }

/* --------------------------------------------------------
    Function:     change_image()
    Description:  Swaps image for rollover states
    Params:       @image_name - string
                  @image_src  - string
   -------------------------------------------------------- */

    function change_image(image_name, image_src) {
        if (document.images) {
            document.images[image_name].src = image_src;
        }
    }

/* --------------------------------------------------------
    Function:     open_window()
    Description:  Opens window (popup) with a set of params
    Params:       @page_url        - string
                  @page_name       - string
                  @window_width    - numeric, no quotes
                  @window_height   - numeric, no quotes
                  @scrollbar_value - boolean, 'yes' or 'no'
                  @is_center       - boolean, 'yes' or 'no'
   -------------------------------------------------------- */

    function open_window(page_url, page_name, window_width, window_height, scrollbar_value, is_center) {
        var window_pos_x = 20;
        var window_pos_y = 20;
        if (is_center == 'yes') {
            window_pos_x = (screen.width / 2) - (window_width / 2);
            window_pos_y = (screen.height / 2) - (window_height / 2);
        }
        popup_window = this.open(page_url, page_name, "toolbar=no,status=no,menubar=no,location=no,scrollbars=" + scrollbar_value + ",resizable=no,width=" + window_width + ",height=" + window_height + ",screenX=" + window_pos_x + ",screenY=" + window_pos_y + ",left=" + window_pos_x + ",top=" + window_pos_y);
        popup_window.resizeTo(window_width + 6, window_height + 54);
        popup_window.focus();
    }

/* --------------------------------------------------------
    Function:     anti_spam_email()
    Description:  Protects email from spam bots
    Params:       @user     - string
                  @domain   - string
                  @linktext - string (not required)
   -------------------------------------------------------- */

    function anti_spam_email(user, domain, linktext) {
        var username = user;
        var hostname = domain;
        if (linktext == '') {
            linktext = username + "&#064;" + hostname;
        }
        document.write("<a href=" + "mail" + "to:" + username +"&#064;" + hostname + ">" + linktext + "</a>");
    }

/* --------------------------------------------------------
    Function:     show_hide_element()
    Description:  Shows and hides DOM element by ID
    Params:       @obj - string
   -------------------------------------------------------- */

    function show_hide_element(id){
        var my_element = document.getElementById(id);
        if (my_element.style.display == "none"){
            my_element.style.display = "block";
        } else {
            my_element.style.display = "none";
        }
    }