/*
 WebSweet JavaScript.
 (c) Caters-Hardy Design Studio

*/
// this function used for operations that take some time to complete.
function ws_please_wait() {
    document.body.innerHTML='<span id="please_wait"></span>' + document.body.innerHTML;
}

/*
Input Param1: object that whose value property is being checked.
Input Param2: message that will be displayed if the object has an empty value
Return: bool
Example Usage:
<form ..... onsubmit="return ws_check_empty(this.label, 'The label field cannot be left blank.');">....</form>
<input type="text" name="label" id="label" size="" maxlength="" value="" />
OR
<input type="submit" name="edit" id="edit" value="Save Page" class="submit" onclick="return ws_check_empty(this.form.label, 'The label field cannot be left blank.');" />
*/
function ws_check_empty(anobj, message) {
    if (anobj.value == '') {
        alert(message);
        return false;
    }
    return true;
}

/*
    Deletes contents of a container depending on the object type.
    Supported types: DIV, SPAN, Input
    Requires: Prototype function: "$"
    Input elements are focused after it has been cleared
*/
function ws_clear_container(container_name) {
    cobj = $(container_name);

    if (cobj.tagName == 'DIV' || cobj.tagName == 'SPAN') {
        cobj.innerHTML = '';
    } else if (cobj.tagName == 'INPUT') {
        cobj.value = '';
        cobj.focus();
    } else {
        return false;
    }

    return true;
}

// Makes some effects e.g. for deletion the item pulsates and changes its colour to red to
// make itself noticed.
function ws_effect(object_id, status, colour) {
    status = status || 'blink';
    if (status == 'delete') {
        colour = colour || '#ff0000'; // Red
    } else if (status == 'blink') {
        colour = colour || '#81BDFF'; // Silver
    }

    new Effect.Highlight($(object_id), {
                        startcolor   : colour,
                        duration     : 1
    });

    new Effect.Pulsate($(object_id), {
    pulses: 1,
    from: 1.0,
    to: 0.8,
    transition: Effect.Transitions.linear,
    duration: 1.5});

    // If delete remove item visually, if the colour is a different one that means the developer wants just to trigger user's attention.
    if (status == 'delete') {
//                new Effect.SwitchOff($(object_id));
//                new Effect.Puff($(object_id));
        new Effect.Shrink($(object_id));
    }
}


// Because of Ajax, I have to execute functions to make tooltips appear or other functionality enabled.
// It is  created by jQuery library
function ws_system_post_ajax() {
    // This is a proxy function to /js/jquery.js:ws_install_jquery_handlers function.
    ws_install_jquery_handlers();
    return;
}
