/* --------------------------------------------------------
   Fonctions globales Javascript
   global.js
   -------------------------------------------------------- */

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

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

/*
 open_window()
 opens a new pop-up window
*/
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.focus();
}

/*
 anti_spam_email()
 protects email from spam bots
*/

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

/*
 valid_guestbook_form()
 protects email from spam bots
*/
function valid_guestbook_form() {

    var at = /^(.+)@(.+)\.(.+)$/;

    if (document.guestbook.posted_by.value == "") {
        alert('Please enter your name');
        document.guestbook.posted_by.focus();
        return false;
    }

    if (!at.test(document.guestbook.email.value) || document.guestbook.email.value == "") {
        alert('Please enter a valid email address');
        document.guestbook.email.focus();
        return false;
    }

    if (document.guestbook.comment.value == "") {
        alert('Please enter a comment');
        document.guestbook.comment.focus();
        return false;
    }
}
