

// 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;
}

// WINDOW LOAD
Event.observe(window, 'load', function() {

    // TOP-RIGHT FADE
    if($('top_image_img')){
        new Effect.Appear('top_image_img', {duration: 1});
    }

    // SUBMIT & RESET BUTTON STYLE
    $$('input').each(function(item) {
        if ((item.type == 'submit') || (item.type == 'reset')) {
            if (item.className!="donttouch") {
                item.setStyle({
                    background: 'transparent url(http://www.lazerpro.com/projects/2kbb.com/images/submit-bg.gif) no-repeat 0 3px',
                    color: '#fff',
                    border: '0px',
                    width: '102px',
                    height: '22px',
                    fontSize: '10px',
                    fontWeight: 'bold',
                    lineHeight: '10px'
                });
            }
        }
    });

});


/** OTHER JS **/


function doPopup(u, w, h) {
    var rand = Math.floor(Math.random() * 100)
    var win = window.open(u, 'Popup_' +rand, 'toolbar=no,location=no,menubar=no,status=yes,scrollbars=yes,resizable=yes,width=' +w+ ',height=' +h);
}