// CONFIRM PROMPT
/* <a href="http://www.google.com/" onclick="return confirmPrompt(this.href, 'Are you sure you want to?');">Test</a> */
function confirmPrompt(url, msg) {
    if (confirm(msg)) window.location = url;
    return false;
}

// POPUP
/* <a href="http://www.google.com/" onclick="return doPopup(this.href, {location:'yes'});">Test</a> */
function doPopup(url, options) {
    var Popup = {
        open: function(url, options) {
            this.options = {
                width: 600,
                height: 500,
                name: '_blank',
                location: 'no',
                menubar: 'no',
                toolbar: 'no',
                status: 'yes',
                scrollbars: 'yes',
                resizable: 'yes',
                top: '',
                left: '',
                center: true
            }
            Object.extend(this.options, options || {});
            this.options.width = this.options.width < screen.availWidth ? this.options.width : screen.availWidth;
            this.options.height = this.options.height < screen.availHeight ? this.options.height : screen.availHeight;
            if (this.options.center) {
                this.options.top = (screen.height - this.options.height) / 2 ;
                this.options.left = (screen.width - this.options.width) / 2;
            }
            var openoptions = 'width=' +this.options.width+ ',height=' +this.options.height+ ',location=' +this.options.location+ ',menubar=' +this.options.menubar+ ',toolbar=' +this.options.toolbar+ ',scrollbars=' +this.options.scrollbars+ ',resizable=' +this.options.resizable+ ',status=' +this.options.status
            if (this.options.top != '') openoptions += ',top=' +this.options.top;
            if (this.options.left != '') openoptions += ',left=' +this.options.left;
            window.open(url, this.options.name, openoptions);
            return false;
        }
    }
    return Popup.open(url, options);
}

// HANDLE AJAX JSON RESPONSE
function handleResponse(transport) {
    var content = (transport.responseText).evalJSON();
    Object.keys(content.elements).each(function(item) {
        $(item).update(content['elements'][item]);
    });
    Object.keys(content.javascript).each(function(item) {
        eval( content['javascript'][item]);
    });
}

// SET COOKIE
function setCookie(c_name, value, expiredays, path) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie = c_name+ "=" +escape(value) + ((expiredays==null) ? "" : ";expires=" +exdate.toGMTString()) + ";path=" +path;
}

// GET COOKIE
function getCookie(name) {
    var search = name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        // COOKIE EXISTS
        if (offset != -1) {
            offset += search.length
            // SET INDEX OF BEGINNING OF VALUE
            end = document.cookie.indexOf(";", offset);
            // SET INDEX OF END OF COOKIE VALUE
            if (end == -1) end = document.cookie.length;
            returnvalue=unescape(document.cookie.substring(offset, end))
        }
    }
    return returnvalue;
}

// PRELOAD IMAGE
function preloadImage(img) {
    var preload = new Image();
    preload.src = img;
}

var swapLoaded = new Array();

// SWAP IMAGE
function swapImage(el, img_over, img_out) {
    if (img_over) preloadImage(img_over);
    var id = $(el).readAttribute('id');
    if (!id) {
        var id = 'rand_id-' +Math.random();
        $(el).writeAttribute('id', id);
    }
    if (!swapLoaded[id]) {
        swapLoaded[id] = $(el).readAttribute('src');
        $(el).writeAttribute('onload', '');
        Event.observe(el, 'mouseover', function() {
            if (img_over) $(el).writeAttribute('src', img_over);
        });
        Event.observe(el, 'mouseout', function() {
            if (img_out) {
                $(el).writeAttribute('src', img_out);
            } else {
                $(el).writeAttribute('src', swapLoaded[id]);
            }
        });
    }
}


/*** CUSTOM FUNCTIONS ***/


/* ON PAGE LOAD
document.observe('dom:loaded', function() {

    leftNav_init();

});
*/