/**
 *******************************************
 * $Id: global.js 689 2008-12-02 06:53:58Z gregbrown $
 * 
 * onFocus Software :: CMS
 * Copyright 2006 12d Networks, Inc.
 * 
 * Description:
 *		Global javascript file for the 
 *		application.
 *******************************************
 */

/**
 *  start: misc scripts
 */
function obMail(recip, dmn, ext, sbjct) {
    window.location.href = "mailto:" + recip + "@" + dmn + "." + ext +"?Subject=" + sbjct;
}

function getQueryVariable(variable, urlParams) {
    var query = urlParams;
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
            return unescape(pair[1]);
        }
    }
    return "";
}

function getVariableFromElementID(variable,idParams) {
    var query = idParams;
    var vars = query.split("--");
    for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("-");
        if (pair[0] == variable) {
            return unescape(pair[1]);
        }
    }
    return "";
}

function popUpWin(url,windowName, windowOptions) {
    windowName = window.open(url,windowName,windowOptions);
    windowName.focus();
}

function logOut(href) {
    ht = document.getElementsByTagName("html");
    ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
    if (confirm(rb.confirmLogoutMsg)) {
        window.location.href = href;
    } else {
        ht[0].style.filter = "";
        return false;
    }
}

function confirmDelete() {
    if (confirm(rb.confirmDeleteMsg)) {
        return true;
    } else {
        return false;
    }
}

function confirmAddFriend() {
    if (confirm(rb.confirmAddFriendMsg)) {
        return true;
    } else {
        return false;
    }
}

function confirmBanFriend() {
    if (confirm(rb.confirmBanFriendMsg)) {
        return true;
    } else {
        return false;
    }
}

function functionDisabled() {
    alert(rb.functionDisabledMsg);
    return false;
}

function textCounter(field, maxlimit) {
    var countField = $('#' + field.id + '_count');
    if (field.value.length > maxlimit) {
        field.value = field.value.substring(0, maxlimit);
    } else {
        countField.html((maxlimit - field.value.length) + " ");
    }
}

function toggleBox(boxId) {
    var box = $('#' + boxId + ' .box .contents');
    var ctrl = $('#' + boxId + ' .box .header .toggle a');
    if (ctrl.html() == "Show") {
        ctrl.html("Hide");
    } else {
        ctrl.html("Show");
    }
    box.toggle("fast");
}

/**
 *  end: misc scripts
 */

/**
 *  start: jQuery plugins
 */
if (jQuery) {
     // add the checkbox plugin hooks to jquery.
    jQuery.fn.check = function(mode) {
            // if mode is undefined, use 'on' as default
            var mode = mode || "on";
            return this.each(function() {
            switch(mode) {
                case "on":
                    this.checked = true;
                    break;
                case "off":
                    this.checked = false;
                    break;
                case "toggle":
                    this.checked = !this.checked;
                    break;
            }
        });
    };

    // nifty plugin for adding png overlays (jquery required)
    // example usage: $("#photos img").addOverlay("pngFile.png");
    jQuery.fn.addOverlay = function(overlay) {
            return this.each(function() {
                this.style.background = "url(" + this.src + ")";
                if (!jQuery.browser.msie || (jQuery.browser.msie && parseInt(jQuery.browser.version) >= 7)) {
                    this.src = overlay;
                } else {
                    this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', src='" + overlay + "')";
                }
            });
        };
}
/**
 *  end: jQuery plugins
 */